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

typedef std::vector< BfCapturePoint * > BfCapturePointVector
 typedef of map witch store capturepoint and the associate gameobject entry More...
 

Public Member Functions

 Battlefield ()
 Constructor. More...
 
 ~Battlefield () override
 Destructor. More...
 
virtual bool SetupBattlefield ()
 Call this to init the Battlefield. More...
 
void SendUpdateWorldState (uint32 field, uint32 value)
 Update data of a worldstate to all players present in zone. More...
 
virtual bool Update (uint32 diff)
 Called every time for update bf data and time. More...
 
void InvitePlayersInZoneToQueue ()
 Invite all players in zone to join the queue, called x minutes before battle start in Update() More...
 
void InvitePlayersInQueueToWar ()
 Invite all players in queue to join battle on battle start. More...
 
void InvitePlayersInZoneToWar ()
 Invite all players in zone to join battle on battle start. More...
 
virtual void HandleKill (Player *, Unit *)
 Called when a Unit is kill in battlefield zone. More...
 
uint32 GetTypeId ()
 
uint32 GetZoneId ()
 
void TeamApplyBuff (TeamId team, uint32 spellId, uint32 spellId2=0)
 
bool IsWarTime ()
 Return true if battle is start, false if battle is not started. More...
 
void ToggleBattlefield (bool enable)
 Enable or Disable battlefield. More...
 
bool IsEnabled ()
 Return if battlefield is enable. More...
 
void KickPlayerFromBattlefield (ObjectGuid guid)
 Kick player from battlefield and teleport him to kick-point location. More...
 
void HandlePlayerEnterZone (Player *player, uint32 zone)
 Called when player (player) enter in zone. More...
 
void HandlePlayerLeaveZone (Player *player, uint32 zone)
 Called when player (player) leave the zone. More...
 
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 ()
 
TeamId GetAttackerTeam ()
 
TeamId GetOtherTeam (TeamId team)
 
void SetDefenderTeam (TeamId team)
 
GroupGetFreeBfRaid (TeamId TeamId)
 Find a not full battlefield group, if there is no, create one. More...
 
GroupGetGroupPlayer (ObjectGuid guid, TeamId TeamId)
 Return battlefield group where player is. More...
 
bool AddOrSetPlayerToCorrectBfGroup (Player *player)
 Force player to join a battlefield group. More...
 
GraveyardStruct const * GetClosestGraveyard (Player *player)
 
virtual void AddPlayerToResurrectQueue (ObjectGuid npc_guid, ObjectGuid player_guid)
 
void RemovePlayerFromResurrectQueue (ObjectGuid player_guid)
 
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. More...
 
virtual void OnBattleEnd (bool)
 Called at the end of battle. More...
 
virtual void OnStartGrouping ()
 Called x minutes before battle start when player in zone are invite to join queue. More...
 
virtual void OnPlayerJoinWar (Player *)
 Called when a player accept to join the battle. More...
 
virtual void OnPlayerLeaveWar (Player *)
 Called when a player leave the battle. More...
 
virtual void OnPlayerLeaveZone (Player *)
 Called when a player leave battlefield zone. More...
 
virtual void OnPlayerEnterZone (Player *)
 Called when a player enter in battlefield zone. More...
 
void SendWarning (uint8 id, WorldObject const *target=nullptr)
 
void PlayerAcceptInviteToQueue (Player *player)
 
void PlayerAcceptInviteToWar (Player *player)
 
uint32 GetBattleId ()
 
void AskToLeaveQueue (Player *player)
 
void PlayerAskToLeave (Player *player)
 
virtual void SendInitWorldStatesToAll ()=0
 Send all worldstate data to all player in zone. More...
 
virtual void FillInitialWorldStates (WorldPacket &)=0
 
bool CanFlyIn ()
 Return if we can use mount in battlefield. More...
 
void SendAreaSpiritHealerQueryOpcode (Player *player, const ObjectGuid &guid)
 
void StartBattle ()
 
void EndBattle (bool endByTimer)
 
void HideNpc (Creature *creature)
 
void ShowNpc (Creature *creature, bool aggressive)
 
GraveyardVect GetGraveyardVector ()
 
uint32 GetTimer ()
 
void SetTimer (uint32 timer)
 
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 uint64 GetData64 (uint32) const
 
virtual void SetData64 (uint32, uint64)
 
virtual uint32 GetData (uint32) const
 
virtual void SetData (uint32, uint32)
 
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)
 

Protected Attributes

ObjectGuid StalkerGuid
 
uint32 m_Timer
 
bool m_IsEnabled
 
bool m_isActive
 
TeamId m_DefenderTeam
 
BfCapturePointVector m_capturePoints
 
GuidUnorderedSet m_players [PVP_TEAMS_COUNT]
 
GuidUnorderedSet m_PlayersInQueue [PVP_TEAMS_COUNT]
 
GuidUnorderedSet m_PlayersInWar [PVP_TEAMS_COUNT]
 
PlayerTimerMap m_InvitedPlayers [PVP_TEAMS_COUNT]
 
PlayerTimerMap m_PlayersWillBeKick [PVP_TEAMS_COUNT]
 
uint32 m_TypeId
 
uint32 m_BattleId
 
uint32 m_ZoneId
 
uint32 m_MapId
 
Mapm_Map
 
uint32 m_MaxPlayer
 
uint32 m_MinPlayer
 
uint32 m_MinLevel
 
uint32 m_BattleTime
 
uint32 m_NoWarBattleTime
 
uint32 m_RestartAfterCrash
 
uint32 m_TimeForAcceptInvite
 
uint32 m_uiKickDontAcceptTimer
 
WorldLocation KickPosition
 
uint32 m_uiKickAfkPlayersTimer
 
GraveyardVect m_GraveyardList
 
uint32 m_LastResurectTimer
 
uint32 m_StartGroupingTimer
 
bool m_StartGrouping
 
GuidUnorderedSet m_Groups [PVP_TEAMS_COUNT]
 
std::vector< uint64m_Data64
 
std::vector< uint32m_Data32
 

Friends

class BattlefieldMgr
 

Detailed Description

Member Typedef Documentation

◆ BfCapturePointVector

typedef of map witch store capturepoint and the associate gameobject entry

Constructor & Destructor Documentation

◆ Battlefield()

Battlefield::Battlefield ( )

Constructor.

