Commit 4faef572d59a9a0dd795125987386e9c91b02ffc

Authored by zhouhaihai
1 parent 7104d350

冒险任务,冒险扫荡, 冒险中继

@@ -43,6 +43,13 @@ ItemType = { @@ -43,6 +43,13 @@ ItemType = {
43 LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具) 43 LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具)
44 TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具) 44 TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具)
45 AdvItem = 14, -- 冒险道具 45 AdvItem = 14, -- 冒险道具
  46 + FuncOpen = 15, -- 管理功能开放
  47 +}
  48 +
  49 +FuncOpenType = {
  50 + AdvEndless = 5919, -- 无尽模式
  51 + AdvRelay = 5920, -- 中继开放
  52 + AdvArtifact = 5921, -- 神器开放
46 } 53 }
47 54
48 -- 物品起始id 55 -- 物品起始id
src/ProtocolCode.lua
@@ -39,6 +39,7 @@ actionCodes = { @@ -39,6 +39,7 @@ actionCodes = {
39 Adv_endBattleRpc = 158, 39 Adv_endBattleRpc = 158,
40 Adv_endHangRpc = 159, 40 Adv_endHangRpc = 159,
41 Adv_buyAdvCountRpc = 160, 41 Adv_buyAdvCountRpc = 160,
  42 + Adv_finishTaskRpc = 161,
42 43
43 Hero_loadInfos = 201, 44 Hero_loadInfos = 201,
44 Hero_updateProperty = 202, 45 Hero_updateProperty = 202,
src/actions/AdvAction.lua
@@ -56,9 +56,9 @@ function _M.startAdvRpc( agent, data ) @@ -56,9 +56,9 @@ function _M.startAdvRpc( agent, data )
56 local layer = msg.layer or 1 --选择层数 56 local layer = msg.layer or 1 --选择层数
57 local format = msg.format --编队 57 local format = msg.format --编队
58 local chapterData = csvdb["adv_chapterCsv"][chapterId] 58 local chapterData = csvdb["adv_chapterCsv"][chapterId]
59 - if not chapterData then return end 59 + if not chapterData then return 1 end
60 60
61 - if role.dailyData:getProperty("advC") >= role:getAdvHangLimit() then return end -- 是否有体力 61 + if role.dailyData:getProperty("advC") >= role:getAdvHangLimit() then return 2 end -- 是否有体力
62 62
63 local oklayer = false --层是否合法 63 local oklayer = false --层是否合法
64 if layer ~= 1 then 64 if layer ~= 1 then
@@ -68,30 +68,32 @@ function _M.startAdvRpc( agent, data ) @@ -68,30 +68,32 @@ function _M.startAdvRpc( agent, data )
68 break 68 break
69 end 69 end
70 end 70 end
  71 + else
  72 + oklayer = true
71 end 73 end
72 74
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 75 + if not oklayer then return 3 end
  76 + if layer > chapterData.limitlevel then return 4 end
79 77
80 - if layer ~= 1 and (advPass[chapterId] or 0) < (layer - 1) then return end --中继 78 + -- 关卡开放判断
  79 + if not role:advChapterIsOpen(chapterId, layer) then return 5 end
81 80
82 - if not checkFormat(role, format) then return end 81 + --中继开放判断
  82 + if layer ~= 1 and (not role:isFuncOpen(FuncOpenType.AdvRelay) or (advPass[chapterId] or 0) < (layer - 1)) then return 6 end
  83 +
  84 + if not checkFormat(role, format) then return 7 end
83 85
84 --上一个关卡结束才可以开始新的关卡 86 --上一个关卡结束才可以开始新的关卡
85 - if next(role:getProperty("advInfo")) then return end 87 + if next(role:getProperty("advInfo")) then return 8 end
86 88
87 local advTeam = role:getProperty("advTeam") 89 local advTeam = role:getProperty("advTeam")
88 table.clear(advTeam) 90 table.clear(advTeam)
89 91
90 advTeam.heros = {} 92 advTeam.heros = {}
91 - for slot, heroId in pairs(msg.heros) do 93 + for slot, heroId in pairs(format.heros) do
92 advTeam.heros[slot] = heroId 94 advTeam.heros[slot] = heroId
93 end 95 end
94 - advTeam.leader = msg.leader 96 + advTeam.leader = format.leader
95 role:updateProperty({field = "advTeam", value = advTeam}) 97 role:updateProperty({field = "advTeam", value = advTeam})
96 role.dailyData:updateProperty({field = "advC", delta = 1}) 98 role.dailyData:updateProperty({field = "advC", delta = 1})
97 99
@@ -203,6 +205,23 @@ function _M.buyAdvCountRpc(agent , data) @@ -203,6 +205,23 @@ function _M.buyAdvCountRpc(agent , data)
203 return true 205 return true
204 end 206 end
205 207
  208 +function _M.finishTaskRpc(agent, data)
  209 + local role = agent.role
  210 + local msg = MsgPack.unpack(data)
  211 +
  212 + local adv = role:getAdvData()
  213 + local taskId = msg.taskId -- -1 则是主线任务
  214 + local status, reward
  215 + if taskId == -1 then
  216 + status, reward = adv:finishMTask()
  217 + else
  218 + status, reward = adv:finishTask(taskId)
  219 + end
  220 + if not status then return end
  221 + SendPacket(actionCodes.Adv_finishTaskRpc, MsgPack.pack({reward = reward}))
  222 + return true
  223 +end
  224 +
206 -- 点击地块(解锁)(触发事件) 225 -- 点击地块(解锁)(触发事件)
207 function _M.clickBlockRpc(agent, data) 226 function _M.clickBlockRpc(agent, data)
208 local role = agent.role 227 local role = agent.role
src/actions/GmAction.lua
@@ -163,12 +163,45 @@ end @@ -163,12 +163,45 @@ end
163 163
164 function _M.advc(role, pms) 164 function _M.advc(role, pms)
165 role:updateProperty({field = "advInfo", value = {}}) 165 role:updateProperty({field = "advInfo", value = {}})
  166 + role:updateProperty({field = "advTask", value = {}})
166 role:updateProperty({field = "advItems", value = ""}) 167 role:updateProperty({field = "advItems", value = ""})
167 role:updateProperty({field = "advTeam", value = {}}) 168 role:updateProperty({field = "advTeam", value = {}})
168 role.advData = nil 169 role.advData = nil
169 return "成功" 170 return "成功"
170 end 171 end
171 172
  173 +function _M.advf(role, pms)
  174 + role.dailyData:updateProperty({field = "advC", value = 0})
  175 + return "成功"
  176 +end
  177 +
  178 +function _M.adv(role, pms)
  179 + local chapterId = tonum(pms.pm1)
  180 + local layer = tonum(pms.pm2)
  181 +
  182 + local advData = csvdb["adv_chapterCsv"][chapterId]
  183 + if not advData then return end
  184 + layer = math.min(layer, advData.limitlevel)
  185 + local advPass = role:getProperty("advPass")
  186 + local addPre
  187 + addPre = function(chapterId)
  188 + local advData = csvdb["adv_chapterCsv"][chapterId]
  189 + for pre, l in ipairs(advData.prepose:toNumMap()) do
  190 + if (advPass[pre] or 0) < l then
  191 + advPass[pre] = l
  192 + addPre(pre)
  193 + end
  194 + end
  195 + end
  196 + if (advPass[chapterId] or 0) < layer then
  197 + advPass[chapterId] = layer
  198 + addPre(chapterId)
  199 + role:updateProperty({field = "advPass", value = advPass})
  200 + end
  201 +
  202 + return "成功"
  203 +end
  204 +
172 function _M.idlec(role, pms) 205 function _M.idlec(role, pms)
173 role:updateProperty({field = "hangTeam", value = {}}) 206 role:updateProperty({field = "hangTeam", value = {}})
174 role:updateProperty({field = "hangInfo", value = {}}) 207 role:updateProperty({field = "hangInfo", value = {}})
@@ -4,12 +4,20 @@ local AdvCommon = require &quot;adv.AdvCommon&quot; @@ -4,12 +4,20 @@ local AdvCommon = require &quot;adv.AdvCommon&quot;
4 local AdvMap = require "adv.AdvMap" 4 local AdvMap = require "adv.AdvMap"
5 5
6 local Adv = class("Adv") 6 local Adv = class("Adv")
  7 +local AdvTask = import(".AdvTask") --任务相关数据搞出去
  8 +AdvTask.bind(Adv)
  9 +
7 function Adv:ctor(owner) 10 function Adv:ctor(owner)
8 assert(owner, "Adv instance must have owner(role)") 11 assert(owner, "Adv instance must have owner(role)")
9 self.owner = owner 12 self.owner = owner
10 self.maps = {} 13 self.maps = {}
11 self.battle = nil 14 self.battle = nil
12 self.backEvents = {} --发给客户端的事件组 15 self.backEvents = {} --发给客户端的事件组
  16 +
  17 + self.advTask = self.owner:getProperty("advTask")
  18 + self.advMTask = self.owner:getProperty("advMTask")
  19 + self.advTaskChange = false -- 任务改变才更新
  20 +
13 self:initByInfo(self.owner:getProperty("advInfo")) 21 self:initByInfo(self.owner:getProperty("advInfo"))
14 end 22 end
15 23
@@ -19,6 +27,7 @@ function Adv:initByInfo(advInfo) @@ -19,6 +27,7 @@ function Adv:initByInfo(advInfo)
19 27
20 self.chapterId = advInfo.chapterId 28 self.chapterId = advInfo.chapterId
21 self.level = advInfo.level or 1 29 self.level = advInfo.level or 1
  30 + self.round = advInfo.round or 0
22 self.score = advInfo.score or {} 31 self.score = advInfo.score or {}
23 self.lastEnemyId = advInfo.lastEId or 1 32 self.lastEnemyId = advInfo.lastEId or 1
24 self.mapStack = advInfo.mstack or {} 33 self.mapStack = advInfo.mstack or {}
@@ -35,6 +44,7 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify) @@ -35,6 +44,7 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify)
35 if self.chapterId and chapterId ~= self.chapterId then return end --新的关卡 或者 去到下一层 44 if self.chapterId and chapterId ~= self.chapterId then return end --新的关卡 或者 去到下一层
36 self.chapterId = chapterId 45 self.chapterId = chapterId
37 self.level = level or 1 46 self.level = level or 1
  47 + self.round = 0
