AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
BattlegroundQueue Class Reference

#include "BattlegroundQueue.h"

Classes

class  SelectionPool
 

Public Types

typedef std::map< ObjectGuid, GroupQueueInfo * > QueuedPlayersMap
 
typedef std::list< GroupQueueInfo * > GroupsQueueType
 

Public Member Functions

 BattlegroundQueue ()
 
 ~BattlegroundQueue ()
 
void BattlegroundQueueUpdate (uint32 diff, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id, uint8 arenaType, bool isRated, uint32 arenaRating)
 
void BattlegroundQueueAnnouncerUpdate (uint32 diff, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundBracketId bracket_id)
 
void UpdateEvents (uint32 diff)
 
void FillPlayersToBG (Battleground *bg, BattlegroundBracketId bracket_id)
 
bool CheckPremadeMatch (BattlegroundBracketId bracket_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam)
 
bool CheckNormalMatch (Battleground *bgTemplate, BattlegroundBracketId bracket_id, uint32 minPlayers, uint32 maxPlayers)
 
bool CheckSkirmishForSameFaction (BattlegroundBracketId bracket_id, uint32 minPlayersPerTeam)
 
GroupQueueInfoAddGroup (Player *leader, Group *group, BattlegroundTypeId bgTypeId, PvPDifficultyEntry const *bracketEntry, uint8 arenaType, bool isRated, bool isPremade, uint32 arenaRating, uint32 matchmakerRating, uint32 arenaTeamId=0, uint32 opponentsArenaTeamId=0)
 
void RemovePlayer (ObjectGuid guid, bool decreaseInvitedCount)
 
bool IsPlayerInvitedToRatedArena (ObjectGuid pl_guid)
 
bool IsPlayerInvited (ObjectGuid pl_guid, uint32 bgInstanceGuid, uint32 removeTime)
 
bool GetPlayerGroupInfoData (ObjectGuid guid, GroupQueueInfo *ginfo)
 
void PlayerInvitedToBGUpdateAverageWaitTime (GroupQueueInfo *ginfo)
 
uint32 GetAverageQueueWaitTime (GroupQueueInfo *ginfo) const
 
void InviteGroupToBG (GroupQueueInfo *ginfo, Battleground *bg, TeamId teamId)
 
uint32 GetPlayersCountInGroupsQueue (BattlegroundBracketId bracketId, BattlegroundQueueGroupTypes bgqueue)
 
bool IsAllQueuesEmpty (BattlegroundBracketId bracket_id)
 
void SendMessageBGQueue (Player *leader, Battleground *bg, PvPDifficultyEntry const *bracketEntry)
 
void SendJoinMessageArenaQueue (Player *leader, GroupQueueInfo *ginfo, PvPDifficultyEntry const *bracketEntry, bool isRated)
 
void SendExitMessageArenaQueue (GroupQueueInfo *ginfo)
 
void AddEvent (BasicEvent *Event, uint64 e_time)
 
void SetQueueAnnouncementTimer (uint32 bracketId, int32 timer, bool isCrossFactionBG=true)
 
int32 GetQueueAnnouncementTimer (uint32 bracketId) const
 

Public Attributes

QueuedPlayersMap m_QueuedPlayers
 
GroupsQueueType m_QueuedGroups [MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_MAX]
 
SelectionPool m_SelectionPools [PVP_TEAMS_COUNT]
 

Private Attributes

uint32 m_WaitTimes [PVP_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME]
 
uint32 m_WaitTimeLastIndex [PVP_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
 
EventProcessor m_events
 
std::array< int32, MAX_BATTLEGROUND_BRACKETS_queueAnnouncementTimer
 
bool _queueAnnouncementCrossfactioned
 

Detailed Description

Member Typedef Documentation

◆ GroupsQueueType

◆ QueuedPlayersMap

Constructor & Destructor Documentation

◆ BattlegroundQueue()

BattlegroundQueue::BattlegroundQueue ( )
39{
40 for (uint32 i = 0; i < PVP_TEAMS_COUNT; ++i)
41 {
42 for (uint32 j = 0; j < MAX_BATTLEGROUND_BRACKETS; ++j)
43 {
44 m_WaitTimeLastIndex[i][j] = 0;
46 m_WaitTimes[i][j][k] = 0;
47 }
48 }
49
52}
std::uint32_t uint32
Definition: Define.h:108
constexpr auto COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
Definition: BattlegroundQueue.h:28
#define MAX_BATTLEGROUND_BRACKETS
Definition: DBCEnums.h:58
uint8 constexpr PVP_TEAMS_COUNT
Definition: SharedDefines.h:3417
bool _queueAnnouncementCrossfactioned
Definition: BattlegroundQueue.h:139
std::array< int32, MAX_BATTLEGROUND_BRACKETS > _queueAnnouncementTimer
Definition: BattlegroundQueue.h:138
uint32 m_WaitTimes[PVP_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME]
Definition: BattlegroundQueue.h:132
uint32 m_WaitTimeLastIndex[PVP_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
Definition: BattlegroundQueue.h:133

References _queueAnnouncementCrossfactioned, _queueAnnouncementTimer, COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME, m_WaitTimeLastIndex, m_WaitTimes, MAX_BATTLEGROUND_BRACKETS, and PVP_TEAMS_COUNT.

◆ ~BattlegroundQueue()

BattlegroundQueue::~BattlegroundQueue ( )
55{
57
58 m_QueuedPlayers.clear();
59 for (auto& m_QueuedGroup : m_QueuedGroups)
60 {
61 for (auto& j : m_QueuedGroup)
62 {
63 for (auto& itr : j)
64 delete itr;
65 j.clear();
66 }
67 }
68}
void KillAllEvents(bool force)
Definition: EventProcessor.cpp:82
QueuedPlayersMap m_QueuedPlayers
Definition: BattlegroundQueue.h:94
GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_BRACKETS][BG_QUEUE_MAX]
Definition: BattlegroundQueue.h:108
EventProcessor m_events
Definition: BattlegroundQueue.h:136

References EventProcessor::KillAllEvents(), m_events, m_QueuedGroups, and m_QueuedPlayers.

Member Function Documentation

◆ AddEvent()

void BattlegroundQueue::AddEvent ( BasicEvent Event,
uint64  e_time 
)
366{
368}
Event
Definition: boss_prince_taldaram.cpp:67
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
Definition: EventProcessor.h:105
uint64 CalculateTime(uint64 t_offset) const
Definition: EventProcessor.cpp:158

References EventProcessor::AddEvent(), EventProcessor::CalculateTime(), and m_events.

Referenced by InviteGroupToBG().

◆ AddGroup()

GroupQueueInfo * BattlegroundQueue::AddGroup ( Player leader,
Group group,
BattlegroundTypeId  bgTypeId,
PvPDifficultyEntry const *  bracketEntry,
uint8  arenaType,
bool  isRated,
bool  isPremade,
uint32  arenaRating,
uint32  matchmakerRating,
uint32  arenaTeamId = 0,
uint32  opponentsArenaTeamId = 0 
)
134{
135 BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
136
137 // create new ginfo
138 auto* ginfo = new GroupQueueInfo;
139 ginfo->BgTypeId = bgTypeId;
140 ginfo->ArenaType = arenaType;
141 ginfo->ArenaTeamId = arenaTeamId;
142 ginfo->IsRated = isRated;
143 ginfo->IsInvitedToBGInstanceGUID = 0;
144 ginfo->JoinTime = GameTime::GetGameTimeMS().count();
145 ginfo->RemoveInviteTime = 0;
146 ginfo->teamId = leader->GetTeamId();
147 ginfo->RealTeamID = leader->GetTeamId(true);
148 ginfo->ArenaTeamRating = arenaRating;
149 ginfo->ArenaMatchmakerRating = matchmakerRating;
150 ginfo->PreviousOpponentsTeamId = opponentsArenaTeamId;
151 ginfo->OpponentsTeamRating = 0;
152 ginfo->OpponentsMatchmakerRating = 0;
153
154 ginfo->Players.clear();
155
156 //compute index (if group is premade or joined a rated match) to queues
157 uint32 index = 0;
158
159 if (!isRated && !isPremade)
160 index += PVP_TEAMS_COUNT;
161
162 if (ginfo->teamId == TEAM_HORDE)
163 index++;
164
165 sScriptMgr->OnAddGroup(this, ginfo, index, leader, group, bgTypeId, bracketEntry,
166 arenaType, isRated, isPremade, arenaRating, matchmakerRating, arenaTeamId, opponentsArenaTeamId);
167
168 LOG_DEBUG("bg.battleground", "Adding Group to BattlegroundQueue bgTypeId: {}, bracket_id: {}, index: {}", bgTypeId, bracketId, index);
169
170 // pussywizard: store indices at which GroupQueueInfo is in m_QueuedGroups
171 ginfo->BracketId = bracketId;
172 ginfo->GroupType = index;
173
174 //add players from group to ginfo
175 if (group)
176 {
177 group->DoForAllMembers([this, ginfo](Player* member)
178 {
179 ASSERT(m_QueuedPlayers.count(member->GetGUID()) == 0);
180 m_QueuedPlayers[member->GetGUID()] = ginfo;
181 ginfo->Players.emplace(member->GetGUID());
182 });
183 }
184 else
185 {
186 ASSERT(m_QueuedPlayers.count(leader->GetGUID()) == 0);
187 m_QueuedPlayers[leader->GetGUID()] = ginfo;
188 ginfo->Players.emplace(leader->GetGUID());
189 }
190
191 //add GroupInfo to m_QueuedGroups
192 m_QueuedGroups[bracketId][index].push_back(ginfo);
193
194 // announce world (this doesn't need mutex)
195 SendJoinMessageArenaQueue(leader, ginfo, bracketEntry, isRated);
196
197 Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(ginfo->BgTypeId);
198 if (!bg)
199 return ginfo;
200
201 if (!isRated && !isPremade && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE))
202 SendMessageBGQueue(leader, bg, bracketEntry);
203
204 return ginfo;
205}
#define ASSERT
Definition: Errors.h:68
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:188
#define sScriptMgr
Definition: ScriptMgr.h:2702
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE
Definition: IWorld.h:116
BattlegroundBracketId
Definition: DBCEnums.h:52
@ TEAM_HORDE
Definition: SharedDefines.h:733
#define sWorld
Definition: World.h:451
Milliseconds GetGameTimeMS()
Definition: GameTime.cpp:43
Definition: Battleground.h:293
Definition: BattlegroundQueue.h:31
BattlegroundTypeId BgTypeId
Definition: BattlegroundQueue.h:35
void SendMessageBGQueue(Player *leader, Battleground *bg, PvPDifficultyEntry const *bracketEntry)
Definition: BattlegroundQueue.cpp:1031
void SendJoinMessageArenaQueue(Player *leader, GroupQueueInfo *ginfo, PvPDifficultyEntry const *bracketEntry, bool isRated)
Definition: BattlegroundQueue.cpp:1085
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
Definition: Player.h:1046
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2059
void DoForAllMembers(std::function< void(Player *)> const &worker)
Definition: Group.cpp:2482

