From 5d57bd7948d676ed5a45ad3b99a12b739f055161 Mon Sep 17 00:00:00 2001 From: gaofengduan <782277855@qq.com> Date: Thu, 23 May 2019 16:13:36 +0800 Subject: [PATCH] add 餐车 getSellRewardRpc --- .luacheckrc | 2 +- src/actions/DinerAction.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/models/Diner.lua | 11 +++++++---- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 71e8923..4175901 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -260,4 +260,4 @@ globals = { "error", } -- Ignore some pedantic checks -ignore = {'6','143','142','212'} \ No newline at end of file +ignore = {'6','143','142','212','311'} \ No newline at end of file diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 6325939..a58ce81 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -57,11 +57,12 @@ function _M.addSellRpc( agent, data ) sells[slot] = { dish = dish, level = dishLevel, - reward = "", + totalCount = 0, 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) @@ -115,7 +116,54 @@ function _M.removeSellRpc( agent, data ) end function _M.getSellRewardRpc( agent, data ) - + local role = agent.role + local rewards = {} + 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 + end + end + end + + sells = json.decode(role.dinerData:getProperty("sells")) + for _,sell in pairs(sells) do + if sell.count == 0 then + sell = nil + end + end + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) + SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = rewards})) + return true end function _M.levelUpRpc( agent, data ) diff --git a/src/models/Diner.lua b/src/models/Diner.lua index ee524fd..55fd067 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -99,10 +99,13 @@ function Diner:updateSell(slot, calOnly) local lastCount = sell.count - deltaCount if not calOnly then - sell.time = skynet.timex() - deltaTime - sell.count = lastCount - sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) - + if lastCount == 0 then + sell = nil + else + sell.time = skynet.timex() - deltaTime + sell.count = lastCount + sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) + end self:setProperty("sells", json.encode(sells)) end return { -- libgit2 0.21.2