AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Battlefield Class Referenceabstract

#include "Battlefield.h"

Inheritance diagram for Battlefield:
ZoneScript BattlefieldWG

Public Types

using BfCapturePointVector = std::vector< BfCapturePoint * >
 Vector of capture points belonging to this battlefield.
 

Public Member Functions

 Battlefield ()
 Constructor.
 
 ~Battlefield () override
 Destructor.
 
virtual bool SetupBattlefield ()
 Call this to init the Battlefield.
 
void SendUpdateWorldState (uint32 field, uint32 value)
 Update data of a worldstate to all players present in zone.
 
virtual bool Update (uint32 diff)
 Called every time for update bf data and time.
 
void InvitePlayersInZoneToQueue ()
 Invite all players in zone to join the queue, called x minutes before battle start in Update()
 
void InvitePlayersInQueueToWar ()
 Invite all players in queue to join battle on battle start.
 
void InvitePlayersInZoneToWar ()
 Invite all players in zone to join battle on battle start.
 
virtual void HandleKill (Player *, Unit *)
 Called when a Unit is killed in battlefield zone.
 
uint32 GetTypeId () const
 
uint32 GetZoneId () const
 
void TeamApplyBuff (TeamId team, uint32 spellId, uint32 spellId2=0)
 
bool IsWarTime () const
 Return true if battle is started, false if battle is not started.
 
void ToggleBattlefield (bool enable)
 Enable or Disable battlefield.
 
bool IsEnabled () const
 Return if battlefield is enabled.
 
void KickPlayerFromBattlefield (ObjectGuid guid)
 Kick player from battlefield and teleport him to kick-point location.
 
void HandlePlayerEnterZone (Player *player, uint32 zone)
 Called when player (player) enters the zone.
 
void HandlePlayerLeaveZone (Player *player, uint32 zone)
 Called when player (player) leaves the zone.
 
uint64 GetData64 (uint32 dataId) const override
 
void SetData64 (uint32 dataId, uint64 value) override
 
uint32 GetData (uint32 dataId) const override
 
void SetData (uint32 dataId, uint32 value) override
 
virtual void UpdateData (uint32 index, int32 pad)
 
TeamId GetDefenderTeam () const
 
TeamId GetAttackerTeam () const
 
TeamId GetOtherTeam (TeamId team) const
 
void SetDefenderTeam (TeamId team)
 
GroupGetFreeBfRaid (TeamId teamId)
 Find a not full battlefield group, if there is no, create one.
 
GroupGetGroupPlayer (ObjectGuid guid, TeamId teamId)
 Return battlefield group where player is.
 
bool AddOrSetPlayerToCorrectBfGroup (Player *player)
 Force player to join a battlefield group.
 
void TryRejoinAfterLogout (Player *player)
 
GraveyardStruct const * GetClosestGraveyard (Player *player)
 
virtual void AddPlayerToResurrectQueue (ObjectGuid npcGuid, ObjectGuid playerGuid)
 
void RemovePlayerFromResurrectQueue (ObjectGuid playerGuid)
 
void SetGraveyardNumber (uint32 number)
 
BfGraveyardGetGraveyardById (uint32 id) const
 
CreatureSpawnCreature (uint32 entry, float x, float y, float z, float o, TeamId teamId)
 
CreatureSpawnCreature (uint32 entry, Position pos, TeamId teamId)
 
GameObjectSpawnGameObject (uint32 entry, float x, float y, float z, float o)
 
CreatureGetCreature (ObjectGuid const &guid)
 
GameObjectGetGameObject (ObjectGuid const &guid)
 
virtual void OnBattleStart ()
 Called on start.
 
virtual void OnBattleEnd (bool)
 Called at the end of battle.
 
virtual void OnStartGrouping ()
 Called x minutes before battle start when players in zone are invited to join queue.
 
virtual void OnPlayerJoinWar (Player *)
 Called when a player accepts to join the battle.
 
virtual void OnPlayerLeaveWar (Player *)
 Called when a player leaves the battle.
 
virtual void OnPlayerLeaveZone (Player *)
 Called when a player leaves the battlefield zone.
 
virtual void OnPlayerEnterZone (Player *)
 Called when a player enters the battlefield zone.
 
void SendWarning (uint8 id, WorldObject const *target=nullptr)
 
void PlayerAcceptInviteToQueue (Player *player)
 
void PlayerAcceptInviteToWar (Player *player)
 
uint32 GetBattleId () const
 
void AskToLeaveQueue (Player *player)
 
void PlayerAskToLeave (Player *player)
 
virtual void SendInitWorldStatesToAll ()=0
 Send all worldstate data to all players in zone.
 
virtual void FillInitialWorldStates (WorldPackets::WorldState::InitWorldStates &)=0
 
virtual void SendUpdateWorldStates (Player *player=nullptr)=0
 
bool CanFlyIn () const
 Return if we can use mount in battlefield.
 
void SendAreaSpiritHealerQueryOpcode (Player *player, ObjectGuid const &guid)
 
void StartBattle ()
 
void EndBattle (bool endByTimer)
 
void HideNpc (Creature *creature)
 
void ShowNpc (Creature *creature, bool aggressive)
 
GraveyardVect const & GetGraveyardVector () const
 
uint32 GetTimer () const
 
void SetTimer (uint32 timer)
 
uint32 GetPlayersInWarCount (TeamId teamId) const
 
uint32 GetPlayersInZoneCount (TeamId teamId) const
 
uint32 GetMaxPlayersPerTeam () const
 
bool HasWarVacancy (TeamId teamId) const
 Returns true if there is still room for another player on the given team in the active war.
 
GuidUnorderedSet const & GetPlayersQueueSet (TeamId teamId) const
 Returns the set of players waiting in the pre-battle queue (per team, read-only).
 
PlayerTimerMap const & GetInvitedPlayersMap (TeamId teamId) const
 
GuidUnorderedSet const & GetPlayersInWarSet (TeamId teamId) const
 Returns the set of players actively fighting in the war (per team, read-only).
 
bool IsPlayerInBattlefield (ObjectGuid guid) const
 
void DoPlaySoundToAll (uint32 soundId)
 
void InvitePlayerToQueue (Player *player)
 
void InvitePlayerToWar (Player *player)
 
void InitStalker (uint32 entry, float x, float y, float z, float o)
 
- Public Member Functions inherited from ZoneScript
 ZoneScript ()
 
virtual ~ZoneScript ()
 
virtual uint32 GetCreatureEntry (ObjectGuid::LowType, CreatureData const *data)
 
virtual uint32 GetGameObjectEntry (ObjectGuid::LowType, uint32 entry)
 
virtual void OnCreatureCreate (Creature *)
 
virtual void OnCreatureRemove (Creature *)
 
virtual void OnGameObjectCreate (GameObject *)
 
virtual void OnGameObjectRemove (GameObject *)
 
virtual void OnUnitDeath (Unit *)
 
virtual void OnCreatureEvade (Creature *)
 
virtual ObjectGuid GetGuidData (uint32) const
 
virtual void SetGuidData (uint32, ObjectGuid)
 
virtual void ProcessEvent (WorldObject *, uint32)
 

Protected Member Functions

void KickAfkPlayers ()
 
virtual void SendRemoveWorldStates (Player *)
 
void BroadcastPacketToZone (WorldPacket const *data) const
 
void BroadcastPacketToQueue (WorldPacket const *data) const
 
void BroadcastPacketToWar (WorldPacket const *data) const
 
void AddCapturePoint (BfCapturePoint *cp)
 
void RegisterZone (uint32 zoneId)
 
bool HasPlayer (Player *player) const
 
void TeamCastSpell (TeamId team, int32 spellId)
 
bool IsPlayerInWarOrInvited (Player *player) const
 Returns true if the player is already tracked as actively in the war or invited to join it.
 
void RemovePlayerFromTracking (ObjectGuid playerGuid, bool removeFromQueue=true)
 
template<typename Func >
void ForEachPlayerInZone (Func &&fn) const
 
template<typename Func >
void ForEachPlayerInQueue (Func &&fn) const
 
template<typename Func >
void ForEachPlayerInWar (Func &&fn) const
 
template<typename Func >
void ForEachPlayerInWar (TeamId team, Func &&fn) const
 

Protected Attributes

ObjectGuid StalkerGuid
 
uint32 Timer
 
bool Enabled
 
bool Active
 
TeamId DefenderTeam
 
BfCapturePointVector CapturePoints
 
GuidUnorderedSet Players [PVP_TEAMS_COUNT]
 
GuidUnorderedSet PlayersInQueue [PVP_TEAMS_COUNT]
 
GuidUnorderedSet PlayersInWar [PVP_TEAMS_COUNT]
 
PlayerTimerMap InvitedPlayers [PVP_TEAMS_COUNT]
 
PlayerTimerMap PlayersWillBeKick [PVP_TEAMS_COUNT]
 
PlayerTimerMap LogoutGracePlayers [PVP_TEAMS_COUNT]
 
uint32 TypeId
 
uint32 BattleId
 
uint32 ZoneId
 
uint32 MapId
 
MapBfMap
 
uint32 MaxPlayer
 
uint32 MinPlayer
 
uint32 MinLevel
 
uint32 BattleTime
 
uint32 NoWarBattleTime
 
uint32 RestartAfterCrash
 
uint32 TimeForAcceptInvite
 
WorldLocation KickPosition
 
GraveyardVect GraveyardList
 
uint32 StartGroupingTimer
 
bool StartGrouping
 
TaskScheduler _scheduler
 
GuidUnorderedSet Groups [PVP_TEAMS_COUNT]
 
std::vector< uint64Data64
 
std::vector< uint32Data32
 

Static Protected Attributes

static constexpr uint32 LOGOUT_GRACE_SECONDS = 120
 