References ASSERT, GroupQueueInfo::BgTypeId, CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE, Group::DoForAllMembers(), PvPDifficultyEntry::GetBracketId(), GameTime::GetGameTimeMS(), Object::GetGUID(), Player::GetTeamId(), LOG_DEBUG, m_QueuedGroups, m_QueuedPlayers, PVP_TEAMS_COUNT, sBattlegroundMgr, SendJoinMessageArenaQueue(), SendMessageBGQueue(), sScriptMgr, sWorld, and TEAM_HORDE.

Referenced by CheckNormalMatch(), WorldSession::HandleBattlemasterJoinArena(), and WorldSession::HandleBattlemasterJoinOpcode().

◆ BattlegroundQueueAnnouncerUpdate()

void BattlegroundQueue::BattlegroundQueueAnnouncerUpdate ( uint32  diff,
BattlegroundQueueTypeId  bgQueueTypeId,
BattlegroundBracketId  bracket_id 
)
955{
956 BattlegroundTypeId bgTypeId = BattlegroundMgr::BGTemplateId(bgQueueTypeId);
957 Battleground* bg_template = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId);
958 if (!bg_template)
959 {
960 return;
961 }
962
963 PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketById(bg_template->GetMapId(), bracket_id);
964 if (!bracketEntry)
965 {
966 return;
967 }
968
970 {
971 uint32 qPlayers = 0;
972
974 {
975 qPlayers = GetPlayersCountInGroupsQueue(bracket_id, BG_QUEUE_CFBG);
976 }
977 else
978 {
980 }
981
982 if (!qPlayers)
983 {
984 _queueAnnouncementTimer[bracket_id] = -1;
985 return;
986 }
987
988 if (_queueAnnouncementTimer[bracket_id] >= 0)
989 {
990 if (_queueAnnouncementTimer[bracket_id] <= static_cast<int32>(diff))
991 {
992 _queueAnnouncementTimer[bracket_id] = -1;
993
994 auto bgName = bg_template->GetName();
995 uint32 MaxPlayers = bg_template->GetMinPlayersPerTeam() * 2;
996 uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32) 80);
997 uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32) 80);
998
999 sWorld->SendWorldTextOptional(LANG_BG_QUEUE_ANNOUNCE_WORLD, ANNOUNCER_FLAG_DISABLE_BG_QUEUE, bgName.c_str(), q_min_level, q_max_level, qPlayers, MaxPlayers);
1000 }
1001 else
1002 {
1003 _queueAnnouncementTimer[bracket_id] -= static_cast<int32>(diff);
1004 }
1005 }
1006 }
1007}
std::int32_t int32
Definition: Define.h:104
@ BG_QUEUE_NORMAL_ALLIANCE
Definition: BattlegroundQueue.h:55
@ BG_QUEUE_CFBG
Definition: BattlegroundQueue.h:58
@ BG_QUEUE_NORMAL_HORDE
Definition: BattlegroundQueue.h:56
PvPDifficultyEntry const * GetBattlegroundBracketById(uint32 mapid, BattlegroundBracketId id)
Definition: DBCStores.cpp:808
@ ANNOUNCER_FLAG_DISABLE_BG_QUEUE
Definition: PlayerSettings.h:33
@ LANG_BG_QUEUE_ANNOUNCE_WORLD
Definition: Language.h:659
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMED
Definition: IWorld.h:118
BattlegroundTypeId
Definition: SharedDefines.h:3451
uint32 GetMapId() const
Definition: Battleground.h:420
uint32 GetMinPlayersPerTeam() const
Definition: Battleground.h:332
std::string GetName() const
Definition: Battleground.h:318
static BattlegroundTypeId BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId)
Definition: BattlegroundMgr.cpp:695
uint32 GetPlayersCountInGroupsQueue(BattlegroundBracketId bracketId, BattlegroundQueueGroupTypes bgqueue)
Definition: BattlegroundQueue.cpp:1009
Definition: DBCStructure.h:1414
uint32 maxLevel
Definition: DBCStructure.h:1419
uint32 minLevel
Definition: DBCStructure.h:1418

References _queueAnnouncementCrossfactioned, _queueAnnouncementTimer, ANNOUNCER_FLAG_DISABLE_BG_QUEUE, BG_QUEUE_CFBG, BG_QUEUE_NORMAL_ALLIANCE, BG_QUEUE_NORMAL_HORDE, BattlegroundMgr::BGTemplateId(), CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMED, GetBattlegroundBracketById(), Battleground::GetMapId(), Battleground::GetMinPlayersPerTeam(), Battleground::GetName(), GetPlayersCountInGroupsQueue(), LANG_BG_QUEUE_ANNOUNCE_WORLD, PvPDifficultyEntry::maxLevel, PvPDifficultyEntry::minLevel, sBattlegroundMgr, and sWorld.

Referenced by BattlegroundMgr::Update().

◆ BattlegroundQueueUpdate()

