TrinityCore
Loading...
Searching...
No Matches
Battlefield.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef BATTLEFIELD_H_
19#define BATTLEFIELD_H_
20
21#include "Position.h"
22#include "SharedDefines.h"
23#include "ZoneScript.h"
24#include <map>
25
27{
28 BATTLEFIELD_WG = 1, // Wintergrasp
30};
31
33{
34 BATTLEFIELD_BATTLEID_WG = 1 // Wintergrasp battle
35};
36
47
54
59
60namespace WorldPackets
61{
62 namespace WorldState
63 {
64 class InitWorldStates;
65 }
66}
67
68// some class predefs
69class Battlefield;
70class BfGraveyard;
71class Creature;
72class GameObject;
73class Group;
74class Map;
75class Player;
76class Unit;
77class WorldPacket;
78
79struct QuaternionData;
81
82typedef std::vector<BfGraveyard*> GraveyardVect;
83typedef std::map<ObjectGuid, time_t> PlayerTimerMap;
84
86{
87 public:
88 explicit BfCapturePoint(Battlefield* bf);
93
94 virtual ~BfCapturePoint();
95
97
98 // Send world state update to all players present
99 void SendUpdateWorldState(uint32 field, uint32 value);
100
101 // Send kill notify to players in the controlling faction
102 void SendObjectiveComplete(uint32 id, ObjectGuid guid);
103
104 // Used when player is activated/inactivated in the area
105 virtual bool HandlePlayerEnter(Player* player);
106 virtual GuidSet::iterator HandlePlayerLeave(Player* player);
107 //virtual void HandlePlayerActivityChanged(Player* player);
108
109 // Checks if player is in range of a capture credit marker
110 bool IsInsideObjective(Player* player) const;
111
112 // Returns true if the state of the objective has changed, in this case, the OutdoorPvP must send a world state ui update.
113 virtual bool Update(uint32 diff);
114 virtual void ChangeTeam(TeamId /*oldTeam*/) { }
115 virtual void SendChangePhase();
116
117 bool SetCapturePointData(GameObject* capturePoint);
118 GameObject* GetCapturePointGo();
119 uint32 GetCapturePointEntry() const { return m_capturePointEntry; }
120
121 TeamId GetTeamId() const { return m_team; }
122
123 protected:
124 bool DelCapturePoint();
125
126 // active Players in the area of the objective, 0 - alliance, 1 - horde
127 GuidSet m_activePlayers[PVP_TEAMS_COUNT];
128
129 // Total shift needed to capture the objective
132
133 // Maximum speed of capture
135
136 // The status of the objective
137 float m_value;
139
140 // Objective states
143
144 // Neutral value on capture bar
146
147 // Pointer to the Battlefield this objective belongs to
149
150 // Capture point entry
152
153 // Gameobject related to that capture point
155};
156
158{
159 public:
160 explicit BfGraveyard(Battlefield* bf);
161 BfGraveyard(BfGraveyard const&) = delete;
165
166 virtual ~BfGraveyard();
167
168 // Method to changing who controls the graveyard
169 void GiveControlTo(TeamId team);
170 TeamId GetControlTeamId() const { return m_ControlTeam; }
171
172 // Find the nearest graveyard to a player
173 float GetDistance(Player* player);
174
175 // Initialize the graveyard
176 void Initialize(TeamId startcontrol, uint32 gy);
177
178 // Set spirit service for the graveyard
179 void SetSpirit(Creature* spirit, TeamId team);
180
181 // Add a player to the graveyard
182 void AddPlayer(ObjectGuid player_guid);
183
184 // Remove a player from the graveyard
185 void RemovePlayer(ObjectGuid player_guid);
186
187 // Resurrect players
188 void Resurrect();
189
190 // Move players waiting to that graveyard on the nearest one
191 void RelocateDeadPlayers();
192
193 // Check if this graveyard has a spirit guide
194 bool HasNpc(ObjectGuid guid);
195
196 // Check if a player is in this graveyard's resurrect queue
197 bool HasPlayer(ObjectGuid guid) { return m_ResurrectQueue.find(guid) != m_ResurrectQueue.end(); }
198
199 // Get the graveyard's ID.
200 uint32 GetGraveyardId() const { return m_GraveyardId; }
201
202 protected:
208};
209
211{
212 friend class BattlefieldMgr;
213
214 public:
216 Battlefield();
217 Battlefield(Battlefield const&) = delete;
221
223 virtual ~Battlefield();
224
226 typedef std::map<ObjectGuid::LowType /*lowguid */, BfCapturePoint*> BfCapturePointMap;
227
229 virtual bool SetupBattlefield() { return true; }
230
231 void SendInitWorldStatesTo(Player* player);
232
234 void SendUpdateWorldState(uint32 variable, uint32 value);
235
243 virtual bool Update(uint32 diff);
244
246 void InvitePlayersInZoneToQueue();
248 void InvitePlayersInQueueToWar();
250 void InvitePlayersInZoneToWar();
251
253 virtual void HandleKill(Player* /*killer*/, Unit* /*killed*/) { };
254
255 uint32 GetTypeId() const { return m_TypeId; }
256 uint32 GetZoneId() const { return m_ZoneId; }
257
258 void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2 = 0);
259
261 bool IsWarTime() const { return m_isActive; }
262
264 void ToggleBattlefield(bool enable) { m_IsEnabled = enable; }
266 bool IsEnabled() const { return m_IsEnabled; }
267
272 void KickPlayerFromBattlefield(ObjectGuid guid);
273
275 void HandlePlayerEnterZone(Player* player, uint32 zone);
277 void HandlePlayerLeaveZone(Player* player, uint32 zone);
278
279 // All-purpose data storage 64 bit
280 virtual uint64 GetData64(uint32 dataId) const override { return m_Data64[dataId]; }
281 virtual void SetData64(uint32 dataId, uint64 value) override { m_Data64[dataId] = value; }
282
283 // All-purpose data storage 32 bit
284 virtual uint32 GetData(uint32 dataId) const override { return m_Data32[dataId]; }
285 virtual void SetData(uint32 dataId, uint32 value) override { m_Data32[dataId] = value; }
286 virtual void UpdateData(uint32 index, int32 pad) { m_Data32[index] += pad; }
287
288 // Battlefield - generic methods
289 TeamId GetDefenderTeam() const { return m_DefenderTeam; }
290 TeamId GetAttackerTeam() const { return TeamId(1 - m_DefenderTeam); }
291 TeamId GetOtherTeam(TeamId team) const { return (team == TEAM_HORDE ? TEAM_ALLIANCE : TEAM_HORDE); }
292 void SetDefenderTeam(TeamId team) { m_DefenderTeam = team; }
293
294 // Group methods
299 Group* GetFreeBfRaid(TeamId TeamId);
301 Group* GetGroupPlayer(ObjectGuid guid, TeamId TeamId);
303 bool AddOrSetPlayerToCorrectBfGroup(Player* player);
304
305 // Graveyard methods
306 // Find which graveyard the player must be teleported to to be resurrected by spiritguide
307 WorldSafeLocsEntry const* GetClosestGraveyard(Player* player);
308
309 virtual void AddPlayerToResurrectQueue(ObjectGuid npc_guid, ObjectGuid player_guid);
310 void RemovePlayerFromResurrectQueue(ObjectGuid player_guid);
311 void SetGraveyardNumber(uint32 number) { m_GraveyardList.resize(number); }
312 BfGraveyard* GetGraveyardById(uint32 id) const;
313
314 // Misc methods
315 Creature* SpawnCreature(uint32 entry, Position const& pos);
316 GameObject* SpawnGameObject(uint32 entry, Position const& pos, QuaternionData const& rot);
317
318 Creature* GetCreature(ObjectGuid guid);
319 GameObject* GetGameObject(ObjectGuid guid);
320
321 // Script-methods
322
324 virtual void OnBattleStart() { }
326 virtual void OnBattleEnd(bool /*endByTimer*/) { }
328 virtual void OnStartGrouping() { }
330 virtual void OnPlayerJoinWar(Player* /*player*/) { }
332 virtual void OnPlayerLeaveWar(Player* /*player*/) { }
334 virtual void OnPlayerLeaveZone(Player* /*player*/) { }
336 virtual void OnPlayerEnterZone(Player* /*player*/) { }
337
338 void SendWarning(uint8 id, WorldObject const* target = nullptr);
339
340 void PlayerAcceptInviteToQueue(Player* player);
341 void PlayerAcceptInviteToWar(Player* player);
342 uint32 GetBattleId() const { return m_BattleId; }
343 void AskToLeaveQueue(Player* player);
344 void PlayerAskToLeave(Player* player);
345
346 virtual void DoCompleteOrIncrementAchievement(uint32 /*achievement*/, Player* /*player*/, uint8 /*incrementNumber = 1*/) { }
347
349 virtual void SendInitWorldStatesToAll() = 0;
351
353 bool CanFlyIn() { return !m_isActive; }
354
355 void SendAreaSpiritHealerQueryOpcode(Player* player, ObjectGuid guid);
356
357 void StartBattle();
358 void EndBattle(bool endByTimer);
359
360 void HideNpc(Creature* creature);
361 void ShowNpc(Creature* creature, bool aggressive);
362
363 GraveyardVect GetGraveyardVector() const { return m_GraveyardList; }
364
365 uint32 GetTimer() const { return m_Timer; }
366 void SetTimer(uint32 timer) { m_Timer = timer; }
367
368 void DoPlaySoundToAll(uint32 soundID);
369
370 void InvitePlayerToQueue(Player* player);
371 void InvitePlayerToWar(Player* player);
372
373 void InitStalker(uint32 entry, Position const& pos);
374
375 protected:
377 uint32 m_Timer; // Global timer for event
381
382 // Map of the objectives belonging to this OutdoorPvP
384
385 // Players info maps
386 GuidUnorderedSet m_players[PVP_TEAMS_COUNT]; // Players in zone
387 GuidUnorderedSet m_PlayersInQueue[PVP_TEAMS_COUNT]; // Players in the queue
388 GuidUnorderedSet m_PlayersInWar[PVP_TEAMS_COUNT]; // Players in WG combat
390 PlayerTimerMap m_PlayersWillBeKick[PVP_TEAMS_COUNT];
391
392 // Variables that must exist for each battlefield
393 uint32 m_TypeId; // See enum BattlefieldTypes
394 uint32 m_BattleId; // BattleID (for packet)
395 uint32 m_ZoneId; // ZoneID of Wintergrasp = 4197
396 uint32 m_MapId; // MapId where is Battlefield
398 uint32 m_MaxPlayer; // Maximum number of player that participated to Battlefield
399 uint32 m_MinPlayer; // Minimum number of player for Battlefield start
400 uint32 m_MinLevel; // Required level to participate at Battlefield
401 uint32 m_BattleTime; // Length of a battle
402 uint32 m_NoWarBattleTime; // Time between two battles
403 uint32 m_RestartAfterCrash; // Delay to restart Wintergrasp if the server crashed during a running battle.
406 WorldLocation KickPosition; // Position where players are teleported if they switch to afk during the battle or if they don't accept invitation
407
408 uint32 m_uiKickAfkPlayersTimer; // Timer for check Afk in war
409
410 // Graveyard variables
411 GraveyardVect m_GraveyardList; // Vector witch contain the different GY of the battle
412 uint32 m_LastResurrectTimer; // Timer for resurrect player every 30 sec
413
414 uint32 m_StartGroupingTimer; // Timer for invite players in area 15 minute before start battle
415 bool m_StartGrouping; // bool for know if all players in area has been invited
416
417 GuidUnorderedSet m_Groups[PVP_TEAMS_COUNT]; // Contain different raid group
418
419 std::vector<uint64> m_Data64;
420 std::vector<uint32> m_Data32;
421
422 void KickAfkPlayers();
423
424 // use for switch off all worldstate for client
425 virtual void SendRemoveWorldStates(Player* /*player*/) { }
426
427 // use for send a packet for all player list
428 void BroadcastPacketToZone(WorldPacket const* data) const;
429 void BroadcastPacketToQueue(WorldPacket const* data) const;
430 void BroadcastPacketToWar(WorldPacket const* data) const;
431
432 // CapturePoint system
433 void AddCapturePoint(BfCapturePoint* cp) { m_capturePoints[cp->GetCapturePointEntry()] = cp; }
434
436 {
437 Battlefield::BfCapturePointMap::const_iterator itr = m_capturePoints.find(lowguid);
438 if (itr != m_capturePoints.end())
439 return itr->second;
440 return nullptr;
441 }
442
443 void RegisterZone(uint32 zoneid);
444 bool HasPlayer(Player* player) const;
445 void TeamCastSpell(TeamId team, int32 spellId);
446};
447
448#endif
std::map< ObjectGuid, time_t > PlayerTimerMap
Definition Battlefield.h:83
std::vector< BfGraveyard * > GraveyardVect
Definition Battlefield.h:82
BattlefieldTypes
Definition Battlefield.h:27
@ BATTLEFIELD_WG
Definition Battlefield.h:28
@ BATTLEFIELD_MAX
Definition Battlefield.h:29
BattlefieldSounds
Definition Battlefield.h:49
@ BF_SOUND_HORDE_WINS
Definition Battlefield.h:50
@ BF_SOUND_ALLIANCE_WINS
Definition Battlefield.h:51
@ BF_SOUND_START
Definition Battlefield.h:52
BattlefieldTimers
Definition Battlefield.h:56
@ BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition Battlefield.h:57
BattlefieldObjectiveStates
Definition Battlefield.h:38
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE
Definition Battlefield.h:43
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE
Definition Battlefield.h:42
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE
Definition Battlefield.h:41
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE
Definition Battlefield.h:44
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE
Definition Battlefield.h:40
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE
Definition Battlefield.h:45
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition Battlefield.h:39
BattlefieldIDs
Definition Battlefield.h:33
@ BATTLEFIELD_BATTLEID_WG
Definition Battlefield.h:34
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint64_t uint64
Definition Define.h:132
uint32_t uint32
Definition Define.h:133
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:263
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:260
TeamId
@ TEAM_ALLIANCE
@ TEAM_HORDE
uint8 constexpr PVP_TEAMS_COUNT
WorldState
void Resurrect(Creature *target)
uint32 m_Timer
uint32 m_MapId
GraveyardVect m_GraveyardList
Battlefield(Battlefield const &)=delete
uint32 GetBattleId() const
std::map< ObjectGuid::LowType, BfCapturePoint * > BfCapturePointMap
typedef of map witch store capturepoint and the associate gameobject entry
virtual uint64 GetData64(uint32 dataId) const override
void AddCapturePoint(BfCapturePoint *cp)
Battlefield & operator=(Battlefield &&)=delete
uint32 m_MaxPlayer
std::vector< uint32 > m_Data32
void SetTimer(uint32 timer)
ObjectGuid StalkerGuid
uint32 m_NoWarBattleTime
virtual void SendInitWorldStatesToAll()=0
Send all worldstate data to all player in zone.
virtual void OnBattleEnd(bool)
Called at the end of battle.
virtual void SetData(uint32 dataId, uint32 value) override
Battlefield(Battlefield &&)=delete
uint32 m_BattleTime
uint32 GetZoneId() const
bool IsWarTime() const
Return true if battle is start, false if battle is not started.
uint32 m_ZoneId
virtual void UpdateData(uint32 index, int32 pad)
uint32 m_TypeId
uint32 m_BattleId
GraveyardVect GetGraveyardVector() const
virtual void DoCompleteOrIncrementAchievement(uint32, Player *, uint8)
virtual bool SetupBattlefield()
Call this to init the Battlefield.
virtual void SendRemoveWorldStates(Player *)
uint32 m_StartGroupingTimer
virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates &)=0
void SetDefenderTeam(TeamId team)
TeamId m_DefenderTeam
uint32 m_uiKickAfkPlayersTimer
virtual void OnPlayerJoinWar(Player *)
Called when a player accept to join the battle.
uint32 m_TimeForAcceptInvite
std::vector< uint64 > m_Data64
virtual void OnBattleStart()
Called on start.
virtual void SetData64(uint32 dataId, uint64 value) override
Battlefield & operator=(Battlefield const &)=delete
uint32 m_RestartAfterCrash
TeamId GetAttackerTeam() const
uint32 m_MinLevel
virtual void HandleKill(Player *, Unit *)
Called when a Unit is kill in battlefield zone.
bool CanFlyIn()
Return if we can use mount in battlefield.
TeamId GetDefenderTeam() const
uint32 m_MinPlayer
uint32 GetTimer() const
virtual uint32 GetData(uint32 dataId) const override
uint32 m_LastResurrectTimer
virtual void OnPlayerLeaveZone(Player *)
Called when a player leave battlefield zone.
BfCapturePoint * GetCapturePoint(ObjectGuid::LowType lowguid) const
BfCapturePointMap m_capturePoints
uint32 m_uiKickDontAcceptTimer
void ToggleBattlefield(bool enable)
Enable or Disable battlefield.
virtual void OnStartGrouping()
Called x minutes before battle start when player in zone are invite to join queue.
bool m_StartGrouping
WorldLocation KickPosition
virtual void OnPlayerLeaveWar(Player *)
Called when a player leave the battle.
void SetGraveyardNumber(uint32 number)
void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2=0)
TeamId GetOtherTeam(TeamId team) const
bool IsEnabled() const
Return if battlefield is enable.
virtual void OnPlayerEnterZone(Player *)
Called when a player enter in battlefield zone.
uint32 GetTypeId() const
virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates &)
Definition Battlefield.h:96
uint32 GetCapturePointEntry() const
Battlefield * m_Bf
BattlefieldObjectiveStates m_OldState
virtual void ChangeTeam(TeamId)
TeamId GetTeamId() const
BfCapturePoint(BfCapturePoint const &)=delete
BfCapturePoint & operator=(BfCapturePoint &&)=delete
BfCapturePoint & operator=(BfCapturePoint const &)=delete
uint32 m_capturePointEntry
ObjectGuid m_capturePointGUID
uint32 m_neutralValuePct
BattlefieldObjectiveStates m_State
virtual ~BfCapturePoint()
BfCapturePoint(BfCapturePoint &&)=delete
bool HasPlayer(ObjectGuid guid)
GuidSet m_ResurrectQueue
virtual ~BfGraveyard()
BfGraveyard(BfGraveyard const &)=delete
BfGraveyard(BfGraveyard &&)=delete
BfGraveyard & operator=(BfGraveyard const &)=delete
uint32 m_GraveyardId
Battlefield * m_Bf
BfGraveyard & operator=(BfGraveyard &&)=delete
TeamId m_ControlTeam
TeamId GetControlTeamId() const
uint32 GetGraveyardId() const
Definition Group.h:165
Definition Map.h:281
uint32 LowType
Definition ObjectGuid.h:142
Definition Unit.h:769