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
 

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 kill in battlefield zone.
 
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.
 
void ToggleBattlefield (bool enable)
 Enable or Disable battlefield.
 
bool IsEnabled ()
 Return if battlefield is enable.
 
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) enter in zone.
 
void HandlePlayerLeaveZone (Player *player, uint32 zone)
 Called when player (player) leave 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 ()
 
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.
 
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 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.
 
virtual void OnBattleEnd (bool)
 Called at the end of battle.
 
virtual void OnStartGrouping ()
 Called x minutes before battle start when player in zone are invite to join queue.
 
virtual void OnPlayerJoinWar (Player *)
 Called when a player accept to join the battle.
 
virtual void OnPlayerLeaveWar (Player *)
 Called when a player leave the battle.
 
virtual void OnPlayerLeaveZone (Player *)
 Called when a player leave battlefield zone.
 
virtual void OnPlayerEnterZone (Player *)
 Called when a player enter in battlefield zone.
 
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.
 
virtual void FillInitialWorldStates (WorldPacket &)=0
 
bool CanFlyIn ()
 Return if we can use mount in battlefield.
 
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.

37{
38 m_Timer = 0;
39 m_IsEnabled = true;
40 m_isActive = false;
42
43 m_TypeId = 0;
44 m_BattleId = 0;
45 m_ZoneId = 0;
46 m_Map = nullptr;
47 m_MapId = 0;
48 m_MaxPlayer = 0;
49 m_MinPlayer = 0;
50 m_MinLevel = 0;
51 m_BattleTime = 0;
56
58
61 m_StartGrouping = false;
62}
#define RESURRECTION_INTERVAL
Definition: Battleground.h:167
@ TEAM_NEUTRAL
Definition: SharedDefines.h:734
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.

65{
66 for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
67 delete *itr;
68
69 for (GraveyardVect::const_iterator itr = m_GraveyardList.begin(); itr != m_GraveyardList.end(); ++itr)
70 delete *itr;
71
72 m_capturePoints.clear();
73}
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.

537{
538 if (!player->IsInWorld())
539 return false;
540
541 if (player->GetGroup() && (player->GetGroup()->isBGGroup() || player->GetGroup()->isBFGroup()))
542 {
543 LOG_INFO("misc", "Battlefield::AddOrSetPlayerToCorrectBfGroup - player is already in {} group!", (player->GetGroup()->isBGGroup() ? "BG" : "BF"));
544 return false;
545 }
546
547 Group* group = GetFreeBfRaid(player->GetTeamId());
548 if (!group)
549 {
550 group = new Group;
551 group->SetBattlefieldGroup(this);
552 group->Create(player);
553 sGroupMgr->AddGroup(group);
554 m_Groups[player->GetTeamId()].insert(group->GetGUID());
555 }
556 else if (group->IsMember(player->GetGUID()))
557 {
558 uint8 subgroup = group->GetMemberGroup(player->GetGUID());
559 player->SetBattlegroundOrBattlefieldRaid(group, subgroup);
560 }
561 else
562 group->AddMember(player);
563
564 return true;
565}
std::uint8_t uint8
Definition: Define.h:110
#define LOG_INFO(filterType__,...)
Definition: Log.h:167
#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:516
GuidUnorderedSet m_Groups[PVP_TEAMS_COUNT]
Definition: Battlefield.h:406
bool IsInWorld() const
Definition: Object.h:101
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2069
Group * GetGroup()
Definition: Player.h:2428
void SetBattlegroundOrBattlefieldRaid(Group *group, int8 subgroup=-1)
Definition: Player.cpp:13004
Definition: Group.h:168
uint8 GetMemberGroup(ObjectGuid guid) const
Definition: Group.cpp:2323
void SetBattlefieldGroup(Battlefield *bf)
Definition: Group.cpp:2336
bool AddMember(Player *player)
Definition: Group.cpp:390
ObjectGuid GetGUID() const
Definition: Group.cpp:2245
bool isBGGroup() const
Definition: Group.cpp:2215
bool isBFGroup() const
Definition: Group.cpp:2220
bool IsMember(ObjectGuid guid) const
Definition: Group.cpp:2275
bool Create(Player *leader)
Definition: Group.cpp:108

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
618{
619 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
620 {
621 if (!m_GraveyardList[i])
622 continue;
623
624 if (m_GraveyardList[i]->HasNpc(npcGuid))
625 {
626 m_GraveyardList[i]->AddPlayer(playerGuid);
627 break;
628 }
629 }
630}

