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#include <memory>
26
28{
29 BATTLEFIELD_WG = 1, // Wintergrasp
30 BATTLEFIELD_TB = 2, // Tol Barad (cataclysm)
32};
33
35{
36 BATTLEFIELD_BATTLEID_WG = 1, // Wintergrasp battle
37 BATTLEFIELD_BATTLEID_TB = 21, // Tol Barad
38 BATTLEFIELD_BATTLEID_ASHRAN = 24 // Ashran
39};
40
47
58
65
70
71// some class predefs
72class Battlefield;
73class BfGraveyard;
74class Creature;
75class GameObject;
76class Group;
77class Map;
78class Player;
79class Unit;
80class WorldPacket;
81struct Position;
82struct QuaternionData;
84
85namespace WorldPackets
86{
87 namespace WorldState
88 {
89 class InitWorldStates;
90 }
91}
92
93typedef std::vector<BfGraveyard*> GraveyardVect;
94typedef std::map<ObjectGuid, time_t> PlayerTimerMap;
95
97{
98public:
101
102protected:
103 Battlefield* GetBattlefield();
104private:
106};
107
109{
110 public:
112 virtual ~BfGraveyard() = default;
113
114 // Method to changing who controls the graveyard
115 void GiveControlTo(TeamId team);
116 TeamId GetControlTeamId() const { return m_ControlTeam; }
117
118 // Find the nearest graveyard to a player
119 float GetDistance(Player* player);
120
121 // Initialize the graveyard
122 void Initialize(TeamId startcontrol, uint32 gy);
123
124 // Set spirit service for the graveyard
125 void SetSpirit(Creature* spirit, TeamId team);
126
127 // Check if this graveyard has a spirit guide
128 bool HasNpc(ObjectGuid guid);
129
130 // Get the graveyard's ID.
131 uint32 GetGraveyardId() const { return m_GraveyardId; }
132
133 protected:
138};
139
141{
142 friend class BattlefieldMgr;
143
144 public:
146 explicit Battlefield(Map* map);
147 Battlefield(Battlefield const& right) = delete;
148 Battlefield(Battlefield&& right) = delete;
149 Battlefield& operator=(Battlefield const& right) = delete;
152 virtual ~Battlefield();
153
155
156 typedef std::unordered_map<uint32 /*control zone entry*/, std::unique_ptr<BattlefieldControlZoneHandler>> ControlZoneHandlerMap;
157
159 virtual bool SetupBattlefield() { return true; }
160
168 virtual bool Update(uint32 diff);
169
171 void InvitePlayersInZoneToQueue();
173 void InvitePlayersInQueueToWar();
175 void InvitePlayersInZoneToWar();
176
178 virtual void HandleKill(Player* /*killer*/, Unit* /*killed*/) { }
179
180 uint32 GetTypeId() const { return m_TypeId; }
181 uint32 GetZoneId() const { return m_ZoneId; }
182 uint32 GetMapId() const { return m_MapId; }
183 Map* GetMap() const { return m_Map; }
184 uint64 GetQueueId() const;
185
186 void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2 = 0);
187
189 bool IsWarTime() const { return m_isActive; }
190
191 int8 GetState() const { return m_isActive ? BATTLEFIELD_IN_PROGRESS : (m_Timer <= m_StartGroupingTimer ? BATTLEFIELD_WARMUP : BATTLEFIELD_INACTIVE); }
192
194 void ToggleBattlefield(bool enable) { m_IsEnabled = enable; }
196 bool IsEnabled() const { return m_IsEnabled; }
197
202 void KickPlayerFromBattlefield(ObjectGuid guid);
203
205 void HandlePlayerEnterZone(Player* player, uint32 zone);
207 void HandlePlayerLeaveZone(Player* player, uint32 zone);
208
209 // All-purpose data storage 64 bit
210 virtual uint64 GetData64(uint32 dataId) const override { return m_Data64[dataId]; }
211 virtual void SetData64(uint32 dataId, uint64 value) override { m_Data64[dataId] = value; }
212
213 // All-purpose data storage 32 bit
214 virtual uint32 GetData(uint32 dataId) const override { return m_Data32[dataId]; }
215 virtual void SetData(uint32 dataId, uint32 value) override { m_Data32[dataId] = value; }
216 virtual void UpdateData(uint32 index, int32 pad) { m_Data32[index] += pad; }
217
218 // Battlefield - generic methods
219 TeamId GetDefenderTeam() const { return m_DefenderTeam; }
220 TeamId GetAttackerTeam() const { return TeamId(1 - m_DefenderTeam); }
221 void SetDefenderTeam(TeamId team) { m_DefenderTeam = team; }
222
223 // Group methods
228 Group* GetFreeBfRaid(TeamId TeamId);
230 Group* GetGroupPlayer(ObjectGuid guid, TeamId TeamId);
232 bool AddOrSetPlayerToCorrectBfGroup(Player* player);
233
234 // Graveyard methods
235 // Find which graveyard the player must be teleported to to be resurrected by spiritguide
236 WorldSafeLocsEntry const* GetClosestGraveyard(Player* player);
237
238 void SetGraveyardNumber(uint32 number);
239 BfGraveyard* GetGraveyardById(uint32 id) const;
240
241 // Misc methods
242 Creature* SpawnCreature(uint32 entry, Position const& pos);
243 GameObject* SpawnGameObject(uint32 entry, Position const& pos, QuaternionData const& rot);
244
245 Creature* GetCreature(ObjectGuid guid);
246 GameObject* GetGameObject(ObjectGuid guid);
247
248 // Script-methods
249
251 virtual void OnBattleStart() { }
253 virtual void OnBattleEnd(bool /*endByTimer*/) { }
255 virtual void OnStartGrouping() { }
257 virtual void OnPlayerJoinWar(Player* /*player*/) { }
259 virtual void OnPlayerLeaveWar(Player* /*player*/) { }
261 virtual void OnPlayerLeaveZone(Player* /*player*/) { }
263 virtual void OnPlayerEnterZone(Player* /*player*/) { }
264
265 void SendWarning(uint8 id, WorldObject const* target = nullptr);
266
267 void PlayerAcceptInviteToQueue(Player* player);
268 void PlayerAcceptInviteToWar(Player* player);
269 uint32 GetBattleId() const { return m_BattleId; }
270 void AskToLeaveQueue(Player* player);
271 void PlayerAskToLeave(Player* player);
272
273 virtual void DoCompleteOrIncrementAchievement(uint32 /*achievement*/, Player* /*player*/, uint8 /*incrementNumber = 1*/) { }
274
276 bool CanFlyIn() { return !m_isActive; }
277
278 void StartBattle();
279 void EndBattle(bool endByTimer);
280
281 void HideNpc(Creature* creature);
282 void ShowNpc(Creature* creature, bool aggressive);
283
284 GraveyardVect const& GetGraveyardVector() const { return m_GraveyardList; }
285
286 uint32 GetTimer() const { return m_Timer; }
287 void SetTimer(uint32 timer) { m_Timer = timer; }
288
289 void DoPlaySoundToAll(uint32 SoundID);
290
291 void InvitePlayerToQueue(Player* player);
292 void InvitePlayerToWar(Player* player);
293
294 void InitStalker(uint32 entry, Position const& pos);
295
296 void ProcessEvent(WorldObject* target, uint32 eventId, WorldObject* invoker) override;
297 protected:
299 uint32 m_Timer; // Global timer for event
303
304 // Map of the objectives belonging to this OutdoorPvP
306
307 // Players info maps
308 GuidUnorderedSet m_players[PVP_TEAMS_COUNT]; // Players in zone
309 GuidUnorderedSet m_PlayersInQueue[PVP_TEAMS_COUNT]; // Players in the queue
310 GuidUnorderedSet m_PlayersInWar[PVP_TEAMS_COUNT]; // Players in WG combat
312 PlayerTimerMap m_PlayersWillBeKick[PVP_TEAMS_COUNT];
313
314 // Variables that must exist for each battlefield
315 uint32 m_TypeId; // See enum BattlefieldTypes
316 uint32 m_BattleId; // BattleID (for packet)
317 uint32 m_ZoneId; // ZoneID of Wintergrasp = 4197
318 uint32 m_MapId; // MapId where is Battlefield
320 uint32 m_MaxPlayer; // Maximum number of player that participated to Battlefield
321 uint32 m_MinPlayer; // Minimum number of player for Battlefield start
322 uint32 m_MinLevel; // Required level to participate at Battlefield
323 uint32 m_BattleTime; // Length of a battle
324 uint32 m_NoWarBattleTime; // Time between two battles
325 uint32 m_RestartAfterCrash; // Delay to restart Wintergrasp if the server crashed during a running battle.
328 WorldLocation KickPosition; // Position where players are teleported if they switch to afk during the battle or if they don't accept invitation
329
330 uint32 m_uiKickAfkPlayersTimer; // Timer for check Afk in war
331
332 // Graveyard variables
333 GraveyardVect m_GraveyardList; // Vector witch contain the different GY of the battle
334
335 uint32 m_StartGroupingTimer; // Timer for invite players in area 15 minute before start battle
336 bool m_StartGrouping; // bool for know if all players in area has been invited
337
338 GuidUnorderedSet m_Groups[PVP_TEAMS_COUNT]; // Contain different raid group
339
340 std::vector<uint64> m_Data64;
341 std::vector<uint32> m_Data32;
342
343 void KickAfkPlayers();
344
345 // use for switch off all worldstate for client
346 virtual void SendRemoveWorldStates(Player* /*player*/) { }
347
348 // use for send a packet for all player list
349 void BroadcastPacketToZone(WorldPacket const* data) const;
350 void BroadcastPacketToQueue(WorldPacket const* data) const;
351 void BroadcastPacketToWar(WorldPacket const* data) const;
352
353 void RegisterZone(uint32 zoneid);
354 bool HasPlayer(Player* player) const;
355 void TeamCastSpell(TeamId team, int32 spellId);
356};
357
358#endif
std::map< ObjectGuid, time_t > PlayerTimerMap
Definition Battlefield.h:94
std::vector< BfGraveyard * > GraveyardVect
Definition Battlefield.h:93
BattlefieldTypes
Definition Battlefield.h:28
@ BATTLEFIELD_WG
Definition Battlefield.h:29
@ BATTLEFIELD_MAX
Definition Battlefield.h:31
@ BATTLEFIELD_TB
Definition Battlefield.h:30
BattlefieldSounds
Definition Battlefield.h:60
@ BF_SOUND_HORDE_WINS
Definition Battlefield.h:61
@ BF_SOUND_ALLIANCE_WINS
Definition Battlefield.h:62
@ BF_SOUND_START
Definition Battlefield.h:63
BattlefieldTimers
Definition Battlefield.h:67
@ BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition Battlefield.h:68
BattlefieldState
Definition Battlefield.h:42
@ BATTLEFIELD_WARMUP
Definition Battlefield.h:44
@ BATTLEFIELD_IN_PROGRESS
Definition Battlefield.h:45
@ BATTLEFIELD_INACTIVE
Definition Battlefield.h:43
BattlefieldObjectiveStates
Definition Battlefield.h:49
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE
Definition Battlefield.h:54
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE
Definition Battlefield.h:53
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE
Definition Battlefield.h:52
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE
Definition Battlefield.h:55
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE
Definition Battlefield.h:51
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE
Definition Battlefield.h:56
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition Battlefield.h:50
BattlefieldIDs
Definition Battlefield.h:35
@ BATTLEFIELD_BATTLEID_WG
Definition Battlefield.h:36
@ BATTLEFIELD_BATTLEID_TB
Definition Battlefield.h:37
@ BATTLEFIELD_BATTLEID_ASHRAN
Definition Battlefield.h:38
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int8_t int8
Definition Define.h:152
int32_t int32
Definition Define.h:150
uint64_t uint64
Definition Define.h:153
uint32_t uint32
Definition Define.h:154
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:435
uint8 constexpr PVP_TEAMS_COUNT
WorldState
virtual ~BattlefieldControlZoneHandler()=default
uint32 m_Timer
Map * GetMap() const
uint32 m_MapId
GraveyardVect m_GraveyardList
uint32 GetBattleId() const
virtual uint64 GetData64(uint32 dataId) const override
uint32 m_MaxPlayer
std::vector< uint32 > m_Data32
void SetTimer(uint32 timer)
ObjectGuid StalkerGuid
uint32 m_NoWarBattleTime
virtual void OnBattleEnd(bool)
Called at the end of battle.
virtual void SetData(uint32 dataId, uint32 value) override
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
virtual void DoCompleteOrIncrementAchievement(uint32, Player *, uint8)
int8 GetState() const
virtual bool SetupBattlefield()
Call this to init the Battlefield.
virtual void SendRemoveWorldStates(Player *)
uint32 m_StartGroupingTimer
GraveyardVect const & GetGraveyardVector() const
void SetDefenderTeam(TeamId team)
TeamId m_DefenderTeam
Battlefield(Battlefield const &right)=delete
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
std::unordered_map< uint32, std::unique_ptr< BattlefieldControlZoneHandler > > ControlZoneHandlerMap
typedef of map witch store capturepoint and the associate gameobject entry
uint32 m_RestartAfterCrash
Battlefield & operator=(Battlefield &&right)=delete
TeamId GetAttackerTeam() const
Battlefield & operator=(Battlefield const &right)=delete
uint32 GetMapId() 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
virtual void OnPlayerLeaveZone(Player *)
Called when a player leave battlefield zone.
uint32 m_uiKickDontAcceptTimer
void ToggleBattlefield(bool enable)
Enable or Disable battlefield.
ControlZoneHandlerMap ControlZoneHandlers
Battlefield(Battlefield &&right)=delete
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 TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2=0)
bool IsEnabled() const
Return if battlefield is enable.
virtual void OnPlayerEnterZone(Player *)
Called when a player enter in battlefield zone.
uint32 GetTypeId() const
virtual ~BfGraveyard()=default
uint32 m_GraveyardId
Battlefield * m_Bf
TeamId m_ControlTeam
TeamId GetControlTeamId() const
uint32 GetGraveyardId() const
Definition Group.h:205
Definition Map.h:225
Definition Unit.h:635