Commit 251d8e5ee3a1b0bccac7a645b0cad1fbc9229f55
1 parent
06562145
fix: 挂机宝鉴,宝藏CD的bug
1. 开始新关卡,重置之前正在挖宝关卡的挂机时间,获取之前挖宝关卡的奖励
Showing
3 changed files
with
67 additions
and
59 deletions
Show diff stats
src/actions/GmAction.lua
| @@ -992,16 +992,19 @@ table.insert(helpDes, {"宝藏图鉴", "treasure", "list"} ) | @@ -992,16 +992,19 @@ table.insert(helpDes, {"宝藏图鉴", "treasure", "list"} ) | ||
| 992 | function _M.treasure(role, pms) | 992 | function _M.treasure(role, pms) |
| 993 | local pm1 = pms.pm1 | 993 | local pm1 = pms.pm1 |
| 994 | if pm1 == "LIST" then | 994 | if pm1 == "LIST" then |
| 995 | - local treasureList= role.dailyData:getTreasrueList(role) | ||
| 996 | - for id, val in pairs(treasureList) do | ||
| 997 | - print(string.format("%s:%d:%d:%d:%d", val.name, val.weight, val.treasure_value, val.expire_time or 0, val.cool_time or 0)) | ||
| 998 | - end | 995 | + local treasureList= role.dailyData:getProperty("treasureList") |
| 996 | + dump(treasureList) | ||
| 999 | return "宝藏图鉴" | 997 | return "宝藏图鉴" |
| 998 | + elseif pm1 == "FLUSH" then | ||
| 999 | + local treasureList= role.dailyData:getTreasrueList(role) | ||
| 1000 | + dump(treasureList) | ||
| 1001 | + return "宝藏图鉴" | ||
| 1000 | elseif pm1 == "CHECK" then | 1002 | elseif pm1 == "CHECK" then |
| 1001 | local treasureList = role.dailyData:checkTreasureList(role) | 1003 | local treasureList = role.dailyData:checkTreasureList(role) |
| 1002 | - for id, val in pairs(treasureList) do | ||
| 1003 | - print(string.format("%s:%d:%d:%d:%d", val.name, val.weight, val.treasure_value, val.expire_time or 0, val.cool_time or 0)) | 1004 | + if treasureList == nil then |
| 1005 | + return "未挖到宝藏" | ||
| 1004 | end | 1006 | end |
| 1007 | + dump(treasureList) | ||
| 1005 | return "挖宝成功" | 1008 | return "挖宝成功" |
| 1006 | elseif pm1 == "RESET" then | 1009 | elseif pm1 == "RESET" then |
| 1007 | role.dailyData:resetTreasureList() | 1010 | role.dailyData:resetTreasureList() |
src/actions/HangAction.lua
| @@ -27,7 +27,7 @@ local function getHangTime(role) | @@ -27,7 +27,7 @@ local function getHangTime(role) | ||
| 27 | return nowCoinTime - hangInfo.coinTime | 27 | return nowCoinTime - hangInfo.coinTime |
| 28 | end | 28 | end |
| 29 | 29 | ||
| 30 | -local function checkReward(role, isTreasure) | 30 | +local function checkReward(role, isTreasure, carbonId) |
| 31 | local hangInfo = role:getProperty("hangInfo") | 31 | local hangInfo = role:getProperty("hangInfo") |
| 32 | if not hangInfo.carbonId or not hangInfo.coinTime or not hangInfo.itemTime then | 32 | if not hangInfo.carbonId or not hangInfo.coinTime or not hangInfo.itemTime then |
| 33 | return false | 33 | return false |
| @@ -56,7 +56,7 @@ local function checkReward(role, isTreasure) | @@ -56,7 +56,7 @@ local function checkReward(role, isTreasure) | ||
| 56 | coinCount = (coinCount + coinDoubleCount) * expCoef | 56 | coinCount = (coinCount + coinDoubleCount) * expCoef |
| 57 | items[ItemId.Gold] = math.floor((items[ItemId.Gold] or 0) + coinCount * (expCarbonData.money or 0)) | 57 | items[ItemId.Gold] = math.floor((items[ItemId.Gold] or 0) + coinCount * (expCarbonData.money or 0)) |
| 58 | items[ItemId.Exp] = math.floor((items[ItemId.Exp] or 0) + coinCount * (expCarbonData.exp or 0)) | 58 | items[ItemId.Exp] = math.floor((items[ItemId.Exp] or 0) + coinCount * (expCarbonData.exp or 0)) |
| 59 | - items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + (coinCount * expCarbonData.playerExp or 0)) | 59 | + items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + coinCount * (expCarbonData.playerExp or 0)) |
| 60 | 60 | ||
| 61 | local pool = {} | 61 | local pool = {} |
| 62 | for _, temp in pairs(carbonData.item:toArray()) do | 62 | for _, temp in pairs(carbonData.item:toArray()) do |
| @@ -127,8 +127,9 @@ local function checkReward(role, isTreasure) | @@ -127,8 +127,9 @@ local function checkReward(role, isTreasure) | ||
| 127 | 127 | ||
| 128 | --挂机得到的宝藏加入到挂机奖励 | 128 | --挂机得到的宝藏加入到挂机奖励 |
| 129 | if isTreasure or false == true then | 129 | if isTreasure or false == true then |
| 130 | - local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId) | ||
| 131 | - if next(treasureList) ~= nil then | 130 | + carbonId = carbonId or hangInfo.carbonId |
| 131 | + local treasureList = role.dailyData:checkTreasureList(carbonId) or {} | ||
| 132 | + if treasureList and next(treasureList) ~= nil then | ||
| 132 | for id, val in pairs(treasureList) do | 133 | for id, val in pairs(treasureList) do |
| 133 | local award = val.award:toNumMap() | 134 | local award = val.award:toNumMap() |
| 134 | for k,v in pairs(award) do | 135 | for k,v in pairs(award) do |
| @@ -171,7 +172,7 @@ function _M.startRpc( agent, data ) | @@ -171,7 +172,7 @@ function _M.startRpc( agent, data ) | ||
| 171 | end | 172 | end |
| 172 | end | 173 | end |
| 173 | 174 | ||
| 174 | - if checkReward(role) then | 175 | + if checkReward(role, true, carbonId) then |
| 175 | role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) | 176 | role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) |
| 176 | end | 177 | end |
| 177 | 178 |
src/models/Daily.lua
| @@ -155,18 +155,20 @@ end | @@ -155,18 +155,20 @@ end | ||
| 155 | --资源 | 155 | --资源 |
| 156 | function Daily:checkTreasureBase(treasureList, treasureBase, removeId) | 156 | function Daily:checkTreasureBase(treasureList, treasureBase, removeId) |
| 157 | local tmptreasure = {} | 157 | local tmptreasure = {} |
| 158 | + local num = 0 | ||
| 158 | for k, val in pairs(treasureList) do | 159 | for k, val in pairs(treasureList) do |
| 159 | if removeId and val.id == removeId then | 160 | if removeId and val.id == removeId then |
| 160 | - table.remove(treasureList, k) | 161 | + treasureList[k] = nil |
| 161 | else | 162 | else |
| 162 | if treasureBase >= val.treasure_value then | 163 | if treasureBase >= val.treasure_value then |
| 163 | treasureBase = treasureBase - val.treasure_value | 164 | treasureBase = treasureBase - val.treasure_value |
| 164 | tmptreasure[val.id] = val | 165 | tmptreasure[val.id] = val |
| 166 | + num = num + 1 | ||
| 165 | end | 167 | end |
| 166 | end | 168 | end |
| 167 | 169 | ||
| 168 | end | 170 | end |
| 169 | - return tmptreasure | 171 | + return tmptreasure, num |
| 170 | end | 172 | end |
| 171 | 173 | ||
| 172 | --绑定通关关卡 | 174 | --绑定通关关卡 |
| @@ -177,14 +179,9 @@ function Daily:checkChapters() | @@ -177,14 +179,9 @@ function Daily:checkChapters() | ||
| 177 | if next(treasureList) ~= nil then | 179 | if next(treasureList) ~= nil then |
| 178 | for id, curInfo in pairs(treasureList) do | 180 | for id, curInfo in pairs(treasureList) do |
| 179 | if curInfo["end_time"] then | 181 | if curInfo["end_time"] then |
| 180 | - if skynet.timex() >= curInfo["end_time"] then | ||
| 181 | - curInfo = nil | 182 | + if skynet.timex() < curInfo["end_time"] then |
| 183 | + tmp_chapters[curInfo.chapter_id] = curInfo | ||
| 182 | end | 184 | end |
| 183 | - else | ||
| 184 | - curInfo = nil | ||
| 185 | - end | ||
| 186 | - if curInfo ~= nil then | ||
| 187 | - tmp_chapters[curInfo.chapter_id] = curInfo | ||
| 188 | end | 185 | end |
| 189 | end | 186 | end |
| 190 | end | 187 | end |
| @@ -207,16 +204,26 @@ end | @@ -207,16 +204,26 @@ end | ||
| 207 | function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) | 204 | function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) |
| 208 | local removeId | 205 | local removeId |
| 209 | local chapters = self:checkChapters() | 206 | local chapters = self:checkChapters() |
| 207 | + local treasure | ||
| 210 | if next(chapters) == nil then return end | 208 | if next(chapters) == nil then return end |
| 211 | 209 | ||
| 212 | while next(tmptreasure) do | 210 | while next(tmptreasure) do |
| 213 | - local tmp = self:checkTreasureBase(tmptreasure, treasureBase, removeId) | ||
| 214 | - local id = math.randWeight(tmp, "weight") --宝藏id | ||
| 215 | - if not id then | 211 | + local tmp, num = self:checkTreasureBase(tmptreasure, treasureBase, removeId) |
| 212 | + | ||
| 213 | + if num == 0 then | ||
| 216 | break | 214 | break |
| 215 | + elseif num == 1 then | ||
| 216 | + for _, val in pairs(tmp) do | ||
| 217 | + treasure = val | ||
| 218 | + end | ||
| 219 | + else | ||
| 220 | + local id = math.randWeight(tmp, "weight") --宝藏id | ||
| 221 | + if not id then | ||
| 222 | + break | ||
| 223 | + end | ||
| 224 | + treasure = tmp[id] | ||
| 217 | end | 225 | end |
| 218 | - | ||
| 219 | - local treasure = tmp[id] | 226 | + |
| 220 | if treasureBase >= treasure.treasure_value then | 227 | if treasureBase >= treasure.treasure_value then |
| 221 | --扣除资源值 | 228 | --扣除资源值 |
| 222 | treasureBase = treasureBase - treasure.treasure_value | 229 | treasureBase = treasureBase - treasure.treasure_value |
| @@ -229,8 +236,8 @@ function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) | @@ -229,8 +236,8 @@ function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) | ||
| 229 | end | 236 | end |
| 230 | 237 | ||
| 231 | treasure.chapter_id = chapterId | 238 | treasure.chapter_id = chapterId |
| 232 | - treasureList[id] = treasure | ||
| 233 | - removeId = id | 239 | + treasureList[treasure.id] = treasure |
| 240 | + removeId = treasure.id | ||
| 234 | end | 241 | end |
| 235 | end | 242 | end |
| 236 | 243 | ||
| @@ -249,49 +256,45 @@ function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) | @@ -249,49 +256,45 @@ function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) | ||
| 249 | if not curInfo["end_time"] then | 256 | if not curInfo["end_time"] then |
| 250 | curInfo["end_time"] = skynet.timex() + curInfo.working_time | 257 | curInfo["end_time"] = skynet.timex() + curInfo.working_time |
| 251 | else | 258 | else |
| 252 | - --宝藏冷却时间 | ||
| 253 | - if not curInfo["expire_time"] then | ||
| 254 | - --已挖到 | ||
| 255 | - if skynet.timex() >= curInfo["end_time"] then | ||
| 256 | - treasure = treasureList[curInfo.id] | ||
| 257 | - if curInfo.cool_time > 1 then | 259 | + if skynet.timex() >= curInfo["end_time"] then |
| 260 | + if curInfo.cool_time > 1 then | ||
| 261 | + --宝藏冷却时间 | ||
| 262 | + if not curInfo["expire_time"] then | ||
| 263 | + treasure = treasureList[curInfo.id] | ||
| 258 | curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay | 264 | curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay |
| 259 | else | 265 | else |
| 260 | - curInfo["expire_time"] = skynet.timex() | 266 | + --已经领取宝藏 检索宝藏冷却时间 |
| 267 | + if skynet.timex() >= curInfo["expire_time"] then | ||
| 268 | + treasureList[curInfo.id] = nil | ||
| 269 | + end | ||
| 261 | end | 270 | end |
| 262 | - if skynet.timex() >= curInfo["expire_time"] then | ||
| 263 | - table.remove(treasureList, curInfo.id) | ||
| 264 | - end | ||
| 265 | - end | ||
| 266 | - else | ||
| 267 | - --已经领取宝藏 检索宝藏冷却时间 | ||
| 268 | - if skynet.timex() >= curInfo["expire_time"] then | ||
| 269 | - table.remove(treasureList, curInfo.id) | 271 | + else |
| 272 | + treasure = treasureList[curInfo.id] | ||
| 273 | + treasureList[curInfo.id] = nil | ||
| 270 | end | 274 | end |
| 271 | end | 275 | end |
| 272 | end | 276 | end |
| 273 | else | 277 | else |
| 274 | --已经开始挖宝 | 278 | --已经开始挖宝 |
| 275 | if curInfo["end_time"] then | 279 | if curInfo["end_time"] then |
| 276 | - if not curInfo["expire_time"] then --宝藏冷却时间 | ||
| 277 | - if skynet.timex() >= curInfo["end_time"] then --已挖到 | ||
| 278 | - treasure = treasureList[curInfo.id] | ||
| 279 | - if curInfo.cool_time > 1 then | 280 | + if skynet.timex() >= curInfo["end_time"] then |
| 281 | + if curInfo.cool_time > 1 then | ||
| 282 | + --宝藏冷却时间 | ||
| 283 | + if not curInfo["expire_time"] then | ||
| 284 | + treasure = treasureList[curInfo.id] | ||
| 280 | curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay | 285 | curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay |
| 281 | else | 286 | else |
| 282 | - curInfo["expire_time"] = skynet.timex() | ||
| 283 | - end | ||
| 284 | - if skynet.timex() >= curInfo["expire_time"] then | ||
| 285 | - table.remove(treasureList, curInfo.id) | 287 | + --已经领取宝藏 检索宝藏冷却时间 |
| 288 | + if skynet.timex() >= curInfo["expire_time"] then | ||
| 289 | + treasureList[curInfo.id] = nil | ||
| 290 | + end | ||
| 286 | end | 291 | end |
| 287 | else | 292 | else |
| 288 | - --未挖到直接删除 | ||
| 289 | - table.remove(treasureList, curInfo.id) | ||
| 290 | - end | ||
| 291 | - else --已经领取宝藏 检索宝藏冷却时间 | ||
| 292 | - if skynet.timex() >= curInfo["expire_time"] then | ||
| 293 | - table.remove(treasureList, curInfo.id) | 293 | + treasure = treasureList[curInfo.id] |
| 294 | + treasureList[curInfo.id] = nil | ||
| 294 | end | 295 | end |
| 296 | + else | ||
| 297 | + curInfo["end_time"] = nil | ||
| 295 | end | 298 | end |
| 296 | end | 299 | end |
| 297 | end | 300 | end |
| @@ -310,7 +313,7 @@ function Daily:buyTreasure(treasureList) | @@ -310,7 +313,7 @@ function Daily:buyTreasure(treasureList) | ||
| 310 | boughtTreasurer[id] = val | 313 | boughtTreasurer[id] = val |
| 311 | end | 314 | end |
| 312 | end | 315 | end |
| 313 | - self:updateProperty({field = "treasureBase", value = treasureBase}) | 316 | + --self:updateProperty({field = "treasureBase", value = treasureBase}) |
| 314 | return boughtTreasurer | 317 | return boughtTreasurer |
| 315 | end | 318 | end |
| 316 | 319 | ||
| @@ -322,7 +325,7 @@ end | @@ -322,7 +325,7 @@ end | ||
| 322 | --宝藏图鉴 | 325 | --宝藏图鉴 |
| 323 | function Daily:getTreasrueList() | 326 | function Daily:getTreasrueList() |
| 324 | local tmpcsv = csvdb["idle_treasureCsv"] | 327 | local tmpcsv = csvdb["idle_treasureCsv"] |
| 325 | - local treasureList = self:getProperty("treasureList") --挖宝列表 过期删除 领取奖励删除 跨天更新 | 328 | + local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 |
| 326 | local tmptreasure = {} | 329 | local tmptreasure = {} |
| 327 | local treasureBase = globalCsv.idle_treasure_base | 330 | local treasureBase = globalCsv.idle_treasure_base |
| 328 | for id, val in pairs(tmpcsv) do | 331 | for id, val in pairs(tmpcsv) do |
| @@ -343,7 +346,7 @@ end | @@ -343,7 +346,7 @@ end | ||
| 343 | 346 | ||
| 344 | --检索挖宝列表 | 347 | --检索挖宝列表 |
| 345 | function Daily:checkTreasureList(chapterId) | 348 | function Daily:checkTreasureList(chapterId) |
| 346 | - local treasureList = self:getProperty("treasureList") | 349 | + local treasureList = self:getProperty("treasureList") or {} |
| 347 | local tmptreasure = {} | 350 | local tmptreasure = {} |
| 348 | for id, val in pairs(treasureList) do | 351 | for id, val in pairs(treasureList) do |
| 349 | local treasure = self:checkTreasureChapterId(val, treasureList, chapterId) | 352 | local treasure = self:checkTreasureChapterId(val, treasureList, chapterId) |
| @@ -353,6 +356,7 @@ function Daily:checkTreasureList(chapterId) | @@ -353,6 +356,7 @@ function Daily:checkTreasureList(chapterId) | ||
| 353 | end | 356 | end |
| 354 | 357 | ||
| 355 | if next(tmptreasure) == nil then | 358 | if next(tmptreasure) == nil then |
| 359 | + self:updateProperty({field = "treasureList", value = treasureList}) | ||
| 356 | return nil | 360 | return nil |
| 357 | end | 361 | end |
| 358 | local boughtTreasurer = self:buyTreasure(tmptreasure) | 362 | local boughtTreasurer = self:buyTreasure(tmptreasure) |