void BattlegroundQueue::BattlegroundQueueUpdate ( uint32  diff,
BattlegroundTypeId  bgTypeId,
BattlegroundBracketId  bracket_id,
uint8  arenaType,
bool  isRated,
uint32  arenaRating 
)
706{
707 // if no players in queue - do nothing
708 if (IsAllQueuesEmpty(bracket_id))
709 return;
710
711 auto InviteAllGroupsToBg = [this](Battleground* bg)
712 {
713 // invite those selection pools
714 for (uint32 i = 0; i < PVP_TEAMS_COUNT; i++)
715 {
716 for (auto const& citr : m_SelectionPools[TEAM_ALLIANCE + i].SelectedGroups)
717 {
718 InviteGroupToBG(citr, bg, citr->teamId);
719 }
720 }
721 };
722
723 // battleground with free slot for player should be always in the beggining of the queue
724 // maybe it would be better to create bgfreeslotqueue for each bracket_id
725 BGFreeSlotQueueContainer& bgQueues = sBattlegroundMgr->GetBGFreeSlotQueueStore(bgTypeId);
726 for (BGFreeSlotQueueContainer::iterator itr = bgQueues.begin(); itr != bgQueues.end();)
727 {
728 Battleground* bg = *itr; ++itr;
729 // DO NOT allow queue manager to invite new player to rated games
730 if (!bg->isRated() && bg->GetBgTypeID() == bgTypeId && bg->GetBracketId() == bracket_id &&
732 {
733 // clear selection pools
736
737 // call a function that does the job for us
738 FillPlayersToBG(bg, bracket_id);
739
740 // now everything is set, invite players
741 InviteAllGroupsToBg(bg);
742
743 if (!bg->HasFreeSlots())
745 }
746 }
747
748 Battleground* bg_template = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId);
749 if (!bg_template)
750 {
751 LOG_ERROR("bg.battleground", "Battleground: Update: bg template not found for {}", bgTypeId);
752 return;
753 }
754
755 PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketById(bg_template->GetMapId(), bracket_id);
756 if (!bracketEntry)
757 {
758 LOG_ERROR("bg.battleground", "Battleground: Update: bg bracket entry not found for map {} bracket id {}", bg_template->GetMapId(), bracket_id);
759 return;
760 }
761
762 // get min and max players per team
763 uint32 MinPlayersPerTeam = bg_template->GetMinPlayersPerTeam();
764 uint32 MaxPlayersPerTeam = bg_template->GetMaxPlayersPerTeam();
765
766 if (bg_template->isArena())
767 {
768 MinPlayersPerTeam = sBattlegroundMgr->isArenaTesting() ? 1 : arenaType;
769 MaxPlayersPerTeam = arenaType;
770 }
771 else if (sBattlegroundMgr->isTesting())
772 MinPlayersPerTeam = 1;
773
774 sScriptMgr->OnQueueUpdate(this, diff, bgTypeId, bracket_id, arenaType, isRated, arenaRating);
775
778
779 // check if can start new premade battleground
780 if (bg_template->isBattleground() && bgTypeId != BATTLEGROUND_RB && CheckPremadeMatch(bracket_id, MinPlayersPerTeam, MaxPlayersPerTeam))
781 {
782 // create new battleground
783 Battleground* bg = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, 0, false);
784 if (!bg)
785 {
786 LOG_ERROR("bg.battleground", "BattlegroundQueue::Update - Cannot create battleground: {}", bgTypeId);
787 return;
788 }
789
790 // invite those selection pools
791 InviteAllGroupsToBg(bg);
792
793 bg->StartBattleground();
794
795 // clear structures
798 }
799
800 // check if can start new normal battleground or non-rated arena
801 if (!isRated)
802 {
803 if (CheckNormalMatch(bg_template, bracket_id, MinPlayersPerTeam, MaxPlayersPerTeam) ||
804 (bg_template->isArena() && CheckSkirmishForSameFaction(bracket_id, MinPlayersPerTeam)))
805 {
806 // create new battleground
807 Battleground* bg = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, false);
808 if (!bg)
809 {
810 LOG_ERROR("bg.battleground", "BattlegroundQueue::Update - Cannot create battleground: {}", bgTypeId);
811 return;
812 }
813
814 // invite players
815 InviteAllGroupsToBg(bg);
816
817 bg->StartBattleground();
818 }
819 }
820 // check if can start new rated arenas (can create many in single queue update)
821 else if (bg_template->isArena())
822 {
823 // found out the minimum and maximum ratings the newly added team should battle against
824 // arenaRating is the rating of the latest joined team, or 0
825 // 0 is on (automatic update call) and we must set it to team's with longest wait time
826 if (!arenaRating)
827 {
828 GroupQueueInfo* front1 = nullptr;
829 GroupQueueInfo* front2 = nullptr;
830
831 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty())
832 {
833 front1 = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].front();
834 arenaRating = front1->ArenaMatchmakerRating;
835 }
836
837 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty())
838 {
839 front2 = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].front();
840 arenaRating = front2->ArenaMatchmakerRating;
841 }
842
843 if (front1 && front2)
844 {
845 if (front1->JoinTime < front2->JoinTime)
846 arenaRating = front1->ArenaMatchmakerRating;
847 }
848 else if (!front1 && !front2)
849 return; // queues are empty
850 }
851
852 //set rating range
853 uint32 arenaMinRating = (arenaRating <= sBattlegroundMgr->GetMaxRatingDifference()) ? 0 : arenaRating - sBattlegroundMgr->GetMaxRatingDifference();
854 uint32 arenaMaxRating = arenaRating + sBattlegroundMgr->GetMaxRatingDifference();
855
856 // if max rating difference is set and the time past since server startup is greater than the rating discard time
857 // (after what time the ratings aren't taken into account when making teams) then
858 // the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account
859 // else leave the discard time on 0, this way all ratings will be discarded
860 // this has to be signed value - when the server starts, this value would be negative and thus overflow
861 int32 discardTime = GameTime::GetGameTimeMS().count() - sBattlegroundMgr->GetRatingDiscardTimer();
862
863 // timer for previous opponents
864 int32 discardOpponentsTime = GameTime::GetGameTimeMS().count() - sWorld->getIntConfig(CONFIG_ARENA_PREV_OPPONENTS_DISCARD_TIMER);
865
866 // we need to find 2 teams which will play next game
867 GroupsQueueType::iterator itr_teams[PVP_TEAMS_COUNT];
868 uint8 found = 0;
869 uint8 team = 0;
870
872 {
873 // take the group that joined first
874 GroupsQueueType::iterator itr2 = m_QueuedGroups[bracket_id][i].begin();
875 for (; itr2 != m_QueuedGroups[bracket_id][i].end(); ++itr2)
876 {
877 // if group match conditions, then add it to pool
878 if (!(*itr2)->IsInvitedToBGInstanceGUID
879 && (((*itr2)->ArenaMatchmakerRating >= arenaMinRating && (*itr2)->ArenaMatchmakerRating <= arenaMaxRating)
880 || (int32)(*itr2)->JoinTime < discardTime))
881 {
882 itr_teams[found++] = itr2;
883 team = i;
884 break;
885 }
886 }
887 }
888
889 if (!found)
890 return;
891
892 if (found == 1)
893 {
894 for (GroupsQueueType::iterator itr3 = itr_teams[0]; itr3 != m_QueuedGroups[bracket_id][team].end(); ++itr3)
895 {
896 if (!(*itr3)->IsInvitedToBGInstanceGUID
897 && (((*itr3)->ArenaMatchmakerRating >= arenaMinRating && (*itr3)->ArenaMatchmakerRating <= arenaMaxRating) || (int32)(*itr3)->JoinTime < discardTime)
898 && ((*(itr_teams[0]))->ArenaTeamId != (*itr3)->PreviousOpponentsTeamId || ((int32)(*itr3)->JoinTime < discardOpponentsTime))
899 && (*(itr_teams[0]))->ArenaTeamId != (*itr3)->ArenaTeamId)
900 {
901 itr_teams[found++] = itr3;
902 break;
903 }
904 }
905 }
906
907 //if we have 2 teams, then start new arena and invite players!
908 if (found == 2)
909 {
910 GroupQueueInfo* aTeam = *(itr_teams[TEAM_ALLIANCE]);
911 GroupQueueInfo* hTeam = *(itr_teams[TEAM_HORDE]);
912
913 Battleground* arena = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, true);
914 if (!arena)
915 {
916 LOG_ERROR("bg.battleground", "BattlegroundQueue::Update couldn't create arena instance for rated arena match!");
917 return;
918 }
919
920 aTeam->OpponentsTeamRating = hTeam->ArenaTeamRating;
921 hTeam->OpponentsTeamRating = aTeam->ArenaTeamRating;
924
925 LOG_DEBUG("bg.battleground", "setting oposite teamrating for team {} to {}", aTeam->ArenaTeamId, aTeam->OpponentsTeamRating);
926 LOG_DEBUG("bg.battleground", "setting oposite teamrating for team {} to {}", hTeam->ArenaTeamId, hTeam->OpponentsTeamRating);
927
928 // now we must move team if we changed its faction to another faction queue, because then we will spam log by errors in Queue::RemovePlayer
929 if (aTeam->teamId != TEAM_ALLIANCE)
930 {
932 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].push_front(aTeam);
933 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].erase(itr_teams[TEAM_ALLIANCE]);
934 }
935
936 if (hTeam->teamId != TEAM_HORDE)
937 {
939 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].push_front(hTeam);
940 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].erase(itr_teams[TEAM_HORDE]);
941 }
942
945 InviteGroupToBG(aTeam, arena, TEAM_ALLIANCE);
946 InviteGroupToBG(hTeam, arena, TEAM_HORDE);
947
948 LOG_DEBUG("bg.battleground", "Starting rated arena match!");
949 arena->StartBattleground();
950 }
951 }
952}
std::uint8_t uint8
Definition: Define.h:110
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
@ STATUS_WAIT_QUEUE
Definition: Battleground.h:195
@ STATUS_WAIT_LEAVE
Definition: Battleground.h:198
std::list< Battleground * > BGFreeSlotQueueContainer
Definition: BattlegroundMgr.h:38
@ BG_QUEUE_PREMADE_HORDE
Definition: BattlegroundQueue.h:54
@ BG_QUEUE_PREMADE_ALLIANCE
Definition: BattlegroundQueue.h:53
@ CONFIG_ARENA_PREV_OPPONENTS_DISCARD_TIMER
Definition: IWorld.h:322
@ TEAM_ALLIANCE
Definition: SharedDefines.h:732
@ BATTLEGROUND_RB
Definition: SharedDefines.h:3465
uint32 GetMaxPlayersPerTeam() const
Definition: Battleground.h:331
bool isRated() const
Definition: Battleground.h:390
void StartBattleground()
Definition: Battleground.cpp:1061
bool isArena() const
Definition: Battleground.h:388
bool isBattleground() const
Definition: Battleground.h:389
BattlegroundStatus GetStatus() const
Definition: Battleground.h:322
bool HasFreeSlots() const
Definition: Battleground.cpp:1246
void RemoveFromBGFreeSlotQueue()
Definition: Battleground.cpp:1185
BattlegroundBracketId GetBracketId() const
Definition: Battleground.h:320
BattlegroundTypeId GetBgTypeID(bool GetRandom=false) const
Definition: Battleground.h:319
void SetArenaMatchmakerRating(TeamId teamId, uint32 MMR)
Definition: Battleground.h:494
uint32 ArenaTeamRating
Definition: BattlegroundQueue.h:42
TeamId teamId
Definition: BattlegroundQueue.h:33
uint32 JoinTime
Definition: BattlegroundQueue.h:39
uint32 OpponentsMatchmakerRating
Definition: BattlegroundQueue.h:45
uint32 ArenaTeamId
Definition: BattlegroundQueue.h:38
uint32 OpponentsTeamRating
Definition: BattlegroundQueue.h:44
uint32 ArenaMatchmakerRating
Definition: BattlegroundQueue.h:43
uint8 GroupType
Definition: BattlegroundQueue.h:48
void FillPlayersToBG(Battleground *bg, BattlegroundBracketId bracket_id)
Definition: BattlegroundQueue.cpp:393
void InviteGroupToBG(GroupQueueInfo *ginfo, Battleground *bg, TeamId teamId)
Definition: BattlegroundQueue.cpp:1186
bool CheckSkirmishForSameFaction(BattlegroundBracketId bracket_id, uint32 minPlayersPerTeam)
Definition: BattlegroundQueue.cpp:630
SelectionPool m_SelectionPools[PVP_TEAMS_COUNT]
Definition: BattlegroundQueue.h:126
bool IsAllQueuesEmpty(BattlegroundBracketId bracket_id)
Definition: BattlegroundQueue.cpp:1020
bool CheckPremadeMatch(BattlegroundBracketId bracket_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam)
Definition: BattlegroundQueue.cpp:508
bool CheckNormalMatch(Battleground *bgTemplate, BattlegroundBracketId bracket_id, uint32 minPlayers, uint32 maxPlayers)
Definition: BattlegroundQueue.cpp:574
void Init()
Definition: BattlegroundQueue.cpp:75

