refactor(Core/BattlegroundRV): Convert to std::chrono (#8498)

This commit is contained in:
Kitzunu
2021-11-20 15:56:16 +01:00
committed by GitHub
parent 00c5fbd5ba
commit d8f4a5cd0c
2 changed files with 14 additions and 13 deletions
@@ -25,6 +25,11 @@
#include "WorldPacket.h" #include "WorldPacket.h"
#include "WorldSession.h" #include "WorldSession.h"
static constexpr Milliseconds BG_RV_PILLAR_SWITCH_TIMER = 25s;
static constexpr Milliseconds BG_RV_FIRE_TO_PILLAR_TIMER = 20s;
static constexpr Milliseconds BG_RV_CLOSE_FIRE_TIMER = 5s;
static constexpr Milliseconds BG_RV_FIRST_TIMER = 20500ms; // elevators rise in 20133ms
BattlegroundRV::BattlegroundRV() BattlegroundRV::BattlegroundRV()
{ {
BgObjects.resize(BG_RV_OBJECT_MAX); BgObjects.resize(BG_RV_OBJECT_MAX);
@@ -72,14 +77,14 @@ void BattlegroundRV::PostUpdateImpl(uint32 diff)
if (GetStatus() != STATUS_IN_PROGRESS) if (GetStatus() != STATUS_IN_PROGRESS)
return; return;
if (getTimer() < diff) if (GetTimer() < Milliseconds(diff))
{ {
switch (getState()) switch (getState())
{ {
case BG_RV_STATE_OPEN_FENCES: case BG_RV_STATE_OPEN_FENCES:
for (uint8 i = BG_RV_OBJECT_FIRE_1; i <= BG_RV_OBJECT_FIREDOOR_2; ++i) for (uint8 i = BG_RV_OBJECT_FIRE_1; i <= BG_RV_OBJECT_FIREDOOR_2; ++i)
DoorOpen(i); DoorOpen(i);
setTimer(BG_RV_CLOSE_FIRE_TIMER); SetTimer(BG_RV_CLOSE_FIRE_TIMER);
setState(BG_RV_STATE_CLOSE_FIRE); setState(BG_RV_STATE_CLOSE_FIRE);
for (auto itr = m_Players.begin(); itr != m_Players.end(); ++itr) for (auto itr = m_Players.begin(); itr != m_Players.end(); ++itr)
@@ -128,17 +133,17 @@ void BattlegroundRV::PostUpdateImpl(uint32 diff)
for (uint8 i = BG_RV_OBJECT_FIRE_1; i <= BG_RV_OBJECT_FIREDOOR_2; ++i) for (uint8 i = BG_RV_OBJECT_FIRE_1; i <= BG_RV_OBJECT_FIREDOOR_2; ++i)
DoorClose(i); DoorClose(i);
// Fire got closed after five seconds, leaves twenty seconds before toggling pillars // Fire got closed after five seconds, leaves twenty seconds before toggling pillars
setTimer(BG_RV_FIRE_TO_PILLAR_TIMER); SetTimer(BG_RV_FIRE_TO_PILLAR_TIMER);
setState(BG_RV_STATE_SWITCH_PILLARS); setState(BG_RV_STATE_SWITCH_PILLARS);
break; break;
case BG_RV_STATE_SWITCH_PILLARS: case BG_RV_STATE_SWITCH_PILLARS:
UpdatePillars(); UpdatePillars();
setTimer(BG_RV_PILLAR_SWITCH_TIMER); SetTimer(BG_RV_PILLAR_SWITCH_TIMER);
break; break;
} }
} }
else else
setTimer(getTimer() - diff); SetTimer(GetTimer() - Milliseconds(diff));
if (getState() == BG_RV_STATE_OPEN_FENCES) if (getState() == BG_RV_STATE_OPEN_FENCES)
return; return;
@@ -173,7 +178,7 @@ void BattlegroundRV::StartingEventOpenDoors()
DoorOpen(BG_RV_OBJECT_ELEVATOR_2); DoorOpen(BG_RV_OBJECT_ELEVATOR_2);
setState(BG_RV_STATE_OPEN_FENCES); setState(BG_RV_STATE_OPEN_FENCES);
setTimer(BG_RV_FIRST_TIMER); SetTimer(BG_RV_FIRST_TIMER);
} }
void BattlegroundRV::AddPlayer(Player* player) void BattlegroundRV::AddPlayer(Player* player)
@@ -77,10 +77,6 @@ enum BattlegroundRVData
BG_RV_STATE_SWITCH_PILLARS, BG_RV_STATE_SWITCH_PILLARS,
BG_RV_STATE_CLOSE_FIRE, BG_RV_STATE_CLOSE_FIRE,
BG_RV_PILLAR_SWITCH_TIMER = 25000,
BG_RV_FIRE_TO_PILLAR_TIMER = 20000,
BG_RV_CLOSE_FIRE_TIMER = 5000,
BG_RV_FIRST_TIMER = 20500, // elevators rise in 20133ms
BG_RV_WORLD_STATE_A = 0xe11, BG_RV_WORLD_STATE_A = 0xe11,
BG_RV_WORLD_STATE_H = 0xe10, BG_RV_WORLD_STATE_H = 0xe10,
BG_RV_WORLD_STATE = 0xe1a, BG_RV_WORLD_STATE = 0xe1a,
@@ -108,15 +104,15 @@ public:
GameObject* GetPillarAtPosition(Position* p); GameObject* GetPillarAtPosition(Position* p);
private: private:
uint32 Timer; Milliseconds Timer;
uint32 State; uint32 State;
uint16 CheckPlayersTimer; uint16 CheckPlayersTimer;
void PostUpdateImpl(uint32 diff) override; void PostUpdateImpl(uint32 diff) override;
protected: protected:
uint32 getTimer() { return Timer; } Milliseconds GetTimer() { return Timer; }
void setTimer(uint32 timer) { Timer = timer; } void SetTimer(Milliseconds timer) { Timer = timer; }
uint32 getState() { return State; }; uint32 getState() { return State; };
void setState(uint32 state) { State = state; } void setState(uint32 state) { State = state; }