local Base = require("Battle/Expression/ExpLevel/ExpLevelFunction/ExpSyncLevelFunction") local ExpSyncGuildWarBaseLevelFunction = class("ExpSyncGuildWarBaseLevelFunction",Base) local EventSystem = require('Event/EventSystem') local ExpCameraSystem = require "Battle/Expression/ExpEntity/System/ExpCameraSystem" local private = {closeToKnockCarTime = 0} -- closeToKnockCarTime 上次弹出冲车的tips时间 ,为了优化 -- 投石车的MonsterFeatureID local Const_Catapult_FeatureID = 47 -- 弩车的MonsterFeatureID local Const_Ballista_FeatureID = 48 -- 小投石车 local Const_MiniCatapult_FeatureID = 49 local EStatisticType = LuaConst.EStatisticType function ExpSyncGuildWarBaseLevelFunction:OnInitLevel() Base.OnInitLevel(self) EventSystem.Regist(EventID.Level_ItemTriggerOccupy, private.OnItemOccupyTriggered) EventSystem.Regist(EventID.Player_DriveEntity, private.OnSelfDriveEntity) -- 只有自己才会收到这个事件 EventSystem.Regist(EventID.UI_GuildWarCloseRevive,private.TryCloseView) self.KnockCarList = {} -- 活着的冲车 end function ExpSyncGuildWarBaseLevelFunction:OnHandleHeroDead(killer, deadEntity, involveKillPlayerIDList, assistHeroEntityIDList, kStatistic, relaxAssistPlayerIDList, relaxKillPlayerIDList) -- 不用base EventSystem.Dispatch(EventID.Level_HeroDead, killer, deadEntity, involveKillPlayerIDList, assistHeroEntityIDList, relaxAssistPlayerIDList) -- 显示 n 助 EventSystem.Dispatch(EventID.Level_UpdateKillHeroNum, killer, kStatistic and kStatistic[EStatisticType.RelaxHeroKillNum], relaxKillPlayerIDList) --显示 n 斩 end function private.OnItemOccupyTriggered(itemID, entity, enter, isHide) if LogicUpdateManager.IsInReconnectFastPlay() then -- 快速追帧过程中 return end if enter and entity:IsPlayerSelf() then if isHide then -- 已经刷出投石车来了 local levelItem = LevelItemManager.GetItemByID(itemID) local campid = levelItem:GetCurOccupierID() if campid == LevelPlayerManager.MainEntityCampID then -- 我方已占领 EventSystem.Dispatch(EventID.UI_GuildWarTips_Help,"IDS_GuildWar_BattleHelpText5") else EventSystem.Dispatch(EventID.UI_GuildWarTips_Help,"IDS_GuildWar_BattleHelpText4") end else EventSystem.Dispatch(EventID.UI_GuildWarTips_Help,"IDS_GuildWar_BattleHelpText3") end end end function private.OnSelfDriveEntity(carEntity , driver) if LogicUpdateManager.IsInReconnectFastPlay() then -- 快速追帧过程中 return end if driver ~= LogicUpdateManager._curEntity then return end local featureID = carEntity:GetFeatureID() if featureID == Const_Catapult_FeatureID then -- 投石车 EventSystem.Dispatch(EventID.UI_GuildWarTips_Help,"IDS_GuildWar_BattleHelpText6") elseif featureID == Const_Ballista_FeatureID then -- 弩车 EventSystem.Dispatch(EventID.UI_GuildWarTips_Help,"IDS_GuildWar_BattleHelpText7") elseif featureID == Const_MiniCatapult_FeatureID then -- 小投石车 EventSystem.Dispatch(EventID.UI_GuildWarTips_Help,"IDS_GuildWar_BattleHelpText10") end end --记录复活界面应该是什么状态(显示、隐藏) function private.TryCloseView(entity) if LogicUpdateManager.IsInReconnectFastPlay() then if entity and entity:IsPlayerSelf() then MDL.GuildWar.RecordRevivePanelState(false) end end end function ExpSyncGuildWarBaseLevelFunction:OnAfterEnter() Base.OnAfterEnter(self) --EventSystem.Dispatch(EventID.UI_GuildWarTips_Begin) end function ExpSyncGuildWarBaseLevelFunction:OnPlayerOneHeroDead_SelectOne(playerHeroDeadTimeFrame,playerID ,entity) if LogicUpdateManager.IsInReconnectFastPlay() then -- 快速追帧过程中,不发送打开复活界面 if playerID == LevelPlayerManager.MyPlayerIDInRoom then MDL.GuildWar.RecordRevivePanelState(true) end return end if playerID == LevelPlayerManager.MyPlayerIDInRoom then -- 不会造成不一致 local firstInfo = playerHeroDeadTimeFrame[playerID][LuaConst.ArmyPosType.First] local secondInfo = playerHeroDeadTimeFrame[playerID][LuaConst.ArmyPosType.Second] local thirdInfo = playerHeroDeadTimeFrame[playerID][LuaConst.ArmyPosType.Third] local first = firstInfo.ReviveFrame or 0 local second = secondInfo.ReviveFrame or 0 local third = thirdInfo.ReviveFrame or 0 if self.uiInfo then self.uiInfo.time[1] = first self.uiInfo.time[2] = second self.uiInfo.time[3] = third self.uiInfo.totalTime[1] = firstInfo.ReviveTotalTime self.uiInfo.totalTime[2] = secondInfo.ReviveTotalTime self.uiInfo.totalTime[3] = thirdInfo.ReviveTotalTime else self.uiInfo = { heroIDs = {firstInfo.heroID ,secondInfo.heroID ,thirdInfo.heroID } , time = {first ,second ,third }, totalTime = {firstInfo.ReviveTotalTime, secondInfo.ReviveTotalTime, thirdInfo.ReviveTotalTime} } end EventSystem.Dispatch(EventID.UI_GuildWarSelfDead,self.uiInfo) end -- 队友的话,发送 if LogicUpdateManager._curEntity then local myTeamID = LogicUpdateManager._curEntity:GetTeamID() local teamID = entity:GetTeamID() if myTeamID == teamID then EventSystem.Dispatch(EventID.UI_GuildWarCampTopViewRefresh,playerID) end end end function ExpSyncGuildWarBaseLevelFunction:OnSwitchHero(fromEntity, toEntity) -- 队友的话,发送 if LogicUpdateManager._curEntity then local myTeamID = LogicUpdateManager._curEntity:GetTeamID() local teamID = toEntity:GetTeamID() if myTeamID == teamID then EventSystem.Dispatch(EventID.UI_GuildWarCampTopViewRefresh,toEntity:GetPlayerID()) end end end function ExpSyncGuildWarBaseLevelFunction:OnHpChange(entity, caster, delta, op) if not LogicUpdateManager.IsInReconnectFastPlay() then if LogicUpdateManager._curEntity then local myTeamID = LogicUpdateManager._curEntity:GetTeamID() local teamID = entity:GetTeamID() if myTeamID == teamID then EventSystem.Dispatch(EventID.UI_GuildWarCampTopViewRefresh,entity:GetPlayerID()) end end end end function ExpSyncGuildWarBaseLevelFunction:OnKnockCarBorn(entity) table.insert(self.KnockCarList ,entity) end function ExpSyncGuildWarBaseLevelFunction:OnKnockCarDead(entity) table.removebyvalue(self.KnockCarList ,entity) end function ExpSyncGuildWarBaseLevelFunction:Update() if LogicUpdateManager.IsInReconnectFastPlay() then -- 快速追帧过程中 return end Base.Update(self) if LogicUpdateManager._clientHandleFrame - private.closeToKnockCarTime > 10 then -- 每0.5秒检测一次冲车距离 if LogicUpdateManager._curEntity then local mypos = LogicUpdateManager._curEntity:GetLogicPos() for i,entity in ipairs(self.KnockCarList) do local pos = entity:GetLogicPos() local deltax = math.abs( mypos.x[1] - pos.x[1]) local deltaz = math.abs( mypos.z[1] - pos.z[1]) if deltax < 5000 and deltaz < 5000 then private.closeToKnockCarTime = LogicUpdateManager._clientHandleFrame EventSystem.Dispatch(EventID.UI_GuildWarTips_Help,"IDS_GuildWar_BattleHelpText8") break; end end end end end function ExpSyncGuildWarBaseLevelFunction:OnSetPlayerActive(playerID) Base.OnSetPlayerActive(self,playerID) if LogicUpdateManager._curEntity then local myTeamID = LogicUpdateManager._curEntity:GetTeamID() local entity = LevelPlayerManager.GetPlayerActiveEntity(playerID) local teamID = entity and entity:GetTeamID() or -1 if myTeamID == teamID then EventSystem.Dispatch(EventID.UI_GuildWarCampTopViewRefresh,playerID) end end end function ExpSyncGuildWarBaseLevelFunction:OnCampResourceAmountChange(campID, delta, contributorEntity, curAmount) EventSystem.Dispatch(EventID.UI_GuildWarResourceScoreChange, campID, curAmount) end function ExpSyncGuildWarBaseLevelFunction:RefreshUIHP(entity) local comp_Attr = entity.components.attr local hp = FP.tonumberV1(comp_Attr.hp) local pc = FP.tonumberV1(comp_Attr.pc) local maxHp = FP.tonumberV1(comp_Attr:GetAttrValue(LuaConst.AttrType.hplmt)) entity.ExpEntity:SetModelUI_HP(hp, pc, maxHp ,false) end -- 追帧完毕 function ExpSyncGuildWarBaseLevelFunction:OnFastPlayOver() if LogicUpdateManager._curEntity then local showRevivePanel = MDL.GuildWar.GetRevivePanelState() if showRevivePanel then self:OnPlayerOneHeroDead_SelectOne(self.levelFunction.playerHeroDeadTimeFrame,LevelPlayerManager.MyPlayerIDInRoom ,LogicUpdateManager._curEntity) MDL.GuildWar.RecordRevivePanelState(false) else CameraController.Instance:SetGray(false) end end end return ExpSyncGuildWarBaseLevelFunction