Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Sep 21, 2024
1 parent 1fea85c commit e65c5bb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 40 deletions.
26 changes: 0 additions & 26 deletions src/game/BattleGround/BattleGroundMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,32 +1153,6 @@ void BattleGroundMgr::ToggleArenaTesting()
sWorld.SendWorldText(LANG_DEBUG_ARENA_OFF);
}

/**
Method that schedules queue update
@param arena rating
@param arena type
@param battleground queue type id
@param battleground type id
@param bracket id
*/
void BattleGroundMgr::ScheduleQueueUpdate(uint32 arenaRating, ArenaType arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BattleGroundBracketId bracketId)
{
// we will use only 1 number created of bgTypeId and bracket_id
uint64 schedule_id = (uint64(arenaRating) << 32) | (uint64(arenaType) << 24) | (uint64(bgQueueTypeId) << 16) | (uint64(bgTypeId) << 8) | bracketId;
bool found = false;
for (unsigned long long i : m_queueUpdateScheduler)
{
if (i == schedule_id)
{
found = true;
break;
}
}
if (!found)
m_queueUpdateScheduler.push_back(schedule_id);
}

/**
Function that returns max arena rating difference
*/
Expand Down
1 change: 0 additions & 1 deletion src/game/BattleGround/BattleGroundMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class BattleGroundMgr

void SendToBattleGround(Player* /*player*/, uint32 /*instanceId*/, BattleGroundTypeId /*bgTypeId*/);

void ScheduleQueueUpdate(uint32 /*arenaRating*/, ArenaType /*arenaType*/, BattleGroundQueueTypeId /*bgQueueTypeId*/, BattleGroundTypeId /*bgTypeId*/, BattleGroundBracketId /*bracketId*/);
uint32 GetMaxRatingDifference() const;
uint32 GetRatingDiscardTimer() const;
uint32 GetPrematureFinishTime() const;
Expand Down
57 changes: 44 additions & 13 deletions src/game/BattleGround/BattleGroundQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,26 +1199,31 @@ bool BgQueueRemoveEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
// battleground can be deleted already when we are removing queue info
// bg pointer can be nullptr! so use it carefully!

bool isBattleGround = bg && bg->IsBattleGround();

uint32 queueSlot = plr->GetBattleGroundQueueIndex(event.m_bgQueueTypeId);
if (queueSlot < PLAYER_MAX_BATTLEGROUND_QUEUES) // player is in queue, or in Battleground
{
// check if player is in queue for this BG and if we are removing his invite event
BattleGroundQueueItem& bgQueue = sBattleGroundMgr.m_battleGroundQueues[event.m_bgQueueTypeId];
if (bgQueue.IsPlayerInvited(event.m_playerGuid, event.m_bgInstanceGuid, event.m_removeTime))
sWorld.GetBGueue().GetMessager().AddMessage([bgQueueTypeId = event.m_bgQueueTypeId, bgTypeId = , playerGuid = event.m_playerGuid, instanceGuid = event.m_bgInstanceGuid, removeTime = event.m_removeTime, isBattleGround](BattleGroundQueue* queue)
{
DEBUG_LOG("Battleground: removing player %u from bg queue for instance %u because of not pressing enter battle in time.", plr->GetGUIDLow(), event.m_bgInstanceGuid);
// check if player is in queue for this BG and if we are removing his invite event
BattleGroundQueueItem& bgQueue = queue->m_battleGroundQueues[bgQueueTypeId];
if (bgQueue.IsPlayerInvited(playerGuid, instanceGuid, removeTime))
{
DEBUG_LOG("Battleground: removing player %u from bg queue for instance %u because of not pressing enter battle in time.", playerGuid.GetCounter(), instanceGuid);

plr->RemoveBattleGroundQueueId(event.m_bgQueueTypeId);
bgQueue.RemovePlayer(event.m_playerGuid, true);
plr->RemoveBattleGroundQueueId(bgTypeId);
bgQueue.RemovePlayer(playerGuid, true);

// update queues if battleground isn't ended
if (bg && bg->IsBattleGround() && bg->GetStatus() != STATUS_WAIT_LEAVE)
sBattleGroundMgr.ScheduleQueueUpdate(0, ARENA_TYPE_NONE, event.m_bgQueueTypeId, event.m_bgTypeId, bg->GetBracketId());
// update queues if battleground isn't ended
if (isBattleGround && bg->GetStatus() != STATUS_WAIT_LEAVE)
queue->ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, bg->GetBracketId());

WorldPacket data;
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, bg, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE);
plr->GetSession()->SendPacket(data);
}
WorldPacket data;
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, bg, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE);
plr->GetSession()->SendPacket(data);
}
});
}
});

Expand Down Expand Up @@ -1355,3 +1360,29 @@ void BattleGroundQueue::InitAutomaticArenaPointDistribution()
}
}
}

/**
Method that schedules queue update
@param arena rating
@param arena type
@param battleground queue type id
@param battleground type id
@param bracket id
*/
void BattleGroundQueue::ScheduleQueueUpdate(uint32 arenaRating, ArenaType arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BattleGroundBracketId bracketId)
{
// we will use only 1 number created of bgTypeId and bracket_id
uint64 schedule_id = (uint64(arenaRating) << 32) | (uint64(arenaType) << 24) | (uint64(bgQueueTypeId) << 16) | (uint64(bgTypeId) << 8) | bracketId;
bool found = false;
for (unsigned long long i : m_queueUpdateScheduler)
{
if (i == schedule_id)
{
found = true;
break;
}
}
if (!found)
m_queueUpdateScheduler.push_back(schedule_id);
}
4 changes: 4 additions & 0 deletions src/game/BattleGround/BattleGroundQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class BgQueueRemoveEvent : public BasicEvent

class BattleGroundQueue
{
friend class BgQueueInviteEvent;
friend class BgQueueRemoveEvent;
public:
BattleGroundQueue();

Expand All @@ -174,6 +176,8 @@ class BattleGroundQueue
Messager<BattleGroundQueue>& GetMessager() { return m_messager; }

void InitAutomaticArenaPointDistribution();

void ScheduleQueueUpdate(uint32 /*arenaRating*/, ArenaType /*arenaType*/, BattleGroundQueueTypeId /*bgQueueTypeId*/, BattleGroundTypeId /*bgTypeId*/, BattleGroundBracketId /*bracketId*/);
private:
BattleGroundQueueItem m_battleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code

Expand Down
2 changes: 2 additions & 0 deletions src/game/World/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "Multithreading/Messager.h"
#include "Globals/GraveyardManager.h"
#include "LFG/LFGQueue.h"
#include "BattleGround/BattleGroundQueue.h"

#include <atomic>
#include <set>
Expand Down Expand Up @@ -682,6 +683,7 @@ class World
void SendGMTextFlags(uint32 accountFlag, int32 stringId, std::string type, const char* message);

LFGQueue& GetLFGQueue() { return m_lfgQueue; }
BattleGroundQueue& GetBGueue() { return m_bgQueue; }
void StartLFGQueueThread();
void StartBGQueueThread();
protected:
Expand Down

0 comments on commit e65c5bb

Please sign in to comment.