Commit 497f9a67f0a8f6ee42f1a235cc8e0f4d8a27e79c
1 parent
9dd0add2
卖零件
Showing
3 changed files
with
52 additions
and
0 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/CarAction.lua
| ... | ... | @@ -151,4 +151,31 @@ function _M.saleEquipRpc(agent, data ) |
| 151 | 151 | return true |
| 152 | 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 | 181 | return _M |
| 155 | 182 | \ No newline at end of file | ... | ... |
src/models/RolePlugin.lua
| ... | ... | @@ -471,6 +471,30 @@ function RolePlugin.bind(Role) |
| 471 | 471 | end |
| 472 | 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 | 498 | function Role:getRuneByType(typ) |
| 475 | 499 | local runeSet = {} |
| 476 | 500 | for _,v in pairs(self.runeBag) do | ... | ... |