c1_lua/lua/app/userdata/dungeon/dungeon_armor_entity.lua
2023-07-20 17:41:42 +08:00

269 lines
6.9 KiB
Lua

local DungeonBaseEntity = require "app/userdata/dungeon/dungeon_base_entity"
local DungeonArmorEntity = class("DungeonArmorEntity", DungeonBaseEntity)
-- 支线副本数据
function DungeonArmorEntity:clear()
DataManager:unregisterCrossDayFunc("DungeonWeaponEntity")
end
function DungeonArmorEntity:init(data)
self.maxPassedId = data.max_challenge_id or 0
self.armorInfo = data.armor_info or {}
self.farmCount = data.farm_count or {}
self.heroes = data.heroes or {}
self.starRewards = data.star_rewards or {}
self.fundRewards = data.fund_rewards
self.giftInfo = data.gift_info
self.totalChallengeCount = data.total_challenge_count
DataManager.FormationData:initDungeonArmor(self.heroes)
DataManager:registerCrossDayFunc("DungeonArmorEntity", function()
self.farmCount = table.clear(self.farmCount)
self:setDirty()
end)
end
function DungeonArmorEntity:refreshInfoOnSettlement(chapterId, result)
self.totalChallengeCount[chapterId] = (self.totalChallengeCount[chapterId] or 0) + 1
self.maxPassedId = result.max_id
self.giftInfo = result.gift_info
self.armorInfo[chapterId] = result.armor_info
self:setDirty()
end
function DungeonArmorEntity:refreshInfoOnFarm(chapterId, result)
self.farmCount[chapterId] = (self.farmCount[chapterId] or 0) + 1
self.giftInfo = result.gift_info
self:setDirty()
end
function DungeonArmorEntity:getStarReward(starId)
self.starRewards[starId] = true
end
function DungeonArmorEntity:setDirty()
self.data.isDirty = not self.data.isDirty
end
function DungeonArmorEntity:getTotalChallengeCount()
local count = 0
for _, c in pairs(self.totalChallengeCount) do
count = count + 1
end
end
function DungeonArmorEntity:getTodayChallengeCount()
return 0
end
function DungeonArmorEntity:getPassedMaxId()
return self.maxPassedId
end
function DungeonArmorEntity:getIsAllTimeOpen()
return true
end
function DungeonArmorEntity:getModuleKey()
return ModuleManager.MODULE_KEY.DUNGEON_ARMOR
end
function DungeonArmorEntity:getConfig(chapterId)
return ConfigManager:getConfig(self:getConfigName())[chapterId]
end
function DungeonArmorEntity:getConfigName()
return "chapter_dungeon_armor"
end
function DungeonArmorEntity:getTitleString()
return I18N:getGlobalText(I18N.GlobalConst.DUNGEON_ARMOR_DESC_1)
end
function DungeonArmorEntity:getRuleString()
return I18N:getGlobalText(I18N.GlobalConst.DUNGEON_ARMOR_DESC_2)
end
function DungeonArmorEntity:getOpenWeekString()
return I18N:getGlobalText(I18N.GlobalConst.DUNGEON_ARMOR_DESC_3)
end
function DungeonArmorEntity:getBanner()
return "assets/arts/textures/background/dungeon/dungeon_bg_4.png"
end
function DungeonArmorEntity:getOpenTextColor()
return "#FFFFFF"
end
function DungeonArmorEntity:getChallengeHpCost()
return GFunc.getConstReward("dungeon_armor_limit")
end
function DungeonArmorEntity:isNoTotalLimit()
return true
end
function DungeonBaseEntity:isNotShowLimitCount()
return true
end
function DungeonArmorEntity:onClickFight()
ModuleManager.DungeonArmorManager:showMainUI()
end
function DungeonArmorEntity:getStagePassEnough(chapterId)
local config = self:getConfig(chapterId)
if not config then
return false
end
if config.main_chapter and not DataManager.ChapterData:getChapterPassed(config.main_chapter) then
return false
end
return true
end
function DungeonArmorEntity:canFightChapter(chapterId)
if not chapterId then
return false
end
if chapterId <= self.maxPassedId + 1 then
if self:getStagePassEnough(chapterId) then
return true
end
end
return false
end
function DungeonArmorEntity:canFarmChapter(chapterId)
if not chapterId then
return false
end
if self.maxPassedId >= chapterId then
if self:getStarNum(chapterId) >= 3 then
return true
end
end
return false
end
function DungeonArmorEntity:getDialyFarmLimit(chapterId)
local config = self:getConfig(chapterId)
if not config then
return 0
end
return config.sweep
end
function DungeonArmorEntity:getFarmCount(chapterId)
return self.farmCount[chapterId] or 0
end
function DungeonArmorEntity:getRemianFarmCount(chapterId)
local count = self:getDialyFarmLimit(chapterId) - self:getFarmCount(chapterId)
if count < 0 then
count = 0
end
return count
end
function DungeonArmorEntity:getStarRewardGot(star)
return self.starRewards[star]
end
function DungeonArmorEntity:getStarNum(chapterId)
if not self.armorInfo[chapterId] then
return 0
end
return #self.armorInfo[chapterId].stars
end
function DungeonArmorEntity:getAllStarNum()
if not self.armorInfo then
return 0
end
local count = 0
for id, info in pairs(self.armorInfo) do
count = count + #info.stars
end
return count
end
function DungeonArmorEntity:getMinStarTarget()
local count = ConfigManager:getConfigNum("chapter_dungeon_armor_reward")
local id
local nextTarget
for i = 1, count do
if not self:getStarRewardGot(i) then
id = i
nextTarget = ConfigManager:getConfig("chapter_dungeon_armor_reward")[id].star
break
end
end
if not id then -- 全部领完
id = count
nextTarget = ConfigManager:getConfig("chapter_dungeon_armor_reward")[id].star
return id, nextTarget, nextTarget
end
local starNum = self:getAllStarNum()
local lastStarNum = 0
local lastConfig = ConfigManager:getConfig("chapter_dungeon_armor_reward")[id - 1]
if lastConfig then -- 不是第一个
lastStarNum = lastConfig.star
end
local progress = starNum - lastStarNum
local totalProgress = nextTarget - lastStarNum
return id, progress, totalProgress
end
function DungeonArmorEntity:getStarDone(chapterId, index)
if not self.armorInfo[chapterId] then
return false
end
for i, info in ipairs(self.armorInfo[chapterId]) do
for _, star in ipairs(info.stars) do
if star == index then
return true
end
end
end
return false
end
function DungeonArmorEntity:getStarReward(chapterId, index)
local config = self:getConfig(chapterId)
return config.star_task_reward[index]
end
function DungeonArmorEntity:getStarStarId(chapterId, index)
local config = self:getConfig(chapterId)
return config.star_task[index - 1]
end
function DungeonArmorEntity:getStarInfo(chapterId)
return self.armorInfo[chapterId]
end
function DungeonArmorEntity:setCurFightChapterId(chapterId)
self.curFightchapterId = chapterId or 1
end
function DungeonArmorEntity:getCurFightChapterId()
return self.curFightchapterId or 1
end
function DungeonArmorEntity:getChapterFightCount(chapterId)
return self.totalChallengeCount[chapterId] or 0
end
return DungeonArmorEntity