]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
New component: change alert level on trigger (#36581)
authorVelken <8467292+Velken@users.noreply.github.com>
Thu, 17 Apr 2025 11:35:27 +0000 (08:35 -0300)
committerGitHub <noreply@github.com>
Thu, 17 Apr 2025 11:35:27 +0000 (21:35 +1000)
* adds component that lets change alert level on trigger

* oops, put stuff on wrong folder

* missclick, forgor a file

* slarti finds ways to improve code

* Apply suggestions from code review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Server/AlertLevel/AlertLevelChangeOnTriggerComponent.cs [new file with mode: 0644]
Content.Server/AlertLevel/AlertLevelSystem.cs
Content.Server/AlertLevel/Systems/AlertLevelChangeOnTriggerSystem.cs [new file with mode: 0644]

diff --git a/Content.Server/AlertLevel/AlertLevelChangeOnTriggerComponent.cs b/Content.Server/AlertLevel/AlertLevelChangeOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..aa6c5ba
--- /dev/null
@@ -0,0 +1,33 @@
+using Content.Server.AlertLevel.Systems;
+
+namespace Content.Server.AlertLevel;
+/// <summary>
+/// This component is for changing the alert level of the station when triggered.
+/// </summary>
+[RegisterComponent, Access(typeof(AlertLevelChangeOnTriggerSystem))]
+public sealed partial class AlertLevelChangeOnTriggerComponent : Component
+{
+    ///<summary>
+    ///The alert level to change to when triggered.
+    ///</summary>
+    [DataField]
+    public string Level = "blue";
+
+    /// <summary>
+    ///Whether to play the sound when the alert level changes.
+    /// </summary>
+    [DataField]
+    public bool PlaySound = true;
+
+    /// <summary>
+    ///Whether to say the announcement when the alert level changes.
+    /// </summary>
+    [DataField]
+    public bool Announce = true;
+
+    /// <summary>
+    ///Force the alert change. This applies if the alert level is not selectable or not.
+    /// </summary>
+    [DataField]
+    public bool Force = false;
+}
index 0b49d7e4bfa897dcc9ec4067100930b1c24ba899..bc02808e7d03c77408be60f4bef4933e53cf7c3c 100644 (file)
@@ -116,6 +116,20 @@ public sealed class AlertLevelSystem : EntitySystem
         return alert.CurrentDelay;
     }
 
+    /// <summary>
+    /// Get the default alert level for a station entity.
+    /// Returns an empty string if the station has no alert levels defined.
+    /// </summary>
+    /// <param name="station">The station entity.</param>
+    public string GetDefaultLevel(Entity<AlertLevelComponent?> station)
+    {
+        if (!Resolve(station.Owner, ref station.Comp) || station.Comp.AlertLevels == null)
+        {
+            return string.Empty;
+        }
+        return station.Comp.AlertLevels.DefaultLevel;
+    }
+
     /// <summary>
     /// Set the alert level based on the station's entity ID.
     /// </summary>
diff --git a/Content.Server/AlertLevel/Systems/AlertLevelChangeOnTriggerSystem.cs b/Content.Server/AlertLevel/Systems/AlertLevelChangeOnTriggerSystem.cs
new file mode 100644 (file)
index 0000000..0c9734b
--- /dev/null
@@ -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<AlertLevelChangeOnTriggerComponent, TriggerEvent>(OnTrigger);
+    }
+
+    private void OnTrigger(Entity<AlertLevelChangeOnTriggerComponent> 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);
+    }
+}