From 0c0b161da689f3af76ad0e20612bb8d91ddfc07a Mon Sep 17 00:00:00 2001 From: gaofengduan <782277855@qq.com> Date: Thu, 23 May 2019 21:06:43 +0800 Subject: [PATCH] fix getSellRewardRpc --- src/actions/DinerAction.lua | 53 ++++++++++++----------------------------------------- src/models/Diner.lua | 32 ++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 47 deletions(-) diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index a58ce81..c4b528e 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -57,12 +57,11 @@ function _M.addSellRpc( agent, data ) sells[slot] = { dish = dish, level = dishLevel, - totalCount = 0, + reward = {}, count = 0, } end local sell = sells[slot] - sell.totalCount = sell.totalCount + count sell.count = sell.count + count sell.time = skynet.timex() - calSell.deltaTime sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) @@ -117,52 +116,24 @@ end function _M.getSellRewardRpc( agent, data ) local role = agent.role - local rewards = {} + local reward = {} local sells = json.decode(role.dinerData:getProperty("sells")) for slot,sell in pairs(sells) do - local info = role.dinerData:updateSell(slot) - if info.deltaCount > 0 then - local dish = sell.dish - local dishSet = csvdb["diner_dishCsv"][dish] - if not dishSet then - return 3 - end - local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) - if dishLevel == 0 then - return 4 - end - local dishData = dishSet[dishLevel] - if not dishData then - return 5 - end - - local reward = dishData.item_normal:toNumMap() - if sell.hot then - for k,v in pairs(dishData.item_popular:toNumMap()) do - if reward[k] then - reward[k] = reward[k] + v - else - reward[k] = v - end - end - end - - for k, n in pairs(reward) do - local sum = n*info.deltaCount - role:addItem({itemId = k,count = sum}) - rewards[k] = sum + role.dinerData:updateSell(slot) + for k,v in pairs(sell.reward) do + if reward[k] then + reward[k] = reward[k] + v + else + reward[k] = v end end + sells[slot].reward = "" end - - sells = json.decode(role.dinerData:getProperty("sells")) - for _,sell in pairs(sells) do - if sell.count == 0 then - sell = nil - end + for k, v in pairs(reward) do + role:addItem({itemId = k,count = v}) end role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) - SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = rewards})) + SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) return true end diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 55fd067..ac719ce 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -99,13 +99,33 @@ function Diner:updateSell(slot, calOnly) local lastCount = sell.count - deltaCount if not calOnly then - if lastCount == 0 then - sell = nil - else - sell.time = skynet.timex() - deltaTime - sell.count = lastCount - sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) + local reward = {} + if deltaCount > 0 then + local tmp = dishData.item_normal:toNumMap() + if sell.hot then + for k,v in pairs(dishData.item_popular:toNumMap()) do + if tmp[k] then + tmp[k] = tmp[k] + v + else + tmp[k] = v + end + end + end + + for k, n in pairs(tmp) do + local sum = n*deltaCount + if reward[tostring(k)] then + reward[tostring(k)] = reward[tostring(k)] + sum + else + reward[tostring(k)] = sum + end + end end + + sell.time = skynet.timex() - deltaTime + sell.count = lastCount + sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) + sell.reward = reward self:setProperty("sells", json.encode(sells)) end return { -- libgit2 0.21.2