TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Battlefield.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 "SharedDefines.h"
22 #include "ZoneScript.h"
24 
26 {
27  BATTLEFIELD_WG, // Wintergrasp
28  BATTLEFIELD_TB // Tol Barad (cataclysm)
29 };
30 
32 {
33  BATTLEFIELD_BATTLEID_WG = 1, // Wintergrasp battle
34  BATTLEFIELD_BATTLEID_TB = 21, // Tol Barad
36 };
37 
39 {
43 };
44 
46 {
54 };
55 
57 {
61 };
62 
64 {
66 };
67 
68 // some class predefs
69 class Player;
70 class GameObject;
71 class WorldPacket;
72 class Creature;
73 class Unit;
74 
75 class Battlefield;
77 
78 typedef std::vector<BfGraveyard*> GraveyardVect;
79 typedef std::map<ObjectGuid, time_t> PlayerTimerMap;
80 
82 {
83  public:
85 
86  virtual ~BfCapturePoint() { }
87 
89 
90  // Send world state update to all players present
91  void SendUpdateWorldState(uint32 field, uint32 value);
92 
93  // Send kill notify to players in the controlling faction
94  void SendObjectiveComplete(uint32 id, ObjectGuid guid);
95 
96  // Used when player is activated/inactivated in the area
97  virtual bool HandlePlayerEnter(Player* player);
98  virtual GuidSet::iterator HandlePlayerLeave(Player* player);
99  //virtual void HandlePlayerActivityChanged(Player* player);
100 
101  // Checks if player is in range of a capture credit marker
102  bool IsInsideObjective(Player* player) const;
103 
104  // Returns true if the state of the objective has changed, in this case, the OutdoorPvP must send a world state ui update.
105  virtual bool Update(uint32 diff);
106  virtual void ChangeTeam(TeamId /*oldTeam*/) { }
107  virtual void SendChangePhase();
108 
109  bool SetCapturePointData(GameObject* capturePoint);
110  GameObject* GetCapturePointGo();
111  uint32 GetCapturePointEntry() const { return m_capturePointEntry; }
112 
113  TeamId GetTeamId() const { return m_team; }
114 
115  protected:
116  bool DelCapturePoint();
117 
118  // active Players in the area of the objective, 0 - alliance, 1 - horde
119  GuidSet m_activePlayers[BG_TEAMS_COUNT];
120 
121  // Total shift needed to capture the objective
122  float m_maxValue;
123  float m_minValue;
124 
125  // Maximum speed of capture
126  float m_maxSpeed;
127 
128  // The status of the objective
129  float m_value;
131 
132  // Objective states
135 
136  // Neutral value on capture bar
138 
139  // Pointer to the Battlefield this objective belongs to
141 
142  // Capture point entry
144 
145  // Gameobject related to that capture point
147 };
148 
150 {
151  public:
153 
154  // Method to changing who controls the graveyard
155  void GiveControlTo(TeamId team);
156  TeamId GetControlTeamId() const { return m_ControlTeam; }
157 
158  // Find the nearest graveyard to a player
159  float GetDistance(Player* player);
160 
161  // Initialize the graveyard
162  void Initialize(TeamId startcontrol, uint32 gy);
163 
164  // Set spirit service for the graveyard
165  void SetSpirit(Creature* spirit, TeamId team);
166 
167  // Add a player to the graveyard
168  void AddPlayer(ObjectGuid player_guid);
169 
170  // Remove a player from the graveyard
171  void RemovePlayer(ObjectGuid player_guid);
172 
173  // Resurrect players
174  void Resurrect();
175 
176  // Move players waiting to that graveyard on the nearest one
177  void RelocateDeadPlayers();
178 
179  // Check if this graveyard has a spirit guide
180  bool HasNpc(ObjectGuid guid);
181 
182  // Check if a player is in this graveyard's resurrect queue
183  bool HasPlayer(ObjectGuid guid) { return m_ResurrectQueue.find(guid) != m_ResurrectQueue.end(); }
184 
185  // Get the graveyard's ID.
186  uint32 GetGraveyardId() const { return m_GraveyardId; }
187 
188  protected:
191  ObjectGuid m_SpiritGuide[BG_TEAMS_COUNT];
194 };
195 
197 {
198  friend class BattlefieldMgr;
199 
200  public:
202  Battlefield();
204  virtual ~Battlefield();
205 
207  typedef std::map<uint32 /*lowguid */, BfCapturePoint*> BfCapturePointMap;
208 
210  virtual bool SetupBattlefield() { return true; }
211 
213  void SendUpdateWorldState(uint32 variable, uint32 value, bool hidden = false);
214 
222  virtual bool Update(uint32 diff);
223 
225  void InvitePlayersInZoneToQueue();
227  void InvitePlayersInQueueToWar();
229  void InvitePlayersInZoneToWar();
230 
232  virtual void HandleKill(Player* /*killer*/, Unit* /*killed*/) { };
233 
234  uint32 GetTypeId() const { return m_TypeId; }
235  uint32 GetZoneId() const { return m_ZoneId; }
236  uint64 GetQueueId() const { return MAKE_PAIR64(m_BattleId | 0x20000, 0x1F100000); }
237 
238  void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2 = 0);
239 
241  bool IsWarTime() const { return m_isActive; }
242 
243  int8 GetState() const { return m_isActive ? BATTLEFIELD_IN_PROGRESS : (m_Timer <= m_StartGroupingTimer ? BATTLEFIELD_WARMUP : BATTLEFIELD_INACTIVE); }
244 
246  void ToggleBattlefield(bool enable) { m_IsEnabled = enable; }
248  bool IsEnabled() const { return m_IsEnabled; }
249 
254  void KickPlayerFromBattlefield(ObjectGuid guid);
255 
257  void HandlePlayerEnterZone(Player* player, uint32 zone);
259  void HandlePlayerLeaveZone(Player* player, uint32 zone);
260 
261  // All-purpose data storage 64 bit
262  virtual uint64 GetData64(uint32 dataId) const override { return m_Data64[dataId]; }
263  virtual void SetData64(uint32 dataId, uint64 value) override { m_Data64[dataId] = value; }
264 
265  // All-purpose data storage 32 bit
266  virtual uint32 GetData(uint32 dataId) const override { return m_Data32[dataId]; }
267  virtual void SetData(uint32 dataId, uint32 value) override { m_Data32[dataId] = value; }
268  virtual void UpdateData(uint32 index, int32 pad) { m_Data32[index] += pad; }
269 
270  // Battlefield - generic methods
271  TeamId GetDefenderTeam() const { return m_DefenderTeam; }
272  TeamId GetAttackerTeam() const { return TeamId(1 - m_DefenderTeam); }
273  TeamId GetOtherTeam(TeamId team) const { return (team == TEAM_HORDE ? TEAM_ALLIANCE : TEAM_HORDE); }
274  void SetDefenderTeam(TeamId team) { m_DefenderTeam = team; }
275 
276  // Group methods
281  Group* GetFreeBfRaid(TeamId TeamId);
283  Group* GetGroupPlayer(ObjectGuid guid, TeamId TeamId);
285  bool AddOrSetPlayerToCorrectBfGroup(Player* player);
286 
287  // Graveyard methods
288  // Find which graveyard the player must be teleported to to be resurrected by spiritguide
289  WorldSafeLocsEntry const* GetClosestGraveYard(Player* player);
290 
291  virtual void AddPlayerToResurrectQueue(ObjectGuid npc_guid, ObjectGuid player_guid);
292  void RemovePlayerFromResurrectQueue(ObjectGuid player_guid);
293  void SetGraveyardNumber(uint32 number) { m_GraveyardList.resize(number); }
294  BfGraveyard* GetGraveyardById(uint32 id) const;
295 
296  // Misc methods
297  virtual Creature* SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId /*teamId*/);
298  Creature* SpawnCreature(uint32 entry, Position const& pos, TeamId /*teamId*/);
299  GameObject* SpawnGameObject(uint32 entry, float x, float y, float z, float o);
300 
303 
304  // Script-methods
305 
307  virtual void OnBattleStart() { }
309  virtual void OnBattleEnd(bool /*endByTimer*/) { }
311  virtual void OnStartGrouping() { }
313  virtual void OnPlayerJoinWar(Player* /*player*/) { }
315  virtual void OnPlayerLeaveWar(Player* /*player*/) { }
317  virtual void OnPlayerLeaveZone(Player* /*player*/) { }
319  virtual void OnPlayerEnterZone(Player* /*player*/) { }
320 
321  void SendWarning(uint8 id, WorldObject const* target = nullptr);
322 
323  void PlayerAcceptInviteToQueue(Player* player);
324  void PlayerAcceptInviteToWar(Player* player);
325  uint32 GetBattleId() const { return m_BattleId; }
326  void AskToLeaveQueue(Player* player);
327 
328  virtual void DoCompleteOrIncrementAchievement(uint32 /*achievement*/, Player* /*player*/, uint8 /*incrementNumber = 1*/) { }
329 
331  virtual void SendInitWorldStatesToAll() = 0;
332  virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates& /*packet*/) = 0;
333 
335  bool CanFlyIn() { return !m_isActive; }
336 
337  void SendAreaSpiritHealerQueryOpcode(Player* player, ObjectGuid const& guid);
338 
339  void StartBattle();
340  void EndBattle(bool endByTimer);
341 
342  void HideNpc(Creature* creature);
343  void ShowNpc(Creature* creature, bool aggressive);
344 
345  GraveyardVect GetGraveyardVector() const { return m_GraveyardList; }
346 
347  uint32 GetTimer() const { return m_Timer; }
348  void SetTimer(uint32 timer) { m_Timer = timer; }
349 
350  void DoPlaySoundToAll(uint32 SoundID);
351 
352  void InvitePlayerToQueue(Player* player);
353  void InvitePlayerToWar(Player* player);
354 
355  void InitStalker(uint32 entry, Position const& pos);
356 
357  protected:
359  uint32 m_Timer; // Global timer for event
363 
364  // Map of the objectives belonging to this OutdoorPvP
365  BfCapturePointMap m_capturePoints;
366 
367  // Players info maps
368  GuidSet m_players[BG_TEAMS_COUNT]; // Players in zone
369  GuidSet m_PlayersInQueue[BG_TEAMS_COUNT]; // Players in the queue
370  GuidSet m_PlayersInWar[BG_TEAMS_COUNT]; // Players in WG combat
371  PlayerTimerMap m_InvitedPlayers[BG_TEAMS_COUNT];
372  PlayerTimerMap m_PlayersWillBeKick[BG_TEAMS_COUNT];
373 
374  // Variables that must exist for each battlefield
375  uint32 m_TypeId; // See enum BattlefieldTypes
376  uint32 m_BattleId; // BattleID (for packet)
377  uint32 m_ZoneId; // ZoneID of Wintergrasp = 4197
378  uint32 m_MapId; // MapId where is Battlefield
380  uint32 m_MaxPlayer; // Maximum number of player that participated to Battlefield
381  uint32 m_MinPlayer; // Minimum number of player for Battlefield start
382  uint32 m_MinLevel; // Required level to participate at Battlefield
383  uint32 m_BattleTime; // Length of a battle
384  uint32 m_NoWarBattleTime; // Time between two battles
385  uint32 m_RestartAfterCrash; // Delay to restart Wintergrasp if the server crashed during a running battle.
388  WorldLocation KickPosition; // Position where players are teleported if they switch to afk during the battle or if they don't accept invitation
389 
390  uint32 m_uiKickAfkPlayersTimer; // Timer for check Afk in war
391 
392  // Graveyard variables
393  GraveyardVect m_GraveyardList; // Vector witch contain the different GY of the battle
394  uint32 m_LastResurrectTimer; // Timer for resurrect player every 30 sec
395 
396  uint32 m_StartGroupingTimer; // Timer for invite players in area 15 minute before start battle
397  bool m_StartGrouping; // bool for know if all players in area has been invited
398 
399  GuidSet m_Groups[BG_TEAMS_COUNT]; // Contain different raid group
400 
401  std::vector<uint64> m_Data64;
402  std::vector<uint32> m_Data32;
403 
404  void KickAfkPlayers();
405 
406  // use for switch off all worldstate for client
407  virtual void SendRemoveWorldStates(Player* /*player*/) { }
408 
409  // use for send a packet for all player list
410  void BroadcastPacketToZone(WorldPacket const* data) const;
411  void BroadcastPacketToQueue(WorldPacket const* data) const;
412  void BroadcastPacketToWar(WorldPacket const* data) const;
413 
414  // CapturePoint system
415  void AddCapturePoint(BfCapturePoint* cp);
416  BfCapturePoint* GetCapturePoint(uint32 entry) const;
417 
418  void RegisterZone(uint32 zoneid);
419  bool HasPlayer(Player* player) const;
420  void TeamCastSpell(TeamId team, int32 spellId);
421 };
422 
423 #endif
virtual uint32 GetData(uint32 dataId) const override
Definition: Battlefield.h:266
bool HasPlayer(ObjectGuid guid)
Definition: Battlefield.h:183
virtual void OnPlayerLeaveWar(Player *)
Called when a player leave the battle.
Definition: Battlefield.h:315
TeamId GetOtherTeam(TeamId team) const
Definition: Battlefield.h:273
Map * m_Map
Definition: Battlefield.h:379
Definition: Battlefield.h:27
Definition: Battlefield.h:49
virtual bool SetupBattlefield()
Call this to init the Battlefield.
Definition: Battlefield.h:210
Definition: Position.h:228
WorldLocation KickPosition
Definition: Battlefield.h:388
bool CanFlyIn()
Return if we can use mount in battlefield.
Definition: Battlefield.h:335
Battlefield * m_Bf
Definition: Battlefield.h:193
int8_t int8
Definition: Define.h:148
float m_maxSpeed
Definition: Battlefield.h:126
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
int8 GetState() const
Definition: Battlefield.h:243
GuidSet m_ResurrectQueue
Definition: Battlefield.h:192
Definition: DBCStructure.h:1434
std::vector< BfGraveyard * > GraveyardVect
Definition: Battlefield.h:76
virtual void OnPlayerJoinWar(Player *)
Called when a player accept to join the battle.
Definition: Battlefield.h:313
GraveyardVect m_GraveyardList
Definition: Battlefield.h:393
virtual uint64 GetData64(uint32 dataId) const override
Definition: Battlefield.h:262
Definition: Battlefield.h:41
BattlefieldObjectiveStates m_State
Definition: Battlefield.h:134
Definition: Object.h:423
Definition: Creature.h:467
virtual void OnPlayerLeaveZone(Player *)
Called when a player leave battlefield zone.
Definition: Battlefield.h:317
virtual void SendRemoveWorldStates(Player *)
Definition: Battlefield.h:407
virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates &)
Definition: Battlefield.h:88
uint64 MAKE_PAIR64(uint32 l, uint32 h)
Definition: ObjectDefines.h:34
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
virtual void OnBattleStart()
Called on start.
Definition: Battlefield.h:307
void HandlePlayerLeaveZone(Player *player, uint32 zoneId)
Definition: BattlefieldMgr.cpp:92
virtual void SetData64(uint32 dataId, uint64 value) override
Definition: Battlefield.h:263
Definition: Battlefield.h:47
float m_minValue
Definition: Battlefield.h:123
uint32 m_BattleId
Definition: Battlefield.h:376
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
virtual void DoCompleteOrIncrementAchievement(uint32, Player *, uint8)
Definition: Battlefield.h:328
virtual void HandleKill(Player *, Unit *)
Called when a Unit is kill in battlefield zone.
Definition: Battlefield.h:232
Definition: Battlefield.h:60
virtual void ChangeTeam(TeamId)
Definition: Battlefield.h:106
void ToggleBattlefield(bool enable)
Enable or Disable battlefield.
Definition: Battlefield.h:246
uint32 GetTimer() const
Definition: Battlefield.h:347
Definition: Battlefield.h:65
BattlefieldState
Definition: Battlefield.h:38
uint32 m_neutralValuePct
Definition: Battlefield.h:137
std::vector< uint64 > m_Data64
Definition: Battlefield.h:401
uint32 m_GraveyardId
Definition: Battlefield.h:190
Definition: ZoneScript.h:26
void SetDefenderTeam(TeamId team)
Definition: Battlefield.h:274
Definition: Battlefield.h:59
virtual ~BfCapturePoint()
Definition: Battlefield.h:86
BattlefieldSounds
Definition: Battlefield.h:56
uint32 m_LastResurrectTimer
Definition: Battlefield.h:394
uint32 m_TimeForAcceptInvite
Definition: Battlefield.h:386
BfCapturePointMap m_capturePoints
Definition: Battlefield.h:365
TeamId GetTeamId() const
Definition: Battlefield.h:113
virtual void OnStartGrouping()
Called x minutes before battle start when player in zone are invite to join queue.
Definition: Battlefield.h:311
uint32 m_StartGroupingTimer
Definition: Battlefield.h:396
void Resurrect(Creature *target)
Definition: bosses_opera.cpp:1037
G3D::int16 z
Definition: Vector3int16.h:46
uint32 m_Timer
Definition: Battlefield.h:359
uint32 m_MaxPlayer
Definition: Battlefield.h:380
Definition: BattlefieldMgr.h:27
virtual void OnBattleEnd(bool)
Called at the end of battle.
Definition: Battlefield.h:309
TeamId m_team
Definition: Battlefield.h:130
int32_t int32
Definition: Define.h:146
uint32 m_MapId
Definition: Battlefield.h:378
void SetTimer(uint32 timer)
Definition: Battlefield.h:348
uint32_t uint32
Definition: Define.h:150
static void Initialize(PCASC_SALSA20 pState, LPBYTE pbKey, DWORD cbKeyLength, LPBYTE pbVector)
Definition: CascDecrypt.cpp:81
bool IsWarTime() const
Return true if battle is start, false if battle is not started.
Definition: Battlefield.h:241
uint64_t uint64
Definition: Define.h:149
Definition: Battlefield.h:196
G3D::int16 y
Definition: Vector2int16.h:38
Definition: WorldStatePackets.h:27
Definition: SharedDefines.h:992
uint32 m_ZoneId
Definition: Battlefield.h:377
Definition: GameObject.h:880
void SetGraveyardNumber(uint32 number)
Definition: Battlefield.h:293
uint32 GetTypeId() const
Definition: Battlefield.h:234
virtual void UpdateData(uint32 index, int32 pad)
Definition: Battlefield.h:268
TeamId m_ControlTeam
Definition: Battlefield.h:189
Definition: Battlefield.h:28
Definition: Map.h:259
GraveyardVect GetGraveyardVector() const
Definition: Battlefield.h:345
BattlefieldIDs
Definition: Battlefield.h:31
TeamId
Definition: SharedDefines.h:990
uint32 GetBattleId() const
Definition: Battlefield.h:325
uint32 m_uiKickDontAcceptTimer
Definition: Battlefield.h:387
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:174
uint32 m_MinPlayer
Definition: Battlefield.h:381
bool m_IsEnabled
Definition: Battlefield.h:360
void HandlePlayerEnterZone(Player *player, uint32 zoneId)
Definition: BattlefieldMgr.cpp:78
BattlefieldObjectiveStates
Definition: Battlefield.h:45
TeamId GetAttackerTeam() const
Definition: Battlefield.h:272
float m_maxValue
Definition: Battlefield.h:122
uint32 m_BattleTime
Definition: Battlefield.h:383
uint32 m_uiKickAfkPlayersTimer
Definition: Battlefield.h:390
Definition: Battlefield.h:42
uint64 GetQueueId() const
Definition: Battlefield.h:236
std::map< uint32, BfCapturePoint * > BfCapturePointMap
typedef of map witch store capturepoint and the associate gameobject entry
Definition: Battlefield.h:207
Definition: Battlefield.h:58
std::vector< uint32 > m_Data32
Definition: Battlefield.h:402
virtual void OnPlayerEnterZone(Player *)
Called when a player enter in battlefield zone.
Definition: Battlefield.h:319
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:332
Definition: Battlefield.h:33
#define TC_GAME_API
Definition: Define.h:134
ObjectGuid StalkerGuid
Definition: Battlefield.h:358
TC_GAME_API GameObject * GetGameObject(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:143
virtual void SetData(uint32 dataId, uint32 value) override
Definition: Battlefield.h:267
TeamId GetControlTeamId() const
Definition: Battlefield.h:156
uint8_t uint8
Definition: Define.h:152
Definition: Position.h:27
Definition: Battlefield.h:35
std::map< ObjectGuid, time_t > PlayerTimerMap
Definition: Battlefield.h:79
uint32 m_NoWarBattleTime
Definition: Battlefield.h:384
bool m_StartGrouping
Definition: Battlefield.h:397
BattlefieldTimers
Definition: Battlefield.h:63
const FieldDescriptor value
Definition: descriptor.h:1522
Definition: Battlefield.h:40
bool m_isActive
Definition: Battlefield.h:361
Definition: ObjectGuid.h:189
uint32 GetZoneId() const
Definition: Battlefield.h:235
BattlefieldObjectiveStates m_OldState
Definition: Battlefield.h:133
TeamId GetDefenderTeam() const
Definition: Battlefield.h:271
uint32 m_TypeId
Definition: Battlefield.h:375
G3D::int16 x
Definition: Vector2int16.h:37
Battlefield * m_Bf
Definition: Battlefield.h:140
Definition: Battlefield.h:48
uint32 m_capturePointEntry
Definition: Battlefield.h:143
Definition: Battlefield.h:34
Definition: SharedDefines.h:993
uint32 m_RestartAfterCrash
Definition: Battlefield.h:385
uint32 m_MinLevel
Definition: Battlefield.h:382
Definition: Unit.h:1305
float m_value
Definition: Battlefield.h:129
TeamId m_DefenderTeam
Definition: Battlefield.h:362
bool IsEnabled() const
Return if battlefield is enable.
Definition: Battlefield.h:248
Definition: WorldPacket.h:26
BattlefieldTypes
Definition: Battlefield.h:25
uint32 GetGraveyardId() const
Definition: Battlefield.h:186
Definition: Battlefield.h:81
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150
Definition: Battlefield.h:149
Definition: Group.h:191
uint32 GetCapturePointEntry() const
Definition: Battlefield.h:111