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.
 
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).
 
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.
 
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]
 
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
 

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:387
bool StartGrouping
Definition Battlefield.h:418
uint32 MapId
Definition Battlefield.h:403
uint32 BattleId
Definition Battlefield.h:401
bool Active
Definition Battlefield.h:386
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:384
uint32 ZoneId
Definition Battlefield.h:402
Map * BfMap
Definition Battlefield.h:404
uint32 TimeForAcceptInvite
Definition Battlefield.h:411
bool Enabled
Definition Battlefield.h:385
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:390
GraveyardVect GraveyardList
Definition Battlefield.h:415
Definition Battlefield.h:86
Definition Battlefield.h:154

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.

519{
520 if (!player->IsInWorld())
521 return false;
522
523 if (player->GetGroup() && (player->GetGroup()->isBGGroup() || player->GetGroup()->isBFGroup()))
524 {
525 LOG_INFO("misc", "Battlefield::AddOrSetPlayerToCorrectBfGroup - player is already in {} group!", (player->GetGroup()->isBGGroup() ? "BG" : "BF"));
526 return false;
527 }
528
529 Group* group = GetFreeBfRaid(player->GetTeamId());
530 if (!group)
531 {
532 group = new Group;
533 group->SetBattlefieldGroup(this);
534 group->Create(player);
535 sGroupMgr->AddGroup(group);
536 Groups[player->GetTeamId()].insert(group->GetGUID());
537 }
538 else if (group->IsMember(player->GetGUID()))
539 {
540 uint8 subgroup = group->GetMemberGroup(player->GetGUID());
541 player->SetBattlegroundOrBattlefieldRaid(group, subgroup);
542 }
543 else
544 group->AddMember(player);
545
546 return true;
547}
std::uint8_t uint8
Definition Define.h:109
#define sGroupMgr
Definition GroupMgr.h:51
#define LOG_INFO(filterType__,...)
Definition Log.h:166
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:498
Definition Group.h:169
uint8 GetMemberGroup(ObjectGuid guid) const
Definition Group.cpp:2394
void SetBattlefieldGroup(Battlefield *bf)
Definition Group.cpp:2407
bool AddMember(Player *player)
Definition Group.cpp:390
ObjectGuid GetGUID() const
Definition Group.cpp:2316
bool isBGGroup() const
Definition Group.cpp:2286
bool isBFGroup() const
Definition Group.cpp:2291
bool IsMember(ObjectGuid guid) const
Definition Group.cpp:2346
bool Create(Player *leader)
Definition Group.cpp:108
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:2127
Group * GetGroup()
Definition Player.h:2504
void SetBattlegroundOrBattlefieldRaid(Group *group, int8 subgroup=-1)
Definition Player.cpp:13095

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().

◆ AddPlayerToResurrectQueue()

void Battlefield::AddPlayerToResurrectQueue ( ObjectGuid  npcGuid,
ObjectGuid  playerGuid 
)
virtual
591{
592 for (BfGraveyard* gy : GraveyardList)
593 {
594 if (!gy)
595 continue;
596
597 if (gy->HasNpc(npcGuid))
598 {
599 gy->AddPlayer(playerGuid);
600 break;
601 }
602 }
603}

References BfGraveyard::AddPlayer(), and GraveyardList.

◆ AskToLeaveQueue()

void Battlefield::AskToLeaveQueue ( Player player)
395{
396 // Remove player from queue
397 PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
398 // Send notification
400}
GuidUnorderedSet PlayersInQueue[PVP_TEAMS_COUNT]
Definition Battlefield.h:394
WorldSession * GetSession() const
Definition Player.h:2019
void SendBfLeaveMessage(uint32 battleId, BFLeaveReason reason=BF_LEAVE_REASON_EXITED)
Definition BattlefieldHandler.cpp:78
@ BF_LEAVE_REASON_CLOSE
Definition WorldSession.h:253

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
447{
448 ForEachPlayerInQueue([data](Player* player) { player->SendDirectMessage(data); });
449}
void ForEachPlayerInQueue(Func &&fn) const
Definition Battlefield.h:459
Definition Player.h:1084
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5680

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

◆ BroadcastPacketToWar()