Todo:
: this import is not necessary for compilation and marked as unused by the IDE
42{
43 m_Timer = 0;
44 m_IsEnabled = true;
45 m_isActive = false;
47
48 m_TypeId = 0;
49 m_BattleId = 0;
50 m_ZoneId = 0;
51 m_Map = nullptr;
52 m_MapId = 0;
53 m_MaxPlayer = 0;
54 m_MinPlayer = 0;
55 m_MinLevel = 0;
56 m_BattleTime = 0;
61
63
66 m_StartGrouping = false;
67}
#define RESURRECTION_INTERVAL
Definition: Battleground.h:167
@ TEAM_NEUTRAL
Definition: SharedDefines.h:762
uint32 m_Timer
Definition: Battlefield.h:366
uint32 m_MapId
Definition: Battlefield.h:385
uint32 m_MaxPlayer
Definition: Battlefield.h:387
uint32 m_NoWarBattleTime
Definition: Battlefield.h:391
uint32 m_BattleTime
Definition: Battlefield.h:390
uint32 m_ZoneId
Definition: Battlefield.h:384
uint32 m_TypeId
Definition: Battlefield.h:382
uint32 m_BattleId
Definition: Battlefield.h:383
uint32 m_StartGroupingTimer
Definition: Battlefield.h:403
uint32 m_LastResurectTimer
Definition: Battlefield.h:401
Map * m_Map
Definition: Battlefield.h:386
TeamId m_DefenderTeam
Definition: Battlefield.h:369
uint32 m_uiKickAfkPlayersTimer
Definition: Battlefield.h:397
uint32 m_TimeForAcceptInvite
Definition: Battlefield.h:393
uint32 m_RestartAfterCrash
Definition: Battlefield.h:392
uint32 m_MinLevel
Definition: Battlefield.h:389
uint32 m_MinPlayer
Definition: Battlefield.h:388
uint32 m_uiKickDontAcceptTimer
Definition: Battlefield.h:394
bool m_IsEnabled
Definition: Battlefield.h:367
bool m_StartGrouping
Definition: Battlefield.h:404
bool m_isActive
Definition: Battlefield.h:368

References m_BattleId, m_BattleTime, m_DefenderTeam, m_isActive, m_IsEnabled, m_LastResurectTimer, m_Map, m_MapId, m_MaxPlayer, m_MinLevel, m_MinPlayer, m_NoWarBattleTime, m_RestartAfterCrash, m_StartGrouping, m_StartGroupingTimer, m_TimeForAcceptInvite, m_Timer, m_TypeId, m_uiKickAfkPlayersTimer, m_uiKickDontAcceptTimer, m_ZoneId, RESURRECTION_INTERVAL, and TEAM_NEUTRAL.

◆ ~Battlefield()

Battlefield::~Battlefield ( )
override

Destructor.

70{
71 for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
72 delete *itr;
73
74 for (GraveyardVect::const_iterator itr = m_GraveyardList.begin(); itr != m_GraveyardList.end(); ++itr)
75 delete *itr;
76
77 m_capturePoints.clear();
78}
GraveyardVect m_GraveyardList
Definition: Battlefield.h:400
BfCapturePointVector m_capturePoints
Definition: Battlefield.h:372

References m_capturePoints, and m_GraveyardList.

Member Function Documentation

◆ AddCapturePoint()

void Battlefield::AddCapturePoint ( BfCapturePoint cp)
inlineprotected
422{ m_capturePoints.push_back(cp); }

References m_capturePoints.

Referenced by BattlefieldWG::OnGameObjectCreate().

◆ AddOrSetPlayerToCorrectBfGroup()

bool Battlefield::AddOrSetPlayerToCorrectBfGroup ( Player player)

Force player to join a battlefield group.

542{
543 if (!player->IsInWorld())
544 return false;
545
546 if (player->GetGroup() && (player->GetGroup()->isBGGroup() || player->GetGroup()->isBFGroup()))
547 {
548 LOG_INFO("misc", "Battlefield::AddOrSetPlayerToCorrectBfGroup - player is already in {} group!", (player->GetGroup()->isBGGroup() ? "BG" : "BF"));
549 return false;
550 }
551
552 Group* group = GetFreeBfRaid(player->GetTeamId());
553 if (!group)
554 {
555 group = new Group;
556 group->SetBattlefieldGroup(this);
557 group->Create(player);
558 sGroupMgr->AddGroup(group);
559 m_Groups[player->GetTeamId()].insert(group->GetGUID());
560 }
561 else if (group->IsMember(player->GetGUID()))
562 {
563 uint8 subgroup = group->GetMemberGroup(player->GetGUID());
564 player->SetBattlegroundOrBattlefieldRaid(group, subgroup);
565 }
566 else
567 group->AddMember(player);
568
569 return true;
570}
#define LOG_INFO(filterType__,...)
Definition: Log.h:164
std::uint8_t uint8
Definition: Define.h:109
#define sGroupMgr
Definition: GroupMgr.h:51
Group * GetFreeBfRaid(TeamId TeamId)
Find a not full battlefield group, if there is no, create one.
Definition: Battlefield.cpp:521
GuidUnorderedSet m_Groups[PVP_TEAMS_COUNT]
Definition: Battlefield.h:406
bool IsInWorld() const
Definition: Object.h:104
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2088
Group * GetGroup()
Definition: Player.h:2448
void SetBattlegroundOrBattlefieldRaid(Group *group, int8 subgroup=-1)
Definition: Player.cpp:13083
Definition: Group.h:169
uint8 GetMemberGroup(ObjectGuid guid) const
Definition: Group.cpp:2384
void SetBattlefieldGroup(Battlefield *bf)
Definition: Group.cpp:2397
bool AddMember(Player *player)
Definition: Group.cpp:392
ObjectGuid GetGUID() const
Definition: Group.cpp:2306
bool isBGGroup() const
Definition: Group.cpp:2276
bool isBFGroup() const
Definition: Group.cpp:2281
bool IsMember(ObjectGuid guid) const
Definition: Group.cpp:2336
bool Create(Player *leader)
Definition: Group.cpp:110

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, m_Groups, Group::SetBattlefieldGroup(), Player::SetBattlegroundOrBattlefieldRaid(), and sGroupMgr.

Referenced by PlayerAcceptInviteToWar().

◆ AddPlayerToResurrectQueue()

