Commit b176d7d37ea0467d18e72f6ec9cd4a2acaf0a278
1 parent
7828ffd0
冒险成就
Showing
8 changed files
with
165 additions
and
10 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/AdvAction.lua
... | ... | @@ -242,6 +242,8 @@ function _M.finishTaskRpc(agent, data) |
242 | 242 | status, reward = adv:finishMTask() |
243 | 243 | else |
244 | 244 | status, reward = adv:finishTask(taskId) |
245 | + adv:checkAchievement(adv.AchievType.TaskLayer, 1, taskId) | |
246 | + adv:updateAchievement() | |
245 | 247 | end |
246 | 248 | adv:updateTask() |
247 | 249 | if not status then return end |
... | ... | @@ -382,6 +384,7 @@ end |
382 | 384 | function _M.wheelSurfRpc(agent, data) |
383 | 385 | local role = agent.role |
384 | 386 | if not role:isFuncOpen(FuncOpenType.AdvWheelSurf) then return end |
387 | + | |
385 | 388 | if not role._advWheelSurfCount then return end |
386 | 389 | |
387 | 390 | local drawData = csvdb["adv_wheelsurfCsv"][role:getFuncLv(FuncOpenType.AdvWheelSurf)] |
... | ... | @@ -413,5 +416,26 @@ function _M.wheelSurfRpc(agent, data) |
413 | 416 | return true |
414 | 417 | end |
415 | 418 | |
419 | +function _M.finishAchievRpc(agent, data) | |
420 | + local role = agent.role | |
421 | + local msg = MsgPack.unpack(data) | |
422 | + -- local ctype = msg.ctype -- 领取类型 1 成就 2 pt累计奖励 | |
423 | + local chapterId = msg.chapterId --章节id | |
424 | + local taskId = msg.taskId -- 领取id | |
425 | + | |
426 | + local adv = role:getAdvData() | |
427 | + | |
428 | + local status, reward | |
429 | + -- if ctype == 1 then | |
430 | + -- status = adv:finishAchievement(chapterId, taskId) | |
431 | + -- elseif ctype == 2 then | |
432 | + status, reward = adv:getAchievementReward(chapterId, taskId) | |
433 | + -- end | |
434 | + if not status then return end | |
435 | + adv:updateAchievement() | |
436 | + SendPacket(actionCodes.Adv_finishAchievRpc, MsgPack.pack({reward = reward})) | |
437 | + return true | |
438 | +end | |
439 | + | |
416 | 440 | |
417 | 441 | return _M |
418 | 442 | \ No newline at end of file | ... | ... |
src/adv/Adv.lua
... | ... | @@ -43,8 +43,13 @@ end |
43 | 43 | |
44 | 44 | -- 随机新的地图 |
45 | 45 | function Adv:initByChapter(chapterId, level, isToNext, notNotify) |
46 | - if self.chapterId and chapterId ~= self.chapterId then return end --新的关卡 或者 去到下一层 | |
47 | - self.chapterId = chapterId | |
46 | + if not self.chapterId then -- 开始新的章节 | |
47 | + self.chapterId = chapterId | |
48 | + self:checkAchievement(Adv.AchievType.StartBattle, 1) | |
49 | + elseif chapterId ~= self.chapterId then -- 正常不会出现 | |
50 | + return | |
51 | + end | |
52 | + | |
48 | 53 | self.level = level or 1 |
49 | 54 | self.round = 0 |
50 | 55 | self.score = self.score or {} |
... | ... | @@ -110,6 +115,7 @@ function Adv:saveDB(notNotify) |
110 | 115 | end |
111 | 116 | |
112 | 117 | self:updateTask(notNotify) |
118 | + self:updateAchievement(notNotify) | |
113 | 119 | self.owner:updateProperties({advInfo = advInfo, advTeam = advTeam}, notNotify) |
114 | 120 | end |
115 | 121 | |
... | ... | @@ -163,6 +169,19 @@ function Adv:over(success) |
163 | 169 | if success then |
164 | 170 | reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) |
165 | 171 | self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId}) |
172 | + | |
173 | + -- 冒险队等级升一下子 | |
174 | + local advL = self.owner:getProperty("advL") | |
175 | + advL[2] = (advL[2] or 0) + 1 | |
176 | + for level = ((advL[1] or 0) + 1), #csvdb["adv_rankCsv"] do | |
177 | + local ldata = csvdb["adv_rankCsv"][level] | |
178 | + if ldata.unlock >= advL[2] then | |
179 | + advL[1] = level | |
180 | + self.owner:award(ldata.reward) | |
181 | + end | |
182 | + end | |
183 | + self.owner:updateProperty("advL", advL) | |
184 | + | |
166 | 185 | if self.owner:isFuncOpen(FuncOpenType.AdvWheelSurf) then |
167 | 186 | self.owner._advWheelSurfCount = 0 -- 抽奖进行次数 |
168 | 187 | end |
... | ... | @@ -238,6 +257,7 @@ function Adv:award(gift, params) |
238 | 257 | if count > 0 then |
239 | 258 | self:scoreChange(AdvScoreType.Item, {itemId, count}) |
240 | 259 | self:checkTask(Adv.TaskType.Item, count, itemId) |
260 | + self:checkAchievement(Adv.AchievType.GetItem, count, itemId) | |
241 | 261 | end |
242 | 262 | local origin = items:getv(itemId, 0) |
243 | 263 | local nums = origin + count |
... | ... | @@ -300,6 +320,8 @@ local function clickOut(self, room, block, params) |
300 | 320 | if params.relay then |
301 | 321 | if self.level % globalCsv.adv_can_out_layer_pre ~= 0 or not self.owner:isFuncOpen(FuncOpenType.AdvRelay) then return end |
302 | 322 | end |
323 | + | |
324 | + self:checkAchievement(Adv.AchievType.OverWin, 1, self.level) | |
303 | 325 | local levellimit = csvdb["adv_chapterCsv"][self.chapterId].limitlevel |
304 | 326 | if params.relay or (not AdvCommon.isEndless(self.chapterId) and (self.level >= levellimit or not self.owner:advChapterIsOpen(self.chapterId, self.level + 1))) then --关卡结束 |
305 | 327 | self:over(true) |
... | ... | @@ -307,6 +329,7 @@ local function clickOut(self, room, block, params) |
307 | 329 | self:initByChapter(self.chapterId, self.level + 1, true, true) |
308 | 330 | self:backNext() --下一关 |
309 | 331 | end |
332 | + | |
310 | 333 | end |
311 | 334 | |
312 | 335 | return true |
... | ... | @@ -395,6 +418,7 @@ local function chooseCommon(self, room, block, chooseData, choose) |
395 | 418 | doEffect[effect[1]]() |
396 | 419 | end |
397 | 420 | self:checkTask(Adv.TaskType.Choose, 1, block.event.id) |
421 | + self:checkAchievement(Adv.AchievType.Choose, 1, block.event.id) | |
398 | 422 | return true, clearBlock |
399 | 423 | end |
400 | 424 | |
... | ... | @@ -421,6 +445,7 @@ local function clickLinkChoose(self, room, block, params) |
421 | 445 | if idx == 9 or not csvdb["event_linkchooseCsv"][block.event.id + 1] then --全部完成 |
422 | 446 | local startId = math.floor(block.event.id / 10) * 10 + 1 |
423 | 447 | self.lchoose[startId] = (self.lchoose[startId] or 0) + 1 |
448 | + self:checkAchievement(Adv.AchievType.LinkChoose, 1, startId) | |
424 | 449 | else |
425 | 450 | self.lchoose.ing = block.event.id + 1 --后面会出现后继事件 |
426 | 451 | end |
... | ... | @@ -428,7 +453,7 @@ local function clickLinkChoose(self, room, block, params) |
428 | 453 | if clearBlock then |
429 | 454 | block:clear() |
430 | 455 | end |
431 | - | |
456 | + | |
432 | 457 | return true |
433 | 458 | end |
434 | 459 | |
... | ... | @@ -454,6 +479,7 @@ local function clickTrader(self, room, block, params) |
454 | 479 | local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]}) |
455 | 480 | block.event.status = block.event.status:setv(buyId, 1) |
456 | 481 | self:checkTask(Adv.TaskType.Shop, 1, block.event.id) |
482 | + self:checkAchievement(Adv.AchievType.Shop, 1, block.event.id) | |
457 | 483 | self:backReward(reward) |
458 | 484 | return true |
459 | 485 | end |
... | ... | @@ -483,6 +509,7 @@ local function clickBuild(self, room, block, params) |
483 | 509 | if not self:cost(buildData.required:toNumMap(), {}) then return end |
484 | 510 | doEffect[effect[1]]() |
485 | 511 | self:checkTask(Adv.TaskType.Build, 1, block.event.id) |
512 | + self:checkAchievement(Adv.AchievType.Build, 1, block.event.id) | |
486 | 513 | if clearBlock then |
487 | 514 | block:clear() |
488 | 515 | end |
... | ... | @@ -526,6 +553,7 @@ local function clickLayer(self, room, block, params) |
526 | 553 | |
527 | 554 | self.maps[mapIdx] = AdvMap.new(self, mapIdx, mapId) |
528 | 555 | self.battle:initMapEnemys(mapIdx) |
556 | + self:checkAchievement(Adv.AchievType.EnterILayer, 1, mapId) | |
529 | 557 | end |
530 | 558 | self:backLayer() |
531 | 559 | return true |
... | ... | @@ -625,6 +653,8 @@ function Adv:useItem(itemId, count, target) |
625 | 653 | return |
626 | 654 | end |
627 | 655 | |
656 | + self:checkAchievement(Adv.AchievType.UseItem, count, itemId) | |
657 | + | |
628 | 658 | self:afterRound() |
629 | 659 | self:saveDB() |
630 | 660 | return true |
... | ... | @@ -715,6 +745,7 @@ function Adv:enemyDead(enemy, escape) |
715 | 745 | end |
716 | 746 | self:checkTask(Adv.TaskType.Kill, 1, enemyId) |
717 | 747 | self:checkTask(Adv.TaskType.KillAll) |
748 | + self:checkAchievement(Adv.AchievType.Kill, 1, enemyId) | |
718 | 749 | end |
719 | 750 | end |
720 | 751 | self:backBlockChange(roomId, blockId) | ... | ... |
src/adv/AdvBlock.lua
src/adv/AdvBuff.lua
... | ... | @@ -19,6 +19,7 @@ Buff.SP_CHANGE = 15 -- sp变化(每回合) |
19 | 19 | Buff.HP_CHANGE_NOW = 16 -- 生命变化(每回合生效,立刻生效) |
20 | 20 | Buff.BATTLE_BUFF = 17 -- 切换为战斗中的buff |
21 | 21 | Buff.CHANGE_DROP = 18 -- 转换掉落 |
22 | +Buff.BATTLE_PASSIVE = 19 -- 切换为战斗中的被动技 | |
22 | 23 | |
23 | 24 | --角色一些属性的变化 |
24 | 25 | local function commonAttr(_Buff, attrName) |
... | ... | @@ -58,7 +59,7 @@ local BuffFactory = { |
58 | 59 | if value > 0 then |
59 | 60 | self.owner:recover(value, self.release) |
60 | 61 | elseif value < 0 then |
61 | - self.owner:hurt(-value, self.release, {hurtType = 2}) | |
62 | + self.owner:hurt(-value, self.release, {hurtType = 2, buffId = self.id}) | |
62 | 63 | end |
63 | 64 | end |
64 | 65 | _Buff._effectValue = function(self) |
... | ... | @@ -85,7 +86,7 @@ local BuffFactory = { |
85 | 86 | if self._changeV > 0 then |
86 | 87 | self.owner:recover(self._changeV, self.release) -- 防止release不存在,地图点buff |
87 | 88 | elseif self._changeV < 0 then |
88 | - self.owner:hurt(self.release and self.release:getHurtValue(-self._changeV) or -self._changeV, self.release, {hurtType = 2}) | |
89 | + self.owner:hurt(self.release and self.release:getHurtValue(-self._changeV) or -self._changeV, self.release, {hurtType = 2, buffId = self.id}) | |
89 | 90 | self.owner.hp = math.min(self.owner.hpMax, self.owner.hp) |
90 | 91 | end |
91 | 92 | end |
... | ... | @@ -214,7 +215,7 @@ local BuffFactory = { |
214 | 215 | if value > 0 then |
215 | 216 | self.owner:recover(value, self.release) |
216 | 217 | elseif value < 0 then |
217 | - self.owner:hurt(-value, self.release, {hurtType = 2}) | |
218 | + self.owner:hurt(-value, self.release, {hurtType = 2, buffId = self.id}) | |
218 | 219 | end |
219 | 220 | end |
220 | 221 | _Buff._effectValue = function(self) |
... | ... | @@ -284,7 +285,7 @@ end |
284 | 285 | |
285 | 286 | |
286 | 287 | function Buff:afterRound() |
287 | - if self.isDel or self.owner.isDead or self.buffData.round == 0 then return end | |
288 | + if self.isDel or self.owner.isDead then return end | |
288 | 289 | if self.roundSpace > 0 then |
289 | 290 | self.roundSpace = self.roundSpace - 1 |
290 | 291 | self:decRound() | ... | ... |
src/adv/AdvPlayer.lua
... | ... | @@ -289,6 +289,10 @@ function BaseObject:hurt(value, releaser, params) |
289 | 289 | team:triggerPassive(Passive.TEAM_DEAD) |
290 | 290 | end |
291 | 291 | |
292 | + if params.hurtType == 2 and self ~= self.battle.player then | |
293 | + self.battle.adv:checkAchievement(self.battle.adv.AchievType.KillByBuff, 1, params.buffId) | |
294 | + end | |
295 | + | |
292 | 296 | self.isDead = true |
293 | 297 | self.battle.adv:backDead(self.id) |
294 | 298 | end |
... | ... | @@ -475,7 +479,7 @@ end |
475 | 479 | --战斗结束了扣战斗buff次数 |
476 | 480 | function Player:effectBattleBuff() |
477 | 481 | for _, buff in ipairs(self.buffs) do |
478 | - if not buff.isDel and buff:getType() == Buff.BATTLE_BUFF then | |
482 | + if not buff.isDel and (buff:getType() == Buff.BATTLE_BUFF or buff:getType() == Buff.BATTLE_PASSIVE) then | |
479 | 483 | buff:effect() |
480 | 484 | end |
481 | 485 | end | ... | ... |
src/adv/AdvTask.lua
... | ... | @@ -177,6 +177,99 @@ function AdvTask.bind(Adv) |
177 | 177 | end |
178 | 178 | advTaskChange = {} |
179 | 179 | end |
180 | + | |
181 | + | |
182 | + | |
183 | + ------ 冒险成就 ------------ | |
184 | + Adv.AchievType = { | |
185 | + StartBattle = 1, --累计挑战N次 | |
186 | + OverWin = 2, --通关N次M层 | |
187 | + TaskLayer = 3, --完成每层任务N次 | |
188 | + UseItem = 4, --使用道具N次 | |
189 | + GetItem = 5, --获得道具N个 | |
190 | + GetMWeapon = 6, --获得神器N个 -todo | |
191 | + Build = 7, --完成建筑N个 | |
192 | + Choose = 8, --完成事件N个 | |
193 | + Shop = 9, --完成商店N次 | |
194 | + LinkChoose = 10, --完成连锁事件N次 | |
195 | + Trap = 11, --触发陷阱N次 | |
196 | + Kill = 12, --消灭怪物N个 | |
197 | + EnterILayer = 13, --进入夹层N次 | |
198 | + KillByBuff = 14, --使用BUFF消灭敌人N个 | |
199 | + } | |
200 | + | |
201 | + | |
202 | + | |
203 | + local advAchievChange = {} | |
204 | + | |
205 | + local function insertChange(chapterId, taskId, value) | |
206 | + table.insert(advAchievChange, {type = "advAchiev", field = {chapterId, taskId}, value = value}) | |
207 | + end | |
208 | + | |
209 | + function Adv:checkAchievement(taskType, count, cond) | |
210 | + local advAchiev = self.owner:getProperty("advAchiev")[self.chapterId] or {} | |
211 | + for taskId , data in pairs(csvdb["adv_achievementCsv"][self.chapterId] or {}) do | |
212 | + local oldStatus = advAchiev[taskId] or 0 | |
213 | + if oldStatus ~= -1 and data.type == taskType then | |
214 | + local status | |
215 | + local checkTaskFunc = {} | |
216 | + -- checkTaskFunc[Adv.AchievType.] = function() | |
217 | + | |
218 | + -- end | |
219 | + if checkTaskFunc[taskType] then | |
220 | + status = checkTaskFunc[taskType]() | |
221 | + else | |
222 | + if count ~= 0 and (data.value2 == 0 or data.value2 == cond) then | |
223 | + status = oldStatus + count | |
224 | + end | |
225 | + end | |
226 | + if (status or -1) >= data.value1 then | |
227 | + status = -1 | |
228 | + end | |
229 | + if status ~= oldStatus then | |
230 | + insertChange(self.chapterId, taskId, status) | |
231 | + if status == -1 then | |
232 | + local ptcount = (self.owner:getProperty("advAchiev")[self.chapterId] or {})[-1] or 0 | |
233 | + ptcount = ptcount + data.pt | |
234 | + insertChange(self.chapterId, -1, ptcount) | |
235 | + end | |
236 | + end | |
237 | + | |
238 | + end | |
239 | + end | |
240 | + end | |
241 | + | |
242 | + -- --说不用领取 注释掉 | |
243 | + -- function Adv:finishAchievement(chapterId, taskId) | |
244 | + -- local achievData = (csvdb["adv_achievementCsv"][chapterId] or {})[taskId] | |
245 | + -- local status = (self.owner:getProperty("advAchiev")[chapterId] or {})[taskId] or -1 | |
246 | + | |
247 | + -- if status >= achievData.value1 then | |
248 | + -- insertChange(chapterId, taskId, -1) | |
249 | + -- local count = (self.owner:getProperty("advAchiev")[chapterId] or {})[-1] or 0 | |
250 | + -- count = count + achievData.pt | |
251 | + -- insertChange(chapterId, -1, count) | |
252 | + -- return true | |
253 | + -- end | |
254 | + -- end | |
255 | + | |
256 | + function Adv:getAchievementReward(chapterId, taskId) | |
257 | + local count = (self.owner:getProperty("advAchiev")[chapterId] or {})[-1] or 0 | |
258 | + local achievData = (csvdb["adv_achievement_rewardCsv"][chapterId] or {})[taskId] | |
259 | + local status = ((self.owner:getProperty("advAchiev")[chapterId] or {})["pts"] or {})[taskId] or 0 | |
260 | + if status == -1 or count < achievData.pt then return end | |
261 | + | |
262 | + local reward = self.owner:award(achievData.reward) | |
263 | + self.owner:changeUpdates({{type = "advAchiev", field = {chapterId, "pts", taskId}, value = -1}}, notNotify) | |
264 | + | |
265 | + return true, reward | |
266 | + end | |
267 | + | |
268 | + function Adv:updateAchievement(notNotify) | |
269 | + if not next(advAchievChange) then return end | |
270 | + self.owner:changeUpdates(advAchievChange, notNotify) | |
271 | + end | |
272 | + | |
180 | 273 | end |
181 | 274 | |
182 | 275 | ... | ... |
src/models/Role.lua
... | ... | @@ -51,8 +51,8 @@ Role.schema = { |
51 | 51 | advHang = {"table", {}}, -- 挂机信息 -- {chapterId = {format = teaminfo, time = endtime}} |
52 | 52 | advTask = {"table", {}}, -- 冒险已领取任务完成状态 {id = status} --每层重置 |
53 | 53 | advMTask = {"table", {id = 1, status = 0, lock = true}}, -- 冒险主线任务 -- {id = id, status = status, lock = true} -- 当前主线id 当前主线状态 是否锁定状态 |
54 | - advAchiev = {"table", {}}, -- 冒险成就 {chapterId = {achievId = status}} | |
55 | - advL = {"number", 1}, -- 冒险队等级 | |
54 | + advAchiev = {"table", {}}, -- 冒险成就 {chapterId = {achievId = status, -1 = pt, pts = {}}, } | |
55 | + advL = {"table", {0, 0}}, -- 冒险队等级 {lv, winCount} | |
56 | 56 | advElM = {"number", 0}, -- 无尽模式通关的最高层数 endless max layer |
57 | 57 | advElS = {"number", globalCsv.adv_endless_season}, -- 无尽模式记录的赛季 endless season |
58 | 58 | ... | ... |