void Battlefield::BroadcastPacketToWar ( WorldPacket const *  data) const
protected
452{
453 ForEachPlayerInWar([data](Player* player) { player->SendDirectMessage(data); });
454}
void ForEachPlayerInWar(Func &&fn) const
Definition Battlefield.h:468

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

Referenced by DoPlaySoundToAll().

◆ BroadcastPacketToZone()

void Battlefield::BroadcastPacketToZone ( WorldPacket const *  data) const
protected
442{
443 ForEachPlayerInZone([data](Player* player) { player->SendDirectMessage(data); });
444}
void ForEachPlayerInZone(Func &&fn) const
Definition Battlefield.h:450

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

◆ CanFlyIn()

bool Battlefield::CanFlyIn ( ) const
inline

Return if we can use mount in battlefield.

343{ return !Active; }

References Active.

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

◆ DoPlaySoundToAll()

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

References BroadcastPacketToWar().

Referenced by EndBattle(), and StartBattle().

◆ EndBattle()

void Battlefield::EndBattle ( bool  endByTimer)
348{
349 if (!Active)
350 return;
351
352 Active = false;
353
355
356 StartGrouping = false;
357
358 if (!endByTimer)
360
363 else
365
366 OnBattleEnd(endByTimer);
367
368 // Reset battlefield timer
372}
@ BATTLEFIELD_TIMER_GROUP_WAR
Definition Battlefield.h:62
@ BF_ALLIANCE_WINS
Definition Battlefield.h:53
@ BF_HORDE_WINS
Definition Battlefield.h:52
@ 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:317
void SetDefenderTeam(TeamId team)
Definition Battlefield.h:282
TaskScheduler _scheduler
Definition Battlefield.h:420
virtual void SendUpdateWorldStates(Player *player=nullptr)=0
TeamId GetAttackerTeam() const
Definition Battlefield.h:280
TeamId GetDefenderTeam() const
Definition Battlefield.h:279
void DoPlaySoundToAll(uint32 soundId)
Definition Battlefield.cpp:374
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(), SendInitWorldStatesToAll(), SendUpdateWorldStates(), SetDefenderTeam(), 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
460 {
461 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
462 for (ObjectGuid const& guid : PlayersInQueue[team])
463 if (Player* player = ObjectAccessor::FindPlayer(guid))
464 fn(player);
465 }
uint8 constexpr PVP_TEAMS_COUNT
Definition SharedDefines.h:3703
Definition ObjectGuid.h:118
Definition ObjectAccessor.h:61
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245

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

Referenced by BroadcastPacketToQueue().

◆ ForEachPlayerInWar() [1/2]

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

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
478 {
479 for (ObjectGuid const& guid : PlayersInWar[team])
480 if (Player* player = ObjectAccessor::FindPlayer(guid))
481 fn(player);
482 }

References ObjectAccessor::FindPlayer(), and PlayersInWar.

◆ ForEachPlayerInZone()

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

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

Referenced by BroadcastPacketToZone(), InvitePlayersInZoneToQueue(), InvitePlayersInZoneToWar(), and SendUpdateWorldState().

◆ GetAttackerTeam()

◆ GetBattleId()

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

References BattleId.

◆ GetClosestGraveyard()

GraveyardStruct const * Battlefield::GetClosestGraveyard ( Player player)
565{
566 BfGraveyard* closestGY = nullptr;
567 float maxdist = -1;
568 for (BfGraveyard* gy : GraveyardList)
569 {
570 if (!gy)
571 continue;
572
573 if (gy->GetControlTeamId() != player->GetTeamId())
574 continue;
575
576 float dist = gy->GetDistance(player);
577 if (dist < maxdist || maxdist < 0)
578 {
579 closestGY = gy;
580 maxdist = dist;
581 }
582 }
583
584 if (closestGY)
585 return sGraveyard->GetGraveyard(closestGY->GetGraveyardId());
586
587 return nullptr;
588}
#define sGraveyard
Definition GameGraveyard.h:74
uint32 GetGraveyardId() const
Definition Battlefield.h:197
float GetDistance(Player *player)
Definition Battlefield.cpp:657

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

Referenced by BfGraveyard::RelocateDeadPlayers().

◆ GetCreature()

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

◆ GetData()

uint32 Battlefield::GetData ( uint32  dataId) const
inlineoverridevirtual

Reimplemented from ZoneScript.

Reimplemented in BattlefieldWG.

