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