Commit bd15e9bc614885638dc0fca90a4a668cd216b64b
1 parent
120c809d
购买剧情
Showing
4 changed files
with
39 additions
and
3 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -26,6 +26,7 @@ actionCodes = { | @@ -26,6 +26,7 @@ actionCodes = { | ||
| 26 | Role_updateEquip = 112, | 26 | Role_updateEquip = 112, |
| 27 | Role_updateRune = 113, | 27 | Role_updateRune = 113, |
| 28 | Role_storyBookRewardRpc = 114, | 28 | Role_storyBookRewardRpc = 114, |
| 29 | + Role_unLockStoryBookRpc = 115, | ||
| 29 | 30 | ||
| 30 | Adv_startAdvRpc = 151, | 31 | Adv_startAdvRpc = 151, |
| 31 | Adv_roleFormatRpc = 152, | 32 | Adv_roleFormatRpc = 152, |
src/actions/RoleAction.lua
| @@ -325,7 +325,6 @@ function _M.storyBookRewardRpc(agent, data) | @@ -325,7 +325,6 @@ function _M.storyBookRewardRpc(agent, data) | ||
| 325 | end | 325 | end |
| 326 | -- 获取奖励 | 326 | -- 获取奖励 |
| 327 | storyStatus[storyId].s = -1 | 327 | storyStatus[storyId].s = -1 |
| 328 | - role:setProperty("storyB", storyBookStatus) -- 统一写入数据库 | ||
| 329 | role:changeUpdates({{ type = "storyB", field = storyId, value = storyStatus[storyId] }}) | 328 | role:changeUpdates({{ type = "storyB", field = storyId, value = storyStatus[storyId] }}) |
| 330 | local reward = role:award(storyBookData.gift) | 329 | local reward = role:award(storyBookData.gift) |
| 331 | SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack({reward = reward})) | 330 | SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack({reward = reward})) |
| @@ -333,7 +332,29 @@ function _M.storyBookRewardRpc(agent, data) | @@ -333,7 +332,29 @@ function _M.storyBookRewardRpc(agent, data) | ||
| 333 | end | 332 | end |
| 334 | 333 | ||
| 335 | function _M.unLockStoryBookRpc(agent, data) | 334 | function _M.unLockStoryBookRpc(agent, data) |
| 336 | - | 335 | + local role = agent.role |
| 336 | + local msg = MsgPack.unpack(data) | ||
| 337 | + | ||
| 338 | + local storyId = msg.id | ||
| 339 | + local storyBookData = csvdb["story_bookCsv"][storyId] | ||
| 340 | + if not storyBookData or storyBookData.lockItem == "" then return end -- 不能解锁 | ||
| 341 | + | ||
| 342 | + local storyStatus = role:getProperty("storyB") | ||
| 343 | + if storyStatus[storyId] and storyStatus[storyId].s then return end --不需要解锁 | ||
| 344 | + | ||
| 345 | + local cost = storyBookData.lockItem:toNumMap() | ||
| 346 | + if not cost or not next(cost) then return end | ||
| 347 | + if not role:checkItemEnough(cost) then return end -- 消耗品不足 | ||
| 348 | + | ||
| 349 | + role:costItems(cost) | ||
| 350 | + | ||
| 351 | + -- 解锁 | ||
| 352 | + storyStatus[storyId] = storyStatus[storyId] or {} | ||
| 353 | + table.clear(storyStatus[storyId]) | ||
| 354 | + storyStatus[storyId].s = 1 | ||
| 355 | + role:changeUpdates({{ type = "storyB", field = storyId, value = storyStatus[storyId] }}) | ||
| 356 | + SendPacket(actionCodes.Role_unLockStoryBookRpc, '') | ||
| 357 | + return true | ||
| 337 | end | 358 | end |
| 338 | 359 | ||
| 339 | 360 |
src/models/RolePlugin.lua
| @@ -301,7 +301,7 @@ function RolePlugin.bind(Role) | @@ -301,7 +301,7 @@ function RolePlugin.bind(Role) | ||
| 301 | newHero.owner = self | 301 | newHero.owner = self |
| 302 | newHero:saveBattleValue() | 302 | newHero:saveBattleValue() |
| 303 | self.heros[heroId] = newHero | 303 | self.heros[heroId] = newHero |
| 304 | - | 304 | + self:checkTaskEnter(role.TaskType.AddHero, {heroType = heroType, wakeL = newHero:getProperty("wakeL")}, params.notNotify) |
| 305 | if not params.notNotify then | 305 | if not params.notNotify then |
| 306 | local heroResponse = {} | 306 | local heroResponse = {} |
| 307 | table.insert(heroResponse, newHero:data()) | 307 | table.insert(heroResponse, newHero:data()) |
| @@ -509,6 +509,18 @@ function RolePlugin.bind(Role) | @@ -509,6 +509,18 @@ function RolePlugin.bind(Role) | ||
| 509 | end | 509 | end |
| 510 | return self.advData | 510 | return self.advData |
| 511 | end | 511 | end |
| 512 | + | ||
| 513 | + function Role:getHeroMaxField(field, hType) | ||
| 514 | + local max = 0 | ||
| 515 | + for _, hero in pairs(self.heros) do | ||
| 516 | + if not hType or hero:getProperty("type") == hType then | ||
| 517 | + if hero:getProperty(field) > max then | ||
| 518 | + max = hero:getProperty(field) | ||
| 519 | + end | ||
| 520 | + end | ||
| 521 | + end | ||
| 522 | + return max | ||
| 523 | + end | ||
| 512 | end | 524 | end |
| 513 | 525 | ||
| 514 | return RolePlugin | 526 | return RolePlugin |
| 515 | \ No newline at end of file | 527 | \ No newline at end of file |
src/models/RoleTask.lua
| @@ -6,6 +6,7 @@ local TaskType = { | @@ -6,6 +6,7 @@ local TaskType = { | ||
| 6 | AdvPass = 2, -- id | 6 | AdvPass = 2, -- id |
| 7 | LoveBreak = 3, -- heroType loveL | 7 | LoveBreak = 3, -- heroType loveL |
| 8 | Wake = 4, -- heroType wakeL | 8 | Wake = 4, -- heroType wakeL |
| 9 | + AddHero = 5, -- heroType wakeL | ||
| 9 | } | 10 | } |
| 10 | 11 | ||
| 11 | local function v(value) | 12 | local function v(value) |
| @@ -23,6 +24,7 @@ local StoryListener = { | @@ -23,6 +24,7 @@ local StoryListener = { | ||
| 23 | [TaskType.AdvPass] = {v(4), f("id")}, | 24 | [TaskType.AdvPass] = {v(4), f("id")}, |
| 24 | [TaskType.LoveBreak] = {v(2), f("heroType")}, | 25 | [TaskType.LoveBreak] = {v(2), f("heroType")}, |
| 25 | [TaskType.Wake] = {v(3), f("heroType"), f("wakeL")}, | 26 | [TaskType.Wake] = {v(3), f("heroType"), f("wakeL")}, |
| 27 | + [TaskType.AddHero] = {v(3), f("heroType"), f("wakeL")}, | ||
| 26 | } | 28 | } |
| 27 | } | 29 | } |
| 28 | 30 |