References GroupQueueInfo::ArenaMatchmakerRating, GroupQueueInfo::ArenaTeamId, GroupQueueInfo::ArenaTeamRating, BATTLEGROUND_RB, BG_QUEUE_NORMAL_ALLIANCE, BG_QUEUE_PREMADE_ALLIANCE, BG_QUEUE_PREMADE_HORDE, CheckNormalMatch(), CheckPremadeMatch(), CheckSkirmishForSameFaction(), CONFIG_ARENA_PREV_OPPONENTS_DISCARD_TIMER, FillPlayersToBG(), GetBattlegroundBracketById(), Battleground::GetBgTypeID(), Battleground::GetBracketId(), GameTime::GetGameTimeMS(), Battleground::GetMapId(), Battleground::GetMaxPlayersPerTeam(), Battleground::GetMinPlayersPerTeam(), Battleground::GetStatus(), GroupQueueInfo::GroupType, Battleground::HasFreeSlots(), BattlegroundQueue::SelectionPool::Init(), InviteGroupToBG(), IsAllQueuesEmpty(), Battleground::isArena(), Battleground::isBattleground(), Battleground::isRated(), GroupQueueInfo::JoinTime, LOG_DEBUG, LOG_ERROR, m_QueuedGroups, m_SelectionPools, GroupQueueInfo::OpponentsMatchmakerRating, GroupQueueInfo::OpponentsTeamRating, PVP_TEAMS_COUNT, Battleground::RemoveFromBGFreeSlotQueue(), sBattlegroundMgr, Battleground::SetArenaMatchmakerRating(), sScriptMgr, Battleground::StartBattleground(), STATUS_WAIT_LEAVE, STATUS_WAIT_QUEUE, sWorld, TEAM_ALLIANCE, TEAM_HORDE, and GroupQueueInfo::teamId.

Referenced by BattlegroundMgr::Update().

◆ CheckNormalMatch()

bool BattlegroundQueue::CheckNormalMatch ( Battleground bgTemplate,
BattlegroundBracketId  bracket_id,
uint32  minPlayers,
uint32  maxPlayers 
)
575{
576 auto CanStartMatch = [this, bgTemplate, minPlayers]()
577 {
578 //allow 1v0 if debug bg
580 return true;
581
582 //return true if there are enough players in selection pools - enable to work .debug bg command correctly
584 };
585
586 if (sScriptMgr->IsCheckNormalMatch(this, bgTemplate, bracket_id, minPlayers, maxPlayers))
587 return CanStartMatch();
588
589 GroupsQueueType::const_iterator itr_team[PVP_TEAMS_COUNT];
590 for (uint32 i = 0; i < PVP_TEAMS_COUNT; i++)
591 {
592 itr_team[i] = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin();
593 for (; itr_team[i] != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].end(); ++(itr_team[i]))
594 {
595 if (!(*(itr_team[i]))->IsInvitedToBGInstanceGUID)
596 {
597 m_SelectionPools[i].AddGroup(*(itr_team[i]), maxPlayers);
598 if (m_SelectionPools[i].GetPlayerCount() >= minPlayers)
599 break;
600 }
601 }
602 }
603
604 //try to invite same number of players - this cycle may cause longer wait time even if there are enough players in queue, but we want ballanced bg
607 j = TEAM_HORDE;
608
611 {
612 //we will try to invite more groups to team with less players indexed by j
613 ++(itr_team[j]); //this will not cause a crash, because for cycle above reached break;
614 for (; itr_team[j] != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + j].end(); ++(itr_team[j]))
615 {
616 if (!(*(itr_team[j]))->IsInvitedToBGInstanceGUID)
617 if (!m_SelectionPools[j].AddGroup(*(itr_team[j]), m_SelectionPools[(j + 1) % PVP_TEAMS_COUNT].GetPlayerCount()))
618 break;
619 }
620
621 // do not allow to start bg with more than 2 players more on 1 faction
623 return false;
624 }
625
626 return CanStartMatch();
627}
@ BG_QUEUE_INVITATION_TYPE_NO_BALANCE
Definition: Battleground.h:287
@ CONFIG_BATTLEGROUND_INVITATION_TYPE
Definition: IWorld.h:312
GroupQueueInfo * AddGroup(Player *leader, Group *group, BattlegroundTypeId bgTypeId, PvPDifficultyEntry const *bracketEntry, uint8 arenaType, bool isRated, bool isPremade, uint32 arenaRating, uint32 matchmakerRating, uint32 arenaTeamId=0, uint32 opponentsArenaTeamId=0)
Definition: BattlegroundQueue.cpp:132
bool AddGroup(GroupQueueInfo *ginfo, uint32 desiredCount)
Definition: BattlegroundQueue.cpp:115
uint32 GetPlayerCount() const
Definition: BattlegroundQueue.h:118

References BattlegroundQueue::SelectionPool::AddGroup(), AddGroup(), BG_QUEUE_INVITATION_TYPE_NO_BALANCE, BG_QUEUE_NORMAL_ALLIANCE, CONFIG_BATTLEGROUND_INVITATION_TYPE, BattlegroundQueue::SelectionPool::GetPlayerCount(), Battleground::isBattleground(), m_QueuedGroups, m_SelectionPools, PVP_TEAMS_COUNT, sBattlegroundMgr, sScriptMgr, sWorld, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by BattlegroundQueueUpdate().

◆ CheckPremadeMatch()

bool BattlegroundQueue::CheckPremadeMatch ( BattlegroundBracketId  bracket_id,
uint32  MinPlayersPerTeam,
uint32  MaxPlayersPerTeam 
)
509{
510 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty() && !m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty())
511 {
512 //start premade match
513 //if groups aren't invited
514 GroupsQueueType::const_iterator ali_group, horde_group;
515 for (ali_group = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].begin(); ali_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].end(); ++ali_group)
516 if (!(*ali_group)->IsInvitedToBGInstanceGUID)
517 break;
518
519 for (horde_group = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].begin(); horde_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].end(); ++horde_group)
520 if (!(*horde_group)->IsInvitedToBGInstanceGUID)
521 break;
522
523 // if found both groups
524 if (ali_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].end() && horde_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].end())
525 {
526 m_SelectionPools[TEAM_ALLIANCE].AddGroup((*ali_group), MaxPlayersPerTeam);
527 m_SelectionPools[TEAM_HORDE].AddGroup((*horde_group), MaxPlayersPerTeam);
528
529 //add groups/players from normal queue to size of bigger group
530 uint32 maxPlayers = std::min(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount(), m_SelectionPools[TEAM_HORDE].GetPlayerCount());
531 GroupsQueueType::const_iterator itr;
532
533 for (uint32 i = 0; i < PVP_TEAMS_COUNT; i++)
534 {
535 for (itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin(); itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].end(); ++itr)
536 {
537 //if itr can join BG and player count is less that maxPlayers, then add group to selectionpool
538 if (!(*itr)->IsInvitedToBGInstanceGUID && !m_SelectionPools[i].AddGroup((*itr), maxPlayers))
539 break;
540 }
541 }
542
543 //premade selection pools are set
544 return true;
545 }
546 }
547
548 // now check if we can move group from Premade queue to normal queue (timer has expired) or group size lowered!!
549 // this could be 2 cycles but i'm checking only first team in queue - it can cause problem -
550 // if first is invited to BG and seconds timer expired, but we can ignore it, because players have only 80 seconds to click to enter bg
551 // and when they click or after 80 seconds the queue info is removed from queue
553
554 for (uint32 i = 0; i < PVP_TEAMS_COUNT; i++)
555 {
556 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty())
557 {
558 GroupsQueueType::iterator itr = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].begin();
559 if (!(*itr)->IsInvitedToBGInstanceGUID && ((*itr)->JoinTime < time_before || (*itr)->Players.size() < MinPlayersPerTeam))
560 {
561 //we must insert group to normal queue and erase pointer from premade queue
562 (*itr)->GroupType = BG_QUEUE_NORMAL_ALLIANCE + i; // pussywizard: update GroupQueueInfo internal variable
563 m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].push_front((*itr));
564 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].erase(itr);
565 }
566 }
567 }
568
569 //selection pools are not set
570 return false;
571}
@ CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH
Definition: IWorld.h:309

