local EventSystem = require('Event/EventSystem') local Base = require("Battle/Logic/Level/LevelFunction/LevelFunction") local BossChallengeLevelFunction = class("BossChallengeLevelFunction",Base) local private = { } function BossChallengeLevelFunction:InitLevel() Base.InitLevel(self) self.allArmyPosBuffs = nil self.isBuffAdded = false self.bossHpPercentRecords = {} --记录所有的boss的hp百分比 end function BossChallengeLevelFunction:CreatePlayers(pos,dir) Base.CreatePlayers(self,pos,dir) if LevelPlayerManager.buffIdList then local entityTable = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_PLAYER_PlayID) --预先计算出buff self:CalculateBuff(LevelPlayerManager.buffIdList,entityTable) end end function BossChallengeLevelFunction:CalculateBuff(levelBuffIdList,entityTable) --计算出全军生效的buff self.allArmyPosBuffs = self:CalculateAllArmyPosBuff(levelBuffIdList,entityTable) --计算出同路军生效的buff self.armyPos2BuffDic = {} for i,entity in ipairs(entityTable) do self.armyPos2BuffDic[i] = self:CalculateBuffOfArmyPos(levelBuffIdList,entityTable[i]) end end function BossChallengeLevelFunction:CalculateBuffOfArmyPos(levelBuffIdList,entity) local buffs = {} local buffData = nil for i,buffId in ipairs(levelBuffIdList) do buffData = DataSheetManager.BuffData:GetDataByBuffID(buffId) if buffData then if buffData.ArmyFilter == LuaConst.EArmyFilter.SAME_ARMY_POS then if BuffManager.IsMeetHeroTypeFilterOfBuff(buffData,entity:GetCharacterID()) then table.insert(buffs,buffId) --策划需求是如果主副将都触发了buff,则该buff会被叠加两次,所以下面还会insert end if BuffManager.IsMeetHeroTypeFilterOfBuff(buffData,entity.components.adjutant:GetAdjutantCharacterID()) then table.insert(buffs,buffId) --策划需求是如果主副将都触发了buff,则该buff会被叠加两次,所以上面也insert了 end elseif buffData.ArmyFilter == LuaConst.EArmyFilter.SELF then if BuffManager.IsMeetHeroTypeFilterOfBuff(buffData,entity:GetCharacterID()) then table.insert(buffs,buffId) end end end end return buffs end function BossChallengeLevelFunction:CalculateAllArmyPosBuff(levelBuffIdList,entityTable) local allArmyPosBuff = {} local buffData = nil for i,buffId in ipairs(levelBuffIdList) do buffData = DataSheetManager.BuffData:GetDataByBuffID(buffId) if buffData and buffData.ArmyFilter == LuaConst.EArmyFilter.WHOLE_ARMIES then for j,entity in ipairs(entityTable) do --策划需求是所有主副将触发的buff都可以叠加,所以这里必须遍历完所有entity以及其副将,不能break if BuffManager.IsMeetHeroTypeFilterOfBuff(buffData,entity:GetCharacterID()) then table.insert(allArmyPosBuff,buffId) end if BuffManager.IsMeetHeroTypeFilterOfBuff(buffData,entity.components.adjutant:GetAdjutantCharacterID()) then table.insert(allArmyPosBuff,buffId) end end end end return allArmyPosBuff end function BossChallengeLevelFunction:AddLevelBuff(entity,armyPos) if self.allArmyPosBuffs then for i,buffId in ipairs(self.allArmyPosBuffs) do SystemManager.AddBuff(entity,buffId, entity, nil, nil) end end if self.armyPos2BuffDic then if self.armyPos2BuffDic[armyPos] then for i,buffId in ipairs(self.armyPos2BuffDic[armyPos]) do SystemManager.AddBuff(entity,buffId, entity, nil, nil) end end end end function BossChallengeLevelFunction:OnUpdate() --延迟3帧添加关卡buff,用这个简便方法解决buff图标不显示的问题 if LogicUpdateManager._clientHandleFrame > 3 and not self.isBuffAdded then self.isBuffAdded = true local entityTable = LevelPlayerManager.GetPlayerEntitysByPlayerIDInRoom(LuaConst.STANDALONE_PLAYER_PlayID) --添加Buff for i,entity in ipairs(entityTable) do self:AddLevelBuff(entity,i) end end end --获取boss剩余血量百分比 function BossChallengeLevelFunction:GetBossHpLeftPercent() if #self.bossHpPercentRecords > 0 then local hpPercent = FP.newV1(0) for i, record in ipairs(self.bossHpPercentRecords) do hpPercent:Add(record.hpPercent) end hpPercent:Div(#self.bossHpPercentRecords) return FP.tonumberV1(hpPercent) else return 1 end end function BossChallengeLevelFunction:GetBossHpRecord(bossEntityID) local bossHpRecord = nil for i,record in ipairs(self.bossHpPercentRecords) do if record.entityID == bossEntityID then bossHpRecord = record break end end if not bossHpRecord then bossHpRecord = {entityID = bossEntityID, hpPercent = FP.newV1(0)} table.insert(self.bossHpPercentRecords, bossHpRecord) end return bossHpRecord end function BossChallengeLevelFunction:OnHpChange(entity, caster) Base.OnHpChange(self, entity, caster) if entity:IsBoss() then local bossHpRecord = self:GetBossHpRecord(entity.EntityID) bossHpRecord.hpPercent:Reset(entity.components.attr:HitPointPercents()) end end return BossChallengeLevelFunction