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.

520{
521 if (!player->IsInWorld())
522 return false;
523
524 if (player->GetGroup() && (player->GetGroup()->isBGGroup() || player->GetGroup()->isBFGroup()))
525 {
526 LOG_INFO("misc", "Battlefield::AddOrSetPlayerToCorrectBfGroup - player is already in {} group!", (player->GetGroup()->isBGGroup() ? "BG" : "BF"));
527 return false;
528 }
529
530 Group* group = GetFreeBfRaid(player->GetTeamId());
531 if (!group)
532 {
533 group = new Group;
534 group->SetBattlefieldGroup(this);
535 group->Create(player);
536 sGroupMgr->AddGroup(group);
537 Groups[player->GetTeamId()].insert(group->GetGUID());
538 }
539 else if (group->IsMember(player->GetGUID()))
540 {
541 uint8 subgroup = group->GetMemberGroup(player->GetGUID());
542 player->SetBattlegroundOrBattlefieldRaid(group, subgroup);
543 }
544 else
545 group->AddMember(player);
546
547 return true;
548}
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:499
Definition Group.h:169
uint8 GetMemberGroup(ObjectGuid guid) const
Definition Group.cpp:2397
void SetBattlefieldGroup(Battlefield *bf)
Definition Group.cpp:2410
bool AddMember(Player *player)
Definition Group.cpp:390
ObjectGuid GetGUID() const
Definition Group.cpp:2319
bool isBGGroup() const
Definition Group.cpp:2289
bool isBFGroup() const
Definition Group.cpp:2294
bool IsMember(ObjectGuid guid) const
Definition Group.cpp:2349
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:2128
Group * GetGroup()
Definition Player.h:2505
void SetBattlegroundOrBattlefieldRaid(Group *group, int8 subgroup=-1)
Definition Player.cpp:13130

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
592{
593 for (BfGraveyard* gy : GraveyardList)
594 {
595 if (!gy)
596 continue;
597
598 if (gy->HasNpc(npcGuid))
599 {
600 gy->AddPlayer(playerGuid);
601 break;
602 }
603 }
604}

References BfGraveyard::AddPlayer(), and GraveyardList.

◆ AskToLeaveQueue()

void Battlefield::AskToLeaveQueue ( Player player)
396{
397 // Remove player from queue
398 PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
399 // Send notification
401}
GuidUnorderedSet PlayersInQueue[PVP_TEAMS_COUNT]
Definition Battlefield.h:394
WorldSession * GetSession() const
Definition Player.h:2020
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
448{
449 ForEachPlayerInQueue([data](Player* player) { player->SendDirectMessage(data); });
450}
void ForEachPlayerInQueue(Func &&fn) const
Definition Battlefield.h:459
Definition Player.h:1084
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5692

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

◆ BroadcastPacketToWar()

void Battlefield::BroadcastPacketToWar ( WorldPacket const *  data) const
protected
453{
454 ForEachPlayerInWar([data](Player* player) { player->SendDirectMessage(data); });
455}
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
443{
444 ForEachPlayerInZone([data](Player* player) { player->SendDirectMessage(data); });
445}
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)
376{
378}
void BroadcastPacketToWar(WorldPacket const *data) const
Definition Battlefield.cpp:452
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 sScriptMgr->OnBattlefieldWarEnd(this, endByTimer);
368
369 // Reset battlefield timer
373}
@ 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:737
@ 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:375
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(), 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
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:3701
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)
566{
567 BfGraveyard* closestGY = nullptr;
568 float maxdist = -1;
569 for (BfGraveyard* gy : GraveyardList)
570 {
571 if (!gy)
572 continue;
573
574 if (gy->GetControlTeamId() != player->GetTeamId())
575 continue;
576
577 float dist = gy->GetDistance(player);
578 if (dist < maxdist || maxdist < 0)
579 {
580 closestGY = gy;
581 maxdist = dist;
582 }
583 }
584
585 if (closestGY)
586 return sGraveyard->GetGraveyard(closestGY->GetGraveyardId());
587
588 return nullptr;
589}
#define sGraveyard
Definition GameGraveyard.h:74
uint32 GetGraveyardId() const
Definition Battlefield.h:197
float GetDistance(Player *player)
Definition Battlefield.cpp:658

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

References sGroupMgr.

Referenced by AddOrSetPlayerToCorrectBfGroup().

