Commit 00e663bd7beb6b8e7ff702c95b7a35178cd36f15
1 parent
0a0267a8
剧情相关
Showing
7 changed files
with
176 additions
and
10 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/HangAction.lua
| ... | ... | @@ -180,6 +180,8 @@ function _M.endBattleRpc(agent, data) |
| 180 | 180 | reward[itemId] = count |
| 181 | 181 | end |
| 182 | 182 | reward = role:award(reward) |
| 183 | + | |
| 184 | + role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId}) | |
| 183 | 185 | end |
| 184 | 186 | hangInfo.key = nil |
| 185 | 187 | role:updateProperty({field = "hangInfo", value = hangInfo}) | ... | ... |
src/actions/HeroAction.lua
| ... | ... | @@ -69,7 +69,7 @@ function _M.wakeRpc(agent, data) |
| 69 | 69 | local skills = {} |
| 70 | 70 | for _,v in pairs(wakeData.skill:toArray(true,"=") ) do |
| 71 | 71 | local skillSet = hero:getSkillData(v) |
| 72 | - if next(skillSet) then | |
| 72 | + if skillSet and next(skillSet) then | |
| 73 | 73 | local skillLv = hero:getSkillLevel(v)+1 |
| 74 | 74 | local skillData = skillSet[skillLv] |
| 75 | 75 | if skillData and next(skillData) then |
| ... | ... | @@ -86,6 +86,8 @@ function _M.wakeRpc(agent, data) |
| 86 | 86 | end |
| 87 | 87 | hero:updateProperty({field = "wakeL", delta = 1}) |
| 88 | 88 | |
| 89 | + role:checkTaskEnter(role.TaskType.Wake, {heroType = typ, wakeL = hero:getProperty("wakeL")}) | |
| 90 | + | |
| 89 | 91 | SendPacket(actionCodes.Hero_wakeRpc, '') |
| 90 | 92 | return true |
| 91 | 93 | end |
| ... | ... | @@ -368,7 +370,8 @@ function _M.loveItemRpc(agent, data) |
| 368 | 370 | end |
| 369 | 371 | local curL = hero:getProperty("loveL") |
| 370 | 372 | local curExp = hero:getProperty("loveExp") |
| 371 | - local curPlus = csvdb["unit_love_plusCsv"][hero:getProperty("type")] | |
| 373 | + local curType = hero:getProperty("type") | |
| 374 | + local curPlus = csvdb["unit_love_plusCsv"][curType] | |
| 372 | 375 | if not curPlus then |
| 373 | 376 | return |
| 374 | 377 | end |
| ... | ... | @@ -392,8 +395,16 @@ function _M.loveItemRpc(agent, data) |
| 392 | 395 | return true |
| 393 | 396 | end |
| 394 | 397 | role:costItems({[cost[1]] = cost[2]}) |
| 395 | - hero:updateProperty({field = "loveL", value = curL + 1}) | |
| 398 | + local newLevel = curL + 1 | |
| 399 | + hero:updateProperty({field = "loveL", value = newLevel}) | |
| 396 | 400 | hero:updateProperty({field = "loveExp", value = 0}) |
| 401 | + | |
| 402 | + if role:getProperty("loveStatus"):getv(curType, 0) < newLevel then | |
| 403 | + role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的 | |
| 404 | + end | |
| 405 | + | |
| 406 | + role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel}) | |
| 407 | + | |
| 397 | 408 | else |
| 398 | 409 | local delta = globalCsv.unit_love_presentValue[msg.itemId] |
| 399 | 410 | if not delta then |
| ... | ... | @@ -438,13 +449,16 @@ function _M.loveTaskRpc(agent, data) |
| 438 | 449 | else |
| 439 | 450 | newExp = 0 |
| 440 | 451 | end |
| 452 | + local newLevel = curL + 1 | |
| 441 | 453 | hero:updateProperty({field = "loveExp", value = newExp}) |
| 442 | - hero:updateProperty({field = "loveL", value = curL + 1}) | |
| 454 | + hero:updateProperty({field = "loveL", value = newLevel}) | |
| 443 | 455 | |
| 444 | - if role:getProperty("loveStatus"):getv(curType, 0) < curL + 1 then | |
| 445 | - role:changeUpdates({{type = "loveStatus", field = curType, value = curL + 1}}) -- 总的 | |
| 456 | + if role:getProperty("loveStatus"):getv(curType, 0) < newLevel then | |
| 457 | + role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的 | |
| 446 | 458 | end |
| 447 | 459 | |
| 460 | + role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel}) | |
| 461 | + | |
| 448 | 462 | SendPacket(actionCodes.Hero_loveTaskRpc, "") |
| 449 | 463 | return true |
| 450 | 464 | end | ... | ... |
src/actions/RoleAction.lua
| ... | ... | @@ -313,5 +313,23 @@ function _M.openItemRpc(agent, data) |
| 313 | 313 | return true |
| 314 | 314 | end |
| 315 | 315 | |
| 316 | +function _M.storyBookRewardRpc(agent, data) | |
| 317 | + local role = agent.role | |
| 318 | + local msg = MsgPack.unpack(data) | |
| 319 | + local storyId = msg.id | |
| 320 | + local storyBookData = csvdb["story_bookCsv"][storyId] | |
| 321 | + if not storyBookData then return end | |
| 322 | + local storyStatus = self:getProperty("storyB") | |
| 323 | + if not storyStatus[id] or not storyStatus[id].s or storyStatus[id].s ~= 1 then return end | |
| 324 | + | |
| 325 | + -- 获取奖励 | |
| 326 | + storyStatus[id].s = -1 | |
| 327 | + self:setProperty("storyB", storyBookStatus) -- 统一写入数据库 | |
| 328 | + self:changeUpdates({{ type = "storyB", field = id, value = storyStatus[id] }}) | |
| 329 | + local reward = role:award(storyBookData.gift) | |
| 330 | + SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack({reward = reward})) | |
| 331 | + return true | |
| 332 | +end | |
| 333 | + | |
| 316 | 334 | |
| 317 | 335 | return _M |
| 318 | 336 | \ No newline at end of file | ... | ... |
src/adv/Adv.lua
| ... | ... | @@ -460,6 +460,8 @@ function Adv:over(success) |
| 460 | 460 | if success then |
| 461 | 461 | self.owner:updateProperty({field = "advPass", self.owner:getProperty("advPass"):setv(self.advInfo.chapter, score)}) |
| 462 | 462 | reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) |
| 463 | + | |
| 464 | + self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.advInfo.chapter}) | |
| 463 | 465 | end |
| 464 | 466 | table.clear(self.advInfo) --清空advInfo |
| 465 | 467 | self.advTeam.player = nil --重置玩家的数据 | ... | ... |
src/models/Role.lua
| ... | ... | @@ -55,6 +55,8 @@ Role.schema = { |
| 55 | 55 | hangBagLimit = {"number", globalCsv.idle_field_origin}, --背包上限 |
| 56 | 56 | |
| 57 | 57 | potionBag = {"table", {}}, -- 营养剂背包 |
| 58 | + | |
| 59 | + storyB = {"table", {}}, -- 剧情记录 | |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | |
| ... | ... | @@ -133,12 +135,18 @@ function Role:changeUpdates(params, notNotify) |
| 133 | 135 | self:setProperty(fieldType) |
| 134 | 136 | return {type = fieldType, field = info["field"], value = info["value"]} |
| 135 | 137 | end, |
| 138 | + ["onlyToC"] = function(info) | |
| 139 | + return info | |
| 140 | + end, | |
| 136 | 141 | } |
| 137 | 142 | |
| 138 | 143 | local updates = {} |
| 139 | 144 | for _, one in ipairs(params) do |
| 140 | 145 | if changeUpdateFunc[one["type"]] then |
| 141 | 146 | table.insert(updates, changeUpdateFunc[one["type"]](one)) |
| 147 | + elseif one.isOnlyToC then | |
| 148 | + one.isOnlyToC = nil | |
| 149 | + table.insert(updates, one) | |
| 142 | 150 | else |
| 143 | 151 | table.insert(updates, changeUpdateFunc["tableCommon"](one["type"], one)) |
| 144 | 152 | end | ... | ... |
src/models/RoleTask.lua
| 1 | 1 | |
| 2 | 2 | |
| 3 | +-- 增加 checkTaskEnter 内的参数 记得增增加注释 | |
| 3 | 4 | local TaskType = { |
| 4 | - | |
| 5 | + HangPass = 1, -- id | |
| 6 | + AdvPass = 2, -- id | |
| 7 | + LoveBreak = 3, -- heroType loveL | |
| 8 | + Wake = 4, -- heroType wakeL | |
| 9 | +} | |
| 10 | + | |
| 11 | +local function v(value) | |
| 12 | + return {type = "value", value = value} | |
| 13 | +end | |
| 14 | + | |
| 15 | +local function f(field) | |
| 16 | + return {type = "field", value = field} | |
| 17 | +end | |
| 18 | + | |
| 19 | +local StoryListener = { | |
| 20 | + func = "checkStoryStatus", | |
| 21 | + listen = { | |
| 22 | + [TaskType.HangPass] = {v(1), f("id")}, | |
| 23 | + [TaskType.AdvPass] = {v(4), f("id")}, | |
| 24 | + [TaskType.LoveBreak] = {v(2), f("heroType")}, | |
| 25 | + [TaskType.Wake] = {v(3), f("heroType"), f("wakeL")}, | |
| 26 | + } | |
| 27 | +} | |
| 28 | + | |
| 29 | +local TaskListeners = { | |
| 30 | + StoryListener, | |
| 5 | 31 | } |
| 6 | 32 | |
| 7 | 33 | local RoleTask = {} |
| ... | ... | @@ -10,11 +36,29 @@ function RoleTask.bind(Role) |
| 10 | 36 | |
| 11 | 37 | Role.TaskType = TaskType |
| 12 | 38 | |
| 13 | - function Role:checkTaskEnter(taskType, ...) | |
| 14 | - | |
| 39 | + -- 任务相关入口 | |
| 40 | + function Role:checkTaskEnter(taskType, params, notNotify) | |
| 41 | + for _, listener in ipairs(TaskListeners) do | |
| 42 | + if listener and listener.listen and listener.listen[taskType] and listener["func"] then | |
| 43 | + local pms = {} | |
| 44 | + for _, v in ipairs(listener.listen[taskType]) do | |
| 45 | + if type(v) == "table" and v.type then | |
| 46 | + if v.type == "value" then | |
| 47 | + table.insert(pms, v.value) | |
| 48 | + elseif v.type == "field" then | |
| 49 | + table.insert(pms, params[v.value]) | |
| 50 | + else | |
| 51 | + table.insert(pms, v) | |
| 52 | + end | |
| 53 | + else | |
| 54 | + table.insert(pms, v) | |
| 55 | + end | |
| 56 | + end | |
| 57 | + self[listener["func"]](self, notNotify, table.unpack(pms)) | |
| 58 | + end | |
| 59 | + end | |
| 15 | 60 | end |
| 16 | 61 | |
| 17 | - | |
| 18 | 62 | function Role:checkDailyTask() |
| 19 | 63 | end |
| 20 | 64 | |
| ... | ... | @@ -24,6 +68,83 @@ function RoleTask.bind(Role) |
| 24 | 68 | function Role:checkAchievTask() |
| 25 | 69 | end |
| 26 | 70 | |
| 71 | + --剧情相关----begin------------- | |
| 72 | + local function checkStoryStatusByHang(role, data, status, cond1) -- cond1 carbonId | |
| 73 | + if tonumber(data.unlockData) ~= cond1 then return end | |
| 74 | + status.s = 1 | |
| 75 | + return true | |
| 76 | + end | |
| 77 | + | |
| 78 | + local function checkStoryStatusByLove(role, data, status, cond1) -- cond1 heroType | |
| 79 | + if data.sort ~= cond1 then return end | |
| 80 | + local curL = role:getProperty("loveStatus"):getv(cond1, 0) | |
| 81 | + if curL < tonumber(data.unlockData) then return end | |
| 82 | + status.s = 1 | |
| 83 | + return true | |
| 84 | + end | |
| 85 | + | |
| 86 | + local function checkStoryStatusByMultStar(role, data, status, cond1, cond2) -- cond1 heroType, cond2 wakeL | |
| 87 | + local heroType = cond1 | |
| 88 | + local need = data.unlockData:toArray(true, "=") | |
| 89 | + local had = false | |
| 90 | + for _, v in pairs(need) do | |
| 91 | + if v == heroType then | |
| 92 | + had = true | |
| 93 | + break | |
| 94 | + end | |
| 95 | + end | |
| 96 | + if not had then return end | |
| 97 | + if cond2 > (status["s" .. heroType] or 0) then | |
| 98 | + status["s" .. heroType] = cond2 | |
| 99 | + end | |
| 100 | + local starC = 0 | |
| 101 | + for _, v in pairs(need) do | |
| 102 | + starC = starC + (status["s" .. v] or 0) | |
| 103 | + end | |
| 104 | + if starC >= tonumber(data.unlockData2) then | |
| 105 | + table.clear(status) | |
| 106 | + status.s = 1 | |
| 107 | + end | |
| 108 | + return true | |
| 109 | + end | |
| 110 | + | |
| 111 | + local function checkStoryStatusByAdv(role, data, status, cond1) -- cond1 advId | |
| 112 | + if tonumber(data.unlockData) ~= cond1 then return end | |
| 113 | + status.s = 1 | |
| 114 | + return true | |
| 115 | + end | |
| 116 | + | |
| 117 | + local checkstoryStatusFunc = { | |
| 118 | + [1] = checkStoryStatusByHang, | |
| 119 | + [2] = checkStoryStatusByLove, | |
| 120 | + [3] = checkStoryStatusByMultStar, | |
| 121 | + [4] = checkStoryStatusByAdv, | |
| 122 | + } | |
| 123 | + | |
| 124 | + function Role:checkStoryStatus(notNotify, stype, cond1, cond2, cond3) | |
| 125 | + local storyBookStatus = self:getProperty("storyB") | |
| 126 | + local change = {} | |
| 127 | + for id, data in pairs(csvdb["story_bookCsv"]) do | |
| 128 | + if stype == data.unlockType and checkstoryStatusFunc[stype] then | |
| 129 | + local curStatus = storyBookStatus[id] or {} | |
| 130 | + if not curStatus.s then -- 存在状态就是已经完成 | |
| 131 | + local isChange = checkstoryStatusFunc[stype](self, data, curStatus, cond1, cond2, cond3) | |
| 132 | + if isChange then | |
| 133 | + storyBookStatus[id] = curStatus | |
| 134 | + table.insert(change, {type = "storyB", field = id, value = curStatus, isOnlyToC = true}) | |
| 135 | + end | |
| 136 | + end | |
| 137 | + end | |
| 138 | + end | |
| 139 | + if next(change) then | |
| 140 | + self:setProperty("storyB", storyBookStatus) -- 统一写入数据库 | |
| 141 | + if not notNotify then | |
| 142 | + self:changeUpdates(change) | |
| 143 | + end | |
| 144 | + end | |
| 145 | + end | |
| 146 | + | |
| 147 | + --剧情相关----end------------- | |
| 27 | 148 | end |
| 28 | 149 | |
| 29 | 150 | return RoleTask |
| 30 | 151 | \ No newline at end of file | ... | ... |