diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index e004b64..f22fa88 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -984,5 +984,27 @@ function _M.drawHero(role, t, act) return result end +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 + 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)) + end + return "挖宝成功" + elseif pm1 == "RESET" then + role.dailyData:resetTreasureList() + return "重置宝藏图鉴" + else + return "暂无指令: ".. pm1 + end +end return _M \ No newline at end of file diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 3c6bacb..5d423ed 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -114,6 +114,15 @@ local function checkReward(role) randomItem() 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 + end + end + if coinCount > 0 or itemCount > 0 then return true end diff --git a/src/models/Daily.lua b/src/models/Daily.lua index cdef0dd..d34c1ed 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -2,6 +2,8 @@ local Daily = class("Daily", require("shared.ModelBaseMysql")) +oneDay = 60*60*24 + function Daily:ctor(properties) Daily.super.ctor(self, properties) end @@ -30,6 +32,8 @@ Daily.schema = { unlockPool = {"table", {}}, -- 解锁的属性卡池 curPool = {"number", 0}, -- 属性卡池当前索引 drawHeroCnt = {"number", 0}, -- 每日抽卡次数 + + treasureList = {"table", {}}, --挂机图鉴 } function Daily:updateProperty(params) @@ -60,6 +64,8 @@ function Daily:refreshDailyData(notify) if self:getProperty(field) > 0 then dataMap[field] = 0 end + elseif field == "treasureList" then + dataMap[field] = self:getTreasrueList() elseif field ~= "key" then local typ, def = table.unpack(schema) dataMap[field] = def @@ -85,6 +91,211 @@ 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 --通关关卡 + if not self.owner:checkHangPass(treasureC[2]) then show = true end + elseif treasureC[1] == 2 then --通关拾荒章节=x层 + local chapterId = treasureC[2] + local layer = 1 + local advCsv = csvdb["adv_chapterCsv"][chapterId] + if not advCsv then return false end --不存在的章节 + if math.floor(chapterId / 100) ~= 2 then + layer = math.min(layer, advCsv.limitlevel) + end + local advPass = role:getProperty("advPass") + if (advPass[chapterId] or 0) < layer then + show = false + else + show = true + end + 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 + elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 + curInfo = nil + end + else + if skynet.timex() > curInfo["expire_time"] then + treasureList[treasureAttr.id] = nil + end + end + end + else + curInfo = clone(treasureAttr) + end + + return curInfo +end + +--资源 +function Daily:checkTreasureBase(treasureList, treasureBase, removeId) + local tmptreasure = {} + for k, val in pairs(treasureList) do + if removeId and val.id == removeId then + table.remove(treasureList, k) + else + if treasureBase >= val.treasure_value then + treasureBase = treasureBase - val.treasure_value + tmptreasure[val.id] = val + end + end + + end + return tmptreasure +end + +--权重 +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 + end + + local treasure = tmp[id] + if treasureBase >= treasure.treasure_value then + --扣除资源值 + treasureBase = treasureBase - treasure.treasure_value + else + break + end + + local chapterId = math.randWeight(csvdb["idle_battleCsv"], "treasure_weight") --关卡id + if not chapterId then + break + end + + treasure.chapter_id = chapterId + treasureList[id] = treasure + removeId = id + end +end + +--chapterId +function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) + local treasure = nil + + if not curInfo then + print("curInfo is nil") + 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 + 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 + 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 + end + end + end + return treasure +end + +function Daily:buyTreasure(treasureList) + local boughtTreasurer = {} + local treasureBase = globalCsv.idle_treasure_base + for id, val in pairs(treasureList) do + treasureBase = treasureBase - val.treasure_value + if treasureBase < 0 then + treasureBase = treasureBase + val.treasure_value + print("资源余额不足") + return + else + boughtTreasurer[id] = val + end + end + self:updateProperty({field = "treasureBase", value = treasureBase}) + return boughtTreasurer +end + +--重置宝藏图鉴 +function Daily:resetTreasureList() + self:updateProperty({field = "treasureList", value = {}}) +end + +--宝藏图鉴 +function Daily:getTreasrueList() + print("宝藏图鉴...") + local tmpcsv = csvdb["idle_treasureCsv"] + local treasureList = self:getProperty("treasureList") --挖宝列表 过期删除 领取奖励删除 跨天更新 + local tmptreasure = {} + local treasureBase = globalCsv.idle_treasure_base + 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}) + return treasureList +end + + +--检索挖宝列表 +function Daily:checkTreasureList(chapterId) + print("检索挖宝列表") + local treasureList = self:getProperty("treasureList") + 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 + print("宝藏列表为空") + return nil + end + local boughtTreasurer = self:buyTreasure(tmptreasure) + self:updateProperty({field = "treasureList", value = treasureList}) + return boughtTreasurer +end + function Daily:data() return { hangQC = self:getProperty("hangQC"), @@ -104,6 +315,7 @@ function Daily:data() goldBuyT = self:getProperty("goldBuyT"), unlockPool = self:getProperty("unlockPool"), curPool = self:getProperty("curPool"), + treasureList = self:getProperty("treasureList"), } end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index d180432..1b0c72b 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -636,6 +636,15 @@ function RolePlugin.bind(Role) return count end + function Role:getHeroByID(heroId) + for id, hero in pairs(self.heros) do + if id == heroId then + return hero + end + end + return nil + end + function Role:loadHeros() local roleId = self:getProperty("id") -- libgit2 0.21.2