TrinityCore
Loading...
Searching...
No Matches
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
40
46
63
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 static void SendToBattleground(Player* player, Battleground const* battleground);
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 // Return whether toggling was successful. In case of a non-existing battlemasterListId, or this battlemasterListId is not an arena, this would return false.
130 bool ToggleArenaTesting(uint32 battlemasterListId);
131 void ToggleTesting();
132
133 bool isArenaTesting() const { return m_ArenaTesting != 0; }
134 bool isTesting() const { return m_Testing; }
135
136 static bool IsRandomBattleground(uint32 battlemasterListId);
137 static BattlegroundQueueTypeId BGQueueTypeId(uint16 battlemasterListId, BattlegroundQueueIdType type, bool rated, uint8 teamSize);
138
139 static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
140 static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
141 static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
142
143 uint32 GetMaxRatingDifference() const;
144 uint32 GetRatingDiscardTimer() const;
145 void LoadBattleMastersEntry();
146 void CheckBattleMasters();
148 {
149 BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
150 if (itr != mBattleMastersMap.end())
151 return itr->second;
153 }
154
156 {
157 BattlegroundTemplateMap::const_iterator itr = _battlegroundTemplates.find(id);
158 if (itr != _battlegroundTemplates.end())
159 return &itr->second;
160 return nullptr;
161 }
162
163 void LoadBattlegroundScriptTemplate();
164 BattlegroundScriptTemplate const* FindBattlegroundScriptTemplate(uint32 mapId, BattlegroundTypeId bgTypeId) const;
165
166 static void QueuePlayerForArena(Player const* player, uint8 teamSize, uint8 roles);
167
168 private:
169 uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
170 static bool IsArenaType(BattlegroundTypeId bgTypeId);
172
173 typedef std::map<BattlegroundTypeId, BattlegroundData> BattlegroundDataContainer;
175
176 std::map<BattlegroundQueueTypeId, BattlegroundQueue> m_BattlegroundQueues;
178
187
188 std::vector<ScheduledQueueUpdate> m_QueueUpdateScheduler;
194
196 {
197 BattlegroundMapTemplateContainer::const_iterator itr = _battlegroundMapTemplates.find(mapId);
198 if (itr != _battlegroundMapTemplates.end())
199 return itr->second;
200 return nullptr;
201 }
202
203 typedef std::map<BattlegroundTypeId, BattlegroundTemplate> BattlegroundTemplateMap;
207
208 std::map<std::pair<int32, uint32>, BattlegroundScriptTemplate> _battlegroundScriptTemplates;
209};
210
211#define sBattlegroundMgr BattlegroundMgr::instance()
212
213#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
BattlegroundBracketId
Definition DBCEnums.h:53
@ MAX_BATTLEGROUND_BRACKETS
Definition DBCEnums.h:58
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
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
BattlegroundContainer m_Battlegrounds
BattlegroundClientIdsContainer m_ClientBattlegroundIds[MAX_BATTLEGROUND_BRACKETS]
bool operator==(ScheduledQueueUpdate const &right) const =default
BattlegroundTypeId Id
BattlemasterListEntry const * BattlemasterEntry
uint16 GetMaxPlayersPerTeam() const
std::vector< int32 > MapIDs
WorldSafeLocsEntry const * StartLocation[PVP_TEAMS_COUNT]
uint16 GetMinPlayersPerTeam() const