Friends

class BattlefieldMgr
 

Detailed Description

Member Typedef Documentation

◆ BfCapturePointVector

Vector of capture points belonging to this battlefield.

Constructor & Destructor Documentation

◆ Battlefield()

Battlefield::Battlefield ( )

Constructor.

Todo:
: this import is not necessary for compilation and marked as unused by the IDE
44 :
45 Timer(0),
46 Enabled(true),
47 Active(false),
49 TypeId(0),
50 BattleId(0),
51 ZoneId(0),
52 MapId(0),
53 BfMap(nullptr),
54 MaxPlayer(0),
55 MinPlayer(0),
56 MinLevel(0),
57 BattleTime(0),
62 StartGrouping(false)
63{
64}
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
uint32 BattleTime
Definition Battlefield.h:408
uint32 MaxPlayer
Definition Battlefield.h:405
TeamId DefenderTeam
Definition Battlefield.h:383
bool StartGrouping
Definition Battlefield.h:418
uint32 MapId
Definition Battlefield.h:403
uint32 BattleId
Definition Battlefield.h:401
bool Active
Definition Battlefield.h:382
uint32 MinPlayer
Definition Battlefield.h:406
uint32 NoWarBattleTime
Definition Battlefield.h:409
uint32 MinLevel
Definition Battlefield.h:407
uint32 RestartAfterCrash
Definition Battlefield.h:410
uint32 StartGroupingTimer
Definition Battlefield.h:417
uint32 Timer
Definition Battlefield.h:380
uint32 ZoneId
Definition Battlefield.h:402
Map * BfMap
Definition Battlefield.h:404
uint32 TimeForAcceptInvite
Definition Battlefield.h:411
bool Enabled
Definition Battlefield.h:381
uint32 TypeId
Definition Battlefield.h:400

◆ ~Battlefield()

Battlefield::~Battlefield ( )
override

Destructor.

67{
69 delete cp;
70
71 for (BfGraveyard* gy : GraveyardList)
72 delete gy;
73
74 CapturePoints.clear();
75}
BfCapturePointVector CapturePoints
Definition Battlefield.h:386
GraveyardVect GraveyardList
Definition Battlefield.h:415
Definition Battlefield.h:86
Definition Battlefield.h:156

References CapturePoints, and GraveyardList.

Member Function Documentation

◆ AddCapturePoint()

void Battlefield::AddCapturePoint ( BfCapturePoint cp)
inlineprotected
438{ CapturePoints.push_back(cp); }

References CapturePoints.

Referenced by BattlefieldWG::OnGameObjectCreate().

◆ AddOrSetPlayerToCorrectBfGroup()

bool Battlefield::AddOrSetPlayerToCorrectBfGroup ( Player player)

Force player to join a battlefield group.

606{
607 if (!player->IsInWorld())
608 return false;
609
610 if (player->GetGroup() && (player->GetGroup()->isBGGroup() || player->GetGroup()->isBFGroup()))
611 {
612 LOG_INFO("misc", "Battlefield::AddOrSetPlayerToCorrectBfGroup - player is already in {} group!", (player->GetGroup()->isBGGroup() ? "BG" : "BF"));
613 return false;
614 }
615
616 Group* group = GetFreeBfRaid(player->GetTeamId());
617 if (!group)
618 {
619 group = new Group;
620 group->SetBattlefieldGroup(this);
621 group->Create(player);
622 sGroupMgr->AddGroup(group);
623 Groups[player->GetTeamId()].insert(group->GetGUID());
624 }
625 else if (group->IsMember(player->GetGUID()))
626 {
627 uint8 subgroup = group->GetMemberGroup(player->GetGUID());
628 player->SetBattlegroundOrBattlefieldRaid(group, subgroup);
629 }
630 else
631 group->AddMember(player);
632
633 return true;
634}
std::uint8_t uint8
Definition Define.h:109
#define sGroupMgr
Definition GroupMgr.h:51
#define LOG_INFO(filterType__,...)
Definition Log.h:153
Groups
Definition boss_moroes.cpp:55
Group * GetFreeBfRaid(TeamId teamId)
Find a not full battlefield group, if there is no, create one.
Definition Battlefield.cpp:585
Definition Group.h:176
uint8 GetMemberGroup(ObjectGuid guid) const
Definition Group.cpp:2459
void SetBattlefieldGroup(Battlefield *bf)
Definition Group.cpp:2472
ObjectGuid GetGUID() const
Definition Group.cpp:2381
bool isBGGroup() const
Definition Group.cpp:2351
bool AddMember(Player *player, uint8 roles=0)
Definition Group.cpp:424
bool isBFGroup() const
Definition Group.cpp:2356
bool IsMember(ObjectGuid guid) const
Definition Group.cpp:2411
bool Create(Player *leader)
Definition Group.cpp:142
bool IsInWorld() const
Definition Object.h:109
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
TeamId GetTeamId(bool original=false) const
Definition Player.h:2131
Group * GetGroup()
Definition Player.h:2509
void SetBattlegroundOrBattlefieldRaid(Group *group, int8 subgroup=-1)
Definition Player.cpp:13212

References Group::AddMember(), Group::Create(), GetFreeBfRaid(), Player::GetGroup(), Group::GetGUID(), Object::GetGUID(), Group::GetMemberGroup(), Player::GetTeamId(), Group::isBFGroup(), Group::isBGGroup(), Object::IsInWorld(), Group::IsMember(), LOG_INFO, Group::SetBattlefieldGroup(), Player::SetBattlegroundOrBattlefieldRaid(), and sGroupMgr.

Referenced by PlayerAcceptInviteToWar(), and TryRejoinAfterLogout().

◆ AddPlayerToResurrectQueue()

void Battlefield::AddPlayerToResurrectQueue ( ObjectGuid  npcGuid,
ObjectGuid  playerGuid 
)
virtual
713{
714 Player* player = ObjectAccessor::FindPlayer(playerGuid);
715 if (!player)
716 return;
717
718 player->CastSpell(player, SPELL_WAITING_FOR_RESURRECT, true);
719}
@ SPELL_WAITING_FOR_RESURRECT
Definition Battleground.h:128
Definition Player.h:1084
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition Unit.cpp:1389
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245

References Unit::CastSpell(), ObjectAccessor::FindPlayer(), and SPELL_WAITING_FOR_RESURRECT.

◆ AskToLeaveQueue()

void Battlefield::AskToLeaveQueue ( Player player)
474{
475 // Remove player from queue
476 PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
477 // Send notification
479}
GuidUnorderedSet PlayersInQueue[PVP_TEAMS_COUNT]
Definition Battlefield.h:390
WorldSession * GetSession() const
Definition Player.h:2023
void SendBfLeaveMessage(uint32 battleId, BFLeaveReason reason=BF_LEAVE_REASON_EXITED)
Definition BattlefieldHandler.cpp:78
@ BF_LEAVE_REASON_CLOSE
Definition WorldSession.h:263

References BattleId, BF_LEAVE_REASON_CLOSE, Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), PlayersInQueue, and WorldSession::SendBfLeaveMessage().

Referenced by WorldSession::HandleBfExitRequest().

◆ BroadcastPacketToQueue()

void Battlefield::BroadcastPacketToQueue ( WorldPacket const *  data) const
protected
534{
535 ForEachPlayerInQueue([data](Player* player) { player->SendDirectMessage(data); });
536}
void ForEachPlayerInQueue(Func &&fn) const
Definition Battlefield.h:461
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5701

References ForEachPlayerInQueue(), and Player::SendDirectMessage().

◆ BroadcastPacketToWar()

void Battlefield::BroadcastPacketToWar ( WorldPacket const *  data) const
protected
539{
540 ForEachPlayerInWar([data](Player* player) { player->SendDirectMessage(data); });
541}
void ForEachPlayerInWar(Func &&fn) const
Definition Battlefield.h:470

References ForEachPlayerInWar(), and Player::SendDirectMessage().

Referenced by DoPlaySoundToAll().

◆ BroadcastPacketToZone()

void Battlefield::BroadcastPacketToZone ( WorldPacket const *  data) const
protected
529{
530 ForEachPlayerInZone([data](Player* player) { player->SendDirectMessage(data); });
531}
void ForEachPlayerInZone(Func &&fn) const
Definition Battlefield.h:452

References ForEachPlayerInZone(), and Player::SendDirectMessage().

◆ CanFlyIn()

bool Battlefield::CanFlyIn ( ) const
inline

Return if we can use mount in battlefield.

336{ return !Active; }

References Active.

Referenced by Spell::CheckCast(), spell_gen_mount::HandleMount(), and SpellArea::IsFitToRequirements().

◆ DoPlaySoundToAll()

void Battlefield::DoPlaySoundToAll ( uint32  soundId)
451{
453}
void BroadcastPacketToWar(WorldPacket const *data) const
Definition Battlefield.cpp:538
Definition MiscPackets.h:85

References BroadcastPacketToWar().

Referenced by EndBattle(), and StartBattle().

◆ EndBattle()