void Battlefield::AddPlayerToResurrectQueue ( ObjectGuid  npc_guid,
ObjectGuid  player_guid 
)
virtual
623{
624 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
625 {
626 if (!m_GraveyardList[i])
627 continue;
628
629 if (m_GraveyardList[i]->HasNpc(npcGuid))
630 {
631 m_GraveyardList[i]->AddPlayer(playerGuid);
632 break;
633 }
634 }
635}

References m_GraveyardList.

◆ AskToLeaveQueue()

void Battlefield::AskToLeaveQueue ( Player player)
402{
403 // Remove player from queue
404 m_PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
405}
GuidUnorderedSet m_PlayersInQueue[PVP_TEAMS_COUNT]
Definition: Battlefield.h:376

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

Referenced by WorldSession::HandleBfExitRequest().

◆ BroadcastPacketToQueue()

void Battlefield::BroadcastPacketToQueue ( WorldPacket const *  data) const
protected
458{
459 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
460 for (GuidUnorderedSet::const_iterator itr = m_PlayersInQueue[team].begin(); itr != m_PlayersInQueue[team].end(); ++itr)
461 if (Player* player = ObjectAccessor::FindPlayer(*itr))
462 player->GetSession()->SendPacket(data);
463}
uint8 constexpr PVP_TEAMS_COUNT
Definition: SharedDefines.h:3445
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:248
Definition: Player.h:1064

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

◆ BroadcastPacketToWar()

void Battlefield::BroadcastPacketToWar ( WorldPacket const *  data) const
protected
466{
467 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
468 for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
469 if (Player* player = ObjectAccessor::FindPlayer(*itr))
470 player->GetSession()->SendPacket(data);
471}
GuidUnorderedSet m_PlayersInWar[PVP_TEAMS_COUNT]
Definition: Battlefield.h:377

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

Referenced by DoPlaySoundToAll().

◆ BroadcastPacketToZone()

void Battlefield::BroadcastPacketToZone ( WorldPacket const *  data) const
protected
450{
451 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
452 for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
453 if (Player* player = ObjectAccessor::FindPlayer(*itr))
454 player->GetSession()->SendPacket(data);
455}
GuidUnorderedSet m_players[PVP_TEAMS_COUNT]
Definition: Battlefield.h:375

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

◆ CanFlyIn()

bool Battlefield::CanFlyIn ( )
inline

Return if we can use mount in battlefield.

342{ return !m_isActive; }

References m_isActive.

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

◆ DoPlaySoundToAll()

void Battlefield::DoPlaySoundToAll ( uint32  SoundID)
382{
384}
void BroadcastPacketToWar(WorldPacket const *data) const
Definition: Battlefield.cpp:465
Definition: MiscPackets.h:85

References BroadcastPacketToWar().

Referenced by EndBattle(), and StartBattle().

◆ EndBattle()

void Battlefield::EndBattle ( bool  endByTimer)
358{
359 if (!m_isActive)
360 return;
361
362 m_isActive = false;
363
364 m_StartGrouping = false;
365
366 if (!endByTimer)
368
371 else
373
374 OnBattleEnd(endByTimer);
375
376 // Reset battlefield timer
379}
@ BF_ALLIANCE_WINS
Definition: Battlefield.h:54
@ BF_HORDE_WINS
Definition: Battlefield.h:53
@ TEAM_ALLIANCE
Definition: SharedDefines.h:760
void DoPlaySoundToAll(uint32 SoundID)
Definition: Battlefield.cpp:381
virtual void SendInitWorldStatesToAll()=0
Send all worldstate data to all player in zone.
virtual void OnBattleEnd(bool)
Called at the end of battle.
Definition: Battlefield.h:315
TeamId GetDefenderTeam()
Definition: Battlefield.h:277
void SetDefenderTeam(TeamId team)
Definition: Battlefield.h:280
TeamId GetAttackerTeam()
Definition: Battlefield.h:278

References BF_ALLIANCE_WINS, BF_HORDE_WINS, DoPlaySoundToAll(), GetAttackerTeam(), GetDefenderTeam(), m_isActive, m_NoWarBattleTime, m_StartGrouping, m_Timer, OnBattleEnd(), SendInitWorldStatesToAll(), SetDefenderTeam(), and TEAM_ALLIANCE.

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

◆ FillInitialWorldStates()

virtual void Battlefield::FillInitialWorldStates ( WorldPacket )
pure virtual

Implemented in BattlefieldWG.

Referenced by Player::SendInitWorldStates().

◆ GetAttackerTeam()

◆ GetBattleId()

uint32 Battlefield::GetBattleId ( )
inline
331{ return m_BattleId; }

References m_BattleId.

◆ GetClosestGraveyard()

GraveyardStruct const * Battlefield::GetClosestGraveyard ( Player player)
597{
598 BfGraveyard* closestGY = nullptr;
599 float maxdist = -1;
600 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
601 {
602 if (m_GraveyardList[i])
603 {
604 if (m_GraveyardList[i]->GetControlTeamId() != player->GetTeamId())
605 continue;
606
607 float dist = m_GraveyardList[i]->GetDistance(player);
608 if (dist < maxdist || maxdist < 0)
609 {
610 closestGY = m_GraveyardList[i];
611 maxdist = dist;
612 }
613 }
614 }
615
616 if (closestGY)
617 return sGraveyard->GetGraveyard(closestGY->GetGraveyardId());
618
619 return nullptr;
620}
#define sGraveyard
Definition: GameGraveyard.h:75
Definition: Battlefield.h:148
uint32 GetGraveyardId() const
Definition: Battlefield.h:195

References BfGraveyard::GetGraveyardId(), Player::GetTeamId(), m_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.

272{ return m_Data32[dataId]; }
std::vector< uint32 > m_Data32
Definition: Battlefield.h:409

References m_Data32.

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

◆ GetData64()

uint64 Battlefield::GetData64 ( uint32  dataId) const
inlineoverridevirtual

Reimplemented from ZoneScript.

268{ return m_Data64[dataId]; }
std::vector< uint64 > m_Data64
Definition: Battlefield.h:408

References m_Data64.

◆ 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())
522{
523 for (GuidUnorderedSet::const_iterator itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr)
524 if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter()))
525 if (!group->IsFull())
526 return group;
527
528 return nullptr;
529}

References m_Groups, and sGroupMgr.

Referenced by AddOrSetPlayerToCorrectBfGroup().

◆ GetGameObject()

