Commit 09be9059971f6a972600a1b7966a79e58f99055e
1 parent
43babcff
冒险接口
Showing
8 changed files
with
191 additions
and
20 deletions
Show diff stats
src/GlobalVar.lua
src/ProtocolCode.lua
@@ -30,13 +30,15 @@ actionCodes = { | @@ -30,13 +30,15 @@ actionCodes = { | ||
30 | Role_openTimeBoxRpc = 116, | 30 | Role_openTimeBoxRpc = 116, |
31 | 31 | ||
32 | Adv_startAdvRpc = 151, | 32 | Adv_startAdvRpc = 151, |
33 | - Adv_roleFormatRpc = 152, | 33 | + Adv_startHangRpc = 152, |
34 | Adv_clickBlockRpc = 153, | 34 | Adv_clickBlockRpc = 153, |
35 | Adv_useItemRpc = 154, | 35 | Adv_useItemRpc = 154, |
36 | Adv_usePotionRpc = 155, | 36 | Adv_usePotionRpc = 155, |
37 | Adv_exitAdvRpc = 156, | 37 | Adv_exitAdvRpc = 156, |
38 | Adv_startBattleRpc = 157, | 38 | Adv_startBattleRpc = 157, |
39 | Adv_endBattleRpc = 158, | 39 | Adv_endBattleRpc = 158, |
40 | + Adv_endHangRpc = 159, | ||
41 | + Adv_buyAdvCountRpc = 160, | ||
40 | 42 | ||
41 | Hero_loadInfos = 201, | 43 | Hero_loadInfos = 201, |
42 | Hero_updateProperty = 202, | 44 | Hero_updateProperty = 202, |
src/actions/AdvAction.lua
@@ -16,38 +16,185 @@ local table_unpack = table.unpack | @@ -16,38 +16,185 @@ local table_unpack = table.unpack | ||
16 | 16 | ||
17 | local _M = {} | 17 | local _M = {} |
18 | 18 | ||
19 | + | ||
20 | +local function checkFormat(role, format, isHang) | ||
21 | + local advHang = role:getProperty("advHang") | ||
22 | + local hadHero = {} | ||
23 | + for chapterId, info in pairs(advHang) do | ||
24 | + if info.format then | ||
25 | + for _, heroId in pairs(info.format.heros) do | ||
26 | + hadHero[heroId] = true | ||
27 | + end | ||
28 | + end | ||
29 | + end | ||
30 | + | ||
31 | + if isHang then | ||
32 | + for _, heroId in pairs(role:getProperty("advTeam").heros or {}) do | ||
33 | + hadHero[heroId] = true | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + if not format.leader then return end | ||
38 | + local hadLeader = false | ||
39 | + for slot, heroId in pairs(format.heros) do | ||
40 | + if not role.heros[heroId] or hadHero[heroId] then | ||
41 | + return | ||
42 | + end | ||
43 | + if heroId == format.leader then | ||
44 | + hadLeader = true | ||
45 | + end | ||
46 | + end | ||
47 | + if not hadLeader then return end | ||
48 | + return true | ||
49 | +end | ||
50 | + | ||
19 | --开始一个新的关卡 | 51 | --开始一个新的关卡 |
20 | function _M.startAdvRpc( agent, data ) | 52 | function _M.startAdvRpc( agent, data ) |
21 | local role = agent.role | 53 | local role = agent.role |
22 | local msg = MsgPack.unpack(data) | 54 | local msg = MsgPack.unpack(data) |
23 | - local chapterId = msg.chapterId | 55 | + local chapterId = msg.chapterId --关卡id |
56 | + local layer = msg.layer or 1 --选择层数 | ||
57 | + local format = msg.format --编队 | ||
58 | + local chapterData = csvdb["adv_chapterCsv"][chapterId] | ||
59 | + if not chapterData then return end | ||
60 | + | ||
61 | + if role.dailyData:getProperty("advC") >= role:getAdvHangLimit() then return end -- 是否有体力 | ||
62 | + | ||
63 | + local oklayer = false --层是否合法 | ||
64 | + if layer ~= 1 then | ||
65 | + for _, exLayer in ipairs(globalCsv.adv_can_out_layer) do | ||
66 | + if exLayer + 1 == layer then | ||
67 | + oklayer = true | ||
68 | + break | ||
69 | + end | ||
70 | + end | ||
71 | + end | ||
72 | + | ||
73 | + if not oklayer then return end | ||
74 | + if layer > chapterData.limitlevel then return end | ||
75 | + local advPass = role:getProperty("advPass") | ||
76 | + for _, id in ipairs(chapterData.prepose:toArray(true, "=")) do | ||
77 | + if advPass[id] ~= csvdb["adv_chapterCsv"][id].limitlevel then return end -- 前置 | ||
78 | + end | ||
79 | + | ||
80 | + if layer ~= 1 and (advPass[chapterId] or 0) < (layer - 1) then return end --中继 | ||
81 | + | ||
82 | + if not checkFormat(role, format) then return end | ||
24 | 83 | ||
25 | --上一个关卡结束才可以开始新的关卡 | 84 | --上一个关卡结束才可以开始新的关卡 |
26 | local advInfo = role:getProperty("advInfo") | 85 | local advInfo = role:getProperty("advInfo") |
27 | if next(advInfo) then return end | 86 | if next(advInfo) then return end |
28 | - role:getAdvData():initByChapter(chapterId, 1) | 87 | + |
88 | + local advTeam = role:getProperty("advTeam") | ||
89 | + table.clear(advTeam) | ||
90 | + | ||
91 | + advTeam.heros = {} | ||
92 | + for slot, heroId in pairs(msg.heros) do | ||
93 | + advTeam.heros[slot] = heroId | ||
94 | + end | ||
95 | + advTeam.leader = msg.leader | ||
96 | + role:updateProperty({field = "advTeam", value = advTeam}) | ||
97 | + role.dailyData:updateProperty({field = "advC", delta = 1}) | ||
98 | + | ||
99 | + role:getAdvData():initByChapter(chapterId, layer) | ||
29 | 100 | ||
30 | SendPacket(actionCodes.Adv_startAdvRpc, '') | 101 | SendPacket(actionCodes.Adv_startAdvRpc, '') |
31 | return true | 102 | return true |
32 | end | 103 | end |
33 | 104 | ||
34 | -function _M.roleFormatRpc(agent , data) | 105 | + |
106 | +function _M.startHangRpc(agent, data) | ||
35 | local role = agent.role | 107 | local role = agent.role |
36 | local msg = MsgPack.unpack(data) | 108 | local msg = MsgPack.unpack(data) |
37 | - local advTeam = role:getProperty("advTeam") | ||
38 | - for slot, heroId in pairs(msg.heros) do | ||
39 | - if not role.heros[heroId] then | 109 | + local chapterId = msg.chapterId --关卡id |
110 | + local format = msg.format --编队 | ||
111 | + | ||
112 | + local chapterData = csvdb["adv_chapterCsv"][chapterId] | ||
113 | + if not chapterData then return end | ||
114 | + | ||
115 | + local advHang = role:getProperty("advHang") | ||
116 | + if advHang[chapterId] then return end --正在挂机 | ||
117 | + | ||
118 | + local advPass = role:getProperty("advPass") | ||
119 | + if advPass[chapterId] ~= chapterData.limitlevel then return end -- 没有全通关 | ||
120 | + | ||
121 | + | ||
122 | + if role.dailyData:getProperty("advC") >= role:getAdvHangLimit() then return end -- 是否有体力 | ||
123 | + | ||
124 | + if not checkFormat(role, format, true) then return end --编队是否正确 | ||
125 | + | ||
126 | + local battleV = 0 | ||
127 | + for _, heroId in pairs(format.heros) do | ||
128 | + local hero = role.heros[heroId] | ||
129 | + battleV = battleV + hero:getProperty("battleV") | ||
130 | + end | ||
131 | + if battleV < chapterData.idleValue then return end -- 战斗力是否满足 | ||
132 | + | ||
133 | + local info = {} | ||
134 | + info.format = {} | ||
135 | + info.format.leader = format.leader | ||
136 | + info.format.heros = {} | ||
137 | + for slot, heroId in pairs(format.heros) do | ||
138 | + info.format.heros[slot] = heroId | ||
139 | + end | ||
140 | + info.time = skynet.timex() + chapterData.idleTime --挂机时间 | ||
141 | + | ||
142 | + role:changeUpdates({{type = "advHang", field = chapterId, value = info}}) | ||
143 | + | ||
144 | + role.dailyData:updateProperty({field = "advC", delta = 1}) | ||
145 | + | ||
146 | + SendPacket(actionCodes.Adv_startHangRpc, '') | ||
147 | + return true | ||
148 | +end | ||
149 | + | ||
150 | +function _M.endHangRpc(agent, data) | ||
151 | + local role = agent.role | ||
152 | + local msg = MsgPack.unpack(data) | ||
153 | + | ||
154 | + local chapterId = msg.chapterId --关卡id | ||
155 | + local cancel = msg.cancel --是否是取消 | ||
156 | + | ||
157 | + local advHang = role:getProperty("advHang") | ||
158 | + local info = advHang[chapterId] | ||
159 | + if not info then return end | ||
160 | + | ||
161 | + local chapterData = csvdb["adv_chapterCsv"][chapterId] | ||
162 | + if not chapterData then return end | ||
163 | + | ||
164 | + local reward, isFull | ||
165 | + if skynet.timex() >= info.time then | ||
166 | + reward = role:award(chapterData.idleReward) | ||
167 | + else | ||
168 | + if cancel then | ||
169 | + if role.dailyData:getProperty("advC") <= 0 then | ||
170 | + isFull = true | ||
171 | + else | ||
172 | + role.dailyData:updateProperty({field = "advC", delta = -1}) | ||
173 | + end | ||
174 | + else | ||
40 | return | 175 | return |
41 | end | 176 | end |
42 | end | 177 | end |
43 | - table.clear(advTeam) | ||
44 | - advTeam.heros = {} | ||
45 | - for slot, heroId in pairs(msg.heros) do | ||
46 | - advTeam.heros[slot] = heroId | ||
47 | - end | ||
48 | - advTeam.leader = msg.leader | ||
49 | - role:updateProperty({field = "advTeam", value = advTeam}) | ||
50 | - SendPacket(actionCodes.Adv_roleFormatRpc, '') | 178 | + |
179 | + role:changeUpdates({{type = "advHang", field = chapterId, value = nil}}) | ||
180 | + | ||
181 | + SendPacket(actionCodes.Adv_endHangRpc, MsgPack.pack({reward = reward, isFull = isFull})) | ||
182 | + return true | ||
183 | +end | ||
184 | + | ||
185 | +function _M.buyAdvCountRpc(agent , data) | ||
186 | + local role = agent.role | ||
187 | + local msg = MsgPack.unpack(data) | ||
188 | + | ||
189 | + local count = msg.count --购买次数 | ||
190 | + if math.illegalNum(count, 1, math.min(globalCsv.adv_daily_buy_count - role.dailyData:getProperty("advBC"), role.dailyData:getProperty("advC"))) then return end | ||
191 | + | ||
192 | + local cost = {[ItemId.Diamond] = count * globalCsv.adv_daily_buy_cost} | ||
193 | + if not role:checkItemEnough(cost) then return end | ||
194 | + role:costItems(cost) | ||
195 | + role.dailyData:updateProperty({field = "advC", delta = -count}) | ||
196 | + | ||
197 | + SendPacket(actionCodes.Adv_buyAdvCountRpc, '') | ||
51 | return true | 198 | return true |
52 | end | 199 | end |
53 | 200 |
src/adv/Adv.lua
@@ -139,9 +139,12 @@ function Adv:over(success) | @@ -139,9 +139,12 @@ function Adv:over(success) | ||
139 | local scoreInfo = self.score | 139 | local scoreInfo = self.score |
140 | local reward | 140 | local reward |
141 | if success then | 141 | if success then |
142 | - self.owner:updateProperty({field = "advPass", self.owner:getProperty("advPass"):setv(self.chapterId, score)}) | ||
143 | - reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) | 142 | + local advPass = self.owner:getProperty("advPass") |
143 | + if self.level > (advPass[self.chapterId] or 0) then | ||
144 | + self.owner:changeUpdates({{type = "advPass", field = self.chapterId, value = self.level}}) | ||
145 | + end | ||
144 | 146 | ||
147 | + reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) | ||
145 | self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId}) | 148 | self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId}) |
146 | end | 149 | end |
147 | self:clear() | 150 | self:clear() |
src/adv/AdvMap.lua
@@ -211,6 +211,7 @@ createMap = function(mapId, chapterId, level) | @@ -211,6 +211,7 @@ createMap = function(mapId, chapterId, level) | ||
211 | end | 211 | end |
212 | haveBoss = true | 212 | haveBoss = true |
213 | end | 213 | end |
214 | + | ||
214 | --怪物 | 215 | --怪物 |
215 | randomFunc[AdvEventType.Monster] = function() | 216 | randomFunc[AdvEventType.Monster] = function() |
216 | if randomCommon() == false then | 217 | if randomCommon() == false then |
@@ -233,6 +234,8 @@ createMap = function(mapId, chapterId, level) | @@ -233,6 +234,8 @@ createMap = function(mapId, chapterId, level) | ||
233 | randomFunc[AdvEventType.Click] = randomCommon | 234 | randomFunc[AdvEventType.Click] = randomCommon |
234 | --跨层点 | 235 | --跨层点 |
235 | randomFunc[AdvEventType.Layer] = randomCommon | 236 | randomFunc[AdvEventType.Layer] = randomCommon |
237 | + --层级任务 | ||
238 | + randomFunc[AdvEventType.Task] = randomCommon | ||
236 | 239 | ||
237 | 240 | ||
238 | if randomFunc[etype] then | 241 | if randomFunc[etype] then |
src/models/Daily.lua
@@ -10,6 +10,8 @@ Daily.schema = { | @@ -10,6 +10,8 @@ Daily.schema = { | ||
10 | commentHero = {"string", ""}, -- 单日评论食灵记录 type=1 | 10 | commentHero = {"string", ""}, -- 单日评论食灵记录 type=1 |
11 | hangQC = {"number", 0}, -- 挂机快速次数 | 11 | hangQC = {"number", 0}, -- 挂机快速次数 |
12 | dinerQC = {"number", 0}, -- 贩卖加速次数 | 12 | dinerQC = {"number", 0}, -- 贩卖加速次数 |
13 | + advC = {"number", 0}, -- 冒险次数(消耗体力) | ||
14 | + advBC = {"number", 0}, -- 冒险次数购买次数(冒险体力购买次数) | ||
13 | } | 15 | } |
14 | 16 | ||
15 | function Daily:updateProperty(params) | 17 | function Daily:updateProperty(params) |
@@ -44,6 +46,8 @@ function Daily:data() | @@ -44,6 +46,8 @@ function Daily:data() | ||
44 | return { | 46 | return { |
45 | hangQC = self:getProperty("hangQC"), | 47 | hangQC = self:getProperty("hangQC"), |
46 | dinerQC = self:getProperty("dinerQC"), | 48 | dinerQC = self:getProperty("dinerQC"), |
49 | + advC = self:getProperty("advC"), | ||
50 | + advBC = self:getProperty("advBC"), | ||
47 | } | 51 | } |
48 | end | 52 | end |
49 | 53 |
src/models/Role.lua
@@ -12,6 +12,7 @@ RoleChangeStruct.bind(Role) | @@ -12,6 +12,7 @@ RoleChangeStruct.bind(Role) | ||
12 | function Role:ctor( properties ) | 12 | function Role:ctor( properties ) |
13 | Role.super.ctor(self, properties) | 13 | Role.super.ctor(self, properties) |
14 | self.ignoreHeartbeat = false | 14 | self.ignoreHeartbeat = false |
15 | + self.dailyData = nil | ||
15 | self.heros = {} | 16 | self.heros = {} |
16 | self.runeBag = {} | 17 | self.runeBag = {} |
17 | self.advData = nil | 18 | self.advData = nil |
@@ -41,11 +42,14 @@ Role.schema = { | @@ -41,11 +42,14 @@ Role.schema = { | ||
41 | bagLimit = {"table", globalCsv.store_limit_max}, | 42 | bagLimit = {"table", globalCsv.store_limit_max}, |
42 | 43 | ||
43 | --冒险相关 | 44 | --冒险相关 |
44 | - advPass = {"string", ""}, -- 通关记录 | 45 | + advPass = {"string", {}}, -- 通关记录 {chapterId = layer} |
45 | advItems = {"string", ""}, -- 冒险临时背包 | 46 | advItems = {"string", ""}, -- 冒险临时背包 |
46 | - advInfo = {"table", {}}, -- 冒险关卡信息 | 47 | + advInfo = {"table", {}}, -- 冒险关卡信息 |
47 | advTeam = {"table", {}}, -- 冒险玩家队伍信息 | 48 | advTeam = {"table", {}}, -- 冒险玩家队伍信息 |
48 | - | 49 | + advHang = {"table", {}}, -- 挂机信息 -- {chapterId = info} |
50 | + advTask = {"table", {l = {}, m = {}}}, -- 冒险已领取任务完成状态 -- l 层级任务, m 主线任务 {id = status} | ||
51 | + advMTask = {"table", {}}, -- 冒险主线已经完成的任务[数组] --为了节省空间 服务器使用 | ||
52 | + advAchiev = {"table", {}}, -- 冒险成就 {chapterId = {achievId = status}} | ||
49 | --挂机相关 | 53 | --挂机相关 |
50 | hangPass = {"table", {}}, -- 挂机通过的最大关卡 | 54 | hangPass = {"table", {}}, -- 挂机通过的最大关卡 |
51 | hangTeam = {"table", {}}, -- 挂机队伍 | 55 | hangTeam = {"table", {}}, -- 挂机队伍 |
@@ -177,6 +181,8 @@ function Role:data() | @@ -177,6 +181,8 @@ function Role:data() | ||
177 | advInfo = self:getProperty("advInfo"), | 181 | advInfo = self:getProperty("advInfo"), |
178 | advItems = self:getProperty("advItems"):toNumMap(), | 182 | advItems = self:getProperty("advItems"):toNumMap(), |
179 | advTeam = self:getProperty("advTeam"), | 183 | advTeam = self:getProperty("advTeam"), |
184 | + advHang = self:getProperty("advHang"), | ||
185 | + advTask = self:getProperty("advTask"), | ||
180 | 186 | ||
181 | hangPass = self:getProperty("hangPass"), | 187 | hangPass = self:getProperty("hangPass"), |
182 | hangTeam = self:getProperty("hangTeam"), | 188 | hangTeam = self:getProperty("hangTeam"), |
src/models/RolePlugin.lua
@@ -580,6 +580,11 @@ function RolePlugin.bind(Role) | @@ -580,6 +580,11 @@ function RolePlugin.bind(Role) | ||
580 | end | 580 | end |
581 | return battleValue | 581 | return battleValue |
582 | end | 582 | end |
583 | + | ||
584 | + function Role:getAdvHangLimit() | ||
585 | + -- todo | ||
586 | + return globalCsv.adv_daily_cross_count | ||
587 | + end | ||
583 | end | 588 | end |
584 | 589 | ||
585 | return RolePlugin | 590 | return RolePlugin |
586 | \ No newline at end of file | 591 | \ No newline at end of file |