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
56 bool IsArena() const;
59 uint8 GetMinLevel() const;
60 uint8 GetMaxLevel() const;
61};
62
63namespace WorldPackets
64{
65 namespace Battleground
66 {
67 struct BattlefieldStatusHeader;
68 class BattlefieldStatusNone;
69 class BattlefieldStatusNeedConfirmation;
70 class BattlefieldStatusActive;
71 class BattlefieldStatusQueued;
72 class BattlefieldStatusFailed;
73 }
74}
75
77{
78 private:
81
82 public:
83 BattlegroundMgr(BattlegroundMgr const& right) = delete;
85 BattlegroundMgr& operator=(BattlegroundMgr const& right) = delete;
87
88 static BattlegroundMgr* instance();
89
90 void Update(uint32 diff);
91
92 /* Packet Building */
93 void SendBattlegroundList(Player* player, ObjectGuid const& guid, BattlegroundTypeId bgTypeId);
94 void BuildBattlegroundStatusHeader(WorldPackets::Battleground::BattlefieldStatusHeader* battlefieldStatus, Player* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId);
95 void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone* battlefieldStatus, Player* player, uint32 ticketId, uint32 joinTime);
96 void BuildBattlegroundStatusNeedConfirmation(WorldPackets::Battleground::BattlefieldStatusNeedConfirmation* battlefieldStatus, Battleground* bg, Player* player, uint32 ticketId, uint32 joinTime, uint32 timeout, BattlegroundQueueTypeId queueId);
97 void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive* battlefieldStatus, Battleground* bg, Player* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId);
98 void BuildBattlegroundStatusQueued(WorldPackets::Battleground::BattlefieldStatusQueued* battlefieldStatus, Player* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId, uint32 avgWaitTime, bool asGroup);
99 void BuildBattlegroundStatusFailed(WorldPackets::Battleground::BattlefieldStatusFailed* battlefieldStatus, BattlegroundQueueTypeId queueId, Player* pPlayer, uint32 ticketId, GroupJoinBattlegroundResult result, ObjectGuid const* errorGuid = nullptr);
100
101 /* Battlegrounds */
102 Battleground* GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId);
103 Battleground* CreateNewBattleground(BattlegroundQueueTypeId queueId, BattlegroundBracketId bracketId);
104
105 void AddBattleground(Battleground* bg);
106 void AddToBGFreeSlotQueue(Battleground* bg);
107 void RemoveFromBGFreeSlotQueue(uint32 mapId, uint32 instanceId);
108 BGFreeSlotQueueContainer& GetBGFreeSlotQueueStore(uint32 mapId);
109
110 void LoadBattlegroundTemplates();
111 void DeleteAllBattlegrounds();
112
113 void SendToBattleground(Player* player, uint32 InstanceID, BattlegroundTypeId bgTypeId);
114
115 /* Battleground queues */
116 static bool IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId);
117 BattlegroundQueue& GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) { return m_BattlegroundQueues.emplace(bgQueueTypeId, bgQueueTypeId).first->second; }
118 void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundBracketId bracket_id);
119 uint32 GetPrematureFinishTime() const;
120
121 void ToggleArenaTesting();
122 void ToggleTesting();
123
124 bool isArenaTesting() const { return m_ArenaTesting; }
125 bool isTesting() const { return m_Testing; }
126
127 static bool IsRandomBattleground(uint32 battlemasterListId);
128 static BattlegroundQueueTypeId BGQueueTypeId(uint16 battlemasterListId, BattlegroundQueueIdType type, bool rated, uint8 teamSize);
129
130 static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
131 static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
132 static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
133
134 uint32 GetMaxRatingDifference() const;
135 uint32 GetRatingDiscardTimer() const;
136 void LoadBattleMastersEntry();
137 void CheckBattleMasters();
139 {
140 BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
141 if (itr != mBattleMastersMap.end())
142 return itr->second;
144 }
145
147 {
148 BattlegroundTemplateMap::const_iterator itr = _battlegroundTemplates.find(id);
149 if (itr != _battlegroundTemplates.end())
150 return &itr->second;
151 return nullptr;
152 }
153
154 private:
155 uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
156 static bool IsArenaType(BattlegroundTypeId bgTypeId);
158
159 typedef std::map<BattlegroundTypeId, BattlegroundData> BattlegroundDataContainer;
161
162 std::map<BattlegroundQueueTypeId, BattlegroundQueue> m_BattlegroundQueues;
164
166 {
170
171 bool operator==(ScheduledQueueUpdate const& right) const = default;
172 };
173
174 std::vector<ScheduledQueueUpdate> m_QueueUpdateScheduler;
180
182 {
183 BattlegroundMapTemplateContainer::const_iterator itr = _battlegroundMapTemplates.find(mapId);
184 if (itr != _battlegroundMapTemplates.end())
185 return itr->second;
186 return nullptr;
187 }
188
189 typedef std::map<BattlegroundTypeId, BattlegroundTemplate> BattlegroundTemplateMap;
193};
194
195#define sBattlegroundMgr BattlegroundMgr::instance()
196
197#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:123
uint8_t uint8
Definition: Define.h:144
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
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
BattlegroundMgr & operator=(BattlegroundMgr &&right)=delete
BattlegroundDataContainer bgDataStore
BattlegroundMgr(BattlegroundMgr &&right)=delete
void Update(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:90
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
WorldSafeLocsEntry const * StartLocation[PVP_TEAMS_COUNT]
uint16 GetMinPlayersPerTeam() const
uint8 GetMaxLevel() const