local Base = require("Battle/Logic/Level/LevelFunction/SyncLevelFunction") local private = {} local LevelRecordManager = require("Battle/Logic/Level/LevelRecordManager") local SyncGuildBossLevelFunction = class("SyncGuildBossLevelFunction",Base) local EventSystem = require('Event/EventSystem') local EStatisticType = LuaConst.EStatisticType function SyncGuildBossLevelFunction:InitLevel() Base.InitLevel(self) self.isFreeToEnterAndLeave = true --如果是随进随出,必须在Base.InitLevel之后把这个设为true self.dontIgnoreEnemy = true --不使用忽略敌人机制,节省性能 self.formulaAdaptiveVar = LevelManager.GetServerLevel() if not self.formulaAdaptiveVar then logging.error(LTAG.ERROR, "HYW : 致命错误! 没有设置服务器等级,无法计算军团boss数值自适应") self.formulaAdaptiveVar = 1 end end function SyncGuildBossLevelFunction:OnPlayerActived(playerID) Base.OnPlayerActived(self, playerID) local firstEntity = LevelPlayerManager.GetPlayerActiveEntity(playerID) SystemManager.StartAutoFight(firstEntity) end function SyncGuildBossLevelFunction:GetLevelAutoFightInitRule() --不调用base return LuaConst.ELevelAutoFightInitRule.OPEN end function SyncGuildBossLevelFunction:GetFormulaAdaptiveVariable() return self.formulaAdaptiveVar end function SyncGuildBossLevelFunction:GetFormulaAdaptVarRangeConstPrefix() return "MonsterAdaptedGuildBossRange_" end function SyncGuildBossLevelFunction:OnLevelSucceed() self:SendResult() self:StopLevel() end function SyncGuildBossLevelFunction:OnLevelFail() self:SendResult() self:StopLevel() end function SyncGuildBossLevelFunction:OnPlayerAllHeroDead(entity) Base.OnPlayerAllHeroDead(self, entity) EventSystem.Dispatch(EventID.GuildBoss_PlayerDead ,entity) end function SyncGuildBossLevelFunction:QuitRoom(entity) SystemManager.Background(entity) if entity == LogicUpdateManager._curEntity then if not LogicUpdateManager.IsReplayOrServerCheck then -- 客户端重播或服务器校验的话,不要执行下面代码 EventSystem.Dispatch(EventID.GuildBoss_QuitRoom) self:StopLevel() end else EventSystem.Dispatch(EventID.UI_WorldBoss_PlayerQuitRoom,entity._logicInitData.PlayerIDInRoom) end end -- 不写在表现层的原因 : 一致性代码需要用到这个checkStr ,为了不写两遍(逻辑一遍表现一遍) function SyncGuildBossLevelFunction:SendResult() -- old↓ 提了一个方法到基类去了,直接使用基类提供的方法 -- local checkStr = "" -- for i,entity in ipairs(LogicUpdateManager.EntityList_Sync) do -- local moveComp = entity.components.move -- local str = string.format("%d,f:%d, px:%d,pz:%d,fx:%d,fz:%d,Anim:%s,hp:%d|" -- , entity._logicInitData.EntityID,BattleDataGetter.GetCurFrameIndex() ,moveComp.LogicPos.x[1], moveComp.LogicPos.z[1],moveComp.LogicRotateDir.x[1], moveComp.LogicRotateDir.z[1],tostring(entity.components.anim.CurAnimID),entity.components.attr.hp[1]) -- checkStr = checkStr .. str -- end -- old↑ -- new↓ 直接使用基类提供的方法 local checkStr = self:GetBattleResultCheckStr() -- new 直接使用基类提供的方法 -- new↑ if USE_LUA_STANDALONE then BattleSimulator.SetCheckResult(checkStr) end EventSystem.Dispatch(EventID.GuildBoss_SendResult ,checkStr) end function SyncGuildBossLevelFunction:InitPlayerStatistic(statistic) Base.InitPlayerStatistic(self, statistic) statistic[EStatisticType.DamageBossHP] = FP.newV1(0) end -- 目前认为entity一定是boss,其他怪不会掉血 --统计血量的代码已经提了公共方法了,SyncLevelFunction:TryAddDamageBossHPStatistic function SyncGuildBossLevelFunction:OnHpChange(entity ,caster, delta,op) local sourceEntity = nil if delta < FP.Const.Zero and op == "sub" and caster then sourceEntity = caster:GetMasterEntity() or caster end if sourceEntity then local playerRoomID = sourceEntity:GetPlayerID() if playerRoomID > 0 then self.PlayerStatisticDic[playerRoomID][EStatisticType.DamageBossHP]:Sub(delta) end end end -- 获取战斗积分和结果 (只给服务器使用的代码) local temp_dmgDic = {} function SyncGuildBossLevelFunction:GetGuildBossDamageRecord() table.clear(temp_dmgDic) local info = {} for _,playerID in ipairs(LevelPlayerManager.SyncPlayerIDList) do local playerInfo = LevelPlayerManager.GetPlayerInfoByPlayerIDInRoom(playerID) -- 玩家基础信息 local statisticInfo = self.PlayerStatisticDic[playerID] -- 玩法统计数据 if statisticInfo then -- 有些玩家只传入了playerInfo ,没有创建entity ,所以就没有数据 local acid = playerInfo.acid local guildID = playerInfo.guildID -- 公会id local damage = math.floor( FP.tonumberV1(statisticInfo[EStatisticType.DamageBossHP]) ) local playerName = playerInfo.name if temp_dmgDic[acid] then -- 这个玩家退出后又进来玩了,前后伤害算在一起 temp_dmgDic[acid] = temp_dmgDic[acid] + damage damage = temp_dmgDic[acid] else temp_dmgDic[acid] = damage end table.insert(info, acid) table.insert(info, guildID) table.insert(info, damage) table.insert(info, playerName) end end return info end function SyncGuildBossLevelFunction:GetDamageRank(entity) local rank = 999999 if entity:IsHero() then local playerID = entity:GetPlayerID() if playerID > 0 then local statisticInfo = self.PlayerStatisticDic[playerID] if statisticInfo then local damage = statisticInfo[EStatisticType.DamageBossHP] if damage then rank = 1 for _, compareToPlayerID in ipairs(LevelPlayerManager.SyncPlayerIDList) do local compareToStatistic = self.PlayerStatisticDic[compareToPlayerID] if compareToStatistic then if damage < compareToStatistic[EStatisticType.DamageBossHP] then rank = rank + 1 end end end end end end end return rank end return SyncGuildBossLevelFunction