Commit bd15e9bc614885638dc0fca90a4a668cd216b64b
1 parent
120c809d
购买剧情
Showing
4 changed files
with
39 additions
and
3 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/RoleAction.lua
... | ... | @@ -325,7 +325,6 @@ function _M.storyBookRewardRpc(agent, data) |
325 | 325 | end |
326 | 326 | -- 获取奖励 |
327 | 327 | storyStatus[storyId].s = -1 |
328 | - role:setProperty("storyB", storyBookStatus) -- 统一写入数据库 | |
329 | 328 | role:changeUpdates({{ type = "storyB", field = storyId, value = storyStatus[storyId] }}) |
330 | 329 | local reward = role:award(storyBookData.gift) |
331 | 330 | SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack({reward = reward})) |
... | ... | @@ -333,7 +332,29 @@ function _M.storyBookRewardRpc(agent, data) |
333 | 332 | end |
334 | 333 | |
335 | 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 | 358 | end |
338 | 359 | |
339 | 360 | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -301,7 +301,7 @@ function RolePlugin.bind(Role) |
301 | 301 | newHero.owner = self |
302 | 302 | newHero:saveBattleValue() |
303 | 303 | self.heros[heroId] = newHero |
304 | - | |
304 | + self:checkTaskEnter(role.TaskType.AddHero, {heroType = heroType, wakeL = newHero:getProperty("wakeL")}, params.notNotify) | |
305 | 305 | if not params.notNotify then |
306 | 306 | local heroResponse = {} |
307 | 307 | table.insert(heroResponse, newHero:data()) |
... | ... | @@ -509,6 +509,18 @@ function RolePlugin.bind(Role) |
509 | 509 | end |
510 | 510 | return self.advData |
511 | 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 | 524 | end |
513 | 525 | |
514 | 526 | return RolePlugin |
515 | 527 | \ No newline at end of file | ... | ... |
src/models/RoleTask.lua
... | ... | @@ -6,6 +6,7 @@ local TaskType = { |
6 | 6 | AdvPass = 2, -- id |
7 | 7 | LoveBreak = 3, -- heroType loveL |
8 | 8 | Wake = 4, -- heroType wakeL |
9 | + AddHero = 5, -- heroType wakeL | |
9 | 10 | } |
10 | 11 | |
11 | 12 | local function v(value) |
... | ... | @@ -23,6 +24,7 @@ local StoryListener = { |
23 | 24 | [TaskType.AdvPass] = {v(4), f("id")}, |
24 | 25 | [TaskType.LoveBreak] = {v(2), f("heroType")}, |
25 | 26 | [TaskType.Wake] = {v(3), f("heroType"), f("wakeL")}, |
27 | + [TaskType.AddHero] = {v(3), f("heroType"), f("wakeL")}, | |
26 | 28 | } |
27 | 29 | } |
28 | 30 | ... | ... |