]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make radio jammer block suit sensors (#26046)
authornikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Thu, 14 Mar 2024 15:55:14 +0000 (17:55 +0200)
committerGitHub <noreply@github.com>
Thu, 14 Mar 2024 15:55:14 +0000 (11:55 -0400)
* Make radio jammer block suit sensors

* Fix stupid

Use CancellableEventArgs instead of doing what the hell I was doing before.

* Address Reviews.

Change the event from a CancellableEntityEventArgs to a ByRefEvent.

Content.Server/Medical/SuitSensors/SuitSensorComponent.cs
Content.Server/Medical/SuitSensors/SuitSensorSystem.cs
Content.Server/Radio/EntitySystems/JammerSystem.cs
Resources/Locale/en-US/store/uplink-catalog.ftl
Resources/Prototypes/Entities/Objects/Tools/jammer.yml

index 9079655c80c15add2ed9a7dc0a628ccaf1aba5b8..8d75d3840afe3109b9f7f4f71ce0f55c3895b33a 100644 (file)
@@ -87,3 +87,9 @@ public sealed partial class SuitSensorComponent : Component
     [DataField, ViewVariables]
     public bool PreviousControlsLocked = false;
 }
+
+[ByRefEvent]
+public record struct SuitSensorsSendAttemptEvent
+{
+    public bool Cancelled;
+};
index b807b63e21f6687cf2a4ab0f006e1bb3bde9f8ff..f19b3d5b81407e77beb78398d3d7a8cd67d839ad 100644 (file)
@@ -73,6 +73,11 @@ public sealed class SuitSensorSystem : EntitySystem
             // TODO: This would cause imprecision at different tick rates.
             sensor.NextUpdate = curTime + sensor.UpdateRate;
 
+            var canEv = new SuitSensorsSendAttemptEvent();
+            RaiseLocalEvent(uid, ref canEv);
+            if (canEv.Cancelled)
+                continue;
+
             // get sensor status
             var status = GetSensorState(uid, sensor);
             if (status == null)
index dc6f4764161e1bc3a31ecd4fcac545f82056828c..fdf02f94df5cbde4e1471c748ee7f645c8d2e517 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Server.Medical.SuitSensors;
 using Content.Server.Popups;
 using Content.Server.Power.EntitySystems;
 using Content.Server.PowerCell;
@@ -23,6 +24,7 @@ public sealed class JammerSystem : EntitySystem
         SubscribeLocalEvent<ActiveRadioJammerComponent, PowerCellChangedEvent>(OnPowerCellChanged);
         SubscribeLocalEvent<RadioJammerComponent, ExaminedEvent>(OnExamine);
         SubscribeLocalEvent<RadioSendAttemptEvent>(OnRadioSendAttempt);
+        SubscribeLocalEvent<SuitSensorComponent, SuitSensorsSendAttemptEvent>(OnSensorSendAttempt);
     }
 
     public override void Update(float frameTime)
@@ -76,15 +78,33 @@ public sealed class JammerSystem : EntitySystem
 
     private void OnRadioSendAttempt(ref RadioSendAttemptEvent args)
     {
-        var source = Transform(args.RadioSource).Coordinates;
+        if (ShouldCancelSend(args.RadioSource))
+        {
+            args.Cancelled = true;
+        }
+    }
+
+    private void OnSensorSendAttempt(EntityUid uid, SuitSensorComponent comp, ref SuitSensorsSendAttemptEvent args)
+    {
+        if (ShouldCancelSend(uid))
+        {
+            args.Cancelled = true;
+        }
+    }
+
+    private bool ShouldCancelSend(EntityUid sourceUid)
+    {
+        var source = Transform(sourceUid).Coordinates;
         var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent, TransformComponent>();
+
         while (query.MoveNext(out _, out _, out var jam, out var transform))
         {
             if (source.InRange(EntityManager, _transform, transform.Coordinates, jam.Range))
             {
-                args.Cancelled = true;
-                return;
+                return true;
             }
         }
+
+        return false;
     }
 }
index 347d1a87e3f1b287de0e08e20bd65d626d9177f4..15a1c78641de22fb2f33653f884119e88306bae5 100644 (file)
@@ -146,7 +146,7 @@ uplink-clothing-eyes-hud-syndicate-name = Syndicate Visor
 uplink-clothing-eyes-hud-syndicate-desc = The syndicate's professional head-up display, designed for better detection of humanoids and their subsequent elimination.
 
 uplink-radio-jammer-name = Radio Jammer
-uplink-radio-jammer-desc = This device will disrupt any nearby outgoing radio communication when activated.
+uplink-radio-jammer-desc = This device will disrupt any nearby outgoing radio communication as well as suit sensors when activated.
 
 uplink-syndicate-weapon-module-name = Weapon Cyborg Module
 uplink-syndicate-weapon-module-desc = This module will give a cyborg advanced laser and machete
index e0a68156e04d02342e933173ac8d29bd919e8087..beb369562752b103e2d05156d06e4a3151257672 100644 (file)
@@ -2,7 +2,7 @@
   name: radio jammer
   parent: BaseItem
   id: RadioJammer
-  description: This device will disrupt any nearby outgoing radio communication when activated.
+  description: This device will disrupt any nearby outgoing radio communication as well as suit sensors when activated.
   components:
   - type: Sprite
     sprite: Objects/Devices/jammer.rsi