void Battlefield::EndBattle ( bool  endByTimer)
412{
413 if (!Active)
414 return;
415
416 Active = false;
417
419
420 StartGrouping = false;
421
422 if (!endByTimer)
424
427 else
429
430 // Hook runs BEFORE OnBattleEnd so subscribers can read PlayersInWar
431 // while it is still populated (OnBattleEnd hands out rewards and then
432 // clears the set).
433 sScriptMgr->OnBattlefieldWarEnd(this, endByTimer);
434 OnBattleEnd(endByTimer);
435
436 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
437 {
438 for (ObjectGuid const& guid : Groups[team])
439 if (Group* group = sGroupMgr->GetGroupByGUID(guid.GetCounter()))
440 group->Disband();
441 Groups[team].clear();
442 }
443
444 // Reset battlefield timer
448}
@ BATTLEFIELD_TIMER_GROUP_WAR
Definition Battlefield.h:62
@ BF_ALLIANCE_WINS
Definition Battlefield.h:53
@ BF_HORDE_WINS
Definition Battlefield.h:52
#define sScriptMgr
Definition ScriptMgr.h:740
uint8 constexpr PVP_TEAMS_COUNT
Definition SharedDefines.h:3701
@ TEAM_ALLIANCE
Definition SharedDefines.h:748
Timer
Definition boss_solakar_flamewreath.cpp:29
virtual void SendInitWorldStatesToAll()=0
Send all worldstate data to all players in zone.
virtual void OnBattleEnd(bool)
Called at the end of battle.
Definition Battlefield.h:310
void SetDefenderTeam(TeamId team)
Definition Battlefield.h:270
TaskScheduler _scheduler
Definition Battlefield.h:420
virtual void SendUpdateWorldStates(Player *player=nullptr)=0
TeamId GetAttackerTeam() const
Definition Battlefield.h:268
TeamId GetDefenderTeam() const
Definition Battlefield.h:267
void DoPlaySoundToAll(uint32 soundId)
Definition Battlefield.cpp:450
Definition ObjectGuid.h:118
TaskScheduler & CancelGroup(group_t const group)
Definition TaskScheduler.cpp:53

References _scheduler, Active, BATTLEFIELD_TIMER_GROUP_WAR, BF_ALLIANCE_WINS, BF_HORDE_WINS, TaskScheduler::CancelGroup(), DoPlaySoundToAll(), GetAttackerTeam(), GetDefenderTeam(), NoWarBattleTime, OnBattleEnd(), PVP_TEAMS_COUNT, SendInitWorldStatesToAll(), SendUpdateWorldStates(), SetDefenderTeam(), sGroupMgr, sScriptMgr, StartGrouping, and TEAM_ALLIANCE.

Referenced by bf_commandscript::HandleBattlefieldEnd(), bf_commandscript::HandleBattlefieldSwitch(), BattlefieldWG::ProcessEvent(), and Update().

◆ FillInitialWorldStates()

virtual void Battlefield::FillInitialWorldStates ( WorldPackets::WorldState::InitWorldStates )
pure virtual

Implemented in BattlefieldWG.

Referenced by Player::SendInitWorldStates().

◆ ForEachPlayerInQueue()

template<typename Func >
void Battlefield::ForEachPlayerInQueue ( Func &&  fn) const
inlineprotected
462 {
463 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
464 for (ObjectGuid const& guid : PlayersInQueue[team])
465 if (Player* player = ObjectAccessor::FindPlayer(guid))
466 fn(player);
467 }
Definition ObjectAccessor.h:61

References ObjectAccessor::FindPlayer(), PlayersInQueue, and PVP_TEAMS_COUNT.

Referenced by BroadcastPacketToQueue().

◆ ForEachPlayerInWar() [1/2]

template<typename Func >
void Battlefield::ForEachPlayerInWar ( Func &&  fn) const
inlineprotected
471 {
472 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
473 for (ObjectGuid const& guid : PlayersInWar[team])
474 if (Player* player = ObjectAccessor::FindPlayer(guid))
475 fn(player);
476 }
GuidUnorderedSet PlayersInWar[PVP_TEAMS_COUNT]
Definition Battlefield.h:391

References ObjectAccessor::FindPlayer(), PlayersInWar, and PVP_TEAMS_COUNT.

Referenced by BroadcastPacketToWar(), KickAfkPlayers(), and TeamCastSpell().

◆ ForEachPlayerInWar() [2/2]

template<typename Func >
void Battlefield::ForEachPlayerInWar ( TeamId  team,
Func &&  fn 
) const
inlineprotected
480 {
481 for (ObjectGuid const& guid : PlayersInWar[team])
482 if (Player* player = ObjectAccessor::FindPlayer(guid))
483 fn(player);
484 }

References ObjectAccessor::FindPlayer(), and PlayersInWar.

◆ ForEachPlayerInZone()

template<typename Func >
void Battlefield::ForEachPlayerInZone ( Func &&  fn) const
inlineprotected
453 {
454 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
455 for (ObjectGuid const& guid : Players[team])
456 if (Player* player = ObjectAccessor::FindPlayer(guid))
457 fn(player);
458 }
GuidUnorderedSet Players[PVP_TEAMS_COUNT]
Definition Battlefield.h:389

References ObjectAccessor::FindPlayer(), Players, and PVP_TEAMS_COUNT.

Referenced by BroadcastPacketToZone(), InvitePlayersInZoneToQueue(), InvitePlayersInZoneToWar(), SendUpdateWorldState(), and BattlefieldWG::SetupBattlefield().

◆ GetAttackerTeam()

◆ GetBattleId()

uint32 Battlefield::GetBattleId ( ) const
inline
326{ return BattleId; }

References BattleId.

◆ GetClosestGraveyard()

GraveyardStruct const * Battlefield::GetClosestGraveyard ( Player player)
687{
688 BfGraveyard* closestGY = nullptr;
689 float maxdist = -1;
690 for (BfGraveyard* gy : GraveyardList)
691 {
692 if (!gy)
693 continue;
694
695 if (gy->GetControlTeamId() != player->GetTeamId())
696 continue;
697
698 float dist = gy->GetDistance(player);
699 if (dist < maxdist || maxdist < 0)
700 {
701 closestGY = gy;
702 maxdist = dist;
703 }
704 }
705
706 if (closestGY)
707 return sGraveyard->GetGraveyard(closestGY->GetGraveyardId());
708
709 return nullptr;
710}
#define sGraveyard
Definition GameGraveyard.h:74
uint32 GetGraveyardId() const
Definition Battlefield.h:186
float GetDistance(Player *player)
Definition Battlefield.cpp:767

References BfGraveyard::GetDistance(), BfGraveyard::GetGraveyardId(), Player::GetTeamId(), GraveyardList, and sGraveyard.

◆ GetCreature()

Creature * Battlefield::GetCreature ( ObjectGuid const &  guid)

◆ GetData()

uint32 Battlefield::GetData ( uint32  dataId) const
inlineoverridevirtual

Reimplemented from ZoneScript.

Reimplemented in BattlefieldWG.

262{ return Data32[dataId]; }
std::vector< uint32 > Data32
Definition Battlefield.h:425

References Data32.

Referenced by npc_wg_demolisher_engineer::canBuild(), BattlefieldWG::GetData(), and SpellArea::IsFitToRequirements().

◆ GetData64()

uint64 Battlefield::GetData64 ( uint32  dataId) const
inlineoverridevirtual

Reimplemented from ZoneScript.

258{ return Data64[dataId]; }
Data64
Definition culling_of_stratholme.h:42

◆ GetDefenderTeam()

◆ GetFreeBfRaid()

Group * Battlefield::GetFreeBfRaid ( TeamId  teamId)

Find a not full battlefield group, if there is no, create one.

Parameters
teamId: Id of player team for who we search a group (player->GetTeamId())
586{
587 for (ObjectGuid const& guid : Groups[teamId])
588 if (Group* group = sGroupMgr->GetGroupByGUID(guid.GetCounter()))
589 if (!group->IsFull())
590 return group;
591
592 return nullptr;
593}

References sGroupMgr.

Referenced by AddOrSetPlayerToCorrectBfGroup().

◆ GetGameObject()

GameObject * Battlefield::GetGameObject ( ObjectGuid const &  guid)
854{
855 if (!BfMap)
856 return nullptr;
857
858 return BfMap->GetGameObject(guid);
859}
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Map.cpp:2367

References BfMap, and Map::GetGameObject().

Referenced by BfWGGameObjectBuilding::Destroyed(), BfCapturePoint::GetCapturePointGo(), BattlefieldWG::GetRelic(), BfWGGameObjectBuilding::Rebuild(), and BfWGGameObjectBuilding::UpdateTurretAttack().

◆ GetGraveyardById()

BfGraveyard * Battlefield::GetGraveyardById ( uint32  id) const
672{
673 if (id < GraveyardList.size())
674 {
675 if (GraveyardList[id])
676 return GraveyardList[id];
677 else
678 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} not existed", id);
679 }
680 else
681 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} cant be found", id);
682
683 return nullptr;
684}
#define LOG_ERROR(filterType__,...)
Definition Log.h:145

References GraveyardList, and LOG_ERROR.

Referenced by BattlefieldWG::GetData(), WGWorkshop::GiveControlTo(), BattlefieldWG::OnBattleEnd(), and WGWorkshop::UpdateGraveyardAndWorkshop().

◆ GetGraveyardVector()

GraveyardVect const & Battlefield::GetGraveyardVector ( ) const
inline

◆ GetGroupPlayer()

Group * Battlefield::GetGroupPlayer ( ObjectGuid  guid,
TeamId  teamId 
)

Return battlefield group where player is.

596{
597 for (ObjectGuid const& groupGuid : Groups[teamId])
598 if (Group* group = sGroupMgr->GetGroupByGUID(groupGuid.GetCounter()))
599 if (group->IsMember(guid))
600 return group;
601
602 return nullptr;
603}

References sGroupMgr.

◆ GetInvitedPlayersMap()

PlayerTimerMap const & Battlefield::GetInvitedPlayersMap ( TeamId  teamId) const
inline

Returns the map of players invited to join the active war, value is invite expiry timestamp (per team, read-only).

364{ return InvitedPlayers[teamId]; }
PlayerTimerMap InvitedPlayers[PVP_TEAMS_COUNT]
Definition Battlefield.h:392

References InvitedPlayers.

Referenced by bf_commandscript::HandleBattlefieldQueue().

◆ GetMaxPlayersPerTeam()

