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 ( )
41{
42 for (uint32 i = 0; i < PVP_TEAMS_COUNT; ++i)
43 {
44 for (uint32 j = 0; j < MAX_BATTLEGROUND_BRACKETS; ++j)
45 {
46 m_WaitTimeLastIndex[i][j] = 0;
48 m_WaitTimes[i][j][k] = 0;
49 }
50 }
51
54}
std::uint32_t uint32
Definition: Define.h:107
#define MAX_BATTLEGROUND_BRACKETS
Definition: DBCEnums.h:52
uint8 constexpr PVP_TEAMS_COUNT
Definition: SharedDefines.h:3445
constexpr auto COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
Definition: BattlegroundQueue.h:28
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 ( )
57{
59
60 m_QueuedPlayers.clear();
61 for (auto& m_QueuedGroup : m_QueuedGroups)
62 {
63 for (auto& j : m_QueuedGroup)
64 {
65 for (auto& itr : j)
66 delete itr;
67 j.clear();
68 }
69 }
70}
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 
)
368{
370}
Event
Definition: boss_prince_taldaram.cpp:68
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
Definition: EventProcessor.h:103
uint64 CalculateTime(uint64 t_offset) const
Definition: EventProcessor.cpp:159

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

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 
)
961{
962 BattlegroundTypeId bgTypeId = BattlegroundMgr::BGTemplateId(bgQueueTypeId);
963 Battleground* bg_template = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId);
964 if (!bg_template)
965 {
966 return;
967 }
968
969 PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketById(bg_template->GetMapId(), bracket_id);
970 if (!bracketEntry)
971 {
972 return;
973 }
974
976 {
977 uint32 qPlayers = 0;
978
980 {
981 qPlayers = GetPlayersCountInGroupsQueue(bracket_id, BG_QUEUE_CFBG);
982 }
983 else
984 {
986 }
987
988 if (!qPlayers)
989 {
990 _queueAnnouncementTimer[bracket_id] = -1;
991 return;
992 }
993
994 if (_queueAnnouncementTimer[bracket_id] >= 0)
995 {
996 if (_queueAnnouncementTimer[bracket_id] <= static_cast<int32>(diff))
997 {
998 _queueAnnouncementTimer[bracket_id] = -1;
999
1000 auto bgName = bg_template->GetName();
1001 uint32 MaxPlayers = GetMinPlayersPerTeam(bg_template, bracketEntry) * 2;
1002 uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32) 80);
1003 uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32) 80);
1004
1005 ChatHandler(nullptr).SendWorldTextOptional(LANG_BG_QUEUE_ANNOUNCE_WORLD, ANNOUNCER_FLAG_DISABLE_BG_QUEUE, bgName.c_str(), q_min_level, q_max_level, qPlayers, MaxPlayers);
1006 }
1007 else
1008 {
1009 _queueAnnouncementTimer[bracket_id] -= static_cast<int32>(diff);
1010 }
1011 }
1012 }
1013}
std::int32_t int32
Definition: Define.h:103
BattlegroundTypeId
Definition: SharedDefines.h:3479
@ LANG_BG_QUEUE_ANNOUNCE_WORLD
Definition: Language.h:679
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMED
Definition: IWorld.h:114
@ ANNOUNCER_FLAG_DISABLE_BG_QUEUE
Definition: PlayerSettings.h:33
PvPDifficultyEntry const * GetBattlegroundBracketById(uint32 mapid, BattlegroundBracketId id)
Definition: DBCStores.cpp:815
@ BG_QUEUE_NORMAL_ALLIANCE
Definition: BattlegroundQueue.h:55
@ BG_QUEUE_CFBG
Definition: BattlegroundQueue.h:58
@ BG_QUEUE_NORMAL_HORDE
Definition: BattlegroundQueue.h:56
uint32 GetMinPlayersPerTeam(Battleground *bg, PvPDifficultyEntry const *bracketEntry)
Definition: BattlegroundUtils.cpp:4
uint32 GetMapId() const
Definition: Battleground.h:445
std::string GetName() const
Definition: Battleground.h:328
static BattlegroundTypeId BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId)
Definition: BattlegroundMgr.cpp:696
uint32 GetPlayersCountInGroupsQueue(BattlegroundBracketId bracketId, BattlegroundQueueGroupTypes bgqueue)
Definition: BattlegroundQueue.cpp:1015
Definition: Chat.h:37
void SendWorldTextOptional(std::string_view str, uint32 flag)
Definition: Chat.cpp:142
Definition: DBCStructure.h:1430
uint32 maxLevel
Definition: DBCStructure.h:1435
uint32 minLevel
Definition: DBCStructure.h:1434

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(), GetMinPlayersPerTeam(), Battleground::GetName(), GetPlayersCountInGroupsQueue(), LANG_BG_QUEUE_ANNOUNCE_WORLD, PvPDifficultyEntry::maxLevel, PvPDifficultyEntry::minLevel, sBattlegroundMgr, ChatHandler::SendWorldTextOptional(), and sWorld.

Referenced by BattlegroundMgr::Update().

◆ BattlegroundQueueUpdate()

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

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(), 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 
)
577{
578 auto CanStartMatch = [this, bgTemplate, minPlayers]()
579 {
580 //allow 1v0 if debug bg
582 return true;
583
584 //return true if there are enough players in selection pools - enable to work .debug bg command correctly
586 };
587
588 if (sScriptMgr->IsCheckNormalMatch(this, bgTemplate, bracket_id, minPlayers, maxPlayers))
589 return CanStartMatch();
590
591 GroupsQueueType::const_iterator itr_team[PVP_TEAMS_COUNT];
592 for (uint32 i = 0; i < PVP_TEAMS_COUNT; i++)
593 {
594 itr_team[i] = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin();
595 for (; itr_team[i] != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].end(); ++(itr_team[i]))
596 {
597 if (!(*(itr_team[i]))->IsInvitedToBGInstanceGUID)
598 {
599 m_SelectionPools[i].AddGroup(*(itr_team[i]), maxPlayers);
600 if (m_SelectionPools[i].GetPlayerCount() >= minPlayers)
601 break;
602 }
603 }
604 }
605
606 //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
609 j = TEAM_HORDE;
610
613 {
614 //we will try to invite more groups to team with less players indexed by j
615 ++(itr_team[j]); //this will not cause a crash, because for cycle above reached break;
616 for (; itr_team[j] != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + j].end(); ++(itr_team[j]))
617 {
618 if (!(*(itr_team[j]))->IsInvitedToBGInstanceGUID)
619 if (!m_SelectionPools[j].AddGroup(*(itr_team[j]), m_SelectionPools[(j + 1) % PVP_TEAMS_COUNT].GetPlayerCount()))
620 break;
621 }
622
623 // do not allow to start bg with more than 2 players more on 1 faction
625 return false;
626 }
627
628 return CanStartMatch();
629}
@ CONFIG_BATTLEGROUND_INVITATION_TYPE
Definition: IWorld.h:315
@ BG_QUEUE_INVITATION_TYPE_NO_BALANCE
Definition: Battleground.h:297
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:134
bool AddGroup(GroupQueueInfo *ginfo, uint32 desiredCount)
Definition: BattlegroundQueue.cpp:117
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 
)
511{
512 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty() && !m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty())
513 {
514 //start premade match
515 //if groups aren't invited
516 GroupsQueueType::const_iterator ali_group, horde_group;
517 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)
518 if (!(*ali_group)->IsInvitedToBGInstanceGUID)
519 break;
520
521 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)
522 if (!(*horde_group)->IsInvitedToBGInstanceGUID)
523 break;
524
525 // if found both groups
526 if (ali_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].end() && horde_group != m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].end())
527 {
528 m_SelectionPools[TEAM_ALLIANCE].AddGroup((*ali_group), MaxPlayersPerTeam);
529 m_SelectionPools[TEAM_HORDE].AddGroup((*horde_group), MaxPlayersPerTeam);
530
531 //add groups/players from normal queue to size of bigger group
532 uint32 maxPlayers = std::min(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount(), m_SelectionPools[TEAM_HORDE].GetPlayerCount());
533 GroupsQueueType::const_iterator itr;
534
535 for (uint32 i = 0; i < PVP_TEAMS_COUNT; i++)
536 {
537 for (itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin(); itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].end(); ++itr)
538 {
539 //if itr can join BG and player count is less that maxPlayers, then add group to selectionpool
540 if (!(*itr)->IsInvitedToBGInstanceGUID && !m_SelectionPools[i].AddGroup((*itr), maxPlayers))
541 break;
542 }
543 }
544
545 //premade selection pools are set
546 return true;
547 }
548 }
549
550 // now check if we can move group from Premade queue to normal queue (timer has expired) or group size lowered!!
551 // this could be 2 cycles but i'm checking only first team in queue - it can cause problem -
552 // 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
553 // and when they click or after 80 seconds the queue info is removed from queue
555
556 for (uint32 i = 0; i < PVP_TEAMS_COUNT; i++)
557 {
558 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty())
559 {
560 GroupsQueueType::iterator itr = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].begin();
561 if (!(*itr)->IsInvitedToBGInstanceGUID && ((*itr)->JoinTime < time_before || (*itr)->Players.size() < MinPlayersPerTeam))
562 {
563 //we must insert group to normal queue and erase pointer from premade queue
564 (*itr)->GroupType = BG_QUEUE_NORMAL_ALLIANCE + i; // pussywizard: update GroupQueueInfo internal variable
565 m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + i].push_front((*itr));
566 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].erase(itr);
567 }
568 }
569 }
570
571 //selection pools are not set
572 return false;
573}
@ CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH
Definition: IWorld.h:312

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 
)
633{
634 if (m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() < minPlayersPerTeam && m_SelectionPools[TEAM_HORDE].GetPlayerCount() < minPlayersPerTeam)
635 return false;
636
637 TeamId teamIndex = TEAM_ALLIANCE;
638 TeamId otherTeam = TEAM_HORDE;
639
640 if (m_SelectionPools[TEAM_HORDE].GetPlayerCount() == minPlayersPerTeam)
641 {
642 teamIndex = TEAM_HORDE;
643 otherTeam = TEAM_ALLIANCE;
644 }
645
646 //clear other team's selection
647 m_SelectionPools[otherTeam].Init();
648
649 //store last ginfo pointer
650 GroupQueueInfo* ginfo = m_SelectionPools[teamIndex].SelectedGroups.back();
651
652 //set itr_team to group that was added to selection pool latest
653 GroupsQueueType::iterator itr_team = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].begin();
654 for (; itr_team != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end(); ++itr_team)
655 if (ginfo == *itr_team)
656 break;
657
658 if (itr_team == m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end())
659 return false;
660
661 GroupsQueueType::iterator itr_team2 = itr_team;
662 ++itr_team2;
663
664 //invite players to other selection pool
665 for (; itr_team2 != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end(); ++itr_team2)
666 {
667 //if selection pool is full then break;
668 if (!(*itr_team2)->IsInvitedToBGInstanceGUID && !m_SelectionPools[otherTeam].AddGroup(*itr_team2, minPlayersPerTeam))
669 break;
670 }
671
672 if (m_SelectionPools[otherTeam].GetPlayerCount() != minPlayersPerTeam)
673 return false;
674
675 //here we have correct 2 selections and we need to change one teams team and move selection pool teams to other team's queue
676 for (GroupsQueueType::iterator itr = m_SelectionPools[otherTeam].SelectedGroups.begin(); itr != m_SelectionPools[otherTeam].SelectedGroups.end(); ++itr)
677 {
678 //set correct team
679 (*itr)->teamId = otherTeam;
680 (*itr)->GroupType = static_cast<uint8>(BG_QUEUE_NORMAL_ALLIANCE) + static_cast<uint8>(otherTeam);
681
682 //add team to other queue
683 m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(otherTeam)].push_front(*itr);
684
685 //remove team from old queue
686 GroupsQueueType::iterator itr2 = itr_team;
687 ++itr2;
688
689 for (; itr2 != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].end(); ++itr2)
690 {
691 if (*itr2 == *itr)
692 {
693 m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE + static_cast<uint8>(teamIndex)].erase(itr2);
694 break;
695 }
696 }
697 }
698
699 return true;
700}
TeamId
Definition: SharedDefines.h:759
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 
)
396{
397 if (!sScriptMgr->CanFillPlayersToBG(this, bg, bracket_id))
398 {
399 return;
400 }
401
402 int32 hordeFree = bg->GetFreeSlotsForTeam(TEAM_HORDE);
404 uint32 aliCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].size();
405 uint32 hordeCount = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].size();
406
407 // try to get even teams
409 {
410 // check if the teams are even
411 if (hordeFree == 1 && aliFree == 1)
412 {
413 // if we are here, the teams have the same amount of players
414 // then we have to allow to join the same amount of players
415 int32 hordeExtra = hordeCount - aliCount;
416 int32 aliExtra = aliCount - hordeCount;
417
418 hordeExtra = std::max(hordeExtra, 0);
419 aliExtra = std::max(aliExtra, 0);
420
421 if (aliCount != hordeCount)
422 {
423 aliFree -= aliExtra;
424 hordeFree -= hordeExtra;
425
426 aliFree = std::max(aliFree, 0);
427 hordeFree = std::max(hordeFree, 0);
428 }
429 }
430 }
431
432 GroupsQueueType::const_iterator Ali_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].begin();
433 //count of groups in queue - used to stop cycles
434
435 //index to queue which group is current
436 uint32 aliIndex = 0;
437 for (; aliIndex < aliCount && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree); aliIndex++)
438 ++Ali_itr;
439
440 //the same thing for horde
441 GroupsQueueType::const_iterator Horde_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].begin();
442
443 uint32 hordeIndex = 0;
444 for (; hordeIndex < hordeCount && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree); hordeIndex++)
445 ++Horde_itr;
446
447 //if ofc like BG queue invitation is set in config, then we are happy
449 return;
450
451 /*
452 if we reached this code, then we have to solve NP - complete problem called Subset sum problem
453 So one solution is to check all possible invitation subgroups, or we can use these conditions:
454 1. Last time when BattlegroundQueue::Update was executed we invited all possible players - so there is only small possibility
455 that we will invite now whole queue, because only 1 change has been made to queues from the last BattlegroundQueue::Update call
456 2. Other thing we should consider is group order in queue
457 */
458
459 // At first we need to compare free space in bg and our selection pool
460 int32 diffAli = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
461 int32 diffHorde = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
462
463 while (std::abs(diffAli - diffHorde) > 1 && (m_SelectionPools[TEAM_HORDE].GetPlayerCount() > 0 || m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() > 0))
464 {
465 //each cycle execution we need to kick at least 1 group
466 if (diffAli < diffHorde)
467 {
468 //kick alliance group, add to pool new group if needed
469 if (m_SelectionPools[TEAM_ALLIANCE].KickGroup(diffHorde - diffAli))
470 {
471 for (; aliIndex < aliCount && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), (aliFree >= diffHorde) ? aliFree - diffHorde : 0); aliIndex++)
472 ++Ali_itr;
473 }
474
475 //if ali selection is already empty, then kick horde group, but if there are less horde than ali in bg - break;
476 if (!m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
477 {
478 if (aliFree <= diffHorde + 1)
479 break;
480
481 m_SelectionPools[TEAM_HORDE].KickGroup(diffHorde - diffAli);
482 }
483 }
484 else
485 {
486 //kick horde group, add to pool new group if needed
487 if (m_SelectionPools[TEAM_HORDE].KickGroup(diffAli - diffHorde))
488 {
489 for (; hordeIndex < hordeCount && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), (hordeFree >= diffAli) ? hordeFree - diffAli : 0); hordeIndex++)
490 ++Horde_itr;
491 }
492
493 if (!m_SelectionPools[TEAM_HORDE].GetPlayerCount())
494 {
495 if (hordeFree <= diffAli + 1)
496 break;
497
498 m_SelectionPools[TEAM_ALLIANCE].KickGroup(diffAli - diffHorde);
499 }
500 }
501
502 //count diffs after small update
503 diffAli = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
504 diffHorde = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
505 }
506}
@ BG_QUEUE_INVITATION_TYPE_EVEN
Definition: Battleground.h:299
uint32 GetFreeSlotsForTeam(TeamId teamId) const
Definition: Battleground.cpp:1232
bool KickGroup(uint32 size)
Definition: BattlegroundQueue.cpp:84

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
236{
237 // team_index: bg alliance - TEAM_ALLIANCE, bg horde - TEAM_HORDE, arena skirmish - TEAM_ALLIANCE, arena rated - TEAM_HORDE
238 uint8 team_index;
239 if (!ginfo->ArenaType)
240 team_index = ginfo->teamId;
241 else
242 team_index = (ginfo->IsRated ? TEAM_HORDE : TEAM_ALLIANCE);
243
244 // just to be sure
245 if (team_index >= TEAM_NEUTRAL)
246 return 0;
247
248 // if there are enough values:
250 {
251 uint32 sum = 0;
253 sum += m_WaitTimes[team_index][ginfo->BracketId][i];
255 }
256 else
257 return 0;
258}
@ TEAM_NEUTRAL
Definition: SharedDefines.h:762
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 
)
1016{
1017 uint32 playersCount = 0;
1018
1019 for (auto const& itr : m_QueuedGroups[bracketId][bgqueue])
1020 if (!itr->IsInvitedToBGInstanceGUID)
1021 playersCount += static_cast<uint32>(itr->Players.size());
1022
1023 return playersCount;
1024}

References m_QueuedGroups.

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

◆ GetQueueAnnouncementTimer()

int32 BattlegroundQueue::GetQueueAnnouncementTimer ( uint32  bracketId) const
1218{
1219 return _queueAnnouncementTimer[bracketId];
1220}

References _queueAnnouncementTimer.

◆ InviteGroupToBG()

void BattlegroundQueue::InviteGroupToBG ( GroupQueueInfo ginfo,
Battleground bg,
TeamId  teamId 
)
1223{
1224 // set side if needed
1225 if (teamId != TEAM_NEUTRAL)
1226 ginfo->teamId = teamId;
1227
1228 if (ginfo->IsInvitedToBGInstanceGUID)
1229 return;
1230
1231 // set invitation
1233
1234 BattlegroundTypeId bgTypeId = bg->GetBgTypeID();
1236 BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
1237
1238 // set ArenaTeamId for rated matches
1239 if (bg->isArena() && bg->isRated())
1240 bg->SetArenaTeamIdForTeam(ginfo->teamId, ginfo->ArenaTeamId);
1241
1243
1244 // loop through the players
1245 for (auto const& itr : ginfo->Players)
1246 {
1247 // get the player
1249 if (!player)
1250 continue;
1251
1252 // update average wait time
1254
1255 // increase invited counter for each invited player
1256 bg->IncreaseInvitedCount(ginfo->teamId);
1257
1258 player->SetInviteForBattlegroundQueueType(bgQueueTypeId, ginfo->IsInvitedToBGInstanceGUID);
1259
1260 // create remind invite events
1261 BGQueueInviteEvent* inviteEvent = new BGQueueInviteEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, ginfo->ArenaType, ginfo->RemoveInviteTime);
1262 bgQueue.AddEvent(inviteEvent, INVITATION_REMIND_TIME);
1263
1264 // create automatic remove events
1265 BGQueueRemoveEvent* removeEvent = new BGQueueRemoveEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, bgQueueTypeId, ginfo->RemoveInviteTime);
1266 bgQueue.AddEvent(removeEvent, INVITE_ACCEPT_WAIT_TIME);
1267
1268 // Check queueSlot
1269 uint32 queueSlot = player->GetBattlegroundQueueIndex(bgQueueTypeId);
1271
1272 LOG_DEBUG("bg.battleground", "Battleground: invited player {} {} to BG instance {} queueindex {} bgtype {}",
1273 player->GetName(), player->GetGUID().ToString(), bg->GetInstanceID(), queueSlot, bgTypeId);
1274
1275 // send status packet
1276 WorldPacket data;
1277 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_WAIT_JOIN, INVITE_ACCEPT_WAIT_TIME, 0, ginfo->ArenaType, TEAM_NEUTRAL, bg->isRated());
1278 player->GetSession()->SendPacket(&data);
1279
1280 // pussywizard:
1281 if (bg->isArena() && bg->isRated())
1282 bg->ArenaLogEntries[player->GetGUID()].Fill(player->GetName(), player->GetGUID().GetCounter(), player->GetSession()->GetAccountId(), ginfo->ArenaTeamId, player->GetSession()->GetRemoteAddress());
1283 }
1284}
BattlegroundQueueTypeId
Definition: SharedDefines.h:3619
#define PLAYER_MAX_BATTLEGROUND_QUEUES
Definition: SharedDefines.h:176
@ INVITE_ACCEPT_WAIT_TIME
Definition: Battleground.h:165
@ INVITATION_REMIND_TIME
Definition: Battleground.h:164
@ STATUS_WAIT_JOIN
Definition: Battleground.h:201
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:257
ArenaLogEntryDataMap ArenaLogEntries
Definition: Battleground.h:426
uint32 GetInstanceID() const
Definition: Battleground.h:331
void IncreaseInvitedCount(TeamId teamId)
Definition: Battleground.h:396
void SetArenaTeamIdForTeam(TeamId teamId, uint32 ArenaTeamId)
Definition: Battleground.h:510
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition: BattlegroundMgr.cpp:672
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:209
void AddEvent(BasicEvent *Event, uint64 e_time)
Definition: BattlegroundQueue.cpp:367
Definition: BattlegroundQueue.h:147
Definition: BattlegroundQueue.h:170
std::string const & GetName() const
Definition: Object.h:463
LowType GetCounter() const
Definition: ObjectGuid.h:145
std::string ToString() const
Definition: ObjectGuid.cpp:47
WorldSession * GetSession() const
Definition: Player.h:1998
uint32 GetBattlegroundQueueIndex(BattlegroundQueueTypeId bgQueueTypeId) const
Definition: Player.cpp:12253
void SetInviteForBattlegroundQueueType(BattlegroundQueueTypeId bgQueueTypeId, uint32 instanceId)
Definition: Player.cpp:12313
Definition: WorldPacket.h:26
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214
uint32 GetAccountId() const
Definition: WorldSession.h:361
std::string const & GetRemoteAddress()
Definition: WorldSession.h:371

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)
1027{
1028 uint8 queueEmptyCount = 0;
1029
1030 for (uint8 i = 0; i < BG_QUEUE_MAX; i++)
1031 if (m_QueuedGroups[bracket_id][i].empty())
1032 queueEmptyCount++;
1033
1034 return queueEmptyCount == BG_QUEUE_MAX;
1035}
@ 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 
)
380{
381 auto qItr = m_QueuedPlayers.find(pl_guid);
382 return qItr != m_QueuedPlayers.end() && qItr->second->IsInvitedToBGInstanceGUID == bgInstanceGuid && qItr->second->RemoveInviteTime == removeTime;
383}

References m_QueuedPlayers.

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

◆ IsPlayerInvitedToRatedArena()

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

References m_QueuedPlayers.

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ PlayerInvitedToBGUpdateAverageWaitTime()

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

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)
1172{
1173 if (!sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
1174 return;
1175
1176 if (!sScriptMgr->OnBeforeSendExitMessageArenaQueue(this, ginfo))
1177 return;
1178
1179 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(ginfo->ArenaTeamId);
1180 if (!team)
1181 return;
1182
1183 if (!ginfo->IsRated)
1184 return;
1185
1186 uint8 ArenaType = ginfo->ArenaType;
1187 uint32 ArenaTeamRating = ginfo->ArenaTeamRating;
1188 std::string TeamName = team->GetName();
1189
1190 if (ArenaType && ginfo->Players.empty())
1191 {
1192 uint32 announcementDetail = sWorld->getIntConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_DETAIL);
1193 switch (announcementDetail)
1194 {
1195 case 3:
1197 break;
1198 case 2:
1200 break;
1201 case 1:
1203 break;
1204 default:
1206 break;
1207 }
1208 }
1209}
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT
Definition: Language.h:731
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT_NAME
Definition: Language.h:727
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT_RATING
Definition: Language.h:729
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT_NAME_RATING
Definition: Language.h:690
@ CONFIG_ARENA_QUEUE_ANNOUNCER_DETAIL
Definition: IWorld.h:333
@ CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE
Definition: IWorld.h:120
@ ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE
Definition: PlayerSettings.h:34
ArenaType
Definition: Battleground.h:216
std::string const & GetName() const
Definition: ArenaTeam.h:154

References ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE, GroupQueueInfo::ArenaTeamId, GroupQueueInfo::ArenaTeamRating, GroupQueueInfo::ArenaType, CONFIG_ARENA_QUEUE_ANNOUNCER_DETAIL, CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE, ArenaTeam::GetName(), GroupQueueInfo::IsRated, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT_NAME, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT_NAME_RATING, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_EXIT_RATING, GroupQueueInfo::Players, sArenaTeamMgr, ChatHandler::SendWorldTextOptional(), sScriptMgr, and sWorld.

Referenced by RemovePlayer().

◆ SendJoinMessageArenaQueue()

void BattlegroundQueue::SendJoinMessageArenaQueue ( Player leader,
GroupQueueInfo ginfo,
PvPDifficultyEntry const *  bracketEntry,
bool  isRated 
)
1092{
1093 if (!sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
1094 return;
1095
1096 if (!sScriptMgr->OnBeforeSendJoinMessageArenaQueue(this, leader, ginfo, bracketEntry, isRated))
1097 return;
1098
1099 if (!isRated)
1100 {
1101 Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(ginfo->BgTypeId);
1102 if (!bg)
1103 {
1104 LOG_ERROR("bg.arena", "> Not found bg template for bgtype id {}", uint32(ginfo->BgTypeId));
1105 return;
1106 }
1107
1108 if (!bg->isArena())
1109 {
1110 // Skip announce for non arena
1111 return;
1112 }
1113
1114 BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
1115 auto bgName = bg->GetName();
1116 auto arenatype = Acore::StringFormat("{}v{}", ginfo->ArenaType, ginfo->ArenaType);
1117 uint32 playersNeed = ArenaTeam::GetReqPlayersForType(ginfo->ArenaType);
1118 uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32)80);
1119 uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32)80);
1121
1122 LOG_DEBUG("bg.arena", "> Queue status for {} (skirmish {}) (Lvl: {} to {}) Queued: {} (Need at least {} more)",
1123 bgName, arenatype, q_min_level, q_max_level, qPlayers, playersNeed - qPlayers);
1124
1126 {
1128 bgName, arenatype, q_min_level, q_max_level, qPlayers, playersNeed - qPlayers);
1129 }
1130 else
1131 {
1132 if (!sBGSpam->CanAnnounce(leader, bg, q_min_level, qPlayers))
1133 {
1134 return;
1135 }
1136
1137 ChatHandler(nullptr).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);
1138 }
1139 }
1140 else
1141 {
1142 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(ginfo->ArenaTeamId);
1143 if (!team || !ginfo->IsRated)
1144 {
1145 return;
1146 }
1147
1148 uint8 ArenaType = ginfo->ArenaType;
1149 uint32 ArenaTeamRating = ginfo->ArenaTeamRating;
1150 std::string TeamName = team->GetName();
1151
1152 uint32 announcementDetail = sWorld->getIntConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_DETAIL);
1153 switch (announcementDetail)
1154 {
1155 case 3:
1157 break;
1158 case 2:
1160 break;
1161 case 1:
1163 break;
1164 default:
1166 break;
1167 }
1168 }
1169}
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN_NAME_RATING
Definition: Language.h:689
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD
Definition: Language.h:683
@ LANG_ARENA_QUEUE_ANNOUNCE_SELF
Definition: Language.h:682
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN_RATING
Definition: Language.h:728
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN_NAME
Definition: Language.h:726
@ LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN
Definition: Language.h:730
@ CONFIG_ARENA_QUEUE_ANNOUNCER_PLAYERONLY
Definition: IWorld.h:121
#define sBGSpam
Definition: BattlegroundSpamProtect.h:34
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
static uint8 GetReqPlayersForType(uint32 type)
Definition: ArenaTeam.cpp:1021
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210

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_DETAIL, 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, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN_NAME, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN_NAME_RATING, LANG_ARENA_QUEUE_ANNOUNCE_WORLD_JOIN_RATING, LOG_DEBUG, LOG_ERROR, PvPDifficultyEntry::maxLevel, PvPDifficultyEntry::minLevel, ChatHandler::PSendSysMessage(), sArenaTeamMgr, sBattlegroundMgr, sBGSpam, ChatHandler::SendWorldTextOptional(), sScriptMgr, Acore::StringFormat(), and sWorld.

Referenced by AddGroup().

◆ SendMessageBGQueue()

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

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(), 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, ChatHandler::SendWorldTextOptional(), sScriptMgr, and sWorld.

Referenced by AddGroup().

◆ SetQueueAnnouncementTimer()

void BattlegroundQueue::SetQueueAnnouncementTimer ( uint32  bracketId,
int32  timer,
bool  isCrossFactionBG = true 
)
1212{
1213 _queueAnnouncementTimer[bracketId] = timer;
1214 _queueAnnouncementCrossfactioned = isCrossFactionBG;
1215}

References _queueAnnouncementCrossfactioned, and _queueAnnouncementTimer.

◆ UpdateEvents()

void BattlegroundQueue::UpdateEvents ( uint32  diff)
703{
704 m_events.Update(diff);
705}
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