diff --git a/Content.Server/AlertLevel/AlertLevelChangeOnTriggerComponent.cs b/Content.Server/AlertLevel/AlertLevelChangeOnTriggerComponent.cs new file mode 100644 index 0000000000..aa6c5ba2bd --- /dev/null +++ b/Content.Server/AlertLevel/AlertLevelChangeOnTriggerComponent.cs @@ -0,0 +1,33 @@ +using Content.Server.AlertLevel.Systems; + +namespace Content.Server.AlertLevel; +/// +/// This component is for changing the alert level of the station when triggered. +/// +[RegisterComponent, Access(typeof(AlertLevelChangeOnTriggerSystem))] +public sealed partial class AlertLevelChangeOnTriggerComponent : Component +{ + /// + ///The alert level to change to when triggered. + /// + [DataField] + public string Level = "blue"; + + /// + ///Whether to play the sound when the alert level changes. + /// + [DataField] + public bool PlaySound = true; + + /// + ///Whether to say the announcement when the alert level changes. + /// + [DataField] + public bool Announce = true; + + /// + ///Force the alert change. This applies if the alert level is not selectable or not. + /// + [DataField] + public bool Force = false; +} diff --git a/Content.Server/AlertLevel/AlertLevelSystem.cs b/Content.Server/AlertLevel/AlertLevelSystem.cs index 0b49d7e4bf..bc02808e7d 100644 --- a/Content.Server/AlertLevel/AlertLevelSystem.cs +++ b/Content.Server/AlertLevel/AlertLevelSystem.cs @@ -116,6 +116,20 @@ public sealed class AlertLevelSystem : EntitySystem return alert.CurrentDelay; } + /// + /// Get the default alert level for a station entity. + /// Returns an empty string if the station has no alert levels defined. + /// + /// The station entity. + public string GetDefaultLevel(Entity station) + { + if (!Resolve(station.Owner, ref station.Comp) || station.Comp.AlertLevels == null) + { + return string.Empty; + } + return station.Comp.AlertLevels.DefaultLevel; + } + /// /// Set the alert level based on the station's entity ID. /// diff --git a/Content.Server/AlertLevel/Systems/AlertLevelChangeOnTriggerSystem.cs b/Content.Server/AlertLevel/Systems/AlertLevelChangeOnTriggerSystem.cs new file mode 100644 index 0000000000..0c9734b943 --- /dev/null +++ b/Content.Server/AlertLevel/Systems/AlertLevelChangeOnTriggerSystem.cs @@ -0,0 +1,27 @@ +using Content.Server.AlertLevel; +using Content.Server.Explosion.EntitySystems; +using Content.Server.Station.Systems; + +namespace Content.Server.AlertLevel.Systems; + +public sealed class AlertLevelChangeOnTriggerSystem : EntitySystem +{ + [Dependency] private readonly AlertLevelSystem _alertLevelSystem = default!; + [Dependency] private readonly StationSystem _station = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnTrigger); + } + + private void OnTrigger(Entity ent, ref TriggerEvent args) + { + var stationUid = _station.GetOwningStation(ent.Owner); + if (!stationUid.HasValue) + return; + + _alertLevelSystem.SetLevel(stationUid.Value, ent.Comp.Level, ent.Comp.PlaySound, ent.Comp.Announce, ent.Comp.Force); + } +}