38 self.score = self.score or {} 48 self.score = self.score or {}
39 self.lastEnemyId = 1 49 self.lastEnemyId = 1
40 self.mapStack = {1} -- 最后一个为当前的地图 50 self.mapStack = {1} -- 最后一个为当前的地图
@@ -50,6 +60,9 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify) @@ -50,6 +60,9 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify)
50 60
51 self:initBattle() 61 self:initBattle()
52 62
  63 + self:initLayerTask()
  64 +
  65 + self:checkTask(Adv.TaskType.Arrive)
53 if not notNotify then 66 if not notNotify then
54 self:saveDB(notNotify) 67 self:saveDB(notNotify)
55 end 68 end
@@ -59,6 +72,7 @@ function Adv:clear() @@ -59,6 +72,7 @@ function Adv:clear()
59 self.chapterId = nil 72 self.chapterId = nil
60 self.level = nil 73 self.level = nil
61 self.score = {} 74 self.score = {}
  75 + self.round = 0
62 self.lastEnemyId = 1 76 self.lastEnemyId = 1
63 self.mapStack = {} 77 self.mapStack = {}
64 self.maps = {} 78 self.maps = {}
@@ -71,6 +85,7 @@ function Adv:saveDB(notNotify) @@ -71,6 +85,7 @@ function Adv:saveDB(notNotify)
71 85
72 advInfo.chapterId = self.chapterId 86 advInfo.chapterId = self.chapterId
73 advInfo.level = self.level 87 advInfo.level = self.level
  88 + advInfo.round = self.round
