Use IGameTiming for lobby timing instead of DateTime.

Fixes #1681
This commit is contained in:
Pieter-Jan Briers
2021-01-11 09:03:58 +01:00
parent b36d22128a
commit 374b100a5e
5 changed files with 31 additions and 29 deletions

View File

@@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Content.Server.Administration;
using Content.Server.Commands.Observer;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
@@ -32,7 +30,6 @@ using Robust.Server.Interfaces.Maps;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Server.ServerStatus;
using Robust.Server.Interfaces.Console;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Configuration;
@@ -71,7 +68,7 @@ namespace Content.Server.GameTicking
public const float PresetFailedCooldownIncrease = 30f;
private const string PlayerPrototypeName = "HumanMob_Content";
private const string ObserverPrototypeName = "MobObserver";
private static TimeSpan _roundStartTimeSpan;
private TimeSpan _roundStartTimeSpan;
[ViewVariables] private readonly List<GameRule> _gameRules = new();
[ViewVariables] private readonly List<ManifestEntry> _manifest = new();
@@ -83,9 +80,9 @@ namespace Content.Server.GameTicking
[ViewVariables] private Type _presetType;
[ViewVariables] private DateTime _pauseTime;
[ViewVariables] private TimeSpan _pauseTime;
[ViewVariables] private bool _roundStartCountdownHasNotStartedYetDueToNoPlayers;
private DateTime _roundStartTimeUtc;
[ViewVariables] private TimeSpan _roundStartTime;
[ViewVariables] private GameRunLevel _runLevel;
[ViewVariables(VVAccess.ReadWrite)] private EntityCoordinates _spawnPoint;
@@ -178,7 +175,7 @@ namespace Content.Server.GameTicking
if (RunLevel != GameRunLevel.PreRoundLobby ||
Paused ||
_roundStartTimeUtc > DateTime.UtcNow ||
_roundStartTime > _gameTiming.CurTime ||
_roundStartCountdownHasNotStartedYetDueToNoPlayers)
{
return;
@@ -217,7 +214,7 @@ namespace Content.Server.GameTicking
if (PlayerManager.PlayerCount == 0)
_roundStartCountdownHasNotStartedYetDueToNoPlayers = true;
else
_roundStartTimeUtc = DateTime.UtcNow + LobbyDuration;
_roundStartTime = _gameTiming.CurTime + LobbyDuration;
_sendStatusToAll();
@@ -532,10 +529,10 @@ namespace Content.Server.GameTicking
return false;
}
_roundStartTimeUtc += time;
_roundStartTime += time;
var lobbyCountdownMessage = _netManager.CreateNetMessage<MsgTickerLobbyCountdown>();
lobbyCountdownMessage.StartTime = _roundStartTimeUtc;
lobbyCountdownMessage.StartTime = _roundStartTime;
lobbyCountdownMessage.Paused = Paused;
_netManager.ServerSendToAll(lobbyCountdownMessage);
@@ -555,15 +552,15 @@ namespace Content.Server.GameTicking
if (pause)
{
_pauseTime = DateTime.UtcNow;
_pauseTime = _gameTiming.CurTime;
}
else if (_pauseTime != default)
{
_roundStartTimeUtc += DateTime.UtcNow - _pauseTime;
_roundStartTime += _gameTiming.CurTime - _pauseTime;
}
var lobbyCountdownMessage = _netManager.CreateNetMessage<MsgTickerLobbyCountdown>();
lobbyCountdownMessage.StartTime = _roundStartTimeUtc;
lobbyCountdownMessage.StartTime = _roundStartTime;
lobbyCountdownMessage.Paused = Paused;
_netManager.ServerSendToAll(lobbyCountdownMessage);
@@ -766,7 +763,7 @@ namespace Content.Server.GameTicking
if (LobbyEnabled && _roundStartCountdownHasNotStartedYetDueToNoPlayers)
{
_roundStartCountdownHasNotStartedYetDueToNoPlayers = false;
_roundStartTimeUtc = DateTime.UtcNow + LobbyDuration;
_roundStartTime = _gameTiming.CurTime + LobbyDuration;
}
break;
@@ -1020,7 +1017,7 @@ namespace Content.Server.GameTicking
_playersInLobby.TryGetValue(session, out var status);
var msg = _netManager.CreateNetMessage<MsgTickerLobbyStatus>();
msg.IsRoundStarted = RunLevel != GameRunLevel.PreRoundLobby;
msg.StartTime = _roundStartTimeUtc;
msg.StartTime = _roundStartTime;
msg.YouAreReady = status == PlayerStatus.Ready;
msg.Paused = Paused;
return msg;