References BattlegroundQueue::SelectionPool::AddGroup(), BG_QUEUE_NORMAL_ALLIANCE, BG_QUEUE_PREMADE_ALLIANCE, BG_QUEUE_PREMADE_HORDE, CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH, GameTime::GetGameTimeMS(), m_QueuedGroups, m_SelectionPools, PVP_TEAMS_COUNT, sWorld, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by BattlegroundQueueUpdate().

◆ CheckSkirmishForSameFaction()

bool BattlegroundQueue::CheckSkirmishForSameFaction ( BattlegroundBracketId  bracket_id,
uint32  minPlayersPerTeam 
)
631{
632 if (m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() < minPlayersPerTeam && m_SelectionPools[TEAM_HORDE].GetPlayerCount() < minPlayersPerTeam)
633 return false;
634
635 TeamId teamIndex = TEAM_ALLIANCE;
636 TeamId otherTeam = TEAM_HORDE;
637
638 if (m_SelectionPools[TEAM_HORDE].GetPlayerCount() == minPlayersPerTeam)
639 {
640 teamIndex = TEAM_HORDE;
641 otherTeam = TEAM_ALLIANCE;
642 }
643
644 //clear other team's selection
645 m_SelectionPools[otherTeam].Init();
646
647 //store last ginfo pointer
648 GroupQueueInfo* ginfo = m_SelectionPools[teamIndex].SelectedGroups.back();
649
650 //set itr_team to group that was added to selection pool latest
651 GroupsQueueType::iterator itr_team = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].begin();
652 for (; itr_team != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end(); ++itr_team)
653 if (ginfo == *itr_team)
654 break;
655
656 if (itr_team == m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end())
657 return false;
658
659 GroupsQueueType::iterator itr_team2 = itr_team;
660 ++itr_team2;
661
662 //invite players to other selection pool
663 for (; itr_team2 != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end(); ++itr_team2)
664 {
665 //if selection pool is full then break;
666 if (!(*itr_team2)->IsInvitedToBGInstanceGUID && !m_SelectionPools[otherTeam].AddGroup(*itr_team2, minPlayersPerTeam))
667 break;
668 }
669
670 if (m_SelectionPools[otherTeam].GetPlayerCount() != minPlayersPerTeam)
671 return false;
672
673 //here we have correct 2 selections and we need to change one teams team and move selection pool teams to other team's queue
674 for (GroupsQueueType::iterator itr = m_SelectionPools[otherTeam].SelectedGroups.begin(); itr != m_SelectionPools[otherTeam].SelectedGroups.end(); ++itr)
675 {
676 //set correct team
677 (*itr)->teamId = otherTeam;
678 (*itr)->GroupType = static_cast<uint8>(BG_QUEUE_NORMAL_ALLIANCE) + static_cast<uint8>(otherTeam);
679
680 //add team to other queue
681 m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(otherTeam)].push_front(*itr);
682
683 //remove team from old queue
684 GroupsQueueType::iterator itr2 = itr_team;
685 ++itr2;
686
687 for (; itr2 != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end(); ++itr2)
688 {
689 if (*itr2 == *itr)
690 {
691 m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].erase(itr2);
692 break;
693 }
694 }
695 }
696
697 return true;
698}
TeamId
Definition: SharedDefines.h:731
GroupsQueueType SelectedGroups
Definition: BattlegroundQueue.h:120

References BattlegroundQueue::SelectionPool::AddGroup(), BG_QUEUE_NORMAL_ALLIANCE, BattlegroundQueue::SelectionPool::Init(), m_QueuedGroups, m_SelectionPools, BattlegroundQueue::SelectionPool::SelectedGroups, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by BattlegroundQueueUpdate().

◆ FillPlayersToBG()

void BattlegroundQueue::FillPlayersToBG ( Battleground bg,
BattlegroundBracketId  bracket_id 
)
394{
395 if (!sScriptMgr->CanFillPlayersToBG(this, bg, bracket_id))
396 {
397 return;
398 }
399
400 int32 hordeFree = bg->GetFreeSlotsForTeam(TEAM_HORDE);
402 uint32 aliCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].size();
403 uint32 hordeCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].size();
404
405 // try to get even teams
407 {
408 // check if the teams are even
409 if (hordeFree == 1 && aliFree == 1)
410 {
411 // if we are here, the teams have the same amount of players
412 // then we have to allow to join the same amount of players
413 int32 hordeExtra = hordeCount - aliCount;
414 int32 aliExtra = aliCount - hordeCount;
415
416 hordeExtra = std::max(hordeExtra, 0);
417 aliExtra = std::max(aliExtra, 0);
418
419 if (aliCount != hordeCount)
420 {
421 aliFree -= aliExtra;
422 hordeFree -= hordeExtra;
423
424 aliFree = std::max(aliFree, 0);
425 hordeFree = std::max(hordeFree, 0);
426 }
427 }
428 }
429
430 GroupsQueueType::const_iterator Ali_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].begin();
431 //count of groups in queue - used to stop cycles
432
433 //index to queue which group is current
434 uint32 aliIndex = 0;
435 for (; aliIndex < aliCount && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree); aliIndex++)
436 ++Ali_itr;
437
438 //the same thing for horde
439 GroupsQueueType::const_iterator Horde_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].begin();
440
441 uint32 hordeIndex = 0;
442 for (; hordeIndex < hordeCount && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree); hordeIndex++)
443 ++Horde_itr;
444
445 //if ofc like BG queue invitation is set in config, then we are happy
447 return;
448
449 /*
450 if we reached this code, then we have to solve NP - complete problem called Subset sum problem
451 So one solution is to check all possible invitation subgroups, or we can use these conditions:
452 1. Last time when BattlegroundQueue::Update was executed we invited all possible players - so there is only small possibility
453 that we will invite now whole queue, because only 1 change has been made to queues from the last BattlegroundQueue::Update call
454 2. Other thing we should consider is group order in queue
455 */
456
457 // At first we need to compare free space in bg and our selection pool
458 int32 diffAli = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
459 int32 diffHorde = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
460
461 while (std::abs(diffAli - diffHorde) > 1 && (m_SelectionPools[TEAM_HORDE].GetPlayerCount() > 0 || m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() > 0))
462 {
463 //each cycle execution we need to kick at least 1 group
464 if (diffAli < diffHorde)
465 {
466 //kick alliance group, add to pool new group if needed
467 if (m_SelectionPools[TEAM_ALLIANCE].KickGroup(diffHorde - diffAli))
468 {
469 for (; aliIndex < aliCount && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), (aliFree >= diffHorde) ? aliFree - diffHorde : 0); aliIndex++)
470 ++Ali_itr;
471 }
472
473 //if ali selection is already empty, then kick horde group, but if there are less horde than ali in bg - break;
474 if (!m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
475 {
476 if (aliFree <= diffHorde + 1)
477 break;
478
479 m_SelectionPools[TEAM_HORDE].KickGroup(diffHorde - diffAli);
480 }
481 }
482 else
483 {
484 //kick horde group, add to pool new group if needed
485 if (m_SelectionPools[TEAM_HORDE].KickGroup(diffAli - diffHorde))
486 {
487 for (; hordeIndex < hordeCount && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), (hordeFree >= diffAli) ? hordeFree - diffAli : 0); hordeIndex++)
488 ++Horde_itr;
489 }
490
491 if (!m_SelectionPools[TEAM_HORDE].GetPlayerCount())
492 {
493 if (hordeFree <= diffAli + 1)
494 break;
495
496 m_SelectionPools[TEAM_ALLIANCE].KickGroup(diffAli - diffHorde);
497 }
498 }
499
500 //count diffs after small update
501 diffAli = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
502 diffHorde = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
503 }
504}
@ BG_QUEUE_INVITATION_TYPE_EVEN
Definition: Battleground.h:289
uint32 GetFreeSlotsForTeam(TeamId teamId) const
Definition: Battleground.cpp:1194
bool KickGroup(uint32 size)
Definition: BattlegroundQueue.cpp:82

References BattlegroundQueue::SelectionPool::AddGroup(), BG_QUEUE_INVITATION_TYPE_EVEN, BG_QUEUE_INVITATION_TYPE_NO_BALANCE, BG_QUEUE_NORMAL_ALLIANCE, BG_QUEUE_NORMAL_HORDE, CONFIG_BATTLEGROUND_INVITATION_TYPE, Battleground::GetFreeSlotsForTeam(), BattlegroundQueue::SelectionPool::KickGroup(), m_QueuedGroups, m_SelectionPools, sScriptMgr, sWorld, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by BattlegroundQueueUpdate().

◆ GetAverageQueueWaitTime()

uint32 BattlegroundQueue::GetAverageQueueWaitTime ( GroupQueueInfo ginfo) const
234{
235 // team_index: bg alliance - TEAM_ALLIANCE, bg horde - TEAM_HORDE, arena skirmish - TEAM_ALLIANCE, arena rated - TEAM_HORDE
236 uint8 team_index;
237 if (!ginfo->ArenaType)
238 team_index = ginfo->teamId;
239 else
240 team_index = (ginfo->IsRated ? TEAM_HORDE : TEAM_ALLIANCE);
241
242 // just to be sure
243 if (team_index >= TEAM_NEUTRAL)
244 return 0;
245
246 // if there are enough values:
248 {
249 uint32 sum = 0;
251 sum += m_WaitTimes[team_index][ginfo->BracketId][i];
253 }
254 else
255 return 0;
256}
@ TEAM_NEUTRAL
Definition: SharedDefines.h:734
uint8 ArenaType
Definition: BattlegroundQueue.h:37
uint8 BracketId
Definition: BattlegroundQueue.h:47
bool IsRated
Definition: BattlegroundQueue.h:36