74 advInfo.score = self.score 89 advInfo.score = self.score
75 advInfo.lastEId = self.lastEnemyId 90 advInfo.lastEId = self.lastEnemyId
76 advInfo.mstack = self.mapStack 91 advInfo.mstack = self.mapStack
@@ -87,7 +102,8 @@ function Adv:saveDB(notNotify) @@ -87,7 +102,8 @@ function Adv:saveDB(notNotify)
87 else 102 else
88 advTeam.player = nil 103 advTeam.player = nil
89 end 104 end
90 - 105 +
  106 + self:updateTask(notNotify)
91 self.owner:updateProperties({advInfo = advInfo, advTeam = advTeam}, notNotify) 107 self.owner:updateProperties({advInfo = advInfo, advTeam = advTeam}, notNotify)
92 end 108 end
93 109
@@ -139,11 +155,6 @@ function Adv:over(success) @@ -139,11 +155,6 @@ function Adv:over(success)
139 local scoreInfo = self.score 155 local scoreInfo = self.score
140 local reward 156 local reward
141 if success then 157 if success then
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  
146 -  
147 reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) 158 reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap())
148 self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId}) 159 self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId})
149 end 160 end
@@ -209,6 +220,7 @@ function Adv:award(gift, params) @@ -209,6 +220,7 @@ function Adv:award(gift, params)
209 for itemId, count in pairs(tgift) do 220 for itemId, count in pairs(tgift) do
210 if count > 0 then 221 if count > 0 then
211 self:scoreChange(AdvScoreType.Item, {itemId, count}) 222 self:scoreChange(AdvScoreType.Item, {itemId, count})
  223 + self:checkTask(Adv.TaskType.Item, count, itemId)
212 end 224 end
213 local origin = items:getv(itemId, 0) 225 local origin = items:getv(itemId, 0)
214 local nums = origin + count 226 local nums = origin + count
@@ -255,7 +267,22 @@ local function clickOut(self, room, block, params) @@ -255,7 +267,22 @@ local function clickOut(self, room, block, params)
255 table.remove(self.mapStack) --退出夹层 267 table.remove(self.mapStack) --退出夹层
256 self:backLayer() 268 self:backLayer()
257 else --处于底层 269 else --处于底层
258 - if self.level >= csvdb["adv_chapterCsv"][self.chapterId].limitlevel then --关卡结束 270 +
  271 + local advPass = self.owner:getProperty("advPass")
  272 + if self.level > (advPass[self.chapterId] or 0) then
  273 + self.owner:changeUpdates({{type = "advPass", field = self.chapterId, value = self.level}})
  274 + end
  275 + if params.relay then
  276 + local ok = false
  277 + for _, exLayer in ipairs(globalCsv.adv_can_out_layer) do
  278 + if exLayer == self.level then
  279 + ok = true
  280 + break
  281 + end
  282 + end
  283 + if not ok then return end
  284 + end
  285 + if params.relay or self.level >= csvdb["adv_chapterCsv"][self.chapterId].limitlevel or not self.owner:advChapterIsOpen(self.chapterId, self.level + 1) then --关卡结束
259 self:over(true) 286 self:over(true)
260 else 287 else
261 self:initByChapter(self.chapterId, self.level + 1, true, true) 288 self:initByChapter(self.chapterId, self.level + 1, true, true)
@@ -340,6 +367,8 @@ local function clickChoose(self, room, block, params) @@ -340,6 +367,8 @@ local function clickChoose(self, room, block, params)
340 doEffect[effect[1]]() 367 doEffect[effect[1]]()
341 end 368 end
342 369
  370 + self:checkTask(Adv.TaskType.Choose, 1, block.event.id)
  371 +
