From: Jessica M Date: Tue, 23 Sep 2025 20:36:23 +0000 (-0700) Subject: Weather On Trigger (#40505) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=2f7b73e830c70219e4ac70f8494e115a4a70aede;p=space-station-14.git Weather On Trigger (#40505) * Weather On Trigger! * Clearing the weather * address review, add duration option --------- Co-authored-by: Jessica M --- diff --git a/Content.Shared/Trigger/Components/Effects/WeatherOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/WeatherOnTriggerComponent.cs new file mode 100644 index 0000000000..44ce576f7b --- /dev/null +++ b/Content.Shared/Trigger/Components/Effects/WeatherOnTriggerComponent.cs @@ -0,0 +1,25 @@ +using Content.Shared.Weather; +using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; + +namespace Content.Shared.Trigger.Components.Effects; + +/// +/// 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. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class WeatherOnTriggerComponent : BaseXOnTriggerComponent +{ + /// + /// Weather type. Null to clear the weather. + /// + [DataField, AutoNetworkedField] + public ProtoId? Weather; + + /// + /// How long the weather should last. Null for forever. + /// + [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 index 0000000000..6343e08f0b --- /dev/null +++ b/Content.Shared/Trigger/Systems/WeatherTriggerSystem.cs @@ -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(OnTrigger); + } + + private void OnTrigger(Entity 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); + } +}