refactor(Core/BattlegroundSA): Convert to std::chrono (#8499)

This commit is contained in:
Kitzunu
2021-11-25 18:24:43 +01:00
committed by GitHub
parent 35fc95312f
commit bf05bd3c88
2 changed files with 22 additions and 25 deletions
@@ -24,6 +24,10 @@
#include "WorldPacket.h" #include "WorldPacket.h"
#include "WorldSession.h" #include "WorldSession.h"
constexpr Milliseconds BG_SA_BOAT_START = 1min;
constexpr Milliseconds BG_SA_WARMUPLENGTH = 2min;
constexpr Milliseconds BG_SA_ROUNDLENGTH = 10min;
BattlegroundSA::BattlegroundSA() BattlegroundSA::BattlegroundSA()
{ {
StartMessageIds[BG_STARTING_EVENT_FIRST] = LANG_BG_SA_START_TWO_MINUTES; StartMessageIds[BG_STARTING_EVENT_FIRST] = LANG_BG_SA_START_TWO_MINUTES;
@@ -38,8 +42,8 @@ BattlegroundSA::BattlegroundSA()
SignaledRoundTwoHalfMin = false; SignaledRoundTwoHalfMin = false;
InitSecondRound = false; InitSecondRound = false;
Attackers = TEAM_ALLIANCE; Attackers = TEAM_ALLIANCE;
TotalTime = 0; TotalTime = 0s;
EndRoundTimer = 0; EndRoundTimer = 0s;
ShipsStarted = false; ShipsStarted = false;
Status = BG_SA_NOTSTARTED; Status = BG_SA_NOTSTARTED;
@@ -49,7 +53,7 @@ BattlegroundSA::BattlegroundSA()
for (uint8 i = 0; i < 2; i++) for (uint8 i = 0; i < 2; i++)
{ {
RoundScores[i].winner = TEAM_ALLIANCE; RoundScores[i].winner = TEAM_ALLIANCE;
RoundScores[i].time = 0; RoundScores[i].time = 0s;
} }
//! This is here to prevent an uninitialised variable warning //! This is here to prevent an uninitialised variable warning
@@ -66,7 +70,7 @@ void BattlegroundSA::Init()
{ {
Battleground::Init(); Battleground::Init();
TotalTime = 0; TotalTime = 0s;
Attackers = ((urand(0, 1)) ? TEAM_ALLIANCE : TEAM_HORDE); Attackers = ((urand(0, 1)) ? TEAM_ALLIANCE : TEAM_HORDE);
for (uint8 i = 0; i <= 5; i++) for (uint8 i = 0; i <= 5; i++)
GateStatus[i] = BG_SA_GATE_OK; GateStatus[i] = BG_SA_GATE_OK;
@@ -169,7 +173,7 @@ bool BattlegroundSA::ResetObjs()
GetBGObject(BG_SA_TITAN_RELIC)->SetUInt32Value(GAMEOBJECT_FACTION, atF); GetBGObject(BG_SA_TITAN_RELIC)->SetUInt32Value(GAMEOBJECT_FACTION, atF);
GetBGObject(BG_SA_TITAN_RELIC)->Refresh(); GetBGObject(BG_SA_TITAN_RELIC)->Refresh();
TotalTime = 0; TotalTime = 0s;
ShipsStarted = false; ShipsStarted = false;
//Graveyards! //Graveyards!
@@ -322,14 +326,14 @@ void BattlegroundSA::PostUpdateImpl(uint32 diff)
return; return;
} }
} }
TotalTime += diff; TotalTime += Milliseconds(diff);
if (Status == BG_SA_WARMUP) if (Status == BG_SA_WARMUP)
{ {
EndRoundTimer = BG_SA_ROUNDLENGTH; EndRoundTimer = BG_SA_ROUNDLENGTH;
if (TotalTime >= BG_SA_WARMUPLENGTH) if (TotalTime >= BG_SA_WARMUPLENGTH)
{ {
TotalTime = 0; TotalTime = 0s;
ToggleTimer(); ToggleTimer();
DemolisherStartState(false); DemolisherStartState(false);
Status = BG_SA_ROUND_ONE; Status = BG_SA_ROUND_ONE;
@@ -346,10 +350,10 @@ void BattlegroundSA::PostUpdateImpl(uint32 diff)
else else
EndRoundTimer = BG_SA_ROUNDLENGTH; EndRoundTimer = BG_SA_ROUNDLENGTH;
if (TotalTime >= 60000) if (TotalTime >= 1min)
{ {
SendWarningToAll(LANG_BG_SA_HAS_BEGUN); SendWarningToAll(LANG_BG_SA_HAS_BEGUN);
TotalTime = 0; TotalTime = 0s;
ToggleTimer(); ToggleTimer();
DemolisherStartState(false); DemolisherStartState(false);
Status = BG_SA_ROUND_TWO; Status = BG_SA_ROUND_TWO;
@@ -360,7 +364,7 @@ void BattlegroundSA::PostUpdateImpl(uint32 diff)
for (BattlegroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr) for (BattlegroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
itr->second->RemoveAurasDueToSpell(SPELL_PREPARATION); itr->second->RemoveAurasDueToSpell(SPELL_PREPARATION);
} }
if (TotalTime >= 30000) if (TotalTime >= 30s)
{ {
if (!SignaledRoundTwoHalfMin) if (!SignaledRoundTwoHalfMin)
{ {
@@ -400,7 +404,7 @@ void BattlegroundSA::PostUpdateImpl(uint32 diff)
_relicClicked = false; _relicClicked = false;
Attackers = (Attackers == TEAM_ALLIANCE) ? TEAM_HORDE : TEAM_ALLIANCE; Attackers = (Attackers == TEAM_ALLIANCE) ? TEAM_HORDE : TEAM_ALLIANCE;
Status = BG_SA_SECOND_WARMUP; Status = BG_SA_SECOND_WARMUP;
TotalTime = 0; TotalTime = 0s;
ToggleTimer(); ToggleTimer();
SendWarningToAll(LANG_BG_SA_ROUND_ONE_END); SendWarningToAll(LANG_BG_SA_ROUND_ONE_END);
UpdateWaitTimer = 5000; UpdateWaitTimer = 5000;
@@ -818,10 +822,10 @@ GraveyardStruct const* BattlegroundSA::GetClosestGraveyard(Player* player)
void BattlegroundSA::SendTime() void BattlegroundSA::SendTime()
{ {
uint32 end_of_round = (EndRoundTimer - TotalTime); Milliseconds end_of_round = (EndRoundTimer - TotalTime);
UpdateWorldState(BG_SA_TIMER_MINS, end_of_round / 60000); UpdateWorldState(BG_SA_TIMER_MINS, end_of_round / 1min);
UpdateWorldState(BG_SA_TIMER_SEC_TENS, (end_of_round % 60000) / 10000); UpdateWorldState(BG_SA_TIMER_SEC_TENS, (end_of_round % 1min) / 10s);
UpdateWorldState(BG_SA_TIMER_SEC_DECS, ((end_of_round % 60000) % 10000) / 1000); UpdateWorldState(BG_SA_TIMER_SEC_DECS, ((end_of_round % 1min) % 10s) / 1s);
} }
bool BattlegroundSA::CanInteractWithObject(uint32 objectId) bool BattlegroundSA::CanInteractWithObject(uint32 objectId)
@@ -52,13 +52,6 @@ enum BG_SA_GateState
BG_SA_GATE_DESTROYED = 3 BG_SA_GATE_DESTROYED = 3
}; };
enum BG_SA_Timers
{
BG_SA_BOAT_START = 60 * IN_MILLISECONDS,
BG_SA_WARMUPLENGTH = 120 * IN_MILLISECONDS,
BG_SA_ROUNDLENGTH = 600 * IN_MILLISECONDS
};
enum BG_SA_WorldStates enum BG_SA_WorldStates
{ {
BG_SA_TIMER_MINS = 3559, BG_SA_TIMER_MINS = 3559,
@@ -415,7 +408,7 @@ float const BG_SA_GYOrientation[BG_SA_MAX_GY] =
struct BG_SA_RoundScore struct BG_SA_RoundScore
{ {
TeamId winner; TeamId winner;
uint32 time; Milliseconds time;
}; };
const float SOTADefPortalDest[5][4] = const float SOTADefPortalDest[5][4] =
@@ -598,9 +591,9 @@ private:
/// Id of attacker team /// Id of attacker team
TeamId Attackers; TeamId Attackers;
/// Totale elapsed time of current round /// Totale elapsed time of current round
uint32 TotalTime; Milliseconds TotalTime;
/// Max time of round /// Max time of round
uint32 EndRoundTimer; Milliseconds EndRoundTimer;
/// For know if boats has start moving or not yet /// For know if boats has start moving or not yet
bool ShipsStarted; bool ShipsStarted;
/// Status of each gate (Destroy/Damage/Intact) /// Status of each gate (Destroy/Damage/Intact)