343 if clearBlock then 372 if clearBlock then
344 block:clear() 373 block:clear()
345 end 374 end
@@ -367,6 +396,7 @@ local function clickTrader(self, room, block, params) @@ -367,6 +396,7 @@ local function clickTrader(self, room, block, params)
367 396
368 local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]}) 397 local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]})
369 block.event.status = block.event.status:setv(buyId, 1) 398 block.event.status = block.event.status:setv(buyId, 1)
  399 + self:checkTask(Adv.TaskType.Shop, 1, block.event.id)
370 self:backReward(reward) 400 self:backReward(reward)
371 return true 401 return true
372 end 402 end
@@ -395,6 +425,7 @@ local function clickBuild(self, room, block, params) @@ -395,6 +425,7 @@ local function clickBuild(self, room, block, params)
395 assert(doEffect[effect[1]], "error effect, event_buildingCsv id :" .. block.event.id) 425 assert(doEffect[effect[1]], "error effect, event_buildingCsv id :" .. block.event.id)
396 if not self:cost(buildData.required:toNumMap(), {}) then return end 426 if not self:cost(buildData.required:toNumMap(), {}) then return end
397 doEffect[effect[1]]() 427 doEffect[effect[1]]()
  428 + self:checkTask(Adv.TaskType.Build, 1, block.event.id)
398 if clearBlock then 429 if clearBlock then
399 block:clear() 430 block:clear()
400 end 431 end
@@ -443,6 +474,13 @@ local function clickLayer(self, room, block, params) @@ -443,6 +474,13 @@ local function clickLayer(self, room, block, params)
443 return true 474 return true
444 end 475 end
445 476
  477 +local function clickTask(self, room, block, params)
  478 + if self:addTask(block.event.id) then --增加任务
  479 + block:clear()
  480 + return true
  481 + end
  482 +end
  483 +
446 local eventCallFunc = { 484 local eventCallFunc = {
447 [AdvEventType.Out] = clickOut, 485 [AdvEventType.Out] = clickOut,
448 [AdvEventType.BOSS] = clickMonster, 486 [AdvEventType.BOSS] = clickMonster,
@@ -453,6 +491,7 @@ local eventCallFunc = { @@ -453,6 +491,7 @@ local eventCallFunc = {
453 [AdvEventType.Build] = clickBuild, 491 [AdvEventType.Build] = clickBuild,
454 [AdvEventType.Click] = clickClick, 492 [AdvEventType.Click] = clickClick,
455 [AdvEventType.Layer] = clickLayer, 493 [AdvEventType.Layer] = clickLayer,
  494 + [AdvEventType.Task] = clickTask,
456 } 495 }
457 496
458 --点击处理 roomId, blockId 497 --点击处理 roomId, blockId
@@ -567,7 +606,9 @@ function Adv:enemyDead(roomId, blockId, escape) @@ -567,7 +606,9 @@ function Adv:enemyDead(roomId, blockId, escape)
567 if escape then 606 if escape then
568 block:clear() 607 block:clear()
569 else 608 else
570 - local monsterData = csvdb["event_monsterCsv"][block.event.id] 609 +
  610 + local enemyId = block.event.id
  611 + local monsterData = csvdb["event_monsterCsv"][enemyId]
571 self:scoreChange(AdvScoreType.Kill, monsterData.type) 612 self:scoreChange(AdvScoreType.Kill, monsterData.type)
572 613
573 local item = block.event.item 614 local item = block.event.item
@@ -575,6 +616,7 @@ function Adv:enemyDead(roomId, blockId, escape) @@ -575,6 +616,7 @@ function Adv:enemyDead(roomId, blockId, escape)
575 local dropData = csvdb["event_dropCsv"][monsterData.dropid] 616 local dropData = csvdb["event_dropCsv"][monsterData.dropid]
576 item = dropData["range"]:randWeight(true) 617 item = dropData["range"]:randWeight(true)
577 end 618 end
  619 +
578 if item[1] == 0 then 620 if item[1] == 0 then
579 block:clear() 621 block:clear()
580 else 622 else
@@ -583,6 +625,8 @@ function Adv:enemyDead(roomId, blockId, escape) @@ -583,6 +625,8 @@ function Adv:enemyDead(roomId, blockId, escape)
583 item = item 625 item = item
584 }) 626 })
585 end 627 end
  628 + self:checkTask(Adv.TaskType.Kill, 1, enemyId)
  629 + self:checkTask(Adv.TaskType.KillAll)
586 end 630 end
587 end 631 end
588 self:backBlockChange(roomId, blockId) 632 self:backBlockChange(roomId, blockId)
@@ -665,7 +709,7 @@ function Adv:scoreChange(scoreType, pms) @@ -665,7 +709,7 @@ function Adv:scoreChange(scoreType, pms)
665 end 709 end
666 cutTypes[AdvScoreType.Kill] = function() 710 cutTypes[AdvScoreType.Kill] = function()
667 local chapterData = csvdb["adv_chapterCsv"][self.chapterId] 711 local chapterData = csvdb["adv_chapterCsv"][self.chapterId]
668 - score = globalCsv.adv_score_monster[pms] * chapterData["monRatio"] 712 + score = globalCsv.adv_score_monster[pms] * chapterData["reward"]
669 end 713 end
670 cutTypes[AdvScoreType.Item] = function() 714 cutTypes[AdvScoreType.Item] = function()
671 score = csvdb["itemCsv"][pms[1]].adv_score_item * pms[2] 715 score = csvdb["itemCsv"][pms[1]].adv_score_item * pms[2]
@@ -704,6 +748,7 @@ end @@ -704,6 +748,7 @@ end
704 748
705 --回合事件处理 749 --回合事件处理
706 function Adv:afterRound() 750 function Adv:afterRound()
  751 + self.round = self.round + 1
