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:107
constexpr auto COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME
Definition: BattlegroundQueue.h:28
uint8 constexpr PVP_TEAMS_COUNT
Definition: SharedDefines.h:3445
#define MAX_BATTLEGROUND_BRACKETS
Definition: DBCEnums.h:52
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: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 
)
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 LOG_DEBUG(filterType__,...)
Definition: Log.h:168
#define ASSERT
Definition: Errors.h:68
#define sScriptMgr
Definition: ScriptMgr.h:708
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:188
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE
Definition: IWorld.h:117
@ TEAM_HORDE
Definition: SharedDefines.h:761
BattlegroundBracketId
Definition: DBCEnums.h:46
#define sWorld
Definition: World.h:444
Milliseconds GetGameTimeMS()
Definition: GameTime.cpp:43
Definition: Battleground.h:298
Definition: BattlegroundQueue.h:31
BattlegroundTypeId BgTypeId
Definition: BattlegroundQueue.h:35
void SendMessageBGQueue(Player *leader, Battleground *bg, PvPDifficultyEntry const *bracketEntry)
Definition: BattlegroundQueue.cpp:1035
void SendJoinMessageArenaQueue(Player *leader, GroupQueueInfo *ginfo, PvPDifficultyEntry const *bracketEntry, bool isRated)
Definition: BattlegroundQueue.cpp:1089
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
Definition: Player.h:1064
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2088
void DoForAllMembers(std::function< void(Player *)> const &worker)
Definition: Group.cpp:2543

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

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, 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 
)
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
776 if (!sScriptMgr->OnQueueUpdateValidity(this, diff, bgTypeId, bracket_id, arenaType, isRated, arenaRating)) {
777 return;
778 }
779
782
783 // check if can start new premade battleground
784 if (bg_template->isBattleground() && bgTypeId != BATTLEGROUND_RB && CheckPremadeMatch(bracket_id, MinPlayersPerTeam, MaxPlayersPerTeam))
785 {
786 // create new battleground
787 Battleground* bg = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, 0, false);
788 if (!bg)
789 {
790 LOG_ERROR("bg.battleground", "BattlegroundQueue::Update - Cannot create battleground: {}", bgTypeId);
791 return;
792 }
793
794 // invite those selection pools
795 InviteAllGroupsToBg(bg);
796
797 bg->StartBattleground();
798
799 // clear structures
802 }
803
804 // check if can start new normal battleground or non-rated arena
805 if (!isRated)
806 {
807 if (CheckNormalMatch(bg_template, bracket_id, MinPlayersPerTeam, MaxPlayersPerTeam) ||
808 (bg_template->isArena() && CheckSkirmishForSameFaction(bracket_id, MinPlayersPerTeam)))
809 {
810 // create new battleground
811 Battleground* bg = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, false);
812 if (!bg)
813 {
814 LOG_ERROR("bg.battleground", "BattlegroundQueue::Update - Cannot create battleground: {}", bgTypeId);
815 return;
816 }
817
818 // invite players
819 InviteAllGroupsToBg(bg);
820
821 bg->StartBattleground();
822 }
823 }
824 // check if can start new rated arenas (can create many in single queue update)
825 else if (bg_template->isArena())
826 {
827 // found out the minimum and maximum ratings the newly added team should battle against
828 // arenaRating is the rating of the latest joined team, or 0
829 // 0 is on (automatic update call) and we must set it to team's with longest wait time
830 if (!arenaRating)
831 {
832 GroupQueueInfo* front1 = nullptr;
833 GroupQueueInfo* front2 = nullptr;
834
835 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty())
836 {
837 front1 = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].front();
838 arenaRating = front1->ArenaMatchmakerRating;
839 }
840
841 if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty())
842 {
843 front2 = m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].front();
844 arenaRating = front2->ArenaMatchmakerRating;
845 }
846
847 if (front1 && front2)
848 {
849 if (front1->JoinTime < front2->JoinTime)
850 arenaRating = front1->ArenaMatchmakerRating;
851 }
852 else if (!front1 && !front2)
853 return; // queues are empty
854 }
855
856 //set rating range
857 uint32 arenaMinRating = (arenaRating <= sBattlegroundMgr->GetMaxRatingDifference()) ? 0 : arenaRating - sBattlegroundMgr->GetMaxRatingDifference();
858 uint32 arenaMaxRating = arenaRating + sBattlegroundMgr->GetMaxRatingDifference();
859
860 // if max rating difference is set and the time past since server startup is greater than the rating discard time
861 // (after what time the ratings aren't taken into account when making teams) then
862 // the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account
863 // else leave the discard time on 0, this way all ratings will be discarded
864 // this has to be signed value - when the server starts, this value would be negative and thus overflow
865 int32 discardTime = GameTime::GetGameTimeMS().count() - sBattlegroundMgr->GetRatingDiscardTimer();
866
867 // timer for previous opponents
868 int32 discardOpponentsTime = GameTime::GetGameTimeMS().count() - sWorld->getIntConfig(CONFIG_ARENA_PREV_OPPONENTS_DISCARD_TIMER);
869
870 // we need to find 2 teams which will play next game
871 GroupsQueueType::iterator itr_teams[PVP_TEAMS_COUNT];
872 uint8 found = 0;
873 uint8 team = 0;
874
876 {
877 // take the group that joined first
878 GroupsQueueType::iterator itr2 = m_QueuedGroups[bracket_id][i].begin();
879 for (; itr2 != m_QueuedGroups[bracket_id][i].end(); ++itr2)
880 {
881 // if group match conditions, then add it to pool
882 if (!(*itr2)->IsInvitedToBGInstanceGUID
883 && (((*itr2)->ArenaMatchmakerRating >= arenaMinRating && (*itr2)->ArenaMatchmakerRating <= arenaMaxRating)
884 || (int32)(*itr2)->JoinTime < discardTime))
885 {
886 itr_teams[found++] = itr2;
887 team = i;
888 break;
889 }
890 }
891 }
892
893 if (!found)
894 return;
895
896 if (found == 1)
897 {
898 for (GroupsQueueType::iterator itr3 = itr_teams[0]; itr3 != m_QueuedGroups[bracket_id][team].end(); ++itr3)
899 {
900 if (!(*itr3)->IsInvitedToBGInstanceGUID
901 && (((*itr3)->ArenaMatchmakerRating >= arenaMinRating && (*itr3)->ArenaMatchmakerRating <= arenaMaxRating) || (int32)(*itr3)->JoinTime < discardTime)
902 && ((*(itr_teams[0]))->ArenaTeamId != (*itr3)->PreviousOpponentsTeamId || ((int32)(*itr3)->JoinTime < discardOpponentsTime))
903 && (*(itr_teams[0]))->ArenaTeamId != (*itr3)->ArenaTeamId)
904 {
905 itr_teams[found++] = itr3;
906 break;
907 }
908 }
909 }
910
911 //if we have 2 teams, then start new arena and invite players!
912 if (found == 2)
913 {
914 GroupQueueInfo* aTeam = *(itr_teams[TEAM_ALLIANCE]);
915 GroupQueueInfo* hTeam = *(itr_teams[TEAM_HORDE]);
916
917 Battleground* arena = sBattlegroundMgr->CreateNewBattleground(bgTypeId, bracketEntry, arenaType, true);
918 if (!arena)
919 {
920 LOG_ERROR("bg.battleground", "BattlegroundQueue::Update couldn't create arena instance for rated arena match!");
921 return;
922 }
923
924 aTeam->OpponentsTeamRating = hTeam->ArenaTeamRating;
925 hTeam->OpponentsTeamRating = aTeam->ArenaTeamRating;
928
929 LOG_DEBUG("bg.battleground", "setting oposite teamrating for team {} to {}", aTeam->ArenaTeamId, aTeam->OpponentsTeamRating);
930 LOG_DEBUG("bg.battleground", "setting oposite teamrating for team {} to {}", hTeam->ArenaTeamId, hTeam->OpponentsTeamRating);
931
932 // 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
933 if (aTeam->teamId != TEAM_ALLIANCE)
934 {
936 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].push_front(aTeam);
937 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].erase(itr_teams[TEAM_ALLIANCE]);
938 }
939
940 if (hTeam->teamId != TEAM_HORDE)
941 {
943 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].push_front(hTeam);
944 m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].erase(itr_teams[TEAM_HORDE]);
945 }
946
949 InviteGroupToBG(aTeam, arena, TEAM_ALLIANCE);
950 InviteGroupToBG(hTeam, arena, TEAM_HORDE);
951
952 LOG_DEBUG("bg.battleground", "Starting rated arena match!");
953 arena->StartBattleground();
954 }
955 }
956}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
std::uint8_t uint8
Definition: Define.h:109
@ BG_QUEUE_PREMADE_HORDE
Definition: BattlegroundQueue.h:54
@ BG_QUEUE_PREMADE_ALLIANCE
Definition: BattlegroundQueue.h:53
@ STATUS_WAIT_QUEUE
Definition: Battleground.h:195
@ STATUS_WAIT_LEAVE
Definition: Battleground.h:198
std::list< Battleground * > BGFreeSlotQueueContainer
Definition: BattlegroundMgr.h:38
@ CONFIG_ARENA_PREV_OPPONENTS_DISCARD_TIMER
Definition: IWorld.h:328
@ BATTLEGROUND_RB
Definition: SharedDefines.h:3493
@ TEAM_ALLIANCE
Definition: SharedDefines.h:760
uint32 GetMaxPlayersPerTeam() const
Definition: Battleground.h:336
bool isRated() const
Definition: Battleground.h:398
void StartBattleground()
Definition: Battleground.cpp:1097
bool isArena() const
Definition: Battleground.h:396
bool isBattleground() const
Definition: Battleground.h:397
BattlegroundStatus GetStatus() const
Definition: Battleground.h:327
bool HasFreeSlots() const
Definition: Battleground.cpp:1282
void RemoveFromBGFreeSlotQueue()
Definition: Battleground.cpp:1221
BattlegroundBracketId GetBracketId() const
Definition: Battleground.h:325
BattlegroundTypeId GetBgTypeID(bool GetRandom=false) const
Definition: Battleground.h:324
void SetArenaMatchmakerRating(TeamId teamId, uint32 MMR)
Definition: Battleground.h:495
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:1220
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:1024
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:292
@ CONFIG_BATTLEGROUND_INVITATION_TYPE
Definition: IWorld.h:318
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:315

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: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 
)
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:294
uint32 GetFreeSlotsForTeam(TeamId teamId) const
Definition: Battleground.cpp:1230
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: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 
)
1014{
1015 uint32 playersCount = 0;
1016
1017 for (auto const& itr : m_QueuedGroups[bracketId][bgqueue])
1018 if (!itr->IsInvitedToBGInstanceGUID)
1019 playersCount += static_cast<uint32>(itr->Players.size());
1020
1021 return playersCount;
1022}

References m_QueuedGroups.

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

◆ GetQueueAnnouncementTimer()

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

References _queueAnnouncementTimer.

◆ InviteGroupToBG()

void BattlegroundQueue::InviteGroupToBG ( GroupQueueInfo ginfo,
Battleground bg,
TeamId  teamId 
)
1221{
1222 // set side if needed
1223 if (teamId != TEAM_NEUTRAL)
1224 ginfo->teamId = teamId;
1225
1226 if (ginfo->IsInvitedToBGInstanceGUID)
1227 return;
1228
1229 // set invitation
1231
1232 BattlegroundTypeId bgTypeId = bg->GetBgTypeID();
1234 BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
1235
1236 // set ArenaTeamId for rated matches
1237 if (bg->isArena() && bg->isRated())
1238 bg->SetArenaTeamIdForTeam(ginfo->teamId, ginfo->ArenaTeamId);
1239
1241
1242 // loop through the players
1243 for (auto const& itr : ginfo->Players)
1244 {
1245 // get the player
1247 if (!player)
1248 continue;
1249
1250 // update average wait time
1252
1253 // increase invited counter for each invited player
1254 bg->IncreaseInvitedCount(ginfo->teamId);
1255
1256 player->SetInviteForBattlegroundQueueType(bgQueueTypeId, ginfo->IsInvitedToBGInstanceGUID);
1257
1258 // create remind invite events
1259 BGQueueInviteEvent* inviteEvent = new BGQueueInviteEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, ginfo->ArenaType, ginfo->RemoveInviteTime);
1260 bgQueue.AddEvent(inviteEvent, INVITATION_REMIND_TIME);
1261
1262 // create automatic remove events
1263 BGQueueRemoveEvent* removeEvent = new BGQueueRemoveEvent(player->GetGUID(), ginfo->IsInvitedToBGInstanceGUID, bgTypeId, bgQueueTypeId, ginfo->RemoveInviteTime);
1264 bgQueue.AddEvent(removeEvent, INVITE_ACCEPT_WAIT_TIME);
1265
1266 // Check queueSlot
1267 uint32 queueSlot = player->GetBattlegroundQueueIndex(bgQueueTypeId);
1269
1270 LOG_DEBUG("bg.battleground", "Battleground: invited player {} {} to BG instance {} queueindex {} bgtype {}",
1271 player->GetName(), player->GetGUID().ToString(), bg->GetInstanceID(), queueSlot, bgTypeId);
1272
1273 // send status packet
1274 WorldPacket data;
1275 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_WAIT_JOIN, INVITE_ACCEPT_WAIT_TIME, 0, ginfo->ArenaType, TEAM_NEUTRAL, bg->isRated());
1276 player->GetSession()->SendPacket(&data);
1277
1278 // pussywizard:
1279 if (bg->isArena() && bg->isRated())
1280 bg->ArenaLogEntries[player->GetGUID()].Fill(player->GetName(), player->GetGUID().GetCounter(), player->GetSession()->GetAccountId(), ginfo->ArenaTeamId, player->GetSession()->GetRemoteAddress());
1281 }
1282}
@ 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:3619
#define PLAYER_MAX_BATTLEGROUND_QUEUES
Definition: SharedDefines.h:176
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:260
ArenaLogEntryDataMap ArenaLogEntries
Definition: Battleground.h:409
uint32 GetInstanceID() const
Definition: Battleground.h:326
void IncreaseInvitedCount(TeamId teamId)
Definition: Battleground.h:379
void SetArenaTeamIdForTeam(TeamId teamId, uint32 ArenaTeamId)
Definition: Battleground.h:493
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: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:458
LowType GetCounter() const
Definition: ObjectGuid.h:145
std::string ToString() const
Definition: ObjectGuid.cpp:47
WorldSession * GetSession() const
Definition: Player.h:1978
uint32 GetBattlegroundQueueIndex(BattlegroundQueueTypeId bgQueueTypeId) const
Definition: Player.cpp:12217
void SetInviteForBattlegroundQueueType(BattlegroundQueueTypeId bgQueueTypeId, uint32 instanceId)
Definition: Player.cpp:12277
Definition: WorldPacket.h:27
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)
1025{
1026 uint8 queueEmptyCount = 0;
1027
1028 for (uint8 i = 0; i < BG_QUEUE_MAX; i++)
1029 if (m_QueuedGroups[bracket_id][i].empty())
1030 queueEmptyCount++;
1031
1032 return queueEmptyCount == BG_QUEUE_MAX;
1033}
@ 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:248
Definition: ArenaTeam.h:138
void SendExitMessageArenaQueue(GroupQueueInfo *ginfo)
Definition: BattlegroundQueue.cpp:1169
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)
1170{
1171 if (!sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
1172 return;
1173
1174 if (!sScriptMgr->OnBeforeSendExitMessageArenaQueue(this, ginfo))
1175 return;
1176
1177 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(ginfo->ArenaTeamId);
1178 if (!team)
1179 return;
1180
1181 if (!ginfo->IsRated)
1182 return;
1183
1184 uint8 ArenaType = ginfo->ArenaType;
1185 uint32 ArenaTeamRating = ginfo->ArenaTeamRating;
1186 std::string TeamName = team->GetName();
1187
1188 if (ArenaType && ginfo->Players.empty())
1189 {
1190 uint32 announcementDetail = sWorld->getIntConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_DETAIL);
1191 switch (announcementDetail)
1192 {
1193 case 3:
1195 break;
1196 case 2:
1198 break;
1199 case 1:
1201 break;
1202 default:
1204 break;
1205 }
1206 }
1207}
ArenaType
Definition: Battleground.h:211
@ CONFIG_ARENA_QUEUE_ANNOUNCER_DETAIL
Definition: IWorld.h:336
@ CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE
Definition: IWorld.h:125
@ 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
@ ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE
Definition: PlayerSettings.h:34
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_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 
)
1090{
1091 if (!sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
1092 return;
1093
1094 if (!sScriptMgr->OnBeforeSendJoinMessageArenaQueue(this, leader, ginfo, bracketEntry, isRated))
1095 return;
1096
1097 if (!isRated)
1098 {
1099 Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(ginfo->BgTypeId);
1100 if (!bg)
1101 {
1102 LOG_ERROR("bg.arena", "> Not found bg template for bgtype id {}", uint32(ginfo->BgTypeId));
1103 return;
1104 }
1105
1106 if (!bg->isArena())
1107 {
1108 // Skip announce for non arena
1109 return;
1110 }
1111
1112 BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
1113 auto bgName = bg->GetName();
1114 auto arenatype = Acore::StringFormat("{}v{}", ginfo->ArenaType, ginfo->ArenaType);
1115 uint32 playersNeed = ArenaTeam::GetReqPlayersForType(ginfo->ArenaType);
1116 uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32)80);
1117 uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32)80);
1119
1120 LOG_DEBUG("bg.arena", "> Queue status for {} (skirmish {}) (Lvl: {} to {}) Queued: {} (Need at least {} more)",
1121 bgName, arenatype, q_min_level, q_max_level, qPlayers, playersNeed - qPlayers);
1122
1124 {
1126 bgName, arenatype, q_min_level, q_max_level, qPlayers, playersNeed - qPlayers);
1127 }
1128 else
1129 {
1130 if (!sBGSpam->CanAnnounce(leader, bg, q_min_level, qPlayers))
1131 {
1132 return;
1133 }
1134
1135 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);
1136 }
1137 }
1138 else
1139 {
1140 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(ginfo->ArenaTeamId);
1141 if (!team || !ginfo->IsRated)
1142 {
1143 return;
1144 }
1145
1146 uint8 ArenaType = ginfo->ArenaType;
1147 uint32 ArenaTeamRating = ginfo->ArenaTeamRating;
1148 std::string TeamName = team->GetName();
1149
1150 uint32 announcementDetail = sWorld->getIntConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_DETAIL);
1151 switch (announcementDetail)
1152 {
1153 case 3:
1155 break;
1156 case 2:
1158 break;
1159 case 1:
1161 break;
1162 default:
1164 break;
1165 }
1166 }
1167}
#define sBGSpam
Definition: BattlegroundSpamProtect.h:34
@ CONFIG_ARENA_QUEUE_ANNOUNCER_PLAYERONLY
Definition: IWorld.h:126
@ 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
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:213

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 
)
1036{
1037 if (!sScriptMgr->CanSendMessageBGQueue(this, leader, bg, bracketEntry))
1038 {
1039 return;
1040 }
1041
1042 if (bg->isArena())
1043 {
1044 // Skip announce for arena skirmish
1045 return;
1046 }
1047
1048 BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
1049 auto bgName = bg->GetName();
1050 uint32 MinPlayers = bg->GetMinPlayersPerTeam();
1051 uint32 MaxPlayers = MinPlayers * 2;
1052 uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32)80);
1053 uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32)80);
1056 auto qTotal = qHorde + qAlliance;
1057
1058 LOG_DEBUG("bg.battleground", "> Queue status for {} (Lvl: {} to {}) Queued: {} (Need at least {} more)",
1059 bgName, q_min_level, q_max_level, qAlliance + qHorde, MaxPlayers - qTotal);
1060
1061 // Show queue status to player only (when joining battleground queue or Arena and arena world announcer is disabled)
1063 {
1064 ChatHandler(leader->GetSession()).PSendSysMessage(LANG_BG_QUEUE_ANNOUNCE_SELF, bgName, q_min_level, q_max_level,
1065 qAlliance, (MinPlayers > qAlliance) ? MinPlayers - qAlliance : (uint32)0,
1066 qHorde, (MinPlayers > qHorde) ? MinPlayers - qHorde : (uint32)0);
1067 }
1068 else // Show queue status to server (when joining battleground queue)
1069 {
1071 {
1072 if (_queueAnnouncementTimer[bracketId] < 0)
1073 {
1075 }
1076 }
1077 else
1078 {
1079 if (!sBGSpam->CanAnnounce(leader, bg, q_min_level, qTotal))
1080 {
1081 return;
1082 }
1083
1084 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);
1085 }
1086 }
1087}
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMER
Definition: IWorld.h:313
@ CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY
Definition: IWorld.h:118
@ LANG_BG_QUEUE_ANNOUNCE_SELF
Definition: Language.h:678

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

Referenced by AddGroup().

◆ SetQueueAnnouncementTimer()

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

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