From 3e464cd1f0c685577ae3927e309be56d6b20616e Mon Sep 17 00:00:00 2001 From: Arimah Greene <30327355+arimah@users.noreply.github.com> Date: Wed, 16 Aug 2023 03:36:50 +0200 Subject: [PATCH] Add CVar for customizing round restart time (#19136) Co-authored-by: TsjipTsjip <19798667+TsjipTsjip@users.noreply.github.com> --- .../Tests/RoundEndTest.cs | 4 ++-- Content.Server/RoundEnd/RoundEndSystem.cs | 23 ++++++++++++++++--- Content.Shared/CCVar/CCVars.cs | 7 ++++++ .../en-US/round-end/round-end-system.ftl | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Content.IntegrationTests/Tests/RoundEndTest.cs b/Content.IntegrationTests/Tests/RoundEndTest.cs index 4d6eff32e4..c307916841 100644 --- a/Content.IntegrationTests/Tests/RoundEndTest.cs +++ b/Content.IntegrationTests/Tests/RoundEndTest.cs @@ -34,10 +34,10 @@ namespace Content.IntegrationTests.Tests config.SetCVar(CCVars.GameLobbyEnabled, true); config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, 1f); config.SetCVar(CCVars.EmergencyShuttleDockTime, 1f); + config.SetCVar(CCVars.RoundRestartTime, 1f); roundEndSystem.DefaultCooldownDuration = TimeSpan.FromMilliseconds(100); roundEndSystem.DefaultCountdownDuration = TimeSpan.FromMilliseconds(300); - roundEndSystem.DefaultRestartRoundDuration = TimeSpan.FromMilliseconds(100); }); await server.WaitAssertion(() => @@ -131,10 +131,10 @@ namespace Content.IntegrationTests.Tests config.SetCVar(CCVars.GameLobbyEnabled, false); config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, CCVars.EmergencyShuttleMinTransitTime.DefaultValue); config.SetCVar(CCVars.EmergencyShuttleDockTime, CCVars.EmergencyShuttleDockTime.DefaultValue); + config.SetCVar(CCVars.RoundRestartTime, CCVars.RoundRestartTime.DefaultValue); roundEndSystem.DefaultCooldownDuration = TimeSpan.FromSeconds(30); roundEndSystem.DefaultCountdownDuration = TimeSpan.FromMinutes(4); - roundEndSystem.DefaultRestartRoundDuration = TimeSpan.FromMinutes(1); ticker.RestartRound(); }); await PoolManager.ReallyBeIdle(pairTracker.Pair, 10); diff --git a/Content.Server/RoundEnd/RoundEndSystem.cs b/Content.Server/RoundEnd/RoundEndSystem.cs index 1479d2d316..5d180b8d17 100644 --- a/Content.Server/RoundEnd/RoundEndSystem.cs +++ b/Content.Server/RoundEnd/RoundEndSystem.cs @@ -41,7 +41,6 @@ namespace Content.Server.RoundEnd /// Countdown to use where there is no station alert countdown to be found. /// public TimeSpan DefaultCountdownDuration { get; set; } = TimeSpan.FromMinutes(10); - public TimeSpan DefaultRestartRoundDuration { get; set; } = TimeSpan.FromMinutes(2); private CancellationTokenSource? _countdownTokenSource = null; private CancellationTokenSource? _cooldownTokenSource = null; @@ -211,8 +210,26 @@ namespace Content.Server.RoundEnd _gameTicker.EndRound(); _countdownTokenSource?.Cancel(); _countdownTokenSource = new(); - _chatManager.DispatchServerAnnouncement(Loc.GetString("round-end-system-round-restart-eta-announcement", ("minutes", DefaultRestartRoundDuration.Minutes))); - Timer.Spawn(DefaultRestartRoundDuration, AfterEndRoundRestart, _countdownTokenSource.Token); + + var countdownTime = TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.RoundRestartTime)); + int time; + string unitsLocString; + if (countdownTime.TotalSeconds < 60) + { + time = countdownTime.Seconds; + unitsLocString = "eta-units-seconds"; + } + else + { + time = countdownTime.Minutes; + unitsLocString = "eta-units-minutes"; + } + _chatManager.DispatchServerAnnouncement( + Loc.GetString( + "round-end-system-round-restart-eta-announcement", + ("time", time), + ("units", Loc.GetString(unitsLocString)))); + Timer.Spawn(countdownTime, AfterEndRoundRestart, _countdownTokenSource.Token); } private void AfterEndRoundRestart() diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index f992d6fbff..9e8ad01006 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -312,6 +312,13 @@ namespace Content.Shared.CCVar /// public static readonly CVarDef ArtifactRoundEndTimer = CVarDef.Create("game.artifact_round_end_timer", 0.5f, CVar.NOTIFY | CVar.REPLICATED); + /// + /// The time in seconds that the server should wait before restarting the round. + /// Defaults to 2 minutes. + /// + public static readonly CVarDef RoundRestartTime = + CVarDef.Create("game.round_restart_time", 120f, CVar.SERVERONLY); + /* * Discord */ diff --git a/Resources/Locale/en-US/round-end/round-end-system.ftl b/Resources/Locale/en-US/round-end/round-end-system.ftl index 7f4d5b0fff..f85bee0323 100644 --- a/Resources/Locale/en-US/round-end/round-end-system.ftl +++ b/Resources/Locale/en-US/round-end/round-end-system.ftl @@ -3,7 +3,7 @@ round-end-system-shuttle-called-announcement = An emergency shuttle has been sent. ETA: {$time} {$units}. round-end-system-shuttle-auto-called-announcement = An automatic crew shift change shuttle has been sent. ETA: {$time} {$units}. Recall the shuttle to extend the shift. round-end-system-shuttle-recalled-announcement = The emergency shuttle has been recalled. -round-end-system-round-restart-eta-announcement = Restarting the round in {$minutes} minutes... +round-end-system-round-restart-eta-announcement = Restarting the round in {$time} {$units}... eta-units-minutes = minutes eta-units-seconds = seconds