274{ 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.

270{ 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())
499{
500 for (ObjectGuid const& guid : Groups[teamId])
501 if (Group* group = sGroupMgr->GetGroupByGUID(guid.GetCounter()))
502 if (!group->IsFull())
503 return group;
504
505 return nullptr;
506}

References sGroupMgr.

Referenced by AddOrSetPlayerToCorrectBfGroup().

◆ GetGameObject()

GameObject * Battlefield::GetGameObject ( ObjectGuid const &  guid)
815{
816 if (!BfMap)
817 return nullptr;
818
819 return BfMap->GetGameObject(guid);
820}
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Map.cpp:2341

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
550{
551 if (id < GraveyardList.size())
552 {
553 if (GraveyardList[id])
554 return GraveyardList[id];
555 else
556 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} not existed", id);
557 }
558 else
559 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} cant be found", id);
560
561 return nullptr;
562}
#define LOG_ERROR(filterType__,...)
Definition Log.h:158

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.

509{
510 for (ObjectGuid const& groupGuid : Groups[teamId])
511 if (Group* group = sGroupMgr->GetGroupByGUID(groupGuid.GetCounter()))
512 if (group->IsMember(guid))
513 return group;
514
515 return nullptr;
516}

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).

371{ return InvitedPlayers[teamId]; }
PlayerTimerMap InvitedPlayers[PVP_TEAMS_COUNT]
Definition Battlefield.h:396

References InvitedPlayers.

Referenced by bf_commandscript::HandleBattlefieldQueue().

◆ GetMaxPlayersPerTeam()

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

References MaxPlayer.

◆ GetOtherTeam()

