From 71eb4d91786b1b3eccbcd61dd5e10dff184fe197 Mon Sep 17 00:00:00 2001
From: TsjipTsjip <19798667+TsjipTsjip@users.noreply.github.com>
Date: Sat, 15 Jun 2024 16:03:20 +0200
Subject: [PATCH] CVarify meteor behavior (#29030)
* CVarify meteor behavior
* Cache value to reduce CVar calls, hook into OnValueChanged
* _cfg is still null at construction time, fixed by just making it set up on Started instead
* Invoke immediately! Learning more every step of the way.
* Move cached value initialisation to Initialize call
* Add explicit supercall
---
.../Components/MeteorSchedulerComponent.cs | 11 -----------
.../StationEvents/MeteorSchedulerSystem.cs | 19 +++++++++++++++++--
Content.Shared/CCVar/CCVars.cs | 12 ++++++++++++
3 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/Content.Server/StationEvents/Components/MeteorSchedulerComponent.cs b/Content.Server/StationEvents/Components/MeteorSchedulerComponent.cs
index e71a284a89..23337f9261 100644
--- a/Content.Server/StationEvents/Components/MeteorSchedulerComponent.cs
+++ b/Content.Server/StationEvents/Components/MeteorSchedulerComponent.cs
@@ -21,15 +21,4 @@ public sealed partial class MeteorSchedulerComponent : Component
[DataField, AutoPausedField]
public TimeSpan NextSwarmTime = TimeSpan.Zero;
- ///
- /// The minimum time between swarms
- ///
- [DataField]
- public TimeSpan MinSwarmDelay = TimeSpan.FromMinutes(7.5f);
-
- ///
- /// The maximum time between swarms
- ///
- [DataField]
- public TimeSpan MaxSwarmDelay = TimeSpan.FromMinutes(12.5f);
}
diff --git a/Content.Server/StationEvents/MeteorSchedulerSystem.cs b/Content.Server/StationEvents/MeteorSchedulerSystem.cs
index 3ad88a7d89..c516229360 100644
--- a/Content.Server/StationEvents/MeteorSchedulerSystem.cs
+++ b/Content.Server/StationEvents/MeteorSchedulerSystem.cs
@@ -1,7 +1,9 @@
using Content.Server.GameTicking.Rules;
using Content.Server.StationEvents.Components;
+using Content.Shared.CCVar;
using Content.Shared.GameTicking.Components;
using Content.Shared.Random.Helpers;
+using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
namespace Content.Server.StationEvents;
@@ -13,12 +15,24 @@ namespace Content.Server.StationEvents;
public sealed class MeteorSchedulerSystem : GameRuleSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+ [Dependency] private readonly IConfigurationManager _cfg = default!;
+
+ private TimeSpan _meteorMinDelay;
+ private TimeSpan _meteorMaxDelay;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+
+ _cfg.OnValueChanged(CCVars.MeteorSwarmMinTime, f => { _meteorMinDelay = TimeSpan.FromMinutes(f); }, true);
+ _cfg.OnValueChanged(CCVars.MeteorSwarmMaxTime, f => { _meteorMaxDelay = TimeSpan.FromMinutes(f); }, true);
+ }
protected override void Started(EntityUid uid, MeteorSchedulerComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
- component.NextSwarmTime = Timing.CurTime + RobustRandom.Next(component.MinSwarmDelay, component.MaxSwarmDelay);
+ component.NextSwarmTime = Timing.CurTime + RobustRandom.Next(_meteorMinDelay, _meteorMaxDelay);
}
protected override void ActiveTick(EntityUid uid, MeteorSchedulerComponent component, GameRuleComponent gameRule, float frameTime)
@@ -28,7 +42,8 @@ public sealed class MeteorSchedulerSystem : GameRuleSystem ent)
diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs
index a9cc2d11da..886ace654d 100644
--- a/Content.Shared/CCVar/CCVars.cs
+++ b/Content.Shared/CCVar/CCVars.cs
@@ -124,6 +124,18 @@ namespace Content.Shared.CCVar
public static readonly CVarDef
EventsRampingAverageChaos = CVarDef.Create("events.ramping_average_chaos", 6f, CVar.ARCHIVE | CVar.SERVERONLY);
+ ///
+ /// Minimum time between meteor swarms in minutes.
+ ///
+ public static readonly CVarDef
+ MeteorSwarmMinTime = CVarDef.Create("events.meteor_swarm_min_time", 7.5f, CVar.ARCHIVE | CVar.SERVERONLY);
+
+ ///
+ /// Maximum time between meteor swarms in minutes.
+ ///
+ public static readonly CVarDef
+ MeteorSwarmMaxTime = CVarDef.Create("events.meteor_swarm_max_time", 12.5f, CVar.ARCHIVE | CVar.SERVERONLY);
+
/*
* Game
*/
--
2.51.2