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