Commit 5d57bd7948d676ed5a45ad3b99a12b739f055161

Authored by gaofengduan
1 parent 1ab9458f

add 餐车 getSellRewardRpc

.luacheckrc
... ... @@ -260,4 +260,4 @@ globals = {
260 260 "error",
261 261 }
262 262 -- Ignore some pedantic checks
263   -ignore = {'6','143','142','212'}
264 263 \ No newline at end of file
  264 +ignore = {'6','143','142','212','311'}
265 265 \ No newline at end of file
... ...
src/actions/DinerAction.lua
... ... @@ -57,11 +57,12 @@ function _M.addSellRpc( agent, data )
57 57 sells[slot] = {
58 58 dish = dish,
59 59 level = dishLevel,
60   - reward = "",
  60 + totalCount = 0,
61 61 count = 0,
62 62 }
63 63 end
64 64 local sell = sells[slot]
  65 + sell.totalCount = sell.totalCount + count
65 66 sell.count = sell.count + count
66 67 sell.time = skynet.timex() - calSell.deltaTime
67 68 sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0)
... ... @@ -115,7 +116,54 @@ function _M.removeSellRpc( agent, data )
115 116 end
116 117  
117 118 function _M.getSellRewardRpc( agent, data )
118   -
  119 + local role = agent.role
  120 + local rewards = {}
  121 + local sells = json.decode(role.dinerData:getProperty("sells"))
  122 + for slot,sell in pairs(sells) do
  123 + local info = role.dinerData:updateSell(slot)
  124 + if info.deltaCount > 0 then
  125 + local dish = sell.dish
  126 + local dishSet = csvdb["diner_dishCsv"][dish]
  127 + if not dishSet then
  128 + return 3
  129 + end
  130 + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
  131 + if dishLevel == 0 then
  132 + return 4
  133 + end
  134 + local dishData = dishSet[dishLevel]
  135 + if not dishData then
  136 + return 5
  137 + end
  138 +
  139 + local reward = dishData.item_normal:toNumMap()
  140 + if sell.hot then
  141 + for k,v in pairs(dishData.item_popular:toNumMap()) do
  142 + if reward[k] then
  143 + reward[k] = reward[k] + v
  144 + else
  145 + reward[k] = v
  146 + end
  147 + end
  148 + end
  149 +
  150 + for k, n in pairs(reward) do
  151 + local sum = n*info.deltaCount
  152 + role:addItem({itemId = k,count = sum})
  153 + rewards[k] = sum
  154 + end
  155 + end
  156 + end
  157 +
  158 + sells = json.decode(role.dinerData:getProperty("sells"))
  159 + for _,sell in pairs(sells) do
  160 + if sell.count == 0 then
  161 + sell = nil
  162 + end
  163 + end
  164 + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  165 + SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = rewards}))
  166 + return true
119 167 end
120 168  
121 169 function _M.levelUpRpc( agent, data )
... ...
src/models/Diner.lua
... ... @@ -99,10 +99,13 @@ function Diner:updateSell(slot, calOnly)
99 99 local lastCount = sell.count - deltaCount
100 100  
101 101 if not calOnly then
102   - sell.time = skynet.timex() - deltaTime
103   - sell.count = lastCount
104   - sell.level = self:getProperty("dishTree"):getv(sell.dish, 1)
105   -
  102 + if lastCount == 0 then
  103 + sell = nil
  104 + else
  105 + sell.time = skynet.timex() - deltaTime
  106 + sell.count = lastCount
  107 + sell.level = self:getProperty("dishTree"):getv(sell.dish, 1)
  108 + end
106 109 self:setProperty("sells", json.encode(sells))
107 110 end
108 111 return {
... ...