707 if self.battle then 752 if self.battle then
708 self.battle:afterRound() 753 self.battle:afterRound()
709 end 754 end
src/adv/AdvBattle.lua
@@ -176,9 +176,9 @@ function Battle:afterRound() @@ -176,9 +176,9 @@ function Battle:afterRound()
176 end 176 end
177 for i = #self.enemys[mapIdx], 1, -1 do 177 for i = #self.enemys[mapIdx], 1, -1 do
178 if self.enemys[mapIdx][i].isDead then 178 if self.enemys[mapIdx][i].isDead then
179 - self.adv:enemyDead(self.enemys[mapIdx][i].roomId, self.enemys[mapIdx][i].blockId)  
180 self.enemys[mapIdx][i]:clear() 179 self.enemys[mapIdx][i]:clear()
181 - table.remove(self.enemys[mapIdx], i) 180 + local enemy = table.remove(self.enemys[mapIdx], i)
  181 + self.adv:enemyDead(enemy.roomId, enemy.blockId)
182 end 182 end
183 end 183 end
184 184
src/adv/AdvMap.lua
@@ -11,7 +11,7 @@ local createMap, getEventLib @@ -11,7 +11,7 @@ local createMap, getEventLib
11 function Map:ctor(adv, mapIdx, mapInfo) 11 function Map:ctor(adv, mapIdx, mapInfo)
12 self.adv = adv 12 self.adv = adv
13 if type(mapInfo) == "number" then -- mapInfo 传入 id 13 if type(mapInfo) == "number" then -- mapInfo 传入 id
14 - mapInfo = createMap(mapInfo, self.adv.chapterId, self.adv.level) -- 生成地图 14 + mapInfo = createMap(self, mapInfo) -- 生成地图
15 end 15 end
16 if not mapInfo then return end 16 if not mapInfo then return end
17 17
@@ -78,7 +78,7 @@ function Map:addNewMonsterRand(monsterId, where) @@ -78,7 +78,7 @@ function Map:addNewMonsterRand(monsterId, where)
78 end 78 end
79 79
80 if not monsterId then 80 if not monsterId then
81 - local eventLib = getEventLib(self.adv.chapterId, self.adv.level, AdvEventType.Monster) 81 + local eventLib = getEventLib(self, AdvEventType.Monster)
82 if not next(eventLib[AdvEventType.Monster][0]) then return false end 82 if not next(eventLib[AdvEventType.Monster][0]) then return false end
83 monsterId = math.randWeight(eventLib[AdvEventType.Monster][0], "showup") 83 monsterId = math.randWeight(eventLib[AdvEventType.Monster][0], "showup")
84 end 84 end
@@ -161,7 +161,7 @@ end @@ -161,7 +161,7 @@ end
161 161
162 -----------------------------随机地图----------------------------- 162 -----------------------------随机地图-----------------------------
163 163
164 -createMap = function(mapId, chapterId, level) 164 +createMap = function(self, mapId)
165 local mapInfo = {} 165 local mapInfo = {}
166 mapInfo.rooms = {} 166 mapInfo.rooms = {}
167 mapInfo.mapId = mapId 167 mapInfo.mapId = mapId
@@ -172,7 +172,7 @@ createMap = function(mapId, chapterId, level) @@ -172,7 +172,7 @@ createMap = function(mapId, chapterId, level)
172 return 172 return
173 end 173 end
174 --事件随机 174 --事件随机
175 - local eventLib = getEventLib(chapterId, level) -- 同时记录出现次数 175 + local eventLib = getEventLib(self) -- 同时记录出现次数
176 local monsterEvents = {} --处理钥匙掉落 176 local monsterEvents = {} --处理钥匙掉落
177 local haveBoss = false 177 local haveBoss = false
178 178
@@ -332,7 +332,8 @@ createMap = function(mapId, chapterId, level) @@ -332,7 +332,8 @@ createMap = function(mapId, chapterId, level)
332 end 332 end
333 333
334 --关卡事件库 334 --关卡事件库
335 -getEventLib = function(chapterId, level, needEventType) -- needEventType 需要的事件 335 +getEventLib = function(self, needEventType) -- needEventType 需要的事件
  336 + local chapterId, level = self.adv.chapterId, self.adv.level
336 local chapter = math.floor(chapterId / 100) % 100 337 local chapter = math.floor(chapterId / 100) % 100
337 338
338 local libsToType = { 339 local libsToType = {
@@ -347,6 +348,9 @@ getEventLib = function(chapterId, level, needEventType) -- needEventType 需要 @@ -347,6 +348,9 @@ getEventLib = function(chapterId, level, needEventType) -- needEventType 需要
347 348
348 } 349 }
349 local eventLib = {} 350 local eventLib = {}
  351 +
  352 + local advEventOpenStatus = self.adv.owner:advEventOpenStatus()
  353 +
