local BattleController = require "app/module/battle/controller/battle_controller"
local BattleControllerFullMoonSkin = class("BattleControllerFullMoonSkin", BattleController)

function BattleControllerFullMoonSkin:getBoardConfig()
    return ConfigManager:getConfig("chapter_board_dungeon_shards")
end

function BattleControllerFullMoonSkin:getChapterConfig()
    return ConfigManager:getConfig("chapter_new_skin_fight")
end

function BattleControllerFullMoonSkin:getChapterId()
    return DataManager.FullMoonData:getCurSkinChallengeId()
end

function BattleControllerFullMoonSkin:initOther()
    local chapterId = DataManager.ChapterData:getMaxChapterId()
    if chapterId <= 0 then
        chapterId = DataManager.ChapterData.MIN_CHAPTER_ID
    end
    local cfg = ConfigManager:getConfig("chapter")[chapterId]
    self.monsterAtkAddition = 0
    self.monsterHpAddition = 0
    if cfg and cfg.daily_challenge_difficulty then
        self.monsterAtkAddition = cfg.daily_challenge_difficulty[2]
        self.monsterHpAddition = cfg.daily_challenge_difficulty[1]
    end
end

-- 怪物攻击力加成
function BattleControllerFullMoonSkin:getMonsterAtkAddition()
	return self.monsterAtkAddition
end

-- 怪物血量加成
function BattleControllerFullMoonSkin:getMonsterHpAddition()
	return self.monsterHpAddition
end

function BattleControllerFullMoonSkin:controllBattleEnd()
    self.combatReport = {
        battleType = GConst.BattleConst.BATTLE_TYPE.FULL_MOON_SKIN,
        wave = self:getWaveIndex(),
        victory = self.victory,
    }
    local atkReport = {}
    local teamEntity = self.battleData:getAtkTeam()
    local members = teamEntity:getAllMembers()
    for k, v in pairs(members) do
        local report = {
            heroId = v:getId(),
            dmg = v:getDamageCount(),
        }
        table.insert(atkReport, report)
    end
    self.combatReport.atkReport = atkReport
    BIReport:postFightHeroReport(self.combatReport.battleType, atkReport)
    ModuleManager.FullMoonManager:reqChapterSkinClaim(self.chapterId, self.combatReport)
end

function BattleControllerFullMoonSkin:postWaveOver(atkDead, isQuit)
    local deathType = BIReport.FIGHT_DEATH_TYPE.SURVIVE
    local waveEndType = BIReport.FIGHT_WAVE_END_TYPE.WIN
    if atkDead then
        if self.isBossWave then
            deathType = BIReport.FIGHT_DEATH_TYPE.BOSS_FAIL
        else
            deathType = BIReport.FIGHT_DEATH_TYPE.NORMAL_FAIL
        end
        waveEndType = BIReport.FIGHT_WAVE_END_TYPE.FAIL
    end

    if isQuit then
        waveEndType = BIReport.FIGHT_WAVE_END_TYPE.QUIT
    end

    local duration = self.waveDurationTime
    local totalTime = self.totalDurationTime
    local isFianlStep = self:getWaveIndex() >= self.maxWaveIndex

    BIReport:postFightEnd(GConst.BattleConst.BATTLE_TYPE.FULL_MOON_SKIN, self.battleData, self.chapterId, self:getWaveIndex(), duration, totalTime, self.eliminateCount, self.eliminateTotalCount, waveEndType, deathType, 0, true, isFianlStep, self.maxLinkCount)
end

function BattleControllerFullMoonSkin:postFightStart()
    BIReport:postFightBegin(GConst.BattleConst.BATTLE_TYPE.FULL_MOON_SKIN, self:getWaveIndex(), self.chapterId, 0, 0)
end

return BattleControllerFullMoonSkin