diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 683d86b..068284b 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -25,6 +25,7 @@ actionCodes = { Role_openItemRpc = 111, Role_updateEquip = 112, Role_updateRune = 113, + Role_storyBookRewardRpc = 114, Adv_startAdvRpc = 151, Adv_roleFormatRpc = 152, diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 1006e0a..600a059 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -180,6 +180,8 @@ function _M.endBattleRpc(agent, data) reward[itemId] = count end reward = role:award(reward) + + role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId}) end hangInfo.key = nil role:updateProperty({field = "hangInfo", value = hangInfo}) diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 231715c..4ff1117 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -69,7 +69,7 @@ function _M.wakeRpc(agent, data) local skills = {} for _,v in pairs(wakeData.skill:toArray(true,"=") ) do local skillSet = hero:getSkillData(v) - if next(skillSet) then + if skillSet and next(skillSet) then local skillLv = hero:getSkillLevel(v)+1 local skillData = skillSet[skillLv] if skillData and next(skillData) then @@ -86,6 +86,8 @@ function _M.wakeRpc(agent, data) end hero:updateProperty({field = "wakeL", delta = 1}) + role:checkTaskEnter(role.TaskType.Wake, {heroType = typ, wakeL = hero:getProperty("wakeL")}) + SendPacket(actionCodes.Hero_wakeRpc, '') return true end @@ -368,7 +370,8 @@ function _M.loveItemRpc(agent, data) end local curL = hero:getProperty("loveL") local curExp = hero:getProperty("loveExp") - local curPlus = csvdb["unit_love_plusCsv"][hero:getProperty("type")] + local curType = hero:getProperty("type") + local curPlus = csvdb["unit_love_plusCsv"][curType] if not curPlus then return end @@ -392,8 +395,16 @@ function _M.loveItemRpc(agent, data) return true end role:costItems({[cost[1]] = cost[2]}) - hero:updateProperty({field = "loveL", value = curL + 1}) + local newLevel = curL + 1 + hero:updateProperty({field = "loveL", value = newLevel}) hero:updateProperty({field = "loveExp", value = 0}) + + if role:getProperty("loveStatus"):getv(curType, 0) < newLevel then + role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的 + end + + role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel}) + else local delta = globalCsv.unit_love_presentValue[msg.itemId] if not delta then @@ -438,13 +449,16 @@ function _M.loveTaskRpc(agent, data) else newExp = 0 end + local newLevel = curL + 1 hero:updateProperty({field = "loveExp", value = newExp}) - hero:updateProperty({field = "loveL", value = curL + 1}) + hero:updateProperty({field = "loveL", value = newLevel}) - if role:getProperty("loveStatus"):getv(curType, 0) < curL + 1 then - role:changeUpdates({{type = "loveStatus", field = curType, value = curL + 1}}) -- 总的 + if role:getProperty("loveStatus"):getv(curType, 0) < newLevel then + role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的 end + role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel}) + SendPacket(actionCodes.Hero_loveTaskRpc, "") return true end diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 87ffa3a..530b9ab 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -313,5 +313,23 @@ function _M.openItemRpc(agent, data) return true end +function _M.storyBookRewardRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local storyId = msg.id + local storyBookData = csvdb["story_bookCsv"][storyId] + if not storyBookData then return end + local storyStatus = self:getProperty("storyB") + if not storyStatus[id] or not storyStatus[id].s or storyStatus[id].s ~= 1 then return end + + -- 获取奖励 + storyStatus[id].s = -1 + self:setProperty("storyB", storyBookStatus) -- 统一写入数据库 + self:changeUpdates({{ type = "storyB", field = id, value = storyStatus[id] }}) + local reward = role:award(storyBookData.gift) + SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack({reward = reward})) + return true +end + return _M \ No newline at end of file diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index a9b53d3..6294b6e 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -460,6 +460,8 @@ function Adv:over(success) if success then self.owner:updateProperty({field = "advPass", self.owner:getProperty("advPass"):setv(self.advInfo.chapter, score)}) reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) + + self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.advInfo.chapter}) end table.clear(self.advInfo) --清空advInfo self.advTeam.player = nil --重置玩家的数据 diff --git a/src/models/Role.lua b/src/models/Role.lua index 45f8644..7d88c53 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -55,6 +55,8 @@ Role.schema = { hangBagLimit = {"number", globalCsv.idle_field_origin}, --背包上限 potionBag = {"table", {}}, -- 营养剂背包 + + storyB = {"table", {}}, -- 剧情记录 } @@ -133,12 +135,18 @@ function Role:changeUpdates(params, notNotify) self:setProperty(fieldType) return {type = fieldType, field = info["field"], value = info["value"]} end, + ["onlyToC"] = function(info) + return info + end, } local updates = {} for _, one in ipairs(params) do if changeUpdateFunc[one["type"]] then table.insert(updates, changeUpdateFunc[one["type"]](one)) + elseif one.isOnlyToC then + one.isOnlyToC = nil + table.insert(updates, one) else table.insert(updates, changeUpdateFunc["tableCommon"](one["type"], one)) end diff --git a/src/models/RoleTask.lua b/src/models/RoleTask.lua index c8e7503..571735f 100644 --- a/src/models/RoleTask.lua +++ b/src/models/RoleTask.lua @@ -1,7 +1,33 @@ +-- 增加 checkTaskEnter 内的参数 记得增增加注释 local TaskType = { - + HangPass = 1, -- id + AdvPass = 2, -- id + LoveBreak = 3, -- heroType loveL + Wake = 4, -- heroType wakeL +} + +local function v(value) + return {type = "value", value = value} +end + +local function f(field) + return {type = "field", value = field} +end + +local StoryListener = { + func = "checkStoryStatus", + listen = { + [TaskType.HangPass] = {v(1), f("id")}, + [TaskType.AdvPass] = {v(4), f("id")}, + [TaskType.LoveBreak] = {v(2), f("heroType")}, + [TaskType.Wake] = {v(3), f("heroType"), f("wakeL")}, + } +} + +local TaskListeners = { + StoryListener, } local RoleTask = {} @@ -10,11 +36,29 @@ function RoleTask.bind(Role) Role.TaskType = TaskType - function Role:checkTaskEnter(taskType, ...) - + -- 任务相关入口 + function Role:checkTaskEnter(taskType, params, notNotify) + for _, listener in ipairs(TaskListeners) do + if listener and listener.listen and listener.listen[taskType] and listener["func"] then + local pms = {} + for _, v in ipairs(listener.listen[taskType]) do + if type(v) == "table" and v.type then + if v.type == "value" then + table.insert(pms, v.value) + elseif v.type == "field" then + table.insert(pms, params[v.value]) + else + table.insert(pms, v) + end + else + table.insert(pms, v) + end + end + self[listener["func"]](self, notNotify, table.unpack(pms)) + end + end end - function Role:checkDailyTask() end @@ -24,6 +68,83 @@ function RoleTask.bind(Role) function Role:checkAchievTask() end + --剧情相关----begin------------- + local function checkStoryStatusByHang(role, data, status, cond1) -- cond1 carbonId + if tonumber(data.unlockData) ~= cond1 then return end + status.s = 1 + return true + end + + local function checkStoryStatusByLove(role, data, status, cond1) -- cond1 heroType + if data.sort ~= cond1 then return end + local curL = role:getProperty("loveStatus"):getv(cond1, 0) + if curL < tonumber(data.unlockData) then return end + status.s = 1 + return true + end + + local function checkStoryStatusByMultStar(role, data, status, cond1, cond2) -- cond1 heroType, cond2 wakeL + local heroType = cond1 + local need = data.unlockData:toArray(true, "=") + local had = false + for _, v in pairs(need) do + if v == heroType then + had = true + break + end + end + if not had then return end + if cond2 > (status["s" .. heroType] or 0) then + status["s" .. heroType] = cond2 + end + local starC = 0 + for _, v in pairs(need) do + starC = starC + (status["s" .. v] or 0) + end + if starC >= tonumber(data.unlockData2) then + table.clear(status) + status.s = 1 + end + return true + end + + local function checkStoryStatusByAdv(role, data, status, cond1) -- cond1 advId + if tonumber(data.unlockData) ~= cond1 then return end + status.s = 1 + return true + end + + local checkstoryStatusFunc = { + [1] = checkStoryStatusByHang, + [2] = checkStoryStatusByLove, + [3] = checkStoryStatusByMultStar, + [4] = checkStoryStatusByAdv, + } + + function Role:checkStoryStatus(notNotify, stype, cond1, cond2, cond3) + local storyBookStatus = self:getProperty("storyB") + local change = {} + for id, data in pairs(csvdb["story_bookCsv"]) do + if stype == data.unlockType and checkstoryStatusFunc[stype] then + local curStatus = storyBookStatus[id] or {} + if not curStatus.s then -- 存在状态就是已经完成 + local isChange = checkstoryStatusFunc[stype](self, data, curStatus, cond1, cond2, cond3) + if isChange then + storyBookStatus[id] = curStatus + table.insert(change, {type = "storyB", field = id, value = curStatus, isOnlyToC = true}) + end + end + end + end + if next(change) then + self:setProperty("storyB", storyBookStatus) -- 统一写入数据库 + if not notNotify then + self:changeUpdates(change) + end + end + end + + --剧情相关----end------------- end return RoleTask \ No newline at end of file -- libgit2 0.21.2