From adfca19d4c8978162ecb3c5d5cfbf3f78a232542 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 31 May 2022 19:51:16 -0400 Subject: [PATCH] Core/Battlegrounds: Replace manual criteria timer starts in battlegrounds with new GameEvents api Port From (https://github.com/TrinityCore/TrinityCore/commit/111fc6ac6fd703bb645046e7a477a986d8519a64) --- Source/Game/BattleGrounds/BattleGround.cs | 5 ++- .../Game/BattleGrounds/Zones/ArathiBasin.cs | 2 +- Source/Game/BattleGrounds/Zones/EyeofStorm.cs | 2 +- .../BattleGrounds/Zones/StrandofAncients.cs | 4 +- .../Game/BattleGrounds/Zones/WarsongGluch.cs | 2 +- Source/Game/Events/GameEventSender.cs | 37 ++++++++++++------- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Source/Game/BattleGrounds/BattleGround.cs b/Source/Game/BattleGrounds/BattleGround.cs index 044445791..1e4628f5f 100644 --- a/Source/Game/BattleGrounds/BattleGround.cs +++ b/Source/Game/BattleGrounds/BattleGround.cs @@ -1846,13 +1846,14 @@ namespace Game.BattleGrounds return Global.ObjectMgr.GetClosestGraveYard(player, GetPlayerTeam(player.GetGUID()), player); } - public void StartCriteriaTimer(CriteriaStartEvent startEvent, uint entry) + public void TriggerGameEvent(uint gameEventId) { + GameEvents.TriggerForMap(gameEventId, GetBgMap()); foreach (var guid in GetPlayers().Keys) { Player player = Global.ObjAccessor.FindPlayer(guid); if (player) - player.StartCriteriaTimer(startEvent, entry); + GameEvents.TriggerForPlayer(gameEventId, player); } } diff --git a/Source/Game/BattleGrounds/Zones/ArathiBasin.cs b/Source/Game/BattleGrounds/Zones/ArathiBasin.cs index f3a06f1d5..f7f32348c 100644 --- a/Source/Game/BattleGrounds/Zones/ArathiBasin.cs +++ b/Source/Game/BattleGrounds/Zones/ArathiBasin.cs @@ -216,7 +216,7 @@ namespace Game.BattleGrounds.Zones DoorOpen(ABObjectTypes.GateH); // Achievement: Let's Get This Done - StartCriteriaTimer(CriteriaStartEvent.SendEvent, EventStartBattle); + TriggerGameEvent(EventStartBattle); } public override void AddPlayer(Player player) diff --git a/Source/Game/BattleGrounds/Zones/EyeofStorm.cs b/Source/Game/BattleGrounds/Zones/EyeofStorm.cs index dfd383441..551fe9580 100644 --- a/Source/Game/BattleGrounds/Zones/EyeofStorm.cs +++ b/Source/Game/BattleGrounds/Zones/EyeofStorm.cs @@ -131,7 +131,7 @@ namespace Game.BattleGrounds.Zones } // Achievement: Flurry - StartCriteriaTimer(CriteriaStartEvent.SendEvent, EotSMisc.EventStartBattle); + TriggerGameEvent(EotSMisc.EventStartBattle); } void AddPoints(Team Team, uint Points) diff --git a/Source/Game/BattleGrounds/Zones/StrandofAncients.cs b/Source/Game/BattleGrounds/Zones/StrandofAncients.cs index e94ed77c5..c7699b57c 100644 --- a/Source/Game/BattleGrounds/Zones/StrandofAncients.cs +++ b/Source/Game/BattleGrounds/Zones/StrandofAncients.cs @@ -343,7 +343,7 @@ namespace Game.BattleGrounds.Zones ToggleTimer(); DemolisherStartState(false); Status = SAStatus.RoundOne; - StartCriteriaTimer(CriteriaStartEvent.SendEvent, (Attackers == TeamId.Alliance) ? 23748 : 21702u); + TriggerGameEvent(Attackers == TeamId.Alliance ? 23748 : 21702u); } if (TotalTime >= SATimers.BoatStart) StartShips(); @@ -366,7 +366,7 @@ namespace Game.BattleGrounds.Zones ToggleTimer(); DemolisherStartState(false); Status = SAStatus.RoundTwo; - StartCriteriaTimer(CriteriaStartEvent.SendEvent, (Attackers == TeamId.Alliance) ? 23748 : 21702u); + TriggerGameEvent(Attackers == TeamId.Alliance ? 23748 : 21702u); // status was set to STATUS_WAIT_JOIN manually for Preparation, set it back now SetStatus(BattlegroundStatus.InProgress); foreach (var pair in GetPlayers()) diff --git a/Source/Game/BattleGrounds/Zones/WarsongGluch.cs b/Source/Game/BattleGrounds/Zones/WarsongGluch.cs index a20fa27a6..5ea24c5e3 100644 --- a/Source/Game/BattleGrounds/Zones/WarsongGluch.cs +++ b/Source/Game/BattleGrounds/Zones/WarsongGluch.cs @@ -193,7 +193,7 @@ namespace Game.BattleGrounds.Zones SpawnBGObject(WSGObjectTypes.DoorH4, BattlegroundConst.RespawnOneDay); // players joining later are not eligibles - StartCriteriaTimer(CriteriaStartEvent.SendEvent, 8563); + TriggerGameEvent( 8563); } public override void AddPlayer(Player player) diff --git a/Source/Game/Events/GameEventSender.cs b/Source/Game/Events/GameEventSender.cs index 10e4f82e6..722eab05d 100644 --- a/Source/Game/Events/GameEventSender.cs +++ b/Source/Game/Events/GameEventSender.cs @@ -38,23 +38,34 @@ namespace Game zoneScript.ProcessEvent(target, gameEventId, source); Map map = refForMapAndZoneScript.GetMap(); - if (target) + GameObject goTarget = target?.ToGameObject(); + if (goTarget != null) { - GameObject goTarget = target.ToGameObject(); - if (goTarget != null) - { - GameObjectAI goAI = goTarget.GetAI(); - if (goAI != null) - goAI.EventInform(gameEventId); - } - - BattlegroundMap bgMap = map.ToBattlegroundMap(); - if (bgMap != null) - bgMap.GetBG().ProcessEvent(target, gameEventId, source); + GameObjectAI goAI = goTarget.GetAI(); + if (goAI != null) + goAI.EventInform(gameEventId); } - map.ScriptsStart(ScriptsType.Event, gameEventId, source, target); + Player sourcePlayer = source?.ToPlayer(); + if (sourcePlayer != null) + TriggerForPlayer(gameEventId, sourcePlayer); + + TriggerForMap(gameEventId, map, source, target); } + public static void TriggerForPlayer(uint gameEventId, Player source) + { + Map map = source.GetMap(); + if (map.Instanceable()) + source.StartCriteriaTimer(CriteriaStartEvent.SendEvent, gameEventId); + } + + public static void TriggerForMap(uint gameEventId, Map map, WorldObject source = null, WorldObject target = null) + { + BattlegroundMap bgMap = map.ToBattlegroundMap(); + if (bgMap != null) + bgMap.GetBG().ProcessEvent(target, gameEventId, source); + map.ScriptsStart(ScriptsType.Event, gameEventId, source, target); + } } }