Core/Battlegrounds: Replace manual criteria timer starts in battlegrounds with new GameEvents api

This commit is contained in:
Shauren
2022-04-24 12:09:10 +02:00
parent 597485f1d4
commit 111fc6ac6f
9 changed files with 37 additions and 18 deletions

View File

@@ -25,6 +25,7 @@
#include "DatabaseEnv.h"
#include "DB2Stores.h"
#include "Formulas.h"
#include "GameEventSender.h"
#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
@@ -1933,11 +1934,12 @@ WorldSafeLocsEntry const* Battleground::GetClosestGraveyard(Player* player)
return sObjectMgr->GetClosestGraveyard(*player, GetPlayerTeam(player->GetGUID()), player);
}
void Battleground::StartCriteriaTimer(CriteriaStartEvent startEvent, uint32 entry)
void Battleground::TriggerGameEvent(uint32 gameEventId)
{
GameEvents::TriggerForMap(gameEventId, GetBgMap());
for (BattlegroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(itr->first))
player->StartCriteriaTimer(startEvent, entry);
GameEvents::TriggerForPlayer(gameEventId, player);
}
void Battleground::SetBracket(PVPDifficultyEntry const* bracketEntry)

View File

@@ -288,7 +288,7 @@ class TC_GAME_API Battleground
/* achievement req. */
virtual bool IsAllNodesControlledByTeam(uint32 /*team*/) const { return false; }
void StartCriteriaTimer(CriteriaStartEvent startEvent, uint32 entry);
void TriggerGameEvent(uint32 gameEventId);
virtual bool CheckAchievementCriteriaMeet(uint32 /*criteriaId*/, Player const* /*player*/, Unit const* /*target*/ = nullptr, uint32 /*miscvalue1*/ = 0);
/* Battleground */

View File

@@ -217,7 +217,7 @@ void BattlegroundAB::StartingEventOpenDoors()
DoorOpen(BG_AB_OBJECT_GATE_H);
// Achievement: Let's Get This Done
StartCriteriaTimer(CriteriaStartEvent::SendEvent, AB_EVENT_START_BATTLE);
TriggerGameEvent(AB_EVENT_START_BATTLE);
}
void BattlegroundAB::AddPlayer(Player* player)

View File

@@ -432,7 +432,7 @@ void BattlegroundAV::StartingEventOpenDoors()
DoorOpen(BG_AV_OBJECT_DOOR_A);
// Achievement: The Alterac Blitz
StartCriteriaTimer(CriteriaStartEvent::SendEvent, BG_AV_EVENT_START_BATTLE);
TriggerGameEvent(BG_AV_EVENT_START_BATTLE);
}
void BattlegroundAV::AddPlayer(Player* player)

View File

@@ -142,7 +142,7 @@ void BattlegroundEY::StartingEventOpenDoors()
}
// Achievement: Flurry
StartCriteriaTimer(CriteriaStartEvent::SendEvent, BG_EY_EVENT_START_BATTLE);
TriggerGameEvent(BG_EY_EVENT_START_BATTLE);
}
void BattlegroundEY::AddPoints(uint32 Team, uint32 Points)

View File

@@ -345,7 +345,7 @@ void BattlegroundSA::PostUpdateImpl(uint32 diff)
ToggleTimer();
DemolisherStartState(false);
Status = BG_SA_ROUND_ONE;
StartCriteriaTimer(CriteriaStartEvent::SendEvent, (Attackers == TEAM_ALLIANCE) ? 23748 : 21702);
TriggerGameEvent((Attackers == TEAM_ALLIANCE) ? 23748 : 21702);
}
if (TotalTime >= BG_SA_BOAT_START)
StartShips();
@@ -367,7 +367,7 @@ void BattlegroundSA::PostUpdateImpl(uint32 diff)
ToggleTimer();
DemolisherStartState(false);
Status = BG_SA_ROUND_TWO;
StartCriteriaTimer(CriteriaStartEvent::SendEvent, (Attackers == TEAM_ALLIANCE) ? 23748 : 21702);
TriggerGameEvent((Attackers == TEAM_ALLIANCE) ? 23748 : 21702);
// status was set to STATUS_WAIT_JOIN manually for Preparation, set it back now
SetStatus(STATUS_IN_PROGRESS);
for (BattlegroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
@@ -544,7 +544,7 @@ void BattlegroundSA::TeleportToEntrancePosition(Player* player)
void BattlegroundSA::ProcessEvent(WorldObject* obj, uint32 eventId, WorldObject* invoker /*= nullptr*/)
{
if (GameObject* go = obj->ToGameObject())
if (GameObject* go = Object::ToGameObject(obj))
{
switch (go->GetGoType())
{

View File

@@ -223,7 +223,7 @@ void BattlegroundWS::StartingEventOpenDoors()
SpawnBGObject(BG_WS_OBJECT_DOOR_H_4, RESPAWN_ONE_DAY);
// players joining later are not eligibles
StartCriteriaTimer(CriteriaStartEvent::SendEvent, WS_EVENT_START_BATTLE);
TriggerGameEvent(WS_EVENT_START_BATTLE);
}
void BattlegroundWS::AddPlayer(Player* player)

View File

@@ -22,6 +22,7 @@
#include "InstanceScript.h"
#include "Map.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Util.h"
void GameEvents::Trigger(uint32 gameEventId, WorldObject* source, WorldObject* target)
@@ -38,15 +39,27 @@ void GameEvents::Trigger(uint32 gameEventId, WorldObject* source, WorldObject* t
zoneScript->ProcessEvent(target, gameEventId, source);
Map* map = refForMapAndZoneScript->GetMap();
if (target)
{
if (GameObject* goTarget = target->ToGameObject())
if (GameObjectAI* goAI = goTarget->AI())
goAI->EventInform(gameEventId);
if (GameObject* goTarget = Object::ToGameObject(target))
if (GameObjectAI* goAI = goTarget->AI())
goAI->EventInform(gameEventId);
if (BattlegroundMap* bgMap = map->ToBattlegroundMap())
bgMap->GetBG()->ProcessEvent(target, gameEventId, source);
}
if (Player* sourcePlayer = Object::ToPlayer(source))
TriggerForPlayer(gameEventId, sourcePlayer);
TriggerForMap(gameEventId, map, source, target);
}
void GameEvents::TriggerForPlayer(uint32 gameEventId, Player* source)
{
Map* map = source->GetMap();
if (map->Instanceable())
source->StartCriteriaTimer(CriteriaStartEvent::SendEvent, gameEventId);
}
void GameEvents::TriggerForMap(uint32 gameEventId, Map* map, WorldObject* source, WorldObject* target)
{
if (BattlegroundMap* bgMap = map->ToBattlegroundMap())
bgMap->GetBG()->ProcessEvent(target, gameEventId, source);
map->ScriptsStart(sEventScripts, gameEventId, source, target);
}

View File

@@ -20,11 +20,15 @@
#include "Define.h"
class Map;
class Player;
class WorldObject;
namespace GameEvents
{
TC_GAME_API void Trigger(uint32 gameEventId, WorldObject* source, WorldObject* target);
TC_GAME_API void TriggerForPlayer(uint32 gameEventId, Player* source);
TC_GAME_API void TriggerForMap(uint32 gameEventId, Map* map, WorldObject* source = nullptr, WorldObject* target = nullptr);
}
#endif // GameEventSender_h__