uint32 Battlefield::GetMaxPlayersPerTeam ( ) const
inline
356{ return MaxPlayer; }

References MaxPlayer.

◆ GetOtherTeam()

TeamId Battlefield::GetOtherTeam ( TeamId  team) const
inline
269{ return (team == TEAM_HORDE ? TEAM_ALLIANCE : TEAM_HORDE); }
@ TEAM_HORDE
Definition SharedDefines.h:749

References TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by InvitePlayerToQueue().

◆ GetPlayersInWarCount()

uint32 Battlefield::GetPlayersInWarCount ( TeamId  teamId) const
inline
352{ return static_cast<uint32>(PlayersInWar[teamId].size() + InvitedPlayers[teamId].size()); }
std::uint32_t uint32
Definition Define.h:107

References InvitedPlayers, and PlayersInWar.

Referenced by HasWarVacancy().

◆ GetPlayersInWarSet()

GuidUnorderedSet const & Battlefield::GetPlayersInWarSet ( TeamId  teamId) const
inline

Returns the set of players actively fighting in the war (per team, read-only).

366{ return PlayersInWar[teamId]; }

References PlayersInWar.

Referenced by bf_commandscript::HandleBattlefieldQueue().

◆ GetPlayersInZoneCount()

uint32 Battlefield::GetPlayersInZoneCount ( TeamId  teamId) const
inline
354{ return static_cast<uint32>(Players[teamId].size()); }

References Players.

◆ GetPlayersQueueSet()

GuidUnorderedSet const & Battlefield::GetPlayersQueueSet ( TeamId  teamId) const
inline

Returns the set of players waiting in the pre-battle queue (per team, read-only).

361{ return PlayersInQueue[teamId]; }

References PlayersInQueue.

Referenced by bf_commandscript::HandleBattlefieldQueue().

◆ GetTimer()

◆ GetTypeId()

uint32 Battlefield::GetTypeId ( ) const
inline
233{ return TypeId; }

References TypeId.

Referenced by SpellArea::IsFitToRequirements(), and Player::SendInitWorldStates().

◆ GetZoneId()

uint32 Battlefield::GetZoneId ( ) const
inline

◆ HandleKill()

virtual void Battlefield::HandleKill ( Player ,
Unit  
)
inlinevirtual

Called when a Unit is killed in battlefield zone.

Reimplemented in BattlefieldWG.

231{};

◆ HandlePlayerEnterZone()

void Battlefield::HandlePlayerEnterZone ( Player player,
uint32  zone 
)

Called when player (player) enters the zone.

Todo:
: Send a packet to announce it to player
90{
92
93 // Allow scripts to adjust the player's effective team or appearance before
94 // any team-based battlefield containers (such as player lists or queues) are updated.
95 sScriptMgr->OnBattlefieldPlayerEnterZone(this, player);
96
97 TryRejoinAfterLogout(player); // relog: auto-rejoin, skip invite below
98
99 // Xinef: do not invite players on taxi
100 // GMs are not invited to war (see InvitePlayerToWar), so skip queue and slot tracking too
101 if (!player->IsInFlight() && !player->IsGameMaster())
102 {
103 // If battle is started,
104 // If not full of players > invite player to join the war
105 // If full of players > announce to player that BF is full and kick him after a few second if he doesn't leave
106 if (IsWarTime())
107 {
108 if (HasWarVacancy(player->GetTeamId()))
109 InvitePlayerToWar(player);
110 else
111 {
113 PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
114 InvitePlayerToQueue(player);
115 }
116 }
117 else
118 {
119 // If time left is < 15 minutes invite player to join queue
121 InvitePlayerToQueue(player);
122 }
123 }
124
125 Players[player->GetTeamId()].insert(player->GetGUID());
126 OnPlayerEnterZone(player);
127}
bool IsWarTime() const
Return true if battle is started, false if battle is not started.
Definition Battlefield.h:239
PlayerTimerMap PlayersWillBeKick[PVP_TEAMS_COUNT]
Definition Battlefield.h:393
void RemovePlayerFromTracking(ObjectGuid playerGuid, bool removeFromQueue=true)
Definition Battlefield.cpp:77
void InvitePlayerToQueue(Player *player)
Definition Battlefield.cpp:216
void InvitePlayerToWar(Player *player)
Definition Battlefield.cpp:259
void TryRejoinAfterLogout(Player *player)
Definition Battlefield.cpp:636
virtual void OnPlayerEnterZone(Player *)
Called when a player enters the battlefield zone.
Definition Battlefield.h:320
bool HasWarVacancy(TeamId teamId) const
Returns true if there is still room for another player on the given team in the active war.
Definition Battlefield.h:358
bool IsGameMaster() const
Definition Player.h:1174
bool IsInFlight() const
Definition Unit.h:1708
Seconds GetGameTime()
Definition GameTime.cpp:38

References GameTime::GetGameTime(), Object::GetGUID(), Player::GetTeamId(), HasWarVacancy(), InvitePlayerToQueue(), InvitePlayerToWar(), Player::IsGameMaster(), Unit::IsInFlight(), IsWarTime(), OnPlayerEnterZone(), Players, PlayersWillBeKick, RemovePlayerFromTracking(), sScriptMgr, StartGroupingTimer, and TryRejoinAfterLogout().

Referenced by BattlefieldMgr::HandlePlayerEnterZone().

◆ HandlePlayerLeaveZone()

void Battlefield::HandlePlayerLeaveZone ( Player player,
uint32  zone 
)

Called when player (player) leaves the zone.

130{
131 // Logout still runs full leave-war cleanup, but marks the player for grace-window auto-rejoin.
132 bool const isLogout = player->GetSession() && player->GetSession()->PlayerLogout();
133
134 if (IsWarTime())
135 {
136 // If the player is participating to the battle
137 if (PlayersInWar[player->GetTeamId()].erase(player->GetGUID()))
138 {
139 if (isLogout)
140 LogoutGracePlayers[player->GetTeamId()][player->GetGUID()] =
142 else
144
145 if (Group* group = player->GetGroup()) // Remove the player from the raid group
146 if (group->isBFGroup())
147 group->RemoveMember(player->GetGUID());
148
149 OnPlayerLeaveWar(player);
150 sScriptMgr->OnBattlefieldPlayerLeaveWar(this, player);
151 }
152 }
153
154 for (BfCapturePoint* cp : CapturePoints)
155 cp->HandlePlayerLeave(player);
156
157 RemovePlayerFromTracking(player->GetGUID(), /*removeFromQueue=*/false);
158 SendRemoveWorldStates(player);
160 OnPlayerLeaveZone(player);
161}
virtual void SendRemoveWorldStates(Player *)
Definition Battlefield.h:430
static constexpr uint32 LOGOUT_GRACE_SECONDS
Definition Battlefield.h:397
virtual void OnPlayerLeaveZone(Player *)
Called when a player leaves the battlefield zone.
Definition Battlefield.h:318
virtual void OnPlayerLeaveWar(Player *)
Called when a player leaves the battle.
Definition Battlefield.h:316
void RemovePlayerFromResurrectQueue(ObjectGuid playerGuid)
Definition Battlefield.cpp:721
PlayerTimerMap LogoutGracePlayers[PVP_TEAMS_COUNT]
Definition Battlefield.h:395
bool PlayerLogout() const
Definition WorldSession.h:412

References BattleId, CapturePoints, GameTime::GetGameTime(), Player::GetGroup(), Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), IsWarTime(), LOGOUT_GRACE_SECONDS, LogoutGracePlayers, OnPlayerLeaveWar(), OnPlayerLeaveZone(), WorldSession::PlayerLogout(), PlayersInWar, RemovePlayerFromResurrectQueue(), RemovePlayerFromTracking(), WorldSession::SendBfLeaveMessage(), SendRemoveWorldStates(), and sScriptMgr.

◆ HasPlayer()

bool Battlefield::HasPlayer ( Player player) const
protected
456{
457 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
458 if (Players[i].count(player->GetGUID()))
459 return true;
460 return false;
461}

References Object::GetGUID(), Players, and PVP_TEAMS_COUNT.

◆ HasWarVacancy()

bool Battlefield::HasWarVacancy ( TeamId  teamId) const
inline

Returns true if there is still room for another player on the given team in the active war.

358{ return GetPlayersInWarCount(teamId) < MaxPlayer; }
uint32 GetPlayersInWarCount(TeamId teamId) const
Definition Battlefield.h:352

References GetPlayersInWarCount(), and MaxPlayer.

Referenced by HandlePlayerEnterZone(), InvitePlayersInQueueToWar(), InvitePlayersInZoneToWar(), and TryRejoinAfterLogout().

◆ HideNpc()

