refactor(Core/Battlefield): remove Hungarian notation and modernize code (#25070)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Andrew 2026-03-13 19:32:06 -03:00 committed by GitHub
parent 077cb4e2de
commit 968a2363eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 765 additions and 844 deletions

File diff suppressed because it is too large Load diff

View file

@ -71,8 +71,8 @@ class Unit;
class Battlefield;
class BfGraveyard;
typedef std::vector<BfGraveyard*> GraveyardVect;
typedef std::map<ObjectGuid, time_t> PlayerTimerMap;
using GraveyardVect = std::vector<BfGraveyard*>;
using PlayerTimerMap = std::map<ObjectGuid, time_t>;
class BfCapturePoint
{
@ -92,7 +92,6 @@ public:
// Used when player is activated/inactivated in the area
virtual bool HandlePlayerEnter(Player* player);
virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player* player);
//virtual void HandlePlayerActivityChanged(Player* player);
// Checks if player is in range of a capture credit marker
bool IsInsideObjective(Player* player) const;
@ -102,70 +101,71 @@ public:
virtual void ChangeTeam(TeamId /*oldTeam*/) {}
virtual void SendChangePhase();
//Added team to reset capturepoints on sliders after warTime
// Added team to reset capturepoints on sliders after warTime
bool SetCapturePointData(GameObject* capturePoint, TeamId team);
GameObject* GetCapturePointGo();
GameObject* GetCapturePointGo(WorldObject* obj);
TeamId GetTeamId() { return m_team; }
TeamId GetTeamId() const { return Team; }
protected:
bool DelCapturePoint();
// active Players in the area of the objective, 0 - alliance, 1 - horde
GuidUnorderedSet m_activePlayers[2];
// Active players in the area of the objective, 0 - alliance, 1 - horde
GuidUnorderedSet ActivePlayers[2];
// Total shift needed to capture the objective
float m_maxValue;
float m_minValue;
float MaxValue;
float MinValue;
// Maximum speed of capture
float m_maxSpeed;
float MaxSpeed;
// The status of the objective
float m_value;
TeamId m_team;
float Value;
TeamId Team;
// Objective states
BattlefieldObjectiveStates m_OldState;
BattlefieldObjectiveStates m_State;
BattlefieldObjectiveStates OldState;
BattlefieldObjectiveStates State;
// Neutral value on capture bar
uint32 m_neutralValuePct;
uint32 NeutralValuePct;
// Pointer to the Battlefield this objective belongs to
Battlefield* m_Bf;
Battlefield* Bf;
// Capture point entry
uint32 m_capturePointEntry;
uint32 CapturePointEntry;
// Gameobject related to that capture point
ObjectGuid m_capturePoint;
ObjectGuid CapturePoint;
};
class BfGraveyard
{
public:
BfGraveyard(Battlefield* Bf);
BfGraveyard(Battlefield* bf);
virtual ~BfGraveyard() = default;
// Method to changing who controls the graveyard
void GiveControlTo(TeamId team);
TeamId GetControlTeamId() const { return m_ControlTeam; }
TeamId GetControlTeamId() const { return ControlTeam; }
// Find the nearest graveyard to a player
float GetDistance(Player* player);
// Initialize the graveyard
void Initialize(TeamId startcontrol, uint32 gy);
void Initialize(TeamId startControl, uint32 graveyardId);
// Set spirit service for the graveyard
void SetSpirit(Creature* spirit, TeamId team);
// Add a player to the graveyard
void AddPlayer(ObjectGuid player_guid);
void AddPlayer(ObjectGuid playerGuid);
// Remove a player from the graveyard
void RemovePlayer(ObjectGuid player_guid);
void RemovePlayer(ObjectGuid playerGuid);
// Resurrect players
void Resurrect();
@ -176,29 +176,24 @@ public:
// Check if this graveyard has a spirit guide
bool HasNpc(ObjectGuid guid)
{
if (!m_SpiritGuide[0] && !m_SpiritGuide[1])
if (!SpiritGuide[0] && !SpiritGuide[1])
return false;
// performance
/*if (!ObjectAccessor::FindUnit(m_SpiritGuide[0]) &&
!ObjectAccessor::FindUnit(m_SpiritGuide[1]))
return false;*/
return (m_SpiritGuide[0] == guid || m_SpiritGuide[1] == guid);
return (SpiritGuide[0] == guid || SpiritGuide[1] == guid);
}
// Check if a player is in this graveyard's resurrect queue
bool HasPlayer(ObjectGuid guid) const { return m_ResurrectQueue.find(guid) != m_ResurrectQueue.end(); }
bool HasPlayer(ObjectGuid guid) const { return ResurrectQueue.find(guid) != ResurrectQueue.end(); }
// Get the graveyard's ID.
uint32 GetGraveyardId() const { return m_GraveyardId; }
uint32 GetGraveyardId() const { return GraveyardId; }
protected:
TeamId m_ControlTeam;
uint32 m_GraveyardId;
ObjectGuid m_SpiritGuide[2];
GuidUnorderedSet m_ResurrectQueue;
Battlefield* m_Bf;
TeamId ControlTeam;
uint32 GraveyardId;
ObjectGuid SpiritGuide[2];
GuidUnorderedSet ResurrectQueue;
Battlefield* Bf;
};
class Battlefield : public ZoneScript
@ -211,8 +206,8 @@ public:
/// Destructor
~Battlefield() override;
/// typedef of map witch store capturepoint and the associate gameobject entry
typedef std::vector<BfCapturePoint*> BfCapturePointVector;
/// Vector of capture points belonging to this battlefield
using BfCapturePointVector = std::vector<BfCapturePoint*>;
/// Call this to init the Battlefield
virtual bool SetupBattlefield() { return true; }
@ -223,9 +218,9 @@ public:
/**
* \brief 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
* - Invite player in zone to queue StartGroupingTimer minutes before start
* - Kick Afk players
* \param diff : time ellapsed since last call (in ms)
* \param diff : time elapsed since last call (in ms)
*/
virtual bool Update(uint32 diff);
@ -236,56 +231,56 @@ public:
/// Invite all players in zone to join battle on battle start
void InvitePlayersInZoneToWar();
/// Called when a Unit is kill in battlefield zone
/// Called when a Unit is killed in battlefield zone
virtual void HandleKill(Player* /*killer*/, Unit* /*killed*/) {};
uint32 GetTypeId() { return m_TypeId; }
uint32 GetZoneId() { return m_ZoneId; }
uint32 GetTypeId() const { return TypeId; }
uint32 GetZoneId() const { return ZoneId; }
void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2 = 0);
/// Return true if battle is start, false if battle is not started
bool IsWarTime() { return m_isActive; }
/// Return true if battle is started, false if battle is not started
bool IsWarTime() const { return Active; }
/// Enable or Disable battlefield
void ToggleBattlefield(bool enable) { m_IsEnabled = enable; }
/// Return if battlefield is enable
bool IsEnabled() { return m_IsEnabled; }
void ToggleBattlefield(bool enable) { Enabled = enable; }
/// Return if battlefield is enabled
bool IsEnabled() const { return Enabled; }
/**
* \brief Kick player from battlefield and teleport him to kick-point location
* \param guid : guid of player who must be kick
* \param guid : guid of player who must be kicked
*/
void KickPlayerFromBattlefield(ObjectGuid guid);
/// Called when player (player) enter in zone
/// Called when player (player) enters the zone
void HandlePlayerEnterZone(Player* player, uint32 zone);
/// Called when player (player) leave the zone
/// Called when player (player) leaves the zone
void HandlePlayerLeaveZone(Player* player, uint32 zone);
// All-purpose data storage 64 bit
uint64 GetData64(uint32 dataId) const override { return m_Data64[dataId]; }
void SetData64(uint32 dataId, uint64 value) override { m_Data64[dataId] = value; }
uint64 GetData64(uint32 dataId) const override { return Data64[dataId]; }
void SetData64(uint32 dataId, uint64 value) override { Data64[dataId] = value; }
// All-purpose data storage 32 bit
uint32 GetData(uint32 dataId) const override { return m_Data32[dataId]; }
void SetData(uint32 dataId, uint32 value) override { m_Data32[dataId] = value; }
virtual void UpdateData(uint32 index, int32 pad) { m_Data32[index] += pad; }
uint32 GetData(uint32 dataId) const override { return Data32[dataId]; }
void SetData(uint32 dataId, uint32 value) override { Data32[dataId] = value; }
virtual void UpdateData(uint32 index, int32 pad) { Data32[index] += pad; }
// Battlefield - generic methods
TeamId GetDefenderTeam() { return m_DefenderTeam; }
TeamId GetAttackerTeam() { return TeamId(1 - m_DefenderTeam); }
TeamId GetOtherTeam(TeamId team) { return (team == TEAM_HORDE ? TEAM_ALLIANCE : TEAM_HORDE); }
void SetDefenderTeam(TeamId team) { m_DefenderTeam = team; }
TeamId GetDefenderTeam() const { return DefenderTeam; }
TeamId GetAttackerTeam() const { return TeamId(1 - DefenderTeam); }
TeamId GetOtherTeam(TeamId team) const { return (team == TEAM_HORDE ? TEAM_ALLIANCE : TEAM_HORDE); }
void SetDefenderTeam(TeamId team) { DefenderTeam = team; }
// Group methods
/**
* \brief Find a not full battlefield group, if there is no, create one
* \param TeamId : Id of player team for who we search a group (player->GetTeamId())
* \param teamId : Id of player team for who we search a group (player->GetTeamId())
*/
Group* GetFreeBfRaid(TeamId TeamId);
Group* GetFreeBfRaid(TeamId teamId);
/// Return battlefield group where player is.
Group* GetGroupPlayer(ObjectGuid guid, TeamId TeamId);
Group* GetGroupPlayer(ObjectGuid guid, TeamId teamId);
/// Force player to join a battlefield group
bool AddOrSetPlayerToCorrectBfGroup(Player* player);
@ -293,9 +288,9 @@ public:
// Find which graveyard the player must be teleported to to be resurrected by spiritguide
GraveyardStruct const* GetClosestGraveyard(Player* player);
virtual void AddPlayerToResurrectQueue(ObjectGuid npc_guid, ObjectGuid player_guid);
void RemovePlayerFromResurrectQueue(ObjectGuid player_guid);
void SetGraveyardNumber(uint32 number) { m_GraveyardList.resize(number); }
virtual void AddPlayerToResurrectQueue(ObjectGuid npcGuid, ObjectGuid playerGuid);
void RemovePlayerFromResurrectQueue(ObjectGuid playerGuid);
void SetGraveyardNumber(uint32 number) { GraveyardList.resize(number); }
BfGraveyard* GetGraveyardById(uint32 id) const;
// Misc methods
@ -312,36 +307,34 @@ public:
virtual void OnBattleStart() {};
/// Called at the end of battle
virtual void OnBattleEnd(bool /*endByTimer*/) {};
/// Called x minutes before battle start when player in zone are invite to join queue
/// Called x minutes before battle start when players in zone are invited to join queue
virtual void OnStartGrouping() {};
/// Called when a player accept to join the battle
/// Called when a player accepts to join the battle
virtual void OnPlayerJoinWar(Player* /*player*/) {};
/// Called when a player leave the battle
/// Called when a player leaves the battle
virtual void OnPlayerLeaveWar(Player* /*player*/) {};
/// Called when a player leave battlefield zone
/// Called when a player leaves the battlefield zone
virtual void OnPlayerLeaveZone(Player* /*player*/) {};
/// Called when a player enter in battlefield zone
/// Called when a player enters the battlefield zone
virtual void OnPlayerEnterZone(Player* /*player*/) {};
void SendWarning(uint8 id, WorldObject const* target = nullptr);
void PlayerAcceptInviteToQueue(Player* player);
void PlayerAcceptInviteToWar(Player* player);
uint32 GetBattleId() { return m_BattleId; }
uint32 GetBattleId() const { return BattleId; }
void AskToLeaveQueue(Player* player);
void PlayerAskToLeave(Player* player);
//virtual void DoCompleteOrIncrementAchievement(uint32 /*achievement*/, Player* /*player*/, uint8 /*incrementNumber = 1*/) {};
/// Send all worldstate data to all player in zone.
/// Send all worldstate data to all players in zone.
virtual void SendInitWorldStatesToAll() = 0;
virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates& /*packet*/) = 0;
virtual void SendUpdateWorldStates(Player* player = nullptr) = 0;
/// Return if we can use mount in battlefield
bool CanFlyIn() { return !m_isActive; }
bool CanFlyIn() const { return !Active; }
void SendAreaSpiritHealerQueryOpcode(Player* player, const ObjectGuid& guid);
void SendAreaSpiritHealerQueryOpcode(Player* player, ObjectGuid const& guid);
void StartBattle();
void EndBattle(bool endByTimer);
@ -349,27 +342,29 @@ public:
void HideNpc(Creature* creature);
void ShowNpc(Creature* creature, bool aggressive);
GraveyardVect GetGraveyardVector() { return m_GraveyardList; }
GraveyardVect const& GetGraveyardVector() const { return GraveyardList; }
uint32 GetTimer() { return m_Timer; }
void SetTimer(uint32 timer) { m_Timer = timer; }
uint32 GetTimer() const { return Timer; }
void SetTimer(uint32 timer) { Timer = timer; }
// Returns combined count of players in war + invited (per team) for balance checking
uint32 GetPlayersInWarCount(TeamId teamId) const { return static_cast<uint32>(m_PlayersInWar[teamId].size() + m_InvitedPlayers[teamId].size()); }
uint32 GetPlayersInWarCount(TeamId teamId) const { return static_cast<uint32>(PlayersInWar[teamId].size() + InvitedPlayers[teamId].size()); }
// Returns total count of players in the battlefield zone per team
uint32 GetPlayersInZoneCount(TeamId teamId) const { return static_cast<uint32>(m_players[teamId].size()); }
uint32 GetPlayersInZoneCount(TeamId teamId) const { return static_cast<uint32>(Players[teamId].size()); }
// Returns the maximum players allowed per team
uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayer; }
uint32 GetMaxPlayersPerTeam() const { return MaxPlayer; }
/// Returns true if there is still room for another player on the given team in the active war.
bool HasWarVacancy(TeamId teamId) const { return GetPlayersInWarCount(teamId) < MaxPlayer; }
/// Returns the set of players waiting in the pre-battle queue (per team, read-only).
GuidUnorderedSet const& GetPlayersQueueSet(TeamId teamId) const { return m_PlayersInQueue[teamId]; }
GuidUnorderedSet const& GetPlayersQueueSet(TeamId teamId) const { return PlayersInQueue[teamId]; }
/// Returns the map of players invited to join the active war, value is invite expiry
/// timestamp (per team, read-only).
PlayerTimerMap const& GetInvitedPlayersMap(TeamId teamId) const { return m_InvitedPlayers[teamId]; }
PlayerTimerMap const& GetInvitedPlayersMap(TeamId teamId) const { return InvitedPlayers[teamId]; }
/// Returns the set of players actively fighting in the war (per team, read-only).
GuidUnorderedSet const& GetPlayersInWarSet(TeamId teamId) const { return m_PlayersInWar[teamId]; }
GuidUnorderedSet const& GetPlayersInWarSet(TeamId teamId) const { return PlayersInWar[teamId]; }
void DoPlaySoundToAll(uint32 SoundID);
void DoPlaySoundToAll(uint32 soundId);
void InvitePlayerToQueue(Player* player);
void InvitePlayerToWar(Player* player);
@ -378,50 +373,50 @@ public:
protected:
ObjectGuid StalkerGuid;
uint32 m_Timer; // Global timer for event
bool m_IsEnabled;
bool m_isActive;
TeamId m_DefenderTeam;
uint32 Timer; // Global timer for event
bool Enabled;
bool Active;
TeamId DefenderTeam;
// Map of the objectives belonging to this OutdoorPvP
BfCapturePointVector m_capturePoints;
BfCapturePointVector CapturePoints;
// Players info maps
GuidUnorderedSet m_players[PVP_TEAMS_COUNT]; // Players in zone
GuidUnorderedSet m_PlayersInQueue[PVP_TEAMS_COUNT]; // Players in the queue
GuidUnorderedSet m_PlayersInWar[PVP_TEAMS_COUNT]; // Players in WG combat
PlayerTimerMap m_InvitedPlayers[PVP_TEAMS_COUNT];
PlayerTimerMap m_PlayersWillBeKick[PVP_TEAMS_COUNT];
GuidUnorderedSet Players[PVP_TEAMS_COUNT]; // Players in zone
GuidUnorderedSet PlayersInQueue[PVP_TEAMS_COUNT]; // Players in the queue
GuidUnorderedSet PlayersInWar[PVP_TEAMS_COUNT]; // Players in WG combat
PlayerTimerMap InvitedPlayers[PVP_TEAMS_COUNT];
PlayerTimerMap PlayersWillBeKick[PVP_TEAMS_COUNT];
// Variables that must exist for each battlefield
uint32 m_TypeId; // See enum BattlefieldTypes
uint32 m_BattleId; // BattleID (for packet)
uint32 m_ZoneId; // ZoneID of Wintergrasp = 4197
uint32 m_MapId; // MapId where is Battlefield
Map* m_Map;
uint32 m_MaxPlayer; // Maximum number of players per team that participated to Battlefield
uint32 m_MinPlayer; // Minimum number of players per team for Battlefield start
uint32 m_MinLevel; // Required level to participate at Battlefield
uint32 m_BattleTime; // Length of a battle
uint32 m_NoWarBattleTime; // Time between two battles
uint32 m_RestartAfterCrash; // Delay to restart Wintergrasp if the server crashed during a running battle.
uint32 m_TimeForAcceptInvite;
uint32 m_uiKickDontAcceptTimer;
uint32 TypeId; // See enum BattlefieldTypes
uint32 BattleId; // BattleID (for packet)
uint32 ZoneId; // ZoneID of Wintergrasp = 4197
uint32 MapId; // MapId where is Battlefield
Map* BfMap;
uint32 MaxPlayer; // Maximum number of players per team that participated to Battlefield
uint32 MinPlayer; // Minimum number of players per team for Battlefield start
uint32 MinLevel; // Required level to participate at Battlefield
uint32 BattleTime; // Length of a battle
uint32 NoWarBattleTime; // Time between two battles
uint32 RestartAfterCrash; // Delay to restart Wintergrasp if the server crashed during a running battle
uint32 TimeForAcceptInvite;
uint32 KickDontAcceptTimer;
WorldLocation KickPosition; // Position where players are teleported if they switch to afk during the battle or if they don't accept invitation
uint32 m_uiKickAfkPlayersTimer; // Timer for check Afk in war
uint32 KickAfkPlayersTimer; // Timer for check Afk in war
// Graveyard variables
GraveyardVect m_GraveyardList; // Vector witch contain the different GY of the battle
uint32 m_LastResurectTimer; // Timer for resurect player every 30 sec
GraveyardVect GraveyardList; // Vector which contains the different GY of the battle
uint32 LastResurrectTimer; // Timer for resurrect player every 30 sec
uint32 m_StartGroupingTimer; // Timer for invite players in area 15 minute before start battle
bool m_StartGrouping; // bool for know if all players in area has been invited
uint32 StartGroupingTimer; // Timer for invite players in area 15 minutes before start battle
bool StartGrouping; // bool for knowing if all players in area have been invited
GuidUnorderedSet m_Groups[PVP_TEAMS_COUNT]; // Contain different raid group
GuidUnorderedSet Groups[PVP_TEAMS_COUNT]; // Contains different raid groups
std::vector<uint64> m_Data64;
std::vector<uint32> m_Data32;
std::vector<uint64> Data64;
std::vector<uint32> Data32;
void KickAfkPlayers();
@ -434,11 +429,51 @@ protected:
void BroadcastPacketToWar(WorldPacket const* data) const;
// CapturePoint system
void AddCapturePoint(BfCapturePoint* cp) { m_capturePoints.push_back(cp); }
void AddCapturePoint(BfCapturePoint* cp) { CapturePoints.push_back(cp); }
void RegisterZone(uint32 zoneid);
void RegisterZone(uint32 zoneId);
bool HasPlayer(Player* player) const;
void TeamCastSpell(TeamId team, int32 spellId);
/// Returns true if the player is already tracked as actively in the war or invited to join it.
bool IsPlayerInWarOrInvited(Player* player) const;
// Player-iteration helpers: resolve each GUID to a live Player* and call fn(player).
// Using templates avoids std::function overhead and works naturally with lambdas.
template<typename Func>
void ForEachPlayerInZone(Func&& fn) const
{
for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
for (ObjectGuid const& guid : Players[team])
if (Player* player = ObjectAccessor::FindPlayer(guid))
fn(player);
}
template<typename Func>
void ForEachPlayerInQueue(Func&& fn) const
{
for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
for (ObjectGuid const& guid : PlayersInQueue[team])
if (Player* player = ObjectAccessor::FindPlayer(guid))
fn(player);
}
template<typename Func>
void ForEachPlayerInWar(Func&& fn) const
{
for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team)
for (ObjectGuid const& guid : PlayersInWar[team])
if (Player* player = ObjectAccessor::FindPlayer(guid))
fn(player);
}
template<typename Func>
void ForEachPlayerInWar(TeamId team, Func&& fn) const
{
for (ObjectGuid const& guid : PlayersInWar[team])
if (Player* player = ObjectAccessor::FindPlayer(guid))
fn(player);
}
};
#endif

