--逐鹿中原(大乱斗)第二层 local EventSystem = require('Event/EventSystem') local Base = require("Battle/Logic/Level/LevelFunction/FightThroneBaseLevelFunction") local FightThroneSecondFloorLevelFunction = class("FightThroneSecondFloorLevelFunction",Base) function FightThroneSecondFloorLevelFunction:InitLevel() Base.InitLevel(self) self.shouldSnatchShard = true self.bossDmgInfoDic = {} --key 是boss的entityID,value是一个list,元素是{playerID, dmg}(玩家对这个boss造成的伤害) self.bossDmgSortList = {} --boss伤害排序列表 self.isBossDead = true --boss是否已经死了。初始没刷boss的时候就认为是死亡,所以默认值为true self.beforeEndLevelOk = false -- 是否已经执行过BeforeEndLevel end function FightThroneSecondFloorLevelFunction:ChangeCollectAmountOfPlayer(entity, playerID, delta) Base.ChangeCollectAmountOfPlayerByCollectKey(self, entity, playerID, 2, delta) end function FightThroneSecondFloorLevelFunction:OnPlayerActived(playerID) Base.OnPlayerActived(self, playerID) SystemManager.SetFightMode(playerID, LuaConst.EFightMode.TEAM_GUILD, true) end function FightThroneSecondFloorLevelFunction:OnEntityBorn(entity) Base.OnEntityBorn(self, entity) if entity:IsBoss() then self.isBossDead = false end end function FightThroneSecondFloorLevelFunction:QuitRoom(entity) Base.QuitRoom(self, entity) -- 清空其对boss伤害 if entity.isHero then self.bossDmgInfoDic[entity:GetPlayerID()] = nil end end -- 统计英雄对boss的伤害量 function FightThroneSecondFloorLevelFunction:OnHpChange(entity, caster, delta, op) if op == "sub" and delta < FP.Const.Zero then -- 先不考虑加血的情况 ,如果有 ,需要改下面代码 if entity.isBoss then local dmgDealer = caster:GetOriginEntity() if dmgDealer.isHero then local dmgDealerPlayerID = dmgDealer:GetPlayerID() local dmg = self.bossDmgInfoDic[dmgDealerPlayerID] if dmg == nil then self.bossDmgInfoDic[dmgDealerPlayerID] = FP.newV1(-1):Mul(delta) else dmg:Sub(delta) end end end end Base.OnHpChange(self, entity, caster, delta, op) end local bossDmgInfoSorter = function(a, b) return a.dmg > b.dmg end function FightThroneSecondFloorLevelFunction:OnBossDead(entity) Base.OnBossDead(self, entity) self.isBossDead = true if self.beforeEndLevelOk then return end -- 给排名最靠前的玩家添加旗帜 self:SortBossDmg() self:AddFlagToHighestBossDmg() end function FightThroneSecondFloorLevelFunction:SortBossDmg() table.clear(self.bossDmgSortList) for playerID, dmg in pairs(self.bossDmgInfoDic) do -- pairs safe table.insert(self.bossDmgSortList, {playerID = playerID, dmg = dmg}) end table.sort(self.bossDmgSortList, bossDmgInfoSorter) end function FightThroneSecondFloorLevelFunction:AddFlagToHighestBossDmg() for i = 1, #self.bossDmgSortList do local playerID = self.bossDmgSortList[i].playerID if self:GetFlagAmountOfPlayer(playerID) <= 0 then local entity = LevelPlayerManager.GetPlayerActiveEntity(playerID) self:ChangeFlagAmountOfPlayer(entity, playerID, 1) break end end end function FightThroneSecondFloorLevelFunction:BeforeEndLevel() Base.BeforeEndLevel(self) self.beforeEndLevelOk = true if self.isBossDead then return end -- 给排名最靠前的玩家添加旗帜 self:SortBossDmg() self:AddFlagToHighestBossDmg() end function FightThroneSecondFloorLevelFunction:GetDamageList() return self.bossDmgInfoDic end return FightThroneSecondFloorLevelFunction