void Battlefield::HideNpc ( Creature creature)
560{
561 creature->CombatStop();
562 creature->SetReactState(REACT_PASSIVE);
564 creature->SetPhaseMask(2, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
565 creature->DisappearAndDie();
566 creature->SetVisible(false);
567}
@ UNIT_FLAG_NON_ATTACKABLE
Definition UnitDefines.h:258
@ UNIT_FLAG_NOT_SELECTABLE
Definition UnitDefines.h:282
@ REACT_PASSIVE
Definition Unit.h:566
void SetReactState(ReactStates state)
A creature can have 3 ReactStates : Agressive, Passive, Neutral.
Definition Creature.h:100
void DisappearAndDie()
Definition Creature.cpp:361
void SetVisible(bool x)
Definition Unit.cpp:11128
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition Unit.cpp:15345
void CombatStop(bool includingCast=false, bool mutualPvP=true)
Definition Unit.cpp:7504
void SetUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:748

References Unit::CombatStop(), Creature::DisappearAndDie(), REACT_PASSIVE, Unit::SetPhaseMask(), Creature::SetReactState(), Unit::SetUnitFlag(), Unit::SetVisible(), UNIT_FLAG_NON_ATTACKABLE, and UNIT_FLAG_NOT_SELECTABLE.

Referenced by BfWGGameObjectBuilding::Damaged(), BfWGGameObjectBuilding::Init(), BattlefieldWG::OnBattleEnd(), BattlefieldWG::SetupBattlefield(), BfWGGameObjectBuilding::UpdateCreatureAndGo(), and BfWGGameObjectBuilding::UpdateTurretAttack().

◆ InitStalker()

void Battlefield::InitStalker ( uint32  entry,
float  x,
float  y,
float  z,
float  o 
)
297{
298 if (Creature* creature = SpawnCreature(entry, x, y, z, o, TEAM_NEUTRAL))
299 StalkerGuid = creature->GetGUID();
300 else
301 LOG_ERROR("bg.battlefield", "Battlefield::InitStalker: could not spawn Stalker (Creature entry {}), zone messages will be unavailable", entry);
302}
ObjectGuid StalkerGuid
Definition Battlefield.h:379
Creature * SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId teamId)
Definition Battlefield.cpp:783
Definition Creature.h:47

References LOG_ERROR, SpawnCreature(), StalkerGuid, and TEAM_NEUTRAL.

Referenced by BattlefieldWG::SetupBattlefield().

◆ InvitePlayersInQueueToWar()

void Battlefield::InvitePlayersInQueueToWar ( )

Invite all players in queue to join battle on battle start.

229{
230 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
231 {
233 for (ObjectGuid const& guid : copy)
234 if (Player* player = ObjectAccessor::FindPlayer(guid))
235 if (HasWarVacancy(player->GetTeamId()))
236 InvitePlayerToWar(player);
237 PlayersInQueue[team].clear();
238 }
239}
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:257
TeamId GetTeamId(PvPTeamId teamId)
Definition SharedDefines.h:3718

References ObjectAccessor::FindPlayer(), HasWarVacancy(), InvitePlayerToWar(), PlayersInQueue, and PVP_TEAMS_COUNT.

Referenced by StartBattle().

◆ InvitePlayersInZoneToQueue()

void Battlefield::InvitePlayersInZoneToQueue ( )

Invite all players in zone to join the queue, called x minutes before battle start in Update()

212{
213 ForEachPlayerInZone([this](Player* player) { InvitePlayerToQueue(player); });
214}

References ForEachPlayerInZone(), and InvitePlayerToQueue().

Referenced by Update().

◆ InvitePlayersInZoneToWar()

void Battlefield::InvitePlayersInZoneToWar ( )

Invite all players in zone to join battle on battle start.

242{
243 ForEachPlayerInZone([this](Player* player)
244 {
245 // Skip GMs: they are never invited, so they would linger in PlayersWillBeKick forever
246 if (player->IsGameMaster())
247 return;
248
249 if (IsPlayerInWarOrInvited(player))
250 return;
251
252 if (HasWarVacancy(player->GetTeamId()))
253 InvitePlayerToWar(player);
254 else if (!PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID())) // Battlefield is full of players
255 PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
256 });
257}
bool IsPlayerInWarOrInvited(Player *player) const
Returns true if the player is already tracked as actively in the war or invited to join it.
Definition Battlefield.cpp:304

References ForEachPlayerInZone(), GameTime::GetGameTime(), Object::GetGUID(), Player::GetTeamId(), HasWarVacancy(), InvitePlayerToWar(), Player::IsGameMaster(), IsPlayerInWarOrInvited(), and PlayersWillBeKick.

Referenced by StartBattle().

◆ InvitePlayerToQueue()

void Battlefield::InvitePlayerToQueue ( Player player)
217{
218 if (player->IsGameMaster()) // GMs are not invited to war, so don't queue them either
219 return;
220
221 if (PlayersInQueue[player->GetTeamId()].count(player->GetGUID()))
222 return;
223
224 if (PlayersInQueue[player->GetTeamId()].size() <= MinPlayer || PlayersInQueue[GetOtherTeam(player->GetTeamId())].size() >= MinPlayer)
226}
TeamId GetOtherTeam(TeamId team) const
Definition Battlefield.h:269
void SendBfInvitePlayerToQueue(uint32 battleId)
Definition BattlefieldHandler.cpp:42

References BattleId, Object::GetGUID(), GetOtherTeam(), Player::GetSession(), Player::GetTeamId(), Player::IsGameMaster(), MinPlayer, PlayersInQueue, and WorldSession::SendBfInvitePlayerToQueue().

Referenced by HandlePlayerEnterZone(), InvitePlayersInZoneToQueue(), and npc_wg_queue::OnGossipSelect().

◆ InvitePlayerToWar()

void Battlefield::InvitePlayerToWar ( Player player)
Todo:
: needed ?
260{
261 if (!player)
262 return;
263
264 if (player->IsGameMaster())
265 return;
266
268 if (player->IsInFlight())
269 return;
270
271 if (player->InBattleground())
272 {
273 PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
274 return;
275 }
276
277 // If the player does not match minimal level requirements for the battlefield, kick him
278 if (player->GetLevel() < MinLevel)
279 {
280 if (!PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()))
281 PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
282 return;
283 }
284
285 // Check if player is not already in war
286 if (IsPlayerInWarOrInvited(player))
287 return;
288
289 sScriptMgr->OnBattlefieldBeforeInvitePlayerToWar(this, player);
290
291 PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
294}
bool InBattleground() const
Definition Player.h:2291
uint8 GetLevel() const
Definition Unit.h:1103
void SendBfInvitePlayerToWar(uint32 battleId, uint32 zoneId, uint32 time)
Definition BattlefieldHandler.cpp:31

References BattleId, GameTime::GetGameTime(), Object::GetGUID(), Unit::GetLevel(), Player::GetSession(), Player::GetTeamId(), Player::InBattleground(), InvitedPlayers, Player::IsGameMaster(), Unit::IsInFlight(), IsPlayerInWarOrInvited(), MinLevel, PlayersInQueue, PlayersWillBeKick, WorldSession::SendBfInvitePlayerToWar(), sScriptMgr, TimeForAcceptInvite, and ZoneId.

Referenced by HandlePlayerEnterZone(), InvitePlayersInQueueToWar(), InvitePlayersInZoneToWar(), and npc_wg_queue::OnGossipSelect().

◆ IsEnabled()

bool Battlefield::IsEnabled ( ) const
inline

Return if battlefield is enabled.

244{ return Enabled; }

References Enabled.

Referenced by bf_commandscript::HandleBattlefieldEnable(), and Update().

◆ IsPlayerInBattlefield()

bool Battlefield::IsPlayerInBattlefield ( ObjectGuid  guid) const
311{
312 if (!IsWarTime())
313 return false;
314
315 // PlayersInWar is split into per-team sets, but a GUID alone does not indicate the team, so check both sets.
316 // This also stays correct if an OnBattlefieldPlayerJoinWar handler reassigned the team GetTeamId() returns.
317 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
318 if (PlayersInWar[team].count(guid))
319 return true;
320
321 return false;
322}

References IsWarTime(), PlayersInWar, and PVP_TEAMS_COUNT.

◆ IsPlayerInWarOrInvited()

bool Battlefield::IsPlayerInWarOrInvited ( Player player) const
protected

Returns true if the player is already tracked as actively in the war or invited to join it.

305{
306 TeamId teamId = player->GetTeamId();
307 return PlayersInWar[teamId].count(player->GetGUID()) || InvitedPlayers[teamId].count(player->GetGUID());
308}

References Object::GetGUID(), Player::GetTeamId(), InvitedPlayers, and PlayersInWar.

Referenced by InvitePlayersInZoneToWar(), and InvitePlayerToWar().

◆ IsWarTime()

◆ KickAfkPlayers()

void Battlefield::KickAfkPlayers ( )
protected
325{
326 ForEachPlayerInWar([this](Player* player)
327 {
328 if (player->isAFK() && player->GetZoneId() == GetZoneId() && !player->IsGameMaster())
329 player->TeleportTo(KickPosition);
330 });
331}
uint32 GetZoneId() const
Definition Battlefield.h:234
WorldLocation KickPosition
Definition Battlefield.h:412
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0, Unit *target=nullptr, bool newInstance=false)
Definition Player.cpp:1353
bool isAFK() const
Definition Player.h:1149
uint32 GetZoneId() const
Definition Object.cpp:3111

References ForEachPlayerInWar(), GetZoneId(), WorldObject::GetZoneId(), Player::isAFK(), Player::IsGameMaster(), KickPosition, and Player::TeleportTo().

Referenced by StartBattle().

◆ KickPlayerFromBattlefield()

void Battlefield::KickPlayerFromBattlefield ( ObjectGuid  guid)

Kick player from battlefield and teleport him to kick-point location.

Parameters
guid: guid of player who must be kicked
334{
335 if (Player* player = ObjectAccessor::FindPlayer(guid))
336 if (player->GetZoneId() == GetZoneId() && !player->IsGameMaster()
337 && !PlayersInWar[player->GetTeamId()].count(guid))
338 {
339 player->TeleportTo(KickPosition);
340 // Eagerly drop zone tracking: the teleport's zone change does not
341 // propagate until the next Player::Update, so callers iterating
342 // Players[team] in the same tick would otherwise still see them.
343 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
344 Players[i].erase(guid);
345 }
346}

References ObjectAccessor::FindPlayer(), GetZoneId(), KickPosition, Players, PlayersInWar, and PVP_TEAMS_COUNT.

Referenced by WorldSession::HandleBfEntryInviteResponse(), BattlefieldWG::OnPlayerEnterZone(), and StartBattle().

◆ OnBattleEnd()

virtual void Battlefield::OnBattleEnd ( bool  )
inlinevirtual

