TrinityCore
BattlegroundMgr.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 __BATTLEGROUNDMGR_H
19#define __BATTLEGROUNDMGR_H
20
21#include "Common.h"
22#include "DBCEnums.h"
23#include "Battleground.h"
24#include "BattlegroundQueue.h"
25#include "UniqueTrackablePtr.h"
26#include <unordered_map>
27
28class Battleground;
30
31typedef std::map<uint32, Trinity::unique_trackable_ptr<Battleground>> BattlegroundContainer;
32typedef std::set<uint32> BattlegroundClientIdsContainer;
33
34typedef std::unordered_map<uint32, BattlegroundTypeId> BattleMastersMap;
35
37{
39};
40
42{
45};
46
48{
55 std::vector<int32> MapIDs;
56
57 bool IsArena() const;
60 uint8 GetMinLevel() const;
61 uint8 GetMaxLevel() const;
62};
63
65{
69};
70
71namespace WorldPackets
72{
73 namespace Battleground
74 {
75 struct BattlefieldStatusHeader;
76 class BattlefieldStatusNone;
77 class BattlefieldStatusNeedConfirmation;
78 class BattlefieldStatusActive;
79 class BattlefieldStatusQueued;
80 class BattlefieldStatusFailed;
81 }
82}
83
85{
86 private:
89
90 public:
91 BattlegroundMgr(BattlegroundMgr const& right) = delete;
93 BattlegroundMgr& operator=(BattlegroundMgr const& right) = delete;
95
96 static BattlegroundMgr* instance();
97
98 void Update(uint32 diff);
99
100 /* Packet Building */
101 void SendBattlegroundList(Player* player, ObjectGuid const& guid, BattlegroundTypeId bgTypeId);
102 static void BuildBattlegroundStatusHeader(WorldPackets::Battleground::BattlefieldStatusHeader* header, Player const* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId);
103 static void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone* battlefieldStatus, Player const* player, uint32 ticketId, uint32 joinTime);
104 static void BuildBattlegroundStatusNeedConfirmation(WorldPackets::Battleground::BattlefieldStatusNeedConfirmation* battlefieldStatus, Battleground const* bg, Player const* player, uint32 ticketId, uint32 joinTime, uint32 timeout, BattlegroundQueueTypeId queueId);
105 static void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive* battlefieldStatus, Battleground const* bg, Player const* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId);
106 static void BuildBattlegroundStatusQueued(WorldPackets::Battleground::BattlefieldStatusQueued* battlefieldStatus, Player const* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId, uint32 avgWaitTime, bool asGroup);
107 static void BuildBattlegroundStatusFailed(WorldPackets::Battleground::BattlefieldStatusFailed* battlefieldStatus, BattlegroundQueueTypeId queueId, Player const* player, uint32 ticketId, GroupJoinBattlegroundResult result, ObjectGuid const* errorGuid = nullptr);
108
109 /* Battlegrounds */
110 Battleground* GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId);
111 Battleground* CreateNewBattleground(BattlegroundQueueTypeId queueId, BattlegroundBracketId bracketId);
112
113 void AddBattleground(Battleground* bg);
114 void AddToBGFreeSlotQueue(Battleground* bg);
115 void RemoveFromBGFreeSlotQueue(uint32 mapId, uint32 instanceId);
116 BGFreeSlotQueueContainer& GetBGFreeSlotQueueStore(uint32 mapId);
117
118 void LoadBattlegroundTemplates();
119 void DeleteAllBattlegrounds();
120
121 void SendToBattleground(Player* player, uint32 InstanceID, BattlegroundTypeId bgTypeId);
122
123 /* Battleground queues */
124 static bool IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId);
125 BattlegroundQueue& GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) { return m_BattlegroundQueues.emplace(bgQueueTypeId, bgQueueTypeId).first->second; }
126 void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundBracketId bracket_id);
127 uint32 GetPrematureFinishTime() const;
128
129 void ToggleArenaTesting();
130 void ToggleTesting();
131
132 bool isArenaTesting() const { return m_ArenaTesting; }
133 bool isTesting() const { return m_Testing; }
134
135 static bool IsRandomBattleground(uint32 battlemasterListId);
136 static BattlegroundQueueTypeId BGQueueTypeId(uint16 battlemasterListId, BattlegroundQueueIdType type, bool rated, uint8 teamSize);
137
138 static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
139 static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
140 static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
141
142 uint32 GetMaxRatingDifference() const;
143 uint32 GetRatingDiscardTimer() const;
144 void LoadBattleMastersEntry();
145 void CheckBattleMasters();
147 {
148 BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
149 if (itr != mBattleMastersMap.end())
150 return itr->second;
152 }
153
155 {
156 BattlegroundTemplateMap::const_iterator itr = _battlegroundTemplates.find(id);
157 if (itr != _battlegroundTemplates.end())
158 return &itr->second;
159 return nullptr;
160 }
161
162 void LoadBattlegroundScriptTemplate();
163 BattlegroundScriptTemplate const* FindBattlegroundScriptTemplate(uint32 mapId, BattlegroundTypeId bgTypeId) const;
164
165 private:
166 uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
167 static bool IsArenaType(BattlegroundTypeId bgTypeId);
169
170 typedef std::map<BattlegroundTypeId, BattlegroundData> BattlegroundDataContainer;
172
173 std::map<BattlegroundQueueTypeId, BattlegroundQueue> m_BattlegroundQueues;
175
177 {
181
182 bool operator==(ScheduledQueueUpdate const& right) const = default;
183 };
184
185 std::vector<ScheduledQueueUpdate> m_QueueUpdateScheduler;
191
193 {
194 BattlegroundMapTemplateContainer::const_iterator itr = _battlegroundMapTemplates.find(mapId);
195 if (itr != _battlegroundMapTemplates.end())
196 return itr->second;
197 return nullptr;
198 }
199
200 typedef std::map<BattlegroundTypeId, BattlegroundTemplate> BattlegroundTemplateMap;
204
205 std::map<std::pair<int32, uint32>, BattlegroundScriptTemplate> _battlegroundScriptTemplates;
206};
207
208#define sBattlegroundMgr BattlegroundMgr::instance()
209
210#endif // __BATTLEGROUNDMGR_H
std::unordered_map< uint32, BattlegroundTypeId > BattleMastersMap
BattlegroundMisc
@ BATTLEGROUND_OBJECTIVE_UPDATE_INTERVAL
std::set< uint32 > BattlegroundClientIdsContainer
std::map< uint32, Trinity::unique_trackable_ptr< Battleground > > BattlegroundContainer
std::list< Battleground * > BGFreeSlotQueueContainer
BattlegroundQueueIdType
Definition: Battleground.h:231
BattlegroundBracketId
Definition: DBCEnums.h:59
@ MAX_BATTLEGROUND_BRACKETS
Definition: DBCEnums.h:64
#define TC_GAME_API
Definition: Define.h:129
uint8_t uint8
Definition: Define.h:150
int32_t int32
Definition: Define.h:144
uint16_t uint16
Definition: Define.h:149
uint32_t uint32
Definition: Define.h:148
GroupJoinBattlegroundResult
uint8 constexpr PVP_TEAMS_COUNT
BattlegroundTypeId
@ BATTLEGROUND_TYPE_NONE
HolidayIds
std::map< BattlegroundTypeId, BattlegroundTemplate > BattlegroundTemplateMap
BattlegroundMapTemplateContainer _battlegroundMapTemplates
std::map< BattlegroundQueueTypeId, BattlegroundQueue > m_BattlegroundQueues
BattlegroundTemplate const * GetBattlegroundTemplateByMapId(uint32 mapId)
std::vector< ScheduledQueueUpdate > m_QueueUpdateScheduler
BattlegroundTemplateMap _battlegroundTemplates
std::map< BattlegroundTypeId, BattlegroundData > BattlegroundDataContainer
std::map< uint32, BattlegroundTemplate * > BattlegroundMapTemplateContainer
bool isArenaTesting() const
BattlegroundQueue & GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId)
BattleMastersMap mBattleMastersMap
std::map< uint32, BGFreeSlotQueueContainer > m_BGFreeSlotQueue
BattlegroundMgr & operator=(BattlegroundMgr const &right)=delete
BattlegroundTemplate const * GetBattlegroundTemplateByTypeId(BattlegroundTypeId id)
BattlegroundMgr(BattlegroundMgr const &right)=delete
BattlegroundTypeId GetBattleMasterBG(uint32 entry) const
uint32 m_NextRatedArenaUpdate
bool isTesting() const
std::map< std::pair< int32, uint32 >, BattlegroundScriptTemplate > _battlegroundScriptTemplates
BattlegroundMgr & operator=(BattlegroundMgr &&right)=delete
BattlegroundDataContainer bgDataStore
BattlegroundMgr(BattlegroundMgr &&right)=delete
void Update(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:101
BattlegroundContainer m_Battlegrounds
BattlegroundClientIdsContainer m_ClientBattlegroundIds[MAX_BATTLEGROUND_BRACKETS]
bool operator==(ScheduledQueueUpdate const &right) const =default
BattlegroundTypeId Id
uint8 GetMinLevel() const
BattlemasterListEntry const * BattlemasterEntry
uint16 GetMaxPlayersPerTeam() const
std::vector< int32 > MapIDs
WorldSafeLocsEntry const * StartLocation[PVP_TEAMS_COUNT]
uint16 GetMinPlayersPerTeam() const
uint8 GetMaxLevel() const