297 lines
7.7 KiB
Lua
297 lines
7.7 KiB
Lua
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 EDITOR_MODE then
|
|
data = {
|
|
today_challenge_count = 2,
|
|
max_chapter_gold_id = 2,
|
|
-- latest_chapter_gold_id = 1,-- todo 这是啥数据呢?
|
|
}
|
|
end
|
|
|
|
self:initAllDataClass()
|
|
self.dataDungeons[ModuleManager.MODULE_KEY.DUNGEON_GOLD]:init(data)
|
|
self.data.gold = data
|
|
self:setDirty()
|
|
end
|
|
|
|
-- 初始化碎片副本数据
|
|
function DungeonData:initDungeonShards(data)
|
|
if EDITOR_MODE then
|
|
data = {
|
|
today_challenge_count = 2,
|
|
max_chapter_shards_id = 2,
|
|
-- latest_chapter_shards_id = 1,
|
|
}
|
|
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
|
|
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: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:getOpenTime(moduleKey)
|
|
if not self.dataDungeons[moduleKey] then
|
|
return 0
|
|
end
|
|
|
|
local isClose = true
|
|
local count = 0
|
|
while isClose do
|
|
local checkWeek = Time:getWeekByTimeStamp(self: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(self: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
|
|
|
|
-- 获取看板展示的副本奖励
|
|
function DungeonData:getBoardShowRewards(moduleKey)
|
|
return nil
|
|
end
|
|
|
|
-- 获取展示副本首通奖励
|
|
function DungeonData:getFirstReward(moduleKey, id)
|
|
-- 通关后,不展示首通奖励
|
|
return self.dataDungeons[moduleKey]:getFirstReward(id)
|
|
end
|
|
|
|
-- 获取展示副本通关奖励
|
|
function DungeonData:getPassReward(moduleKey, id)
|
|
-- 波次奖励数量==通关+波次奖励数量
|
|
return self.dataDungeons[moduleKey]:getPassReward(id)
|
|
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
|
|
|
|
-- 获取副本开启时间描述
|
|
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
|
|
|
|
return DungeonData |