View file

@ -24,125 +24,113 @@
#include "WorldPacket.h"
#include "WorldSession.h"
//This send to player windows for invite player to join the war
//Param1:(BattleId) the BattleId of Bf
//Param2:(ZoneId) the zone where the battle is (4197 for wg)
//Param3:(time) Time in second that the player have for accept
void WorldSession::SendBfInvitePlayerToWar(uint32 BattleId, uint32 ZoneId, uint32 p_time)
// Sends to player the window to invite them to join the war
// Param1:(battleId) the BattleId of Bf
// Param2:(zoneId) the zone where the battle is (4197 for wg)
// Param3:(time) Time in seconds that the player has to accept
void WorldSession::SendBfInvitePlayerToWar(uint32 battleId, uint32 zoneId, uint32 time)
{
//Send packet
WorldPacket data(SMSG_BATTLEFIELD_MGR_ENTRY_INVITE, 12);
data << uint32(BattleId);
data << uint32(ZoneId);
data << uint32((GameTime::GetGameTime().count() + p_time));
//Sending the packet to player
data << uint32(battleId);
data << uint32(zoneId);
data << uint32(GameTime::GetGameTime().count() + time);
SendPacket(&data);
}
//This send invitation to player to join the queue
//Param1:(BattleId) the BattleId of Bf
void WorldSession::SendBfInvitePlayerToQueue(uint32 BattleId)
// Sends invitation to player to join the queue
// Param1:(battleId) the BattleId of Bf
void WorldSession::SendBfInvitePlayerToQueue(uint32 battleId)
{
WorldPacket data(SMSG_BATTLEFIELD_MGR_QUEUE_INVITE, 5);
data << uint32(BattleId);
data << uint8(1); //warmup ? used ?
//Sending packet to player
data << uint32(battleId);
data << uint8(1); // warmup ? used ?
SendPacket(&data);
}
//This send packet for inform player that he join queue
//Param1:(BattleId) the BattleId of Bf
//Param2:(ZoneId) the zone where the battle is (4197 for wg)
//Param3:(CanQueue) if able to queue
//Param4:(Full) on log in is full
void WorldSession::SendBfQueueInviteResponse(uint32 BattleId, uint32 ZoneId, bool CanQueue, bool Full)
// Sends packet to inform player that they joined the queue
// Param1:(battleId) the BattleId of Bf
// Param2:(zoneId) the zone where the battle is (4197 for wg)
// Param3:(canQueue) if able to queue
// Param4:(full) on log in is full
void WorldSession::SendBfQueueInviteResponse(uint32 battleId, uint32 zoneId, bool canQueue, bool full)
{
WorldPacket data(SMSG_BATTLEFIELD_MGR_QUEUE_REQUEST_RESPONSE, 11);
data << uint32(BattleId);
data << uint32(ZoneId);
data << uint8((CanQueue ? 1 : 0)); //Accepted //0 you cannot queue wg //1 you are queued
data << uint8((Full ? 0 : 1)); //Logging In //0 wg full //1 queue for upcoming
data << uint32(battleId);
data << uint32(zoneId);
data << uint8((canQueue ? 1 : 0)); //Accepted //0 you cannot queue wg //1 you are queued
data << uint8((full ? 0 : 1)); //Logging In //0 wg full //1 queue for upcoming
data << uint8(1); //Warmup
SendPacket(&data);
}
//This is call when player accept to join war
//Param1:(BattleId) the BattleId of Bf
void WorldSession::SendBfEntered(uint32 BattleId)
// Called when player accepts to join war
// Param1:(battleId) the BattleId of Bf
void WorldSession::SendBfEntered(uint32 battleId)
{
// m_PlayerInWar[player->GetTeamId()].insert(player->GetGUID());
WorldPacket data(SMSG_BATTLEFIELD_MGR_ENTERED, 7);
data << uint32(BattleId);
data << uint8(1); //unk
data << uint8(1); //unk
data << uint8(_player->isAFK() ? 1 : 0); //Clear AFK
data << uint32(battleId);
data << uint8(1); // unk
data << uint8(1); // unk
data << uint8(_player->isAFK() ? 1 : 0); // Clear AFK
SendPacket(&data);
}
void WorldSession::SendBfLeaveMessage(uint32 BattleId, BFLeaveReason reason)
void WorldSession::SendBfLeaveMessage(uint32 battleId, BFLeaveReason reason)
{
WorldPacket data(SMSG_BATTLEFIELD_MGR_EJECTED, 7);
data << uint32(BattleId);
data << uint8(reason);//byte Reason
data << uint8(2);//byte BattleStatus
data << uint8(0);//bool Relocated
data << uint32(battleId);
data << uint8(reason); // byte Reason
data << uint8(2); // byte BattleStatus
data << uint8(0); // bool Relocated
SendPacket(&data);
}
//Send by client when he click on accept for queue
// Sent by client when they click accept for queue
void WorldSession::HandleBfQueueInviteResponse(WorldPacket& recvData)
{
uint32 BattleId;
uint8 Accepted;
uint32 battleId;
uint8 accepted;
recvData >> BattleId >> Accepted;
recvData >> battleId >> accepted;
Battlefield* Bf = sBattlefieldMgr->GetBattlefieldByBattleId(BattleId);
if (!Bf)
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
if (!bf)
return;
if (Accepted)
{
Bf->PlayerAcceptInviteToQueue(_player);
}
if (accepted)
bf->PlayerAcceptInviteToQueue(_player);
}
//Send by client on clicking in accept or refuse of invitation windows for join game
// Sent by client on clicking accept or refuse of invitation window to join game
void WorldSession::HandleBfEntryInviteResponse(WorldPacket& recvData)
{
uint32 BattleId;
uint8 Accepted;
uint32 battleId;
uint8 accepted;
recvData >> BattleId >> Accepted;
recvData >> battleId >> accepted;
Battlefield* Bf = sBattlefieldMgr->GetBattlefieldByBattleId(BattleId);
if (!Bf)
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
if (!bf)
return;
//If player accept invitation
if (Accepted)
{
Bf->PlayerAcceptInviteToWar(_player);
}
if (accepted)
bf->PlayerAcceptInviteToWar(_player);
else
{
if (_player->GetZoneId() == Bf->GetZoneId())
Bf->KickPlayerFromBattlefield(_player->GetGUID());
if (_player->GetZoneId() == bf->GetZoneId())
bf->KickPlayerFromBattlefield(_player->GetGUID());
}
}
void WorldSession::HandleBfExitRequest(WorldPacket& recvData)
{
uint32 BattleId;
uint32 battleId;
recvData >> BattleId;
recvData >> battleId;
Battlefield* Bf = sBattlefieldMgr->GetBattlefieldByBattleId(BattleId);
if (!Bf)
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
if (!bf)
return;
Bf->AskToLeaveQueue(_player);
bf->AskToLeaveQueue(_player);
}

