feat(Core/Battlefield): Add Player::InBattlefield() and Battlefield::IsPlayerInBattlefield() (#26129)
This commit is contained in:
@@ -298,6 +298,20 @@ bool Battlefield::IsPlayerInWarOrInvited(Player* player) const
|
||||
return PlayersInWar[teamId].count(player->GetGUID()) || InvitedPlayers[teamId].count(player->GetGUID());
|
||||
}
|
||||
|
||||
bool Battlefield::IsPlayerInBattlefield(ObjectGuid guid) const
|
||||
{
|
||||
if (!IsWarTime())
|
||||
return false;
|
||||
|
||||
// PlayersInWar is split into per-team sets, but a GUID alone does not indicate the team, so check both sets.
|
||||
// This also stays correct if an OnBattlefieldPlayerJoinWar handler reassigned the team GetTeamId() returns.
|
||||
for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
|
||||
if (PlayersInWar[team].count(guid))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Battlefield::KickAfkPlayers()
|
||||
{
|
||||
ForEachPlayerInWar([this](Player* player)
|
||||
|
||||
@@ -365,6 +365,9 @@ public:
|
||||
/// Returns the set of players actively fighting in the war (per team, read-only).
|
||||
GuidUnorderedSet const& GetPlayersInWarSet(TeamId teamId) const { return PlayersInWar[teamId]; }
|
||||
|
||||
// Returns true if the player is enrolled as a participant in the currently active battle.
|
||||
bool IsPlayerInBattlefield(ObjectGuid guid) const;
|
||||
|
||||
void DoPlaySoundToAll(uint32 soundId);
|
||||
|
||||
void InvitePlayerToQueue(Player* player);
|
||||
|
||||
@@ -12227,6 +12227,12 @@ Battleground* Player::GetBattleground(bool create) const
|
||||
return (create || (bg && bg->FindBgMap()) ? bg : nullptr);
|
||||
}
|
||||
|
||||
bool Player::InBattlefield() const
|
||||
{
|
||||
Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(GetZoneId());
|
||||
return bf && bf->IsWarTime();
|
||||
}
|
||||
|
||||
bool Player::InBattlegroundQueue(bool ignoreArena) const
|
||||
{
|
||||
for (uint8 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i)
|
||||
|
||||
@@ -2289,6 +2289,7 @@ public:
|
||||
/*********************************************************/
|
||||
|
||||
[[nodiscard]] bool InBattleground() const { return m_bgData.bgInstanceID != 0; }
|
||||
[[nodiscard]] bool InBattlefield() const; // True if the player is in Wintergrasp and it's war time.
|
||||
[[nodiscard]] bool InArena() const;
|
||||
[[nodiscard]] uint32 GetBattlegroundId() const { return m_bgData.bgInstanceID; }
|
||||
[[nodiscard]] BattlegroundTypeId GetBattlegroundTypeId() const { return m_bgData.bgTypeID; }
|
||||
|
||||
Reference in New Issue
Block a user