References GroupQueueInfo::ArenaType, GroupQueueInfo::BracketId, COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME, GroupQueueInfo::IsRated, m_WaitTimes, TEAM_ALLIANCE, TEAM_HORDE, TEAM_NEUTRAL, and GroupQueueInfo::teamId.

Referenced by WorldSession::HandleBattlefieldStatusOpcode(), WorldSession::HandleBattlemasterJoinArena(), and WorldSession::HandleBattlemasterJoinOpcode().

◆ GetPlayerGroupInfoData()

bool BattlegroundQueue::GetPlayerGroupInfoData ( ObjectGuid  guid,
GroupQueueInfo ginfo 
)

◆ GetPlayersCountInGroupsQueue()

uint32 BattlegroundQueue::GetPlayersCountInGroupsQueue ( BattlegroundBracketId  bracketId,
BattlegroundQueueGroupTypes  bgqueue 
)
1010{
1011 uint32 playersCount = 0;
1012
1013 for (auto const& itr : m_QueuedGroups[bracketId][bgqueue])
1014 if (!itr->IsInvitedToBGInstanceGUID)
1015 playersCount += static_cast<uint32>(itr->Players.size());
1016
1017 return playersCount;
1018}

References m_QueuedGroups.

Referenced by BattlegroundQueueAnnouncerUpdate(), SendJoinMessageArenaQueue(), and SendMessageBGQueue().

◆ GetQueueAnnouncementTimer()

int32 BattlegroundQueue::GetQueueAnnouncementTimer ( uint32  bracketId) const
1182{
1183 return _queueAnnouncementTimer[bracketId];
1184}

References _queueAnnouncementTimer.

◆ InviteGroupToBG()

void BattlegroundQueue::InviteGroupToBG ( GroupQueueInfo ginfo,
Battleground bg,
TeamId  teamId 
)
1187{
1188 // set side if needed
1189 if (teamId != TEAM_NEUTRAL)
1190 ginfo->teamId = teamId;
1191
1192 if (ginfo->IsInvitedToBGInstanceGUID)
1193 return;
1194
1195 // set invitation
1197
1198 BattlegroundTypeId bgTypeId = bg->GetBgTypeID();
1200 BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
1201
1202 // set ArenaTeamId for rated matches
1203 if (bg->isArena() && bg->isRated())
1204 bg->SetArenaTeamIdForTeam(ginfo->teamId, ginfo->ArenaTeamId);
1205
1207
1208 // loop through the players
1209 for (auto const& itr : ginfo->Players)
1210 {
1211 // get the player
1213 if (!player)
1214 continue;
1215
1216 // update average wait time
1218
1219 // increase invited counter for each invited player
1220 bg->IncreaseInvitedCount(ginfo->teamId);
1221
1222 player->SetInviteForBattlegroundQueueType(bgQueueTypeId, ginfo->IsInvitedToBGInstanceGUID);
1223
1224 // create remind invite events
1225 BGQueueInviteEvent* inviteEvent = new BGQueueInviteEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, ginfo->ArenaType, ginfo->RemoveInviteTime);
1226 bgQueue.AddEvent(inviteEvent, INVITATION_REMIND_TIME);
1227
1228 // create automatic remove events
1229 BGQueueRemoveEvent* removeEvent = new BGQueueRemoveEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, bgQueueTypeId, ginfo->RemoveInviteTime);
1230 bgQueue.AddEvent(removeEvent, INVITE_ACCEPT_WAIT_TIME);
1231
1232 // Check queueSlot
1233 uint32 queueSlot = player->GetBattlegroundQueueIndex(bgQueueTypeId);
1235
1236 LOG_DEBUG("bg.battleground", "Battleground: invited player {} {} to BG instance {} queueindex {} bgtype {}",
1237 player->GetName(), player->GetGUID().ToString(), bg->GetInstanceID(), queueSlot, bgTypeId);
1238
1239 // send status packet
1240 WorldPacket data;
1241 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_WAIT_JOIN, INVITE_ACCEPT_WAIT_TIME, 0, ginfo->ArenaType, TEAM_NEUTRAL, bg->isRated());
1242 player->GetSession()->SendPacket(&data);
1243
1244 // pussywizard:
1245 if (bg->isArena() && bg->isRated())
1246 bg->ArenaLogEntries[player->GetGUID()].Fill(player->GetName(), player->GetGUID().GetCounter(), player->GetSession()->GetAccountId(), ginfo->ArenaTeamId, player->GetSession()->GetRemoteAddress());
1247 }
1248}
@ INVITE_ACCEPT_WAIT_TIME
Definition: Battleground.h:160
@ INVITATION_REMIND_TIME
Definition: Battleground.h:159
@ STATUS_WAIT_JOIN
Definition: Battleground.h:196
BattlegroundQueueTypeId
Definition: SharedDefines.h:3591
#define PLAYER_MAX_BATTLEGROUND_QUEUES
Definition: SharedDefines.h:148
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:262
ArenaLogEntryDataMap ArenaLogEntries
Definition: Battleground.h:401
uint32 GetInstanceID() const
Definition: Battleground.h:321
void IncreaseInvitedCount(TeamId teamId)
Definition: Battleground.h:371
void SetArenaTeamIdForTeam(TeamId teamId, uint32 ArenaTeamId)
Definition: Battleground.h:492
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition: BattlegroundMgr.cpp:671
uint32 IsInvitedToBGInstanceGUID
Definition: BattlegroundQueue.h:41
GuidSet Players
Definition: BattlegroundQueue.h:32
uint32 RemoveInviteTime
Definition: BattlegroundQueue.h:40
Definition: BattlegroundQueue.h:64
void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo *ginfo)
Definition: BattlegroundQueue.cpp:207
void AddEvent(BasicEvent *Event, uint64 e_time)
Definition: BattlegroundQueue.cpp:365
Definition: BattlegroundQueue.h:147
Definition: BattlegroundQueue.h:170
std::string const & GetName() const
Definition: Object.h:446
LowType GetCounter() const
Definition: ObjectGuid.h:147
std::string ToString() const
Definition: ObjectGuid.cpp:47
WorldSession * GetSession() const
Definition: Player.h:1948
uint32 GetBattlegroundQueueIndex(BattlegroundQueueTypeId bgQueueTypeId) const
Definition: Player.cpp:12122
void SetInviteForBattlegroundQueueType(BattlegroundQueueTypeId bgQueueTypeId, uint32 instanceId)
Definition: Player.cpp:12182
Definition: WorldPacket.h:27
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:207
uint32 GetAccountId() const
Definition: WorldSession.h:360
std::string const & GetRemoteAddress()
Definition: WorldSession.h:370

References AddEvent(), Battleground::ArenaLogEntries, GroupQueueInfo::ArenaTeamId, GroupQueueInfo::ArenaType, ASSERT, BattlegroundMgr::BGQueueTypeId(), GroupQueueInfo::BgTypeId, ObjectAccessor::FindConnectedPlayer(), WorldSession::GetAccountId(), Player::GetBattlegroundQueueIndex(), Battleground::GetBgTypeID(), ObjectGuid::GetCounter(), GameTime::GetGameTimeMS(), Object::GetGUID(), Battleground::GetInstanceID(), WorldObject::GetName(), WorldSession::GetRemoteAddress(), Player::GetSession(), Battleground::IncreaseInvitedCount(), INVITATION_REMIND_TIME, INVITE_ACCEPT_WAIT_TIME, Battleground::isArena(), GroupQueueInfo::IsInvitedToBGInstanceGUID, Battleground::isRated(), LOG_DEBUG, PLAYER_MAX_BATTLEGROUND_QUEUES, PlayerInvitedToBGUpdateAverageWaitTime(), GroupQueueInfo::Players, GroupQueueInfo::RemoveInviteTime, sBattlegroundMgr, WorldSession::SendPacket(), Battleground::SetArenaTeamIdForTeam(), Player::SetInviteForBattlegroundQueueType(), STATUS_WAIT_JOIN, TEAM_NEUTRAL, GroupQueueInfo::teamId, and ObjectGuid::ToString().

Referenced by BattlegroundQueueUpdate().

◆ IsAllQueuesEmpty()

bool BattlegroundQueue::IsAllQueuesEmpty ( BattlegroundBracketId  bracket_id)
1021{
1022 uint8 queueEmptyCount = 0;
1023
1024 for (uint8 i = 0; i < BG_QUEUE_MAX; i++)
1025 if (m_QueuedGroups[bracket_id][i].empty())
1026 queueEmptyCount++;
1027
1028 return queueEmptyCount == BG_QUEUE_MAX;
1029}
@ BG_QUEUE_MAX
Definition: BattlegroundQueue.h:60

References BG_QUEUE_MAX, and m_QueuedGroups.

Referenced by BattlegroundQueueUpdate().

◆ IsPlayerInvited()

bool BattlegroundQueue::IsPlayerInvited ( ObjectGuid  pl_guid,
uint32  bgInstanceGuid,
uint32  removeTime 
)
378{
379 auto qItr = m_QueuedPlayers.find(pl_guid);
380 return qItr != m_QueuedPlayers.end() && qItr->second->IsInvitedToBGInstanceGUID == bgInstanceGuid && qItr->second->RemoveInviteTime == removeTime;
381}

