Commit 36482c8b3ef357ce354d40c27730a6321ef54dcd
1 parent
84e7c06e
回收养成
Showing
2 changed files
with
74 additions
and
1 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -55,6 +55,7 @@ actionCodes = { | @@ -55,6 +55,7 @@ actionCodes = { | ||
| 55 | Hero_referEquipsRpc = 216, | 55 | Hero_referEquipsRpc = 216, |
| 56 | Hero_referRunesRpc = 217, | 56 | Hero_referRunesRpc = 217, |
| 57 | Hero_createHeroRandomRpc = 218, | 57 | Hero_createHeroRandomRpc = 218, |
| 58 | + Hero_getResetRewardRpc = 219, | ||
| 58 | 59 | ||
| 59 | Hang_startRpc = 251, | 60 | Hang_startRpc = 251, |
| 60 | Hang_checkRpc = 252, | 61 | Hang_checkRpc = 252, |
src/actions/HeroAction.lua
| @@ -18,7 +18,7 @@ local _M = {} | @@ -18,7 +18,7 @@ local _M = {} | ||
| 18 | function _M.levelUpRpc( agent, data ) | 18 | function _M.levelUpRpc( agent, data ) |
| 19 | local role = agent.role | 19 | local role = agent.role |
| 20 | local msg = MsgPack.unpack(data) | 20 | local msg = MsgPack.unpack(data) |
| 21 | - print("msg.id "..msg.id) | 21 | + |
| 22 | local hero = role.heros[msg.id] | 22 | local hero = role.heros[msg.id] |
| 23 | if not hero then return 1 end | 23 | if not hero then return 1 end |
| 24 | 24 | ||
| @@ -607,4 +607,76 @@ function _M.createHeroRandomRpc(agent, data) | @@ -607,4 +607,76 @@ function _M.createHeroRandomRpc(agent, data) | ||
| 607 | return true | 607 | return true |
| 608 | end | 608 | end |
| 609 | 609 | ||
| 610 | +function _M.getResetRewardRpc(agent, data) | ||
| 611 | + local role = agent.role | ||
| 612 | + local msg = MsgPack.unpack(data) | ||
| 613 | + | ||
| 614 | + local msg = MsgPack.unpack(data) | ||
| 615 | + | ||
| 616 | + local hero = role.heros[msg.id] | ||
| 617 | + if not hero then return end | ||
| 618 | + | ||
| 619 | + local level = hero:getProperty("level") | ||
| 620 | + local breakL = hero:getProperty("breakL") | ||
| 621 | + local talent = hero:getProperty("talent") | ||
| 622 | + | ||
| 623 | + if level <= 1 and talent == "" then return end | ||
| 624 | + | ||
| 625 | + local reward = {} | ||
| 626 | + while level > 1 do | ||
| 627 | + local curData = csvdb["unit_expCsv"][level - 1] | ||
| 628 | + reward[ItemId.Exp] = (reward[ItemId.Exp] or 0) + curData.exp | ||
| 629 | + reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + curData.gold | ||
| 630 | + level = level - 1 | ||
| 631 | + end | ||
| 632 | + | ||
| 633 | + while breakL > 0 do | ||
| 634 | + local curData = csvdb["unit_breakCsv"][breakL - 1] | ||
| 635 | + reward[ItemId.BreakCost] = (reward[ItemId.BreakCost] or 0) + curData.cost | ||
| 636 | + reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + curData.gold | ||
| 637 | + breakL = breakL - 1 | ||
| 638 | + end | ||
| 639 | + | ||
| 640 | + local stage = talent:getv(0, 1) | ||
| 641 | + local tlevel = {talent:getv(1, 0), talent:getv(2, 0), talent:getv(3, 0), talent:getv(4, 0)} | ||
| 642 | + | ||
| 643 | + local talentCostIds = globalCsv.unit_talent_cost[csvdb["unitCsv"][hero:getProperty("type")].camp] | ||
| 644 | + while stage > 0 do | ||
| 645 | + local curData = csvdb["unit_talentCsv"][stage] | ||
| 646 | + for level = math.max(table.unpack(tlevel)), 1, -1 do | ||
| 647 | + local add = 0 | ||
| 648 | + for i = 1, 4 do | ||
| 649 | + if tlevel[i] == level then | ||
| 650 | + add = add + 1 | ||
| 651 | + tlevel[i] = tlevel[i] - 1 | ||
| 652 | + end | ||
| 653 | + end | ||
| 654 | + local talentData = curData[level - 1] | ||
| 655 | + for itemId, count in pairs(talentData.money:toNumMap()) do | ||
| 656 | + reward[itemId] = (reward[itemId] or 0) + count * add | ||
| 657 | + end | ||
| 658 | + for idx , count in pairs(talentData.cost:toNumMap()) do | ||
| 659 | + reward[talentCostIds[idx]] = (reward[talentCostIds[idx]] or 0) + count * add | ||
| 660 | + end | ||
| 661 | + end | ||
| 662 | + stage = stage - 1 | ||
| 663 | + curData = csvdb["unit_talentCsv"][stage] | ||
| 664 | + if curData then | ||
| 665 | + tlevel = {#curData, #curData, #curData, #curData} | ||
| 666 | + end | ||
| 667 | + end | ||
| 668 | + | ||
| 669 | + hero:updateProperty({field = "level", value = level}) | ||
| 670 | + hero:updateProperty({field = "breakL", value = breakL}) | ||
| 671 | + hero:updateProperty({field = "talent", value = ""}) | ||
| 672 | + | ||
| 673 | + for itemId, count in pairs(reward) do | ||
| 674 | + reward[itemId] = math.floor(count * globalCsv.unit_back_discount) | ||
| 675 | + end | ||
| 676 | + reward = role:award(reward) | ||
| 677 | + | ||
| 678 | + SendPacket(actionCodes.Hero_getResetRewardRpc, MsgPack.pack({reward = reward})) | ||
| 679 | + return true | ||
| 680 | +end | ||
| 681 | + | ||
| 610 | return _M | 682 | return _M |
| 611 | \ No newline at end of file | 683 | \ No newline at end of file |