View file

@ -19,17 +19,14 @@
#include "Player.h"
#include "Zones/BattlefieldWG.h"
BattlefieldMgr::BattlefieldMgr()
BattlefieldMgr::BattlefieldMgr() : _updateTimer(0)
{
m_UpdateTimer = 0;
//LOG_DEBUG("bg.battlefield", "Instantiating BattlefieldMgr");
}
BattlefieldMgr::~BattlefieldMgr()
{
//LOG_DEBUG("bg.battlefield", "Deleting BattlefieldMgr");
for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
delete *itr;
for (Battlefield* bf : _battlefieldSet)
delete bf;
}
BattlefieldMgr* BattlefieldMgr::instance()
@ -46,107 +43,89 @@ void BattlefieldMgr::InitBattlefield()
LOG_INFO("server.loading", " ");
return;
}
Battlefield* pBf = new BattlefieldWG;
Battlefield* bf = new BattlefieldWG;
// respawn, init variables
if (!pBf->SetupBattlefield())
if (!bf->SetupBattlefield())
{
LOG_ERROR("server.loading", "Battlefield: Wintergrasp init failed.");
LOG_INFO("server.loading", " ");
delete pBf;
delete bf;
}
else
{
m_BattlefieldSet.push_back(pBf);
_battlefieldSet.push_back(bf);
LOG_INFO("server.loading", "Battlefield: Wintergrasp successfully initiated.");
LOG_INFO("server.loading", " ");
}
/* For Cataclysm: Tol Barad
pBf = new BattlefieldTB;
// respawn, init variables
if (!pBf->SetupBattlefield())
{
LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad init failed.");
delete pBf;
}
else
{
m_BattlefieldSet.push_back(pBf);
LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad successfully initiated.");
} */
}
void BattlefieldMgr::AddZone(uint32 zoneid, Battlefield* handle)
void BattlefieldMgr::AddZone(uint32 zoneId, Battlefield* handle)
{
m_BattlefieldMap[zoneid] = handle;
_battlefieldMap[zoneId] = handle;
}
void BattlefieldMgr::HandlePlayerEnterZone(Player* player, uint32 zoneid)
void BattlefieldMgr::HandlePlayerEnterZone(Player* player, uint32 zoneId)
{
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
if (itr == m_BattlefieldMap.end())
auto itr = _battlefieldMap.find(zoneId);
if (itr == _battlefieldMap.end())
return;
if (itr->second->HasPlayer(player) || !itr->second->IsEnabled())
return;
itr->second->HandlePlayerEnterZone(player, zoneid);
itr->second->HandlePlayerEnterZone(player, zoneId);
LOG_DEBUG("bg.battlefield", "Player {} entered outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
}
void BattlefieldMgr::HandlePlayerLeaveZone(Player* player, uint32 zoneid)
void BattlefieldMgr::HandlePlayerLeaveZone(Player* player, uint32 zoneId)
{
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
if (itr == m_BattlefieldMap.end())
auto itr = _battlefieldMap.find(zoneId);
if (itr == _battlefieldMap.end())
return;
// teleport: remove once in removefromworld, once in updatezone
if (!itr->second->HasPlayer(player))
return;
itr->second->HandlePlayerLeaveZone(player, zoneid);
itr->second->HandlePlayerLeaveZone(player, zoneId);
LOG_DEBUG("bg.battlefield", "Player {} left outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
}
Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(uint32 zoneid)
Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(uint32 zoneId)
{
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
if (itr == m_BattlefieldMap.end())
{
// no handle for this zone, return
auto itr = _battlefieldMap.find(zoneId);
if (itr == _battlefieldMap.end())
return nullptr;
}
if (!itr->second->IsEnabled())
return nullptr;
return itr->second;
}
Battlefield* BattlefieldMgr::GetBattlefieldByBattleId(uint32 battleid)
Battlefield* BattlefieldMgr::GetBattlefieldByBattleId(uint32 battleId)
{
for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
{
if ((*itr)->GetBattleId() == battleid)
return (*itr);
}
for (Battlefield* bf : _battlefieldSet)
if (bf->GetBattleId() == battleId)
return bf;
return nullptr;
}
void BattlefieldMgr::Update(uint32 diff)
{
m_UpdateTimer += diff;
if (m_UpdateTimer > BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL)
_updateTimer += diff;
if (_updateTimer > BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL)
{
for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
//if ((*itr)->IsEnabled())
(*itr)->Update(m_UpdateTimer);
m_UpdateTimer = 0;
for (Battlefield* bf : _battlefieldSet)
bf->Update(_updateTimer);
_updateTimer = 0;
}
}
ZoneScript* BattlefieldMgr::GetZoneScript(uint32 zoneId)
{
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneId);
if (itr != m_BattlefieldMap.end())
auto itr = _battlefieldMap.find(zoneId);
if (itr != _battlefieldMap.end())
return itr->second;
else
return nullptr;
return nullptr;
}

View file

@ -30,48 +30,47 @@ struct GossipMenuItems;
class BattlefieldMgr
{
public:
// ctor
BattlefieldMgr();
// dtor
~BattlefieldMgr();
static BattlefieldMgr* instance();
// create battlefield events
void InitBattlefield();
// called when a player enters an battlefield area
// called when a player enters a battlefield area
void HandlePlayerEnterZone(Player* player, uint32 areaflag);
// called when player leaves an battlefield area
// called when player leaves a battlefield area
void HandlePlayerLeaveZone(Player* player, uint32 areaflag);
// called when player resurrects
void HandlePlayerResurrects(Player* player, uint32 areaflag);
// return assigned battlefield
Battlefield* GetBattlefieldToZoneId(uint32 zoneid);
Battlefield* GetBattlefieldByBattleId(uint32 battleid);
Battlefield* GetBattlefieldToZoneId(uint32 zoneId);
Battlefield* GetBattlefieldByBattleId(uint32 battleId);
ZoneScript* GetZoneScript(uint32 zoneId);
void AddZone(uint32 zoneid, Battlefield* handle);
void AddZone(uint32 zoneId, Battlefield* handle);
void Update(uint32 diff);
void HandleGossipOption(Player* player, ObjectGuid guid, uint32 gossipid);
void HandleGossipOption(Player* player, ObjectGuid guid, uint32 gossipId);
bool CanTalkTo(Player* player, Creature* creature, GossipMenuItems gso);
void HandleDropFlag(Player* player, uint32 spellId);
typedef std::vector < Battlefield* >BattlefieldSet;
typedef std::map < uint32 /* zoneid */, Battlefield* >BattlefieldMap;
using BattlefieldSet = std::vector<Battlefield*>;
using BattlefieldMap = std::map<uint32 /* zoneid */, Battlefield*>;
private:
// contains all initiated battlefield events
// used when initing / cleaning up
BattlefieldSet m_BattlefieldSet;
// maps the zone ids to an battlefield event
BattlefieldSet _battlefieldSet;
// maps the zone ids to a battlefield event
// used in player event handling
BattlefieldMap m_BattlefieldMap;
BattlefieldMap _battlefieldMap;
// update interval
uint32 m_UpdateTimer;
uint32 _updateTimer;
};
#define sBattlefieldMgr BattlefieldMgr::instance()

View file

@ -36,47 +36,48 @@
BattlefieldWG::~BattlefieldWG()
{
for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
delete *itr;
for (WGWorkshop* workshop : WorkshopsList)
delete workshop;
for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
delete *itr;
for (BfWGGameObjectBuilding* building : BuildingsInZone)
delete building;
}
bool BattlefieldWG::SetupBattlefield()
{
m_TypeId = BATTLEFIELD_WG; // See enum BattlefieldTypes
m_BattleId = BATTLEFIELD_BATTLEID_WG;
m_ZoneId = AREA_WINTERGRASP;
m_MapId = MAP_NORTHREND;
m_Map = sMapMgr->FindMap(m_MapId, 0);
TypeId = BATTLEFIELD_WG; // See enum BattlefieldTypes
BattleId = BATTLEFIELD_BATTLEID_WG;
ZoneId = AREA_WINTERGRASP;
MapId = MAP_NORTHREND;
BfMap = sMapMgr->FindMap(MapId, 0);
// init stalker AFTER setting map id... we spawn it at map=random memory value?...
InitStalker(BATTLEFIELD_WG_NPC_STALKER, WintergraspStalkerPos[0], WintergraspStalkerPos[1], WintergraspStalkerPos[2], WintergraspStalkerPos[3]);
m_MaxPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MAX);
m_IsEnabled = sWorld->getIntConfig(CONFIG_WINTERGRASP_ENABLE) == 1;
m_MinPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN);
m_MinLevel = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN_LVL);
m_BattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_BATTLETIME) * MINUTE * IN_MILLISECONDS;
m_NoWarBattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_NOBATTLETIME) * MINUTE * IN_MILLISECONDS;
m_RestartAfterCrash = sWorld->getIntConfig(CONFIG_WINTERGRASP_RESTART_AFTER_CRASH) * MINUTE * IN_MILLISECONDS;
MaxPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MAX);
Enabled = sWorld->getIntConfig(CONFIG_WINTERGRASP_ENABLE) == 1;
MinPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN);
MinLevel = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN_LVL);
BattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_BATTLETIME) * MINUTE * IN_MILLISECONDS;
NoWarBattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_NOBATTLETIME) * MINUTE * IN_MILLISECONDS;
RestartAfterCrash = sWorld->getIntConfig(CONFIG_WINTERGRASP_RESTART_AFTER_CRASH) * MINUTE * IN_MILLISECONDS;
m_TimeForAcceptInvite = 20;
m_StartGroupingTimer = 15 * MINUTE * IN_MILLISECONDS;
m_StartGrouping = false;
TimeForAcceptInvite = 20;
StartGroupingTimer = 15 * MINUTE * IN_MILLISECONDS;
StartGrouping = false;
m_tenacityStack = 0;
m_titansRelic.Clear();
TenacityStack = 0;
TitansRelic.Clear();
IsRelicInteractible = false;
KickPosition.Relocate(5728.117f, 2714.346f, 697.733f, 0);
KickPosition.m_mapId = m_MapId;
KickPosition.m_mapId = MapId;
RegisterZone(m_ZoneId);
RegisterZone(ZoneId);
m_Data32.resize(BATTLEFIELD_WG_DATA_MAX);
Data32.resize(BATTLEFIELD_WG_DATA_MAX);
m_saveTimer = 60000;
SaveTimer = 60000;
// Init Graveyards
SetGraveyardNumber(BATTLEFIELD_WG_GRAVEYARD_MAX);
@ -88,17 +89,17 @@ bool BattlefieldWG::SetupBattlefield()
{
sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, uint64(false));
sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER, uint64(urand(0, 1)));
sWorldState->setWorldState(ClockWorldState[0], uint64(m_NoWarBattleTime));
sWorldState->setWorldState(ClockWorldState[0], uint64(NoWarBattleTime));
}
m_isActive = bool(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE));
m_DefenderTeam = TeamId(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER));
Active = bool(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE));
DefenderTeam = TeamId(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER));
m_Timer = sWorldState->getWorldState(ClockWorldState[0]);
if (m_isActive)
Timer = sWorldState->getWorldState(ClockWorldState[0]);
if (Active)
{
m_isActive = false;
m_Timer = m_RestartAfterCrash;
Active = false;
Timer = RestartAfterCrash;
}
for (uint8 i = 0; i < BATTLEFIELD_WG_GRAVEYARD_MAX; i++)
@ -107,12 +108,12 @@ bool BattlefieldWG::SetupBattlefield()
// When between games, the graveyard is controlled by the defending team
if (WGGraveyard[i].startcontrol == TEAM_NEUTRAL)
graveyard->Initialize(WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SE || WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SW ? GetAttackerTeam() : m_DefenderTeam, WGGraveyard[i].gyid);
graveyard->Initialize(WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SE || WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SW ? GetAttackerTeam() : DefenderTeam, WGGraveyard[i].gyid);
else
graveyard->Initialize(WGGraveyard[i].startcontrol, WGGraveyard[i].gyid);
graveyard->SetTextId(WGGraveyard[i].textid);
m_GraveyardList[i] = graveyard;
GraveyardList[i] = graveyard;
}
// Spawn workshop creatures and gameobjects
@ -140,8 +141,8 @@ bool BattlefieldWG::SetupBattlefield()
}
// Hide NPCs from the Attacker's team in the keep
for (GuidUnorderedSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : KeepCreature[GetAttackerTeam()])
if (Creature* creature = GetCreature(guid))
HideNpc(creature);
// Spawn Horde NPCs outside the keep
@ -155,8 +156,8 @@ bool BattlefieldWG::SetupBattlefield()
OutsideCreature[TEAM_ALLIANCE].insert(creature->GetGUID());
// Hide units outside the keep that are defenders
for (GuidUnorderedSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : OutsideCreature[GetDefenderTeam()])
if (Creature* creature = GetCreature(guid))
HideNpc(creature);
// Spawn turrets and hide them per default
@ -193,32 +194,32 @@ bool BattlefieldWG::SetupBattlefield()
bool BattlefieldWG::Update(uint32 diff)
{
bool m_return = Battlefield::Update(diff);
if (m_saveTimer <= diff)
bool result = Battlefield::Update(diff);
if (SaveTimer <= diff)
{
sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, m_isActive);
sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER, m_DefenderTeam);
sWorldState->setWorldState(ClockWorldState[0], m_Timer);
m_saveTimer = 60 * IN_MILLISECONDS;
sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, Active);
sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER, DefenderTeam);
sWorldState->setWorldState(ClockWorldState[0], Timer);
SaveTimer = 60 * IN_MILLISECONDS;
}
else
m_saveTimer -= diff;
SaveTimer -= diff;
// Update Tenacity
if (IsWarTime())
{
if (m_tenacityUpdateTimer <= diff)
if (TenacityUpdateTimer <= diff)
{
m_tenacityUpdateTimer = 10000;
if (!m_updateTenacityList.empty())
TenacityUpdateTimer = 10000;
if (!UpdateTenacityList.empty())
UpdateTenacity();
m_updateTenacityList.clear();
UpdateTenacityList.clear();
}
else
m_tenacityUpdateTimer -= diff;
TenacityUpdateTimer -= diff;
}
return m_return;
return result;
}
void BattlefieldWG::OnBattleStart()
@ -233,15 +234,15 @@ void BattlefieldWG::OnBattleStart()
go->SetGameObjectFlag(GO_FLAG_NOT_SELECTABLE);
// save guid
m_titansRelic = go->GetGUID();
TitansRelic = go->GetGUID();
}
else
LOG_ERROR("bg.battlefield", "WG: Failed to spawn titan relic.");
// Update tower visibility and update faction
for (GuidUnorderedSet::const_iterator itr = CanonList.begin(); itr != CanonList.end(); ++itr)
for (ObjectGuid const& guid : CanonList)
{
if (Creature* creature = GetCreature(*itr))
if (Creature* creature = GetCreature(guid))
{
ShowNpc(creature, true);
creature->SetFaction(WintergraspFaction[GetDefenderTeam()]);
@ -249,12 +250,12 @@ void BattlefieldWG::OnBattleStart()
}
// Rebuild all wall
for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
for (BfWGGameObjectBuilding* building : BuildingsInZone)
{
if (*itr)
if (building)
{
(*itr)->Rebuild();
(*itr)->UpdateTurretAttack(false);
building->Rebuild();
building->UpdateTurretAttack(false);
}
}
@ -263,20 +264,20 @@ void BattlefieldWG::OnBattleStart()
SetData(BATTLEFIELD_WG_DATA_DAMAGED_TOWER_ATT, 0);
// Update graveyard (in no war time all graveyard is to deffender, in war time, depend of base)
for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
if (*itr)
(*itr)->UpdateGraveyardAndWorkshop();
for (WGWorkshop* workshop : WorkshopsList)
if (workshop)
workshop->UpdateGraveyardAndWorkshop();
// Set Sliders capture points data to his owners when battle start
for (BfCapturePointVector::const_iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr)
(*itr)->SetCapturePointData((*itr)->GetCapturePointGo(),
(*itr)->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SE || (*itr)->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SW ? GetAttackerTeam() : GetDefenderTeam());
for (BfCapturePoint* capturePoint : CapturePoints)
capturePoint->SetCapturePointData(capturePoint->GetCapturePointGo(),
capturePoint->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SE || capturePoint->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SW ? GetAttackerTeam() : GetDefenderTeam());
for (uint8 team = 0; team < 2; ++team)
for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
for (ObjectGuid const& guid : Players[team])
{
// Kick player in orb room, TODO: offline player ?
if (Player* player = ObjectAccessor::FindPlayer(*itr))
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
float x, y, z;
player->GetPosition(x, y, z);
@ -291,8 +292,8 @@ void BattlefieldWG::OnBattleStart()
SendWarning(BATTLEFIELD_WG_TEXT_START);
// Xinef: reset tenacity counter
m_tenacityStack = 0;
m_tenacityUpdateTimer = 20000;
TenacityStack = 0;
TenacityUpdateTimer = 20000;
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE))
ChatHandler(nullptr).SendWorldText(BATTLEFIELD_WG_WORLD_START_MESSAGE);
@ -308,9 +309,9 @@ void BattlefieldWG::UpdateCounterVehicle(bool init)
SetData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_H, 0);
SetData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_A, 0);
for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
for (WGWorkshop* workshop : WorkshopsList)
{
if (WGWorkshop* workshop = (*itr))
if (workshop)
{
if (workshop->teamControl == TEAM_ALLIANCE)
UpdateData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_A, 4);
@ -326,8 +327,8 @@ void BattlefieldWG::UpdateCounterVehicle(bool init)
void BattlefieldWG::UpdateVehicleCountWG()
{
for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
for (GuidUnorderedSet::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : Players[i])
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
player->SendUpdateWorldState(WORLD_STATE_BATTLEFIELD_WG_VEHICLE_H, GetData(BATTLEFIELD_WG_DATA_VEHICLE_H));
player->SendUpdateWorldState(WORLD_STATE_BATTLEFIELD_WG_MAX_VEHICLE_H, GetData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_H));
@ -339,8 +340,8 @@ void BattlefieldWG::UpdateVehicleCountWG()
void BattlefieldWG::CapturePointTaken(uint32 areaId)
{
for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
for (GuidUnorderedSet::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : Players[i])
if (Player* player = ObjectAccessor::FindPlayer(guid))
if (player->GetAreaId() == areaId)
player->UpdateAreaDependentAuras(areaId);
}
@ -351,12 +352,12 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
if (GameObject* go = GetRelic())
go->RemoveFromWorld();
m_titansRelic.Clear();
TitansRelic.Clear();
// Remove turret
for (GuidUnorderedSet::const_iterator itr = CanonList.begin(); itr != CanonList.end(); ++itr)
for (ObjectGuid const& guid : CanonList)
{
if (Creature* creature = GetCreature(*itr))
if (Creature* creature = GetCreature(guid))
{
if (!endByTimer)
creature->SetFaction(WintergraspFaction[GetDefenderTeam()]);
@ -365,21 +366,21 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
}
// Change all npc in keep
for (GuidUnorderedSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : KeepCreature[GetAttackerTeam()])
if (Creature* creature = GetCreature(guid))
HideNpc(creature);
for (GuidUnorderedSet::const_iterator itr = KeepCreature[GetDefenderTeam()].begin(); itr != KeepCreature[GetDefenderTeam()].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : KeepCreature[GetDefenderTeam()])
if (Creature* creature = GetCreature(guid))
ShowNpc(creature, true);
// Change all npc out of keep
for (GuidUnorderedSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : OutsideCreature[GetDefenderTeam()])
if (Creature* creature = GetCreature(guid))
HideNpc(creature);
for (GuidUnorderedSet::const_iterator itr = OutsideCreature[GetAttackerTeam()].begin(); itr != OutsideCreature[GetAttackerTeam()].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : OutsideCreature[GetAttackerTeam()])
if (Creature* creature = GetCreature(guid))
ShowNpc(creature, true);
// Update all graveyard, control is to defender when no wartime
@ -387,37 +388,37 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
if (BfGraveyard* graveyard = GetGraveyardById(i))
graveyard->GiveControlTo(i == BATTLEFIELD_WG_GY_WORKSHOP_SE || i == BATTLEFIELD_WG_GY_WORKSHOP_SW ? GetAttackerTeam() : GetDefenderTeam());
for (GameObjectSet::const_iterator itr = m_KeepGameObject[GetDefenderTeam()].begin(); itr != m_KeepGameObject[GetDefenderTeam()].end(); ++itr)
(*itr)->SetRespawnTime(RESPAWN_IMMEDIATELY);
for (GameObject* go : KeepGameObject[GetDefenderTeam()])
go->SetRespawnTime(RESPAWN_IMMEDIATELY);
for (GameObjectSet::const_iterator itr = m_KeepGameObject[GetAttackerTeam()].begin(); itr != m_KeepGameObject[GetAttackerTeam()].end(); ++itr)
(*itr)->SetRespawnTime(RESPAWN_ONE_DAY);
for (GameObject* go : KeepGameObject[GetAttackerTeam()])
go->SetRespawnTime(RESPAWN_ONE_DAY);
// Update portal defender faction
for (GameObjectSet::const_iterator itr = DefenderPortalList.begin(); itr != DefenderPortalList.end(); ++itr)
(*itr)->SetUInt32Value(GAMEOBJECT_FACTION, WintergraspFaction[GetDefenderTeam()]);
for (GameObject* go : DefenderPortalList)
go->SetUInt32Value(GAMEOBJECT_FACTION, WintergraspFaction[GetDefenderTeam()]);
// Saving data
for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
for (BfWGGameObjectBuilding* building : BuildingsInZone)
{
(*itr)->Rebuild();
(*itr)->Save();
(*itr)->UpdateTurretAttack(true);
building->Rebuild();
building->Save();
building->UpdateTurretAttack(true);
}
for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
for (WGWorkshop* workshop : WorkshopsList)
{
(*itr)->GiveControlTo((*itr)->workshopId == BATTLEFIELD_WG_WORKSHOP_SE || (*itr)->workshopId == BATTLEFIELD_WG_WORKSHOP_SW ? GetAttackerTeam() : GetDefenderTeam(), true);
(*itr)->Save();
workshop->GiveControlTo(workshop->workshopId == BATTLEFIELD_WG_WORKSHOP_SE || workshop->workshopId == BATTLEFIELD_WG_WORKSHOP_SW ? GetAttackerTeam() : GetDefenderTeam(), true);
workshop->Save();
}
for (uint8 team = 0; team < 2; ++team)
{
for (GuidUnorderedSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : Vehicles[team])
if (Creature* creature = GetCreature(guid))
creature->DespawnOrUnsummon(1ms);
m_vehicles[team].clear();
Vehicles[team].clear();
}
uint8 damagedTowersDef = GetData(BATTLEFIELD_WG_DATA_DAMAGED_TOWER_ATT);
@ -439,9 +440,9 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
spellFullAtt = SPELL_DESTROYED_TOWER;
}
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr)
for (ObjectGuid const& guid : PlayersInWar[GetDefenderTeam()])
{
if (Player* player = ObjectAccessor::FindPlayer(*itr))
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
// Victory in Wintergrasp
player->AreaExploredOrEventHappens(GetDefenderTeam() ? 13183 : 13181); // HORDE / ALLY win wg quest id
@ -457,8 +458,8 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
}
}
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()])
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
player->CastSpell(player, SPELL_DEFEAT_REWARD, true);
RemoveAurasFromPlayer(player);
@ -473,20 +474,20 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
{
for (uint8 team = 0; team < 2; ++team)
{
for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
for (ObjectGuid const& guid : Players[team])
{
if (Player* player = ObjectAccessor::FindPlayer(*itr))
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
player->RemoveAurasDueToSpell(m_DefenderTeam == TEAM_ALLIANCE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player->GetGUID());
player->AddAura(m_DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player);
player->RemoveAurasDueToSpell(DefenderTeam == TEAM_ALLIANCE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player->GetGUID());
player->AddAura(DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player);
}
}
}
}
// Clear players in war list at the end.
m_PlayersInWar[TEAM_ALLIANCE].clear();
m_PlayersInWar[TEAM_HORDE].clear();
PlayersInWar[TEAM_ALLIANCE].clear();
PlayersInWar[TEAM_HORDE].clear();
if (!endByTimer) // win alli/horde
{
@ -504,10 +505,6 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer)
}
}
// *******************************************************
// ******************* Reward System *********************
// *******************************************************
void BattlefieldWG::OnStartGrouping()
{
if (!IsWarTime())
@ -571,8 +568,8 @@ void BattlefieldWG::OnCreatureCreate(Creature* creature)
if (creature->IsWithinDist2d(5103.0f, 3461.5f, 5.0f))
graveyardId = BATTLEFIELD_WG_GY_WORKSHOP_NW;
if (m_GraveyardList[graveyardId])
m_GraveyardList[graveyardId]->SetSpirit(creature, teamId);
if (GraveyardList[graveyardId])
GraveyardList[graveyardId]->SetSpirit(creature, teamId);
break;
}
}
@ -601,7 +598,7 @@ void BattlefieldWG::OnCreatureCreate(Creature* creature)
{
UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_H, 1);
creature->CastSpell(creature, SPELL_HORDE_FLAG, true);
m_vehicles[team].insert(creature->GetGUID());
Vehicles[team].insert(creature->GetGUID());
UpdateVehicleCountWG();
}
else
@ -616,7 +613,7 @@ void BattlefieldWG::OnCreatureCreate(Creature* creature)
{
UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_A, 1);
creature->CastSpell(creature, SPELL_ALLIANCE_FLAG, true);
m_vehicles[team].insert(creature->GetGUID());
Vehicles[team].insert(creature->GetGUID());
UpdateVehicleCountWG();
}
else
@ -661,7 +658,7 @@ void BattlefieldWG::OnCreatureRemove(Creature* /*creature*/)
else
return;
m_vehicles[team].erase(creature->GetGUID());
Vehicles[team].erase(creature->GetGUID());
if (team == TEAM_HORDE)
UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_H, -1);
else
@ -696,9 +693,9 @@ void BattlefieldWG::OnGameObjectCreate(GameObject* go)
return;
}
for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
for (WGWorkshop* workshop : WorkshopsList)
{
if (WGWorkshop* workshop = (*itr))
if (workshop)
{
if (workshop->workshopId == workshopId)
{
@ -729,7 +726,7 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim)
if (victim->IsPlayer() && victim->HasAura(SPELL_LIEUTENANT))
{
// Quest - Wintergrasp - PvP Kill - Horde/Alliance
for (auto& playerGuid : m_PlayersInWar[killerTeam])
for (ObjectGuid const& playerGuid : PlayersInWar[killerTeam])
{
if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
{
@ -741,7 +738,7 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim)
}
}
for (auto& playerGuid : m_PlayersInWar[killerTeam])
for (ObjectGuid const& playerGuid : PlayersInWar[killerTeam])
{
if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
{
@ -761,7 +758,7 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim)
else if (victim->IsVehicle() && !killer->IsFriendlyTo(victim))
{
// Quest - Wintergrasp - PvP Kill - Vehicle
for (auto& playerGuid : m_PlayersInWar[killerTeam])
for (ObjectGuid const& playerGuid : PlayersInWar[killerTeam])
{
if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
{
@ -776,12 +773,12 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim)
bool BattlefieldWG::FindAndRemoveVehicleFromList(Unit* vehicle)
{
for (uint32 itr = 0; itr < 2; ++itr)
for (uint32 i = 0; i < 2; ++i)
{
if (m_vehicles[itr].find(vehicle->GetGUID()) != m_vehicles[itr].end())
if (Vehicles[i].find(vehicle->GetGUID()) != Vehicles[i].end())
{
//m_vehicles[itr].erase(vehicle->GetGUID());
if (itr == TEAM_HORDE)
//Vehicles[i].erase(vehicle->GetGUID());
if (i == TEAM_HORDE)
UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_H, -1);
else
UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_A, -1);
@ -802,7 +799,7 @@ void BattlefieldWG::OnUnitDeath(Unit* unit)
// Update rank for player
void BattlefieldWG::PromotePlayer(Player* killer)
{
if (!m_isActive)
if (!Active)
return;
// Updating rank of player
if (Aura* recruitAura = killer->GetAura(SPELL_RECRUIT))
@ -890,7 +887,7 @@ void BattlefieldWG::OnPlayerLeaveWar(Player* player)
void BattlefieldWG::OnPlayerLeaveZone(Player* player)
{
if (!m_isActive)
if (!Active)
RemoveAurasFromPlayer(player);
player->RemoveAurasDueToSpell(SPELL_HORDE_CONTROLS_FACTORY_PHASE_SHIFT);
@ -901,10 +898,10 @@ void BattlefieldWG::OnPlayerLeaveZone(Player* player)
void BattlefieldWG::OnPlayerEnterZone(Player* player)
{
if (!m_isActive)
if (!Active)
RemoveAurasFromPlayer(player);
player->AddAura(m_DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player);
player->AddAura(DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player);
// Send worldstate to player
SendInitWorldStatesTo(player);
@ -949,7 +946,7 @@ void BattlefieldWG::FillInitialWorldStates(WorldPackets::WorldState::InitWorldSt
// Note: cleanup these two, their names look awkward
packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, IsWarTime() ? 0 : 1);
packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_SHOW, IsWarTime() ? 1 : 0);
packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_CONTROL, m_DefenderTeam == TEAM_ALLIANCE ? 2 : 1); // Alliance 2, Hord 1
packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_CONTROL, DefenderTeam == TEAM_ALLIANCE ? 2 : 1); // Alliance 2, Hord 1
packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_ICON_ACTIVE, iconActive ? 1 : 0);
for (uint32 i = 0; i < 2; ++i)
@ -965,19 +962,19 @@ void BattlefieldWG::FillInitialWorldStates(WorldPackets::WorldState::InitWorldSt
packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_HORDE_KEEP_DEFENDED, uint32(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_HORDE_KEEP_DEFENDED)));
packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_ALLIANCE_KEEP_CAPTURED, uint32(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_ALLIANCE_KEEP_CAPTURED)));
for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
packet.Worldstates.emplace_back((*itr)->m_WorldState, (*itr)->m_State);
for (BfWGGameObjectBuilding* building : BuildingsInZone)
packet.Worldstates.emplace_back(building->m_WorldState, building->m_State);
for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr)
if (*itr)
packet.Worldstates.emplace_back(WorkshopsData[(*itr)->workshopId].worldstate, (*itr)->state);
for (WGWorkshop* workshop : WorkshopsList)
if (workshop)
packet.Worldstates.emplace_back(WorkshopsData[workshop->workshopId].worldstate, workshop->state);
}
void BattlefieldWG::SendInitWorldStatesTo(Player* player)
{
WorldPackets::WorldState::InitWorldStates packet;
packet.MapID = m_MapId;
packet.ZoneID = m_ZoneId;
packet.MapID = MapId;
packet.ZoneID = ZoneId;
packet.AreaID = player->GetAreaId();
FillInitialWorldStates(packet);
@ -987,8 +984,8 @@ void BattlefieldWG::SendInitWorldStatesTo(Player* player)
void BattlefieldWG::SendInitWorldStatesToAll()
{
for (uint8 team = 0; team < 2; team++)
for (GuidUnorderedSet::iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : Players[team])
if (Player* player = ObjectAccessor::FindPlayer(guid))
SendInitWorldStatesTo(player);
}
@ -1025,9 +1022,9 @@ void BattlefieldWG::BrokenWallOrTower(TeamId /*team*/)
// might be some use for this in the future. old code commented out below. KL
/* if (team == GetDefenderTeam())
{
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr)
for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()])
{
if (Player* player = ObjectAccessor::FindPlayer(*itr))
if (Player* player = ObjectAccessor::FindPlayer(guid))
IncrementQuest(player, WGQuest[player->GetTeamId()][2], true);
}
}*/
@ -1044,13 +1041,13 @@ void BattlefieldWG::UpdatedDestroyedTowerCount(TeamId team, GameObject* go)
UpdateData(BATTLEFIELD_WG_DATA_BROKEN_TOWER_ATT, 1);
// Remove buff stack on attackers
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()])
if (Player* player = ObjectAccessor::FindPlayer(guid))
player->RemoveAuraFromStack(SPELL_TOWER_CONTROL);
// Add buff stack to defenders
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : PlayersInWar[GetDefenderTeam()])
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
// Quest - Wintergrasp - Southern Tower Kill
if (go && player->GetDistance2d(go) < 200.0f)
@ -1063,18 +1060,18 @@ void BattlefieldWG::UpdatedDestroyedTowerCount(TeamId team, GameObject* go)
// If all three south towers are destroyed (ie. all attack towers), remove ten minutes from battle time
if (GetData(BATTLEFIELD_WG_DATA_BROKEN_TOWER_ATT) == 3)
{
if (int32(m_Timer - 600000) < 0)
m_Timer = 0;
if (int32(Timer - 600000) < 0)
Timer = 0;
else
m_Timer -= 600000;
Timer -= 600000;
SendInitWorldStatesToAll();
}
}
else
{
// Xinef: rest of structures, quest credit
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()])
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
// Quest - Wintergrasp - Vehicle Protected
if (go && player->GetDistance2d(go) < 100.0f)
@ -1107,17 +1104,17 @@ void BattlefieldWG::ProcessEvent(WorldObject* obj, uint32 eventId)
}
// if destroy or damage event, search the wall/tower and update worldstate/send warning message
for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr)
for (BfWGGameObjectBuilding* building : BuildingsInZone)
{
if (GameObject* build = ObjectAccessor::GetGameObject(*obj, (*itr)->m_Build))
if (GameObject* build = ObjectAccessor::GetGameObject(*obj, building->m_Build))
{
if (go->GetEntry() == build->GetEntry())
{
if (build->GetGOInfo()->building.damagedEvent == eventId)
(*itr)->Damaged();
building->Damaged();
if (build->GetGOInfo()->building.destroyedEvent == eventId)
(*itr)->Destroyed();
building->Destroyed();
break;
}
@ -1148,20 +1145,20 @@ uint32 BattlefieldWG::GetHonorBuff(int32 stack) const
void BattlefieldWG::AddUpdateTenacity(Player* player)
{
m_updateTenacityList.insert(player->GetGUID());
UpdateTenacityList.insert(player->GetGUID());
}
void BattlefieldWG::RemoveUpdateTenacity(Player* player)
{
m_updateTenacityList.erase(player->GetGUID());
m_updateTenacityList.insert(ObjectGuid::Empty);
UpdateTenacityList.erase(player->GetGUID());
UpdateTenacityList.insert(ObjectGuid::Empty);
}
void BattlefieldWG::UpdateTenacity()
{
TeamId team = TEAM_NEUTRAL;
uint32 alliancePlayers = m_PlayersInWar[TEAM_ALLIANCE].size();
uint32 hordePlayers = m_PlayersInWar[TEAM_HORDE].size();
uint32 alliancePlayers = PlayersInWar[TEAM_ALLIANCE].size();
uint32 hordePlayers = PlayersInWar[TEAM_HORDE].size();
int32 newStack = 0;
if (alliancePlayers && hordePlayers)
@ -1173,11 +1170,11 @@ void BattlefieldWG::UpdateTenacity()
}
// Return if no change in stack and apply tenacity to new player
if (newStack == m_tenacityStack)
if (newStack == TenacityStack)
{
for (GuidUnorderedSet::const_iterator itr = m_updateTenacityList.begin(); itr != m_updateTenacityList.end(); ++itr)
if (Player* newPlayer = ObjectAccessor::FindPlayer(*itr))
if ((newPlayer->GetTeamId() == TEAM_ALLIANCE && m_tenacityStack > 0) || (newPlayer->GetTeamId() == TEAM_HORDE && m_tenacityStack < 0))
for (ObjectGuid const& guid : UpdateTenacityList)
if (Player* newPlayer = ObjectAccessor::FindPlayer(guid))
if ((newPlayer->GetTeamId() == TEAM_ALLIANCE && TenacityStack > 0) || (newPlayer->GetTeamId() == TEAM_HORDE && TenacityStack < 0))
{
newStack = std::min(std::abs(newStack), 20);
uint32 buff_honor = GetHonorBuff(newStack);
@ -1188,24 +1185,24 @@ void BattlefieldWG::UpdateTenacity()
return;
}
if (m_tenacityStack != 0)
if (TenacityStack != 0)
{
if (m_tenacityStack > 0 && newStack <= 0) // old buff was on alliance
if (TenacityStack > 0 && newStack <= 0) // old buff was on alliance
team = TEAM_ALLIANCE;
else if (m_tenacityStack < 0 && newStack >= 0) // old buff was on horde
else if (TenacityStack < 0 && newStack >= 0) // old buff was on horde
team = TEAM_HORDE;
}
m_tenacityStack = newStack;
TenacityStack = newStack;
// Remove old buff
if (team != TEAM_NEUTRAL)
{
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : PlayersInWar[team])
if (Player* player = ObjectAccessor::FindPlayer(guid))
player->RemoveAurasDueToSpell(SPELL_TENACITY);
for (GuidUnorderedSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : Vehicles[team])
if (Creature* creature = GetCreature(guid))
creature->RemoveAurasDueToSpell(SPELL_TENACITY_VEHICLE);
}
@ -1216,16 +1213,16 @@ void BattlefieldWG::UpdateTenacity()
newStack = std::min(std::abs(newStack), 20);
uint32 buff_honor = GetHonorBuff(newStack);
for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
for (ObjectGuid const& guid : PlayersInWar[team])
if (Player* player = ObjectAccessor::FindPlayer(guid))
{
player->SetAuraStack(SPELL_TENACITY, player, newStack);
if (buff_honor)
player->CastSpell(player, buff_honor, true);
}
for (GuidUnorderedSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr)
if (Creature* creature = GetCreature(*itr))
for (ObjectGuid const& guid : Vehicles[team])
if (Creature* creature = GetCreature(guid))
{
creature->SetAuraStack(SPELL_TENACITY_VEHICLE, creature, newStack);
if (buff_honor)
@ -1236,19 +1233,19 @@ void BattlefieldWG::UpdateTenacity()
WintergraspCapturePoint::WintergraspCapturePoint(BattlefieldWG* battlefield, TeamId teamInControl) : BfCapturePoint(battlefield)
{
m_Bf = battlefield;
m_team = teamInControl;
m_Workshop = nullptr;
Bf = battlefield;
Team = teamInControl;
LinkedWorkshop = nullptr;
}
void WintergraspCapturePoint::ChangeTeam(TeamId /*oldTeam*/)
{
ASSERT(m_Workshop);
m_Workshop->GiveControlTo(m_team, false);
ASSERT(LinkedWorkshop);
LinkedWorkshop->GiveControlTo(Team, false);
}
BfGraveyardWG::BfGraveyardWG(BattlefieldWG* battlefield) : BfGraveyard(battlefield)
{
m_Bf = battlefield;
m_GossipTextId = 0;
Bf = battlefield;
GossipTextId = 0;
}

View file

@ -32,11 +32,11 @@ class WintergraspCapturePoint;
struct BfWGGameObjectBuilding;
struct WGWorkshop;
typedef std::set<GameObject*> GameObjectSet;
typedef std::set<BfWGGameObjectBuilding*> GameObjectBuilding;
typedef std::set<WGWorkshop*> Workshop;
typedef std::set<Group*> GroupSet;
//typedef std::set<WintergraspCapturePoint *> CapturePointSet; unused ?
using GameObjectSet = std::set<GameObject*>;
using GameObjectBuilding = std::set<BfWGGameObjectBuilding*>;
using Workshop = std::set<WGWorkshop*>;
using GroupSet = std::set<Group*>;
//using CapturePointSet = std::set<WintergraspCapturePoint*>; unused ?
uint32 const VehNumWorldState[2] = { WORLD_STATE_BATTLEFIELD_WG_VEHICLE_A, WORLD_STATE_BATTLEFIELD_WG_VEHICLE_H };
uint32 const MaxVehNumWorldState[2] = { WORLD_STATE_BATTLEFIELD_WG_MAX_VEHICLE_A, WORLD_STATE_BATTLEFIELD_WG_MAX_VEHICLE_H };
@ -110,10 +110,10 @@ class BfGraveyardWG : public BfGraveyard
public:
BfGraveyardWG(BattlefieldWG* Bf);
void SetTextId(uint32 textid) { m_GossipTextId = textid; }
uint32 GetTextId() { return m_GossipTextId; }
void SetTextId(uint32 textid) { GossipTextId = textid; }
uint32 GetTextId() const { return GossipTextId; }
protected:
uint32 m_GossipTextId;
uint32 GossipTextId;
};
enum WGGraveyardId
@ -236,13 +236,13 @@ class WintergraspCapturePoint : public BfCapturePoint
public:
WintergraspCapturePoint(BattlefieldWG* battlefield, TeamId teamInControl);
void LinkToWorkshop(WGWorkshop* workshop) { m_Workshop = workshop; }
void LinkToWorkshop(WGWorkshop* workshop) { LinkedWorkshop = workshop; }
void ChangeTeam(TeamId oldteam) override;
TeamId GetTeam() const { return m_team; }
TeamId GetTeam() const { return Team; }
protected:
WGWorkshop* m_Workshop;
WGWorkshop* LinkedWorkshop;
};
/* ######################### *
@ -363,16 +363,16 @@ public:
bool SetupBattlefield() override;
/// Return pointer to relic object
GameObject* GetRelic() { return GetGameObject(m_titansRelic); }
GameObject* GetRelic() { return GetGameObject(TitansRelic); }
/// Define relic object
//void SetRelic(GameObject* relic) { m_titansRelic = relic; }
//void SetRelic(GameObject* relic) { TitansRelic = relic; }
/// Check if players can interact with the relic (Only if the last door has been broken)
bool CanInteractWithRelic() { return m_isRelicInteractible; }
bool CanInteractWithRelic() { return IsRelicInteractible; }
/// Define if player can interact with the relic
void SetRelicInteractible(bool allow) { m_isRelicInteractible = allow; }
void SetRelicInteractible(bool allow) { IsRelicInteractible = allow; }
/// Vehicle world states update
void UpdateCounterVehicle(bool init);
@ -434,25 +434,25 @@ public:
return false;
}
protected:
bool m_isRelicInteractible;
bool IsRelicInteractible;
Workshop WorkshopsList;
GameObjectSet DefenderPortalList;
GameObjectSet m_KeepGameObject[2];
GameObjectSet KeepGameObject[2];
GameObjectBuilding BuildingsInZone;
GuidUnorderedSet m_vehicles[2];
GuidUnorderedSet Vehicles[2];
GuidUnorderedSet CanonList;
GuidUnorderedSet KeepCreature[2];
GuidUnorderedSet OutsideCreature[2];
GuidUnorderedSet m_updateTenacityList;
GuidUnorderedSet UpdateTenacityList;
int32 m_tenacityStack;
uint32 m_tenacityUpdateTimer;
uint32 m_saveTimer;
int32 TenacityStack;
uint32 TenacityUpdateTimer;
uint32 SaveTimer;
ObjectGuid m_titansRelic;
ObjectGuid TitansRelic;
};
uint8 const WG_MAX_OBJ = 32;
@ -558,10 +558,7 @@ struct WintergraspObjectPositionData
uint32 entryAlliance;
};
// *****************************************************
// ************ Destructible (Wall,Tower..) ************
// *****************************************************
// Destructible buildings (walls, towers, etc.)
struct WintergraspBuildingSpawnData
{
uint32 entry;
@ -748,10 +745,7 @@ WintergraspTeleporterData const WGPortalDefenderData[WG_MAX_TELEPORTER] =
{ 192951, 5316.25f, 2977.04f, 408.539f, -0.820f },
};
// *********************************************************
// **********Tower Element(GameObject,Creature)*************
// *********************************************************
// Tower elements (GameObjects and Creatures)
struct WintergraspTowerData
{
uint32 towerEntry; // Gameobject id of tower
@ -1022,10 +1016,7 @@ WintergraspTowerCannonData const TowerCannon[WG_MAX_TOWER_CANNON] =
},
};
// *********************************************************
// *****************WorkShop Data & Element*****************
// *********************************************************
// Workshop data and elements
uint8 const WG_MAX_WORKSHOP = 6;
struct WGWorkshopData
@ -1052,10 +1043,9 @@ WGWorkshopData const WorkshopsData[WG_MAX_WORKSHOP] =
{BATTLEFIELD_WG_WORKSHOP_KEEP_EAST, WORLD_STATE_BATTLEFIELD_WG_WORKSHOP_K_E, 0, BATTLEFIELD_WG_TEXT_WORKSHOP_NE_TAKEN}
};
// ********************************************************************
// * Structs using for Building,Graveyard,Workshop *
// ********************************************************************
// Structure for different buildings that can be destroyed during battle
// Structs for Building, Graveyard, and Workshop runtime objects
// Buildings that can be destroyed during battle
struct BfWGGameObjectBuilding
{
BfWGGameObjectBuilding(BattlefieldWG* WG)