-- 日常数据 local Daily = class("Daily", require("shared.ModelBaseMysql")) oneDay = 60*60*24 function Daily:ctor(properties) Daily.super.ctor(self, properties) end Daily.schema = { id = {"number", 0, "pri"}, -- 角色id commentHero = {"string", "", "blob"}, -- 单日评论食灵记录 type=1 hangQC = {"number", 0}, -- 挂机快速次数 dinerQC = {"number", 0}, -- 贩卖加速次数 advElC = {"number", 0}, -- 无尽次数(消耗体力) advBC = {"number", 0}, -- 冒险次数购买次数(冒险体力购买次数) advElBC = {"number", 0}, -- 无尽次数购买次数(冒险体力购买次数) advWs = {"table", {}}, -- 冒险队工坊 bonusC = {"table", {}}, -- 奖励副本 次数 {[type] = {c = 0, b = 0}} 修改为 {c=0, b=0} giveFP = {"table", {}}, -- 给谁送过心心 getFP = {"table", {}}, -- 领过谁的心心 pvpFree = {"number", 0}, -- pvp使用免费次数 pvpFreeH = {"number", 0}, -- 高级pvp使用免费次 pvpBought = {"number", 0}, -- 门票购买次数 dailySDC = {"table", {}}, -- daily shop diamond count {[id] = count} -- 每日商城购买次数统计 dailySDD = {"table", {}}, -- daily shop diamond disount {[id] = 1} -- 每日商城折扣统计 advSupRe = {"number", 0}, -- 冒险支援效果刷新次数 goldBuyT = {"number", 0}, -- 金币购买次数 unlockPool = {"table", {}}, -- 解锁的属性卡池 curPool = {"number", 0}, -- 属性卡池当前索引 drawHeroCnt = {"number", 0}, -- 每日抽卡次数 treasureBase = {"number", 0}, -- 资源值 treasureList = {"table", {}}, --挂机图鉴 chatTimes = {"number", 0}, --每日发言次数 } function Daily:updateProperty(params) local type, default = table.unpack(self.schema[params.field]) if params.delta then self:incrProperty(params.field, params.delta) if not params.notNotify then self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) end return true end if params.value then self:setProperty(params.field, params.value) if not params.notNotify then self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) end return true end return false end function Daily:refreshDailyData(notify) redisproxy:del(FRIEND_POINT:format(self.owner:getProperty("id"))) local dataMap = {} for field, schema in pairs(self.schema) do if field == "advElC" then if self:getProperty(field) > 0 then dataMap[field] = 0 end elseif field == "id" then -- skip elseif field == "treasureBase" then dataMap[field] = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum() elseif field == "treasureList" then dataMap[field] = self:getTreasrueList() elseif field == "pvpBought" then dataMap[field] = 0 elseif field ~= "key" then local typ, def = table.unpack(schema) dataMap[field] = def end end -- 每日折扣搞一下 local dailySDD = {} local sddPool = {} for id, data in pairs(csvdb["shop_normalCsv"]) do if data.shop == 1 and data.disount ~= 0 then table.insert(sddPool, id) end end for i = 1, math.min(#sddPool, globalCsv.shop_diamond_disount_count) do local idx = math.randomInt(1, #sddPool) dailySDD[sddPool[idx]] = 1 table.remove(sddPool, idx) end dataMap["dailySDD"] = dailySDD self:setProperties(dataMap) if notify then self.owner:notifyUpdateProperties(self:data()) 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"), dinerQC = self:getProperty("dinerQC"), advBC = self:getProperty("advBC"), advElC = self:getProperty("advElC"), advElBC = self:getProperty("advElBC"), advWs = self:getProperty("advWs"), bonusC = self:getProperty("bonusC"), giveFP = self:getProperty("giveFP"), getFP = self:getProperty("getFP"), pvpFree = self:getProperty("pvpFree"), pvpFreeH = self:getProperty("pvpFreeH"), pvpBought = self:getProperty("pvpBought"), dailySDC = self:getProperty("dailySDC"), dailySDD = self:getProperty("dailySDD"), advSupRe = self:getProperty("advSupRe"), goldBuyT = self:getProperty("goldBuyT"), unlockPool = self:getProperty("unlockPool"), curPool = self:getProperty("curPool"), treasureBase = self:getProperty("treasureBase"), treasureList = self:getProperty("treasureList"), chatTimes = self:getProperty("chatTimes"), } end return Daily