Called at the end of battle.

Reimplemented in BattlefieldWG.

310{};

Referenced by EndBattle().

◆ OnBattleStart()

virtual void Battlefield::OnBattleStart ( )
inlinevirtual

Called on start.

Reimplemented in BattlefieldWG.

308{};

Referenced by StartBattle().

◆ OnPlayerEnterZone()

virtual void Battlefield::OnPlayerEnterZone ( Player )
inlinevirtual

Called when a player enters the battlefield zone.

Reimplemented in BattlefieldWG.

320{};

Referenced by HandlePlayerEnterZone().

◆ OnPlayerJoinWar()

virtual void Battlefield::OnPlayerJoinWar ( Player )
inlinevirtual

Called when a player accepts to join the battle.

Reimplemented in BattlefieldWG.

314{};

Referenced by PlayerAcceptInviteToWar(), and TryRejoinAfterLogout().

◆ OnPlayerLeaveWar()

virtual void Battlefield::OnPlayerLeaveWar ( Player )
inlinevirtual

Called when a player leaves the battle.

Reimplemented in BattlefieldWG.

316{};

Referenced by HandlePlayerLeaveZone().

◆ OnPlayerLeaveZone()

virtual void Battlefield::OnPlayerLeaveZone ( Player )
inlinevirtual

Called when a player leaves the battlefield zone.

Reimplemented in BattlefieldWG.

318{};

Referenced by HandlePlayerLeaveZone().

◆ OnStartGrouping()

virtual void Battlefield::OnStartGrouping ( )
inlinevirtual

Called x minutes before battle start when players in zone are invited to join queue.

Reimplemented in BattlefieldWG.

312{};

Referenced by Update().

◆ PlayerAcceptInviteToQueue()

void Battlefield::PlayerAcceptInviteToQueue ( Player player)
465{
466 // Add player in queue
467 PlayersInQueue[player->GetTeamId()].insert(player->GetGUID());
468 // Send notification
470}
void SendBfQueueInviteResponse(uint32 battleId, uint32 zoneId, bool canQueue=true, bool full=false)
Definition BattlefieldHandler.cpp:55

References BattleId, Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), PlayersInQueue, WorldSession::SendBfQueueInviteResponse(), and ZoneId.

Referenced by WorldSession::HandleBfQueueInviteResponse().

◆ PlayerAcceptInviteToWar()

void Battlefield::PlayerAcceptInviteToWar ( Player player)
490{
491 if (!IsWarTime())
492 return;
493
494 // Reject unknown / expired invites; the kick task only sweeps every 5s.
495 TeamId const invitedTeam = player->GetTeamId();
496 auto itr = InvitedPlayers[invitedTeam].find(player->GetGUID());
497 if (itr == InvitedPlayers[invitedTeam].end()
498 || itr->second <= GameTime::GetGameTime().count())
499 return;
500
501 sScriptMgr->OnBattlefieldPlayerJoinWar(this, player);
502
504 {
506 PlayersInWar[player->GetTeamId()].insert(player->GetGUID());
507 // Use pre-hook team: JoinWar may have just reassigned GetTeamId().
508 InvitedPlayers[invitedTeam].erase(player->GetGUID());
509
510 if (player->isAFK())
511 player->ToggleAFK();
512
513 OnPlayerJoinWar(player);
514 }
515}
virtual void OnPlayerJoinWar(Player *)
Called when a player accepts to join the battle.
Definition Battlefield.h:314
bool AddOrSetPlayerToCorrectBfGroup(Player *player)
Force player to join a battlefield group.
Definition Battlefield.cpp:605
void ToggleAFK()
Definition Player.cpp:1311
void SendBfEntered(uint32 battleId)
Definition BattlefieldHandler.cpp:68

References AddOrSetPlayerToCorrectBfGroup(), BattleId, GameTime::GetGameTime(), Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), InvitedPlayers, Player::isAFK(), IsWarTime(), OnPlayerJoinWar(), PlayersInWar, WorldSession::SendBfEntered(), sScriptMgr, and Player::ToggleAFK().

Referenced by WorldSession::HandleBfEntryInviteResponse().

◆ PlayerAskToLeave()

void Battlefield::PlayerAskToLeave ( Player player)
483{
484 // Player leaving Wintergrasp, teleport to homebind position.
485 player->TeleportTo(player->m_homebindMapId, player->m_homebindX, player->m_homebindY, player->m_homebindZ, player->GetOrientation());
486}
float m_homebindZ
Definition Player.h:2415
uint32 m_homebindMapId
Definition Player.h:2411
float m_homebindY
Definition Player.h:2414
float m_homebindX
Definition Player.h:2413
float GetOrientation() const
Definition Position.h:124

References Position::GetOrientation(), Player::m_homebindMapId, Player::m_homebindX, Player::m_homebindY, Player::m_homebindZ, and Player::TeleportTo().

◆ RegisterZone()

void Battlefield::RegisterZone ( uint32  zoneId)
protected
555{
556 sBattlefieldMgr->AddZone(zoneId, this);
557}
#define sBattlefieldMgr
Definition BattlefieldMgr.h:79

References sBattlefieldMgr.

Referenced by BattlefieldWG::SetupBattlefield().

◆ RemovePlayerFromResurrectQueue()

void Battlefield::RemovePlayerFromResurrectQueue ( ObjectGuid  playerGuid)
722{
723 Player* player = ObjectAccessor::FindPlayer(playerGuid);
724 if (!player)
725 return;
726
728}
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:5189

References ObjectAccessor::FindPlayer(), Unit::RemoveAurasDueToSpell(), and SPELL_WAITING_FOR_RESURRECT.

Referenced by HandlePlayerLeaveZone().

◆ RemovePlayerFromTracking()

void Battlefield::RemovePlayerFromTracking ( ObjectGuid  playerGuid,
bool  removeFromQueue = true 
)
protected
78{
79 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
80 {
81 InvitedPlayers[i].erase(playerGuid);
82 if (removeFromQueue)
83 PlayersInQueue[i].erase(playerGuid);
84 PlayersWillBeKick[i].erase(playerGuid);
85 Players[i].erase(playerGuid);
86 }
87}

References InvitedPlayers, Players, PlayersInQueue, PlayersWillBeKick, and PVP_TEAMS_COUNT.

Referenced by HandlePlayerEnterZone(), and HandlePlayerLeaveZone().

◆ SendAreaSpiritHealerQueryOpcode()

void Battlefield::SendAreaSpiritHealerQueryOpcode ( Player player,
ObjectGuid const &  guid 
)
731{
734 uint32 time = static_cast<uint32>(std::clamp(remaining,
735 Milliseconds::zero(), Milliseconds(RESURRECTION_INTERVAL)).count());
736
737 data << guid << time;
738 ASSERT(player);
739 player->SendDirectMessage(&data);
740}
@ BATTLEFIELD_TIMER_GROUP_RESURRECT
Definition Battlefield.h:61
#define RESURRECTION_INTERVAL
Definition Battleground.h:163
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:27
#define ASSERT
Definition Errors.h:68
Milliseconds GetNextGroupOccurrence(group_t const group) const
Definition TaskScheduler.cpp:127
Definition WorldPacket.h:26
@ SMSG_AREA_SPIRIT_HEALER_TIME
Definition Opcodes.h:770

References _scheduler, ASSERT, BATTLEFIELD_TIMER_GROUP_RESURRECT, TaskScheduler::GetNextGroupOccurrence(), RESURRECTION_INTERVAL, Player::SendDirectMessage(), and SMSG_AREA_SPIRIT_HEALER_TIME.

Referenced by npc_wg_spirit_guide::OnGossipHello().

◆ SendInitWorldStatesToAll()

virtual void Battlefield::SendInitWorldStatesToAll ( )
pure virtual

Send all worldstate data to all players in zone.

Implemented in BattlefieldWG.

Referenced by EndBattle(), and bf_commandscript::HandleBattlefieldTimer().

◆ SendRemoveWorldStates()

virtual void Battlefield::SendRemoveWorldStates ( Player )
inlineprotectedvirtual
430{}

Referenced by HandlePlayerLeaveZone().

◆ SendUpdateWorldState()

void Battlefield::SendUpdateWorldState ( uint32  field,
uint32  value 
)

Update data of a worldstate to all players present in zone.

550{
551 ForEachPlayerInZone([field, value](Player* player) { player->SendUpdateWorldState(field, value); });
552}
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition PlayerUpdates.cpp:2240

References ForEachPlayerInZone(), and Player::SendUpdateWorldState().

Referenced by BfWGGameObjectBuilding::Damaged(), BfWGGameObjectBuilding::Destroyed(), WGWorkshop::GiveControlTo(), and BfWGGameObjectBuilding::Rebuild().

◆ SendUpdateWorldStates()

virtual void Battlefield::SendUpdateWorldStates ( Player player = nullptr)
pure virtual

Implemented in BattlefieldWG.

Referenced by EndBattle(), StartBattle(), and Update().

◆ SendWarning()

void Battlefield::SendWarning ( uint8  id,
WorldObject const *  target = nullptr 
)
544{
545 if (Creature* stalker = GetCreature(StalkerGuid))
546 sCreatureTextMgr->SendChat(stalker, id, target);
547}
#define sCreatureTextMgr
Definition CreatureTextMgr.h:110
Creature * GetCreature(ObjectGuid const &guid)
Definition Battlefield.cpp:845

References GetCreature(), sCreatureTextMgr, and StalkerGuid.

Referenced by BfWGGameObjectBuilding::Damaged(), BfWGGameObjectBuilding::Destroyed(), WGWorkshop::GiveControlTo(), BattlefieldWG::OnBattleEnd(), BattlefieldWG::OnBattleStart(), BattlefieldWG::OnStartGrouping(), and BattlefieldWG::PromotePlayer().

