Commit f5c07b1b12de128667c51fc5afd63819778b7e0f

Authored by gaofengduan
1 parent cc796aaf

fix diner

.luacheckrc
1 1 std = "max"
2 2 globals = {
  3 + "DinerTask",
3 4 "SendPipelining",
4 5 "AdvEventType",
5 6 "class",
... ...
src/actions/DinerAction.lua
... ... @@ -72,7 +72,6 @@ function _M.addSellRpc( agent, data )
72 72 level = dishLevel,
73 73 reward = "",
74 74 count = 0,
75   - famous = 0,
76 75 }
77 76 end
78 77 local sell = sells[slot]
... ... @@ -130,20 +129,15 @@ end
130 129  
131 130 function _M.getSellRewardRpc( agent, data )
132 131 local role = agent.role
133   - local reward = {}
134 132 local dirty = false
135 133  
  134 + local reward = ""
136 135 local sells = json.decode(role.dinerData:getProperty("sells"))
137   - for slot,sell in pairs(sells) do
  136 + for slot, sell in pairs(sells) do
138 137 role.dinerData:updateSell(slot)
139   -
140 138 local rewards = sell.reward:toNumMap()
141 139 for k,v in pairs(rewards) do
142   - if reward[k] then
143   - reward[k] = reward[k] + v
144   - else
145   - reward[k] = v
146   - end
  140 + reward = reward:incrv(k, v)
147 141 end
148 142 sells[slot].reward = ""
149 143  
... ... @@ -153,14 +147,15 @@ function _M.getSellRewardRpc( agent, data )
153 147 end
154 148 end
155 149 end
156   - for k, v in pairs(reward) do
  150 +
  151 + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  152 + for k, v in pairs(reward:toNumMap()) do
157 153 role:addItem({itemId = k,count = v})
158 154 end
159 155 if dirty then
160 156 role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
161 157 end
162 158  
163   - role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
164 159 SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward}))
165 160 return true
166 161 end
... ...
1   -Subproject commit a877f94b084a3571e2f3d57e4997fd00c0a51eaf
  1 +Subproject commit d52d26ecb27c5bc5e532d033544cae9917434ea5
... ...
src/models/Diner.lua
... ... @@ -60,7 +60,7 @@ function Diner:refreshDailyData(notify)
60 60 end
61 61 end
62 62 end
63   - self:updateProperty({field = "order", value = json.encode(orders)), notNotify = not notify})
  63 + self:updateProperty({field = "order", value = json.encode(orders), notNotify = not notify})
64 64 end
65 65  
66 66 function Diner:updateProperty(params)
... ... @@ -105,24 +105,25 @@ function Diner:checkDinerTask(type, count, param1, param2, notNotify)
105 105 end
106 106 end
107 107 if dirty then
108   - self:updateProperty({field = "order", value = json.encode(orders)), notNotify = notNotify})
  108 + self:updateProperty({field = "order", value = json.encode(orders), notNotify = notNotify})
109 109 end
110 110 return dirty
111 111 end
112 112  
113 113 function Diner:calSellReward(sell, delta, dishData)
  114 + echoLog("calSellReward delta ",delta)
114 115 local reward = sell.reward or ""
115 116 local popular = 0
116 117 if delta <= 0 then
117 118 return reward, popular
118 119 end
119   - for type, value in pairs(dishData.item_normal:toNumMap()) do
120   - reward = reward:incrv(type, value * delta)
  120 + for key, value in pairs(dishData.item_normal:toNumMap()) do
  121 + reward = reward:incrv(key, value * delta)
121 122 end
122 123 popular = popular + dishData.famous_normal * delta
123 124 if sell.hot > 0 then
124   - for type, value in pairs(dishData.item_popular:toNumMap()) do
125   - reward = reward:incrv(type, value * delta)
  125 + for key, value in pairs(dishData.item_popular:toNumMap()) do
  126 + reward = reward:incrv(key, value * delta)
126 127 end
127 128 popular = popular + dishData.famous_popular * delta
128 129 end
... ... @@ -148,6 +149,7 @@ function Diner:calSellReward(sell, delta, dishData)
148 149 popular = math.floor(popular * (100 + buildData.famous_up) / 100)
149 150 end
150 151 end
  152 + echoLog("calSellReward reward ",reward,popular)
151 153 return reward, popular
152 154 end
153 155  
... ...