350 for lib, eventType in pairs(libsToType) do 354 for lib, eventType in pairs(libsToType) do
351 -- init eventLib 355 -- init eventLib
352 if type(eventType) == "table" then 356 if type(eventType) == "table" then
@@ -359,15 +363,12 @@ getEventLib = function(chapterId, level, needEventType) -- needEventType 需要 @@ -359,15 +363,12 @@ getEventLib = function(chapterId, level, needEventType) -- needEventType 需要
359 -- needEventType 只获取这个事件类型 363 -- needEventType 只获取这个事件类型
360 if not needEventType or eventLib[needEventType] then 364 if not needEventType or eventLib[needEventType] then
361 for id, data in pairs(csvdb[lib]) do 365 for id, data in pairs(csvdb[lib]) do
362 - if data.levelchapter == chapter then 366 + local etype = type(eventType) == "table" and eventType[data.type] or eventType
  367 +
  368 + if data.levelchapter == chapter and (data.unlockType == 0 or (advEventOpenStatus[etype] or {})[data.unlockType]) then
363 if AdvCommon.checkIsIn(level, data.leveltype, data.levellimit) then 369 if AdvCommon.checkIsIn(level, data.leveltype, data.levellimit) then
364 - if type(eventType) == "table" then  
365 - eventLib[eventType[data.type]][data.BlockEventType] = eventLib[eventType[data.type]][data.BlockEventType] or {}  
366 - eventLib[eventType[data.type]][data.BlockEventType][id] = {showup = data.showup, limit = data.limit}  
367 - else  
368 - eventLib[eventType][data.BlockEventType] = eventLib[eventType][data.BlockEventType] or {}  
369 - eventLib[eventType][data.BlockEventType][id] = {showup = data.showup, limit = data.limit}  
370 - end 370 + eventLib[etype][data.BlockEventType] = eventLib[etype][data.BlockEventType] or {}
  371 + eventLib[etype][data.BlockEventType][id] = {showup = data.showup, limit = data.limit}