◆ SetData()

void Battlefield::SetData ( uint32  dataId,
uint32  value 
)
inlineoverridevirtual

Reimplemented from ZoneScript.

263{ Data32[dataId] = value; }

References Data32.

Referenced by BattlefieldWG::OnBattleStart(), and BattlefieldWG::UpdateCounterVehicle().

◆ SetData64()

void Battlefield::SetData64 ( uint32  dataId,
uint64  value 
)
inlineoverridevirtual

Reimplemented from ZoneScript.

259{ Data64[dataId] = value; }

◆ SetDefenderTeam()

void Battlefield::SetDefenderTeam ( TeamId  team)
inline
270{ DefenderTeam = team; }

References DefenderTeam.

Referenced by EndBattle().

◆ SetGraveyardNumber()

void Battlefield::SetGraveyardNumber ( uint32  number)
inline
294{ GraveyardList.resize(number); }

References GraveyardList.

Referenced by BattlefieldWG::SetupBattlefield().

◆ SetTimer()

void Battlefield::SetTimer ( uint32  timer)
inline
349{ Timer = timer; }

Referenced by bf_commandscript::HandleBattlefieldTimer().

◆ SetupBattlefield()

virtual bool Battlefield::SetupBattlefield ( )
inlinevirtual

Call this to init the Battlefield.

Reimplemented in BattlefieldWG.

209{ return true; }

Referenced by BattlefieldMgr::InitBattlefield().

◆ ShowNpc()

void Battlefield::ShowNpc ( Creature creature,
bool  aggressive 
)
570{
571 creature->SetPhaseMask(1, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
572 creature->SetVisible(true);
574 if (!creature->IsAlive())
575 creature->Respawn(true);
576 if (aggressive)
578 else
579 {
581 creature->SetReactState(REACT_PASSIVE);
582 }
583}
@ REACT_AGGRESSIVE
Definition Unit.h:568
void Respawn(bool force=false)
Definition Creature.cpp:2019
bool IsAlive() const
Definition Unit.h:1797
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition Unit.h:749

References Unit::IsAlive(), REACT_AGGRESSIVE, REACT_PASSIVE, Unit::RemoveUnitFlag(), Creature::Respawn(), Unit::SetPhaseMask(), Creature::SetReactState(), Unit::SetUnitFlag(), Unit::SetVisible(), UNIT_FLAG_NON_ATTACKABLE, and UNIT_FLAG_NOT_SELECTABLE.

Referenced by BattlefieldWG::OnBattleEnd(), BattlefieldWG::OnBattleStart(), BfWGGameObjectBuilding::UpdateCreatureAndGo(), and BfWGGameObjectBuilding::UpdateTurretAttack().

◆ SpawnCreature() [1/2]

Creature * Battlefield::SpawnCreature ( uint32  entry,
float  x,
float  y,
float  z,
float  o,
TeamId  teamId 
)
784{
785 Map* map = sMapMgr->CreateBaseMap(MapId);
786 if (!map)
787 {
788 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {} map not found", entry);
789 return nullptr;
790 }
791
792 CreatureTemplate const* cinfo = sObjectMgr->GetCreatureTemplate(entry);
793 if (!cinfo)
794 {
795 LOG_ERROR("sql.sql", "Battlefield::SpawnCreature: entry {} does not exist.", entry);
796 return nullptr;
797 }
798
799 Creature* creature = new Creature();
800 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, PHASEMASK_NORMAL, entry, 0, x, y, z, o))
801 {
802 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {}", entry);
803 delete creature;
804 return nullptr;
805 }
806
807 // no need to set faction for neutral team
808 if (teamId == TEAM_ALLIANCE || teamId == TEAM_HORDE)
809 creature->SetFaction(BattlefieldFactions[teamId]);
810
811 creature->SetHomePosition(x, y, z, o);
812
813 // force using DB speeds -- do we really need this?
814 creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
815 creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
816
817 map->AddToMap(creature);
818 creature->setActive(true);
819
820 return creature;
821}
const uint32 BattlefieldFactions[PVP_TEAMS_COUNT]
Definition Battlefield.h:66
#define sMapMgr
Definition MapMgr.h:220
#define sObjectMgr
Definition ObjectMgr.h:1732
@ PHASEMASK_NORMAL
Definition Object.h:63
@ MOVE_RUN
Definition UnitDefines.h:357
@ MOVE_WALK
Definition UnitDefines.h:356
void SetHomePosition(float x, float y, float z, float o)
Definition Creature.h:347
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 vehId, float x, float y, float z, float ang, const CreatureData *data=nullptr)
Definition Creature.cpp:1151
Definition Map.h:166
ObjectGuid::LowType GenerateLowGuid()
Definition Map.h:519
bool AddToMap(T *, bool checkTransport=false)
Definition Map.cpp:304
void SetFaction(uint32 faction)
Definition Unit.cpp:7091
void SetSpeed(UnitMoveType mtype, float rate, bool forced=false)
Definition Unit.cpp:11326
void setActive(bool isActiveObject)
Definition Object.cpp:1082
Definition CreatureData.h:187
float speed_run
Definition CreatureData.h:202
float speed_walk
Definition CreatureData.h:201

References Map::AddToMap(), BattlefieldFactions, Creature::Create(), Map::GenerateLowGuid(), LOG_ERROR, MapId, MOVE_RUN, MOVE_WALK, PHASEMASK_NORMAL, WorldObject::setActive(), Unit::SetFaction(), Creature::SetHomePosition(), Unit::SetSpeed(), sMapMgr, sObjectMgr, CreatureTemplate::speed_run, CreatureTemplate::speed_walk, TEAM_ALLIANCE, TEAM_HORDE, and Unit.

Referenced by BfWGGameObjectBuilding::Init(), InitStalker(), BattlefieldWG::SetupBattlefield(), and SpawnCreature().

◆ SpawnCreature() [2/2]

Creature * Battlefield::SpawnCreature ( uint32  entry,
Position  pos,
TeamId  teamId 
)
779{
780 return SpawnCreature(entry, pos.m_positionX, pos.m_positionY, pos.m_positionZ, pos.m_orientation, teamId);
781}
float m_positionZ
Definition Position.h:57
float m_positionX
Definition Position.h:55
float m_positionY
Definition Position.h:56
float m_orientation
Definition Position.h:58

References Position::m_orientation, Position::m_positionX, Position::m_positionY, Position::m_positionZ, and SpawnCreature().

◆ SpawnGameObject()

GameObject * Battlefield::SpawnGameObject ( uint32  entry,
float  x,
float  y,
float  z,
float  o 
)
824{
825 Map* map = sMapMgr->CreateBaseMap(MapId);
826 if (!map)
827 return nullptr;
828
829 GameObject* go = sObjectMgr->IsGameObjectStaticTransport(entry) ? new StaticTransport() : new GameObject();
830 G3D::Quat rotation = G3D::Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), o);
831 if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, PHASEMASK_NORMAL, x, y, z, o, rotation, 100, GO_STATE_READY))
832 {
833 LOG_ERROR("sql.sql", "Battlefield::SpawnGameObject: Gameobject template {} not found in database! Battlefield not created!", entry);
834 LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Cannot create gameobject template {}! Battlefield not created!", entry);
835 delete go;
836 return nullptr;
837 }
838
839 map->AddToMap(go);
840 go->setActive(true);
841
842 return go;
843}
@ GO_STATE_READY
Definition GameObjectData.h:709
Definition GameObject.h:120
virtual bool Create(ObjectGuid::LowType guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, G3D::Quat const &rotation, uint32 animprogress, GOState go_state, uint32 artKit=0)
Definition GameObject.cpp:270
Definition Transport.h:115

References Map::AddToMap(), GameObject::Create(), GameObject, Map::GenerateLowGuid(), GO_STATE_READY, LOG_ERROR, MapId, PHASEMASK_NORMAL, WorldObject::setActive(), sMapMgr, and sObjectMgr.

Referenced by BfWGGameObjectBuilding::Init(), BattlefieldWG::OnBattleStart(), and BattlefieldWG::SetupBattlefield().

◆ StartBattle()

void Battlefield::StartBattle ( )
349{
350 if (Active)
351 return;
352
353 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
354 {
355 PlayersInWar[team].clear();
356 Groups[team].clear();
357 LogoutGracePlayers[team].clear();
358 }
359
361 Active = true;
362
363 // Schedule war-only periodic timers
365 {
367 context.Repeat(20s);
368 });
369
371 {
372 time_t const now = GameTime::GetGameTime().count();
373
374 // Send eject so the 3.3.5 client closes its popup (it does not on its
375 // own when the timer hits zero), then drop the entry and teleport.
376 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
377 {
378 std::vector<ObjectGuid> expired;
379 for (auto const& [guid, expireAt] : InvitedPlayers[team])
380 if (expireAt <= now)
381 expired.push_back(guid);
382
383 for (ObjectGuid const& guid : expired)
384 {
385 if (Player* player = ObjectAccessor::FindPlayer(guid))
386 player->GetSession()->SendBfLeaveMessage(BattleId, BF_LEAVE_REASON_EXITED);
387 InvitedPlayers[team].erase(guid);
389 }
390 }
391
393 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
394 for (PlayerTimerMap::value_type const& pair : PlayersWillBeKick[team])
395 if (pair.second <= now)
396 KickPlayerFromBattlefield(pair.first);
397
398 context.Repeat(5s);
399 });
400
403
405
407
409}
@ BF_START
Definition Battlefield.h:54
void InvitePlayersInQueueToWar()
Invite all players in queue to join battle on battle start.
Definition Battlefield.cpp:228
void KickPlayerFromBattlefield(ObjectGuid guid)
Kick player from battlefield and teleport him to kick-point location.
Definition Battlefield.cpp:333
virtual void OnBattleStart()
Called on start.
Definition Battlefield.h:308
void InvitePlayersInZoneToWar()
Invite all players in zone to join battle on battle start.
Definition Battlefield.cpp:241
void KickAfkPlayers()
Definition Battlefield.cpp:324
Definition TaskScheduler.h:422
TaskContext & Repeat(std::chrono::duration< _Rep, _Period > const &duration)
Definition TaskScheduler.h:494
TaskScheduler & Schedule(std::chrono::duration< _Rep, _Period > const &time, task_handler_t const &task)
Definition TaskScheduler.h:233
@ BF_LEAVE_REASON_EXITED
Definition WorldSession.h:266