References m_GraveyardList.

◆ AskToLeaveQueue()

void Battlefield::AskToLeaveQueue ( Player player)
397{
398 // Remove player from queue
399 m_PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
400}
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
453{
454 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
455 for (GuidUnorderedSet::const_iterator itr = m_PlayersInQueue[team].begin(); itr != m_PlayersInQueue[team].end(); ++itr)
456 if (Player* player = ObjectAccessor::FindPlayer(*itr))
457 player->GetSession()->SendPacket(data);
458}
uint8 constexpr PVP_TEAMS_COUNT
Definition: SharedDefines.h:3417
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:250
Definition: Player.h:1056

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

◆ BroadcastPacketToWar()

void Battlefield::BroadcastPacketToWar ( WorldPacket const *  data) const
protected
461{
462 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
463 for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
464 if (Player* player = ObjectAccessor::FindPlayer(*itr))
465 player->GetSession()->SendPacket(data);
466}
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
445{
446 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
447 for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
448 if (Player* player = ObjectAccessor::FindPlayer(*itr))
449 player->GetSession()->SendPacket(data);
450}
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)
377{
379}
void BroadcastPacketToWar(WorldPacket const *data) const
Definition: Battlefield.cpp:460
Definition: MiscPackets.h:83

References BroadcastPacketToWar().

Referenced by EndBattle(), and StartBattle().

◆ EndBattle()

void Battlefield::EndBattle ( bool  endByTimer)
353{
354 if (!m_isActive)
355 return;
356
357 m_isActive = false;
358
359 m_StartGrouping = false;
360
361 if (!endByTimer)
363
366 else
368
369 OnBattleEnd(endByTimer);
370
371 // Reset battlefield timer
374}
@ BF_ALLIANCE_WINS
Definition: Battlefield.h:54
@ BF_HORDE_WINS
Definition: Battlefield.h:53
@ TEAM_ALLIANCE
Definition: SharedDefines.h:732
void DoPlaySoundToAll(uint32 SoundID)
Definition: Battlefield.cpp:376
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)
592{
593 BfGraveyard* closestGY = nullptr;
594 float maxdist = -1;
595 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
596 {
597 if (m_GraveyardList[i])
598 {
599 if (m_GraveyardList[i]->GetControlTeamId() != player->GetTeamId())
600 continue;
601
602 float dist = m_GraveyardList[i]->GetDistance(player);
603 if (dist < maxdist || maxdist < 0)
604 {
605 closestGY = m_GraveyardList[i];
606 maxdist = dist;
607 }
608 }
609 }
610
611 if (closestGY)
612 return sGraveyard->GetGraveyard(closestGY->GetGraveyardId());
613
614 return nullptr;
615}
#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())
517{
518 for (GuidUnorderedSet::const_iterator itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr)
519 if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter()))
520 if (!group->IsFull())
521 return group;
522
523 return nullptr;
524}

References m_Groups, and sGroupMgr.

Referenced by AddOrSetPlayerToCorrectBfGroup().

◆ GetGameObject()

GameObject * Battlefield::GetGameObject ( ObjectGuid const  guid)
852{
853 if (!m_Map)
854 return nullptr;
855
856 return m_Map->GetGameObject(guid);
857}
GameObject * GetGameObject(ObjectGuid const guid)
Definition: Map.cpp:3309

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
577{
578 if (id < m_GraveyardList.size())
579 {
580 if (m_GraveyardList[id])
581 return m_GraveyardList[id];
582 else
583 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} not existed", id);
584 }
585 else
586 LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} cant be found", id);
587
588 return nullptr;
589}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159

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.