References m_QueuedPlayers.

Referenced by BGQueueInviteEvent::Execute(), and BGQueueRemoveEvent::Execute().

◆ IsPlayerInvitedToRatedArena()

bool BattlegroundQueue::IsPlayerInvitedToRatedArena ( ObjectGuid  pl_guid)
371{
372 auto qItr = m_QueuedPlayers.find(pl_guid);
373 return qItr != m_QueuedPlayers.end() && qItr->second->IsRated && qItr->second->IsInvitedToBGInstanceGUID;
374}

References m_QueuedPlayers.

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ PlayerInvitedToBGUpdateAverageWaitTime()

void BattlegroundQueue::PlayerInvitedToBGUpdateAverageWaitTime ( GroupQueueInfo ginfo)
208{
209 uint32 timeInQueue = std::max<uint32>(1, getMSTimeDiff(ginfo->JoinTime, GameTime::GetGameTimeMS().count()));
210
211 // team_index: bg alliance - TEAM_ALLIANCE, bg horde - TEAM_HORDE, arena skirmish - TEAM_ALLIANCE, arena rated - TEAM_HORDE
212 uint8 team_index;
213 if (!ginfo->ArenaType)
214 team_index = ginfo->teamId;
215 else
216 team_index = (ginfo->IsRated ? TEAM_HORDE : TEAM_ALLIANCE);
217
218 // just to be sure
219 if (team_index >= TEAM_NEUTRAL)
220 return;
221
222 // pointer to last index
223 uint32* lastIndex = &m_WaitTimeLastIndex[team_index][ginfo->BracketId];
224
225 // set time at index to new value
226 m_WaitTimes[team_index][ginfo->BracketId][*lastIndex] = timeInQueue;
227
228 // set last index to next one
229 (*lastIndex)++;
231}
uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
Definition: Timer.h:110

References GroupQueueInfo::ArenaType, GroupQueueInfo::BracketId, COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME, GameTime::GetGameTimeMS(), getMSTimeDiff(), GroupQueueInfo::IsRated, GroupQueueInfo::JoinTime, m_WaitTimeLastIndex, m_WaitTimes, TEAM_ALLIANCE, TEAM_HORDE, TEAM_NEUTRAL, and GroupQueueInfo::teamId.

Referenced by InviteGroupToBG().

◆ RemovePlayer()

void BattlegroundQueue::RemovePlayer ( ObjectGuid  guid,
bool  decreaseInvitedCount 
)
260{
261 //remove player from map, if he's there
262 auto const& itr = m_QueuedPlayers.find(guid);
263 if (itr == m_QueuedPlayers.end())
264 {
265 //This happens if a player logs out while in a bg because WorldSession::LogoutPlayer() notifies the bg twice
266 std::string playerName = "Unknown";
267
268 if (Player* player = ObjectAccessor::FindPlayer(guid))
269 {
270 playerName = player->GetName();
271 }
272
273 LOG_ERROR("bg.battleground", "BattlegroundQueue: couldn't find player {} ({})", playerName, guid.ToString());
274 //ABORT("BattlegroundQueue: couldn't find player {} ({})", playerName, guid.ToString());
275 return;
276 }
277
278 GroupQueueInfo* groupInfo = itr->second;
279
280 uint32 _bracketId = groupInfo->BracketId;
281 uint32 _groupType = groupInfo->GroupType;
282
283 // find iterator
284 auto group_itr = m_QueuedGroups[_bracketId][_groupType].end();
285
286 for (auto k = m_QueuedGroups[_bracketId][_groupType].begin(); k != m_QueuedGroups[_bracketId][_groupType].end(); k++)
287 if ((*k) == groupInfo)
288 {
289 group_itr = k;
290 break;
291 }
292
293 // player can't be in queue without group, but just in case
294 if (group_itr == m_QueuedGroups[_bracketId][_groupType].end())
295 {
296 LOG_ERROR("bg.battleground", "BattlegroundQueue: ERROR Cannot find groupinfo for {}", guid.ToString());
297 //ABORT("BattlegroundQueue: ERROR Cannot find groupinfo for {}", guid.ToString());
298 return;
299 }
300
301 LOG_DEBUG("bg.battleground", "BattlegroundQueue: Removing {}, from bracket_id {}", guid.ToString(), _bracketId);
302
303 // remove player from group queue info
304 auto const& pitr = groupInfo->Players.find(guid);
305 ASSERT(pitr != groupInfo->Players.end());
306 if (pitr != groupInfo->Players.end())
307 groupInfo->Players.erase(pitr);
308
309 // if invited to bg, and should decrease invited count, then do it
310 if (decreaseInvitedCount && groupInfo->IsInvitedToBGInstanceGUID)
311 if (Battleground* bg = sBattlegroundMgr->GetBattleground(groupInfo->IsInvitedToBGInstanceGUID, groupInfo->BgTypeId))
312 bg->DecreaseInvitedCount(groupInfo->teamId);
313
314 // remove player queue info
315 m_QueuedPlayers.erase(itr);
316
317 // announce to world if arena team left queue for rated match, show only once
318 SendExitMessageArenaQueue(groupInfo);
319
320 // if player leaves queue and he is invited to a rated arena match, then count it as he lost
321 if (groupInfo->IsInvitedToBGInstanceGUID && groupInfo->IsRated && decreaseInvitedCount)
322 {
323 if (ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(groupInfo->ArenaTeamId))
324 {
325 LOG_DEBUG("bg.battleground", "UPDATING memberLost's personal arena rating for {} by opponents rating: {}", guid.ToString(), groupInfo->OpponentsTeamRating);
326
328 {
329 at->MemberLost(player, groupInfo->OpponentsMatchmakerRating);
330 }
331
332 at->SaveToDB();
333 }
334 }
335
336 // remove group queue info no players left
337 if (groupInfo->Players.empty())
338 {
339 m_QueuedGroups[_bracketId][_groupType].erase(group_itr);
340 delete groupInfo;
341 return;
342 }
343
344 // group isn't yet empty, so not deleted yet
345 // if it's a rated arena and any member leaves when group not yet invited - everyone from group leaves too!
346 if (groupInfo->IsRated && !groupInfo->IsInvitedToBGInstanceGUID)
347 {
348 if (Player* plr = ObjectAccessor::FindConnectedPlayer(*(groupInfo->Players.begin())))
349 {
350 Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(groupInfo->BgTypeId);
351 BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId(groupInfo->BgTypeId, groupInfo->ArenaType);
352 uint32 queueSlot = plr->GetBattlegroundQueueIndex(bgQueueTypeId);
353 plr->RemoveBattlegroundQueueId(bgQueueTypeId);
354
355 WorldPacket data;
356 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_NONE, 0, 0, 0, TEAM_NEUTRAL);
357 plr->SendDirectMessage(&data);
358 }
359
360 // recursive call
361 RemovePlayer(*groupInfo->Players.begin(), decreaseInvitedCount);
362 }
363}
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:67
@ STATUS_NONE
Definition: Battleground.h:194
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:250
Definition: ArenaTeam.h:138
void SendExitMessageArenaQueue(GroupQueueInfo *ginfo)
Definition: BattlegroundQueue.cpp:1150
void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount)
Definition: BattlegroundQueue.cpp:259

References GroupQueueInfo::ArenaTeamId, GroupQueueInfo::ArenaType, ASSERT, BattlegroundMgr::BGQueueTypeId(), GroupQueueInfo::BgTypeId, GroupQueueInfo::BracketId, ObjectAccessor::FindConnectedPlayer(), ObjectAccessor::FindPlayer(), GroupQueueInfo::GroupType, GroupQueueInfo::IsInvitedToBGInstanceGUID, GroupQueueInfo::IsRated, LOG_DEBUG, LOG_ERROR, m_QueuedGroups, m_QueuedPlayers, GroupQueueInfo::OpponentsMatchmakerRating, GroupQueueInfo::OpponentsTeamRating, GroupQueueInfo::Players, RemovePlayer(), sArenaTeamMgr, sBattlegroundMgr, SendExitMessageArenaQueue(), STATUS_NONE, TEAM_NEUTRAL, GroupQueueInfo::teamId, and ObjectGuid::ToString().

Referenced by ArenaTeam::DelMember(), BGQueueRemoveEvent::Execute(), WorldSession::HandleBattleFieldPortOpcode(), and RemovePlayer().

◆ SendExitMessageArenaQueue()