TeamId Battlefield::GetOtherTeam ( TeamId  team) const
inline
281{ 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
359{ 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).

373{ return PlayersInWar[teamId]; }

References PlayersInWar.

Referenced by bf_commandscript::HandleBattlefieldQueue().

◆ GetPlayersInZoneCount()

uint32 Battlefield::GetPlayersInZoneCount ( TeamId  teamId) const
inline
361{ 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).

368{ return PlayersInQueue[teamId]; }

References PlayersInQueue.

Referenced by bf_commandscript::HandleBattlefieldQueue().

◆ GetTimer()

◆ GetTypeId()

uint32 Battlefield::GetTypeId ( ) const
inline
245{ 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.

243{};

◆ HandlePlayerEnterZone()

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

Called when player (player) enters the zone.

Todo:
: Send a packet to announce it to player
78{
79 // Allow scripts to adjust the player's effective team or appearance before
80 // any team-based battlefield containers (such as player lists or queues) are updated.
81 sScriptMgr->OnBattlefieldPlayerEnterZone(this, player);
82
83 // Xinef: do not invite players on taxi
84 if (!player->IsInFlight())
85 {
86 // If battle is started,
87 // If not full of players > invite player to join the war
88 // If full of players > announce to player that BF is full and kick him after a few second if he doesn't leave
89 if (IsWarTime())
90 {
91 if (HasWarVacancy(player->GetTeamId()))
92 InvitePlayerToWar(player);
93 else
94 {
96 PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + (player->IsGameMaster() ? 30 * MINUTE : 10);
97 InvitePlayerToQueue(player);
98 }
99 }
100 else
101 {
102 // If time left is < 15 minutes invite player to join queue
104 InvitePlayerToQueue(player);
105 }
106 }
107
108 Players[player->GetTeamId()].insert(player->GetGUID());
109 OnPlayerEnterZone(player);
110}
constexpr auto MINUTE
Definition Common.h:47
#define sScriptMgr
Definition ScriptMgr.h:734
bool IsWarTime() const
Return true if battle is started, false if battle is not started.
Definition Battlefield.h:251
PlayerTimerMap PlayersWillBeKick[PVP_TEAMS_COUNT]
Definition Battlefield.h:397
void InvitePlayerToQueue(Player *player)
Definition Battlefield.cpp:198
void InvitePlayerToWar(Player *player)
Definition Battlefield.cpp:234
virtual void OnPlayerEnterZone(Player *)
Called when a player enters the battlefield zone.
Definition Battlefield.h:327
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:365
bool IsGameMaster() const
Definition Player.h:1174
bool IsInFlight() const
Definition Unit.h:1705
Seconds GetGameTime()
Definition GameTime.cpp:38

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

Referenced by BattlefieldMgr::HandlePlayerEnterZone().

◆ HandlePlayerLeaveZone()

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

Called when player (player) leaves the zone.

113{
114 if (IsWarTime())
115 {
116 // If the player is participating to the battle
117 if (PlayersInWar[player->GetTeamId()].erase(player->GetGUID()))
118 {
120 if (Group* group = player->GetGroup()) // Remove the player from the raid group
121 if (group->isBFGroup())
122 group->RemoveMember(player->GetGUID());
123
124 OnPlayerLeaveWar(player);
125 sScriptMgr->OnBattlefieldPlayerLeaveWar(this, player);
126 }
127 }
128
129 for (BfCapturePoint* cp : CapturePoints)
130 cp->HandlePlayerLeave(player);
131
132 InvitedPlayers[player->GetTeamId()].erase(player->GetGUID());
133 PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
134 PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
135 Players[player->GetTeamId()].erase(player->GetGUID());
136 SendRemoveWorldStates(player);
138 OnPlayerLeaveZone(player);
139 // Scripts must restore player->GetTeamId() here (e.g. ClearFakePlayer).
140 // All Battlefield data-structure cleanup above has already completed using
141 // the assigned team, so it is safe to restore the real team now.
142 sScriptMgr->OnBattlefieldPlayerLeaveZone(this, player);
143}
virtual void SendRemoveWorldStates(Player *)
Definition Battlefield.h:430
virtual void OnPlayerLeaveZone(Player *)
Called when a player leaves the battlefield zone.
Definition Battlefield.h:325
virtual void OnPlayerLeaveWar(Player *)
Called when a player leaves the battle.
Definition Battlefield.h:323
void RemovePlayerFromResurrectQueue(ObjectGuid playerGuid)
Definition Battlefield.cpp:605

References BattleId, CapturePoints, Player::GetGroup(), Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), InvitedPlayers, IsWarTime(), OnPlayerLeaveWar(), OnPlayerLeaveZone(), Players, PlayersInQueue, PlayersInWar, PlayersWillBeKick, RemovePlayerFromResurrectQueue(), WorldSession::SendBfLeaveMessage(), SendRemoveWorldStates(), and sScriptMgr.

◆ HasPlayer()

bool Battlefield::HasPlayer ( Player player) const
protected
380{
381 return Players[player->GetTeamId()].find(player->GetGUID()) != Players[player->GetTeamId()].end();
382}

References Object::GetGUID(), Player::GetTeamId(), and Players.

◆ 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.

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

References GetPlayersInWarCount(), and MaxPlayer.

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

◆ HideNpc()

void Battlefield::HideNpc ( Creature creature)
473{
474 creature->CombatStop();
475 creature->SetReactState(REACT_PASSIVE);
477 creature->SetPhaseMask(2, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
478 creature->DisappearAndDie();
479 creature->SetVisible(false);
480}
@ 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:99
void DisappearAndDie()
Definition Creature.cpp:361
void SetVisible(bool x)
Definition Unit.cpp:11072
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition Unit.cpp:15274
void CombatStop(bool includingCast=false, bool mutualPvP=true)
Definition Unit.cpp:7469
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 
)
269{
270 if (Creature* creature = SpawnCreature(entry, x, y, z, o, TEAM_NEUTRAL))
271 StalkerGuid = creature->GetGUID();
272 else
273 LOG_ERROR("bg.battlefield", "Battlefield::InitStalker: could not spawn Stalker (Creature entry {}), zone messages will be unavailable", entry);
274}
ObjectGuid StalkerGuid
Definition Battlefield.h:383
Creature * SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId teamId)
Definition Battlefield.cpp:744
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.

208{
209 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
210 {
212 for (ObjectGuid const& guid : copy)
213 if (Player* player = ObjectAccessor::FindPlayer(guid))
214 if (HasWarVacancy(player->GetTeamId()))
215 InvitePlayerToWar(player);
216 PlayersInQueue[team].clear();
217 }
218}
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:257
TeamId GetTeamId(PvPTeamId teamId)
Definition SharedDefines.h:3720

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()

194{
195 ForEachPlayerInZone([this](Player* player) { InvitePlayerToQueue(player); });
196}

References ForEachPlayerInZone(), and InvitePlayerToQueue().

Referenced by Update().

