local EventSystem = require('Event/EventSystem') local Base = require("Battle/Logic/Level/LevelFunction/LevelFunction") local DemonGodLevelFunction = class("DemonGodLevelFunction",Base) local AMY_MAX_DURATION_FRAME = DataSheetManager.ConstData:GetDataByID("DemonGodEachArmyTimeMax").IntValue * LuaConst.LogicFrameRate function DemonGodLevelFunction:GetExpClass() return require "Battle/Expression/ExpLevel/ExpLevelFunction/ExpDemonGodLevelFunction" end function DemonGodLevelFunction:InitLevel() self.armyCountdown = -1 LevelPlayerManager.SetCanSwitchHeroByCommand(false) --魔神玩法禁止手动切将 self.dmgToBoss = FP.newV1(0) self.heroDmgToBossDic = {} self.swithHeroCount = 0 Base.InitLevel(self) end function DemonGodLevelFunction:GetHeroDeadSwitchIndex() if self.swithHeroCount == 0 then return 2 elseif self.swithHeroCount == 1 then return 3 else return 1 end end function DemonGodLevelFunction:GetArmyDamageList() local armyDamageList = {0,0,0} for heroId,dmgFp in pairs(self.heroDmgToBossDic) do local armyPos = LevelPlayerManager.GetHeroArmyPos(LevelPlayerManager.MyPlayerIDInRoom, heroId) if armyPos == LuaConst.ArmyPosType.First then armyDamageList[1] = FP.tonumberV1(dmgFp) elseif armyPos == LuaConst.ArmyPosType.Second then armyDamageList[2] = FP.tonumberV1(dmgFp) elseif armyPos == LuaConst.ArmyPosType.Third then armyDamageList[3] = FP.tonumberV1(dmgFp) else logging.error(LTAG.ERROR, "HYW : armyPos value Error armyPos : ", armyPos) end end return armyDamageList end function DemonGodLevelFunction:OnUpdate() Base.OnUpdate(self) if self.isDmgToBossDirty then self.isDmgToBossDirty = false EventSystem.Dispatch(EventID.UIBattle_DmgToBossChanged) end self.armyCountdown = self.armyCountdown - 1 if self.armyCountdown == 0 then if self.swithHeroCount + 1 == self.armyCount then self:OnAllArmyFinish(false) else if self.swithHeroCount == 0 then LevelPlayerManager.SwitchHero(LevelPlayerManager.MyPlayerIDInRoom, 2, false, LuaConst.ESwitchHeroSource.FORCE_IGNORE_CD) --主视角safe,因为是单机玩法 EventSystem.Dispatch(EventID.UIBattle_Level_SetProgressBar, DataSheetManager.ConstData:GetDataByID("DemonGodEachArmyTimeMax").IntValue, "IDS_LevelLayout300041_Event54_ActionProgressName_1", false) elseif self.swithHeroCount == 1 then LevelPlayerManager.SwitchHero(LevelPlayerManager.MyPlayerIDInRoom, 3, false, LuaConst.ESwitchHeroSource.FORCE_IGNORE_CD) --主视角safe,因为是单机玩法 EventSystem.Dispatch(EventID.UIBattle_Level_SetProgressBar, DataSheetManager.ConstData:GetDataByID("DemonGodEachArmyTimeMax").IntValue, "IDS_LevelLayout300041_Event54_ActionProgressName_1", false) end end end end function DemonGodLevelFunction:OnCreatePlayer() Base.OnCreatePlayer(self) self.armyCountdown = AMY_MAX_DURATION_FRAME local entities = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LevelPlayerManager.MyPlayerIDInRoom)--主视角safe,因为是单机玩法 for i,entity in ipairs(entities) do self.heroDmgToBossDic[entity:GetCharacterID()] = FP.newV1(0) end self.armyCount = #entities end function DemonGodLevelFunction:OnHpChange(entity, caster, delta, op, realDelta) Base.OnHpChange(self) --魔神要求统计delta if delta < FP.Const.Zero and caster then local originCaster = caster:GetOriginEntity() if entity:IsBoss() and originCaster:IsHero() then self.dmgToBoss:Sub(delta) --统计正数 self.isDmgToBossDirty = true self.heroDmgToBossDic[originCaster:GetCharacterID()]:Sub(delta) --统计正数 end end end function DemonGodLevelFunction:OnSwitchHero(fromEntity, toEntity) Base.OnSwitchHero(self, fromEntity, toEntity) self.armyCountdown = AMY_MAX_DURATION_FRAME self.swithHeroCount = self.swithHeroCount + 1 end function DemonGodLevelFunction:OnPlayerOneHeroDead(entity) local isFinished = false --这段要先调↓ if self.swithHeroCount + 1 >= self.armyCount then isFinished = true self:OnAllArmyFinish(true) end --↑ Base.OnPlayerOneHeroDead(self ,entity) --这段要最后调↓ if isFinished then self:ShowVictoryPose() end --↑ end function DemonGodLevelFunction:OnAllArmyFinish(isBecauseDead) self.armyCountdown = -1 LevelItemManager.Global:HandleEndLevel(not isBecauseDead, not isBecauseDead) end return DemonGodLevelFunction