diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 068284b..1cfe567 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -26,6 +26,7 @@ actionCodes = { Role_updateEquip = 112, Role_updateRune = 113, Role_storyBookRewardRpc = 114, + Role_unLockStoryBookRpc = 115, Adv_startAdvRpc = 151, Adv_roleFormatRpc = 152, diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index edcd955..765a314 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -325,7 +325,6 @@ function _M.storyBookRewardRpc(agent, data) end -- 获取奖励 storyStatus[storyId].s = -1 - role:setProperty("storyB", storyBookStatus) -- 统一写入数据库 role:changeUpdates({{ type = "storyB", field = storyId, value = storyStatus[storyId] }}) local reward = role:award(storyBookData.gift) SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack({reward = reward})) @@ -333,7 +332,29 @@ function _M.storyBookRewardRpc(agent, data) end function _M.unLockStoryBookRpc(agent, data) - + local role = agent.role + local msg = MsgPack.unpack(data) + + local storyId = msg.id + local storyBookData = csvdb["story_bookCsv"][storyId] + if not storyBookData or storyBookData.lockItem == "" then return end -- 不能解锁 + + local storyStatus = role:getProperty("storyB") + if storyStatus[storyId] and storyStatus[storyId].s then return end --不需要解锁 + + local cost = storyBookData.lockItem:toNumMap() + if not cost or not next(cost) then return end + if not role:checkItemEnough(cost) then return end -- 消耗品不足 + + role:costItems(cost) + + -- 解锁 + storyStatus[storyId] = storyStatus[storyId] or {} + table.clear(storyStatus[storyId]) + storyStatus[storyId].s = 1 + role:changeUpdates({{ type = "storyB", field = storyId, value = storyStatus[storyId] }}) + SendPacket(actionCodes.Role_unLockStoryBookRpc, '') + return true end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 0d21ad8..2bf8751 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -301,7 +301,7 @@ function RolePlugin.bind(Role) newHero.owner = self newHero:saveBattleValue() self.heros[heroId] = newHero - + self:checkTaskEnter(role.TaskType.AddHero, {heroType = heroType, wakeL = newHero:getProperty("wakeL")}, params.notNotify) if not params.notNotify then local heroResponse = {} table.insert(heroResponse, newHero:data()) @@ -509,6 +509,18 @@ function RolePlugin.bind(Role) end return self.advData end + + function Role:getHeroMaxField(field, hType) + local max = 0 + for _, hero in pairs(self.heros) do + if not hType or hero:getProperty("type") == hType then + if hero:getProperty(field) > max then + max = hero:getProperty(field) + end + end + end + return max + end end return RolePlugin \ No newline at end of file diff --git a/src/models/RoleTask.lua b/src/models/RoleTask.lua index 571735f..68d6300 100644 --- a/src/models/RoleTask.lua +++ b/src/models/RoleTask.lua @@ -6,6 +6,7 @@ local TaskType = { AdvPass = 2, -- id LoveBreak = 3, -- heroType loveL Wake = 4, -- heroType wakeL + AddHero = 5, -- heroType wakeL } local function v(value) @@ -23,6 +24,7 @@ local StoryListener = { [TaskType.AdvPass] = {v(4), f("id")}, [TaskType.LoveBreak] = {v(2), f("heroType")}, [TaskType.Wake] = {v(3), f("heroType"), f("wakeL")}, + [TaskType.AddHero] = {v(3), f("heroType"), f("wakeL")}, } } -- libgit2 0.21.2