2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
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.
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.
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
21 #include "BattleGroundMgr.h"
22 #include "BattleGroundAV.h"
23 #include "BattleGroundAB.h"
24 #include "BattleGroundEY.h"
25 #include "BattleGroundWS.h"
26 #include "BattleGroundNA.h"
27 #include "BattleGroundBE.h"
28 #include "BattleGroundAA.h"
29 #include "BattleGroundRL.h"
30 #include "SharedDefines.h"
31 #include "Policies/SingletonImp.h"
32 #include "MapManager.h"
34 #include "MapInstanced.h"
35 #include "ObjectMgr.h"
36 #include "ProgressBar.h"
39 #include "ArenaTeam.h"
41 INSTANTIATE_SINGLETON_1( BattleGroundMgr
);
43 /*********************************************************/
44 /*** BATTLEGROUND QUEUE SYSTEM ***/
45 /*********************************************************/
47 BattleGroundQueue::BattleGroundQueue()
49 //queues are empty, we don't have to call clear()
50 /* for (int i = 0; i < MAX_BATTLEGROUND_QUEUES; i++)
52 //m_QueuedPlayers[i].Horde = 0;
53 //m_QueuedPlayers[i].Alliance = 0;
54 //m_QueuedPlayers[i].AverageTime = 0;
58 BattleGroundQueue::~BattleGroundQueue()
60 for (int i
= 0; i
< MAX_BATTLEGROUND_QUEUES
; i
++)
62 m_QueuedPlayers
[i
].clear();
63 for(QueuedGroupsList::iterator itr
= m_QueuedGroups
[i
].begin(); itr
!= m_QueuedGroups
[i
].end(); ++itr
)
67 m_QueuedGroups
[i
].clear();
71 // initialize eligible groups from the given source matching the given specifications
72 void BattleGroundQueue::EligibleGroups::Init(BattleGroundQueue::QueuedGroupsList
*source
, uint32 BgTypeId
, uint32 side
, uint32 MaxPlayers
, uint8 ArenaType
, bool IsRated
, uint32 MinRating
, uint32 MaxRating
, uint32 DisregardTime
, uint32 excludeTeam
)
74 // clear from prev initialization
76 BattleGroundQueue::QueuedGroupsList::iterator itr
, next
;
77 // iterate through the source
78 for(itr
= source
->begin(); itr
!= source
->end(); itr
= next
)
82 if( (*itr
)->BgTypeId
== BgTypeId
&& // bg type must match
83 (*itr
)->ArenaType
== ArenaType
&& // arena type must match
84 (*itr
)->IsRated
== IsRated
&& // israted must match
85 (*itr
)->IsInvitedToBGInstanceGUID
== 0 && // leave out already invited groups
86 (*itr
)->Team
== side
&& // match side
87 (*itr
)->Players
.size() <= MaxPlayers
&& // the group must fit in the bg
88 ( !excludeTeam
|| (*itr
)->ArenaTeamId
!= excludeTeam
) && // if excludeTeam is specified, leave out those arena team ids
89 ( !IsRated
|| (*itr
)->Players
.size() == MaxPlayers
) && // if rated, then pass only if the player count is exact NEEDS TESTING! (but now this should never happen)
90 ( (*itr
)->JoinTime
<= DisregardTime
// pass if disregard time is greater than join time
91 || (*itr
)->ArenaTeamRating
== 0 // pass if no rating info
92 || ( (*itr
)->ArenaTeamRating
>= MinRating
// pass if matches the rating range
93 && (*itr
)->ArenaTeamRating
<= MaxRating
) ) )
95 // the group matches the conditions
96 // insert it in order of groupsize, and join time
97 uint32 size
= (*itr
)->Players
.size();
98 uint32 jointime
= (*itr
)->JoinTime
;
99 bool inserted
= false;
101 for(std::list
<GroupQueueInfo
*>::iterator elig_itr
= begin(); elig_itr
!= end(); ++elig_itr
)
103 // if the next one's size is smaller, then insert
104 // also insert if the next one's size is equal, but it joined the queue later
105 if( ((*elig_itr
)->Players
.size()<size
) ||
106 ((*elig_itr
)->Players
.size() == size
&& (*elig_itr
)->JoinTime
> jointime
) )
108 insert(elig_itr
,(*itr
));
113 // if not inserted -> this is the smallest group -> push_back
122 // remove group from eligible groups
123 // used when building selection pools
124 void BattleGroundQueue::EligibleGroups::RemoveGroup(GroupQueueInfo
* ginfo
)
126 for(std::list
<GroupQueueInfo
*>::iterator itr
= begin(); itr
!= end(); ++itr
)
136 // selection pool initialization, used to clean up from prev selection
137 void BattleGroundQueue::SelectionPool::Init()
139 SelectedGroups
.clear();
144 // get the maximal group from the selection pool
145 // used when building the pool, and have to remove the largest
146 GroupQueueInfo
* BattleGroundQueue::SelectionPool::GetMaximalGroup()
148 if(SelectedGroups
.empty())
150 sLog
.outError("Getting max group when selection pool is empty, this should never happen.");
154 // actually select the max group if it's not set
155 if(MaxGroup
==0 && !SelectedGroups
.empty())
158 for(std::list
<GroupQueueInfo
*>::iterator itr
= SelectedGroups
.begin(); itr
!= SelectedGroups
.end(); ++itr
)
160 if(max_size
<(*itr
)->Players
.size())
163 max_size
= MaxGroup
->Players
.size();
170 // remove group info from selection pool
171 // used when building selection pools and have to remove maximal group
172 void BattleGroundQueue::SelectionPool::RemoveGroup(GroupQueueInfo
*ginfo
)
174 // uninitiate max group info if needed
175 if(MaxGroup
== ginfo
)
177 // find what to remove
178 for(std::list
<GroupQueueInfo
*>::iterator itr
= SelectedGroups
.begin(); itr
!= SelectedGroups
.end(); ++itr
)
182 SelectedGroups
.erase(itr
);
183 // decrease selected players count
184 PlayerCount
-= ginfo
->Players
.size();
190 // add group to selection
191 // used when building selection pools
192 void BattleGroundQueue::SelectionPool::AddGroup(GroupQueueInfo
* ginfo
)
194 SelectedGroups
.push_back(ginfo
);
195 // increase selected players count
196 PlayerCount
+=ginfo
->Players
.size();
197 if(!MaxGroup
|| ginfo
->Players
.size() > MaxGroup
->Players
.size())
199 // update max group info if needed
204 // add group to bg queue with the given leader and bg specifications
205 GroupQueueInfo
* BattleGroundQueue::AddGroup(Player
*leader
, uint32 BgTypeId
, uint8 ArenaType
, bool isRated
, uint32 arenaRating
, uint32 arenateamid
)
207 uint32 queue_id
= leader
->GetBattleGroundQueueIdFromLevel();
210 // cannot use the method like in addplayer, because that could modify an in-queue group's stats
211 // (e.g. leader leaving queue then joining as individual again)
212 GroupQueueInfo
* ginfo
= new GroupQueueInfo
;
213 ginfo
->BgTypeId
= BgTypeId
;
214 ginfo
->ArenaType
= ArenaType
;
215 ginfo
->ArenaTeamId
= arenateamid
;
216 ginfo
->IsRated
= isRated
;
217 ginfo
->IsInvitedToBGInstanceGUID
= 0; // maybe this should be modifiable by function arguments to enable selection of running instances?
218 ginfo
->JoinTime
= getMSTime();
219 ginfo
->Team
= leader
->GetTeam();
220 ginfo
->ArenaTeamRating
= arenaRating
;
221 ginfo
->OpponentsTeamRating
= 0; //initialize it to 0
223 ginfo
->Players
.clear();
225 m_QueuedGroups
[queue_id
].push_back(ginfo
);
227 // return ginfo, because it is needed to add players to this group info
231 void BattleGroundQueue::AddPlayer(Player
*plr
, GroupQueueInfo
*ginfo
)
233 uint32 queue_id
= plr
->GetBattleGroundQueueIdFromLevel();
235 //if player isn't in queue, he is added, if already is, then values are overwritten, no memory leak
236 PlayerQueueInfo
& info
= m_QueuedPlayers
[queue_id
][plr
->GetGUID()];
238 info
.LastInviteTime
= 0;
239 info
.LastOnlineTime
= getMSTime();
240 info
.GroupInfo
= ginfo
;
242 // add the pinfo to ginfo's list
243 ginfo
->Players
[plr
->GetGUID()] = &info
;
245 if( sWorld.getConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE) )
247 BattleGround* bg = sBattleGroundMgr.GetBattleGround(bgTypeId);
248 char const* bgName = bg->GetName();
250 uint32 q_min_level = Player::GetMinLevelForBattleGroundQueueId(queue_id);
251 uint32 q_max_level = Player::GetMaxLevelForBattleGroundQueueId(queue_id);
253 // replace hardcoded max level by player max level for nice output
254 if(q_max_level > sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL))
255 q_max_level = sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL);
257 int8 MinPlayers = bg->GetMinPlayersPerTeam();
259 uint8 qHorde = m_QueuedPlayers[queue_id].Horde;
260 uint8 qAlliance = m_QueuedPlayers[queue_id].Alliance;
262 // Show queue status to player only (when joining queue)
263 if(sWorld.getConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY))
265 ChatHandler(plr).PSendSysMessage(LANG_BG_QUEUE_ANNOUNCE_SELF,
266 bgName, q_min_level, q_max_level, qAlliance, (MinPlayers > qAlliance) ? (MinPlayers - qAlliance) : 0, qHorde, (MinPlayers > qHorde) ? (MinPlayers - qHorde) : 0);
271 sWorld.SendWorldText(LANG_BG_QUEUE_ANNOUNCE_WORLD,
272 bgName, q_min_level, q_max_level, qAlliance, (MinPlayers > qAlliance) ? (MinPlayers - qAlliance) : 0, qHorde, (MinPlayers > qHorde) ? (MinPlayers - qHorde) : 0);
278 void BattleGroundQueue::RemovePlayer(uint64 guid
, bool decreaseInvitedCount
)
280 Player
*plr
= objmgr
.GetPlayer(guid
);
283 QueuedPlayersMap::iterator itr
;
284 GroupQueueInfo
* group
;
285 QueuedGroupsList::iterator group_itr
;
289 queue_id
= plr
->GetBattleGroundQueueIdFromLevel();
291 itr
= m_QueuedPlayers
[queue_id
].find(guid
);
292 if(itr
!= m_QueuedPlayers
[queue_id
].end())
298 // either player is offline, or he levelled up to another queue category
299 // sLog.outError("Battleground: removing offline player from BG queue - this might not happen, but it should not cause crash");
300 for (uint32 i
= 0; i
< MAX_BATTLEGROUND_QUEUES
; i
++)
302 itr
= m_QueuedPlayers
[i
].find(guid
);
303 if(itr
!= m_QueuedPlayers
[i
].end())
312 // couldn't find the player in bg queue, return
315 sLog
.outError("Battleground: couldn't find player to remove.");
319 group
= itr
->second
.GroupInfo
;
321 for(group_itr
=m_QueuedGroups
[queue_id
].begin(); group_itr
!= m_QueuedGroups
[queue_id
].end(); ++group_itr
)
323 if(group
== (GroupQueueInfo
*)(*group_itr
))
327 // variables are set (what about leveling up when in queue????)
328 // remove player from group
329 // if only player there, remove group
331 // remove player queue info from group queue info
332 std::map
<uint64
, PlayerQueueInfo
*>::iterator pitr
= group
->Players
.find(guid
);
334 if(pitr
!= group
->Players
.end())
335 group
->Players
.erase(pitr
);
337 // check for iterator correctness
338 if (group_itr
!= m_QueuedGroups
[queue_id
].end() && itr
!= m_QueuedPlayers
[queue_id
].end())
340 // used when player left the queue, NOT used when porting to bg
341 if (decreaseInvitedCount
)
343 // if invited to bg, and should decrease invited count, then do it
344 if(group
->IsInvitedToBGInstanceGUID
)
346 BattleGround
* bg
= sBattleGroundMgr
.GetBattleGround(group
->IsInvitedToBGInstanceGUID
);
348 bg
->DecreaseInvitedCount(group
->Team
);
349 if (bg
&& !bg
->GetPlayersSize() && !bg
->GetInvitedCount(ALLIANCE
) && !bg
->GetInvitedCount(HORDE
))
351 // no more players on battleground, set delete it
355 // update the join queue, maybe now the player's group fits in a queue!
356 // not yet implemented (should store bgTypeId in group queue info?)
358 // remove player queue info
359 m_QueuedPlayers
[queue_id
].erase(itr
);
360 // remove group queue info if needed
361 if(group
->Players
.empty())
363 m_QueuedGroups
[queue_id
].erase(group_itr
);
367 // group wasn't empty, so it wasn't deleted, and player have left a rated queue -> everyone from the group should leave too
368 // don't remove recursively if already invited to bg!
369 else if(!group
->IsInvitedToBGInstanceGUID
&& decreaseInvitedCount
&& group
->IsRated
)
371 // remove next player, this is recursive
372 // first send removal information
373 if(Player
*plr2
= objmgr
.GetPlayer(group
->Players
.begin()->first
))
375 BattleGround
* bg
= sBattleGroundMgr
.GetBattleGroundTemplate(group
->BgTypeId
);
376 uint32 bgQueueTypeId
= sBattleGroundMgr
.BGQueueTypeId(group
->BgTypeId
,group
->ArenaType
);
377 uint32 queueSlot
= plr2
->GetBattleGroundQueueIndex(bgQueueTypeId
);
378 plr2
->RemoveBattleGroundQueueId(bgQueueTypeId
); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs
380 sBattleGroundMgr
.BuildBattleGroundStatusPacket(&data
, bg
, plr2
->GetTeam(), queueSlot
, STATUS_NONE
, 0, 0);
381 plr2
->GetSession()->SendPacket(&data
);
383 // then actually delete, this may delete the group as well!
384 RemovePlayer(group
->Players
.begin()->first
,decreaseInvitedCount
);
389 bool BattleGroundQueue::InviteGroupToBG(GroupQueueInfo
* ginfo
, BattleGround
* bg
, uint32 side
)
391 // set side if needed
395 if(!ginfo
->IsInvitedToBGInstanceGUID
)
399 ginfo
->IsInvitedToBGInstanceGUID
= bg
->GetInstanceID();
400 uint32 bgQueueTypeId
= sBattleGroundMgr
.BGQueueTypeId(bg
->GetTypeID(), bg
->GetArenaType());
401 // loop through the players
402 for(std::map
<uint64
,PlayerQueueInfo
*>::iterator itr
= ginfo
->Players
.begin(); itr
!= ginfo
->Players
.end(); ++itr
)
405 itr
->second
->InviteTime
= getMSTime();
406 itr
->second
->LastInviteTime
= getMSTime();
409 Player
* plr
= objmgr
.GetPlayer(itr
->first
);
410 // if offline, skip him
415 sBattleGroundMgr
.InvitePlayer(plr
, bg
->GetInstanceID(),ginfo
->Team
);
419 uint32 queueSlot
= plr
->GetBattleGroundQueueIndex(bgQueueTypeId
);
421 sLog
.outDebug("Battleground: invited plr %s (%u) to BG instance %u queueindex %u bgtype %u, I can't help it if they don't press the enter battle button.",plr
->GetName(),plr
->GetGUIDLow(),bg
->GetInstanceID(),queueSlot
,bg
->GetTypeID());
423 // send status packet
424 sBattleGroundMgr
.BuildBattleGroundStatusPacket(&data
, bg
, side
?side
:plr
->GetTeam(), queueSlot
, STATUS_WAIT_JOIN
, INVITE_ACCEPT_WAIT_TIME
, 0);
425 plr
->GetSession()->SendPacket(&data
);
433 // this function is responsible for the selection of queued groups when trying to create new battlegrounds
434 bool BattleGroundQueue::BuildSelectionPool(uint32 bgTypeId
, uint32 queue_id
, uint32 MinPlayers
, uint32 MaxPlayers
, SelectionPoolBuildMode mode
, uint8 ArenaType
, bool isRated
, uint32 MinRating
, uint32 MaxRating
, uint32 DisregardTime
, uint32 excludeTeam
)
439 case NORMAL_ALLIANCE
:
440 case ONESIDE_ALLIANCE_TEAM1
:
441 case ONESIDE_ALLIANCE_TEAM2
:
445 case ONESIDE_HORDE_TEAM1
:
446 case ONESIDE_HORDE_TEAM2
:
450 //unknown mode, return false
451 sLog
.outDebug("Battleground: unknown selection pool build mode, returning...");
456 // inititate the groups eligible to create the bg
457 m_EligibleGroups
.Init(&(m_QueuedGroups
[queue_id
]), bgTypeId
, side
, MaxPlayers
, ArenaType
, isRated
, MinRating
, MaxRating
, DisregardTime
, excludeTeam
);
458 // init the selected groups (clear)
459 m_SelectionPools
[mode
].Init();
460 while(!(m_EligibleGroups
.empty()))
462 sLog
.outDebug("m_EligibleGroups is not empty, continue building selection pool");
463 // in decreasing group size, add groups to join if they fit in the MaxPlayersPerTeam players
464 for(EligibleGroups::iterator itr
= m_EligibleGroups
.begin(); itr
!=m_EligibleGroups
.end(); ++itr
)
466 // get the maximal not yet checked group
467 GroupQueueInfo
* MaxGroup
= (*itr
);
468 // if it fits in the maxplayer size, add it
469 if( (m_SelectionPools
[mode
].GetPlayerCount() + MaxGroup
->Players
.size()) <= MaxPlayers
)
471 m_SelectionPools
[mode
].AddGroup(MaxGroup
);
474 if(m_SelectionPools
[mode
].GetPlayerCount()>=MinPlayers
)
476 // the selection pool is set, return
477 sLog
.outDebug("pool build succeeded, return true");
480 // if the selection pool's not set, then remove the group with the highest player count, and try again with the rest.
481 GroupQueueInfo
* MaxGroup
= m_SelectionPools
[mode
].GetMaximalGroup();
482 m_EligibleGroups
.RemoveGroup(MaxGroup
);
483 m_SelectionPools
[mode
].RemoveGroup(MaxGroup
);
485 // failed to build a selection pool matching the given values
489 // used to remove the Enter Battle window if the battle has already, but someone still has it
490 // (this can happen in arenas mainly, since the preparation is shorter than the timer for the bgqueueremove event
491 void BattleGroundQueue::BGEndedRemoveInvites(BattleGround
*bg
)
493 uint32 queue_id
= bg
->GetQueueType();
494 uint32 bgInstanceId
= bg
->GetInstanceID();
495 uint32 bgQueueTypeId
= sBattleGroundMgr
.BGQueueTypeId(bg
->GetTypeID(), bg
->GetArenaType());
496 QueuedGroupsList::iterator itr
, next
;
497 for(itr
= m_QueuedGroups
[queue_id
].begin(); itr
!= m_QueuedGroups
[queue_id
].end(); itr
= next
)
499 // must do this way, because the groupinfo will be deleted when all playerinfos are removed
500 GroupQueueInfo
* ginfo
= (*itr
);
503 // if group was invited to this bg instance, then remove all references
504 if(ginfo
->IsInvitedToBGInstanceGUID
== bgInstanceId
)
506 // after removing this much playerinfos, the ginfo will be deleted, so we'll use a for loop
507 uint32 to_remove
= ginfo
->Players
.size();
508 uint32 team
= ginfo
->Team
;
509 for(int i
= 0; i
< to_remove
; ++i
)
511 // always remove the first one in the group
512 std::map
<uint64
, PlayerQueueInfo
* >::iterator itr2
= ginfo
->Players
.begin();
513 if(itr2
== ginfo
->Players
.end())
515 sLog
.outError("Empty Players in ginfo, this should never happen!");
520 Player
* plr
= objmgr
.GetPlayer(itr2
->first
);
523 sLog
.outError("Player offline when trying to remove from GroupQueueInfo, this should never happen.");
528 uint32 queueSlot
= plr
->GetBattleGroundQueueIndex(bgQueueTypeId
);
529 if (queueSlot
< PLAYER_MAX_BATTLEGROUND_QUEUES
) // player is in queue
531 plr
->RemoveBattleGroundQueueId(bgQueueTypeId
);
532 // remove player from queue, this might delete the ginfo as well! don't use that pointer after this!
533 RemovePlayer(itr2
->first
, true);
534 // this is probably unneeded, since this player was already invited -> does not fit when initing eligible groups
535 // but updateing the queue can't hurt
536 Update(bgQueueTypeId
, bg
->GetQueueType());
537 // send info to client
539 sBattleGroundMgr
.BuildBattleGroundStatusPacket(&data
, bg
, team
, queueSlot
, STATUS_NONE
, 0, 0);
540 plr
->GetSession()->SendPacket(&data
);
548 this method is called when group is inserted, or player / group is removed from BG Queue - there is only one player's status changed, so we don't use while(true) cycles to invite whole queue
549 it must be called after fully adding the members of a group to ensure group joining
550 should be called after removeplayer functions in some cases
552 void BattleGroundQueue::Update(uint32 bgTypeId
, uint32 queue_id
, uint8 arenatype
, bool isRated
, uint32 arenaRating
)
554 if (queue_id
>= MAX_BATTLEGROUND_QUEUES
)
556 //this is error, that caused crashes (not in , but now it shouldn't)
557 sLog
.outError("BattleGroundQueue::Update() called for non existing queue type - this can cause crash, pls report problem, if this is the last line of error log before crash");
561 //if no players in queue ... do nothing
562 if (m_QueuedGroups
[queue_id
].empty())
565 uint32 bgQueueTypeId
= sBattleGroundMgr
.BGQueueTypeId(bgTypeId
, arenatype
);
567 //battleground with free slot for player should be always the last in this queue
568 BGFreeSlotQueueType::iterator itr
, next
;
569 for (itr
= sBattleGroundMgr
.BGFreeSlotQueue
[bgTypeId
].begin(); itr
!= sBattleGroundMgr
.BGFreeSlotQueue
[bgTypeId
].end(); itr
= next
)
573 // battleground is running, so if:
574 // DO NOT allow queue manager to invite new player to running arena
575 if ((*itr
)->isBattleGround() && (*itr
)->GetTypeID() == bgTypeId
&& (*itr
)->GetQueueType() == queue_id
&& (*itr
)->GetStatus() > STATUS_WAIT_QUEUE
&& (*itr
)->GetStatus() < STATUS_WAIT_LEAVE
)
577 //we must check both teams
578 BattleGround
* bg
= *itr
; //we have to store battleground pointer here, because when battleground is full, it is removed from free queue (not yet implemented!!)
579 // and iterator is invalid
581 for(QueuedGroupsList::iterator itr
= m_QueuedGroups
[queue_id
].begin(); itr
!= m_QueuedGroups
[queue_id
].end(); ++itr
)
583 // did the group join for this bg type?
584 if((*itr
)->BgTypeId
!= bgTypeId
)
586 // if so, check if fits in
587 if(bg
->GetFreeSlotsForTeam((*itr
)->Team
) >= (*itr
)->Players
.size())
589 // if group fits in, invite it
590 InviteGroupToBG((*itr
),bg
,(*itr
)->Team
);
594 if (!bg
->HasFreeSlots())
596 //remove BG from BGFreeSlotQueue
597 bg
->RemoveFromBGFreeSlotQueue();
602 // finished iterating through the bgs with free slots, maybe we need to create a new bg
604 BattleGround
* bg_template
= sBattleGroundMgr
.GetBattleGroundTemplate(bgTypeId
);
607 sLog
.outError("Battleground: Update: bg template not found for %u", bgTypeId
);
611 // get the min. players per team, properly for larger arenas as well. (must have full teams for arena matches!)
612 uint32 MinPlayersPerTeam
= bg_template
->GetMinPlayersPerTeam();
613 uint32 MaxPlayersPerTeam
= bg_template
->GetMaxPlayersPerTeam();
614 if(bg_template
->isArena())
616 if(sBattleGroundMgr
.isArenaTesting())
618 MaxPlayersPerTeam
= 1;
619 MinPlayersPerTeam
= 1;
626 MaxPlayersPerTeam
= 2;
627 MinPlayersPerTeam
= 2;
630 MaxPlayersPerTeam
= 3;
631 MinPlayersPerTeam
= 3;
634 MaxPlayersPerTeam
= 5;
635 MinPlayersPerTeam
= 5;
641 // found out the minimum and maximum ratings the newly added team should battle against
642 // arenaRating is the rating of the latest joined team
643 uint32 arenaMinRating
= (arenaRating
<= sBattleGroundMgr
.GetMaxRatingDifference()) ? 0 : arenaRating
- sBattleGroundMgr
.GetMaxRatingDifference();
644 // if no rating is specified, set maxrating to 0
645 uint32 arenaMaxRating
= (arenaRating
== 0)? 0 : arenaRating
+ sBattleGroundMgr
.GetMaxRatingDifference();
646 uint32 discardTime
= 0;
647 // if max rating difference is set and the time past since server startup is greater than the rating discard time
648 // (after what time the ratings aren't taken into account when making teams) then
649 // the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account
650 // else leave the discard time on 0, this way all ratings will be discarded
651 if(sBattleGroundMgr
.GetMaxRatingDifference() && getMSTime() >= sBattleGroundMgr
.GetRatingDiscardTimer())
652 discardTime
= getMSTime() - sBattleGroundMgr
.GetRatingDiscardTimer();
654 // try to build the selection pools
655 bool bAllyOK
= BuildSelectionPool(bgTypeId
, queue_id
, MinPlayersPerTeam
, MaxPlayersPerTeam
, NORMAL_ALLIANCE
, arenatype
, isRated
, arenaMinRating
, arenaMaxRating
, discardTime
);
657 sLog
.outDebug("Battleground: ally pool succesfully build");
659 sLog
.outDebug("Battleground: ally pool wasn't created");
660 bool bHordeOK
= BuildSelectionPool(bgTypeId
, queue_id
, MinPlayersPerTeam
, MaxPlayersPerTeam
, NORMAL_HORDE
, arenatype
, isRated
, arenaMinRating
, arenaMaxRating
, discardTime
);
662 sLog
.outDebug("Battleground: horde pool succesfully built");
664 sLog
.outDebug("Battleground: horde pool wasn't created");
666 // if selection pools are ready, create the new bg
667 if (bAllyOK
&& bHordeOK
)
669 BattleGround
* bg2
= 0;
670 // special handling for arenas
671 if(bg_template
->isArena())
673 // Find a random arena, that can be created
674 uint8 arenas
[] = {BATTLEGROUND_NA
, BATTLEGROUND_BE
, BATTLEGROUND_RL
};
675 uint32 arena_num
= urand(0,2);
676 if( !(bg2
= sBattleGroundMgr
.CreateNewBattleGround(arenas
[arena_num
%3])) &&
677 !(bg2
= sBattleGroundMgr
.CreateNewBattleGround(arenas
[(arena_num
+1)%3])) &&
678 !(bg2
= sBattleGroundMgr
.CreateNewBattleGround(arenas
[(arena_num
+2)%3])) )
680 sLog
.outError("Battleground: couldn't create any arena instance!");
684 // set the MaxPlayersPerTeam values based on arenatype
685 // setting the min player values isn't needed, since we won't be using that value later on.
686 if(sBattleGroundMgr
.isArenaTesting())
688 bg2
->SetMaxPlayersPerTeam(1);
689 bg2
->SetMaxPlayers(2);
696 bg2
->SetMaxPlayersPerTeam(2);
697 bg2
->SetMaxPlayers(4);
700 bg2
->SetMaxPlayersPerTeam(3);
701 bg2
->SetMaxPlayers(6);
704 bg2
->SetMaxPlayersPerTeam(5);
705 bg2
->SetMaxPlayers(10);
714 // create new battleground
715 bg2
= sBattleGroundMgr
.CreateNewBattleGround(bgTypeId
);
720 sLog
.outError("Battleground: couldn't create bg %u",bgTypeId
);
724 // start the joining of the bg
725 bg2
->SetStatus(STATUS_WAIT_JOIN
);
726 bg2
->SetQueueType(queue_id
);
727 // initialize arena / rating info
728 bg2
->SetArenaType(arenatype
);
730 bg2
->SetRated(isRated
);
732 std::list
<GroupQueueInfo
* >::iterator itr
;
734 // invite groups from horde selection pool
735 for(itr
= m_SelectionPools
[NORMAL_HORDE
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[NORMAL_HORDE
].SelectedGroups
.end(); ++itr
)
737 InviteGroupToBG((*itr
),bg2
,HORDE
);
740 // invite groups from ally selection pools
741 for(itr
= m_SelectionPools
[NORMAL_ALLIANCE
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[NORMAL_ALLIANCE
].SelectedGroups
.end(); ++itr
)
743 InviteGroupToBG((*itr
),bg2
,ALLIANCE
);
748 std::list
<GroupQueueInfo
* >::iterator itr_alliance
= m_SelectionPools
[NORMAL_ALLIANCE
].SelectedGroups
.begin();
749 std::list
<GroupQueueInfo
* >::iterator itr_horde
= m_SelectionPools
[NORMAL_HORDE
].SelectedGroups
.begin();
750 (*itr_alliance
)->OpponentsTeamRating
= (*itr_horde
)->ArenaTeamRating
;
751 sLog
.outDebug("setting oposite teamrating for team %u to %u", (*itr_alliance
)->ArenaTeamId
, (*itr_alliance
)->OpponentsTeamRating
);
752 (*itr_horde
)->OpponentsTeamRating
= (*itr_alliance
)->ArenaTeamRating
;
753 sLog
.outDebug("setting oposite teamrating for team %u to %u", (*itr_horde
)->ArenaTeamId
, (*itr_horde
)->OpponentsTeamRating
);
756 // start the battleground
757 bg2
->StartBattleGround();
760 // there weren't enough players for a "normal" match
761 // if arena, enable horde versus horde or alliance versus alliance teams here
763 else if(bg_template
->isArena())
765 bool bOneSideHordeTeam1
= false, bOneSideHordeTeam2
= false;
766 bool bOneSideAllyTeam1
= false, bOneSideAllyTeam2
= false;
767 bOneSideHordeTeam1
= BuildSelectionPool(bgTypeId
, queue_id
,MaxPlayersPerTeam
,MaxPlayersPerTeam
,ONESIDE_HORDE_TEAM1
,arenatype
, isRated
, arenaMinRating
, arenaMaxRating
, discardTime
);
768 if(bOneSideHordeTeam1
)
770 // one team has been selected, find out if other can be selected too
771 std::list
<GroupQueueInfo
* >::iterator itr
;
772 // temporarily change the team side to enable building the next pool excluding the already selected groups
773 for(itr
= m_SelectionPools
[ONESIDE_HORDE_TEAM1
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[ONESIDE_HORDE_TEAM1
].SelectedGroups
.end(); ++itr
)
774 (*itr
)->Team
=ALLIANCE
;
776 bOneSideHordeTeam2
= BuildSelectionPool(bgTypeId
, queue_id
,MaxPlayersPerTeam
,MaxPlayersPerTeam
,ONESIDE_HORDE_TEAM2
,arenatype
, isRated
, arenaMinRating
, arenaMaxRating
, discardTime
, (*(m_SelectionPools
[ONESIDE_HORDE_TEAM1
].SelectedGroups
.begin()))->ArenaTeamId
);
778 // change back the team to horde
779 for(itr
= m_SelectionPools
[ONESIDE_HORDE_TEAM1
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[ONESIDE_HORDE_TEAM1
].SelectedGroups
.end(); ++itr
)
782 if(!bOneSideHordeTeam2
)
783 bOneSideHordeTeam1
= false;
785 if(!bOneSideHordeTeam1
)
787 // check for one sided ally
788 bOneSideAllyTeam1
= BuildSelectionPool(bgTypeId
, queue_id
,MaxPlayersPerTeam
,MaxPlayersPerTeam
,ONESIDE_ALLIANCE_TEAM1
,arenatype
, isRated
, arenaMinRating
, arenaMaxRating
, discardTime
);
789 if(bOneSideAllyTeam1
)
791 // one team has been selected, find out if other can be selected too
792 std::list
<GroupQueueInfo
* >::iterator itr
;
793 // temporarily change the team side to enable building the next pool excluding the already selected groups
794 for(itr
= m_SelectionPools
[ONESIDE_ALLIANCE_TEAM1
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[ONESIDE_ALLIANCE_TEAM1
].SelectedGroups
.end(); ++itr
)
797 bOneSideAllyTeam2
= BuildSelectionPool(bgTypeId
, queue_id
,MaxPlayersPerTeam
,MaxPlayersPerTeam
,ONESIDE_ALLIANCE_TEAM2
,arenatype
, isRated
, arenaMinRating
, arenaMaxRating
, discardTime
,(*(m_SelectionPools
[ONESIDE_ALLIANCE_TEAM1
].SelectedGroups
.begin()))->ArenaTeamId
);
799 // change back the team to ally
800 for(itr
= m_SelectionPools
[ONESIDE_ALLIANCE_TEAM1
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[ONESIDE_ALLIANCE_TEAM1
].SelectedGroups
.end(); ++itr
)
801 (*itr
)->Team
=ALLIANCE
;
804 if(!bOneSideAllyTeam2
)
805 bOneSideAllyTeam1
= false;
807 // 1-sided BuildSelectionPool() will work, because the MinPlayersPerTeam == MaxPlayersPerTeam in every arena!!!!
808 if( (bOneSideHordeTeam1
&& bOneSideHordeTeam2
) ||
809 (bOneSideAllyTeam1
&& bOneSideAllyTeam2
) )
811 // which side has enough players?
813 SelectionPoolBuildMode mode1
, mode2
;
814 // find out what pools are we using
815 if(bOneSideAllyTeam1
&& bOneSideAllyTeam2
)
818 mode1
= ONESIDE_ALLIANCE_TEAM1
;
819 mode2
= ONESIDE_ALLIANCE_TEAM2
;
824 mode1
= ONESIDE_HORDE_TEAM1
;
825 mode2
= ONESIDE_HORDE_TEAM2
;
828 // create random arena
829 uint8 arenas
[] = {BATTLEGROUND_NA
, BATTLEGROUND_BE
, BATTLEGROUND_RL
};
830 uint32 arena_num
= urand(0,2);
831 BattleGround
* bg2
= NULL
;
832 if( !(bg2
= sBattleGroundMgr
.CreateNewBattleGround(arenas
[arena_num
%3])) &&
833 !(bg2
= sBattleGroundMgr
.CreateNewBattleGround(arenas
[(arena_num
+1)%3])) &&
834 !(bg2
= sBattleGroundMgr
.CreateNewBattleGround(arenas
[(arena_num
+2)%3])) )
836 sLog
.outError("Could not create arena.");
840 sLog
.outDebug("Battleground: One-faction arena created.");
842 if(sBattleGroundMgr
.isArenaTesting())
844 bg2
->SetMaxPlayersPerTeam(1);
845 bg2
->SetMaxPlayers(2);
852 bg2
->SetMaxPlayersPerTeam(2);
853 bg2
->SetMaxPlayers(4);
856 bg2
->SetMaxPlayersPerTeam(3);
857 bg2
->SetMaxPlayers(6);
860 bg2
->SetMaxPlayersPerTeam(5);
861 bg2
->SetMaxPlayers(10);
868 bg2
->SetRated(isRated
);
870 // assigned team of the other group
875 other_side
= ALLIANCE
;
877 // start the joining of the bg
878 bg2
->SetStatus(STATUS_WAIT_JOIN
);
879 bg2
->SetQueueType(queue_id
);
880 // initialize arena / rating info
881 bg2
->SetArenaType(arenatype
);
883 std::list
<GroupQueueInfo
* >::iterator itr
;
885 // invite players from the first group as horde players (actually green team)
886 for(itr
= m_SelectionPools
[mode1
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[mode1
].SelectedGroups
.end(); ++itr
)
888 InviteGroupToBG((*itr
),bg2
,HORDE
);
891 // invite players from the second group as ally players (actually gold team)
892 for(itr
= m_SelectionPools
[mode2
].SelectedGroups
.begin(); itr
!= m_SelectionPools
[mode2
].SelectedGroups
.end(); ++itr
)
894 InviteGroupToBG((*itr
),bg2
,ALLIANCE
);
899 std::list
<GroupQueueInfo
* >::iterator itr_alliance
= m_SelectionPools
[mode1
].SelectedGroups
.begin();
900 std::list
<GroupQueueInfo
* >::iterator itr_horde
= m_SelectionPools
[mode2
].SelectedGroups
.begin();
901 (*itr_alliance
)->OpponentsTeamRating
= (*itr_horde
)->ArenaTeamRating
;
902 (*itr_horde
)->OpponentsTeamRating
= (*itr_alliance
)->ArenaTeamRating
;
905 bg2
->StartBattleGround();
910 /*********************************************************/
911 /*** BATTLEGROUND QUEUE EVENTS ***/
912 /*********************************************************/
914 bool BGQueueInviteEvent::Execute(uint64
/*e_time*/, uint32
/*p_time*/)
916 Player
* plr
= objmgr
.GetPlayer( m_PlayerGuid
);
918 // player logged off (we should do nothing, he is correctly removed from queue in another procedure)
922 // Player can be in another BG queue and must be removed in normal way in any case
923 // // player is already in battleground ... do nothing (battleground queue status is deleted when player is teleported to BG)
924 // if (plr->GetBattleGroundId() > 0)
927 BattleGround
* bg
= sBattleGroundMgr
.GetBattleGround(m_BgInstanceGUID
);
931 uint32 queueSlot
= plr
->GetBattleGroundQueueIndex(bg
->GetTypeID());
932 if (queueSlot
< PLAYER_MAX_BATTLEGROUND_QUEUES
) // player is in queue
934 uint32 bgQueueTypeId
= sBattleGroundMgr
.BGQueueTypeId(bg
->GetTypeID(), bg
->GetArenaType());
935 uint32 queueSlot
= plr
->GetBattleGroundQueueIndex(bgQueueTypeId
);
936 if (queueSlot
< PLAYER_MAX_BATTLEGROUND_QUEUES
) // player is in queue
938 // check if player is invited to this bg ... this check must be here, because when player leaves queue and joins another, it would cause a problems
939 BattleGroundQueue::QueuedPlayersMap
const& qpMap
= sBattleGroundMgr
.m_BattleGroundQueues
[bgQueueTypeId
].m_QueuedPlayers
[plr
->GetBattleGroundQueueIdFromLevel()];
940 BattleGroundQueue::QueuedPlayersMap::const_iterator qItr
= qpMap
.find(m_PlayerGuid
);
941 if (qItr
!= qpMap
.end() && qItr
->second
.GroupInfo
->IsInvitedToBGInstanceGUID
== m_BgInstanceGUID
)
944 sBattleGroundMgr
.BuildBattleGroundStatusPacket(&data
, bg
, qItr
->second
.GroupInfo
->Team
, queueSlot
, STATUS_WAIT_JOIN
, INVITE_ACCEPT_WAIT_TIME
/2, 0);
945 plr
->GetSession()->SendPacket(&data
);
949 return true; //event will be deleted
952 void BGQueueInviteEvent::Abort(uint64
/*e_time*/)
954 //this should not be called
955 sLog
.outError("Battleground invite event ABORTED!");
958 bool BGQueueRemoveEvent::Execute(uint64
/*e_time*/, uint32
/*p_time*/)
960 Player
* plr
= objmgr
.GetPlayer( m_PlayerGuid
);
962 // player logged off (we should do nothing, he is correctly removed from queue in another procedure)
965 BattleGround
* bg
= sBattleGroundMgr
.GetBattleGround(m_BgInstanceGUID
);
969 sLog
.outDebug("Battleground: removing player %u from bg queue for instance %u because of not pressing enter battle in time.",plr
->GetGUIDLow(),m_BgInstanceGUID
);
971 uint32 bgQueueTypeId
= sBattleGroundMgr
.BGQueueTypeId(bg
->GetTypeID(), bg
->GetArenaType());
972 uint32 queueSlot
= plr
->GetBattleGroundQueueIndex(bgQueueTypeId
);
973 if (queueSlot
< PLAYER_MAX_BATTLEGROUND_QUEUES
) // player is in queue
975 // check if player is invited to this bg ... this check must be here, because when player leaves queue and joins another, it would cause a problems
976 BattleGroundQueue::QueuedPlayersMap::iterator qMapItr
= sBattleGroundMgr
.m_BattleGroundQueues
[bgQueueTypeId
].m_QueuedPlayers
[plr
->GetBattleGroundQueueIdFromLevel()].find(m_PlayerGuid
);
977 if (qMapItr
!= sBattleGroundMgr
.m_BattleGroundQueues
[bgQueueTypeId
].m_QueuedPlayers
[plr
->GetBattleGroundQueueIdFromLevel()].end() && qMapItr
->second
.GroupInfo
&& qMapItr
->second
.GroupInfo
->IsInvitedToBGInstanceGUID
== m_BgInstanceGUID
)
979 if (qMapItr
->second
.GroupInfo
->IsRated
)
981 ArenaTeam
* at
= objmgr
.GetArenaTeamById(qMapItr
->second
.GroupInfo
->ArenaTeamId
);
984 sLog
.outDebug("UPDATING memberLost's personal arena rating for %u by opponents rating: %u", GUID_LOPART(plr
->GetGUID()), qMapItr
->second
.GroupInfo
->OpponentsTeamRating
);
985 at
->MemberLost(plr
, qMapItr
->second
.GroupInfo
->OpponentsTeamRating
);
989 plr
->RemoveBattleGroundQueueId(bgQueueTypeId
);
990 sBattleGroundMgr
.m_BattleGroundQueues
[bgQueueTypeId
].RemovePlayer(m_PlayerGuid
, true);
991 sBattleGroundMgr
.m_BattleGroundQueues
[bgQueueTypeId
].Update(bgQueueTypeId
, bg
->GetQueueType());
993 sBattleGroundMgr
.BuildBattleGroundStatusPacket(&data
, bg
, m_PlayersTeam
, queueSlot
, STATUS_NONE
, 0, 0);
994 plr
->GetSession()->SendPacket(&data
);
998 sLog
.outDebug("Battleground: Player was already removed from queue");
1000 //event will be deleted
1004 void BGQueueRemoveEvent::Abort(uint64
/*e_time*/)
1006 //this should not be called
1007 sLog
.outError("Battleground remove event ABORTED!");
1010 /*********************************************************/
1011 /*** BATTLEGROUND MANAGER ***/
1012 /*********************************************************/
1014 BattleGroundMgr::BattleGroundMgr()
1016 m_BattleGrounds
.clear();
1017 m_AutoDistributePoints
= (bool)sWorld
.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_POINTS
);
1018 m_MaxRatingDifference
= sWorld
.getConfig(CONFIG_ARENA_MAX_RATING_DIFFERENCE
);
1019 m_RatingDiscardTimer
= sWorld
.getConfig(CONFIG_ARENA_RATING_DISCARD_TIMER
);
1020 m_PrematureFinishTimer
= sWorld
.getConfig(CONFIG_BATTLEGROUND_PREMATURE_FINISH_TIMER
);
1021 m_NextRatingDiscardUpdate
= m_RatingDiscardTimer
;
1022 m_AutoDistributionTimeChecker
= 0;
1023 m_ArenaTesting
= false;
1026 BattleGroundMgr::~BattleGroundMgr()
1028 BattleGroundSet::iterator itr
, next
;
1029 for(itr
= m_BattleGrounds
.begin(); itr
!= m_BattleGrounds
.end(); itr
= next
)
1033 BattleGround
* bg
= itr
->second
;
1034 m_BattleGrounds
.erase(itr
);
1037 m_BattleGrounds
.clear();
1040 // used to update running battlegrounds, and delete finished ones
1041 void BattleGroundMgr::Update(time_t diff
)
1043 BattleGroundSet::iterator itr
, next
;
1044 for(itr
= m_BattleGrounds
.begin(); itr
!= m_BattleGrounds
.end(); itr
= next
)
1048 itr
->second
->Update(diff
);
1049 // use the SetDeleteThis variable
1050 // direct deletion caused crashes
1051 if(itr
->second
->m_SetDeleteThis
)
1053 BattleGround
* bg
= itr
->second
;
1054 m_BattleGrounds
.erase(itr
);
1058 // if rating difference counts, maybe force-update queues
1059 if(m_MaxRatingDifference
)
1061 // it's time to force update
1062 if(m_NextRatingDiscardUpdate
< diff
)
1064 // forced update for level 70 rated arenas
1065 m_BattleGroundQueues
[BATTLEGROUND_QUEUE_2v2
].Update(BATTLEGROUND_AA
,6,ARENA_TYPE_2v2
,true,0);
1066 m_BattleGroundQueues
[BATTLEGROUND_QUEUE_3v3
].Update(BATTLEGROUND_AA
,6,ARENA_TYPE_3v3
,true,0);
1067 m_BattleGroundQueues
[BATTLEGROUND_QUEUE_5v5
].Update(BATTLEGROUND_AA
,6,ARENA_TYPE_5v5
,true,0);
1068 m_NextRatingDiscardUpdate
= m_RatingDiscardTimer
;
1071 m_NextRatingDiscardUpdate
-= diff
;
1073 if(m_AutoDistributePoints
)
1075 if(m_AutoDistributionTimeChecker
< diff
)
1077 if(sWorld
.GetGameTime() > m_NextAutoDistributionTime
)
1079 DistributeArenaPoints();
1080 m_NextAutoDistributionTime
= sWorld
.GetGameTime() + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY
* sWorld
.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS
);
1081 CharacterDatabase
.PExecute("UPDATE saved_variables SET NextArenaPointDistributionTime = '"I64FMTD
"'", m_NextAutoDistributionTime
);
1083 m_AutoDistributionTimeChecker
= 600000; // check 10 minutes
1086 m_AutoDistributionTimeChecker
-= diff
;
1090 void BattleGroundMgr::BuildBattleGroundStatusPacket(WorldPacket
*data
, BattleGround
*bg
, uint32 team
, uint8 QueueSlot
, uint8 StatusID
, uint32 Time1
, uint32 Time2
, uint32 arenatype
, uint8 israted
)
1092 // we can be in 3 queues in same time...
1095 data
->Initialize(SMSG_BATTLEFIELD_STATUS
, 4*3);
1096 *data
<< uint32(QueueSlot
); // queue id (0...2)
1101 data
->Initialize(SMSG_BATTLEFIELD_STATUS
, (4+1+1+4+2+4+1+4+4+4));
1102 *data
<< uint32(QueueSlot
); // queue id (0...2) - player can be in 3 queues in time
1104 *data
<< uint64( uint64(arenatype
? arenatype
: bg
->GetArenaType()) | (uint64(0x0D) << 8) | (uint64(bg
->GetTypeID()) << 16) | (uint64(0x1F90) << 48) );
1105 *data
<< uint32(0); // unknown
1106 // alliance/horde for BG and skirmish/rated for Arenas
1107 *data
<< uint8(bg
->isArena() ? ( israted
? israted
: bg
->isRated() ) : bg
->GetTeamIndexByTeamId(team
));
1108 /* *data << uint8(arenatype ? arenatype : bg->GetArenaType()); // team type (0=BG, 2=2x2, 3=3x3, 5=5x5), for arenas // NOT PROPER VALUE IF ARENA ISN'T RUNNING YET!!!!
1109 switch(bg->GetTypeID()) // value depends on bg id
1111 case BATTLEGROUND_AV:
1114 case BATTLEGROUND_WS:
1117 case BATTLEGROUND_AB:
1120 case BATTLEGROUND_NA:
1123 case BATTLEGROUND_BE:
1126 case BATTLEGROUND_AA:
1129 case BATTLEGROUND_EY:
1132 case BATTLEGROUND_RL:
1140 if(bg->isArena() && (StatusID == STATUS_WAIT_QUEUE))
1141 *data << uint32(BATTLEGROUND_AA); // all arenas I don't think so.
1143 *data << uint32(bg->GetTypeID()); // BG id from DBC
1145 *data << uint16(0x1F90); // unk value 8080
1146 *data << uint32(bg->GetInstanceID()); // instance id
1148 if(bg->isBattleGround())
1149 *data << uint8(bg->GetTeamIndexByTeamId(team)); // team
1151 *data << uint8(israted?israted:bg->isRated()); // is rated battle
1153 *data
<< uint32(StatusID
); // status
1156 case STATUS_WAIT_QUEUE
: // status_in_queue
1157 *data
<< uint32(Time1
); // average wait time, milliseconds
1158 *data
<< uint32(Time2
); // time in queue, updated every minute?
1160 case STATUS_WAIT_JOIN
: // status_invite
1161 *data
<< uint32(bg
->GetMapId()); // map id
1162 *data
<< uint32(Time1
); // time to remove from queue, milliseconds
1164 case STATUS_IN_PROGRESS
: // status_in_progress
1165 *data
<< uint32(bg
->GetMapId()); // map id
1166 *data
<< uint32(Time1
); // 0 at bg start, 120000 after bg end, time to bg auto leave, milliseconds
1167 *data
<< uint32(Time2
); // time from bg start, milliseconds
1168 *data
<< uint8(0x1); // unk sometimes 0x0!
1171 sLog
.outError("Unknown BG status!");
1176 void BattleGroundMgr::BuildPvpLogDataPacket(WorldPacket
*data
, BattleGround
*bg
)
1178 uint8 type
= (bg
->isArena() ? 1 : 0);
1179 // last check on 2.4.1
1180 data
->Initialize(MSG_PVP_LOG_DATA
, (1+1+4+40*bg
->GetPlayerScoresSize()));
1181 *data
<< uint8(type
); // seems to be type (battleground=0/arena=1)
1185 // it seems this must be according to BG_WINNER_A/H and _NOT_ BG_TEAM_A/H
1186 for(int i
= 1; i
>= 0; --i
)
1188 *data
<< uint32(3000-bg
->m_ArenaTeamRatingChanges
[i
]); // rating change: showed value - 3000
1189 *data
<< uint32(3999); // huge thanks for TOM_RUS for this!
1190 sLog
.outDebug("rating change: %d", bg
->m_ArenaTeamRatingChanges
[i
]);
1192 for(int i
= 1; i
>= 0; --i
)
1194 uint32 at_id
= bg
->m_ArenaTeamIds
[i
];
1195 ArenaTeam
* at
= objmgr
.GetArenaTeamById(at_id
);
1197 *data
<< at
->GetName();
1203 if(bg
->GetWinner() == 2)
1205 *data
<< uint8(0); // bg in progress
1209 *data
<< uint8(1); // bg ended
1210 *data
<< uint8(bg
->GetWinner()); // who win
1213 *data
<< (int32
)(bg
->GetPlayerScoresSize());
1215 for(std::map
<uint64
, BattleGroundScore
*>::const_iterator itr
= bg
->GetPlayerScoresBegin(); itr
!= bg
->GetPlayerScoresEnd(); ++itr
)
1217 *data
<< (uint64
)itr
->first
;
1218 *data
<< (int32
)itr
->second
->KillingBlows
;
1219 Player
*plr
= objmgr
.GetPlayer(itr
->first
);
1220 uint32 team
= bg
->GetPlayerTeam(itr
->first
);
1221 if(!team
&& plr
) team
= plr
->GetTeam();
1224 *data
<< (int32
)itr
->second
->HonorableKills
;
1225 *data
<< (int32
)itr
->second
->Deaths
;
1226 *data
<< (int32
)(itr
->second
->BonusHonor
);
1230 // that part probably wrong
1235 else if(team
== ALLIANCE
)
1245 *data
<< (int32
)itr
->second
->DamageDone
; // damage done
1246 *data
<< (int32
)itr
->second
->HealingDone
; // healing done
1247 switch(bg
->GetTypeID()) // battleground specific things
1249 case BATTLEGROUND_AV
:
1250 *data
<< (uint32
)0x00000005; // count of next fields
1251 *data
<< (uint32
)((BattleGroundAVScore
*)itr
->second
)->GraveyardsAssaulted
; // GraveyardsAssaulted
1252 *data
<< (uint32
)((BattleGroundAVScore
*)itr
->second
)->GraveyardsDefended
; // GraveyardsDefended
1253 *data
<< (uint32
)((BattleGroundAVScore
*)itr
->second
)->TowersAssaulted
; // TowersAssaulted
1254 *data
<< (uint32
)((BattleGroundAVScore
*)itr
->second
)->TowersDefended
; // TowersDefended
1255 *data
<< (uint32
)((BattleGroundAVScore
*)itr
->second
)->MinesCaptured
; // MinesCaptured
1257 case BATTLEGROUND_WS
:
1258 *data
<< (uint32
)0x00000002; // count of next fields
1259 *data
<< (uint32
)((BattleGroundWGScore
*)itr
->second
)->FlagCaptures
; // flag captures
1260 *data
<< (uint32
)((BattleGroundWGScore
*)itr
->second
)->FlagReturns
; // flag returns
1262 case BATTLEGROUND_AB
:
1263 *data
<< (uint32
)0x00000002; // count of next fields
1264 *data
<< (uint32
)((BattleGroundABScore
*)itr
->second
)->BasesAssaulted
; // bases asssulted
1265 *data
<< (uint32
)((BattleGroundABScore
*)itr
->second
)->BasesDefended
; // bases defended
1267 case BATTLEGROUND_EY
:
1268 *data
<< (uint32
)0x00000001; // count of next fields
1269 *data
<< (uint32
)((BattleGroundEYScore
*)itr
->second
)->FlagCaptures
; // flag captures
1271 case BATTLEGROUND_NA
:
1272 case BATTLEGROUND_BE
:
1273 case BATTLEGROUND_AA
:
1274 case BATTLEGROUND_RL
:
1275 *data
<< (int32
)0; // 0
1278 sLog
.outDebug("Unhandled MSG_PVP_LOG_DATA for BG id %u", bg
->GetTypeID());
1285 void BattleGroundMgr::BuildGroupJoinedBattlegroundPacket(WorldPacket
*data
, uint32 bgTypeId
)
1288 0 - Your group has joined a battleground queue, but you are not eligible
1289 1 - Your group has joined the queue for AV
1290 2 - Your group has joined the queue for WS
1291 3 - Your group has joined the queue for AB
1292 4 - Your group has joined the queue for NA
1293 5 - Your group has joined the queue for BE Arena
1294 6 - Your group has joined the queue for All Arenas
1295 7 - Your group has joined the queue for EotS*/
1296 data
->Initialize(SMSG_GROUP_JOINED_BATTLEGROUND
, 4);
1297 *data
<< uint32(bgTypeId
);
1300 void BattleGroundMgr::BuildUpdateWorldStatePacket(WorldPacket
*data
, uint32 field
, uint32 value
)
1302 data
->Initialize(SMSG_UPDATE_WORLD_STATE
, 4+4);
1303 *data
<< uint32(field
);
1304 *data
<< uint32(value
);
1307 void BattleGroundMgr::BuildPlaySoundPacket(WorldPacket
*data
, uint32 soundid
)
1309 data
->Initialize(SMSG_PLAY_SOUND
, 4);
1310 *data
<< uint32(soundid
);
1313 void BattleGroundMgr::BuildPlayerLeftBattleGroundPacket(WorldPacket
*data
, Player
*plr
)
1315 data
->Initialize(SMSG_BATTLEGROUND_PLAYER_LEFT
, 8);
1316 *data
<< uint64(plr
->GetGUID());
1319 void BattleGroundMgr::BuildPlayerJoinedBattleGroundPacket(WorldPacket
*data
, Player
*plr
)
1321 data
->Initialize(SMSG_BATTLEGROUND_PLAYER_JOINED
, 8);
1322 *data
<< uint64(plr
->GetGUID());
1325 void BattleGroundMgr::InvitePlayer(Player
* plr
, uint32 bgInstanceGUID
, uint32 team
)
1327 // set invited player counters:
1328 BattleGround
* bg
= GetBattleGround(bgInstanceGUID
);
1331 bg
->IncreaseInvitedCount(team
);
1333 plr
->SetInviteForBattleGroundQueueType(BGQueueTypeId(bg
->GetTypeID(),bg
->GetArenaType()), bgInstanceGUID
);
1335 // set the arena teams for rated matches
1336 if(bg
->isArena() && bg
->isRated())
1338 switch(bg
->GetArenaType())
1340 case ARENA_TYPE_2v2
:
1341 bg
->SetArenaTeamIdForTeam(team
, plr
->GetArenaTeamId(0));
1343 case ARENA_TYPE_3v3
:
1344 bg
->SetArenaTeamIdForTeam(team
, plr
->GetArenaTeamId(1));
1346 case ARENA_TYPE_5v5
:
1347 bg
->SetArenaTeamIdForTeam(team
, plr
->GetArenaTeamId(2));
1354 // create invite events:
1355 //add events to player's counters ---- this is not good way - there should be something like global event processor, where we should add those events
1356 BGQueueInviteEvent
* inviteEvent
= new BGQueueInviteEvent(plr
->GetGUID(), bgInstanceGUID
);
1357 plr
->m_Events
.AddEvent(inviteEvent
, plr
->m_Events
.CalculateTime(INVITE_ACCEPT_WAIT_TIME
/2));
1358 BGQueueRemoveEvent
* removeEvent
= new BGQueueRemoveEvent(plr
->GetGUID(), bgInstanceGUID
, team
);
1359 plr
->m_Events
.AddEvent(removeEvent
, plr
->m_Events
.CalculateTime(INVITE_ACCEPT_WAIT_TIME
));
1362 BattleGround
* BattleGroundMgr::GetBattleGroundTemplate(uint32 bgTypeId
)
1364 return BGFreeSlotQueue
[bgTypeId
].empty() ? NULL
: BGFreeSlotQueue
[bgTypeId
].back();
1367 // create a new battleground that will really be used to play
1368 BattleGround
* BattleGroundMgr::CreateNewBattleGround(uint32 bgTypeId
)
1370 BattleGround
*bg
= NULL
;
1372 // get the template BG
1373 BattleGround
*bg_template
= GetBattleGroundTemplate(bgTypeId
);
1377 sLog
.outError("BattleGround: CreateNewBattleGround - bg template not found for %u", bgTypeId
);
1381 // create a copy of the BG template
1384 case BATTLEGROUND_AV
:
1385 bg
= new BattleGroundAV(*(BattleGroundAV
*)bg_template
);
1387 case BATTLEGROUND_WS
:
1388 bg
= new BattleGroundWS(*(BattleGroundWS
*)bg_template
);
1390 case BATTLEGROUND_AB
:
1391 bg
= new BattleGroundAB(*(BattleGroundAB
*)bg_template
);
1393 case BATTLEGROUND_NA
:
1394 bg
= new BattleGroundNA(*(BattleGroundNA
*)bg_template
);
1396 case BATTLEGROUND_BE
:
1397 bg
= new BattleGroundBE(*(BattleGroundBE
*)bg_template
);
1399 case BATTLEGROUND_AA
:
1400 bg
= new BattleGroundAA(*(BattleGroundAA
*)bg_template
);
1402 case BATTLEGROUND_EY
:
1403 bg
= new BattleGroundEY(*(BattleGroundEY
*)bg_template
);
1405 case BATTLEGROUND_RL
:
1406 bg
= new BattleGroundRL(*(BattleGroundRL
*)bg_template
);
1409 //bg = new BattleGround;
1411 break; // placeholder for non implemented BG
1414 // generate a new instance id
1415 bg
->SetInstanceID(MapManager::Instance().GenerateInstanceId()); // set instance id
1417 // reset the new bg (set status to status_wait_queue from status_none)
1420 /* will be setup in BG::Update() when the first player is ported in
1421 if(!(bg->SetupBattleGround()))
1423 sLog.outError("BattleGround: CreateNewBattleGround: SetupBattleGround failed for bg %u", bgTypeId);
1429 // add BG to free slot queue
1430 bg
->AddToBGFreeSlotQueue();
1432 // add bg to update list
1433 AddBattleGround(bg
->GetInstanceID(), bg
);
1438 // used to create the BG templates
1439 uint32
BattleGroundMgr::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
)
1442 BattleGround
*bg
= NULL
;
1446 case BATTLEGROUND_AV
: bg
= new BattleGroundAV
; break;
1447 case BATTLEGROUND_WS
: bg
= new BattleGroundWS
; break;
1448 case BATTLEGROUND_AB
: bg
= new BattleGroundAB
; break;
1449 case BATTLEGROUND_NA
: bg
= new BattleGroundNA
; break;
1450 case BATTLEGROUND_BE
: bg
= new BattleGroundBE
; break;
1451 case BATTLEGROUND_AA
: bg
= new BattleGroundAA
; break;
1452 case BATTLEGROUND_EY
: bg
= new BattleGroundEY
; break;
1453 case BATTLEGROUND_RL
: bg
= new BattleGroundRL
; break;
1454 default:bg
= new BattleGround
; break; // placeholder for non implemented BG
1457 bg
->SetMapId(MapID
);
1461 BattlemasterListEntry
const *bl
= sBattlemasterListStore
.LookupEntry(bgTypeId
);
1462 //in previous method is checked if exists entry in sBattlemasterListStore, so no check needed
1465 bg
->SetArenaorBGType(bl
->type
== TYPE_ARENA
);
1468 bg
->SetTypeID(bgTypeId
);
1469 bg
->SetInstanceID(0); // template bg, instance id is 0
1470 bg
->SetMinPlayersPerTeam(MinPlayersPerTeam
);
1471 bg
->SetMaxPlayersPerTeam(MaxPlayersPerTeam
);
1472 bg
->SetMinPlayers(MinPlayersPerTeam
*2);
1473 bg
->SetMaxPlayers(MaxPlayersPerTeam
*2);
1474 bg
->SetName(BattleGroundName
);
1475 bg
->SetTeamStartLoc(ALLIANCE
, Team1StartLocX
, Team1StartLocY
, Team1StartLocZ
, Team1StartLocO
);
1476 bg
->SetTeamStartLoc(HORDE
, Team2StartLocX
, Team2StartLocY
, Team2StartLocZ
, Team2StartLocO
);
1477 bg
->SetLevelRange(LevelMin
, LevelMax
);
1479 //add BattleGround instance to FreeSlotQueue (.back() will return the template!)
1480 bg
->AddToBGFreeSlotQueue();
1482 // do NOT add to update list, since this is a template battleground!
1484 // return some not-null value, bgTypeId is good enough for me
1488 void BattleGroundMgr::CreateInitialBattleGrounds()
1492 uint32 MaxPlayersPerTeam
, MinPlayersPerTeam
, MinLvl
, MaxLvl
, start1
, start2
;
1493 BattlemasterListEntry
const *bl
;
1494 WorldSafeLocsEntry
const *start
;
1498 // 0 1 2 3 4 5 6 7 8
1499 QueryResult
*result
= WorldDatabase
.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO FROM battleground_template");
1508 sLog
.outErrorDb(">> Loaded 0 battlegrounds. DB table `battleground_template` is empty.");
1512 barGoLink
bar(result
->GetRowCount());
1516 Field
*fields
= result
->Fetch();
1519 uint32 bgTypeID
= fields
[0].GetUInt32();
1521 // can be overwrited by values from DB
1522 bl
= sBattlemasterListStore
.LookupEntry(bgTypeID
);
1525 sLog
.outError("Battleground ID %u not found in BattlemasterList.dbc. Battleground not created.",bgTypeID
);
1529 MaxPlayersPerTeam
= bl
->maxplayersperteam
;
1530 MinPlayersPerTeam
= bl
->maxplayersperteam
/2;
1531 MinLvl
= bl
->minlvl
;
1532 MaxLvl
= bl
->maxlvl
;
1534 if(fields
[1].GetUInt32())
1535 MinPlayersPerTeam
= fields
[1].GetUInt32();
1537 if(fields
[2].GetUInt32())
1538 MaxPlayersPerTeam
= fields
[2].GetUInt32();
1540 if(fields
[3].GetUInt32())
1541 MinLvl
= fields
[3].GetUInt32();
1543 if(fields
[4].GetUInt32())
1544 MaxLvl
= fields
[4].GetUInt32();
1546 start1
= fields
[5].GetUInt32();
1548 start
= sWorldSafeLocsStore
.LookupEntry(start1
);
1551 AStartLoc
[0] = start
->x
;
1552 AStartLoc
[1] = start
->y
;
1553 AStartLoc
[2] = start
->z
;
1554 AStartLoc
[3] = fields
[6].GetFloat();
1556 else if(bgTypeID
== BATTLEGROUND_AA
)
1561 AStartLoc
[3] = fields
[6].GetFloat();
1565 sLog
.outErrorDb("Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `AllianceStartLoc`. BG not created.",bgTypeID
,start1
);
1569 start2
= fields
[7].GetUInt32();
1571 start
= sWorldSafeLocsStore
.LookupEntry(start2
);
1574 HStartLoc
[0] = start
->x
;
1575 HStartLoc
[1] = start
->y
;
1576 HStartLoc
[2] = start
->z
;
1577 HStartLoc
[3] = fields
[8].GetFloat();
1579 else if(bgTypeID
== BATTLEGROUND_AA
)
1584 HStartLoc
[3] = fields
[8].GetFloat();
1588 sLog
.outErrorDb("Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `HordeStartLoc`. BG not created.",bgTypeID
,start2
);
1592 //sLog.outDetail("Creating battleground %s, %u-%u", bl->name[sWorld.GetDBClang()], MinLvl, MaxLvl);
1593 if(!CreateBattleGround(bgTypeID
, MinPlayersPerTeam
, MaxPlayersPerTeam
, MinLvl
, MaxLvl
, bl
->name
[sWorld
.GetDefaultDbcLocale()], bl
->mapid
[0], AStartLoc
[0], AStartLoc
[1], AStartLoc
[2], AStartLoc
[3], HStartLoc
[0], HStartLoc
[1], HStartLoc
[2], HStartLoc
[3]))
1597 } while (result
->NextRow());
1602 sLog
.outString( ">> Loaded %u battlegrounds", count
);
1605 void BattleGroundMgr::InitAutomaticArenaPointDistribution()
1607 if(m_AutoDistributePoints
)
1609 sLog
.outDebug("Initializing Automatic Arena Point Distribution");
1610 QueryResult
* result
= CharacterDatabase
.Query("SELECT NextArenaPointDistributionTime FROM saved_variables");
1613 sLog
.outDebug("Battleground: Next arena point distribution time not found in SavedVariables, reseting it now.");
1614 m_NextAutoDistributionTime
= sWorld
.GetGameTime() + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY
* sWorld
.getConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS
);
1615 CharacterDatabase
.PExecute("INSERT INTO saved_variables (NextArenaPointDistributionTime) VALUES ('"I64FMTD
"')", m_NextAutoDistributionTime
);
1619 m_NextAutoDistributionTime
= (*result
)[0].GetUInt64();
1622 sLog
.outDebug("Automatic Arena Point Distribution initialized.");
1626 void BattleGroundMgr::DistributeArenaPoints()
1628 // used to distribute arena points based on last week's stats
1629 sWorld
.SendGlobalText("Flushing Arena points based on team ratings, this may take a few minutes. Please stand by...", NULL
);
1631 sWorld
.SendGlobalText("Distributing arena points to players...", NULL
);
1633 //temporary structure for storing maximum points to add values for all players
1634 std::map
<uint32
, uint32
> PlayerPoints
;
1636 //at first update all points for all team members
1637 for(ObjectMgr::ArenaTeamMap::iterator team_itr
= objmgr
.GetArenaTeamMapBegin(); team_itr
!= objmgr
.GetArenaTeamMapEnd(); ++team_itr
)
1639 if(ArenaTeam
* at
= team_itr
->second
)
1641 at
->UpdateArenaPointsHelper(PlayerPoints
);
1645 //cycle that gives points to all players
1646 for (std::map
<uint32
, uint32
>::iterator plr_itr
= PlayerPoints
.begin(); plr_itr
!= PlayerPoints
.end(); ++plr_itr
)
1648 //update to database
1649 CharacterDatabase
.PExecute("UPDATE characters SET arena_pending_points = '%u' WHERE `guid` = '%u'", plr_itr
->second
, plr_itr
->first
);
1650 //add points if player is online
1651 Player
* pl
= objmgr
.GetPlayer(plr_itr
->first
);
1653 pl
->ModifyArenaPoints(plr_itr
->second
);
1656 PlayerPoints
.clear();
1658 sWorld
.SendGlobalText("Finished setting arena points for online players.", NULL
);
1660 sWorld
.SendGlobalText("Modifying played count, arena points etc. for loaded arena teams, sending updated stats to online players...", NULL
);
1661 for(ObjectMgr::ArenaTeamMap::iterator titr
= objmgr
.GetArenaTeamMapBegin(); titr
!= objmgr
.GetArenaTeamMapEnd(); ++titr
)
1663 if(ArenaTeam
* at
= titr
->second
)
1665 at
->FinishWeek(); // set played this week etc values to 0 in memory, too
1666 at
->SaveToDB(); // save changes
1667 at
->NotifyStatsChanged(); // notify the players of the changes
1671 sWorld
.SendGlobalText("Modification done.", NULL
);
1673 sWorld
.SendGlobalText("Done flushing Arena points.", NULL
);
1676 void BattleGroundMgr::BuildBattleGroundListPacket(WorldPacket
*data
, uint64 guid
, Player
* plr
, uint32 bgTypeId
)
1678 uint32 PlayerLevel
= 10;
1681 PlayerLevel
= plr
->getLevel();
1683 data
->Initialize(SMSG_BATTLEFIELD_LIST
);
1684 *data
<< uint64(guid
); // battlemaster guid
1685 *data
<< uint32(bgTypeId
); // battleground id
1686 if(bgTypeId
== BATTLEGROUND_AA
) // arena
1688 *data
<< uint8(5); // unk
1689 *data
<< uint32(0); // unk
1691 else // battleground
1693 *data
<< uint8(0x00); // unk
1695 size_t count_pos
= data
->wpos();
1697 *data
<< uint32(0x00); // number of bg instances
1699 for(std::map
<uint32
, BattleGround
*>::iterator itr
= m_BattleGrounds
.begin(); itr
!= m_BattleGrounds
.end(); ++itr
)
1701 if(itr
->second
->GetTypeID() == bgTypeId
&& (PlayerLevel
>= itr
->second
->GetMinLevel()) && (PlayerLevel
<= itr
->second
->GetMaxLevel()))
1703 *data
<< uint32(itr
->second
->GetInstanceID());
1707 data
->put
<uint32
>( count_pos
, count
);
1711 void BattleGroundMgr::SendToBattleGround(Player
*pl
, uint32 instanceId
)
1713 BattleGround
*bg
= GetBattleGround(instanceId
);
1716 uint32 mapid
= bg
->GetMapId();
1718 uint32 team
= pl
->GetBGTeam();
1720 team
= pl
->GetTeam();
1721 bg
->GetTeamStartLoc(team
, x
, y
, z
, O
);
1723 sLog
.outDetail("BATTLEGROUND: Sending %s to map %u, X %f, Y %f, Z %f, O %f", pl
->GetName(), mapid
, x
, y
, z
, O
);
1724 pl
->TeleportTo(mapid
, x
, y
, z
, O
);
1728 sLog
.outError("player %u trying to port to non-existent bg instance %u",pl
->GetGUIDLow(), instanceId
);
1732 void BattleGroundMgr::SendAreaSpiritHealerQueryOpcode(Player
*pl
, BattleGround
*bg
, uint64 guid
)
1734 WorldPacket
data(SMSG_AREA_SPIRIT_HEALER_TIME
, 12);
1735 uint32 time_
= 30000 - bg
->GetLastResurrectTime(); // resurrect every 30 seconds
1736 if(time_
== uint32(-1))
1738 data
<< guid
<< time_
;
1739 pl
->GetSession()->SendPacket(&data
);
1742 void BattleGroundMgr::RemoveBattleGround(uint32 instanceID
)
1744 BattleGroundSet::iterator itr
= m_BattleGrounds
.find(instanceID
);
1745 if(itr
!=m_BattleGrounds
.end())
1746 m_BattleGrounds
.erase(itr
);
1749 bool BattleGroundMgr::IsArenaType(uint32 bgTypeId
) const
1751 return ( bgTypeId
== BATTLEGROUND_AA
||
1752 bgTypeId
== BATTLEGROUND_BE
||
1753 bgTypeId
== BATTLEGROUND_NA
||
1754 bgTypeId
== BATTLEGROUND_RL
);
1757 bool BattleGroundMgr::IsBattleGroundType(uint32 bgTypeId
) const
1759 return !IsArenaType(bgTypeId
);
1762 uint32
BattleGroundMgr::BGQueueTypeId(uint32 bgTypeId
, uint8 arenaType
) const
1766 case BATTLEGROUND_WS
:
1767 return BATTLEGROUND_QUEUE_WS
;
1768 case BATTLEGROUND_AB
:
1769 return BATTLEGROUND_QUEUE_AB
;
1770 case BATTLEGROUND_AV
:
1771 return BATTLEGROUND_QUEUE_AV
;
1772 case BATTLEGROUND_EY
:
1773 return BATTLEGROUND_QUEUE_EY
;
1774 case BATTLEGROUND_AA
:
1775 case BATTLEGROUND_NA
:
1776 case BATTLEGROUND_RL
:
1777 case BATTLEGROUND_BE
:
1780 case ARENA_TYPE_2v2
:
1781 return BATTLEGROUND_QUEUE_2v2
;
1782 case ARENA_TYPE_3v3
:
1783 return BATTLEGROUND_QUEUE_3v3
;
1784 case ARENA_TYPE_5v5
:
1785 return BATTLEGROUND_QUEUE_5v5
;
1794 uint32
BattleGroundMgr::BGTemplateId(uint32 bgQueueTypeId
) const
1796 switch(bgQueueTypeId
)
1798 case BATTLEGROUND_QUEUE_WS
:
1799 return BATTLEGROUND_WS
;
1800 case BATTLEGROUND_QUEUE_AB
:
1801 return BATTLEGROUND_AB
;
1802 case BATTLEGROUND_QUEUE_AV
:
1803 return BATTLEGROUND_AV
;
1804 case BATTLEGROUND_QUEUE_EY
:
1805 return BATTLEGROUND_EY
;
1806 case BATTLEGROUND_QUEUE_2v2
:
1807 case BATTLEGROUND_QUEUE_3v3
:
1808 case BATTLEGROUND_QUEUE_5v5
:
1809 return BATTLEGROUND_AA
;
1815 uint8
BattleGroundMgr::BGArenaType(uint32 bgQueueTypeId
) const
1817 switch(bgQueueTypeId
)
1819 case BATTLEGROUND_QUEUE_2v2
:
1820 return ARENA_TYPE_2v2
;
1821 case BATTLEGROUND_QUEUE_3v3
:
1822 return ARENA_TYPE_3v3
;
1823 case BATTLEGROUND_QUEUE_5v5
:
1824 return ARENA_TYPE_5v5
;
1830 void BattleGroundMgr::ToggleArenaTesting()
1832 m_ArenaTesting
= !m_ArenaTesting
;
1834 sWorld
.SendGlobalText("Arenas are set to 1v1 for debugging. So, don't join as group.", NULL
);
1836 sWorld
.SendGlobalText("Arenas are set to normal playercount.", NULL
);