GameObject * Battlefield::GetGameObject ( ObjectGuid const  guid)
857{
858 if (!m_Map)
859 return nullptr;
860
861 return m_Map->GetGameObject(guid);
862}
GameObject * GetGameObject(ObjectGuid const guid)
Definition: Map.cpp:3319

References Map::GetGameObject(), and m_Map.

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

◆ GetGraveyardById()

BfGraveyard * Battlefield::GetGraveyardById ( uint32  id) const
582{
583 if (id < m_GraveyardList.size())
584 {
585 if (m_GraveyardList[id])
586 return m_GraveyardList[id];
587 else
588 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} not existed", id);
589 }
590 else
591 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} cant be found", id);
592
593 return nullptr;
594}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156

References LOG_ERROR, and m_GraveyardList.

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

◆ GetGraveyardVector()

GraveyardVect Battlefield::GetGraveyardVector ( )
inline

◆ GetGroupPlayer()

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

Return battlefield group where player is.

532{
533 for (GuidUnorderedSet::const_iterator itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr)
534 if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter()))
535 if (group->IsMember(guid))
536 return group;
537
538 return nullptr;
539}

References m_Groups, and sGroupMgr.

◆ GetOtherTeam()

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

References TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by InvitePlayerToQueue().

◆ GetTimer()

◆ GetTypeId()

uint32 Battlefield::GetTypeId ( )
inline
243{ return m_TypeId; }

References m_TypeId.

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

◆ GetZoneId()

uint32 Battlefield::GetZoneId ( )
inline

◆ HandleKill()

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

Called when a Unit is kill in battlefield zone.

Reimplemented in BattlefieldWG.

241{};

◆ HandlePlayerEnterZone()

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

Called when player (player) enter in zone.

Todo:
: Send a packet to announce it to 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 desn't leave
89 if (IsWarTime())
90 {
91 if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer) // Vacant spaces
92 InvitePlayerToWar(player);
93 else // No more vacant places
94 {
96 m_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 // Add player in the list of player in zone
109 m_players[player->GetTeamId()].insert(player->GetGUID());
110 OnPlayerEnterZone(player);
111}
constexpr auto MINUTE
Definition: Common.h:47
Seconds GetGameTime()
Definition: GameTime.cpp:38
void InvitePlayerToQueue(Player *player)
Definition: Battlefield.cpp:229
void InvitePlayerToWar(Player *player)
Definition: Battlefield.cpp:276
bool IsWarTime()
Return true if battle is start, false if battle is not started.
Definition: Battlefield.h:249
PlayerTimerMap m_PlayersWillBeKick[PVP_TEAMS_COUNT]
Definition: Battlefield.h:379
PlayerTimerMap m_InvitedPlayers[PVP_TEAMS_COUNT]
Definition: Battlefield.h:378
virtual void OnPlayerEnterZone(Player *)
Called when a player enter in battlefield zone.
Definition: Battlefield.h:325
bool IsGameMaster() const
Definition: Player.h:1158
bool IsInFlight() const
Definition: Unit.h:1096

References GameTime::GetGameTime(), Object::GetGUID(), Player::GetTeamId(), InvitePlayerToQueue(), InvitePlayerToWar(), Player::IsGameMaster(), Unit::IsInFlight(), IsWarTime(), m_InvitedPlayers, m_MaxPlayer, m_players, m_PlayersInWar, m_PlayersWillBeKick, m_StartGroupingTimer, m_Timer, MINUTE, and OnPlayerEnterZone().

◆ HandlePlayerLeaveZone()

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

Called when player (player) leave the zone.

115{
116 if (IsWarTime())
117 {
118 // If the player is participating to the battle
119 if (m_PlayersInWar[player->GetTeamId()].find(player->GetGUID()) != m_PlayersInWar[player->GetTeamId()].end())
120 {
121 m_PlayersInWar[player->GetTeamId()].erase(player->GetGUID());
123 if (Group* group = player->GetGroup()) // Remove the player from the raid group
124 if (group->isBFGroup())
125 group->RemoveMember(player->GetGUID());
126
127 OnPlayerLeaveWar(player);
128 }
129 }
130
131 for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
132 (*itr)->HandlePlayerLeave(player);
133
134 m_InvitedPlayers[player->GetTeamId()].erase(player->GetGUID());
135 m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
136 m_players[player->GetTeamId()].erase(player->GetGUID());
137 SendRemoveWorldStates(player);
139 OnPlayerLeaveZone(player);
140}
virtual void SendRemoveWorldStates(Player *)
Definition: Battlefield.h:414
virtual void OnPlayerLeaveZone(Player *)
Called when a player leave battlefield zone.
Definition: Battlefield.h:323
void RemovePlayerFromResurrectQueue(ObjectGuid player_guid)
Definition: Battlefield.cpp:637
virtual void OnPlayerLeaveWar(Player *)
Called when a player leave the battle.
Definition: Battlefield.h:321
WorldSession * GetSession() const
Definition: Player.h:1978
void SendBfLeaveMessage(uint32 battleId, BFLeaveReason reason=BF_LEAVE_REASON_EXITED)
Definition: BattlefieldHandler.cpp:85

References Player::GetGroup(), Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), IsWarTime(), m_BattleId, m_capturePoints, m_InvitedPlayers, m_players, m_PlayersInWar, m_PlayersWillBeKick, OnPlayerLeaveWar(), OnPlayerLeaveZone(), RemovePlayerFromResurrectQueue(), WorldSession::SendBfLeaveMessage(), and SendRemoveWorldStates().

◆ HasPlayer()

bool Battlefield::HasPlayer ( Player player) const
protected
387{
388 return m_players[player->GetTeamId()].find(player->GetGUID()) != m_players[player->GetTeamId()].end();
389}

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

Referenced by RemovePlayerFromResurrectQueue().

◆ HideNpc()

