]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Weather On Trigger (#40505)
authorJessica M <jessica@jessicamaybe.com>
Tue, 23 Sep 2025 20:36:23 +0000 (13:36 -0700)
committerGitHub <noreply@github.com>
Tue, 23 Sep 2025 20:36:23 +0000 (13:36 -0700)
* Weather On Trigger!

* Clearing the weather

* address review, add duration option

---------

Co-authored-by: Jessica M <jessica@maybe.sh>
Content.Shared/Trigger/Components/Effects/WeatherOnTriggerComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/WeatherTriggerSystem.cs [new file with mode: 0644]

diff --git a/Content.Shared/Trigger/Components/Effects/WeatherOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/WeatherOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..44ce576
--- /dev/null
@@ -0,0 +1,25 @@
+using Content.Shared.Weather;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.Trigger.Components.Effects;
+
+/// <summary>
+/// Changes the current weather when triggered.
+/// If TargetUser is true then it will change the weather at the user's map instead of the entitys map.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class WeatherOnTriggerComponent : BaseXOnTriggerComponent
+{
+    /// <summary>
+    /// Weather type. Null to clear the weather.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public ProtoId<WeatherPrototype>? Weather;
+
+    /// <summary>
+    /// How long the weather should last. Null for forever.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public TimeSpan? Duration;
+}
diff --git a/Content.Shared/Trigger/Systems/WeatherTriggerSystem.cs b/Content.Shared/Trigger/Systems/WeatherTriggerSystem.cs
new file mode 100644 (file)
index 0000000..6343e08
--- /dev/null
@@ -0,0 +1,44 @@
+using Content.Shared.Trigger.Components.Effects;
+using Content.Shared.Weather;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Timing;
+
+namespace Content.Shared.Trigger.Systems;
+
+public sealed class WeatherTriggerSystem : EntitySystem
+{
+    [Dependency] private readonly IGameTiming _timing = default!;
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+    [Dependency] private readonly SharedWeatherSystem _weather = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<WeatherOnTriggerComponent, TriggerEvent>(OnTrigger);
+    }
+
+    private void OnTrigger(Entity<WeatherOnTriggerComponent> ent, ref TriggerEvent args)
+    {
+        if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
+            return;
+
+        var target = ent.Comp.TargetUser ? args.User : ent.Owner;
+
+        if (target == null)
+            return;
+
+        var xform = Transform(target.Value);
+
+        if (ent.Comp.Weather == null) //Clear weather if nothing is set
+        {
+            _weather.SetWeather(xform.MapID, null, null);
+            return;
+        }
+
+        var endTime = ent.Comp.Duration == null ? null : ent.Comp.Duration + _timing.CurTime;
+
+        if (_prototypeManager.Resolve(ent.Comp.Weather, out var weatherPrototype))
+            _weather.SetWeather(xform.MapID, weatherPrototype, endTime);
+    }
+}