◆ InvitePlayersInZoneToWar()

void Battlefield::InvitePlayersInZoneToWar ( )

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

221{
222 ForEachPlayerInZone([this](Player* player)
223 {
224 if (IsPlayerInWarOrInvited(player))
225 return;
226
227 if (HasWarVacancy(player->GetTeamId()))
228 InvitePlayerToWar(player);
229 else if (!PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID())) // Battlefield is full of players
230 PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
231 });
232}
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:276

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

Referenced by StartBattle().

◆ InvitePlayerToQueue()

void Battlefield::InvitePlayerToQueue ( Player player)
199{
200 if (PlayersInQueue[player->GetTeamId()].count(player->GetGUID()))
201 return;
202
203 if (PlayersInQueue[player->GetTeamId()].size() <= MinPlayer || PlayersInQueue[GetOtherTeam(player->GetTeamId())].size() >= MinPlayer)
205}
TeamId GetOtherTeam(TeamId team) const
Definition Battlefield.h:281
void SendBfInvitePlayerToQueue(uint32 battleId)
Definition BattlefieldHandler.cpp:42

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

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

◆ InvitePlayerToWar()

void Battlefield::InvitePlayerToWar ( Player player)
Todo:
: needed ?
235{
236 if (!player)
237 return;
238
240 if (player->IsInFlight())
241 return;
242
243 if (player->InBattleground())
244 {
245 PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
246 return;
247 }
248
249 // If the player does not match minimal level requirements for the battlefield, kick him
250 if (player->GetLevel() < MinLevel)
251 {
252 if (!PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()))
253 PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
254 return;
255 }
256
257 // Check if player is not already in war
258 if (IsPlayerInWarOrInvited(player))
259 return;
260
261 sScriptMgr->OnBattlefieldBeforeInvitePlayerToWar(this, player);
262
263 PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
266}
bool InBattleground() const
Definition Player.h:2287
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, 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.

256{ return Enabled; }

References Enabled.

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

◆ 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.

277{
278 TeamId teamId = player->GetTeamId();
279 return PlayersInWar[teamId].count(player->GetGUID()) || InvitedPlayers[teamId].count(player->GetGUID());
280}

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

Referenced by InvitePlayersInZoneToWar(), and InvitePlayerToWar().

◆ IsWarTime()

◆ KickAfkPlayers()

void Battlefield::KickAfkPlayers ( )
protected
283{
284 ForEachPlayerInWar([this](Player* player)
285 {
286 if (player->isAFK() && player->GetZoneId() == GetZoneId() && !player->IsGameMaster())
287 player->TeleportTo(KickPosition);
288 });
289}
uint32 GetZoneId() const
Definition Battlefield.h:246
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:1352
bool isAFK() const
Definition Player.h:1149
uint32 GetZoneId() const
Definition Object.cpp:3112

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
292{
293 if (Player* player = ObjectAccessor::FindPlayer(guid))
294 if (player->GetZoneId() == GetZoneId() && !player->IsGameMaster()
295 && !PlayersInWar[player->GetTeamId()].count(guid))
296 player->TeleportTo(KickPosition);
297}

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

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

◆ OnBattleEnd()

virtual void Battlefield::OnBattleEnd ( bool  )
inlinevirtual

Called at the end of battle.

Reimplemented in BattlefieldWG.

317{};

Referenced by EndBattle().

◆ OnBattleStart()

virtual void Battlefield::OnBattleStart ( )
inlinevirtual

Called on start.

Reimplemented in BattlefieldWG.

315{};

Referenced by StartBattle().

◆ OnPlayerEnterZone()

virtual void Battlefield::OnPlayerEnterZone ( Player )
inlinevirtual

Called when a player enters the battlefield zone.

Reimplemented in BattlefieldWG.

327{};

Referenced by HandlePlayerEnterZone().

◆ OnPlayerJoinWar()

virtual void Battlefield::OnPlayerJoinWar ( Player )
inlinevirtual

Called when a player accepts to join the battle.

Reimplemented in BattlefieldWG.

321{};

Referenced by PlayerAcceptInviteToWar().

◆ OnPlayerLeaveWar()

virtual void Battlefield::OnPlayerLeaveWar ( Player )
inlinevirtual

Called when a player leaves the battle.

Reimplemented in BattlefieldWG.

323{};

