From ecf875630fc00c38d800c7a8d2e5f3e6dbb77ac3 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Wed, 12 Jan 2022 11:01:02 +0800 Subject: [PATCH] feat: 挂机图鉴的扩展功能——额外宝藏奖励 --- src/ProtocolCode.lua | 2 ++ src/actions/GmAction.lua | 37 ++++++++++++++++++++++++++++++++++++- src/actions/HangAction.lua | 31 ++++++++++++++++++++++++------- src/actions/RoleAction.lua | 36 ++++++++++++++++++++++++++++++++++++ src/models/Daily.lua | 311 ++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/models/DailyPlugin.lua | 402 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/RoleLog.lua | 1 + 7 files changed, 515 insertions(+), 305 deletions(-) create mode 100644 src/models/DailyPlugin.lua diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index d5d6591..8955a50 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -67,6 +67,8 @@ actionCodes = { Role_itemConvertDevilTicketRpc = 148, -- 兑换魔鬼训练营门票 Role_unRegisterRpc = 149, --注销账号 Role_searchAllRoleRpc = 150, --查询所有服的角色信息 + Role_takeTreasureRpc = 151, --抓取额外宝藏 + Role_treasureMapRpc = 152, --兑换宝藏图 Adv_startAdvRpc = 151, Adv_startHangRpc = 152, diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index d4f3a35..f2eded0 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -1008,7 +1008,7 @@ function _M.treasure(role, pms) dump(treasureList) return "宝藏图鉴" elseif pm1 == "FLUSH" then - local treasureList= role.dailyData:getTreasrueList(role) + local treasureList= role.dailyData:getTreasureList(role) dump(treasureList) return "宝藏图鉴" elseif pm1 == "CHECK" then @@ -1171,5 +1171,40 @@ function _M.draw_code(role, pms) return ret end +table.insert(helpDes, {"抓取额外宝藏", "treasure_extra"}) +function _M.treasure_extra(role, pms) + local extraCount = role.dailyData:getProperty("treasureExtraCount") --每日发现额外宝藏使用次数(累计),隔天清零 + local mapCount = role.dailyData:getProperty("treasureMapCount") + local baseExtra = role.dailyData:getProperty("treasureBaseExtra") + + if extraCount >= globalCsv.idle_treasure_extra_limie then return 1 end + if mapCount <= 0 then return 2 end + + baseExtra = baseExtra + globalCsv.idle_treasure_base_extra + + local tmpTreasure, treasureListExtra = role.dailyData:getTreasureExtra(baseExtra) + + dump(tmpTreasure) + dump(treasureListExtra) + if not tmpTreasure then return 3 end + + role.dailyData:updateProperty({field = "treasureExtraCount", delta = 1}) + role.dailyData:updateProperty({field = "treasureBaseExtra", value = mapCount - 1}) + role.dailyData:updateProperty({field = "treasureBaseExtra", value = baseExtra}) + + return "成功" +end + +table.insert(helpDes, {"兑换宝藏图", "treasure_map"}) +function _M.treasure_map(role, pms) + local count = tonumber(pms.pm1 or 1) + local cost ={[ItemId.Jade] = globalCsv.idle_treasure_buy * count} + if not role:checkItemEnough(cost) then return -1 end + if not role:costItems(cost, {log = {desc = "treasureMap", int1 = count}}) then return -2 end + role.dailyData:updateProperty({field = "treasureMapCount", delta = 1*count}) + + local treasureMapCount = role.dailyData:getProperty("treasureMapCount") + return treasureMapCount +end return _M \ No newline at end of file diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 0cbe140..bb45436 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -125,10 +125,18 @@ local function checkReward(role, isTreasure, carbonId) randomItem() end - --挂机得到的宝藏加入到挂机奖励 - if isTreasure or false == true then - local treasureList= role.dailyData:checkTreasureList(carbonId or hangInfo.carbonId) or {} - for _, val in pairs(treasureList) do + --挂机得到的宝藏加入到挂机奖励 + 额外宝藏奖励 + if isTreasure then + local treasureList= role.dailyData:checkTreasureList(carbonId or hangInfo.carbonId) + for _, val in pairs(treasureList or {}) do + local award = val.award:toNumMap() + for k,v in pairs(award) do + items[k] = (items[k] or 0) + v + end + end + + treasureList = role.dailyData:checkTreasureListExtra(carbonId or hangInfo.carbonId) + for _, val in pairs(treasureList or {}) do local award = val.award:toNumMap() for k,v in pairs(award) do items[k] = (items[k] or 0) + v @@ -339,7 +347,7 @@ function _M.endBattleRpc(agent, data) --刷新宝藏图鉴 if isWin and globalCsv.idle_treasure_point and globalCsv.idle_treasure_point == carbonId then - role.dailyData:getTreasrueList() + role.dailyData:getTreasureList() end role:updateProperty({field = "hangInfo", value = hangInfo}) @@ -513,8 +521,17 @@ function _M.quickRpc(agent , data) end --宝藏加速 - local treasureList = role.dailyData:quickTreasureList(hangInfo.carbonId, time) or {} - for id, val in pairs(treasureList) do + local treasureList = role.dailyData:quickTreasureList(hangInfo.carbonId, time) + for _, val in pairs(treasureList or {}) do + local award = val.award:toNumMap() + for k,v in pairs(award) do + reward[k] = (reward[k] or 0) + v + end + end + + --额外宝藏加速 + treasureList = role.dailyData:quickTreasureListExtra(hangInfo.carbonId, time) + for _, val in pairs(treasureList or {}) do local award = val.award:toNumMap() for k,v in pairs(award) do reward[k] = (reward[k] or 0) + v diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index c61741f..ff579b8 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1900,4 +1900,40 @@ function _M.itemConvertDevilTicketRpc(agent, data) return true end +function _M.takeTreasureRpc(agent, data) + local role = agent.role + local extraCount = role.dailyData:getProperty("treasureExtraCount") --每日发现额外宝藏使用次数(累计),隔天清零 + local mapCount = role.dailyData:getProperty("treasureMapCount") + local baseExtra = role.dailyData:getProperty("treasureBaseExtra") + + if extraCount >= globalCsv.idle_treasure_extra_limie then return 1 end + if mapCount <= 0 then return 2 end + + baseExtra = baseExtra + globalCsv.idle_treasure_base_extra + + local tmpTreasure, treasureListExtra = role.dailyData:getTreasureExtra(baseExtra) + if not tmpTreasure then return 3 end + + role.dailyData:updateProperty({field = "treasureExtraCount", delta = 1}) + role.dailyData:updateProperty({field = "treasureBaseExtra", value = mapCount - 1}) + role.dailyData:updateProperty({field = "treasureBaseExtra", value = baseExtra}) + + SendPacket(actionCodes.Role_takeTreasureRpc, MsgPack.pack({treasureListExtra = treasureListExtra, treasure = tmpTreasure})) + return true +end + +function _M.treasureMapRpc(agent,data) + local role = agent.role + local msg = MsgPack.unpack(data) + local count = msg.count or 1 + local cost ={[ItemId.Jade] = globalCsv.idle_treasure_buy * count} + if not role:checkItemEnough(cost) then return 1 end + if not role:costItems(cost, {log = {desc = "treasureMap", int1 = count}}) then return 2 end + role.dailyData:updateProperty({field = "treasureMapCount", delta = 1*count}) + + local treasureMapCount = role.dailyData:getProperty("treasureMapCount") + SendPacket(actionCodes.Role_treasureMapRpc, MsgPack.pack({mapCount = treasureMapCount})) + return true +end + return _M \ No newline at end of file diff --git a/src/models/Daily.lua b/src/models/Daily.lua index a674d30..b6e9f91 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -1,8 +1,8 @@ -- 日常数据 local Daily = class("Daily", require("shared.ModelBaseMysql")) - -oneDay = 60*60*24 +local DailyPlugin = import(".DailyPlugin") --宝藏相关 +DailyPlugin.bind(Daily) function Daily:ctor(properties) Daily.super.ctor(self, properties) @@ -37,6 +37,11 @@ Daily.schema = { treasureBase = {"number", 0}, -- 资源值 treasureList = {"table", {}}, --挂机图鉴 + treasureListExtra = {"table", {}}, --额外宝藏,挂机图鉴扩展功能 + treasureMapCount = {"number", 0}, --宝藏图,消耗一张宝藏图可以发现一次额外宝藏 + treasureExtraCount = {"number", 0}, --每日发现额外宝藏使用次数(累计),隔天清零 + treasureBaseExtra = {"number", 0}, --额外宝藏资源值 + chatTimes = {"number", 0}, --每日发言次数 } @@ -73,7 +78,9 @@ function Daily:refreshDailyData(notify) elseif field == "treasureBase" then dataMap[field] = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum() elseif field == "treasureList" then - dataMap[field] = self:getTreasrueList() + dataMap[field] = self:getTreasureList() + elseif field == "treasureExtraCount" then + dataMap[field] = 0 elseif field == "pvpBought" then dataMap[field] = 0 elseif field ~= "key" then @@ -101,300 +108,6 @@ function Daily:refreshDailyData(notify) end end ---解锁 -function Daily:checkUnlock(treaval) - local role = self.owner - local treasureC = treaval.unlock:toArray(true, "=") - local show = false - if treasureC[1] == 1 then --通关关卡 - show = self.owner:checkHangPass(treasureC[2]) - elseif treasureC[1] == 2 then --通关拾荒章节=x层 - show = role:checkAdvChapterPass(treasureC[2]) - elseif treasureC[1] == 3 then --拥有指定id的角色时 - local hero = role:getHeroByID(treasureC[2]) - if hero then show = true end - else - show = true - end - return show -end - ---CD -function Daily:checkTreasureExpired(treasureAttr, treasureList) - local curInfo = treasureList[treasureAttr.id] - if curInfo then - -- check finish - if curInfo["expire_time"] then - if curInfo.cool_time > 1 then - if skynet.timex() >= curInfo["expire_time"] then - treasureList[treasureAttr.id] = nil - curInfo = clone(treasureAttr) - elseif skynet.timex() >= curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 - curInfo = nil - else - curInfo = clone(treasureAttr) - end - else - if skynet.timex() >= curInfo["expire_time"] then - treasureList[treasureAttr.id] = nil - end - curInfo = clone(treasureAttr) - end - end - else - curInfo = clone(treasureAttr) - end - - return curInfo -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 - 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, num -end - ---绑定通关关卡 -function Daily:checkChapters() - local chapters = {} - local tmp_chapters = {} - local treasureList = self:getProperty("treasureList") - if next(treasureList) then - for _, curInfo in pairs(treasureList) do - if curInfo["expire_time"] or not curInfo["end_time"] then - tmp_chapters[curInfo.chapter_id] = curInfo - end - end - end - local hangInfo = self.owner:getProperty("hangInfo") or {} - for chapter_id, val in pairs(csvdb["idle_battleCsv"]) do - if chapter_id ~= hangInfo.carbonId then - if self.owner:checkHangPass(chapter_id) then - if next(tmp_chapters) and not tmp_chapters[chapter_id] then - chapters[chapter_id] = val - else - chapters[chapter_id] = val - end - end - end - - end - return chapters -end - ---权重 -function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) - local removeId - local chapters = self:checkChapters() - local treasure - if next(chapters) == nil then return end - - --扣除在挖宝列表里未过期宝藏的资源值 - for _, val in pairs(treasureList) do - if not val["expire_time"] then - treasureBase = treasureBase - val["treasure_value"] - end - end - - while next(tmptreasure) do - 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 - - if treasureBase >= treasure.treasure_value then - --扣除资源值 - treasureBase = treasureBase - treasure.treasure_value - else - break - end - local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id - if not chapterId then - break - end - - treasure.chapter_id = chapterId - treasureList[treasure.id] = treasure - removeId = treasure.id - end -end - ---chapterId -function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) - local treasure = nil - - if not curInfo then - return treasure - end - local treasureBase = self:getProperty("treasureBase") - - --开始挖宝关卡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["end_time"] then - if curInfo.cool_time > 1 then - --宝藏冷却时间 - if not curInfo["expire_time"] then - if treasureBase >= curInfo["treasure_value"] then - treasureBase = treasureBase - curInfo["treasure_value"] - - treasure = treasureList[curInfo.id] - curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay - end - else - --已经领取宝藏 检索宝藏冷却时间 - if skynet.timex() >= curInfo["expire_time"] then - treasureList[curInfo.id] = nil - end - end - else - if treasureBase >= curInfo["treasure_value"] then - treasureBase = treasureBase - curInfo["treasure_value"] - - treasure = treasureList[curInfo.id] - treasureList[curInfo.id] = nil - end - end - end - end - else - --已经开始挖宝 - if curInfo["end_time"] then - if skynet.timex() >= curInfo["end_time"] then - if curInfo.cool_time > 1 then - --宝藏冷却时间 - if not curInfo["expire_time"] then - if treasureBase >= curInfo["treasure_value"] then - treasureBase = treasureBase - curInfo["treasure_value"] - - treasure = treasureList[curInfo.id] - curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay - end - - else - --已经领取宝藏 检索宝藏冷却时间 - if skynet.timex() >= curInfo["expire_time"] then - treasureList[curInfo.id] = nil - end - end - else - if treasureBase >= curInfo["treasure_value"] then - treasureBase = treasureBase - curInfo["treasure_value"] - - treasure = treasureList[curInfo.id] - treasureList[curInfo.id] = nil - end - end - else - curInfo["end_time"] = nil - end - end - end - return treasure -end - -function Daily:buyTreasure(treasureList) - local boughtTreasurer = {} - local treasureBase = self:getProperty("treasureBase") - for id, val in pairs(treasureList) do - if treasureBase >= val.treasure_value then - boughtTreasurer[id] = val - treasureBase = treasureBase - val.treasure_value - end - end - self:updateProperty({field = "treasureBase", value = treasureBase}) - return boughtTreasurer -end - ---重置宝藏图鉴 -function Daily:resetTreasureList() - self:updateProperty({field = "treasureList", value = {}}) -end - ---宝藏图鉴 -function Daily:getTreasrueList() - local tmpcsv = csvdb["idle_treasureCsv"] - local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 - local tmptreasure = {} - local treasureBase = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum() - for id, val in pairs(tmpcsv) do - if self:checkUnlock(val) == true then - local treasure = self:checkTreasureExpired(val, treasureList) - if treasure then - table.insert(tmptreasure, treasure) - end - end - end - table.sort(tmptreasure, function (a,b) return a.treasure_value > b.treasure_value end) - - self:checkTreasureWeight(treasureList, tmptreasure, treasureBase) - self:updateProperty({field = "treasureList", value = treasureList}) - self:updateProperty({field = "treasureBase", value = treasureBase}) - return treasureList -end - - ---检索挖宝列表 -function Daily:checkTreasureList(chapterId) - local treasureList = self:getProperty("treasureList") or {} - local tmptreasure = {} - for id, val in pairs(treasureList) do - local treasure = self:checkTreasureChapterId(val, treasureList, chapterId) - if treasure ~= nil then - tmptreasure[id] = treasure - end - end - - if next(tmptreasure) == nil then - self:updateProperty({field = "treasureList", value = treasureList}) - return nil - end - local boughtTreasurer = self:buyTreasure(tmptreasure) - self:updateProperty({field = "treasureList", value = treasureList}) - return boughtTreasurer -end - ---宝藏加速 -function Daily:quickTreasureList(chapterId, time) - local treasureList = self:getProperty("treasureList") or {} - if next(treasureList) then - for id, val in pairs(treasureList) do - if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then - val["end_time"] = val["end_time"] - time - end - end - end - self:updateProperty({field = "treasureList", value = treasureList}) - return self:checkTreasureList(chapterId) -end - function Daily:data() return { hangQC = self:getProperty("hangQC"), @@ -417,6 +130,10 @@ function Daily:data() curPool = self:getProperty("curPool"), treasureBase = self:getProperty("treasureBase"), treasureList = self:getProperty("treasureList"), + treasureListExtra = self:getProperty("treasureListExtra"), + treasureMapCount = self:getProperty("treasureMapCount"), + treasureExtraCount = self:getProperty("treasureExtraCount"), + treasureBaseExtra = self:getProperty("treasureBaseExtra"), chatTimes = self:getProperty("chatTimes"), } end diff --git a/src/models/DailyPlugin.lua b/src/models/DailyPlugin.lua new file mode 100644 index 0000000..9e70938 --- /dev/null +++ b/src/models/DailyPlugin.lua @@ -0,0 +1,402 @@ + +local DailyPlugin = {} +oneDay = 60*60*24 +function DailyPlugin.bind(Daily) + --解锁 + function Daily:checkUnlock(treaval) + local role = self.owner + local treasureC = treaval.unlock:toArray(true, "=") + if treasureC[1] == 1 then --通关关卡 + return self.owner:checkHangPass(treasureC[2]) + elseif treasureC[1] == 2 then --通关拾荒章节=x层 + return role:checkAdvChapterPass(treasureC[2]) + elseif treasureC[1] == 3 then --拥有指定id的角色时 + local hero = role:getHeroByID(treasureC[2]) + if hero then return true end + else + return true + end + return false + end + + --CD + function Daily:checkTreasureExpired(treasureAttr, treasureList) + local curInfo = treasureList[treasureAttr.id] + if curInfo then + -- check finish + if curInfo["expire_time"] then + if curInfo.cool_time > 1 then + if skynet.timex() >= curInfo["expire_time"] then + treasureList[treasureAttr.id] = nil + curInfo = clone(treasureAttr) + elseif skynet.timex() >= curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 + curInfo = nil + else + curInfo = clone(treasureAttr) + end + else + if skynet.timex() >= curInfo["expire_time"] then + treasureList[treasureAttr.id] = nil + end + curInfo = clone(treasureAttr) + end + end + else + curInfo = clone(treasureAttr) + end + + return curInfo + end + + --绑定通关关卡 + function Daily:checkChapters(treasureList, treasureListOther) + local chapters = {} + local tmp_chapters = {} + + for _, curInfo in pairs(treasureList or {}) do + if curInfo["expire_time"] or not curInfo["end_time"] then + tmp_chapters[curInfo.chapter_id] = curInfo + end + end + + for _, curInfo in pairs(treasureListOther or {}) do + if curInfo["expire_time"] or not curInfo["end_time"] then + tmp_chapters[curInfo.chapter_id] = curInfo + end + end + + local hangInfo = self.owner:getProperty("hangInfo") or {} + for chapter_id, val in pairs(csvdb["idle_battleCsv"]) do + if chapter_id ~= hangInfo.carbonId then + if self.owner:checkHangPass(chapter_id) then + if next(tmp_chapters) and not tmp_chapters[chapter_id] then + chapters[chapter_id] = val + else + chapters[chapter_id] = val + end + end + end + + end + return chapters + end + + --权重 + function Daily:checkTreasureWeight(treasureList, tmpTreasure, treasureBase, treasureListOther) + local chapters = self:checkChapters(treasureList, treasureListOther) + if not chapters or not next(chapters) then return end + + --扣除在挖宝列表里未过期宝藏的资源值 + for _, val in pairs(treasureList) do + if not val["expire_time"] then + treasureBase = treasureBase - val["treasure_value"] + end + end + + if tmpTreasure and next(tmpTreasure) then + table.sort(tmpTreasure, function (a, b) return a.treasure_value > b.treasure_value end) + end + + local treasure + while next(tmpTreasure or {}) do + local tmp = {} + local tmpBase = treasureBase + for _, val in pairs(tmpTreasure) do + if tmpBase >= val.treasure_value then + tmpBase = tmpBase - val.treasure_value + tmp[val.id] = val + end + end + if not next(tmp) then break end + + local id = math.randWeight(tmp, "weight") --宝藏id + if not id then break end + + treasure = tmp[id] + if treasureBase < treasure.treasure_value then break end + --扣除资源值 + treasureBase = treasureBase - treasure.treasure_value + + local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id + if not chapterId then break end + + treasure.chapter_id = chapterId + treasureList[treasure.id] = treasure + + tmpTreasure[treasure.id] = nil + chapters[chapterId] = nil + end + end + + --只抓一个 额外宝藏 + function Daily:getOneTreasureExtra(treasureList, tmpTreasure, treasureBase, treasureListOther) + local chapters = self:checkChapters(treasureList, treasureListOther) + if not chapters or not next(chapters) then return end + + --扣除在挖宝列表里未过期宝藏的资源值 + for _, val in pairs(treasureList) do + if not val["expire_time"] then + treasureBase = treasureBase - val["treasure_value"] + end + end + + if tmpTreasure and next(tmpTreasure) then + table.sort(tmpTreasure, function (a, b) return a.treasure_value > b.treasure_value end) + end + + local treasure + local tmp = {} + local tmpBase = treasureBase + for _, val in pairs(tmpTreasure) do + if tmpBase >= val.treasure_value then + tmpBase = tmpBase - val.treasure_value + tmp[val.id] = val + end + end + if not next(tmp) then return end + + local id = math.randWeight(tmp, "weight") --宝藏id + if not id then return end + + treasure = tmp[id] + if treasureBase < treasure.treasure_value then return end + --扣除资源值 + treasureBase = treasureBase - treasure.treasure_value + + local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id + if not chapterId then return end + + + treasure.chapter_id = chapterId + treasureList[treasure.id] = treasure + + return treasure + end + + --chapterId + function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId, treasureBase) + if not curInfo then return nil end + + local treasure = nil + --开始挖宝关卡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["end_time"] then + if curInfo.cool_time > 1 then + --宝藏冷却时间 + if not curInfo["expire_time"] then + if treasureBase >= curInfo["treasure_value"] then + treasureBase = treasureBase - curInfo["treasure_value"] + + treasure = treasureList[curInfo.id] + curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay + end + else + --已经领取宝藏 检索宝藏冷却时间 + if skynet.timex() >= curInfo["expire_time"] then + treasureList[curInfo.id] = nil + end + end + else + if treasureBase >= curInfo["treasure_value"] then + treasureBase = treasureBase - curInfo["treasure_value"] + + treasure = treasureList[curInfo.id] + treasureList[curInfo.id] = nil + end + end + end + end + else + --已经开始挖宝 + if curInfo["end_time"] then + if skynet.timex() >= curInfo["end_time"] then + if curInfo.cool_time > 1 then + --宝藏冷却时间 + if not curInfo["expire_time"] then + if treasureBase >= curInfo["treasure_value"] then + treasureBase = treasureBase - curInfo["treasure_value"] + + treasure = treasureList[curInfo.id] + curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay + end + + else + --已经领取宝藏 检索宝藏冷却时间 + if skynet.timex() >= curInfo["expire_time"] then + treasureList[curInfo.id] = nil + end + end + else + if treasureBase >= curInfo["treasure_value"] then + treasureBase = treasureBase - curInfo["treasure_value"] + + treasure = treasureList[curInfo.id] + treasureList[curInfo.id] = nil + end + end + else + curInfo["end_time"] = nil + end + end + end + return treasure + end + + function Daily:buyTreasure(treasureList) + local boughtTreasure = {} + local treasureBase = self:getProperty("treasureBase") + for id, val in pairs(treasureList) do + if treasureBase >= val.treasure_value then + boughtTreasure[id] = val + treasureBase = treasureBase - val.treasure_value + end + end + self:updateProperty({field = "treasureBase", value = treasureBase}) + return boughtTreasure + end + + --重置宝藏图鉴 + function Daily:resetTreasureList() + self:updateProperty({field = "treasureList", value = {}}) + self:updateProperty({field = "treasureListExtra", value = {}}) + end + + --宝藏图鉴 + function Daily:getTreasureList() + local tmpcsv = csvdb["idle_treasureCsv"] + local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 + local treasureListExtra = self:getProperty("treasureListExtra") or {} --额外宝藏列表 过期删除 领取奖励删除 跨天更新 + local tmpTreasure = {} + local treasureBase = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum() + for _, val in pairs(tmpcsv) do + if self:checkUnlock(val) == true then + local treasure = self:checkTreasureExpired(val, treasureList) + if treasure then + table.insert(tmpTreasure, treasure) + end + end + end + + if not next(tmpTreasure) then return treasureList end + + self:checkTreasureWeight(treasureList, tmpTreasure, treasureBase, treasureListExtra) + self:updateProperty({field = "treasureList", value = treasureList}) + self:updateProperty({field = "treasureBase", value = treasureBase}) + return treasureList + end + + + --检索挖宝列表 获得宝藏 + function Daily:checkTreasureList(chapterId) + local treasureList = self:getProperty("treasureList") or {} + local treasureBase = self:getProperty("treasureBase") or {} + local tmpTreasure = {} + for id, val in pairs(treasureList) do + local treasure = self:checkTreasureChapterId(val, treasureList, chapterId, treasureBase) + if treasure then + tmpTreasure[id] = treasure + end + end + + if not next(tmpTreasure) then + self:updateProperty({field = "treasureList", value = treasureList}) + return nil + end + local boughtTreasure = self:buyTreasure(tmpTreasure) + self:updateProperty({field = "treasureList", value = treasureList}) + return boughtTreasure + end + + --宝藏加速 + function Daily:quickTreasureList(chapterId, time) + local treasureList = self:getProperty("treasureList") or {} + if next(treasureList) then + for _, val in pairs(treasureList) do + if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then + val["end_time"] = val["end_time"] - time + end + end + end + self:updateProperty({field = "treasureList", value = treasureList}) + return self:checkTreasureList(chapterId) + end + + --宝藏功能优化——增加"发现宝藏"功能 + function Daily:buyTreasureExtra(treasureList) + local boughtTreasure = {} + local treasureBase = self:getProperty("treasureExtraBase") + for id, val in pairs(treasureList) do + if treasureBase >= val.treasure_value then + boughtTreasure[id] = val + treasureBase = treasureBase - val.treasure_value + end + end + self:updateProperty({field = "treasureExtraBase", value = treasureBase}) + return boughtTreasure + end + + function Daily:getTreasureExtra(tmpBaseExtra) + local tmpcsv = csvdb["idle_treasureCsv"] + local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 + local treasureListExtra = self:getProperty("treasureListExtra") or {} --额外宝藏 过期删除 领取奖励删除 跨天更新 + + local tmpTreasure = {} + for _, val in pairs(tmpcsv) do + if self:checkUnlock(val) then + local treasure = self:checkTreasureExpired(val, treasureListExtra) + if treasure then + table.insert(tmpTreasure, treasure) + end + end + end + if not next(tmpTreasure) then return nil, treasureListExtra end + + local tmp = self:getOneTreasureExtra(treasureListExtra, tmpTreasure, tmpBaseExtra, treasureList) + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) + return tmp, treasureListExtra + end + + --检索宝藏列表 获得额外宝藏 + function Daily:checkTreasureListExtra(chapterId) + local treasureListExtra = self:getProperty("treasureListExtra") or {} + local treasureBaseExtra = self:getProperty("treasureBaseExtra") or {} + local tmpTreasure = {} + for id, val in pairs(treasureListExtra) do + local treasure = self:checkTreasureChapterId(val, treasureListExtra, chapterId, treasureBaseExtra) + if treasure then + tmpTreasure[id] = treasure + end + end + + if next(tmpTreasure) then + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) + return nil + end + + local boughtTreasure = self:buyTreasureExtra(tmpTreasure) + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) + return boughtTreasure + end + + --额外宝藏加速 + function Daily:quickTreasureListExtra(chapterId, time) + local treasureListExtra = self:getProperty("treasureListExtra") or {} + if next(treasureListExtra) then + for _, val in pairs(treasureListExtra) do + if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then + val["end_time"] = val["end_time"] - time + end + end + end + + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) + return self:checkTreasureListExtra(chapterId) + end +end + + +return DailyPlugin \ No newline at end of file diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index b653287..8e7500e 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -74,6 +74,7 @@ local ItemReason = { regularWorldBossMilestone = 158, -- 常规世界boss伤害里程碑 regularWorldBossBattle = 159, -- 常规世界boss战斗奖励 itemConvertDevilTicket = 160, -- 兑换魔鬼训练营门票 + treasureMap = 161, --虹光玉兑换宝藏图 -- libgit2 0.21.2