Commit 497f9a67f0a8f6ee42f1a235cc8e0f4d8a27e79c
1 parent
9dd0add2
卖零件
Showing
3 changed files
with
52 additions
and
0 deletions
Show diff stats
src/ProtocolCode.lua
@@ -82,6 +82,7 @@ actionCodes = { | @@ -82,6 +82,7 @@ actionCodes = { | ||
82 | Car_equipUpRpc = 401, | 82 | Car_equipUpRpc = 401, |
83 | Car_runeUpRpc = 402, | 83 | Car_runeUpRpc = 402, |
84 | Car_saleEquipRpc = 403, | 84 | Car_saleEquipRpc = 403, |
85 | + Car_saleRuneRpc = 404, | ||
85 | } | 86 | } |
86 | 87 | ||
87 | rpcResponseBegin = 10000 | 88 | rpcResponseBegin = 10000 |
src/actions/CarAction.lua
@@ -151,4 +151,31 @@ function _M.saleEquipRpc(agent, data ) | @@ -151,4 +151,31 @@ function _M.saleEquipRpc(agent, data ) | ||
151 | return true | 151 | return true |
152 | end | 152 | end |
153 | 153 | ||
154 | +function _M.saleRuneRpc(agent, data ) | ||
155 | + local role = agent.role | ||
156 | + local msg = MsgPack.unpack(data) | ||
157 | + local backs = msg.backs | ||
158 | + if not backs then return end | ||
159 | + | ||
160 | + local reward = {} | ||
161 | + for _, id in pairs(backs) do | ||
162 | + local rune = role.runeBag[uid] | ||
163 | + if not rune then return end | ||
164 | + if rune:getProperty("refer") ~= 0 then return end | ||
165 | + local itemData = csvdb["ItemCsv"][rune:getProperty("id")] | ||
166 | + if not itemData then return end | ||
167 | + local one = itemData.sell_effect:toNumMap() | ||
168 | + for k ,v in pairs(one) do | ||
169 | + reward[k] = (reward[k] or 0) + v | ||
170 | + end | ||
171 | + end | ||
172 | + | ||
173 | + role:delRunes(backs) | ||
174 | + | ||
175 | + reward = role:award(reward) | ||
176 | + | ||
177 | + SendPacket(actionCodes.Car_saleRuneRpc, MsgPack.pack({reward = reward})) | ||
178 | + return true | ||
179 | +end | ||
180 | + | ||
154 | return _M | 181 | return _M |
155 | \ No newline at end of file | 182 | \ No newline at end of file |
src/models/RolePlugin.lua
@@ -471,6 +471,30 @@ function RolePlugin.bind(Role) | @@ -471,6 +471,30 @@ function RolePlugin.bind(Role) | ||
471 | end | 471 | end |
472 | end | 472 | end |
473 | 473 | ||
474 | + function Role:delRunes(runeIds) -- 批量删除 {id, } | ||
475 | + local roleId = self:getProperty('id') | ||
476 | + local bDel = {} | ||
477 | + for _, runeId in paris(runeIds) do | ||
478 | + local rune = self.runeBag[runeId] | ||
479 | + if rune and rune:getProperty("refer") == 0 then | ||
480 | + self.runeBag[runeId] = nil | ||
481 | + table.insert(bDel, runeId) | ||
482 | + end | ||
483 | + end | ||
484 | + | ||
485 | + redisproxy:pipelining(function (red) | ||
486 | + for _, runeId in pairs(bDel) do | ||
487 | + red:del(string.format(R_RUNE, roleId, runeId)) | ||
488 | + red:srem(string.format(R_RUNEIDS, roleId), runeId) | ||
489 | + end | ||
490 | + end) | ||
491 | + local response = {} | ||
492 | + for _, runeId in pairs(bDel) do | ||
493 | + table.insert(response, {uid = runeId, bDel = true}) | ||
494 | + end | ||
495 | + SendPacket(actionCodes.Role_loadRunes, MsgPack.pack(response)) | ||
496 | + end | ||
497 | + | ||
474 | function Role:getRuneByType(typ) | 498 | function Role:getRuneByType(typ) |
475 | local runeSet = {} | 499 | local runeSet = {} |
476 | for _,v in pairs(self.runeBag) do | 500 | for _,v in pairs(self.runeBag) do |