void BattlegroundQueue::SendExitMessageArenaQueue ( GroupQueueInfo ginfo)
1151{
1152 if (!sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
1153 return;
1154
1155 if (!sScriptMgr->OnBeforeSendExitMessageArenaQueue(this, ginfo))
1156 return;
1157
1158 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(ginfo->ArenaTeamId);
1159 if (!team)
1160 return;
1161
1162 if (!ginfo->IsRated)
1163 return;
1164
1165 uint8 ArenaType = ginfo->ArenaType;
1166 uint32 ArenaTeamRating = ginfo->ArenaTeamRating;
1167 std::string TeamName = team->GetName();
1168
1169 if (ArenaType && ginfo->Players.empty())
1170 {
1171 sWorld->SendWorldTextOptional(LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT, ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE, TeamName.c_str(), ArenaType, ArenaType, ArenaTeamRating);
1172 }
1173}
ArenaType
Definition: Battleground.h:211
@ ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE
Definition: PlayerSettings.h:34
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT
Definition: Language.h:670
@ CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE
Definition: IWorld.h:124
std::string const & GetName() const
Definition: ArenaTeam.h:155

References ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE, GroupQueueInfo::ArenaTeamId, GroupQueueInfo::ArenaTeamRating, GroupQueueInfo::ArenaType, CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE, ArenaTeam::GetName(), GroupQueueInfo::IsRated, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT, GroupQueueInfo::Players, sArenaTeamMgr, sScriptMgr, and sWorld.

Referenced by RemovePlayer().

◆ SendJoinMessageArenaQueue()

void BattlegroundQueue::SendJoinMessageArenaQueue ( Player leader,
GroupQueueInfo ginfo,
PvPDifficultyEntry const *  bracketEntry,
bool  isRated 
)
1086{
1087 if (!sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
1088 return;
1089
1090 if (!sScriptMgr->OnBeforeSendJoinMessageArenaQueue(this, leader, ginfo, bracketEntry, isRated))
1091 return;
1092
1093 if (!isRated)
1094 {
1095 Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(ginfo->BgTypeId);
1096 if (!bg)
1097 {
1098 LOG_ERROR("bg.arena", "> Not found bg template for bgtype id {}", uint32(ginfo->BgTypeId));
1099 return;
1100 }
1101
1102 if (!bg->isArena())
1103 {
1104 // Skip announce for non arena
1105 return;
1106 }
1107
1108 BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
1109 auto bgName = bg->GetName();
1110 auto arenatype = Acore::StringFormat("%uv%u", ginfo->ArenaType, ginfo->ArenaType);
1111 uint32 playersNeed = ArenaTeam::GetReqPlayersForType(ginfo->ArenaType);
1112 uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32)80);
1113 uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32)80);
1115
1116 LOG_DEBUG("bg.arena", "> Queue status for {} (skirmish {}) (Lvl: {} to {}) Queued: {} (Need at least {} more)",
1117 bgName, arenatype, q_min_level, q_max_level, qPlayers, playersNeed - qPlayers);
1118
1120 {
1122 bgName, arenatype.c_str(), q_min_level, q_max_level, qPlayers, playersNeed - qPlayers);
1123 }
1124 else
1125 {
1126 if (!sBGSpam->CanAnnounce(leader, bg, q_min_level, qPlayers))
1127 {
1128 return;
1129 }
1130
1131 sWorld->SendWorldTextOptional(LANG_ARENA_QUEUE_ANNOUNCE_WORLD, ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE, bgName.c_str(), arenatype.c_str(), q_min_level, q_max_level, qPlayers, playersNeed);
1132 }
1133 }
1134 else
1135 {
1136 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(ginfo->ArenaTeamId);
1137 if (!team || !ginfo->IsRated)
1138 {
1139 return;
1140 }
1141
1142 uint8 ArenaType = ginfo->ArenaType;
1143 uint32 ArenaTeamRating = ginfo->ArenaTeamRating;
1144 std::string TeamName = team->GetName();
1145
1146 sWorld->SendWorldTextOptional(LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN, ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE, TeamName.c_str(), ArenaType, ArenaType, ArenaTeamRating);
1147 }
1148}
#define sBGSpam
Definition: BattlegroundSpamProtect.h:34
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD
Definition: Language.h:663
@ LANG_ARENA_QUEUE_ANNOUNCE_SELF
Definition: Language.h:662
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN
Definition: Language.h:669
@ CONFIG_ARENA_QUEUE_ANNOUNCER_PLAYERONLY
Definition: IWorld.h:125
std::string StringFormat(Format &&fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:29
static uint8 GetReqPlayersForType(uint32 type)
Definition: ArenaTeam.cpp:1011
Definition: Chat.h:38
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60

References ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE, GroupQueueInfo::ArenaTeamId, GroupQueueInfo::ArenaTeamRating, GroupQueueInfo::ArenaType, BG_QUEUE_NORMAL_ALLIANCE, BG_QUEUE_NORMAL_HORDE, GroupQueueInfo::BgTypeId, CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE, CONFIG_ARENA_QUEUE_ANNOUNCER_PLAYERONLY, PvPDifficultyEntry::GetBracketId(), ArenaTeam::GetName(), Battleground::GetName(), GetPlayersCountInGroupsQueue(), ArenaTeam::GetReqPlayersForType(), Player::GetSession(), Battleground::isArena(), GroupQueueInfo::IsRated, LANG_ARENA_QUEUE_ANNOUNCE_SELF, LANG_ARENA_QUEUE_ANNOUNCE_WORLD, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN, LOG_DEBUG, LOG_ERROR, PvPDifficultyEntry::maxLevel, PvPDifficultyEntry::minLevel, ChatHandler::PSendSysMessage(), sArenaTeamMgr, sBattlegroundMgr, sBGSpam, sScriptMgr, Acore::StringFormat(), and sWorld.

Referenced by AddGroup().

◆ SendMessageBGQueue()

void BattlegroundQueue::SendMessageBGQueue ( Player leader,
Battleground bg,
PvPDifficultyEntry const *  bracketEntry 
)
1032{
1033 if (!sScriptMgr->CanSendMessageBGQueue(this, leader, bg, bracketEntry))
1034 {
1035 return;
1036 }
1037
1038 if (bg->isArena())
1039 {
1040 // Skip announce for arena skirmish
1041 return;
1042 }
1043
1044 BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
1045 auto bgName = bg->GetName();
1046 uint32 MinPlayers = bg->GetMinPlayersPerTeam();
1047 uint32 MaxPlayers = MinPlayers * 2;
1048 uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32)80);
1049 uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32)80);
1052 auto qTotal = qHorde + qAlliance;
1053
1054 LOG_DEBUG("bg.battleground", "> Queue status for {} (Lvl: {} to {}) Queued: {} (Need at least {} more)",
1055 bgName, q_min_level, q_max_level, qAlliance + qHorde, MaxPlayers - qTotal);
1056
1057 // Show queue status to player only (when joining battleground queue or Arena and arena world announcer is disabled)
1059 {
1060 ChatHandler(leader->GetSession()).PSendSysMessage(LANG_BG_QUEUE_ANNOUNCE_SELF, bgName.c_str(), q_min_level, q_max_level,
1061 qAlliance, (MinPlayers > qAlliance) ? MinPlayers - qAlliance : (uint32)0,
1062 qHorde, (MinPlayers > qHorde) ? MinPlayers - qHorde : (uint32)0);
1063 }
1064 else // Show queue status to server (when joining battleground queue)
1065 {
1067 {
1068 if (_queueAnnouncementTimer[bracketId] < 0)
1069 {
1071 }
1072 }
1073 else
1074 {
1075 if (!sBGSpam->CanAnnounce(leader, bg, q_min_level, qTotal))
1076 {
1077 return;
1078 }
1079
1080 sWorld->SendWorldTextOptional(LANG_BG_QUEUE_ANNOUNCE_WORLD, ANNOUNCER_FLAG_DISABLE_BG_QUEUE, bgName.c_str(), q_min_level, q_max_level, qAlliance + qHorde, MaxPlayers);
1081 }
1082 }
1083}
@ LANG_BG_QUEUE_ANNOUNCE_SELF
Definition: Language.h:658
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMER
Definition: IWorld.h:307
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY
Definition: IWorld.h:117

References _queueAnnouncementTimer, ANNOUNCER_FLAG_DISABLE_BG_QUEUE, BG_QUEUE_NORMAL_ALLIANCE, BG_QUEUE_NORMAL_HORDE, CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY, CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMED, CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMER, PvPDifficultyEntry::GetBracketId(), Battleground::GetMinPlayersPerTeam(), Battleground::GetName(), GetPlayersCountInGroupsQueue(), Player::GetSession(), Battleground::isArena(), LANG_BG_QUEUE_ANNOUNCE_SELF, LANG_BG_QUEUE_ANNOUNCE_WORLD, LOG_DEBUG, PvPDifficultyEntry::maxLevel, PvPDifficultyEntry::minLevel, ChatHandler::PSendSysMessage(), sBGSpam, sScriptMgr, and sWorld.

Referenced by AddGroup().

◆ SetQueueAnnouncementTimer()

void BattlegroundQueue::SetQueueAnnouncementTimer ( uint32  bracketId,
int32  timer,
bool  isCrossFactionBG = true 
)
1176{
1177 _queueAnnouncementTimer[bracketId] = timer;
1178 _queueAnnouncementCrossfactioned = isCrossFactionBG;
1179}

References _queueAnnouncementCrossfactioned, and _queueAnnouncementTimer.

◆ UpdateEvents()

void BattlegroundQueue::UpdateEvents ( uint32  diff)
701{
702 m_events.Update(diff);
703}
void Update(uint32 p_time)
Definition: EventProcessor.cpp:40

References m_events, and EventProcessor::Update().

Member Data Documentation

◆ _queueAnnouncementCrossfactioned

bool BattlegroundQueue::_queueAnnouncementCrossfactioned
private

◆ _queueAnnouncementTimer

◆ m_events

EventProcessor BattlegroundQueue::m_events
private

◆ m_QueuedGroups

◆ m_QueuedPlayers

◆ m_SelectionPools

◆ m_WaitTimeLastIndex

uint32 BattlegroundQueue::m_WaitTimeLastIndex[PVP_TEAMS_COUNT][MAX_BATTLEGROUND_BRACKETS]
private

◆ m_WaitTimes