void Battlefield::HideNpc ( Creature creature)
493{
494 creature->CombatStop();
495 creature->SetReactState(REACT_PASSIVE);
497 creature->SetPhaseMask(2, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
498 creature->DisappearAndDie();
499 creature->SetVisible(false);
500}
@ REACT_PASSIVE
Definition: Unit.h:548
@ UNIT_FLAG_NON_ATTACKABLE
Definition: UnitDefines.h:230
@ UNIT_FLAG_NOT_SELECTABLE
Definition: UnitDefines.h:254
void SetReactState(ReactStates state)
A creature can have 3 ReactStates : Agressive, Passive, Neutral.
Definition: Creature.h:97
void DisappearAndDie()
Definition: Creature.cpp:371
void SetVisible(bool x)
Definition: Unit.cpp:14189
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10398
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition: Unit.cpp:19005
void SetUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition: Unit.h:683

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 
)
309{
310 if (Creature* creature = SpawnCreature(entry, x, y, z, o, TEAM_NEUTRAL))
311 StalkerGuid = creature->GetGUID();
312 else
313 LOG_ERROR("bg.battlefield", "Battlefield::InitStalker: could not spawn Stalker (Creature entry {}), zone messeges will be un-available", entry);
314}
ObjectGuid StalkerGuid
Definition: Battlefield.h:365
Creature * SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId teamId)
Definition: Battlefield.cpp:784
Definition: Creature.h:46

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.

239{
240 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
241 {
243 for (GuidUnorderedSet::const_iterator itr = copy.begin(); itr != copy.end(); ++itr)
244 {
245 if (Player* player = ObjectAccessor::FindPlayer(*itr))
246 {
247 if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer)
248 InvitePlayerToWar(player);
249 else
250 {
251 //Full
252 }
253 }
254 }
255 m_PlayersInQueue[team].clear();
256 }
257}
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:257

References ObjectAccessor::FindPlayer(), InvitePlayerToWar(), m_InvitedPlayers, m_MaxPlayer, m_PlayersInQueue, m_PlayersInWar, 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()

222{
223 for (uint8 team = 0; team < 2; ++team)
224 for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
225 if (Player* player = ObjectAccessor::FindPlayer(*itr))
226 InvitePlayerToQueue(player);
227}

References ObjectAccessor::FindPlayer(), InvitePlayerToQueue(), and m_players.

Referenced by Update().

◆ InvitePlayersInZoneToWar()

void Battlefield::InvitePlayersInZoneToWar ( )

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

260{
261 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
262 for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
263 {
264 if (Player* player = ObjectAccessor::FindPlayer(*itr))
265 {
266 if (m_PlayersInWar[player->GetTeamId()].count(player->GetGUID()) || m_InvitedPlayers[player->GetTeamId()].count(player->GetGUID()))
267 continue;
268 if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer)
269 InvitePlayerToWar(player);
270 else if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0)// Battlefield is full of players
271 m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
272 }
273 }
274}

References ObjectAccessor::FindPlayer(), GameTime::GetGameTime(), InvitePlayerToWar(), m_InvitedPlayers, m_MaxPlayer, m_players, m_PlayersInWar, m_PlayersWillBeKick, and PVP_TEAMS_COUNT.

Referenced by StartBattle(), and Update().

◆ InvitePlayerToQueue()

void Battlefield::InvitePlayerToQueue ( Player player)
230{
231 if (m_PlayersInQueue[player->GetTeamId()].count(player->GetGUID()))
232 return;
233
234 if (m_PlayersInQueue[player->GetTeamId()].size() <= m_MinPlayer || m_PlayersInQueue[GetOtherTeam(player->GetTeamId())].size() >= m_MinPlayer)
236}
TeamId GetOtherTeam(TeamId team)
Definition: Battlefield.h:279
void SendBfInvitePlayerToQueue(uint32 battleId)
Definition: BattlefieldHandler.cpp:45

References Object::GetGUID(), GetOtherTeam(), Player::GetSession(), Player::GetTeamId(), m_BattleId, m_MinPlayer, m_PlayersInQueue, and WorldSession::SendBfInvitePlayerToQueue().

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

◆ InvitePlayerToWar()

void Battlefield::InvitePlayerToWar ( Player player)
Todo:
: needed ?
277{
278 if (!player)
279 return;
280
282 if (player->IsInFlight())
283 return;
284
285 if (player->InBattleground())
286 {
287 m_PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
288 return;
289 }
290
291 // If the player does not match minimal level requirements for the battlefield, kick him
292 if (player->GetLevel() < m_MinLevel)
293 {
294 if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0)
295 m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
296 return;
297 }
298
299 // Check if player is not already in war
300 if (m_PlayersInWar[player->GetTeamId()].count(player->GetGUID()) || m_InvitedPlayers[player->GetTeamId()].count(player->GetGUID()))
301 return;
302
303 m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
306}
bool InBattleground() const
Definition: Player.h:2232
uint8 GetLevel() const
Definition: Unit.h:855
void SendBfInvitePlayerToWar(uint32 battleId, uint32 zoneId, uint32 time)
Definition: BattlefieldHandler.cpp:31

References GameTime::GetGameTime(), Object::GetGUID(), Unit::GetLevel(), Player::GetSession(), Player::GetTeamId(), Player::InBattleground(), Unit::IsInFlight(), m_BattleId, m_InvitedPlayers, m_MinLevel, m_PlayersInQueue, m_PlayersInWar, m_PlayersWillBeKick, m_TimeForAcceptInvite, m_ZoneId, and WorldSession::SendBfInvitePlayerToWar().

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

◆ IsEnabled()

bool Battlefield::IsEnabled ( )
inline

Return if battlefield is enable.

254{ return m_IsEnabled; }

References m_IsEnabled.

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

◆ IsWarTime()

◆ KickAfkPlayers()

void Battlefield::KickAfkPlayers ( )
protected
317{
318 // xinef: optimization, dont lookup player twice
319 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
320 for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
321 if (Player* player = ObjectAccessor::FindPlayer(*itr))
322 if (player->isAFK() && player->GetZoneId() == GetZoneId() && !player->IsGameMaster())
323 player->TeleportTo(KickPosition);
324}
uint32 GetZoneId()
Definition: Battlefield.h:244
WorldLocation KickPosition
Definition: Battlefield.h:395

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

Referenced by Update().

◆ 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 kick
327{
328 if (Player* player = ObjectAccessor::FindPlayer(guid))
329 {
330 if (player->GetZoneId() == GetZoneId() && !player->IsGameMaster())
331 player->TeleportTo(KickPosition);
332 }
333}

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

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

◆ OnBattleEnd()

virtual void Battlefield::OnBattleEnd ( bool  )
inlinevirtual

Called at the end of battle.

Reimplemented in BattlefieldWG.

315{};

Referenced by EndBattle().

◆ OnBattleStart()

virtual void Battlefield::OnBattleStart ( )
inlinevirtual

Called on start.

Reimplemented in BattlefieldWG.

313{};

Referenced by StartBattle().

◆ OnPlayerEnterZone()