◆ GetGameObject()

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

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

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

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
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:1706
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:606

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
381{
382 return Players[player->GetTeamId()].find(player->GetGUID()) != Players[player->GetTeamId()].end();
383}

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)
474{
475 creature->CombatStop();
476 creature->SetReactState(REACT_PASSIVE);
478 creature->SetPhaseMask(2, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
479 creature->DisappearAndDie();
480 creature->SetVisible(false);
481}
@ 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:11098
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition Unit.cpp:15303
void CombatStop(bool includingCast=false, bool mutualPvP=true)
Definition Unit.cpp:7486
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:745
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: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()

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:2288
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: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
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)
387{
388 // Add player in queue
389 PlayersInQueue[player->GetTeamId()].insert(player->GetGUID());
390 // Send notification
392}
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)
412{
413 if (!IsWarTime())
414 return;
415
416 sScriptMgr->OnBattlefieldPlayerJoinWar(this, player);
417
419 {
421 PlayersInWar[player->GetTeamId()].insert(player->GetGUID());
422 InvitedPlayers[player->GetTeamId()].erase(player->GetGUID());
423
424 if (player->isAFK())
425 player->ToggleAFK();
426
427 OnPlayerJoinWar(player);
428 }
429}
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:519
void ToggleAFK()
Definition Player.cpp:1311
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)
405{
406 // Player leaving Wintergrasp, teleport to homebind position.
407 player->TeleportTo(player->m_homebindMapId, player->m_homebindX, player->m_homebindY, player->m_homebindZ, player->GetOrientation());
408}
float m_homebindZ
Definition Player.h:2411
uint32 m_homebindMapId
Definition Player.h:2407
float m_homebindY
Definition Player.h:2410
float m_homebindX
Definition Player.h:2409
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
469{
470 sBattlefieldMgr->AddZone(zoneId, this);
471}
#define sBattlefieldMgr
Definition BattlefieldMgr.h:76

References sBattlefieldMgr.

Referenced by BattlefieldWG::SetupBattlefield().

◆ RemovePlayerFromResurrectQueue()

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

References GraveyardList.

Referenced by HandlePlayerLeaveZone().

◆ SendAreaSpiritHealerQueryOpcode()

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

464{
465 ForEachPlayerInZone([field, value](Player* player) { player->SendUpdateWorldState(field, value); });
466}
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 
)
458{
459 if (Creature* stalker = GetCreature(StalkerGuid))
460 sCreatureTextMgr->SendChat(stalker, id, target);
461}
#define sCreatureTextMgr
Definition CreatureTextMgr.h:110
Creature * GetCreature(ObjectGuid const &guid)
Definition Battlefield.cpp:807

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 
)
484{
485 creature->SetPhaseMask(1, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
486 creature->SetVisible(true);
488 if (!creature->IsAlive())
489 creature->Respawn(true);
490 if (aggressive)
492 else
493 {
495 creature->SetReactState(REACT_PASSIVE);
496 }
497}
@ REACT_AGGRESSIVE
Definition Unit.h:568
void Respawn(bool force=false)
Definition Creature.cpp:2017
bool IsAlive() const
Definition Unit.h:1794
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 
)
746{
747 Map* map = sMapMgr->CreateBaseMap(MapId);
748 if (!map)
749 {
750 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {} map not found", entry);
751 return nullptr;
752 }
753
754 CreatureTemplate const* cinfo = sObjectMgr->GetCreatureTemplate(entry);
755 if (!cinfo)
756 {
757 LOG_ERROR("sql.sql", "Battlefield::SpawnCreature: entry {} does not exist.", entry);
758 return nullptr;
759 }
760
761 Creature* creature = new Creature();
762 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, PHASEMASK_NORMAL, entry, 0, x, y, z, o))
763 {
764 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {}", entry);
765 delete creature;
766 return nullptr;
767 }
768
769 // no need to set faction for neutral team
770 if (teamId == TEAM_ALLIANCE || teamId == TEAM_HORDE)
771 creature->SetFaction(BattlefieldFactions[teamId]);
772
773 creature->SetHomePosition(x, y, z, o);
774
775 // force using DB speeds -- do we really need this?
776 creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
777 creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
778
779 map->AddToMap(creature);
780 creature->setActive(true);
781
782 return creature;
783}
const uint32 BattlefieldFactions[PVP_TEAMS_COUNT]
Definition Battlefield.h:66
#define sMapMgr
Definition MapMgr.h:220
#define sObjectMgr
Definition ObjectMgr.h:1723
@ 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:7073
void SetSpeed(UnitMoveType mtype, float rate, bool forced=false)
Definition Unit.cpp:11296
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 
)
741{
742 return SpawnCreature(entry, pos.m_positionX, pos.m_positionY, pos.m_positionZ, pos.m_orientation, teamId);
743}
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 
)
786{
787 Map* map = sMapMgr->CreateBaseMap(MapId);
788 if (!map)
789 return nullptr;
790
791 GameObject* go = sObjectMgr->IsGameObjectStaticTransport(entry) ? new StaticTransport() : new GameObject();
792 G3D::Quat rotation = G3D::Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), o);
793 if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, PHASEMASK_NORMAL, x, y, z, o, rotation, 100, GO_STATE_READY))
794 {
795 LOG_ERROR("sql.sql", "Battlefield::SpawnGameObject: Gameobject template {} not found in database! Battlefield not created!", entry);
796 LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Cannot create gameobject template {}! Battlefield not created!", entry);
797 delete go;
798 return nullptr;
799 }
800
801 map->AddToMap(go);
802 go->setActive(true);
803
804 return go;
805}
@ 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: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

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
432{
433 ForEachPlayerInWar(team, [spellId](Player* player)
434 {
435 if (spellId > 0)
436 player->CastSpell(player, uint32(spellId), true);
437 else
438 player->RemoveAuraFromStack(uint32(-spellId));
439 });
440}
void RemoveAuraFromStack(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:5187
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:1375

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:328
#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: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 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: