From 1199daf93d7c3ac2618479aab6a38ab04f339653 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Thu, 22 Apr 2021 17:05:07 +0800 Subject: [PATCH] fix: 挂机图鉴, 增加宝藏CD检查 --- src/actions/HangAction.lua | 18 +++++++++++------- src/models/Daily.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 59 insertions(+), 29 deletions(-) diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 602b833..8bc66e4 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) +local function checkReward(role, isTreasure) local hangInfo = role:getProperty("hangInfo") if not hangInfo.carbonId or not hangInfo.coinTime or not hangInfo.itemTime then return false @@ -126,11 +126,15 @@ local function checkReward(role) end --挂机得到的宝藏加入到挂机奖励 - local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId) - for id, val in pairs(treasureList) do - local award = val.award:toNumMap() - for k,v in pairs(award) do - items[k] = (award[k] or 0) + v + if isTreasure or false == true then + local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId) + if next(treasureList) ~= nil then + for id, val in pairs(treasureList) do + local award = val.award:toNumMap() + for k,v in pairs(award) do + items[k] = (award[k] or 0) + v + end + end end end @@ -418,7 +422,7 @@ end function _M.getRewardRpc(agent , data) local role = agent.role local hangTime = getHangTime(role) - checkReward(role) + checkReward(role, true) local items = role:getProperty("hangBag") if not next(items) then return end local reward, change = role:award(items, {log = {desc = "hangReward"}}) diff --git a/src/models/Daily.lua b/src/models/Daily.lua index d34c1ed..71a00a5 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -128,13 +128,13 @@ function Daily:checkTreasureExpired(treasureAttr, treasureList) -- check finish if curInfo["expire_time"] then if curInfo.cool_time > 1 then - if skynet.timex() > curInfo["expire_time"] then --已过期 + if skynet.timex() >= curInfo["expire_time"] then --已过期 treasureList[treasureAttr.id] = nil elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 curInfo = nil end else - if skynet.timex() > curInfo["expire_time"] then + if skynet.timex() >= curInfo["expire_time"] then treasureList[treasureAttr.id] = nil end end @@ -168,7 +168,6 @@ function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) local removeId while next(tmptreasure) do local tmp = self:checkTreasureBase(tmptreasure, treasureBase, removeId) - print(treasureBase) local id = math.randWeight(tmp, "weight") --宝藏id if not id then break @@ -202,28 +201,55 @@ function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) return treasure end - if chapterId == curInfo.chapter_id then --开始挖宝关卡ID=挂机关卡ID - if not curInfo["expire_time"] then - if curInfo.cool_time > 1 then - curInfo["expire_time"] = skynet.timex() + curInfo.working_time + curInfo.cool_time * oneDay - else - curInfo["expire_time"] = skynet.timex() + curInfo.working_time - end + --开始挖宝关卡ID=挂机关卡ID + if chapterId == curInfo.chapter_id then + --开始挖宝 + if not curInfo["end_time"] then + curInfo["end_time"] = skynet.timex() + curInfo.working_time else - if skynet.timex() > curInfo["expire_time"] then --已过期 - treasure = table.remove(treasureList, curInfo.id) - elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 - treasure = curInfo + --宝藏冷却时间 + if not curInfo["expire_time"] then + --已挖到 + if skynet.timex() >= curInfo["end_time"] then + treasure = treasureList[curInfo.id] + if curInfo.cool_time > 1 then + 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) + end + end + else + --已经领取宝藏 检索宝藏冷却时间 + if skynet.timex() >= curInfo["expire_time"] then + table.remove(treasureList, curInfo.id) + end end end else - if curInfo["expire_time"] then - if skynet.timex() > curInfo["expire_time"] then --已过期 - treasure = table.remove(treasureList, curInfo.id) - elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 - treasure = curInfo - else - curInfo["expire_time"] = nil + --已经开始挖宝 + 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 + 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) + end + else + --未挖到直接删除 + table.remove(treasureList, curInfo.id) + end + else --已经领取宝藏 检索宝藏冷却时间 + if skynet.timex() >= curInfo["expire_time"] then + table.remove(treasureList, curInfo.id) + end end end end @@ -236,7 +262,7 @@ function Daily:buyTreasure(treasureList) for id, val in pairs(treasureList) do treasureBase = treasureBase - val.treasure_value if treasureBase < 0 then - treasureBase = treasureBase + val.treasure_value + treasureBase = treasureBase + val.treasure_value print("资源余额不足") return else -- libgit2 0.21.2