168 lines
4.7 KiB
Lua
168 lines
4.7 KiB
Lua
local DungeonMaterialData = class("DungeonMaterialData", BaseData)
|
|
|
|
local FIRST_CHAPTER_ID = 2001
|
|
|
|
function DungeonMaterialData:ctor()
|
|
self.data.isDirty = false
|
|
self.data.maxPassed = 0
|
|
self.data.times = 0
|
|
self.data.challengeId = 0
|
|
end
|
|
|
|
function DungeonMaterialData:setDirty()
|
|
self.data.isDirty = not self.data.isDirty
|
|
end
|
|
|
|
function DungeonMaterialData:init(data)
|
|
data = data or GConst.EMPTY_TABLE
|
|
self.data.maxPassed = data.max_passed or 0 -- 最大通关的副本id
|
|
self.data.itemTimes = data.item_times or 0 -- 今日道具挑战次数
|
|
if self.data.maxPassed <= 0 then -- 一关都没打过
|
|
self.data.challengeId = FIRST_CHAPTER_ID
|
|
else
|
|
local info = self:getConfig()[self.data.maxPassed]
|
|
if info then
|
|
local nextId = info.next_chapter
|
|
if nextId then
|
|
self.data.challengeId = nextId
|
|
else
|
|
self.data.challengeId = self.data.maxPassed
|
|
end
|
|
else
|
|
self.data.maxPassed = 0
|
|
self.data.challengeId = FIRST_CHAPTER_ID
|
|
end
|
|
end
|
|
self.data.times = data.times or 0 -- 今日剩余挑战次数
|
|
end
|
|
|
|
function DungeonMaterialData:isOpen(showToast)
|
|
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.DUNGEON_RES, not showToast) then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
function DungeonMaterialData:getModuleKey()
|
|
return ModuleManager.MODULE_KEY.DUNGEON_RES
|
|
end
|
|
|
|
function DungeonMaterialData:getConfig()
|
|
if self._chapterCungeonCfg == nil then
|
|
self._chapterCungeonCfg = ConfigManager:getConfig("chapter_dungeon")
|
|
end
|
|
return self._chapterCungeonCfg
|
|
end
|
|
|
|
function DungeonMaterialData:getAllChaptersInfo()
|
|
if self._allChaptersInfo == nil then
|
|
self._allChaptersInfo = {}
|
|
local cfg = ConfigManager:getConfig("chapter_dungeon")
|
|
for k, v in pairs(cfg) do
|
|
if v.type == 2 then
|
|
table.insert(self._allChaptersInfo, {
|
|
id = k,
|
|
cfg = v
|
|
})
|
|
end
|
|
end
|
|
table.sort(self._allChaptersInfo, function (a, b)
|
|
return a.id < b.id
|
|
end)
|
|
end
|
|
return self._allChaptersInfo
|
|
end
|
|
|
|
--只显示已通关 + 目前通关往后的十个
|
|
function DungeonMaterialData:getLimitChaptersInfo()
|
|
local list = self:getAllChaptersInfo()
|
|
local limitList = {}
|
|
for i,v in ipairs(list) do
|
|
if self.data.maxPassed + 10 >= v.id or i <= 10 then
|
|
table.insert(limitList, v)
|
|
end
|
|
end
|
|
return limitList
|
|
end
|
|
|
|
function DungeonMaterialData:getChapterInfo(index)
|
|
return self:getAllChaptersInfo()[index]
|
|
end
|
|
|
|
function DungeonMaterialData:getMaxPassedId()
|
|
return self.data.maxPassed
|
|
end
|
|
|
|
function DungeonMaterialData:getChallengeId()
|
|
return self.data.challengeId
|
|
end
|
|
|
|
function DungeonMaterialData:getTodayMaxTimes()
|
|
if self._dungeonMaterialTimes == nil then
|
|
self._dungeonMaterialTimes = GFunc.getConstIntValue("dungeon_res_times")
|
|
end
|
|
if DataManager.PrivilegeCardData:getIsChallegeCardActive() then
|
|
return self._dungeonMaterialTimes + self:getPrivilegeCardAddTimes()
|
|
else
|
|
return self._dungeonMaterialTimes
|
|
end
|
|
end
|
|
|
|
function DungeonMaterialData:getPrivilegeCardAddTimes()
|
|
if self._privilegeCardAddTimes == nil then
|
|
self._privilegeCardAddTimes = GFunc.getConstIntValue("card_fight_res")
|
|
end
|
|
return self._privilegeCardAddTimes
|
|
end
|
|
|
|
function DungeonMaterialData:getTodayRemainTimes()
|
|
local maxTimes = self:getTodayMaxTimes()
|
|
local times = maxTimes - self.data.times
|
|
if times < 0 then
|
|
times = 0
|
|
end
|
|
return times
|
|
end
|
|
|
|
function DungeonMaterialData:getChapterName(chapterId)
|
|
return I18N:getConfig("chapter_dungeon")[chapterId].name
|
|
end
|
|
|
|
function DungeonMaterialData:onFightDungeonDailyFinish(chapterId, victory)
|
|
if not victory then
|
|
return
|
|
end
|
|
if self.data.maxPassed < chapterId then
|
|
local info = self:getConfig()[chapterId]
|
|
if info then
|
|
self.data.maxPassed = chapterId
|
|
local nextId = info.next_chapter
|
|
if nextId then
|
|
self.data.challengeId = nextId
|
|
else
|
|
self.data.challengeId = self.data.maxPassed
|
|
end
|
|
end
|
|
end
|
|
self.data.times = self.data.times + 1
|
|
self:setDirty()
|
|
end
|
|
|
|
function DungeonMaterialData:onSweepDungeonDailyFinish()
|
|
self.data.times = self.data.times + 1
|
|
self:setDirty()
|
|
end
|
|
|
|
function DungeonMaterialData:getIsShowRedPoint()
|
|
if not self:isOpen() then
|
|
return false
|
|
end
|
|
return self:getTodayRemainTimes() > 0
|
|
end
|
|
|
|
function DungeonMaterialData:onCrossDay()
|
|
self.data.times = 0
|
|
self:setDirty()
|
|
end
|
|
|
|
return DungeonMaterialData |