Commit 0c0b161da689f3af76ad0e20612bb8d91ddfc07a

Authored by gaofengduan
1 parent 5d57bd79

fix getSellRewardRpc

Showing 2 changed files with 38 additions and 47 deletions   Show diff stats
src/actions/DinerAction.lua
@@ -57,12 +57,11 @@ function _M.addSellRpc( agent, data ) @@ -57,12 +57,11 @@ function _M.addSellRpc( agent, data )
57 sells[slot] = { 57 sells[slot] = {
58 dish = dish, 58 dish = dish,
59 level = dishLevel, 59 level = dishLevel,
60 - totalCount = 0, 60 + reward = {},
61 count = 0, 61 count = 0,
62 } 62 }
63 end 63 end
64 local sell = sells[slot] 64 local sell = sells[slot]
65 - sell.totalCount = sell.totalCount + count  
66 sell.count = sell.count + count 65 sell.count = sell.count + count
67 sell.time = skynet.timex() - calSell.deltaTime 66 sell.time = skynet.timex() - calSell.deltaTime
68 sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) 67 sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0)
@@ -117,52 +116,24 @@ end @@ -117,52 +116,24 @@ end
117 116
118 function _M.getSellRewardRpc( agent, data ) 117 function _M.getSellRewardRpc( agent, data )
119 local role = agent.role 118 local role = agent.role
120 - local rewards = {} 119 + local reward = {}
121 local sells = json.decode(role.dinerData:getProperty("sells")) 120 local sells = json.decode(role.dinerData:getProperty("sells"))
122 for slot,sell in pairs(sells) do 121 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 122 + role.dinerData:updateSell(slot)
  123 + for k,v in pairs(sell.reward) do
  124 + if reward[k] then
  125 + reward[k] = reward[k] + v
  126 + else
  127 + reward[k] = v
154 end 128 end
155 end 129 end
  130 + sells[slot].reward = ""
156 end 131 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 132 + for k, v in pairs(reward) do
  133 + role:addItem({itemId = k,count = v})
163 end 134 end
164 role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) 135 role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
165 - SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = rewards})) 136 + SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward}))
166 return true 137 return true
167 end 138 end
168 139
src/models/Diner.lua
@@ -99,13 +99,33 @@ function Diner:updateSell(slot, calOnly) @@ -99,13 +99,33 @@ function Diner:updateSell(slot, calOnly)
99 local lastCount = sell.count - deltaCount 99 local lastCount = sell.count - deltaCount
100 100
101 if not calOnly then 101 if not calOnly then
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) 102 + local reward = {}
  103 + if deltaCount > 0 then
  104 + local tmp = dishData.item_normal:toNumMap()
  105 + if sell.hot then
  106 + for k,v in pairs(dishData.item_popular:toNumMap()) do
  107 + if tmp[k] then
  108 + tmp[k] = tmp[k] + v
  109 + else
  110 + tmp[k] = v
  111 + end
  112 + end
  113 + end
  114 +
  115 + for k, n in pairs(tmp) do
  116 + local sum = n*deltaCount
  117 + if reward[tostring(k)] then
  118 + reward[tostring(k)] = reward[tostring(k)] + sum
  119 + else
  120 + reward[tostring(k)] = sum
  121 + end
  122 + end
108 end 123 end
  124 +
  125 + sell.time = skynet.timex() - deltaTime
  126 + sell.count = lastCount
  127 + sell.level = self:getProperty("dishTree"):getv(sell.dish, 1)
  128 + sell.reward = reward
109 self:setProperty("sells", json.encode(sells)) 129 self:setProperty("sells", json.encode(sells))
110 end 130 end
111 return { 131 return {