527{
528 for (GuidUnorderedSet::const_iterator itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr)
529 if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter()))
530 if (group->IsMember(guid))
531 return group;
532
533 return nullptr;
534}

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

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
77{
78 // Xinef: do not invite players on taxi
79 if (!player->IsInFlight())
80 {
81 // If battle is started,
82 // If not full of players > invite player to join the war
83 // If full of players > announce to player that BF is full and kick him after a few second if he desn't leave
84 if (IsWarTime())
85 {
86 if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer) // Vacant spaces
87 InvitePlayerToWar(player);
88 else // No more vacant places
89 {
91 m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + (player->IsGameMaster() ? 30 * MINUTE : 10);
92 InvitePlayerToQueue(player);
93 }
94 }
95 else
96 {
97 // If time left is < 15 minutes invite player to join queue
99 InvitePlayerToQueue(player);
100 }
101 }
102
103 // Add player in the list of player in zone
104 m_players[player->GetTeamId()].insert(player->GetGUID());
105 OnPlayerEnterZone(player);
106}
constexpr auto MINUTE
Definition: Common.h:56
Seconds GetGameTime()
Definition: GameTime.cpp:38
void InvitePlayerToQueue(Player *player)
Definition: Battlefield.cpp:224
void InvitePlayerToWar(Player *player)
Definition: Battlefield.cpp:271
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:1146
bool IsInFlight() const
Definition: Unit.h:1688

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.

110{
111 if (IsWarTime())
112 {
113 // If the player is participating to the battle
114 if (m_PlayersInWar[player->GetTeamId()].find(player->GetGUID()) != m_PlayersInWar[player->GetTeamId()].end())
115 {
116 m_PlayersInWar[player->GetTeamId()].erase(player->GetGUID());
118 if (Group* group = player->GetGroup()) // Remove the player from the raid group
119 if (group->isBFGroup())
120 group->RemoveMember(player->GetGUID());
121
122 OnPlayerLeaveWar(player);
123 }
124 }
125
126 for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
127 (*itr)->HandlePlayerLeave(player);
128
129 m_InvitedPlayers[player->GetTeamId()].erase(player->GetGUID());
130 m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
131 m_players[player->GetTeamId()].erase(player->GetGUID());
132 SendRemoveWorldStates(player);
134 OnPlayerLeaveZone(player);
135}
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:632
virtual void OnPlayerLeaveWar(Player *)
Called when a player leave the battle.
Definition: Battlefield.h:321
WorldSession * GetSession() const
Definition: Player.h:1958
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
382{
383 return m_players[player->GetTeamId()].find(player->GetGUID()) != m_players[player->GetTeamId()].end();
384}

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

Referenced by RemovePlayerFromResurrectQueue().

◆ HideNpc()

void Battlefield::HideNpc ( Creature creature)
488{
489 creature->CombatStop();
490 creature->SetReactState(REACT_PASSIVE);
492 creature->SetPhaseMask(2, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
493 creature->DisappearAndDie();
494 creature->SetVisible(false);
495}
@ REACT_PASSIVE
Definition: Unit.h:1035
@ UNIT_FLAG_NON_ATTACKABLE
Definition: Unit.h:449
@ UNIT_FLAG_NOT_SELECTABLE
Definition: Unit.h:473
void SetReactState(ReactStates st)
Definition: Creature.h:89
void DisappearAndDie()
Definition: Creature.cpp:317
void SetVisible(bool x)
Definition: Unit.cpp:14222
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10424
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition: Unit.cpp:19312
void SetUnitFlag(UnitFlags flags)
Definition: Unit.h:1493

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

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

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

217{
218 for (uint8 team = 0; team < 2; ++team)
219 for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
220 if (Player* player = ObjectAccessor::FindPlayer(*itr))
221 InvitePlayerToQueue(player);
222}

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.

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

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)
225{
226 if (m_PlayersInQueue[player->GetTeamId()].count(player->GetGUID()))
227 return;
228
229 if (m_PlayersInQueue[player->GetTeamId()].size() <= m_MinPlayer || m_PlayersInQueue[GetOtherTeam(player->GetTeamId())].size() >= m_MinPlayer)
231}
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 ?
272{
273 if (!player)
274 return;
275
277 if (player->IsInFlight())
278 return;
279
280 if (player->InBattleground())
281 {
282 m_PlayersInQueue[player->GetTeamId()].erase(player->GetGUID());
283 return;
284 }
285
286 // If the player does not match minimal level requirements for the battlefield, kick him
287 if (player->GetLevel() < m_MinLevel)
288 {
289 if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0)
290 m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10;
291 return;
292 }
293
294 // Check if player is not already in war
295 if (m_PlayersInWar[player->GetTeamId()].count(player->GetGUID()) || m_InvitedPlayers[player->GetTeamId()].count(player->GetGUID()))
296 return;
297
298 m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
301}
bool InBattleground() const
Definition: Player.h:2211
uint8 GetLevel() const
Definition: Unit.h:1432
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
312{
313 // xinef: optimization, dont lookup player twice
314 for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
315 for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
316 if (Player* player = ObjectAccessor::FindPlayer(*itr))
317 if (player->isAFK() && player->GetZoneId() == GetZoneId() && !player->IsGameMaster())
318 player->TeleportTo(KickPosition);
319}
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
322{
323 if (Player* player = ObjectAccessor::FindPlayer(guid))
324 {
325 if (player->GetZoneId() == GetZoneId() && !player->IsGameMaster())
326 player->TeleportTo(KickPosition);
327 }
328}

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)
388{
389 // Add player in queue
390 m_PlayersInQueue[player->GetTeamId()].insert(player->GetGUID());
391 // Send notification
393}
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)
411{
412 if (!IsWarTime())
413 return;
414
416 {
418 m_PlayersInWar[player->GetTeamId()].insert(player->GetGUID());
419 m_InvitedPlayers[player->GetTeamId()].erase(player->GetGUID());
420
421 if (player->isAFK())
422 player->ToggleAFK();
423
424 OnPlayerJoinWar(player); //for scripting
425 }
426}
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:536
void ToggleAFK()
Definition: Player.cpp:1272
bool isAFK() const
Definition: Player.h:1124
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)
404{
405 // Player leaving Wintergrasp, trigger Hearthstone spell.
406 player->CastSpell(player, 8690, true);
407}
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:1169