Referenced by HandlePlayerLeaveZone().

◆ OnPlayerLeaveZone()

virtual void Battlefield::OnPlayerLeaveZone ( Player )
inlinevirtual

Called when a player leaves the battlefield zone.

Reimplemented in BattlefieldWG.

325{};

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.

319{};

Referenced by Update().

◆ PlayerAcceptInviteToQueue()

void Battlefield::PlayerAcceptInviteToQueue ( Player player)
386{
387 // Add player in queue
388 PlayersInQueue[player->GetTeamId()].insert(player->GetGUID());
389 // Send notification
391}
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)
411{
412 if (!IsWarTime())
413 return;
414
415 sScriptMgr->OnBattlefieldPlayerJoinWar(this, player);
416
418 {
420 PlayersInWar[player->GetTeamId()].insert(player->GetGUID());
421 InvitedPlayers[player->GetTeamId()].erase(player->GetGUID());
422
423 if (player->isAFK())
424 player->ToggleAFK();
425
426 OnPlayerJoinWar(player);
427 }
428}
virtual void OnPlayerJoinWar(Player *)
Called when a player accepts to join the battle.
Definition Battlefield.h:321
bool AddOrSetPlayerToCorrectBfGroup(Player *player)
Force player to join a battlefield group.
Definition Battlefield.cpp:518
void ToggleAFK()
Definition Player.cpp:1310
void SendBfEntered(uint32 battleId)
Definition BattlefieldHandler.cpp:68

References AddOrSetPlayerToCorrectBfGroup(), BattleId, 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)
404{
405 // Player leaving Wintergrasp, teleport to homebind position.
406 player->TeleportTo(player->m_homebindMapId, player->m_homebindX, player->m_homebindY, player->m_homebindZ, player->GetOrientation());
407}
float m_homebindZ
Definition Player.h:2410
uint32 m_homebindMapId
Definition Player.h:2406
float m_homebindY
Definition Player.h:2409
float m_homebindX
Definition Player.h:2408
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
468{
469 sBattlefieldMgr->AddZone(zoneId, this);
470}
#define sBattlefieldMgr
Definition BattlefieldMgr.h:76

References sBattlefieldMgr.

Referenced by BattlefieldWG::SetupBattlefield().

◆ RemovePlayerFromResurrectQueue()

void Battlefield::RemovePlayerFromResurrectQueue ( ObjectGuid  playerGuid)
606{
607 for (BfGraveyard* gy : GraveyardList)
608 {
609 if (!gy)
610 continue;
611
612 if (gy->HasPlayer(playerGuid))
613 {
614 gy->RemovePlayer(playerGuid);
615 break;
616 }
617 }
618}

References GraveyardList.

Referenced by HandlePlayerLeaveZone().

◆ SendAreaSpiritHealerQueryOpcode()

void Battlefield::SendAreaSpiritHealerQueryOpcode ( Player player,
ObjectGuid const &  guid 
)
621{
624 uint32 time = static_cast<uint32>(std::clamp(remaining,
625 Milliseconds::zero(), Milliseconds(RESURRECTION_INTERVAL)).count());
626
627 data << guid << time;
628 ASSERT(player);
629 player->SendDirectMessage(&data);
630}
@ 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.

◆ 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.

463{
464 ForEachPlayerInZone([field, value](Player* player) { player->SendUpdateWorldState(field, value); });
465}
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition PlayerUpdates.cpp:2235

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 
)
457{
458 if (Creature* stalker = GetCreature(StalkerGuid))
459 sCreatureTextMgr->SendChat(stalker, id, target);
460}
#define sCreatureTextMgr
Definition CreatureTextMgr.h:110
Creature * GetCreature(ObjectGuid const &guid)
Definition Battlefield.cpp:806

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.

275{ Data32[dataId] = value; }

References Data32.

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

◆ SetData64()

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

Reimplemented from ZoneScript.

271{ Data64[dataId] = value; }

◆ SetDefenderTeam()

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

References DefenderTeam.

Referenced by EndBattle().

◆ SetGraveyardNumber()

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

References GraveyardList.

Referenced by BattlefieldWG::SetupBattlefield().

◆ SetTimer()

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

Referenced by bf_commandscript::HandleBattlefieldTimer().

◆ SetupBattlefield()

virtual bool Battlefield::SetupBattlefield ( )
inlinevirtual

