Weather On Trigger (#40505)
* Weather On Trigger! * Clearing the weather * address review, add duration option --------- Co-authored-by: Jessica M <jessica@maybe.sh>
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
44
Content.Shared/Trigger/Systems/WeatherTriggerSystem.cs
Normal file
44
Content.Shared/Trigger/Systems/WeatherTriggerSystem.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user