Commit bcf5bfbb14007154e4a67df741ef70f1356fc943
1 parent
00115a7a
挂机new
Showing
1 changed file
with
85 additions
and
12 deletions
Show diff stats
src/actions/HangAction.lua
| ... | ... | @@ -22,12 +22,13 @@ local function checkReward(role) |
| 22 | 22 | return |
| 23 | 23 | end |
| 24 | 24 | local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] |
| 25 | - local nowTime = math.min(skynet.timex(), hangInfo.endTime or 0) | |
| 25 | + local nowCoinTime = math.min(skynet.timex(), hangInfo.endCoinTime or 0) | |
| 26 | + local nowItemTime = math.min(skynet.timex(), hangInfo.endItemTime or 0) | |
| 26 | 27 | |
| 27 | - local coinCount = math.max(0, math.floor((nowTime - hangInfo.coinTime) / globalCsv.idle_money_produce_cd)) | |
| 28 | + local coinCount = math.max(0, math.floor((nowCoinTime - hangInfo.coinTime) / globalCsv.idle_money_produce_cd)) | |
| 28 | 29 | hangInfo.coinTime = hangInfo.coinTime + coinCount * globalCsv.idle_money_produce_cd |
| 29 | 30 | |
| 30 | - local itemCount = math.max(0, math.floor((nowTime - hangInfo.itemTime) / globalCsv.idle_item_produce_cd)) | |
| 31 | + local itemCount = math.max(0, math.floor((nowItemTime - hangInfo.itemTime) / globalCsv.idle_item_produce_cd)) | |
| 31 | 32 | hangInfo.itemTime = hangInfo.itemTime + itemCount * globalCsv.idle_item_produce_cd |
| 32 | 33 | |
| 33 | 34 | local items = role:getProperty("hangBag") |
| ... | ... | @@ -41,7 +42,7 @@ local function checkReward(role) |
| 41 | 42 | end |
| 42 | 43 | local curTypeCount = 0 |
| 43 | 44 | for id, _ in pairs(items) do |
| 44 | - if id ~= ItemId.Gold and id ~= ItemId.Exp then | |
| 45 | + if id ~= ItemId.Gold and id ~= ItemId.Exp and id ~= ItemId.PlayerExp then | |
| 45 | 46 | curTypeCount = curTypeCount + 1 |
| 46 | 47 | end |
| 47 | 48 | end |
| ... | ... | @@ -87,7 +88,8 @@ function _M.startRpc( agent, data ) |
| 87 | 88 | hangInfo.coinTime = nowTime |
| 88 | 89 | hangInfo.itemTime = nowTime |
| 89 | 90 | if isNew then |
| 90 | - hangInfo.endTime = nowTime + globalCsv.idle_producetime_max | |
| 91 | + hangInfo.endCoinTime = nowTime + globalCsv.idle_producetime_max | |
| 92 | + hangInfo.endItemTime = nowTime + globalCsv.idle_producetime_max | |
| 91 | 93 | end |
| 92 | 94 | if not hangPass[carbonId] then |
| 93 | 95 | hangInfo.bossTime = nowTime + carbonData.idle_time |
| ... | ... | @@ -115,10 +117,18 @@ end |
| 115 | 117 | function _M.startBattleRpc(agent, data) |
| 116 | 118 | local role = agent.role |
| 117 | 119 | local msg = MsgPack.unpack(data) |
| 120 | + local carbonId = msg.carbonId | |
| 121 | + local curData = csvdb["idle_battleCsv"][carbonId] | |
| 122 | + if not curData then return end | |
| 123 | + | |
| 118 | 124 | local hangInfo = role:getProperty("hangInfo") |
| 119 | - if msg.carbonId ~= hangInfo.carbonId then return end | |
| 125 | + if curData.main ~= 1 then | |
| 126 | + if carbonId ~= hangInfo.carbonId then return end | |
| 127 | + end | |
| 128 | + | |
| 120 | 129 | local hangPass = role:getProperty("hangPass") |
| 121 | 130 | if hangPass[hangInfo.carbonId] then return end |
| 131 | + | |
| 122 | 132 | local key = tostring(math.random()) |
| 123 | 133 | hangInfo.key = key |
| 124 | 134 | local nowTime = skynet.timex() |
| ... | ... | @@ -132,18 +142,22 @@ function _M.endBattleRpc(agent, data) |
| 132 | 142 | local msg = MsgPack.unpack(data) |
| 133 | 143 | local hangInfo = role:getProperty("hangInfo") |
| 134 | 144 | if not msg.key or msg.key ~= hangInfo.key then return end |
| 135 | - if msg.carbonId ~= hangInfo.carbonId then return end | |
| 145 | + local carbonId = msg.carbonId | |
| 146 | + local carbonData = csvdb["idle_battleCsv"][carbonId] | |
| 147 | + if carbonData.main ~= 1 then | |
| 148 | + if carbonId ~= hangInfo.carbonId then return end | |
| 149 | + end | |
| 136 | 150 | local hangPass = role:getProperty("hangPass") |
| 137 | 151 | if hangPass[hangInfo.carbonId] then return end |
| 138 | 152 | local reward |
| 139 | 153 | if msg.starNum and msg.starNum > 0 then --win |
| 140 | - hangPass[hangInfo.carbonId] = 1 | |
| 154 | + hangPass[carbonId] = 1 | |
| 141 | 155 | role:updateProperty({field = "hangPass", value = hangPass}) |
| 142 | - hangInfo.bossTime = nil | |
| 143 | - | |
| 156 | + if carbonData.main ~= 1 then | |
| 157 | + hangInfo.bossTime = nil | |
| 158 | + end | |
| 144 | 159 | -- reward |
| 145 | 160 | reward = {} |
| 146 | - local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] | |
| 147 | 161 | reward[ItemId.Gold] = carbonData.money_clear |
| 148 | 162 | reward[ItemId.Exp] = carbonData.exp_clear |
| 149 | 163 | reward[ItemId.PlayerExp] = carbonData.playerExp_clear |
| ... | ... | @@ -191,7 +205,8 @@ function _M.getRewardRpc(agent , data) |
| 191 | 205 | table.clear(items) |
| 192 | 206 | local hangInfo = role:getProperty("hangInfo") |
| 193 | 207 | local nowTime = skynet.timex() |
| 194 | - hangInfo.endTime = nowTime + globalCsv.idle_producetime_max | |
| 208 | + hangInfo.endItemTime = nowTime + globalCsv.idle_producetime_max | |
| 209 | + hangInfo.endCoinTime = nowTime + globalCsv.idle_producetime_max | |
| 195 | 210 | hangInfo.coinTime = nowTime |
| 196 | 211 | hangInfo.itemTime = nowTime |
| 197 | 212 | role:updateProperty({field = "hangBag", value = items}) |
| ... | ... | @@ -203,6 +218,64 @@ function _M.getRewardRpc(agent , data) |
| 203 | 218 | return true |
| 204 | 219 | end |
| 205 | 220 | |
| 221 | +function _M.getRewardItemRpc(agent , data) | |
| 222 | + local role = agent.role | |
| 223 | + checkReward(role) | |
| 224 | + local items = role:getProperty("hangBag") | |
| 225 | + if not next(items) then return end | |
| 226 | + | |
| 227 | + local notNeed = {[ItemId.Gold] = 1, [ItemId.Exp] = 1, [ItemId.PlayerExp] = 1} | |
| 228 | + local reward = {} | |
| 229 | + for itemId , count in pairs(items) do | |
| 230 | + if not notNeed[itemId] then | |
| 231 | + reward[itemId] = count | |
| 232 | + items[itemId] = nil | |
| 233 | + end | |
| 234 | + end | |
| 235 | + if not next(reward) then return end | |
| 236 | + local reward = role:award(reward, {}) | |
| 237 | + | |
| 238 | + local hangInfo = role:getProperty("hangInfo") | |
| 239 | + local nowTime = skynet.timex() | |
| 240 | + hangInfo.endItemTime = nowTime + globalCsv.idle_producetime_max | |
| 241 | + hangInfo.itemTime = nowTime | |
| 242 | + role:updateProperty({field = "hangBag", value = items}) | |
| 243 | + role:updateProperty({field = "hangInfo", value = hangInfo}) | |
| 244 | + | |
| 245 | + SendPacket(actionCodes.Hang_getRewardItemRpc, MsgPack.pack({ | |
| 246 | + reward = reward | |
| 247 | + })) | |
| 248 | + return true | |
| 249 | +end | |
| 250 | + | |
| 251 | +function _M.getRewardCoinRpc(agent , data) | |
| 252 | + local role = agent.role | |
| 253 | + checkReward(role) | |
| 254 | + local items = role:getProperty("hangBag") | |
| 255 | + if not next(items) then return end | |
| 256 | + | |
| 257 | + local need = {[ItemId.Gold] = 1, [ItemId.Exp] = 1, [ItemId.PlayerExp] = 1} | |
| 258 | + local reward = {} | |
| 259 | + for itemId , count in pairs(items) do | |
| 260 | + if need[itemId] then | |
| 261 | + reward[itemId] = count | |
| 262 | + items[itemId] = nil | |
| 263 | + end | |
| 264 | + end | |
| 265 | + local reward = role:award(reward, {}) | |
| 266 | + | |
| 267 | + local hangInfo = role:getProperty("hangInfo") | |
| 268 | + local nowTime = skynet.timex() | |
| 269 | + hangInfo.endCoinTime = nowTime + globalCsv.idle_producetime_max | |
| 270 | + hangInfo.coinTime = nowTime | |
| 271 | + role:updateProperty({field = "hangBag", value = items}) | |
| 272 | + role:updateProperty({field = "hangInfo", value = hangInfo}) | |
| 273 | + | |
| 274 | + SendPacket(actionCodes.Hang_getRewardCoinRpc, MsgPack.pack({ | |
| 275 | + reward = reward | |
| 276 | + })) | |
| 277 | + return true | |
| 278 | +end | |
| 206 | 279 | |
| 207 | 280 | function _M.quickRpc(agent , data) |
| 208 | 281 | local role = agent.role | ... | ... |