371 end 372 end
372 end 373 end
373 end 374 end
src/adv/AdvTask.lua 0 → 100644
@@ -0,0 +1,176 @@ @@ -0,0 +1,176 @@
  1 +local AdvTask = {}
  2 +
  3 +
  4 +function AdvTask.bind(Adv)
  5 + Adv.TaskType = {
  6 + Arrive = 1, --到达N层
  7 + Kill = 2, --消灭指定怪物N个
  8 + Item = 3, --获得指定道具N个
  9 + Choose = 4, --完成指定抉择点N次
  10 + Shop = 5, --和指定商人交易N次
  11 + Build = 6, --和指定建筑交互N次
  12 + KillAll = 7, --消灭本层所有怪物
  13 + }
  14 +
  15 + -- 检查任务状态 在新领取任务的时候回进行检查
  16 + local function checkTaskStatus(self, taskData, status, count, cond)
  17 + count = count or 0
  18 + if status == -1 or not taskData then
  19 + return
  20 + end
  21 + local function checkCondValue()
  22 + if taskData.value2 ~= "" then
  23 + local conds = taskData.value2:toArray(true, "=")
  24 + for _, one in pairs(conds) do
  25 + if one == cond then
  26 + return true
  27 + end
  28 + end
  29 + end
  30 + return true
  31 + end
  32 +
  33 + local checkTaskFunc = {}
  34 + checkTaskFunc[Adv.TaskType.Arrive] = function()
  35 + if self.level > status then
  36 + if self.level >= taskData.value1 then
  37 + return -1
  38 + else
  39 + return self.level
  40 + end
  41 + end
  42 + end
  43 + checkTaskFunc[Adv.TaskType.KillAll] = function()
  44 + if #self.battle.player:getTeam(2) == 0 then
  45 + return -1
  46 + end
  47 + end
  48 +
  49 + if checkTaskFunc[taskData.condition] then
  50 + status = checkTaskFunc[taskData.condition]()
  51 + else
  52 + if count == 0 or not checkCondValue() then return end --没有变化
  53 + status = status + count
  54 + if status >= taskData.value1 then
  55 + status = -1
  56 + end
  57 + end
  58 + return status
  59 + end
  60 +
  61 + function Adv:initLayerTask()
  62 + self.advTask = {}
  63 + if not next(self.advMTask) then
  64 + self.advMTask = {
  65 + id = 1,
  66 + status = 0,
  67 + lock = 1,
  68 + }
  69 + self.advTaskChange = true
  70 + end
  71 + self.advMTask.id = self.advMTask.id or 1
  72 + local mainTaskData = csvdb["adv_questCsv"][self.advMTask.id]
  73 + if mainTaskData and self.advMTask.lock then
  74 + if math.floor(self.chapterId / 100) % 100 == mainTaskData.chapter and self.level >= mainTaskData.level then --到达指定关卡解锁当前任务
  75 + self.advMTask.lock = nil
  76 + self.advMTask.status = 0
  77 + local ts = checkTaskStatus(self, mainTaskData, self.advMTask.status, 0)
  78 + if ts then
  79 + self.advMTask.status = ts
  80 + end
  81 + self.advTaskChange = true
  82 + end
  83 + end
  84 + end
  85 +
  86 + function Adv:checkTask(taskType, count, cond)
  87 + local chapter = math.floor(self.chapterId / 100) % 100
  88 + for taskId, status in pairs(self.advTask) do
  89 + local taskData = csvdb["event_questCsv"][taskId]
  90 + if taskData and taskData.levelchapter == chapter and taskType == taskData.condition then
  91 + local ts = checkTaskStatus(self, taskData, status, count, cond)
  92 + if ts then
  93 + self.advTask[taskId] = ts
  94 + self.advTaskChange = true
  95 + end
  96 + end
  97 + end
  98 +
  99 + local mainTaskData = csvdb["adv_questCsv"][self.advMTask.id]
  100 + if not self.advMTask.lock and mainTaskData and mainTaskData.chapter == chapter and taskType == mainTaskData.condition then
  101 + local ts = checkTaskStatus(self, mainTaskData, self.advMTask.status, count, cond)
  102 + if ts then
  103 + self.advMTask.status = ts
  104 + self.advTaskChange = true
  105 + end
  106 + end
  107 + end
  108 +
  109 + -- 点击任务地块领取任务
  110 + function Adv:addTask(taskId)
  111 + local taskData = csvdb["event_questCsv"][taskId]
  112 + if taskData then
  113 + self.advTask[taskId] = 0
  114 + local ts = checkTaskStatus(self, taskData, self.advTask[taskId], 0)
  115 + if ts then
  116 + self.advTask[taskId] = ts
  117 + end
  118 +
  119 + self.advTaskChange = true
  120 + return true
  121 + end
  122 + end
  123 +
  124 + --完成层任务
  125 + function Adv:finishTask(taskId)
  126 + local ok, reward
  127 + if self.advTask[taskId] and self.advTask[taskId] == -1 then
  128 + local taskData = csvdb["event_questCsv"][taskId]
  129 + if not taskData then return end
  130 + if taskData.reward == 1 then
  131 + reward = self.owner:award(taskData.rewardValue)
  132 + end
  133 + self.advTask[taskId] = nil
  134 + self.owner:updateProperty({field = "advTask", value = self.advTask})
  135 + ok = true
  136 + end
  137 + return ok, reward
  138 + end
  139 +
  140 + -- 完成主线任务
  141 + function Adv:finishMTask()
  142 + local ok, reward
  143 + if self.advMTask.status == -1 then --已完成带领取
  144 + local mainTaskData = csvdb["adv_questCsv"][self.advMTask.id]
  145 + if not mainTaskData then return end
  146 + if mainTaskData.reward == 1 then
  147 + reward = self.owner:award(mainTaskData.rewardValue)
  148 + end
  149 + self.advMTask.id = self.advMTask.id + 1
  150 + self.advMTask.status = 0
  151 + local nextTaskData = csvdb["adv_questCsv"][self.advMTask.id]
  152 + if not nextTaskData or math.floor(self.chapterId / 100) % 100 ~= nextTaskData.chapter or self.level < nextTaskData.level then
  153 + self.advMTask.lock = true
  154 + else
  155 + local ts = checkTaskStatus(self, nextTaskData, self.advMTask.status, 0)
  156 + if ts then
  157 + self.advMTask.status = ts
  158 + end
  159 + end
  160 +
  161 + self.owner:updateProperty({field = "advMTask", value = self.advMTask})
  162 + ok = true
  163 + end
  164 + return ok, reward
  165 + end
  166 +
  167 + function Adv:updateTask(notNotify)
  168 + if self.advTaskChange then
  169 + self.owner:updateProperties({advTask = self.advTask, advMTask = self.advMTask}, notNotify)
  170 + end
  171 + self.advTaskChange = false
  172 + end
  173 +end
  174 +
  175 +
  176 +return AdvTask
