c1_lua/lua/app/userdata/dungeon/dungeon_data.lua
2023-06-13 18:44:47 +08:00

354 lines
9.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local DungeonData = class("DungeonData", BaseData)
-- 副本展示权重(由上到下排列)
local DUNGEON_SHOW_WEIGHT = {
[1] = ModuleManager.MODULE_KEY.DUNGEON_SHARDS,
[2] = ModuleManager.MODULE_KEY.DUNGEON_GOLD,
}
-- 所有活动副本数据
function DungeonData:ctor()
self.data.isDirty = false
end
function DungeonData:clear()
end
-- 初始化金币副本数据
function DungeonData:initDungeonGold(data)
if data == nil then
return
end
self:initAllDataClass()
self.dataDungeons[ModuleManager.MODULE_KEY.DUNGEON_GOLD]:init(data)
self.data.gold = data
self:setDirty()
end
-- 初始化碎片副本数据
function DungeonData:initDungeonShards(data)
if data == nil then
return
end
self:initAllDataClass()
self.dataDungeons[ModuleManager.MODULE_KEY.DUNGEON_SHARDS]:init(data)
self.data.shards = data
self:setDirty()
end
-- 初始化所有副本数据类
function DungeonData:initAllDataClass()
if self.dataDungeons == nil then
self.dataDungeons = {}
self.dataDungeons[ModuleManager.MODULE_KEY.DUNGEON_GOLD] = require "app/userdata/dungeon/dungeon_gold_data_comp":create()
self.dataDungeons[ModuleManager.MODULE_KEY.DUNGEON_SHARDS] = require "app/userdata/dungeon/dungeon_shards_data_comp":create()
end
self.initDay = Time:getBeginningOfServerToday()
end
function DungeonData:getIfCanReset()
return self.initDay < Time:getBeginningOfServerToday()
end
-- 跨天处理
function DungeonData:onDayChange()
self.data.gold.today_challenge_count = 0
self.data.shards.today_challenge_count = 0
self:initDungeonGold(self.data.gold)
self:initDungeonGold(self.data.shards)
end
-- 客户端处理副本次数+1的情况
function DungeonData:onFightCountReduce(moduleKey)
if moduleKey == ModuleManager.MODULE_KEY.DUNGEON_GOLD then
self.data.gold.today_challenge_count = self.data.gold.today_challenge_count + 1
self:initDungeonGold(self.data.gold)
elseif moduleKey == ModuleManager.MODULE_KEY.DUNGEON_SHARDS then
self.data.shards.today_challenge_count = self.data.shards.today_challenge_count + 1
self:initDungeonGold(self.data.shards)
end
end
function DungeonData:setDirty()
self.data.isDirty = not self.data.isDirty
end
-- 是否开启任意一个副本
function DungeonData:isOpenAnyone()
for key, value in pairs(self.dataDungeons) do
if self:isOpen(key) then
return true
end
end
return false
end
-- 某副本是否已开启
function DungeonData:isOpen(moduleKey)
if not ModuleManager:getIsOpen(moduleKey, true) then
return false
end
return true
end
-- 返回已开启的副本
function DungeonData:getOpenDungeons()
local openDungeons = {}
for idx, moduleKey in pairs(DUNGEON_SHOW_WEIGHT) do
if self:isOpen(moduleKey) then
table.insert(openDungeons, moduleKey)
end
end
if EDITOR_MODE then
Logger.logHighlight("已开启副本:")
Logger.printTable(openDungeons)
end
return table.revert(openDungeons)
end
-- 是否在活动副本时间内
function DungeonData:isActive(moduleKey)
if not self:isOpen(moduleKey) then
return false
end
-- 判断周期
if self:isActiveCycle(moduleKey, Time:getWeekByTimeStamp()) then
return true
else
return false
end
end
-- 判断是否在活跃周期内
function DungeonData:isActiveCycle(moduleKey, checkWeek)
if not self.dataDungeons[moduleKey] then
return false
end
for index, week in ipairs(self.dataDungeons[moduleKey]:getOpenWeekCycle()) do
if week == checkWeek then
return true
end
end
return false
end
-- 是否任意一个副本可以挑战
function DungeonData:isCanChallengeAnyone()
for key, value in pairs(self.dataDungeons) do
if self:isCanChallenge(key) then
return true
end
end
return false
end
-- 副本是否可以挑战
function DungeonData:isCanChallenge(moduleKey)
if not self:isActive(moduleKey) then
return false
end
if not (self:getRemainTimes(moduleKey) > 0) then
return false
end
if not self:isEnoughHp(moduleKey) then
return false
end
return true
end
-- 副本是否可以扫荡
function DungeonData:isCanSweep(moduleKey, id)
if not self:isActive(moduleKey) then
return false
end
if not (self:getRemainTimes(moduleKey) > 0) then
return false
end
if not self:isEnoughHp(moduleKey) then
return false
end
if not self:getPassedMaxId(moduleKey) >= id then
return false
end
return true
end
-- 获取副本挑战总次数
function DungeonData:getTotalCount(moduleKey)
return self.dataDungeons[moduleKey]:getTotalChallengeCount()
end
-- 获取副本今日剩余次数
function DungeonData:getRemainTimes(moduleKey)
if not self:isActive(moduleKey) then
return 0
end
if not self.dataDungeons[moduleKey] then
return 0
end
return self.dataDungeons[moduleKey]:getTodayRemainLimitCount()
end
-- 体力是否足够
function DungeonData:isEnoughHp(moduleKey)
local const = self:getChallengeHpCost(moduleKey)
local constNum = 0
if const then
constNum = GFunc.getRewardNum(const)
end
return constNum <= DataManager.BagData.ItemData:getVit()
end
-- 获取挑战体力消耗
function DungeonData:getChallengeHpCost(moduleKey)
if not self:isActive(moduleKey) then
return 0
end
if not self.dataDungeons[moduleKey] then
return 0
end
return self.dataDungeons[moduleKey]:getChallengeHpCost()
end
-- 获取副本下个状态改变时间
function DungeonData:geNextTime(moduleKey)
if self:isActive(moduleKey) then
return self:getCloseTime(moduleKey)
else
return self:getOpenTime(moduleKey)
end
end
-- 获取副本开启倒计时
function DungeonData:getOpenTime(moduleKey)
if not self.dataDungeons[moduleKey] then
return 0
end
local isClose = true
local count = 0
while isClose do
local checkWeek = Time:getWeekByTimeStamp(Time:getServerTime() + ((count + 1) * 86400))
if self:isActiveCycle(moduleKey, checkWeek) then
isClose = false
else
count = count + 1
end
end
return Time:getTodaySurplusTime() + (count * 86400)
end
-- 获取副本关闭倒计时
function DungeonData:getCloseTime(moduleKey)
if not self.dataDungeons[moduleKey] then
return 0
end
local isActive = true
local count = 0
while isActive do
local checkWeek = Time:getWeekByTimeStamp(Time:getServerTime() + ((count + 1) * 86400))
if not self:isActiveCycle(moduleKey, checkWeek) then
isActive = false
else
count = count + 1
end
end
return Time:getTodaySurplusTime() + (count * 86400)
end
-- 获取看板展示的副本奖励(返回icon)
function DungeonData:getBoardShowRewardIcon(moduleKey)
return self.dataDungeons[moduleKey]:getBoardShowRewardIcon()
end
-- 获取看板展示的副本奖励返回item id list
function DungeonData:getBoardShowRewardId(moduleKey)
return self.dataDungeons[moduleKey]:getBoardShowRewardId()
end
-- 获取展示副本首通奖励个数
function DungeonData:getFirstRewardNum(moduleKey, id)
-- 通关后,不展示首通奖励
return self.dataDungeons[moduleKey]:getFirstRewardNum(id)
end
-- 获取展示副本通关奖励个数
function DungeonData:getPassRewardNum(moduleKey, id)
return self.dataDungeons[moduleKey]:getPassRewardNum(id)
end
--获取副本已解锁最大id
function DungeonData:getUnlockMaxId(moduleKey)
local id = self.dataDungeons[moduleKey]:getPassedMaxId() + 1
if id > self:getConfigMaxId(moduleKey) then
id = id - 1
end
return id
end
-- 获取副本配置的最高关卡
function DungeonData:getConfigMaxId(moduleKey)
return #self.dataDungeons[moduleKey]:getConfig()
end
--获取副本已通关的最高关卡id
function DungeonData:getPassedMaxId(moduleKey)
return self.dataDungeons[moduleKey]:getPassedMaxId()
end
-- 获取副本标题文案
function DungeonData:getTitle(moduleKey)
return self.dataDungeons[moduleKey]:getTitleString()
end
-- 获取副本规则描述
function DungeonData:getRule(moduleKey)
return self.dataDungeons[moduleKey]:getRuleString()
end
-- 获取副本当前关卡buff
function DungeonData:getBossBuff(moduleKey, id)
return self.dataDungeons[moduleKey]:getBossBuff(id)
end
-- 获取副本开启时间描述
function DungeonData:getOpenTimeDesc(moduleKey)
return self.dataDungeons[moduleKey]:getOpenWeekString()
end
-- 获取副本角标图
function DungeonData:getIcon(moduleKey)
return self.dataDungeons[moduleKey]:getIcon()
end
-- 获取副本banner图
function DungeonData:getBanner(moduleKey)
return self.dataDungeons[moduleKey]:getBanner()
end
-- 获取开启时间文本颜色
function DungeonData:getOpenTextColor(moduleKey)
return self.dataDungeons[moduleKey]:getOpenTextColor()
end
function DungeonData:setCurFightChapterId(chapterId)
self.curFightchapterId = chapterId or 1
end
function DungeonData:getCurFightChapterId()
return self.curFightchapterId or 1
end
return DungeonData