virtual void Battlefield::OnPlayerEnterZone ( Player )
inlinevirtual

Called when a player enter in battlefield zone.

Reimplemented in BattlefieldWG.

325{};

Referenced by HandlePlayerEnterZone().

◆ OnPlayerJoinWar()

virtual void Battlefield::OnPlayerJoinWar ( Player )
inlinevirtual

Called when a player accept to join the battle.

Reimplemented in BattlefieldWG.

319{};

Referenced by PlayerAcceptInviteToWar().

◆ OnPlayerLeaveWar()

virtual void Battlefield::OnPlayerLeaveWar ( Player )
inlinevirtual

Called when a player leave the battle.

Reimplemented in BattlefieldWG.

321{};

Referenced by HandlePlayerLeaveZone().

◆ OnPlayerLeaveZone()

virtual void Battlefield::OnPlayerLeaveZone ( Player )
inlinevirtual

Called when a player leave battlefield zone.

Reimplemented in BattlefieldWG.

323{};

Referenced by HandlePlayerLeaveZone().

◆ OnStartGrouping()

virtual void Battlefield::OnStartGrouping ( )
inlinevirtual

Called x minutes before battle start when player in zone are invite to join queue.

Reimplemented in BattlefieldWG.

317{};

Referenced by Update().

◆ PlayerAcceptInviteToQueue()

void Battlefield::PlayerAcceptInviteToQueue ( Player player)
393{
394 // Add player in queue
395 m_PlayersInQueue[player->GetTeamId()].insert(player->GetGUID());
396 // Send notification
398}
void SendBfQueueInviteResponse(uint32 battleId, uint32 zoneId, bool canQueue=true, bool full=false)
Definition: BattlefieldHandler.cpp:61

References Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), m_BattleId, m_PlayersInQueue, m_ZoneId, and WorldSession::SendBfQueueInviteResponse().

Referenced by WorldSession::HandleBfQueueInviteResponse().

◆ PlayerAcceptInviteToWar()

void Battlefield::PlayerAcceptInviteToWar ( Player player)
416{
417 if (!IsWarTime())
418 return;
419
421 {
423 m_PlayersInWar[player->GetTeamId()].insert(player->GetGUID());
424 m_InvitedPlayers[player->GetTeamId()].erase(player->GetGUID());
425
426 if (player->isAFK())
427 player->ToggleAFK();
428
429 OnPlayerJoinWar(player); //for scripting
430 }
431}
virtual void OnPlayerJoinWar(Player *)
Called when a player accept to join the battle.
Definition: Battlefield.h:319
bool AddOrSetPlayerToCorrectBfGroup(Player *player)
Force player to join a battlefield group.
Definition: Battlefield.cpp:541
void ToggleAFK()
Definition: Player.cpp:1289
bool isAFK() const
Definition: Player.h:1134
void SendBfEntered(uint32 battleId)
Definition: BattlefieldHandler.cpp:74

References AddOrSetPlayerToCorrectBfGroup(), Object::GetGUID(), Player::GetSession(), Player::GetTeamId(), Player::isAFK(), IsWarTime(), m_BattleId, m_InvitedPlayers, m_PlayersInWar, OnPlayerJoinWar(), WorldSession::SendBfEntered(), and Player::ToggleAFK().

Referenced by WorldSession::HandleBfEntryInviteResponse().

◆ PlayerAskToLeave()

void Battlefield::PlayerAskToLeave ( Player player)
409{
410 // Player leaving Wintergrasp, trigger Hearthstone spell.
411 player->CastSpell(player, 8690, true);
412}
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:1168

References Unit::CastSpell().

◆ RegisterZone()

void Battlefield::RegisterZone ( uint32  zoneid)
protected
488{
489 sBattlefieldMgr->AddZone(zoneId, this);
490}
#define sBattlefieldMgr
Definition: BattlefieldMgr.h:77

References sBattlefieldMgr.

Referenced by BattlefieldWG::SetupBattlefield().

◆ RemovePlayerFromResurrectQueue()

void Battlefield::RemovePlayerFromResurrectQueue ( ObjectGuid  player_guid)
638{
639 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
640 {
641 if (!m_GraveyardList[i])
642 continue;
643
644 if (m_GraveyardList[i]->HasPlayer(playerGuid))
645 {
646 m_GraveyardList[i]->RemovePlayer(playerGuid);
647 break;
648 }
649 }
650}
bool HasPlayer(Player *player) const
Definition: Battlefield.cpp:386

References HasPlayer(), and m_GraveyardList.

Referenced by HandlePlayerLeaveZone().

◆ SendAreaSpiritHealerQueryOpcode()

void Battlefield::SendAreaSpiritHealerQueryOpcode ( Player player,
const ObjectGuid guid 
)
653{
655 uint32 time = m_LastResurectTimer; // resurrect every 30 seconds
656
657 data << guid << time;
658 ASSERT(player);
659 player->GetSession()->SendPacket(&data);
660}
std::uint32_t uint32
Definition: Define.h:107
#define ASSERT
Definition: Errors.h:68
@ SMSG_AREA_SPIRIT_HEALER_TIME
Definition: Opcodes.h:770
Definition: WorldPacket.h:27
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214

References ASSERT, Player::GetSession(), m_LastResurectTimer, WorldSession::SendPacket(), and SMSG_AREA_SPIRIT_HEALER_TIME.

◆ SendInitWorldStatesToAll()

virtual void Battlefield::SendInitWorldStatesToAll ( )
pure virtual

Send all worldstate data to all player in zone.

Implemented in BattlefieldWG.

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

◆ SendRemoveWorldStates()

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

Referenced by HandlePlayerLeaveZone().

◆ SendUpdateWorldState()

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

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