Call this to init the Battlefield.

Reimplemented in BattlefieldWG.

221{ return true; }

Referenced by BattlefieldMgr::InitBattlefield().

◆ ShowNpc()

void Battlefield::ShowNpc ( Creature creature,
bool  aggressive 
)
483{
484 creature->SetPhaseMask(1, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
485 creature->SetVisible(true);
487 if (!creature->IsAlive())
488 creature->Respawn(true);
489 if (aggressive)
491 else
492 {
494 creature->SetReactState(REACT_PASSIVE);
495 }
496}
@ REACT_AGGRESSIVE
Definition Unit.h:568
void Respawn(bool force=false)
Definition Creature.cpp:1987
bool IsAlive() const
Definition Unit.h:1793
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 
)
745{
746 Map* map = sMapMgr->CreateBaseMap(MapId);
747 if (!map)
748 {
749 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {} map not found", entry);
750 return nullptr;
751 }
752
753 CreatureTemplate const* cinfo = sObjectMgr->GetCreatureTemplate(entry);
754 if (!cinfo)
755 {
756 LOG_ERROR("sql.sql", "Battlefield::SpawnCreature: entry {} does not exist.", entry);
757 return nullptr;
758 }
759
760 Creature* creature = new Creature();
761 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, PHASEMASK_NORMAL, entry, 0, x, y, z, o))
762 {
763 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {}", entry);
764 delete creature;
765 return nullptr;
766 }
767
768 // no need to set faction for neutral team
769 if (teamId == TEAM_ALLIANCE || teamId == TEAM_HORDE)
770 creature->SetFaction(BattlefieldFactions[teamId]);
771
772 creature->SetHomePosition(x, y, z, o);
773
774 // force using DB speeds -- do we really need this?
775 creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
776 creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
777
778 map->AddToMap(creature);
779 creature->setActive(true);
780
781 return creature;
782}
const uint32 BattlefieldFactions[PVP_TEAMS_COUNT]
Definition Battlefield.h:66
#define sMapMgr
Definition MapMgr.h:220
#define sObjectMgr
Definition ObjectMgr.h:1712
@ 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:345
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:1126
Definition Map.h:164
ObjectGuid::LowType GenerateLowGuid()
Definition Map.h:480
bool AddToMap(T *, bool checkTransport=false)
Definition Map.cpp:303
void SetFaction(uint32 faction)
Definition Unit.cpp:7056
void SetSpeed(UnitMoveType mtype, float rate, bool forced=false)
Definition Unit.cpp:11270
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 
)
740{
741 return SpawnCreature(entry, pos.m_positionX, pos.m_positionY, pos.m_positionZ, pos.m_orientation, teamId);
742}
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 
)
785{
786 Map* map = sMapMgr->CreateBaseMap(MapId);
787 if (!map)
788 return nullptr;
789
790 GameObject* go = sObjectMgr->IsGameObjectStaticTransport(entry) ? new StaticTransport() : new GameObject();
791 G3D::Quat rotation = G3D::Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), o);
792 if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, PHASEMASK_NORMAL, x, y, z, o, rotation, 100, GO_STATE_READY))
793 {
794 LOG_ERROR("sql.sql", "Battlefield::SpawnGameObject: Gameobject template {} not found in database! Battlefield not created!", entry);
795 LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Cannot create gameobject template {}! Battlefield not created!", entry);
796 delete go;
797 return nullptr;
798 }
799
800 map->AddToMap(go);
801 go->setActive(true);
802
803 return go;
804}
@ 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 ( )
300{
301 if (Active)
302 return;
303
304 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
305 {
306 PlayersInWar[team].clear();
307 Groups[team].clear();
308 }
309
311 Active = true;
312
313 // Schedule war-only periodic timers
315 {
317 context.Repeat(20s);
318 });
319
321 {
322 time_t now = GameTime::GetGameTime().count();
323 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
324 for (PlayerTimerMap::value_type const& pair : InvitedPlayers[team])
325 if (pair.second <= now)
326 KickPlayerFromBattlefield(pair.first);
327
329 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
330 for (PlayerTimerMap::value_type const& pair : PlayersWillBeKick[team])
331 if (pair.second <= now)
332 KickPlayerFromBattlefield(pair.first);
333
334 context.Repeat(5s);
335 });
336
339
341
343
345}
@ BF_START
Definition Battlefield.h:54
void InvitePlayersInQueueToWar()
Invite all players in queue to join battle on battle start.
Definition Battlefield.cpp:207
void KickPlayerFromBattlefield(ObjectGuid guid)
Kick player from battlefield and teleport him to kick-point location.
Definition Battlefield.cpp:291
virtual void OnBattleStart()
Called on start.
Definition Battlefield.h:315
void InvitePlayersInZoneToWar()
Invite all players in zone to join battle on battle start.
Definition Battlefield.cpp:220
void KickAfkPlayers()
Definition Battlefield.cpp:282
Definition TaskScheduler.h:421
TaskContext & Repeat(std::chrono::duration< _Rep, _Period > const &duration)
Definition TaskScheduler.h:493
TaskScheduler & Schedule(std::chrono::duration< _Rep, _Period > const &time, task_handler_t const &task)
Definition TaskScheduler.h:232

