| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #ifndef __BATTLEGROUNDMGR_H |
|---|
| 22 | #define __BATTLEGROUNDMGR_H |
|---|
| 23 | |
|---|
| 24 | #include "BattleGround.h" |
|---|
| 25 | #include "Policies/Singleton.h" |
|---|
| 26 | |
|---|
| 27 | class BattleGround; |
|---|
| 28 | |
|---|
| 29 | //TODO it is not possible to have this structure, because we should have BattlegroundSet for each queue |
|---|
| 30 | //so i propose to change this type to array 1..MAX_BATTLEGROUND_TYPES of sets or maps.. |
|---|
| 31 | typedef std::map<uint32, BattleGround*> BattleGroundSet; |
|---|
| 32 | //typedef std::map<uint32, BattleGroundQueue*> BattleGroundQueueSet; |
|---|
| 33 | typedef std::deque<BattleGround*> BGFreeSlotQueueType; |
|---|
| 34 | |
|---|
| 35 | #define MAX_BATTLEGROUND_QUEUES 7 // for level ranges 10-19, 20-29, 30-39, 40-49, 50-59, 60-69, 70+ |
|---|
| 36 | |
|---|
| 37 | #define MAX_BATTLEGROUND_TYPES 9 // each BG type will be in array |
|---|
| 38 | |
|---|
| 39 | #define MAX_BATTLEGROUND_QUEUE_TYPES 8 |
|---|
| 40 | |
|---|
| 41 | #define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // seconds in a day |
|---|
| 42 | |
|---|
| 43 | struct GroupQueueInfo; // type predefinition |
|---|
| 44 | struct PlayerQueueInfo // stores information for players in queue |
|---|
| 45 | { |
|---|
| 46 | uint32 InviteTime; // first invite time |
|---|
| 47 | uint32 LastInviteTime; // last invite time |
|---|
| 48 | uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes |
|---|
| 49 | GroupQueueInfo * GroupInfo; // pointer to the associated groupqueueinfo |
|---|
| 50 | }; |
|---|
| 51 | |
|---|
| 52 | struct GroupQueueInfo // stores information about the group in queue (also used when joined as solo!) |
|---|
| 53 | { |
|---|
| 54 | std::map<uint64, PlayerQueueInfo*> Players; // player queue info map |
|---|
| 55 | uint32 Team; // Player team (ALLIANCE/HORDE) |
|---|
| 56 | bool IsRated; // rated |
|---|
| 57 | uint32 BgTypeId; // battleground type id |
|---|
| 58 | uint8 ArenaType; // 2v2, 3v3, 5v5 or 0 when BG |
|---|
| 59 | uint32 ArenaTeamId; // team id if rated match |
|---|
| 60 | uint32 JoinTime; // time when group was added |
|---|
| 61 | uint32 IsInvitedToBGInstanceGUID; // was invited to certain BG |
|---|
| 62 | uint32 ArenaTeamRating; // if rated match, inited to the rating of the team |
|---|
| 63 | }; |
|---|
| 64 | |
|---|
| 65 | class BattleGround; |
|---|
| 66 | class BattleGroundQueue |
|---|
| 67 | { |
|---|
| 68 | public: |
|---|
| 69 | BattleGroundQueue(); |
|---|
| 70 | ~BattleGroundQueue(); |
|---|
| 71 | |
|---|
| 72 | void Update(uint32 bgTypeId, uint32 queue_id, uint8 arenatype = 0, bool isRated = false, uint32 minRating = 0); |
|---|
| 73 | |
|---|
| 74 | GroupQueueInfo * AddGroup(Player * leader, uint32 BgTypeId, uint8 ArenaType, bool isRated, uint32 ArenaRating, uint32 ArenaTeamId = 0); |
|---|
| 75 | void AddPlayer(Player *plr, GroupQueueInfo * ginfo); |
|---|
| 76 | void RemovePlayer(uint64 guid, bool decreaseInvitedCount); |
|---|
| 77 | void DecreaseGroupLength(uint32 queueId, uint32 AsGroup); |
|---|
| 78 | void BGEndedRemoveInvites(BattleGround * bg); |
|---|
| 79 | |
|---|
| 80 | typedef std::map<uint64, PlayerQueueInfo> QueuedPlayersMap; |
|---|
| 81 | QueuedPlayersMap m_QueuedPlayers[MAX_BATTLEGROUND_QUEUES]; |
|---|
| 82 | |
|---|
| 83 | typedef std::list<GroupQueueInfo*> QueuedGroupsList; |
|---|
| 84 | QueuedGroupsList m_QueuedGroups[MAX_BATTLEGROUND_QUEUES]; |
|---|
| 85 | |
|---|
| 86 | // class to hold pointers to the groups eligible for a specific selection pool building mode |
|---|
| 87 | class EligibleGroups : public std::list<GroupQueueInfo *> |
|---|
| 88 | { |
|---|
| 89 | public: |
|---|
| 90 | void Init(QueuedGroupsList * source, uint32 BgTypeId, uint32 side, uint32 MaxPlayers, uint8 ArenaType = 0, bool IsRated = false, uint32 MinRating = 0, uint32 MaxRating = 0, uint32 DisregardTime = 0, uint32 excludeTeam = 0); |
|---|
| 91 | void RemoveGroup(GroupQueueInfo * ginfo); |
|---|
| 92 | }; |
|---|
| 93 | |
|---|
| 94 | EligibleGroups m_EligibleGroups; |
|---|
| 95 | |
|---|
| 96 | // class to select and invite groups to bg |
|---|
| 97 | class SelectionPool |
|---|
| 98 | { |
|---|
| 99 | public: |
|---|
| 100 | void Init(); |
|---|
| 101 | void AddGroup(GroupQueueInfo * group); |
|---|
| 102 | GroupQueueInfo * GetMaximalGroup(); |
|---|
| 103 | void RemoveGroup(GroupQueueInfo * group); |
|---|
| 104 | uint32 GetPlayerCount() const {return PlayerCount;} |
|---|
| 105 | public: |
|---|
| 106 | std::list<GroupQueueInfo *> SelectedGroups; |
|---|
| 107 | private: |
|---|
| 108 | uint32 PlayerCount; |
|---|
| 109 | GroupQueueInfo * MaxGroup; |
|---|
| 110 | }; |
|---|
| 111 | |
|---|
| 112 | enum SelectionPoolBuildMode |
|---|
| 113 | { |
|---|
| 114 | NORMAL_ALLIANCE, |
|---|
| 115 | NORMAL_HORDE, |
|---|
| 116 | ONESIDE_ALLIANCE_TEAM1, |
|---|
| 117 | ONESIDE_ALLIANCE_TEAM2, |
|---|
| 118 | ONESIDE_HORDE_TEAM1, |
|---|
| 119 | ONESIDE_HORDE_TEAM2, |
|---|
| 120 | |
|---|
| 121 | NUM_SELECTION_POOL_TYPES |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | SelectionPool m_SelectionPools[NUM_SELECTION_POOL_TYPES]; |
|---|
| 125 | |
|---|
| 126 | bool BuildSelectionPool(uint32 bgTypeId, uint32 queue_id, uint32 MinPlayers, uint32 MaxPlayers, SelectionPoolBuildMode mode, uint8 ArenaType = 0, bool isRated = false, uint32 MinRating = 0, uint32 MaxRating = 0, uint32 DisregardTime = 0, uint32 excludeTeam = 0); |
|---|
| 127 | |
|---|
| 128 | private: |
|---|
| 129 | |
|---|
| 130 | bool InviteGroupToBG(GroupQueueInfo * ginfo, BattleGround * bg, uint32 side); |
|---|
| 131 | }; |
|---|
| 132 | |
|---|
| 133 | /* |
|---|
| 134 | This class is used to invite player to BG again, when minute lasts from his first invitation |
|---|
| 135 | it is capable to solve all possibilities |
|---|
| 136 | */ |
|---|
| 137 | class BGQueueInviteEvent : public BasicEvent |
|---|
| 138 | { |
|---|
| 139 | public: |
|---|
| 140 | BGQueueInviteEvent(uint64 pl_guid, uint32 BgInstanceGUID) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(BgInstanceGUID) {}; |
|---|
| 141 | virtual ~BGQueueInviteEvent() {}; |
|---|
| 142 | |
|---|
| 143 | virtual bool Execute(uint64 e_time, uint32 p_time); |
|---|
| 144 | virtual void Abort(uint64 e_time); |
|---|
| 145 | private: |
|---|
| 146 | uint64 m_PlayerGuid; |
|---|
| 147 | uint32 m_BgInstanceGUID; |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | /* |
|---|
| 151 | This class is used to remove player from BG queue after 2 minutes from first invitation |
|---|
| 152 | */ |
|---|
| 153 | class BGQueueRemoveEvent : public BasicEvent |
|---|
| 154 | { |
|---|
| 155 | public: |
|---|
| 156 | BGQueueRemoveEvent(uint64 pl_guid, uint32 bgInstanceGUID, uint32 playersTeam) : m_PlayerGuid(pl_guid), m_BgInstanceGUID(bgInstanceGUID), m_PlayersTeam(playersTeam) {}; |
|---|
| 157 | virtual ~BGQueueRemoveEvent() {}; |
|---|
| 158 | |
|---|
| 159 | virtual bool Execute(uint64 e_time, uint32 p_time); |
|---|
| 160 | virtual void Abort(uint64 e_time); |
|---|
| 161 | private: |
|---|
| 162 | uint64 m_PlayerGuid; |
|---|
| 163 | uint32 m_BgInstanceGUID; |
|---|
| 164 | uint32 m_PlayersTeam; |
|---|
| 165 | }; |
|---|
| 166 | |
|---|
| 167 | class BattleGroundMgr |
|---|
| 168 | { |
|---|
| 169 | public: |
|---|
| 170 | /* Construction */ |
|---|
| 171 | BattleGroundMgr(); |
|---|
| 172 | ~BattleGroundMgr(); |
|---|
| 173 | void Update(time_t diff); |
|---|
| 174 | |
|---|
| 175 | /* Packet Building */ |
|---|
| 176 | void BuildPlayerJoinedBattleGroundPacket(WorldPacket *data, Player *plr); |
|---|
| 177 | void BuildPlayerLeftBattleGroundPacket(WorldPacket *data, Player *plr); |
|---|
| 178 | void BuildBattleGroundListPacket(WorldPacket *data, uint64 guid, Player *plr, uint32 bgTypeId); |
|---|
| 179 | void BuildGroupJoinedBattlegroundPacket(WorldPacket *data, uint32 bgTypeId); |
|---|
| 180 | void BuildUpdateWorldStatePacket(WorldPacket *data, uint32 field, uint32 value); |
|---|
| 181 | void BuildPvpLogDataPacket(WorldPacket *data, BattleGround *bg); |
|---|
| 182 | void BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint32 team, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2, uint32 arenatype = 0, uint8 israted = 0); |
|---|
| 183 | void BuildPlaySoundPacket(WorldPacket *data, uint32 soundid); |
|---|
| 184 | |
|---|
| 185 | /* Player invitation */ |
|---|
| 186 | // called from Queue update, or from Addplayer to queue |
|---|
| 187 | void InvitePlayer(Player* plr, uint32 bgInstanceGUID, uint32 team); |
|---|
| 188 | |
|---|
| 189 | /* Battlegrounds */ |
|---|
| 190 | BattleGroundSet::iterator GetBattleGroundsBegin() { return m_BattleGrounds.begin(); }; |
|---|
| 191 | BattleGroundSet::iterator GetBattleGroundsEnd() { return m_BattleGrounds.end(); }; |
|---|
| 192 | |
|---|
| 193 | BattleGround* GetBattleGround(uint32 ID) |
|---|
| 194 | { |
|---|
| 195 | BattleGroundSet::iterator i = m_BattleGrounds.find(ID); |
|---|
| 196 | if(i != m_BattleGrounds.end()) |
|---|
| 197 | return i->second; |
|---|
| 198 | else |
|---|
| 199 | return NULL; |
|---|
| 200 | }; |
|---|
| 201 | |
|---|
| 202 | BattleGround * GetBattleGroundTemplate(uint32 bgTypeId); |
|---|
| 203 | BattleGround * CreateNewBattleGround(uint32 bgTypeId); |
|---|
| 204 | |
|---|
| 205 | uint32 CreateBattleGround(uint32 bgTypeId, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam, uint32 LevelMin, uint32 LevelMax, char* BattleGroundName, uint32 MapID, float Team1StartLocX, float Team1StartLocY, float Team1StartLocZ, float Team1StartLocO, float Team2StartLocX, float Team2StartLocY, float Team2StartLocZ, float Team2StartLocO); |
|---|
| 206 | |
|---|
| 207 | inline void AddBattleGround(uint32 ID, BattleGround* BG) { m_BattleGrounds[ID] = BG; }; |
|---|
| 208 | void RemoveBattleGround(uint32 instanceID); |
|---|
| 209 | |
|---|
| 210 | void CreateInitialBattleGrounds(); |
|---|
| 211 | |
|---|
| 212 | void SendToBattleGround(Player *pl, uint32 bgTypeId); |
|---|
| 213 | |
|---|
| 214 | /* Battleground queues */ |
|---|
| 215 | //these queues are instantiated when creating BattlegroundMrg |
|---|
| 216 | BattleGroundQueue m_BattleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code |
|---|
| 217 | |
|---|
| 218 | BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPES]; |
|---|
| 219 | |
|---|
| 220 | void SendAreaSpiritHealerQueryOpcode(Player *pl, BattleGround *bg, uint64 guid); |
|---|
| 221 | |
|---|
| 222 | bool IsArenaType(uint32 bgTypeId) const; |
|---|
| 223 | bool IsBattleGroundType(uint32 bgTypeId) const; |
|---|
| 224 | uint32 BGQueueTypeId(uint32 bgTypeId, uint8 arenaType) const; |
|---|
| 225 | uint32 BGTemplateId(uint32 bgQueueTypeId) const; |
|---|
| 226 | uint8 BGArenaType(uint32 bgQueueTypeId) const; |
|---|
| 227 | |
|---|
| 228 | uint32 GetMaxRatingDifference() const {return m_MaxRatingDifference;} |
|---|
| 229 | uint32 GetRatingDiscardTimer() const {return m_RatingDiscardTimer;} |
|---|
| 230 | |
|---|
| 231 | void InitAutomaticArenaPointDistribution(); |
|---|
| 232 | void DistributeArenaPoints(); |
|---|
| 233 | uint32 GetPrematureFinishTime() const {return m_PrematureFinishTimer;} |
|---|
| 234 | void ToggleArenaTesting(); |
|---|
| 235 | const bool isArenaTesting() const { return m_ArenaTesting; } |
|---|
| 236 | |
|---|
| 237 | void SetHolidayWeekends(uint32 mask); |
|---|
| 238 | |
|---|
| 239 | private: |
|---|
| 240 | |
|---|
| 241 | /* Battlegrounds */ |
|---|
| 242 | BattleGroundSet m_BattleGrounds; |
|---|
| 243 | uint32 m_MaxRatingDifference; |
|---|
| 244 | uint32 m_RatingDiscardTimer; |
|---|
| 245 | uint32 m_NextRatingDiscardUpdate; |
|---|
| 246 | bool m_AutoDistributePoints; |
|---|
| 247 | uint64 m_NextAutoDistributionTime; |
|---|
| 248 | uint32 m_AutoDistributionTimeChecker; |
|---|
| 249 | uint32 m_PrematureFinishTimer; |
|---|
| 250 | bool m_ArenaTesting; |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | #define sBattleGroundMgr Trinity::Singleton<BattleGroundMgr>::Instance() |
|---|
| 254 | #endif |
|---|