480{
481 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
482 for (GuidUnorderedSet::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
483 if (Player* player = ObjectAccessor::FindPlayer(*itr))
484 player->SendUpdateWorldState(field, value);
485}

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

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

◆ SendWarning()

void Battlefield::SendWarning ( uint8  id,
WorldObject const *  target = nullptr 
)
474{
475 if (Creature* stalker = GetCreature(StalkerGuid))
476 sCreatureTextMgr->SendChat(stalker, id, target);
477}
#define sCreatureTextMgr
Definition: CreatureTextMgr.h:119
Creature * GetCreature(ObjectGuid const guid)
Definition: Battlefield.cpp:848

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.

273{ m_Data32[dataId] = value; }

References m_Data32.

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

◆ SetData64()

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

Reimplemented from ZoneScript.

269{ m_Data64[dataId] = value; }

References m_Data64.

◆ SetDefenderTeam()

void Battlefield::SetDefenderTeam ( TeamId  team)
inline
280{ m_DefenderTeam = team; }

References m_DefenderTeam.

Referenced by EndBattle().

◆ SetGraveyardNumber()

void Battlefield::SetGraveyardNumber ( uint32  number)
inline
299{ m_GraveyardList.resize(number); }

References m_GraveyardList.

Referenced by BattlefieldWG::SetupBattlefield().

◆ SetTimer()

void Battlefield::SetTimer ( uint32  timer)
inline
355{ m_Timer = timer; }

References m_Timer.

Referenced by bf_commandscript::HandleBattlefieldTimer().

◆ SetupBattlefield()

virtual bool Battlefield::SetupBattlefield ( )
inlinevirtual

Call this to init the Battlefield.

Reimplemented in BattlefieldWG.

219{ return true; }

Referenced by BattlefieldMgr::InitBattlefield().

◆ ShowNpc()

void Battlefield::ShowNpc ( Creature creature,
bool  aggressive 
)
503{
504 creature->SetPhaseMask(1, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
505 creature->SetVisible(true);
507 if (!creature->IsAlive())
508 creature->Respawn(true);
509 if (aggressive)
511 else
512 {
514 creature->SetReactState(REACT_PASSIVE);
515 }
516}
@ REACT_AGGRESSIVE
Definition: Unit.h:550
void Respawn(bool force=false)
Definition: Creature.cpp:2030
bool IsAlive() const
Definition: Unit.h:1204
void RemoveUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition: Unit.h:684

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 
)
785{
786 //Get map object
787 Map* map = sMapMgr->CreateBaseMap(m_MapId);
788 if (!map)
789 {
790 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {} map not found", entry);
791 return nullptr;
792 }
793
794 CreatureTemplate const* cinfo = sObjectMgr->GetCreatureTemplate(entry);
795 if (!cinfo)
796 {
797 LOG_ERROR("sql.sql", "Battlefield::SpawnCreature: entry {} does not exist.", entry);
798 return nullptr;
799 }
800
801 Creature* creature = new Creature(true);
802 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, PHASEMASK_NORMAL, entry, 0, x, y, z, o))
803 {
804 LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {}", entry);
805 delete creature;
806 return nullptr;
807 }
808
809 creature->SetFaction(BattlefieldFactions[teamId]);
810 creature->SetHomePosition(x, y, z, o);
811
812 // force using DB speeds -- do we really need this?
813 creature->SetSpeed(MOVE_WALK, cinfo->speed_walk);
814 creature->SetSpeed(MOVE_RUN, cinfo->speed_run);
815
816 // Set creature in world
817 map->AddToMap(creature);
818 creature->setActive(true);
819
820 return creature;
821}
#define sMapMgr
Definition: MapMgr.h:221
const uint32 BattlefieldFactions[PVP_TEAMS_COUNT]
Definition: Battlefield.h:60
#define sObjectMgr
Definition: ObjectMgr.h:1623
@ MOVE_RUN
Definition: UnitDefines.h:329
@ MOVE_WALK
Definition: UnitDefines.h:328
@ PHASEMASK_NORMAL
Definition: Object.h:59
void SetHomePosition(float x, float y, float z, float o)
Definition: Creature.h:337
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:1123
Definition: CreatureData.h:189
float speed_run
Definition: CreatureData.h:204
float speed_walk
Definition: CreatureData.h:203
void setActive(bool isActiveObject)
Definition: Object.cpp:1085
void SetFaction(uint32 faction)
Definition: Unit.cpp:10018
void SetSpeed(UnitMoveType mtype, float rate, bool forced=false)
Definition: Unit.cpp:14383
Definition: Map.h:313
ObjectGuid::LowType GenerateLowGuid()
Definition: Map.h:638
bool AddToMap(T *, bool checkTransport=false)
Definition: Map.cpp:555

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

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

◆ SpawnCreature() [2/2]

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

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 
)
825{
826 // Get map object
827 Map* map = sMapMgr->CreateBaseMap(m_MapId);
828 if (!map)
829 return 0;
830
831 // Create gameobject
832 GameObject* go = sObjectMgr->IsGameObjectStaticTransport(entry) ? new StaticTransport() : new GameObject();
833 if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, PHASEMASK_NORMAL, x, y, z, o, G3D::Quat(), 100, GO_STATE_READY))
834 {
835 LOG_ERROR("sql.sql", "Battlefield::SpawnGameObject: Gameobject template {} not found in database! Battlefield not created!", entry);
836 LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Cannot create gameobject template {}! Battlefield not created!", entry);
837 delete go;
838 return nullptr;
839 }
840
841 // Add to world
842 map->AddToMap(go);
843 go->setActive(true);
844
845 return go;
846}
@ GO_STATE_READY
Definition: GameObjectData.h:691
Definition: GameObject.h:121
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:254
Definition: Transport.h:112

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

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

◆ StartBattle()

void Battlefield::StartBattle ( )
336{
337 if (m_isActive)
338 return;
339
340 for (int team = 0; team < PVP_TEAMS_COUNT; team++)
341 {
342 m_PlayersInWar[team].clear();
343 m_Groups[team].clear();
344 }
345
347 m_isActive = true;
348
351
353
355}
@ BF_START
Definition: Battlefield.h:55
void InvitePlayersInQueueToWar()
Invite all players in queue to join battle on battle start.
Definition: Battlefield.cpp:238
virtual void OnBattleStart()
Called on start.
Definition: Battlefield.h:313
void InvitePlayersInZoneToWar()
Invite all players in zone to join battle on battle start.
Definition: Battlefield.cpp:259

References BF_START, DoPlaySoundToAll(), InvitePlayersInQueueToWar(), InvitePlayersInZoneToWar(), m_BattleTime, m_Groups, m_isActive, m_PlayersInWar, m_Timer, OnBattleStart(), and PVP_TEAMS_COUNT.

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
434{
435 if (spellId > 0)
436 {
437 for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
438 if (Player* player = ObjectAccessor::FindPlayer(*itr))
439 player->CastSpell(player, uint32(spellId), true);
440 }
441 else
442 {
443 for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
444 if (Player* player = ObjectAccessor::FindPlayer(*itr))
445 player->RemoveAuraFromStack(uint32(-spellId));
446 }
447}