References _scheduler, Active, BATTLEFIELD_TIMER_GROUP_WAR, BattleTime, BF_START, DoPlaySoundToAll(), GameTime::GetGameTime(), InvitedPlayers, InvitePlayersInQueueToWar(), InvitePlayersInZoneToWar(), KickAfkPlayers(), KickPlayerFromBattlefield(), 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
431{
432 ForEachPlayerInWar(team, [spellId](Player* player)
433 {
434 if (spellId > 0)
435 player->CastSpell(player, uint32(spellId), true);
436 else
437 player->RemoveAuraFromStack(uint32(-spellId));
438 });
439}
void RemoveAuraFromStack(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:5173
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:1350

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

◆ ToggleBattlefield()

void Battlefield::ToggleBattlefield ( bool  enable)
inline

Enable or Disable battlefield.

254{ Enabled = enable; }

References Enabled.

Referenced by bf_commandscript::HandleBattlefieldEnable().

◆ 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.

146{
147 if (Timer <= diff)
148 {
149 uint32 sessionLimit = sWorld->getIntConfig(CONFIG_WINTERGRASP_SKIP_BATTLE_SESSION_COUNT);
150 bool tooManySessions = sessionLimit && !IsWarTime()
151 && sWorldSessionMgr->GetActiveSessionCount() > sessionLimit;
152
153 if (!IsEnabled() || tooManySessions)
154 {
155 Active = true;
156 EndBattle(false);
157 return false;
158 }
159 // Battlefield ends on time
160 if (IsWarTime())
161 EndBattle(true);
162 else // Time to start a new battle!
163 StartBattle();
164 }
165 else
166 Timer -= diff;
167
168 if (!IsEnabled())
169 return false;
170
171 // Invite players a few minutes before the battle's beginning
173 {
174 StartGrouping = true;
178 }
179
180 _scheduler.Update(diff);
181
182 bool objectiveChanged = false;
183 if (IsWarTime())
184 {
185 for (BfCapturePoint* cp : CapturePoints)
186 if (cp->Update(diff))
187 objectiveChanged = true;
188 }
189
190 return objectiveChanged;
191}
@ CONFIG_WINTERGRASP_SKIP_BATTLE_SESSION_COUNT
Definition WorldConfig.h:332
#define sWorldSessionMgr
Definition WorldSessionMgr.h:108
void EndBattle(bool endByTimer)
Definition Battlefield.cpp:347
virtual bool Update(uint32 diff)
Called every time for update bf data and time.
Definition Battlefield.cpp:145
void InvitePlayersInZoneToQueue()
Invite all players in zone to join the queue, called x minutes before battle start in Update()
Definition Battlefield.cpp:193
void StartBattle()
Definition Battlefield.cpp:299
virtual void OnStartGrouping()
Called x minutes before battle start when players in zone are invited to join queue.
Definition Battlefield.h:319
bool IsEnabled() const
Return if battlefield is enabled.
Definition Battlefield.h:256
TaskScheduler & Update(success_t const &callback=EmptyCallback)
Definition TaskScheduler.cpp:27
#define sWorld
Definition World.h:316

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 BattlefieldMgr::Update(), and BattlefieldWG::Update().

◆ UpdateData()

virtual void Battlefield::UpdateData ( uint32  index,
int32  pad 
)
inlinevirtual
276{ 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

◆ 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: