Commit f5c07b1b12de128667c51fc5afd63819778b7e0f
1 parent
cc796aaf
fix diner
Showing
4 changed files
with
16 additions
and
18 deletions
Show diff stats
.luacheckrc
src/actions/DinerAction.lua
@@ -72,7 +72,6 @@ function _M.addSellRpc( agent, data ) | @@ -72,7 +72,6 @@ function _M.addSellRpc( agent, data ) | ||
72 | level = dishLevel, | 72 | level = dishLevel, |
73 | reward = "", | 73 | reward = "", |
74 | count = 0, | 74 | count = 0, |
75 | - famous = 0, | ||
76 | } | 75 | } |
77 | end | 76 | end |
78 | local sell = sells[slot] | 77 | local sell = sells[slot] |
@@ -130,20 +129,15 @@ end | @@ -130,20 +129,15 @@ end | ||
130 | 129 | ||
131 | function _M.getSellRewardRpc( agent, data ) | 130 | function _M.getSellRewardRpc( agent, data ) |
132 | local role = agent.role | 131 | local role = agent.role |
133 | - local reward = {} | ||
134 | local dirty = false | 132 | local dirty = false |
135 | 133 | ||
134 | + local reward = "" | ||
136 | local sells = json.decode(role.dinerData:getProperty("sells")) | 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 | role.dinerData:updateSell(slot) | 137 | role.dinerData:updateSell(slot) |
139 | - | ||
140 | local rewards = sell.reward:toNumMap() | 138 | local rewards = sell.reward:toNumMap() |
141 | for k,v in pairs(rewards) do | 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 | end | 141 | end |
148 | sells[slot].reward = "" | 142 | sells[slot].reward = "" |
149 | 143 | ||
@@ -153,14 +147,15 @@ function _M.getSellRewardRpc( agent, data ) | @@ -153,14 +147,15 @@ function _M.getSellRewardRpc( agent, data ) | ||
153 | end | 147 | end |
154 | end | 148 | end |
155 | end | 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 | role:addItem({itemId = k,count = v}) | 153 | role:addItem({itemId = k,count = v}) |
158 | end | 154 | end |
159 | if dirty then | 155 | if dirty then |
160 | role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) | 156 | role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) |
161 | end | 157 | end |
162 | 158 | ||
163 | - role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) | ||
164 | SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) | 159 | SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) |
165 | return true | 160 | return true |
166 | end | 161 | end |
src/models/Diner.lua
@@ -60,7 +60,7 @@ function Diner:refreshDailyData(notify) | @@ -60,7 +60,7 @@ function Diner:refreshDailyData(notify) | ||
60 | end | 60 | end |
61 | end | 61 | end |
62 | end | 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 | end | 64 | end |
65 | 65 | ||
66 | function Diner:updateProperty(params) | 66 | function Diner:updateProperty(params) |
@@ -105,24 +105,25 @@ function Diner:checkDinerTask(type, count, param1, param2, notNotify) | @@ -105,24 +105,25 @@ function Diner:checkDinerTask(type, count, param1, param2, notNotify) | ||
105 | end | 105 | end |
106 | end | 106 | end |
107 | if dirty then | 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 | end | 109 | end |
110 | return dirty | 110 | return dirty |
111 | end | 111 | end |
112 | 112 | ||
113 | function Diner:calSellReward(sell, delta, dishData) | 113 | function Diner:calSellReward(sell, delta, dishData) |
114 | + echoLog("calSellReward delta ",delta) | ||
114 | local reward = sell.reward or "" | 115 | local reward = sell.reward or "" |
115 | local popular = 0 | 116 | local popular = 0 |
116 | if delta <= 0 then | 117 | if delta <= 0 then |
117 | return reward, popular | 118 | return reward, popular |
118 | end | 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 | end | 122 | end |
122 | popular = popular + dishData.famous_normal * delta | 123 | popular = popular + dishData.famous_normal * delta |
123 | if sell.hot > 0 then | 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 | end | 127 | end |
127 | popular = popular + dishData.famous_popular * delta | 128 | popular = popular + dishData.famous_popular * delta |
128 | end | 129 | end |
@@ -148,6 +149,7 @@ function Diner:calSellReward(sell, delta, dishData) | @@ -148,6 +149,7 @@ function Diner:calSellReward(sell, delta, dishData) | ||
148 | popular = math.floor(popular * (100 + buildData.famous_up) / 100) | 149 | popular = math.floor(popular * (100 + buildData.famous_up) / 100) |
149 | end | 150 | end |
150 | end | 151 | end |
152 | + echoLog("calSellReward reward ",reward,popular) | ||
151 | return reward, popular | 153 | return reward, popular |
152 | end | 154 | end |
153 | 155 |