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
29
30typedef std::map<uint32, Trinity::unique_trackable_ptr<Battleground>> BattlegroundContainer;
31typedef std::set<uint32> BattlegroundClientIdsContainer;
32
33typedef std::unordered_map<uint32, BattlegroundTypeId> BattleMastersMap;
34
41
48
65
66namespace WorldPackets
67{
68 namespace Battleground
69 {
70 struct BattlefieldStatusHeader;
71 class BattlefieldStatusNone;
72 class BattlefieldStatusNeedConfirmation;
73 class BattlefieldStatusActive;
74 class BattlefieldStatusQueued;
75 class GroupJoinedBattleground;
77 }
78}
79
81{
82 private:
85
86 public:
87 BattlegroundMgr(BattlegroundMgr const& right) = delete;
89 BattlegroundMgr& operator=(BattlegroundMgr const& right) = delete;
91
92 static BattlegroundMgr* instance();
93
94 void Update(uint32 diff);
95
96 /* Packet Building */
97 static void BuildBattlegroundStatusHeader(WorldPackets::Battleground::BattlefieldStatusHeader* header, Battleground const* bg, uint32 queueSlot, BattlegroundQueueTypeId queueId);
98 static void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone* battlefieldStatus, uint32 queueSlot);
99 static void BuildBattlegroundStatusNeedConfirmation(WorldPackets::Battleground::BattlefieldStatusNeedConfirmation* battlefieldStatus, Battleground const* bg, uint32 queueSlot, uint32 timeout, BattlegroundQueueTypeId queueId);
100 static void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive* battlefieldStatus, Battleground const* bg, Player const* player, uint32 queueSlot, BattlegroundQueueTypeId queueId);
101 static void BuildBattlegroundStatusQueued(WorldPackets::Battleground::BattlefieldStatusQueued* battlefieldStatus, Battleground const* bg, uint32 queueSlot, uint32 joinTime, BattlegroundQueueTypeId queueId, uint32 avgWaitTime);
102 static void BuildBattlegroundStatusFailed(WorldPackets::Battleground::BattlefieldStatusFailed* battlefieldStatus, GroupJoinBattlegroundResult result, ObjectGuid const* errorGuid = nullptr);
103 static void BuildGroupJoinedBattlegroundPacket(WorldPackets::Battleground::GroupJoinedBattleground* groupJoinedBattleground, BattlegroundTypeId bgTypeId);
104
105 void SendBattlegroundList(Player* player, ObjectGuid const& guid, BattlegroundTypeId bgTypeId);
106 void SendAreaSpiritHealerQueryOpcode(Player* player, Battleground* bg, ObjectGuid guid);
107
108 /* Battlegrounds */
109 Battleground* GetBattlegroundThroughClientInstance(uint32 instanceId, BattlegroundTypeId bgTypeId);
110 Battleground* GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId);
111 Battleground* GetBattlegroundTemplate(BattlegroundTypeId bgTypeId);
112 Battleground* CreateNewBattleground(BattlegroundTypeId bgTypeId, PvPDifficultyEntry const* bracketEntry, uint8 arenaType, bool isRated);
113
114 void AddBattleground(Battleground* bg);
115 void AddToBGFreeSlotQueue(BattlegroundTypeId bgTypeId, Battleground* bg);
116 void RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint32 instanceId);
117 BGFreeSlotQueueContainer& GetBGFreeSlotQueueStore(BattlegroundTypeId bgTypeId);
118
119 void LoadBattlegroundTemplates();
120 void DeleteAllBattlegrounds();
121
122 void SendToBattleground(Player* player, uint32 InstanceID, BattlegroundTypeId bgTypeId);
123
124 /* Battleground queues */
125 bool IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId);
126 BattlegroundQueue& GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) { return m_BattlegroundQueues.emplace(bgQueueTypeId, bgQueueTypeId).first->second; }
127 void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, BattlegroundQueueTypeId bgQueueTypeId);
128 uint32 GetPrematureFinishTime() const;
129
130 void ToggleArenaTesting();
131 void ToggleTesting();
132
133 void ResetHolidays();
134 void SetHolidayActive(uint32 battlegroundId);
135
136 bool isArenaTesting() const { return m_ArenaTesting; }
137 bool isTesting() const { return m_Testing; }
138
139 static bool IsRandomBattleground(uint32 battlemasterListId);
140 static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 bracketId, uint8 arenaType);
141
142 static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
143 static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
144 static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
145
146 uint32 GetMaxRatingDifference() const;
147 uint32 GetRatingDiscardTimer() const;
148 void InitAutomaticArenaPointDistribution();
149 void LoadBattleMastersEntry();
150 void CheckBattleMasters();
152 {
153 BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
154 if (itr != mBattleMastersMap.end())
155 return itr->second;
157 }
158
159 private:
160 bool CreateBattleground(BattlegroundTemplate const* bgTemplate);
161 uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
162 static bool IsArenaType(BattlegroundTypeId bgTypeId);
164
165 typedef std::map<BattlegroundTypeId, BattlegroundData> BattlegroundDataContainer;
167
168 std::map<BattlegroundQueueTypeId, BattlegroundQueue> m_BattlegroundQueues;
169
177
178 std::vector<ScheduledQueueUpdate> m_QueueUpdateScheduler;
186
188 {
189 BattlegroundTemplateMap::const_iterator itr = _battlegroundTemplates.find(id);
190 if (itr != _battlegroundTemplates.end())
191 return &itr->second;
192 return nullptr;
193 }
194
196 {
197 BattlegroundMapTemplateContainer::const_iterator itr = _battlegroundMapTemplates.find(mapId);
198 if (itr != _battlegroundMapTemplates.end())
199 return itr->second;
200 return nullptr;
201 }
202
204
205 typedef std::map<BattlegroundTypeId, BattlegroundTemplate> BattlegroundTemplateMap;
209};
210
211#define sBattlegroundMgr BattlegroundMgr::instance()
212
213#endif // __BATTLEGROUNDMGR_H
std::unordered_map< uint32, BattlegroundTypeId > BattleMastersMap
BattlegroundMisc
@ BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY
@ BATTLEGROUND_OBJECTIVE_UPDATE_INTERVAL
std::set< uint32 > BattlegroundClientIdsContainer
std::map< uint32, Trinity::unique_trackable_ptr< Battleground > > BattlegroundContainer
std::list< Battleground * > BGFreeSlotQueueContainer
#define MAX_BATTLEGROUND_BRACKETS
Definition DBCEnums.h:63
BattlegroundBracketId
Definition DBCEnums.h:57
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
GroupJoinBattlegroundResult
uint8 constexpr PVP_TEAMS_COUNT
BattlegroundTypeId
@ BATTLEGROUND_TYPE_NONE
HolidayIds
std::map< BattlegroundTypeId, BattlegroundTemplate > BattlegroundTemplateMap
BattlegroundMapTemplateContainer _battlegroundMapTemplates
std::map< BattlegroundQueueTypeId, BattlegroundQueue > m_BattlegroundQueues
std::map< BattlegroundTypeId, uint8 > BattlegroundSelectionWeightMap
BattlegroundTemplate const * GetBattlegroundTemplateByMapId(uint32 mapId)
std::vector< ScheduledQueueUpdate > m_QueueUpdateScheduler
BattlegroundTemplateMap _battlegroundTemplates
uint32 m_AutoDistributionTimeChecker
std::map< BattlegroundTypeId, BattlegroundData > BattlegroundDataContainer
std::map< uint32, BattlegroundTemplate * > BattlegroundMapTemplateContainer
bool isArenaTesting() const
BattlegroundQueue & GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId)
time_t m_NextAutoDistributionTime
BattleMastersMap mBattleMastersMap
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
BattlegroundContainer m_Battlegrounds
BattlegroundClientIdsContainer m_ClientBattlegroundIds[MAX_BATTLEGROUND_BRACKETS]
BGFreeSlotQueueContainer BGFreeSlotQueue
bool operator==(ScheduledQueueUpdate const &right) const =default
BattlegroundTypeId Id
BattlemasterListEntry const * BattlemasterEntry
Position StartLocation[PVP_TEAMS_COUNT]
std::vector< int32 > MapIDs