From d8281c7d2d867552c88d9f60dda919206b4fa222 Mon Sep 17 00:00:00 2001
From: Velken <8467292+Velken@users.noreply.github.com>
Date: Thu, 17 Apr 2025 08:35:27 -0300
Subject: [PATCH] New component: change alert level on trigger (#36581)
* 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>
---
.../AlertLevelChangeOnTriggerComponent.cs | 33 +++++++++++++++++++
Content.Server/AlertLevel/AlertLevelSystem.cs | 14 ++++++++
.../AlertLevelChangeOnTriggerSystem.cs | 27 +++++++++++++++
3 files changed, 74 insertions(+)
create mode 100644 Content.Server/AlertLevel/AlertLevelChangeOnTriggerComponent.cs
create mode 100644 Content.Server/AlertLevel/Systems/AlertLevelChangeOnTriggerSystem.cs
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);
+ }
+}
--
2.51.2