Commit 8c199cec3a53e791b9838e650414cfc3b291f40b
1 parent
b67180e8
简化物品奖励接口,设置默认参数
Showing
6 changed files
with
21 additions
and
18 deletions
Show diff stats
src/actions/GmAction.lua
src/actions/HangAction.lua
| ... | ... | @@ -164,7 +164,7 @@ function _M.endBattleRpc(agent, data) |
| 164 | 164 | for itemId, count in pairs(carbonData.item_clear:toNumMap()) do |
| 165 | 165 | reward[itemId] = count |
| 166 | 166 | end |
| 167 | - reward = role:award(reward, {}) | |
| 167 | + reward = role:award(reward) | |
| 168 | 168 | end |
| 169 | 169 | hangInfo.key = nil |
| 170 | 170 | role:updateProperty({field = "hangInfo", value = hangInfo}) |
| ... | ... | @@ -201,7 +201,7 @@ function _M.getRewardRpc(agent , data) |
| 201 | 201 | checkReward(role) |
| 202 | 202 | local items = role:getProperty("hangBag") |
| 203 | 203 | if not next(items) then return end |
| 204 | - local reward = role:award(items, {}) | |
| 204 | + local reward = role:award(items) | |
| 205 | 205 | table.clear(items) |
| 206 | 206 | local hangInfo = role:getProperty("hangInfo") |
| 207 | 207 | local nowTime = skynet.timex() |
| ... | ... | @@ -233,7 +233,7 @@ function _M.getRewardItemRpc(agent , data) |
| 233 | 233 | end |
| 234 | 234 | end |
| 235 | 235 | if not next(reward) then return end |
| 236 | - local reward = role:award(reward, {}) | |
| 236 | + local reward = role:award(reward) | |
| 237 | 237 | |
| 238 | 238 | local hangInfo = role:getProperty("hangInfo") |
| 239 | 239 | local nowTime = skynet.timex() |
| ... | ... | @@ -262,7 +262,7 @@ function _M.getRewardCoinRpc(agent , data) |
| 262 | 262 | items[itemId] = nil |
| 263 | 263 | end |
| 264 | 264 | end |
| 265 | - local reward = role:award(reward, {}) | |
| 265 | + local reward = role:award(reward) | |
| 266 | 266 | |
| 267 | 267 | local hangInfo = role:getProperty("hangInfo") |
| 268 | 268 | local nowTime = skynet.timex() |
| ... | ... | @@ -311,7 +311,7 @@ function _M.quickRpc(agent , data) |
| 311 | 311 | reward[cur[1]] = (reward[cur[1]] or 0) + cur[2] |
| 312 | 312 | end |
| 313 | 313 | |
| 314 | - reward = role:award(reward, {}) | |
| 314 | + reward = role:award(reward) | |
| 315 | 315 | |
| 316 | 316 | SendPacket(actionCodes.Hang_quickRpc, MsgPack.pack({ |
| 317 | 317 | reward = reward | ... | ... |
src/actions/HeroAction.lua
| ... | ... | @@ -425,7 +425,7 @@ function _M.createHeroRpc(agent, data) |
| 425 | 425 | end |
| 426 | 426 | |
| 427 | 427 | role:costItems({[heroType] = cost}) |
| 428 | - role:award({[heroType + ItemStartId.Hero] = 1}, {}) | |
| 428 | + role:award({[heroType + ItemStartId.Hero] = 1}) | |
| 429 | 429 | |
| 430 | 430 | SendPacket(actionCodes.Hero_createHeroRpc, "") |
| 431 | 431 | return true | ... | ... |
src/actions/RoleAction.lua
| ... | ... | @@ -257,7 +257,7 @@ function _M.saleItemRpc(agent, data) |
| 257 | 257 | local sellEffect = itemData.sell_effect:toArray(true, "=") |
| 258 | 258 | |
| 259 | 259 | role:costItems({[itemId] = count}) |
| 260 | - local reward = role:award({[sellEffect[1]] = sellEffect[2] * count}, {}) | |
| 260 | + local reward = role:award({[sellEffect[1]] = sellEffect[2] * count}) | |
| 261 | 261 | |
| 262 | 262 | SendPacket(actionCodes.Role_saleItemRpc, MsgPack.pack({reward = reward})) |
| 263 | 263 | return true |
| ... | ... | @@ -293,7 +293,7 @@ function _M.openItemRpc(agent, data) |
| 293 | 293 | end |
| 294 | 294 | end |
| 295 | 295 | role:costItems({[itemId] = count}) |
| 296 | - reward = role:award(reward, {}) | |
| 296 | + reward = role:award(reward) | |
| 297 | 297 | |
| 298 | 298 | SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward})) |
| 299 | 299 | return true | ... | ... |
src/adv/Adv.lua
| ... | ... | @@ -456,7 +456,7 @@ function Adv:over(success) |
| 456 | 456 | local reward |
| 457 | 457 | if success then |
| 458 | 458 | self.owner:updateProperty({field = "advPass", self.owner:getProperty("advPass"):setv(self.advInfo.chapter, score)}) |
| 459 | - reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap(), {}) | |
| 459 | + reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) | |
| 460 | 460 | end |
| 461 | 461 | table.clear(self.advInfo) --清空advInfo |
| 462 | 462 | self.advTeam.player = nil --重置玩家的数据 |
| ... | ... | @@ -630,6 +630,7 @@ end |
| 630 | 630 | |
| 631 | 631 | -- 在冒险中获得的物品都发放在冒险背包内 |
| 632 | 632 | function Adv:award(gift, params) |
| 633 | + params = params or {} | |
| 633 | 634 | local tgift = {} |
| 634 | 635 | if type(gift) == "string" then |
| 635 | 636 | for _, one in pairs(gift:toTableArray(true)) do |
| ... | ... | @@ -779,7 +780,7 @@ end |
| 779 | 780 | local function clickDrop(self, room, block, params) |
| 780 | 781 | local reward = {} |
| 781 | 782 | if not block.event.item then return end |
| 782 | - local reward = self:award({[block.event.item[1]] = block.event.item[2]}, {}) | |
| 783 | + local reward = self:award({[block.event.item[1]] = block.event.item[2]}) | |
| 783 | 784 | room:clearBEvent(block) |
| 784 | 785 | self:backReward(reward) |
| 785 | 786 | return true |
| ... | ... | @@ -795,7 +796,7 @@ local function clickTrader(self, room, block, params) |
| 795 | 796 | |
| 796 | 797 | if not self:cost({[traderData.type] = block.event.shop[buyId][3]}, {}) then return end --不够 |
| 797 | 798 | |
| 798 | - local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]}, {}) | |
| 799 | + local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]}) | |
| 799 | 800 | block.event.status = block.event.status:setv(buyId, 1) |
| 800 | 801 | self:backReward(reward) |
| 801 | 802 | return true | ... | ... |
src/models/RolePlugin.lua
| ... | ... | @@ -62,6 +62,7 @@ function RolePlugin.bind(Role) |
| 62 | 62 | end |
| 63 | 63 | |
| 64 | 64 | local function _award(self, itemId, count, params) |
| 65 | + local pms = clone(params) | |
| 65 | 66 | local itemData = csvdb["itemCsv"][itemId] |
| 66 | 67 | local curType = itemData.type |
| 67 | 68 | local change = {} -- 奖励被转化为了其他奖励 id = count |
| ... | ... | @@ -74,9 +75,9 @@ function RolePlugin.bind(Role) |
| 74 | 75 | |
| 75 | 76 | local itemTypeAward = { |
| 76 | 77 | [ItemType.Hero] = function() |
| 77 | - params.type = itemId - ItemStartId.Hero | |
| 78 | + pms.type = itemId - ItemStartId.Hero | |
| 78 | 79 | for i = 1, count do |
| 79 | - self:addHero(params) | |
| 80 | + self:addHero(pms) | |
| 80 | 81 | end |
| 81 | 82 | end, |
| 82 | 83 | [ItemType.AdvItem] = function() --冒险道具不会进入 玩家仓库 |
| ... | ... | @@ -91,9 +92,9 @@ function RolePlugin.bind(Role) |
| 91 | 92 | elseif itemTypeAward[curType] then |
| 92 | 93 | itemTypeAward[curType]() |
| 93 | 94 | else |
| 94 | - params.itemId = itemId | |
| 95 | - params.count = count | |
| 96 | - self:addItem(params) | |
| 95 | + pms.itemId = itemId | |
| 96 | + pms.count = count | |
| 97 | + self:addItem(pms) | |
| 97 | 98 | end |
| 98 | 99 | end |
| 99 | 100 | |
| ... | ... | @@ -103,6 +104,7 @@ function RolePlugin.bind(Role) |
| 103 | 104 | |
| 104 | 105 | -- 发奖功能入口 award string id=count or {[id] = count} |
| 105 | 106 | function Role:award(gift, params) |
| 107 | + params = params or {} | |
| 106 | 108 | local tgift = {} |
| 107 | 109 | if type(gift) == "string" then |
| 108 | 110 | for _, one in pairs(gift:toTableArray(true)) do |
| ... | ... | @@ -114,7 +116,7 @@ function RolePlugin.bind(Role) |
| 114 | 116 | local reward, allChange = {}, {} |
| 115 | 117 | |
| 116 | 118 | for itemId, count in pairs(tgift) do |
| 117 | - local count, change = _award(self, itemId, count, clone(params or {})) | |
| 119 | + local count, change = _award(self, itemId, count, params) | |
| 118 | 120 | if next(change) then |
| 119 | 121 | local cr, cc = self:award(change, params) -- 内部转换忽略 |
| 120 | 122 | for _id, _ct in pairs(cr) do | ... | ... |