References _scheduler, Active, BATTLEFIELD_TIMER_GROUP_WAR, BattleId, BattleTime, BF_LEAVE_REASON_EXITED, BF_START, DoPlaySoundToAll(), ObjectAccessor::FindPlayer(), GameTime::GetGameTime(), InvitedPlayers, InvitePlayersInQueueToWar(), InvitePlayersInZoneToWar(), KickAfkPlayers(), KickPlayerFromBattlefield(), LogoutGracePlayers, OnBattleStart(), PlayersInWar, PlayersWillBeKick, PVP_TEAMS_COUNT, TaskContext::Repeat(), TaskScheduler::Schedule(), and SendUpdateWorldStates().

Referenced by bf_commandscript::HandleBattlefieldStart(), and Update().

◆ TeamApplyBuff()

void Battlefield::TeamApplyBuff ( TeamId  team,
uint32  spellId,
uint32  spellId2 = 0 
)

◆ TeamCastSpell()

void Battlefield::TeamCastSpell ( TeamId  team,
int32  spellId 
)
protected
518{
519 ForEachPlayerInWar(team, [spellId](Player* player)
520 {
521 if (spellId > 0)
522 player->CastSpell(player, uint32(spellId), true);
523 else
524 player->RemoveAuraFromStack(uint32(-spellId));
525 });
526}
void RemoveAuraFromStack(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:5205

References Unit::CastSpell(), ForEachPlayerInWar(), and Unit::RemoveAuraFromStack().

◆ ToggleBattlefield()

void Battlefield::ToggleBattlefield ( bool  enable)
inline

Enable or Disable battlefield.

242{ Enabled = enable; }

References Enabled.

Referenced by bf_commandscript::HandleBattlefieldEnable().

◆ TryRejoinAfterLogout()

void Battlefield::TryRejoinAfterLogout ( Player player)

Auto-rejoin a player who relogged within the grace window after a mid-war logout, via the normal join hooks. No-op without a pending logout marker. Called from HandlePlayerEnterZone (which fires on the post-login zone set).

637{
638 ObjectGuid const guid = player->GetGUID();
639 time_t const now = GameTime::GetGameTime().count();
640
641 // Consume the marker and honor its grace window (check both teams; team may have changed).
642 bool pending = false;
643 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
644 if (auto itr = LogoutGracePlayers[team].find(guid); itr != LogoutGracePlayers[team].end())
645 {
646 pending = itr->second > now;
647 LogoutGracePlayers[team].erase(itr);
648 }
649
650 // Vacancy gate mirrors HandlePlayerEnterZone (full team -> queue path). Pre-hook:
651 // we can't abort after JoinWar, which may already have mutated module state.
652 if (!pending || !IsWarTime() || !HasWarVacancy(player->GetTeamId()))
653 return;
654
655 if (Group* current = player->GetGroup())
656 if (current->isBGGroup() || current->isBFGroup())
657 return;
658
659 // Rejoin via the normal join path: firing JoinWar lets modules rebuild
660 // per-session (Player*-keyed) state and pick the team before the raid bind.
661 sScriptMgr->OnBattlefieldPlayerJoinWar(this, player);
662
664 {
666 PlayersInWar[player->GetTeamId()].insert(guid);
667 OnPlayerJoinWar(player);
668 }
669}

References AddOrSetPlayerToCorrectBfGroup(), BattleId, GameTime::GetGameTime(), Player::GetGroup(), Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), HasWarVacancy(), IsWarTime(), LogoutGracePlayers, OnPlayerJoinWar(), PlayersInWar, PVP_TEAMS_COUNT, WorldSession::SendBfEntered(), and sScriptMgr.

Referenced by HandlePlayerEnterZone().

◆ Update()

bool Battlefield::Update ( uint32  diff)
virtual

Called every time for update bf data and time.

  • Update timer for start/end battle
  • Invite player in zone to queue StartGroupingTimer minutes before start
  • Kick Afk players
    Parameters
    diff: time elapsed since last call (in ms)

Reimplemented in BattlefieldWG.

164{
165 if (Timer <= diff)
166 {
167 uint32 sessionLimit = sWorld->getIntConfig(CONFIG_WINTERGRASP_SKIP_BATTLE_SESSION_COUNT);
168 bool tooManySessions = sessionLimit && !IsWarTime()
169 && sWorldSessionMgr->GetActiveSessionCount() > sessionLimit;
170
171 if (!IsEnabled() || tooManySessions)
172 {
173 Active = true;
174 EndBattle(false);
175 return false;
176 }
177 // Battlefield ends on time
178 if (IsWarTime())
179 EndBattle(true);
180 else // Time to start a new battle!
181 StartBattle();
182 }
183 else
184 Timer -= diff;
185
186 if (!IsEnabled())
187 return false;
188
189 // Invite players a few minutes before the battle's beginning
191 {
192 StartGrouping = true;
196 }
197
199
200 bool objectiveChanged = false;
201 if (IsWarTime())
202 {
203 for (BfCapturePoint* cp : CapturePoints)
204 if (cp->Update(diff))
205 objectiveChanged = true;
206 }
207
208 return objectiveChanged;
209}
@ CONFIG_WINTERGRASP_SKIP_BATTLE_SESSION_COUNT
Definition WorldConfig.h:332
#define sWorldSessionMgr
Definition WorldSessionMgr.h:108
void EndBattle(bool endByTimer)
Definition Battlefield.cpp:411
virtual bool Update(uint32 diff)
Called every time for update bf data and time.
Definition Battlefield.cpp:163
void InvitePlayersInZoneToQueue()
Invite all players in zone to join the queue, called x minutes before battle start in Update()
Definition Battlefield.cpp:211
void StartBattle()
Definition Battlefield.cpp:348
virtual void OnStartGrouping()
Called x minutes before battle start when players in zone are invited to join queue.
Definition Battlefield.h:312
bool IsEnabled() const
Return if battlefield is enabled.
Definition Battlefield.h:244
TaskScheduler & Update(success_t const &callback=EmptyCallback)
Definition TaskScheduler.cpp:27
#define sWorld
Definition World.h:317

References _scheduler, Active, CapturePoints, CONFIG_WINTERGRASP_SKIP_BATTLE_SESSION_COUNT, EndBattle(), InvitePlayersInZoneToQueue(), IsEnabled(), IsWarTime(), OnStartGrouping(), SendUpdateWorldStates(), StartBattle(), StartGrouping, StartGroupingTimer, sWorld, sWorldSessionMgr, and TaskScheduler::Update().

Referenced by BattlefieldWG::Update().

◆ UpdateData()

virtual void Battlefield::UpdateData ( uint32  index,
int32  pad 
)
inlinevirtual
264{ Data32[index] += pad; }

References Data32.

Friends And Related Symbol Documentation

◆ BattlefieldMgr

friend class BattlefieldMgr
friend

Member Data Documentation

◆ _scheduler

◆ Active

◆ BattleId

◆ BattleTime

uint32 Battlefield::BattleTime
protected

◆ BfMap

Map* Battlefield::BfMap
protected

◆ CapturePoints

◆ Data32

std::vector<uint32> Battlefield::Data32
protected

◆ Data64

std::vector<uint64> Battlefield::Data64
protected

◆ DefenderTeam

◆ Enabled

bool Battlefield::Enabled
protected

◆ GraveyardList

◆ Groups

GuidUnorderedSet Battlefield::Groups[PVP_TEAMS_COUNT]
protected

◆ InvitedPlayers

◆ KickPosition

WorldLocation Battlefield::KickPosition
protected

◆ LOGOUT_GRACE_SECONDS

constexpr uint32 Battlefield::LOGOUT_GRACE_SECONDS = 120
staticconstexprprotected

Referenced by HandlePlayerLeaveZone().

◆ LogoutGracePlayers

PlayerTimerMap Battlefield::LogoutGracePlayers[PVP_TEAMS_COUNT]
protected

◆ MapId

◆ MaxPlayer

uint32 Battlefield::MaxPlayer
protected

◆ MinLevel

uint32 Battlefield::MinLevel
protected

◆ MinPlayer

uint32 Battlefield::MinPlayer
protected

◆ NoWarBattleTime

uint32 Battlefield::NoWarBattleTime
protected

◆ Players

◆ PlayersInQueue

◆ PlayersInWar

◆ PlayersWillBeKick

◆ RestartAfterCrash

uint32 Battlefield::RestartAfterCrash
protected

◆ StalkerGuid

ObjectGuid Battlefield::StalkerGuid
protected

Referenced by InitStalker(), and SendWarning().

◆ StartGrouping

bool Battlefield::StartGrouping
protected

◆ StartGroupingTimer

uint32 Battlefield::StartGroupingTimer
protected

◆ TimeForAcceptInvite

uint32 Battlefield::TimeForAcceptInvite
protected

◆ Timer

uint32 Battlefield::Timer
protected

Referenced by GetTimer().

◆ TypeId

uint32 Battlefield::TypeId
protected

◆ ZoneId


The documentation for this class was generated from the following files: