feat(Core/Scripting): Add Battlefield scripting hooks and API (#24957)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "Battlefield.h"
|
||||
#include "BattlefieldMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "CellImpl.h"
|
||||
#include "CreatureTextMgr.h"
|
||||
#include "GameGraveyard.h"
|
||||
@@ -81,6 +82,10 @@ Battlefield::~Battlefield()
|
||||
// Called when a player enters the zone
|
||||
void Battlefield::HandlePlayerEnterZone(Player* player, uint32 /*zone*/)
|
||||
{
|
||||
// Allow scripts to adjust the player's effective team or appearance before
|
||||
// any team-based battlefield containers (such as player lists or queues) are updated.
|
||||
sScriptMgr->OnBattlefieldPlayerEnterZone(this, player);
|
||||
|
||||
// Xinef: do not invite players on taxi
|
||||
if (!player->IsInFlight())
|
||||
{
|
||||
@@ -126,6 +131,7 @@ void Battlefield::HandlePlayerLeaveZone(Player* player, uint32 /*zone*/)
|
||||
group->RemoveMember(player->GetGUID());
|
||||
|
||||
OnPlayerLeaveWar(player);
|
||||
sScriptMgr->OnBattlefieldPlayerLeaveWar(this, player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +144,10 @@ void Battlefield::HandlePlayerLeaveZone(Player* player, uint32 /*zone*/)
|
||||
SendRemoveWorldStates(player);
|
||||
RemovePlayerFromResurrectQueue(player->GetGUID());
|
||||
OnPlayerLeaveZone(player);
|
||||
// Scripts must restore player->GetTeamId() here (e.g. ClearFakePlayer).
|
||||
// All Battlefield data-structure cleanup above has already completed using
|
||||
// the assigned team, so it is safe to restore the real team now.
|
||||
sScriptMgr->OnBattlefieldPlayerLeaveZone(this, player);
|
||||
}
|
||||
|
||||
bool Battlefield::Update(uint32 diff)
|
||||
@@ -434,6 +444,7 @@ void Battlefield::PlayerAcceptInviteToWar(Player* player)
|
||||
player->ToggleAFK();
|
||||
|
||||
OnPlayerJoinWar(player); //for scripting
|
||||
sScriptMgr->OnBattlefieldPlayerJoinWar(this, player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -354,6 +354,13 @@ public:
|
||||
uint32 GetTimer() { return m_Timer; }
|
||||
void SetTimer(uint32 timer) { m_Timer = timer; }
|
||||
|
||||
// Returns combined count of players in war + invited (per team) for balance checking
|
||||
uint32 GetPlayersInWarCount(TeamId teamId) const { return static_cast<uint32>(m_PlayersInWar[teamId].size() + m_InvitedPlayers[teamId].size()); }
|
||||
// Returns total count of players in the battlefield zone per team
|
||||
uint32 GetPlayersInZoneCount(TeamId teamId) const { return static_cast<uint32>(m_players[teamId].size()); }
|
||||
// Returns the maximum players allowed per team
|
||||
uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayer; }
|
||||
|
||||
void DoPlaySoundToAll(uint32 SoundID);
|
||||
|
||||
void InvitePlayerToQueue(Player* player);
|
||||
|
||||
Reference in New Issue
Block a user