References ObjectAccessor::FindPlayer(), and m_PlayersInWar.

◆ ToggleBattlefield()

void Battlefield::ToggleBattlefield ( bool  enable)
inline

Enable or Disable battlefield.

252{ m_IsEnabled = enable; }

References m_IsEnabled.

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 m_StartGroupingTimer minutes before start
  • Kick Afk players
    Parameters
    diff: time ellapsed since last call (in ms)

Reimplemented in BattlefieldWG.

143{
144 if (m_Timer <= diff)
145 {
146 if (!IsEnabled() || (!IsWarTime() && sWorld->GetActiveSessionCount() > 3500)) // if WG is disabled or there is more than 3500 connections, switch automaticly
147 {
148 m_isActive = true;
149 EndBattle(false);
150 return false;
151 }
152 // Battlefield ends on time
153 if (IsWarTime())
154 EndBattle(true);
155 else // Time to start a new battle!
156 StartBattle();
157 }
158 else
159 m_Timer -= diff;
160
161 if (!IsEnabled())
162 return false;
163
164 // Invite players a few minutes before the battle's beginning
166 {
167 m_StartGrouping = true;
170 }
171
172 bool objective_changed = false;
173 if (IsWarTime())
174 {
175 if (m_uiKickAfkPlayersTimer <= diff)
176 {
179 }
180 else
182
183 // Kick players who chose not to accept invitation to the battle
184 if (m_uiKickDontAcceptTimer <= diff)
185 {
186 time_t now = GameTime::GetGameTime().count();
187 for (int team = 0; team < 2; team++)
188 for (PlayerTimerMap::iterator itr = m_InvitedPlayers[team].begin(); itr != m_InvitedPlayers[team].end(); ++itr)
189 if (itr->second <= now)
190 KickPlayerFromBattlefield(itr->first);
191
193 for (int team = 0; team < 2; team++)
194 for (PlayerTimerMap::iterator itr = m_PlayersWillBeKick[team].begin(); itr != m_PlayersWillBeKick[team].end(); ++itr)
195 if (itr->second <= now)
196 KickPlayerFromBattlefield(itr->first);
197
199 }
200 else
202
203 for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
204 if ((*itr)->Update(diff))
205 objective_changed = true;
206 }
207
208 if (m_LastResurectTimer <= diff)
209 {
210 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
211 if (GetGraveyardById(i))
212 m_GraveyardList[i]->Resurrect();
214 }
215 else
216 m_LastResurectTimer -= diff;
217
218 return objective_changed;
219}
#define sWorld
Definition: World.h:444
void EndBattle(bool endByTimer)
Definition: Battlefield.cpp:357
void InvitePlayersInZoneToQueue()
Invite all players in zone to join the queue, called x minutes before battle start in Update()
Definition: Battlefield.cpp:221
void KickPlayerFromBattlefield(ObjectGuid guid)
Kick player from battlefield and teleport him to kick-point location.
Definition: Battlefield.cpp:326
void StartBattle()
Definition: Battlefield.cpp:335
BfGraveyard * GetGraveyardById(uint32 id) const
Definition: Battlefield.cpp:581
void KickAfkPlayers()
Definition: Battlefield.cpp:316
virtual void OnStartGrouping()
Called x minutes before battle start when player in zone are invite to join queue.
Definition: Battlefield.h:317
bool IsEnabled()
Return if battlefield is enable.
Definition: Battlefield.h:254

References EndBattle(), GameTime::GetGameTime(), GetGraveyardById(), InvitePlayersInZoneToQueue(), InvitePlayersInZoneToWar(), IsEnabled(), IsWarTime(), KickAfkPlayers(), KickPlayerFromBattlefield(), m_capturePoints, m_GraveyardList, m_InvitedPlayers, m_isActive, m_LastResurectTimer, m_PlayersWillBeKick, m_StartGrouping, m_StartGroupingTimer, m_Timer, m_uiKickAfkPlayersTimer, m_uiKickDontAcceptTimer, OnStartGrouping(), RESURRECTION_INTERVAL, StartBattle(), and sWorld.

Referenced by BattlefieldWG::Update().

◆ UpdateData()

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

References m_Data32.

Friends And Related Function Documentation

◆ BattlefieldMgr

friend class BattlefieldMgr
friend

Member Data Documentation

◆ KickPosition

WorldLocation Battlefield::KickPosition
protected

◆ m_BattleId

◆ m_BattleTime

uint32 Battlefield::m_BattleTime
protected

◆ m_capturePoints

◆ m_Data32

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

◆ m_Data64

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

Referenced by GetData64(), and SetData64().

◆ m_DefenderTeam

◆ m_GraveyardList

◆ m_Groups

◆ m_InvitedPlayers

◆ m_isActive

◆ m_IsEnabled

bool Battlefield::m_IsEnabled
protected

◆ m_LastResurectTimer

uint32 Battlefield::m_LastResurectTimer
protected

◆ m_Map

Map* Battlefield::m_Map
protected

◆ m_MapId

◆ m_MaxPlayer

◆ m_MinLevel

uint32 Battlefield::m_MinLevel
protected

◆ m_MinPlayer

uint32 Battlefield::m_MinPlayer
protected

◆ m_NoWarBattleTime

uint32 Battlefield::m_NoWarBattleTime
protected

◆ m_players

◆ m_PlayersInQueue

◆ m_PlayersInWar

◆ m_PlayersWillBeKick

◆ m_RestartAfterCrash

uint32 Battlefield::m_RestartAfterCrash
protected

◆ m_StartGrouping

bool Battlefield::m_StartGrouping
protected

◆ m_StartGroupingTimer

uint32 Battlefield::m_StartGroupingTimer
protected

◆ m_TimeForAcceptInvite

uint32 Battlefield::m_TimeForAcceptInvite
protected

◆ m_Timer

◆ m_TypeId

uint32 Battlefield::m_TypeId
protected

◆ m_uiKickAfkPlayersTimer

uint32 Battlefield::m_uiKickAfkPlayersTimer
protected

Referenced by Battlefield(), and Update().

◆ m_uiKickDontAcceptTimer

uint32 Battlefield::m_uiKickDontAcceptTimer
protected

Referenced by Battlefield(), and Update().

◆ m_ZoneId

◆ StalkerGuid

ObjectGuid Battlefield::StalkerGuid
protected

Referenced by InitStalker(), and SendWarning().