0 \ No newline at end of file 177 \ No newline at end of file
src/models/Daily.lua
@@ -18,7 +18,7 @@ function Daily:updateProperty(params) @@ -18,7 +18,7 @@ function Daily:updateProperty(params)
18 local type, default = table.unpack(self.schema[params.field]) 18 local type, default = table.unpack(self.schema[params.field])
19 19
20 if params.delta then 20 if params.delta then
21 - self:setProperty(params.field, self:getProperty(paramsfield) + params.delta) 21 + self:incrProperty(params.field, params.delta)
22 self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) 22 self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
23 return true 23 return true
24 end 24 end
src/models/Role.lua
@@ -36,6 +36,7 @@ Role.schema = { @@ -36,6 +36,7 @@ Role.schema = {
36 level = {"number", 1}, 36 level = {"number", 1},
37 exp = {"number", 0}, 37 exp = {"number", 0},
38 items = {"string", ""}, 38 items = {"string", ""},
  39 + funcOpen = {"table", {}}, --功能是否开放
39 loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL 40 loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL
40 crown = {"number", 0}, -- 看伴娘 41 crown = {"number", 0}, -- 看伴娘
41 42
@@ -47,8 +48,8 @@ Role.schema = { @@ -47,8 +48,8 @@ Role.schema = {
47 advInfo = {"table", {}}, -- 冒险关卡信息 48 advInfo = {"table", {}}, -- 冒险关卡信息
48 advTeam = {"table", {}}, -- 冒险玩家队伍信息 49 advTeam = {"table", {}}, -- 冒险玩家队伍信息
49 advHang = {"table", {}}, -- 挂机信息 -- {chapterId = {format = teaminfo, time = endtime}} 50 advHang = {"table", {}}, -- 挂机信息 -- {chapterId = {format = teaminfo, time = endtime}}
50 - advTask = {"table", {l = {}, m = {}}}, -- 冒险已领取任务完成状态 -- l 层级任务, m 主线任务 {id = status}  
51 - advMTask = {"table", {}}, -- 冒险主线已经完成的任务[数组] --为了节省空间 服务器使用 51 + advTask = {"table", {}}, -- 冒险已领取任务完成状态 {id = status} --每层重置
  52 + advMTask = {"table", {id = 1, status = 0, lock = true}}, -- 冒险主线任务 -- {id = id, status = status, lock = true} -- 当前主线id 当前主线状态 是否锁定状态
52 advAchiev = {"table", {}}, -- 冒险成就 {chapterId = {achievId = status}} 53 advAchiev = {"table", {}}, -- 冒险成就 {chapterId = {achievId = status}}
53 --挂机相关 54 --挂机相关
54 hangPass = {"table", {}}, -- 挂机通过的最大关卡 55 hangPass = {"table", {}}, -- 挂机通过的最大关卡
@@ -173,6 +174,7 @@ function Role:data() @@ -173,6 +174,7 @@ function Role:data()
173 level = self:getProperty("level"), 174 level = self:getProperty("level"),
174 exp = self:getProperty("exp"), 175 exp = self:getProperty("exp"),
175 items = self:getProperty("items"):toNumMap(), 176 items = self:getProperty("items"):toNumMap(),
  177 + funcOpen = self:getProperty("funcOpen"),
176 loveStatus = self:getProperty("loveStatus"):toNumMap(), 178 loveStatus = self:getProperty("loveStatus"):toNumMap(),
177 diamond = self:getAllDiamond(), 179 diamond = self:getAllDiamond(),
178 bagLimit = self:getProperty("bagLimit"), 180 bagLimit = self:getProperty("bagLimit"),
src/models/RolePlugin.lua
@@ -96,6 +96,9 @@ function RolePlugin.bind(Role) @@ -96,6 +96,9 @@ function RolePlugin.bind(Role)
96 [ItemType.AdvItem] = function() --冒险道具不会进入 玩家仓库 96 [ItemType.AdvItem] = function() --冒险道具不会进入 玩家仓库
97 count = 0 97 count = 0
98 end, 98 end,
  99 + [ItemType.FuncOpen] = function()
  100 + self:funcOpen(itemId)
  101 + end,
99 } 102 }
100 -- 对数量筛查 103 -- 对数量筛查
101 count = checkItemCount(self, itemId, count) 104 count = checkItemCount(self, itemId, count)
@@ -585,6 +588,55 @@ function RolePlugin.bind(Role) @@ -585,6 +588,55 @@ function RolePlugin.bind(Role)
585 -- todo 588 -- todo
586 return globalCsv.adv_daily_cross_count 589 return globalCsv.adv_daily_cross_count
587 end 590 end
  591 +
  592 + function Role:isFuncOpen(func)
  593 + return self:getProperty("funcOpen")[func] == 1
  594 + end
  595 +
  596 + function Role:funcOpen(func)
  597 + if csvdb["itemCsv"][func] and csvdb["itemCsv"][func].type == ItemType.FuncOpen then
  598 + self:changeUpdates({{type = "funcOpen", field = func, value = 1}})
  599 + end
  600 + end
  601 +
  602 + function Role:funcClose(func)
  603 + if csvdb["itemCsv"][func] and csvdb["itemCsv"][func].type == ItemType.FuncOpen then
  604 + self:changeUpdates({{type = "funcOpen", field = func, value = nil}})
  605 + end
  606 + end
  607 +
  608 + function Role:advChapterIsOpen(chapterId, layer)
  609 + local chapter = math.floor(chapterId / 100) % 100
  610 + local exlayer = math.floor((layer - 1) / 10) * 10 + 1
  611 +
  612 + if exlayer == 1 then --第一层判断前置
  613 + local advPass = self:getProperty("advPass")
  614 + local chapterData = csvdb["adv_chapterCsv"][chapterId]
  615 + for id, l in pairs(chapterData.prepose:toNumMap()) do
  616 + if (advPass[id] or 0) < l then return false end -- 前置
  617 + end
  618 + return true
  619 + end
  620 +
  621 + local unlock = {}
  622 + for func , data in pairs(csvdb["unlockCsv"]) do
  623 + if data.type == 1 and chapter == data.value1 and exlayer == data.value2 then
  624 + return self:isFuncOpen(func)
  625 + end
  626 + end
  627 + end
  628 +
  629 + function Role:advEventOpenStatus()
  630 + local openStatus = {}
  631 + for func , data in pairs(csvdb["unlockCsv"]) do
  632 + if data.type == 5 then
  633 + openStatus[data.value1] = openStatus[data.value1] or {}
  634 + openStatus[data.value1][data.value2] = self:isFuncOpen(func)
  635 + end
  636 + end
  637 + return openStatus
  638 + end
  639 +
588 end 640 end
589 641
590 return RolePlugin 642 return RolePlugin
591 \ No newline at end of file 643 \ No newline at end of file