TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BattlegroundMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __BATTLEGROUNDMGR_H
20 #define __BATTLEGROUNDMGR_H
21 
22 #include "Common.h"
23 #include "DBCEnums.h"
24 #include "Battleground.h"
25 #include "BattlegroundQueue.h"
26 
27 typedef std::map<uint32, Battleground*> BattlegroundContainer;
28 typedef std::set<uint32> BattlegroundClientIdsContainer;
29 
30 typedef std::unordered_map<uint32, BattlegroundTypeId> BattleMastersMap;
31 
32 #define WS_CURRENCY_RESET_TIME 20001 // Custom worldstate
33 
35 {
39 };
40 
42 {
53 
54  bool IsArena() const { return BattlemasterEntry->InstanceType == MAP_ARENA; }
55 };
56 
57 namespace WorldPackets
58 {
59  namespace Battleground
60  {
67  }
68 }
69 
71 {
72  private:
74  ~BattlegroundMgr();
75 
76  public:
77  static BattlegroundMgr* instance();
78 
79  void Update(uint32 diff);
80 
81  /* Packet Building */
82  void SendBattlegroundList(Player* player, ObjectGuid const& guid, BattlegroundTypeId bgTypeId);
83  void BuildBattlegroundStatusHeader(WorldPackets::Battleground::BattlefieldStatusHeader* battlefieldStatus, Battleground* bg, Player* player, uint32 ticketId, uint32 joinTime, uint32 arenaType);
84  void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone* battlefieldStatus, Player* player, uint32 ticketId, uint32 joinTime, uint32 arenaType);
85  void BuildBattlegroundStatusNeedConfirmation(WorldPackets::Battleground::BattlefieldStatusNeedConfirmation* battlefieldStatus, Battleground* bg, Player* player, uint32 ticketId, uint32 joinTime, uint32 timeout, uint32 arenaType);
86  void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive* battlefieldStatus, Battleground* bg, Player* player, uint32 ticketId, uint32 joinTime, uint32 arenaType);
87  void BuildBattlegroundStatusQueued(WorldPackets::Battleground::BattlefieldStatusQueued* battlefieldStatus, Battleground* bg, Player* player, uint32 ticketId, uint32 joinTime, uint32 avgWaitTime, uint32 arenaType, bool asGroup);
88  void BuildBattlegroundStatusFailed(WorldPackets::Battleground::BattlefieldStatusFailed* battlefieldStatus, Battleground* bg, Player* pPlayer, uint32 ticketId, uint32 arenaType, GroupJoinBattlegroundResult result, ObjectGuid const* errorGuid = nullptr);
89  void SendAreaSpiritHealerQueryOpcode(Player* player, Battleground* bg, ObjectGuid const& guid);
90 
91  /* Battlegrounds */
92  Battleground* GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId);
93  Battleground* GetBattlegroundTemplate(BattlegroundTypeId bgTypeId);
94  Battleground* CreateNewBattleground(BattlegroundTypeId bgTypeId, PvPDifficultyEntry const* bracketEntry, uint8 arenaType, bool isRated);
95 
96  void AddBattleground(Battleground* bg);
97  void RemoveBattleground(BattlegroundTypeId bgTypeId, uint32 instanceId);
98  void AddToBGFreeSlotQueue(BattlegroundTypeId bgTypeId, Battleground* bg);
99  void RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint32 instanceId);
100  BGFreeSlotQueueContainer& GetBGFreeSlotQueueStore(BattlegroundTypeId bgTypeId);
101 
102  void LoadBattlegroundTemplates();
103  void DeleteAllBattlegrounds();
104 
105  void SendToBattleground(Player* player, uint32 InstanceID, BattlegroundTypeId bgTypeId);
106 
107  /* Battleground queues */
108  BattlegroundQueue& GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) { return m_BattlegroundQueues[bgQueueTypeId]; }
109  void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, uint8 arenaType, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
110  uint32 GetPrematureFinishTime() const;
111 
112  void ToggleArenaTesting();
113  void ToggleTesting();
114 
115  void SetHolidayWeekends(uint32 mask);
116 
117  bool isArenaTesting() const { return m_ArenaTesting; }
118  bool isTesting() const { return m_Testing; }
119 
120  static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType);
121  static BattlegroundTypeId BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId);
122  static uint8 BGArenaType(BattlegroundQueueTypeId bgQueueTypeId);
123 
124  static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId);
125  static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
126  static bool IsBGWeekend(BattlegroundTypeId bgTypeId);
127 
128  uint32 GetMaxRatingDifference() const;
129  uint32 GetRatingDiscardTimer() const;
130  void LoadBattleMastersEntry();
131  void CheckBattleMasters();
133  {
134  BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
135  if (itr != mBattleMastersMap.end())
136  return itr->second;
137  return BATTLEGROUND_TYPE_NONE;
138  }
139 
140  private:
141  bool CreateBattleground(BattlegroundTemplate const* bgTemplate);
142  uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id);
143  static bool IsArenaType(BattlegroundTypeId bgTypeId);
144  BattlegroundTypeId GetRandomBG(BattlegroundTypeId id);
145 
146  typedef std::map<BattlegroundTypeId, BattlegroundData> BattlegroundDataContainer;
147  BattlegroundDataContainer bgDataStore;
148 
150 
151  std::vector<uint64> m_QueueUpdateScheduler;
154  bool m_Testing;
156 
158  {
159  BattlegroundTemplateMap::const_iterator itr = _battlegroundTemplates.find(id);
160  if (itr != _battlegroundTemplates.end())
161  return &itr->second;
162  return nullptr;
163  }
164 
166  {
167  BattlegroundMapTemplateContainer::const_iterator itr = _battlegroundMapTemplates.find(mapId);
168  if (itr != _battlegroundMapTemplates.end())
169  return itr->second;
170  return nullptr;
171  }
172 
174 
175  typedef std::map<BattlegroundTypeId, BattlegroundTemplate> BattlegroundTemplateMap;
177  BattlegroundTemplateMap _battlegroundTemplates;
178  BattlegroundMapTemplateContainer _battlegroundMapTemplates;
179 };
180 
181 #define sBattlegroundMgr BattlegroundMgr::instance()
182 
183 #endif // __BATTLEGROUNDMGR_H
Definition: BattlegroundPackets.h:147
Definition: BattlegroundMgr.h:70
Definition: DBCEnums.h:63
Definition: BattlegroundPackets.h:200
BattlegroundTypeId
Definition: SharedDefines.h:4558
std::unordered_map< uint32, BattlegroundTypeId > BattleMastersMap
Definition: BattlegroundMgr.h:30
std::list< Battleground * > BGFreeSlotQueueContainer
Definition: BattlegroundQueue.h:30
BattlegroundBracketId
Definition: DBCEnums.h:57
Definition: DBCEnums.h:482
uint32 m_NextRatedArenaUpdate
Definition: BattlegroundMgr.h:152
uint16 MinPlayersPerTeam
Definition: BattlegroundMgr.h:44
uint8 Weight
Definition: BattlegroundMgr.h:50
BattlegroundTypeId Id
Definition: BattlegroundMgr.h:43
float MaxStartDistSq
Definition: BattlegroundMgr.h:49
bool IsArena() const
Definition: BattlegroundMgr.h:54
uint16 MaxPlayersPerTeam
Definition: BattlegroundMgr.h:45
BattlegroundTemplateMap _battlegroundTemplates
Definition: BattlegroundMgr.h:177
BattlemasterListEntry const * BattlemasterEntry
Definition: BattlegroundMgr.h:52
std::map< uint32, BattlegroundTemplate * > BattlegroundMapTemplateContainer
Definition: BattlegroundMgr.h:176
std::map< BattlegroundTypeId, BattlegroundTemplate > BattlegroundTemplateMap
Definition: BattlegroundMgr.h:175
Definition: BattlegroundPackets.h:185
uint8 MinLevel
Definition: BattlegroundMgr.h:46
#define BG_TEAMS_COUNT
Definition: SharedDefines.h:4555
Definition: BattlegroundMgr.h:34
bool m_ArenaTesting
Definition: BattlegroundMgr.h:153
bool isArenaTesting() const
Definition: BattlegroundMgr.h:117
Definition: SharedDefines.h:4747
std::vector< uint64 > m_QueueUpdateScheduler
Definition: BattlegroundMgr.h:151
BattlegroundQueue & GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId)
Definition: BattlegroundMgr.h:108
std::map< BattlegroundTypeId, BattlegroundData > BattlegroundDataContainer
Definition: BattlegroundMgr.h:146
uint32_t uint32
Definition: Define.h:150
uint32 ScriptId
Definition: BattlegroundMgr.h:51
uint16_t uint16
Definition: Define.h:151
uint32 InstanceType
Definition: DBCStructure.h:118
Definition: BattlegroundMgr.h:41
BattleMastersMap mBattleMastersMap
Definition: BattlegroundMgr.h:155
bool m_Testing
Definition: BattlegroundMgr.h:154
Definition: BattlegroundMgr.h:57
std::map< uint32, Battleground * > BattlegroundContainer
Definition: BattlegroundMgr.h:27
BattlegroundTemplate const * GetBattlegroundTemplateByMapId(uint32 mapId)
Definition: BattlegroundMgr.h:165
BattlegroundDataContainer bgDataStore
Definition: BattlegroundMgr.h:147
BattlegroundTemplate const * GetBattlegroundTemplateByTypeId(BattlegroundTypeId id)
Definition: BattlegroundMgr.h:157
Definition: BattlegroundQueue.h:75
BattlegroundQueueTypeId
Definition: SharedDefines.h:4732
BattlegroundClientIdsContainer m_ClientBattlegroundIds[MAX_BATTLEGROUND_BRACKETS]
Definition: BattlegroundMgr.h:37
uint8 MaxLevel
Definition: BattlegroundMgr.h:47
Definition: DBCStructure.h:926
#define TC_GAME_API
Definition: Define.h:134
BGFreeSlotQueueContainer BGFreeSlotQueue
Definition: BattlegroundMgr.h:38
Definition: BattlegroundPackets.h:170
BattlegroundMapTemplateContainer _battlegroundMapTemplates
Definition: BattlegroundMgr.h:178
Position StartLocation[BG_TEAMS_COUNT]
Definition: BattlegroundMgr.h:48
Definition: BattlegroundPackets.h:135
uint8_t uint8
Definition: Define.h:152
Definition: Position.h:27
std::map< BattlegroundTypeId, uint8 > BattlegroundSelectionWeightMap
Definition: BattlegroundMgr.h:173
bool isTesting() const
Definition: BattlegroundMgr.h:118
Definition: SharedDefines.h:4560
Definition: Battleground.h:235
BattlegroundContainer m_Battlegrounds
Definition: BattlegroundMgr.h:36
Definition: ObjectGuid.h:189
GroupJoinBattlegroundResult
Definition: SharedDefines.h:4750
BattlegroundTypeId GetBattleMasterBG(uint32 entry) const
Definition: BattlegroundMgr.h:132
HolidayIds
Definition: SharedDefines.h:3714
Definition: DBCStructure.h:114
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150
std::set< uint32 > BattlegroundClientIdsContainer
Definition: BattlegroundMgr.h:28