1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BATTLEGROUNDMGR_H
#define __BATTLEGROUNDMGR_H
#include "Common.h"
#include "DBCEnums.h"
#include "Battleground.h"
#include "BattlegroundQueue.h"
#include "UniqueTrackablePtr.h"
#include <unordered_map>
class Battleground;
struct BattlemasterListEntry;
typedef std::map<uint32, Trinity::unique_trackable_ptr<Battleground>> BattlegroundContainer;
typedef std::set<uint32> BattlegroundClientIdsContainer;
typedef std::unordered_map<uint32, BattlegroundTypeId> BattleMastersMap;
enum BattlegroundMisc
{
BATTLEGROUND_OBJECTIVE_UPDATE_INTERVAL = 1000
};
struct BattlegroundData
{
BattlegroundContainer m_Battlegrounds;
BattlegroundClientIdsContainer m_ClientBattlegroundIds[MAX_BATTLEGROUND_BRACKETS];
};
struct BattlegroundTemplate
{
BattlegroundTypeId Id;
WorldSafeLocsEntry const* StartLocation[PVP_TEAMS_COUNT] = { };
float MaxStartDistSq;
uint8 Weight;
uint32 ScriptId;
BattlemasterListEntry const* BattlemasterEntry;
std::vector<int32> MapIDs;
bool IsArena() const;
uint16 GetMinPlayersPerTeam() const;
uint16 GetMaxPlayersPerTeam() const;
uint8 GetMinLevel() const;
uint8 GetMaxLevel() const;
};
struct BattlegroundScriptTemplate
{
int32 MapId;
BattlegroundTypeId Id;
uint32 ScriptId;
};
namespace WorldPackets
{
namespace Battleground
{
struct BattlefieldStatusHeader;
class BattlefieldStatusNone;
class BattlefieldStatusNeedConfirmation;
class BattlefieldStatusActive;
class BattlefieldStatusQueued;
class BattlefieldStatusFailed;
}
}
class TC_GAME_API BattlegroundMgr
{
private:
BattlegroundMgr();
~BattlegroundMgr();
public:
BattlegroundMgr(BattlegroundMgr const& right) = delete;
BattlegroundMgr(BattlegroundMgr&& right) = delete;
BattlegroundMgr& operator=(BattlegroundMgr const& right) = delete;
BattlegroundMgr& operator=(BattlegroundMgr&& right) = delete;
static BattlegroundMgr* instance();
void Update(uint32 diff);
/* Packet Building */
void SendBattlegroundList(Player* player, ObjectGuid const& guid, BattlegroundTypeId bgTypeId);
static void BuildBattlegroundStatusHeader(WorldPackets::Battleground::BattlefieldStatusHeader* header, Player const* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId);
static void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone* battlefieldStatus, Player const* player, uint32 ticketId, uint32 joinTime);
static void BuildBattlegroundStatusNeedConfirmation(WorldPackets::Battleground::BattlefieldStatusNeedConfirmation* battlefieldStatus, Battleground const* bg, Player const* player, uint32 ticketId, uint32 joinTime, uint32 timeout, BattlegroundQueueTypeId queueId);
static void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive* battlefieldStatus, Battleground const* bg, Player const* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId);
static void BuildBattlegroundStatusQueued(WorldPackets::Battleground::BattlefieldStatusQueued* battlefieldStatus, Player const* player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId, uint32 avgWaitTime, bool asGroup);
static void BuildBattlegroundStatusFailed(WorldPackets::Battleground::BattlefieldStatusFailed* battlefieldStatus, BattlegroundQueueTypeId queueId, Player const* player, uint32 ticketId, GroupJoinBattlegroundResult result, ObjectGuid const* errorGuid = nullptr);
/* Battlegrounds */
Battleground* GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId);
Battleground* CreateNewBattleground(BattlegroundQueueTypeId queueId, BattlegroundBracketId bracketId);
void AddBattleground(Battleground* bg);
void AddToBGFreeSlotQueue(Battleground* bg);
void RemoveFromBGFreeSlotQueue(uint32 mapId, uint32 instanceId);
BGFreeSlotQueueContainer& GetBGFreeSlotQueueStore(uint32 mapId);
void LoadBattlegroundTemplates();
void DeleteAllBattlegrounds();
void SendToBattleground(Player* player, uint32 InstanceID, BattlegroundTypeId bgTypeId);
/* Battleground queues */
static bool IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId);
BattlegroundQueue& GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) { return m_BattlegroundQueues.emplace(bgQueueTypeId, bgQueueTypeId).first->second; }
void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundBracketId bracket_id);
uint32 GetPrematureFinishTime() const;
void ToggleArenaTesting();
void ToggleTesting();
bool isArenaTesting() const { return m_ArenaTesting; }
bool isTesting() const { return m_Testing; }
static bool IsRandomBattleground(uint32 battlemasterListId);
static BattlegroundQueueTypeId BGQueueTypeId(uint16 battlemasterListId, BattlegroundQueueIdType type, bool rated, uint8 teamSize);
static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
uint32 GetMaxRatingDifference() const;
uint32 GetRatingDiscardTimer() const;
void LoadBattleMastersEntry();
void CheckBattleMasters();
BattlegroundTypeId GetBattleMasterBG(uint32 entry) const
{
BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
if (itr != mBattleMastersMap.end())
return itr->second;
return BATTLEGROUND_TYPE_NONE;
}
BattlegroundTemplate const* GetBattlegroundTemplateByTypeId(BattlegroundTypeId id)
{
BattlegroundTemplateMap::const_iterator itr = _battlegroundTemplates.find(id);
if (itr != _battlegroundTemplates.end())
return &itr->second;
return nullptr;
}
void LoadBattlegroundScriptTemplate();
BattlegroundScriptTemplate const* FindBattlegroundScriptTemplate(uint32 mapId, BattlegroundTypeId bgTypeId) const;
private:
uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
static bool IsArenaType(BattlegroundTypeId bgTypeId);
BattlegroundTypeId GetRandomBG(BattlegroundTypeId id);
typedef std::map<BattlegroundTypeId, BattlegroundData> BattlegroundDataContainer;
BattlegroundDataContainer bgDataStore;
std::map<BattlegroundQueueTypeId, BattlegroundQueue> m_BattlegroundQueues;
std::map<uint32 /*mapId*/, BGFreeSlotQueueContainer> m_BGFreeSlotQueue;
struct ScheduledQueueUpdate
{
uint32 ArenaMatchmakerRating;
BattlegroundQueueTypeId QueueId;
BattlegroundBracketId BracketId;
bool operator==(ScheduledQueueUpdate const& right) const = default;
};
std::vector<ScheduledQueueUpdate> m_QueueUpdateScheduler;
uint32 m_NextRatedArenaUpdate;
uint32 m_UpdateTimer;
bool m_ArenaTesting;
bool m_Testing;
BattleMastersMap mBattleMastersMap;
BattlegroundTemplate const* GetBattlegroundTemplateByMapId(uint32 mapId)
{
BattlegroundMapTemplateContainer::const_iterator itr = _battlegroundMapTemplates.find(mapId);
if (itr != _battlegroundMapTemplates.end())
return itr->second;
return nullptr;
}
typedef std::map<BattlegroundTypeId, BattlegroundTemplate> BattlegroundTemplateMap;
typedef std::map<uint32 /*mapId*/, BattlegroundTemplate*> BattlegroundMapTemplateContainer;
BattlegroundTemplateMap _battlegroundTemplates;
BattlegroundMapTemplateContainer _battlegroundMapTemplates;
std::map<std::pair<int32, uint32>, BattlegroundScriptTemplate> _battlegroundScriptTemplates;
};
#define sBattlegroundMgr BattlegroundMgr::instance()
#endif // __BATTLEGROUNDMGR_H
|