References Unit::CastSpell().

◆ RegisterZone()

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

References sBattlefieldMgr.

Referenced by BattlefieldWG::SetupBattlefield().

◆ RemovePlayerFromResurrectQueue()

void Battlefield::RemovePlayerFromResurrectQueue ( ObjectGuid  player_guid)
633{
634 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
635 {
636 if (!m_GraveyardList[i])
637 continue;
638
639 if (m_GraveyardList[i]->HasPlayer(playerGuid))
640 {
641 m_GraveyardList[i]->RemovePlayer(playerGuid);
642 break;
643 }
644 }
645}
bool HasPlayer(Player *player) const
Definition: Battlefield.cpp:381

References HasPlayer(), and m_GraveyardList.

Referenced by HandlePlayerLeaveZone().

◆ SendAreaSpiritHealerQueryOpcode()

void Battlefield::SendAreaSpiritHealerQueryOpcode ( Player player,
const ObjectGuid guid 
)
648{
650 uint32 time = m_LastResurectTimer; // resurrect every 30 seconds
651
652 data << guid << time;
653 ASSERT(player);
654 player->GetSession()->SendPacket(&data);
655}
#define ASSERT
Definition: Errors.h:68
std::uint32_t uint32
Definition: Define.h:108
@ 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:207

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.

