diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 25f3a34..11b1e71 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -992,16 +992,19 @@ table.insert(helpDes, {"宝藏图鉴", "treasure", "list"} ) function _M.treasure(role, pms) local pm1 = pms.pm1 if pm1 == "LIST" then - local treasureList= role.dailyData:getTreasrueList(role) - for id, val in pairs(treasureList) do - 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)) - end + local treasureList= role.dailyData:getProperty("treasureList") + dump(treasureList) return "宝藏图鉴" + elseif pm1 == "FLUSH" then + local treasureList= role.dailyData:getTreasrueList(role) + dump(treasureList) + return "宝藏图鉴" elseif pm1 == "CHECK" then local treasureList = role.dailyData:checkTreasureList(role) - for id, val in pairs(treasureList) do - 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)) + if treasureList == nil then + return "未挖到宝藏" end + dump(treasureList) return "挖宝成功" elseif pm1 == "RESET" then role.dailyData:resetTreasureList() diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 5a220e7..f848dd8 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -27,7 +27,7 @@ local function getHangTime(role) return nowCoinTime - hangInfo.coinTime end -local function checkReward(role, isTreasure) +local function checkReward(role, isTreasure, carbonId) local hangInfo = role:getProperty("hangInfo") if not hangInfo.carbonId or not hangInfo.coinTime or not hangInfo.itemTime then return false @@ -56,7 +56,7 @@ local function checkReward(role, isTreasure) coinCount = (coinCount + coinDoubleCount) * expCoef items[ItemId.Gold] = math.floor((items[ItemId.Gold] or 0) + coinCount * (expCarbonData.money or 0)) items[ItemId.Exp] = math.floor((items[ItemId.Exp] or 0) + coinCount * (expCarbonData.exp or 0)) - items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + (coinCount * expCarbonData.playerExp or 0)) + items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + coinCount * (expCarbonData.playerExp or 0)) local pool = {} for _, temp in pairs(carbonData.item:toArray()) do @@ -127,8 +127,9 @@ local function checkReward(role, isTreasure) --挂机得到的宝藏加入到挂机奖励 if isTreasure or false == true then - local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId) - if next(treasureList) ~= nil then + carbonId = carbonId or hangInfo.carbonId + local treasureList = role.dailyData:checkTreasureList(carbonId) or {} + if treasureList and next(treasureList) ~= nil then for id, val in pairs(treasureList) do local award = val.award:toNumMap() for k,v in pairs(award) do @@ -171,7 +172,7 @@ function _M.startRpc( agent, data ) end end - if checkReward(role) then + if checkReward(role, true, carbonId) then role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) end diff --git a/src/models/Daily.lua b/src/models/Daily.lua index 7defc49..af8f2fd 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -155,18 +155,20 @@ end --资源 function Daily:checkTreasureBase(treasureList, treasureBase, removeId) local tmptreasure = {} + local num = 0 for k, val in pairs(treasureList) do if removeId and val.id == removeId then - table.remove(treasureList, k) + treasureList[k] = nil else if treasureBase >= val.treasure_value then treasureBase = treasureBase - val.treasure_value tmptreasure[val.id] = val + num = num + 1 end end end - return tmptreasure + return tmptreasure, num end --绑定通关关卡 @@ -177,14 +179,9 @@ function Daily:checkChapters() if next(treasureList) ~= nil then for id, curInfo in pairs(treasureList) do if curInfo["end_time"] then - if skynet.timex() >= curInfo["end_time"] then - curInfo = nil + if skynet.timex() < curInfo["end_time"] then + tmp_chapters[curInfo.chapter_id] = curInfo end - else - curInfo = nil - end - if curInfo ~= nil then - tmp_chapters[curInfo.chapter_id] = curInfo end end end @@ -207,16 +204,26 @@ end function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) local removeId local chapters = self:checkChapters() + local treasure if next(chapters) == nil then return end while next(tmptreasure) do - local tmp = self:checkTreasureBase(tmptreasure, treasureBase, removeId) - local id = math.randWeight(tmp, "weight") --宝藏id - if not id then + local tmp, num = self:checkTreasureBase(tmptreasure, treasureBase, removeId) + + if num == 0 then break + elseif num == 1 then + for _, val in pairs(tmp) do + treasure = val + end + else + local id = math.randWeight(tmp, "weight") --宝藏id + if not id then + break + end + treasure = tmp[id] end - - local treasure = tmp[id] + if treasureBase >= treasure.treasure_value then --扣除资源值 treasureBase = treasureBase - treasure.treasure_value @@ -229,8 +236,8 @@ function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) end treasure.chapter_id = chapterId - treasureList[id] = treasure - removeId = id + treasureList[treasure.id] = treasure + removeId = treasure.id end end @@ -249,49 +256,45 @@ function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) if not curInfo["end_time"] then curInfo["end_time"] = skynet.timex() + curInfo.working_time else - --宝藏冷却时间 - if not curInfo["expire_time"] then - --已挖到 - if skynet.timex() >= curInfo["end_time"] then - treasure = treasureList[curInfo.id] - if curInfo.cool_time > 1 then + if skynet.timex() >= curInfo["end_time"] then + if curInfo.cool_time > 1 then + --宝藏冷却时间 + if not curInfo["expire_time"] then + treasure = treasureList[curInfo.id] curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay else - curInfo["expire_time"] = skynet.timex() + --已经领取宝藏 检索宝藏冷却时间 + if skynet.timex() >= curInfo["expire_time"] then + treasureList[curInfo.id] = nil + end end - if skynet.timex() >= curInfo["expire_time"] then - table.remove(treasureList, curInfo.id) - end - end - else - --已经领取宝藏 检索宝藏冷却时间 - if skynet.timex() >= curInfo["expire_time"] then - table.remove(treasureList, curInfo.id) + else + treasure = treasureList[curInfo.id] + treasureList[curInfo.id] = nil end end end else --已经开始挖宝 if curInfo["end_time"] then - if not curInfo["expire_time"] then --宝藏冷却时间 - if skynet.timex() >= curInfo["end_time"] then --已挖到 - treasure = treasureList[curInfo.id] - if curInfo.cool_time > 1 then + if skynet.timex() >= curInfo["end_time"] then + if curInfo.cool_time > 1 then + --宝藏冷却时间 + if not curInfo["expire_time"] then + treasure = treasureList[curInfo.id] curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay else - curInfo["expire_time"] = skynet.timex() - end - if skynet.timex() >= curInfo["expire_time"] then - table.remove(treasureList, curInfo.id) + --已经领取宝藏 检索宝藏冷却时间 + if skynet.timex() >= curInfo["expire_time"] then + treasureList[curInfo.id] = nil + end end else - --未挖到直接删除 - table.remove(treasureList, curInfo.id) - end - else --已经领取宝藏 检索宝藏冷却时间 - if skynet.timex() >= curInfo["expire_time"] then - table.remove(treasureList, curInfo.id) + treasure = treasureList[curInfo.id] + treasureList[curInfo.id] = nil end + else + curInfo["end_time"] = nil end end end @@ -310,7 +313,7 @@ function Daily:buyTreasure(treasureList) boughtTreasurer[id] = val end end - self:updateProperty({field = "treasureBase", value = treasureBase}) + --self:updateProperty({field = "treasureBase", value = treasureBase}) return boughtTreasurer end @@ -322,7 +325,7 @@ end --宝藏图鉴 function Daily:getTreasrueList() local tmpcsv = csvdb["idle_treasureCsv"] - local treasureList = self:getProperty("treasureList") --挖宝列表 过期删除 领取奖励删除 跨天更新 + local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 local tmptreasure = {} local treasureBase = globalCsv.idle_treasure_base for id, val in pairs(tmpcsv) do @@ -343,7 +346,7 @@ end --检索挖宝列表 function Daily:checkTreasureList(chapterId) - local treasureList = self:getProperty("treasureList") + local treasureList = self:getProperty("treasureList") or {} local tmptreasure = {} for id, val in pairs(treasureList) do local treasure = self:checkTreasureChapterId(val, treasureList, chapterId) @@ -353,6 +356,7 @@ function Daily:checkTreasureList(chapterId) end if next(tmptreasure) == nil then + self:updateProperty({field = "treasureList", value = treasureList}) return nil end local boughtTreasurer = self:buyTreasure(tmptreasure) -- libgit2 0.21.2