Skip to content

Commit

Permalink
Resolve battleground code
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Sep 30, 2024
1 parent 8179352 commit b04cf9a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
34 changes: 24 additions & 10 deletions src/game/BattleGround/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ BattleGround::~BattleGround()
m_bgMap->SetUnload();

// remove from bg free slot queue
this->RemovedFromBgFreeSlotQueue();
this->RemovedFromBgFreeSlotQueue(true);

for (BattleGroundScoreMap::const_iterator itr = m_playerScores.begin(); itr != m_playerScores.end(); ++itr)
delete itr->second;
Expand Down Expand Up @@ -735,7 +735,7 @@ void BattleGround::UpdateWorldStateForPlayer(uint32 field, uint32 value, Player*
*/
void BattleGround::EndBattleGround(Team winner)
{
this->RemovedFromBgFreeSlotQueue();
this->RemovedFromBgFreeSlotQueue(true);

ArenaTeam* winner_arena_team = nullptr;
ArenaTeam* loser_arena_team = nullptr;
Expand Down Expand Up @@ -928,7 +928,7 @@ void BattleGround::EndBattleGround(Team winner)
plr->GetSession()->SendPacket(data);

BattleGroundQueueTypeId bgQueueTypeId = BattleGroundMgr::BgQueueTypeId(GetTypeId(), GetArenaType());
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, this, plr->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, TIME_TO_AUTOREMOVE, GetStartTime(), GetArenaType(), plr->GetBGTeam());
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, GetTypeId(), GetClientInstanceId(), IsRated(), GetMapId(), plr->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, TIME_TO_AUTOREMOVE, GetStartTime(), GetArenaType(), plr->GetBGTeam());
plr->GetSession()->SendPacket(data);
}

Expand Down Expand Up @@ -1237,7 +1237,7 @@ void BattleGround::RemovePlayerAtLeave(ObjectGuid playerGuid, bool isOnTransport
if (doSendPacket)
{
WorldPacket data;
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, this, player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE);
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, GetTypeId(), GetClientInstanceId(), IsRated(), GetMapId(), player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE);
player->GetSession()->SendPacket(data);
}

Expand Down Expand Up @@ -1272,7 +1272,10 @@ void BattleGround::RemovePlayerAtLeave(ObjectGuid playerGuid, bool isOnTransport
{
// a player has left the battleground, so there are free slots -> add to queue
AddToBgFreeSlotQueue();
sBattleGroundMgr.ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, GetBracketId());
sWorld.GetBGQueue().GetMessager().AddMessage([bgQueueTypeId, bgTypeId, bracketId = GetBracketId()](BattleGroundQueue* queue)
{
queue->ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, bracketId);
});
}

// Let others know
Expand Down Expand Up @@ -1509,18 +1512,29 @@ void BattleGround::AddToBgFreeSlotQueue()
if (!m_hasBgFreeSlotQueue && IsBattleGround())
{
m_hasBgFreeSlotQueue = true;
// TODO: Resolve adding to queue
BattleGroundInQueueInfo bgInfo;
// TODO: Fill
sWorld.GetBGQueue().GetMessager().AddMessage([bgInfo](BattleGroundQueue* queue)
{
queue->AddBgToFreeSlots(bgInfo);
});
}
}

/**
Method that removes this battleground from free queue - it must be called when deleting battleground
*/
void BattleGround::RemovedFromBgFreeSlotQueue()
void BattleGround::RemovedFromBgFreeSlotQueue(bool removeFromQueue)
{
// set to be able to re-add if needed
if (m_hasBgFreeSlotQueue && removeFromQueue)
{
sWorld.GetBGQueue().GetMessager().AddMessage([instanceId = GetInstanceId()](BattleGroundQueue* queue)
{
queue->RemoveBgFromFreeSlots(instanceId);
});
}
m_hasBgFreeSlotQueue = false;
// TODO: Resolve if called from queue or elsewhere
}

/**
Expand Down Expand Up @@ -1953,7 +1967,7 @@ void BattleGround::SendBcdToTeam(int32 bcdEntry, ChatMsg msgtype, Creature const
*/
void BattleGround::EndNow()
{
RemovedFromBgFreeSlotQueue();
RemovedFromBgFreeSlotQueue(true);
SetStatus(STATUS_WAIT_LEAVE);
SetEndTime(0);
}
Expand Down Expand Up @@ -2048,7 +2062,7 @@ void BattleGround::PlayerAddedToBgCheckIfBgIsRunning(Player* player)
sBattleGroundMgr.BuildPvpLogDataPacket(data, this);
player->GetSession()->SendPacket(data);

sBattleGroundMgr.BuildBattleGroundStatusPacket(data, this, player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, GetEndTime(), GetStartTime(), GetArenaType(), player->GetBGTeam());
sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, GetTypeId(), GetClientInstanceId(), IsRated(), GetMapId(), player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, GetEndTime(), GetStartTime(), GetArenaType(), player->GetBGTeam());
player->GetSession()->SendPacket(data);
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGround/BattleGround.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class BattleGround
void SetMinPlayersPerTeam(uint32 minPlayers) { m_minPlayersPerTeam = minPlayers; }

void AddToBgFreeSlotQueue(); // this queue will be useful when more battlegrounds instances will be available
void RemovedFromBgFreeSlotQueue(); // this method could delete whole BG instance, if another free is available
void RemovedFromBgFreeSlotQueue(bool removeFromQueue); // this method could delete whole BG instance, if another free is available

// Functions to decrease or increase player count
void DecreaseInvitedCount(Team team) { (team == ALLIANCE) ? --m_invitedAlliance : --m_invitedHorde; }
Expand Down
4 changes: 2 additions & 2 deletions src/game/BattleGround/BattleGroundQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId
{
if (BattleGround* bg = sBattleGroundMgr.GetBattleGround(instanceId, typeId))
{
bg->RemovedFromBgFreeSlotQueue();
bg->RemovedFromBgFreeSlotQueue(false);
}
});
}
Expand Down Expand Up @@ -1450,7 +1450,7 @@ void BattleGroundQueue::ScheduleQueueUpdate(uint32 arenaRating, ArenaType arenaT
m_queueUpdateScheduler.push_back(schedule_id);
}

void BattleGroundQueue::AddBgToFreeSlots(BattleGroundInQueueInfo& info)
void BattleGroundQueue::AddBgToFreeSlots(BattleGroundInQueueInfo const& info)
{
// TODO:
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGround/BattleGroundQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class BattleGroundQueue

void ScheduleQueueUpdate(uint32 /*arenaRating*/, ArenaType /*arenaType*/, BattleGroundQueueTypeId /*bgQueueTypeId*/, BattleGroundTypeId /*bgTypeId*/, BattleGroundBracketId /*bracketId*/);

void AddBgToFreeSlots(BattleGroundInQueueInfo& info);
void AddBgToFreeSlots(BattleGroundInQueueInfo const& info);
void RemoveBgFromFreeSlots(uint32 instanceId);

void RemovePlayer(BattleGroundQueueTypeId bgQueueTypeId, ObjectGuid player, bool decreaseInvitedCount);
Expand Down

0 comments on commit b04cf9a

Please sign in to comment.