475{
476 for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
477 for (GuidUnorderedSet::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
478 if (Player* player = ObjectAccessor::FindPlayer(*itr))
479 player->SendUpdateWorldState(field, value);
480}

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 
)
469{
470 if (Creature* stalker = GetCreature(StalkerGuid))
471 sCreatureTextMgr->SendChat(stalker, id, target);
472}
#define sCreatureTextMgr
Definition: CreatureTextMgr.h:119
Creature * GetCreature(ObjectGuid const guid)
Definition: Battlefield.cpp:843

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 
)
498{
499 creature->SetPhaseMask(1, false); // pussywizard: false because UpdateObjectVisibility(true) is called below in SetVisible(), no need to have it here
500 creature->SetVisible(true);
502 if (!creature->IsAlive())
503 creature->Respawn(true);
504 if (aggressive)
506 else
507 {
509 creature->SetReactState(REACT_PASSIVE);
510 }
511}
@ REACT_AGGRESSIVE
Definition: Unit.h:1037
void Respawn(bool force=false)
Definition: Creature.cpp:2005
bool IsAlive() const
Definition: Unit.h:1820
void RemoveUnitFlag(UnitFlags flags)
Definition: Unit.h:1494

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

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 
)
775{
776 return SpawnCreature(entry, pos.m_positionX, pos.m_positionY, pos.m_positionZ, pos.m_orientation, teamId);
777}
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 
)
820{
821 // Get map object
822 Map* map = sMapMgr->CreateBaseMap(m_MapId);
823 if (!map)
824 return 0;
825
826 // Create gameobject
827 GameObject* go = sObjectMgr->IsGameObjectStaticTransport(entry) ? new StaticTransport() : new GameObject();
828 if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, PHASEMASK_NORMAL, x, y, z, o, G3D::Quat(), 100, GO_STATE_READY))
829 {
830 LOG_ERROR("sql.sql", "Battlefield::SpawnGameObject: Gameobject template {} not found in database! Battlefield not created!", entry);
831 LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Cannot create gameobject template {}! Battlefield not created!", entry);
832 delete go;
833 return nullptr;
834 }
835
836 // Add to world
837 map->AddToMap(go);
838 go->setActive(true);
839
840 return go;
841}
@ GO_STATE_READY
Definition: GameObjectData.h:691
Definition: GameObject.h:122
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:248
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 ( )
331{
332 if (m_isActive)
333 return;
334
335 for (int team = 0; team < PVP_TEAMS_COUNT; team++)
336 {
337 m_PlayersInWar[team].clear();
338 m_Groups[team].clear();
339 }
340
342 m_isActive = true;
343
346
348
350}
@ BF_START
Definition: Battlefield.h:55
void InvitePlayersInQueueToWar()
Invite all players in queue to join battle on battle start.
Definition: Battlefield.cpp:233
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:254

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

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.

138{
139 if (m_Timer <= diff)
140 {
141 if (!IsEnabled() || (!IsWarTime() && sWorld->GetActiveSessionCount() > 3500)) // if WG is disabled or there is more than 3500 connections, switch automaticly
142 {
143 m_isActive = true;
144 EndBattle(false);
145 return false;
146 }
147 // Battlefield ends on time
148 if (IsWarTime())
149 EndBattle(true);
150 else // Time to start a new battle!
151 StartBattle();
152 }
153 else
154 m_Timer -= diff;
155
156 if (!IsEnabled())
157 return false;
158
159 // Invite players a few minutes before the battle's beginning
161 {
162 m_StartGrouping = true;
165 }
166
167 bool objective_changed = false;
168 if (IsWarTime())
169 {
170 if (m_uiKickAfkPlayersTimer <= diff)
171 {
174 }
175 else
177
178 // Kick players who chose not to accept invitation to the battle
179 if (m_uiKickDontAcceptTimer <= diff)
180 {
181 time_t now = GameTime::GetGameTime().count();
182 for (int team = 0; team < 2; team++)
183 for (PlayerTimerMap::iterator itr = m_InvitedPlayers[team].begin(); itr != m_InvitedPlayers[team].end(); ++itr)
184 if (itr->second <= now)
185 KickPlayerFromBattlefield(itr->first);
186
188 for (int team = 0; team < 2; team++)
189 for (PlayerTimerMap::iterator itr = m_PlayersWillBeKick[team].begin(); itr != m_PlayersWillBeKick[team].end(); ++itr)
190 if (itr->second <= now)
191 KickPlayerFromBattlefield(itr->first);
192
194 }
195 else
197
198 for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
199 if ((*itr)->Update(diff))
200 objective_changed = true;
201 }
202
203 if (m_LastResurectTimer <= diff)
204 {
205 for (uint8 i = 0; i < m_GraveyardList.size(); i++)
206 if (GetGraveyardById(i))
207 m_GraveyardList[i]->Resurrect();
209 }
210 else
211 m_LastResurectTimer -= diff;
212
213 return objective_changed;
214}
#define sWorld
Definition: World.h:449
void EndBattle(bool endByTimer)
Definition: Battlefield.cpp:352
void InvitePlayersInZoneToQueue()
Invite all players in zone to join the queue, called x minutes before battle start in Update()
Definition: Battlefield.cpp:216
void KickPlayerFromBattlefield(ObjectGuid guid)
Kick player from battlefield and teleport him to kick-point location.
Definition: Battlefield.cpp:321
void StartBattle()
Definition: Battlefield.cpp:330
BfGraveyard * GetGraveyardById(uint32 id) const
Definition: Battlefield.cpp:576
void KickAfkPlayers()
Definition: Battlefield.cpp:311
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().