From cefc37903ed25af7add393db6e0524b616a22f5c Mon Sep 17 00:00:00 2001
From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Fri, 31 Mar 2023 15:20:43 +1100
Subject: [PATCH] Random emergency shuttle time (#10047)
* Random emergency shuttle time
60 to 180 seconds. Rounds up to nearest 10.
All other FTL will go to the default of 30s.
* fix
---
.../Tests/RoundEndTest.cs | 4 +--
.../Systems/EmergencyShuttleSystem.Console.cs | 31 ++++++++++++++++---
Content.Shared/CCVar/CCVars.cs | 14 ++++++---
.../ConfigPresets/Build/development.toml | 2 +-
4 files changed, 39 insertions(+), 12 deletions(-)
diff --git a/Content.IntegrationTests/Tests/RoundEndTest.cs b/Content.IntegrationTests/Tests/RoundEndTest.cs
index 6a5a0da8c7..9e4b71d8c2 100644
--- a/Content.IntegrationTests/Tests/RoundEndTest.cs
+++ b/Content.IntegrationTests/Tests/RoundEndTest.cs
@@ -32,7 +32,7 @@ namespace Content.IntegrationTests.Tests
await server.WaitAssertion(() =>
{
config.SetCVar(CCVars.GameLobbyEnabled, true);
- config.SetCVar(CCVars.EmergencyShuttleTransitTime, 1f);
+ config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, 1f);
config.SetCVar(CCVars.EmergencyShuttleDockTime, 1f);
roundEndSystem.DefaultCooldownDuration = TimeSpan.FromMilliseconds(100);
@@ -116,7 +116,7 @@ namespace Content.IntegrationTests.Tests
await server.WaitAssertion(() =>
{
config.SetCVar(CCVars.GameLobbyEnabled, false);
- config.SetCVar(CCVars.EmergencyShuttleTransitTime, CCVars.EmergencyShuttleTransitTime.DefaultValue);
+ config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, CCVars.EmergencyShuttleMinTransitTime.DefaultValue);
config.SetCVar(CCVars.EmergencyShuttleDockTime, CCVars.EmergencyShuttleDockTime.DefaultValue);
roundEndSystem.DefaultCooldownDuration = TimeSpan.FromSeconds(30);
diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs
index 3bc7264fb3..6e487ee7a3 100644
--- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs
+++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs
@@ -41,7 +41,17 @@ public sealed partial class EmergencyShuttleSystem
private readonly TimeSpan _bufferTime = TimeSpan.FromSeconds(5);
///
- ///
+ ///
+ ///
+ public float MinimumTransitTime { get; private set; }
+
+ ///
+ ///
+ ///
+ public float MaximumTransitTime { get; private set; }
+
+ ///
+ /// How long it will take for the emergency shuttle to arrive at CentComm.
///
public float TransitTime { get; private set; }
@@ -69,7 +79,8 @@ public sealed partial class EmergencyShuttleSystem
private void InitializeEmergencyConsole()
{
- _configManager.OnValueChanged(CCVars.EmergencyShuttleTransitTime, SetTransitTime, true);
+ _configManager.OnValueChanged(CCVars.EmergencyShuttleMinTransitTime, SetMinTransitTime, true);
+ _configManager.OnValueChanged(CCVars.EmergencyShuttleMaxTransitTime, SetMaxTransitTime, true);
_configManager.OnValueChanged(CCVars.EmergencyShuttleAuthorizeTime, SetAuthorizeTime, true);
SubscribeLocalEvent(OnEmergencyStartup);
SubscribeLocalEvent(OnEmergencyAuthorize);
@@ -95,15 +106,22 @@ public sealed partial class EmergencyShuttleSystem
_authorizeTime = obj;
}
- private void SetTransitTime(float obj)
+ private void SetMinTransitTime(float obj)
{
- TransitTime = obj;
+ MinimumTransitTime = obj;
+ MaximumTransitTime = Math.Max(MaximumTransitTime, MinimumTransitTime);
+ }
+
+ private void SetMaxTransitTime(float obj)
+ {
+ MaximumTransitTime = Math.Max(MinimumTransitTime, obj);
}
private void ShutdownEmergencyConsole()
{
_configManager.UnsubValueChanged(CCVars.EmergencyShuttleAuthorizeTime, SetAuthorizeTime);
- _configManager.UnsubValueChanged(CCVars.EmergencyShuttleTransitTime, SetTransitTime);
+ _configManager.UnsubValueChanged(CCVars.EmergencyShuttleMinTransitTime, SetMinTransitTime);
+ _configManager.UnsubValueChanged(CCVars.EmergencyShuttleMaxTransitTime, SetMaxTransitTime);
}
private void OnEmergencyStartup(EntityUid uid, EmergencyShuttleConsoleComponent component, ComponentStartup args)
@@ -283,6 +301,9 @@ public sealed partial class EmergencyShuttleSystem
_consoleAccumulator = float.MinValue;
EarlyLaunchAuthorized = false;
EmergencyShuttleArrived = false;
+ TransitTime = MinimumTransitTime + (MaximumTransitTime - MinimumTransitTime) * _random.NextFloat();
+ // Round to nearest 10
+ TransitTime = MathF.Round(TransitTime / 10f) * 10f;
}
private void UpdateAllEmergencyConsoles()
diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs
index 8280d8d294..6b3e6ea2e7 100644
--- a/Content.Shared/CCVar/CCVars.cs
+++ b/Content.Shared/CCVar/CCVars.cs
@@ -1108,16 +1108,22 @@ namespace Content.Shared.CCVar
CVarDef.Create("shuttle.emergency_authorize_time", 10f, CVar.SERVERONLY);
///
- /// How long after the console is authorized for the shuttle to early launch.
+ /// The minimum time for the emergency shuttle to arrive at centcomm.
///
- public static readonly CVarDef EmergencyShuttleTransitTime =
- CVarDef.Create("shuttle.emergency_transit_time", 60f, CVar.SERVERONLY);
+ public static readonly CVarDef EmergencyShuttleMinTransitTime =
+ CVarDef.Create("shuttle.emergency_transit_time_min", 60f, CVar.SERVERONLY);
+
+ ///
+ /// The maximum time for the emergency shuttle to arrive at centcomm.
+ ///
+ public static readonly CVarDef EmergencyShuttleMaxTransitTime =
+ CVarDef.Create("shuttle.emergency_transit_time_max", 180f, CVar.SERVERONLY);
///
/// Whether the emergency shuttle is enabled or should the round just end.
///
public static readonly CVarDef EmergencyShuttleEnabled =
- CVarDef.Create("shuttle.emergency_enabled", true, CVar.SERVERONLY);
+ CVarDef.Create("shuttle.emergency", true, CVar.SERVERONLY);
///
/// The percentage of time passed from the initial call to when the shuttle can no longer be recalled.
diff --git a/Resources/ConfigPresets/Build/development.toml b/Resources/ConfigPresets/Build/development.toml
index 31fccc5b44..aa4172331a 100644
--- a/Resources/ConfigPresets/Build/development.toml
+++ b/Resources/ConfigPresets/Build/development.toml
@@ -15,5 +15,5 @@ preload = false
# Wastes startup time
auto_call_time = 0
cargo = false
-emergency_enabled = false
+emergency = false
arrivals = false