Commit 37037eebce759fd4a355508ad01a73716de6ee58
1 parent
0c0b161d
计算奖励
Showing
8 changed files
with
54 additions
and
31 deletions
Show diff stats
src/GlobalVar.lua
src/actions/DinerAction.lua
src/actions/HangAction.lua
| ... | ... | @@ -193,6 +193,7 @@ end |
| 193 | 193 | function _M.roleFormatRpc(agent , data) |
| 194 | 194 | local role = agent.role |
| 195 | 195 | local msg = MsgPack.unpack(data) |
| 196 | + dump(msg) | |
| 196 | 197 | local hangTeam = role:getProperty("hangTeam") |
| 197 | 198 | for slot, heroId in pairs(msg.heros) do |
| 198 | 199 | if not role.heros[heroId] then | ... | ... |
src/main.lua
src/models/Diner.lua
| ... | ... | @@ -76,6 +76,47 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) |
| 76 | 76 | SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) |
| 77 | 77 | end |
| 78 | 78 | |
| 79 | +local function calSellReward(sell, delta, dishData) | |
| 80 | + local reward = sell.reward or "" | |
| 81 | + local famous = sell.famous or 0 | |
| 82 | + if delta <= 0 then | |
| 83 | + return reward, famous | |
| 84 | + end | |
| 85 | + for type, value in pairs(dishData.item_normal:toNumMap()) do | |
| 86 | + reward = reward:incrv(type, value * delta) | |
| 87 | + end | |
| 88 | + famous = famous + dishData.famous_normal * delta | |
| 89 | + if sell.hot > 0 then | |
| 90 | + for type, value in pairs(dishData.item_popular:toNumMap()) do | |
| 91 | + reward = reward:incrv(type, value * delta) | |
| 92 | + end | |
| 93 | + famous = famous + dishData.famous_popular * delta | |
| 94 | + end | |
| 95 | + | |
| 96 | + for buildType = 1, 6 do | |
| 97 | + local level = self:getProperty("buildL"):getv(buildType, 1) | |
| 98 | + local buildData = csvdb["diner_buildingCsv"][buildType][level] | |
| 99 | + if buildData.gold_up > 0 then | |
| 100 | + local value = reward:getv(ItemId.Gold, 0) | |
| 101 | + value = math.floor(value * (100 + buildData.gold_up) / 100) | |
| 102 | + if value > 0 then | |
| 103 | + reward = reward:setv(ItemId.Gold, value) | |
| 104 | + end | |
| 105 | + end | |
| 106 | + if buildData.item_up > 0 then | |
| 107 | + local value = reward:getv(ItemId.DinerCoin, 0) | |
| 108 | + value = math.floor(value * (100 + buildData.item_up) / 100) | |
| 109 | + if value > 0 then | |
| 110 | + reward = reward:setv(ItemId.DinerCoin, value) | |
| 111 | + end | |
| 112 | + end | |
| 113 | + if buildData and buildData.famous_up > 0 then | |
| 114 | + famous = math.floor(famous * (100 + buildData.famous_up) / 100) | |
| 115 | + end | |
| 116 | + end | |
| 117 | + return reward, famous | |
| 118 | +end | |
| 119 | + | |
| 79 | 120 | function Diner:updateSell(slot, calOnly) |
| 80 | 121 | local sells = json.decode(self:getProperty("sells")) |
| 81 | 122 | local sell = sells[slot] |
| ... | ... | @@ -88,9 +129,7 @@ function Diner:updateSell(slot, calOnly) |
| 88 | 129 | local deltaCount = 0 |
| 89 | 130 | local timePass = skynet.timex() - sell.time |
| 90 | 131 | local sellTime = dishData.sell_time |
| 91 | - if self:getProperty("hot"):getv(sell.dish, 0) > 0 then | |
| 92 | - sellTime = sellTime * 1.5 | |
| 93 | - end | |
| 132 | + | |
| 94 | 133 | deltaCount = math.floor(timePass / sellTime) |
| 95 | 134 | if deltaCount < sell.count then |
| 96 | 135 | deltaTime = math.floor(timePass - sellTime * deltaCount) |
| ... | ... | @@ -99,33 +138,13 @@ function Diner:updateSell(slot, calOnly) |
| 99 | 138 | local lastCount = sell.count - deltaCount |
| 100 | 139 | |
| 101 | 140 | if not calOnly then |
| 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 | |
| 123 | - end | |
| 124 | - | |
| 141 | + local reward, famous = self:calSellReward(sell, deltaCount, dishData) | |
| 125 | 142 | sell.time = skynet.timex() - deltaTime |
| 126 | 143 | sell.count = lastCount |
| 127 | 144 | sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) |
| 145 | + sell.hot = self:getProperty("hot"):getv(sell.dish, 0) | |
| 128 | 146 | sell.reward = reward |
| 147 | + sell.famous = famous | |
| 129 | 148 | self:setProperty("sells", json.encode(sells)) |
| 130 | 149 | end |
| 131 | 150 | return { | ... | ... |
src/models/Role.lua