]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Adds EMP Resistance component, gives it to ninja suit and headset (#42334)
authoralexalexmax <149889301+alexalexmax@users.noreply.github.com>
Tue, 13 Jan 2026 13:30:53 +0000 (08:30 -0500)
committerGitHub <noreply@github.com>
Tue, 13 Jan 2026 13:30:53 +0000 (13:30 +0000)
* add comp and apply to ninja gear

* cleanup

* requested changes

---------

Co-authored-by: seanpimble <149889301+seanpimble@users.noreply.github.com>
Content.Shared/Emp/EmpResistanceComponent.cs [new file with mode: 0644]
Content.Shared/Emp/SharedEmpSystem.cs
Content.Shared/Ninja/Systems/SharedNinjaSuitSystem.cs
Resources/Prototypes/Entities/Clothing/Ears/headsets.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml

diff --git a/Content.Shared/Emp/EmpResistanceComponent.cs b/Content.Shared/Emp/EmpResistanceComponent.cs
new file mode 100644 (file)
index 0000000..0768ad7
--- /dev/null
@@ -0,0 +1,18 @@
+using Content.Shared.FixedPoint;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Emp;
+
+/// <summary>
+/// An entity with this component resists or is fully immune to EMPs.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(SharedEmpSystem))]
+public sealed partial class EmpResistanceComponent : Component
+{
+    /// <summary>
+    ///     The proportion of the EMP effect that is resisted. 1.00 indicates full immunity while 0.00 indicates no resistance.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public FixedPoint2 Resistance = FixedPoint2.Zero;
+}
index 7e6ea58dbc93977e77c6d637e5c9899c924e306c..d1c773dd90988d5d77655ee65286818db9c4211a 100644 (file)
@@ -6,6 +6,7 @@ using Robust.Shared.Map;
 using Robust.Shared.Timing;
 using Robust.Shared.Network;
 using Robust.Shared.Prototypes;
+using Robust.Shared.Utility;
 
 namespace Content.Shared.Emp;
 
@@ -26,6 +27,9 @@ public abstract class SharedEmpSystem : EntitySystem
         SubscribeLocalEvent<EmpDisabledComponent, ExaminedEvent>(OnExamine);
         SubscribeLocalEvent<EmpDisabledComponent, ComponentRemove>(OnRemove);
         SubscribeLocalEvent<EmpDisabledComponent, RejuvenateEvent>(OnRejuvenate);
+
+        SubscribeLocalEvent<EmpResistanceComponent, EmpAttemptEvent>(OnResistEmpAttempt);
+        SubscribeLocalEvent<EmpResistanceComponent, EmpPulseEvent>(OnResistEmpPulse);
     }
 
     public static readonly EntProtoId EmpPulseEffectPrototype = "EffectEmpPulse";
@@ -152,6 +156,23 @@ public abstract class SharedEmpSystem : EntitySystem
     {
         RemCompDeferred<EmpDisabledComponent>(ent);
     }
+
+    private void OnResistEmpAttempt(Entity<EmpResistanceComponent> ent, ref EmpAttemptEvent args)
+    {
+        if (ent.Comp.Resistance >= 1)
+            args.Cancelled = true;
+    }
+
+    private void OnResistEmpPulse(Entity<EmpResistanceComponent> ent, ref EmpPulseEvent args)
+    {
+        var empStrengthMultiplier = 1 - ent.Comp.Resistance;
+
+        if (empStrengthMultiplier <= 0)
+            return;
+
+        args.Duration *= (float) empStrengthMultiplier;
+        args.EnergyConsumption *= (float) empStrengthMultiplier;
+    }
 }
 
 /// <summary>
index f316b16f6be580889699e36cb8cd447019634789..01f860da1256762b0e650b9221da33d8be3cfa5f 100644 (file)
@@ -36,7 +36,6 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
         SubscribeLocalEvent<NinjaSuitComponent, CreateItemAttemptEvent>(OnCreateStarAttempt);
         SubscribeLocalEvent<NinjaSuitComponent, ItemToggleActivateAttemptEvent>(OnActivateAttempt);
         SubscribeLocalEvent<NinjaSuitComponent, GotUnequippedEvent>(OnUnequipped);
-        SubscribeLocalEvent<NinjaSuitComponent, EmpAttemptEvent>(OnEmpAttempt);
     }
 
     private void OnEquipped(Entity<NinjaSuitComponent> ent, ref ClothingGotEquippedEvent args)
@@ -172,11 +171,4 @@ public abstract class SharedNinjaSuitSystem : EntitySystem
         if (user.Comp.Gloves is { } uid)
             _toggle.TryDeactivate(uid, user: user);
     }
-
-    private void OnEmpAttempt(Entity<NinjaSuitComponent> ent, ref EmpAttemptEvent args)
-    {
-        // ninja suit (battery) is immune to emp
-        // powercell relays the event to suit
-        args.Cancelled = true;
-    }
 }
index 8b3154b4ab9f19d4fada8b1e57f0454aeab9662b..30c5c9f29534a9cac909fe46ed47a9d343350b48 100644 (file)
     sprite: Clothing/Ears/Headsets/ninja.rsi
   - type: Clothing
     sprite: Clothing/Ears/Headsets/ninja.rsi
+  - type: EmpResistance
+    resistance: 1
index 068ed1a51112fd042ce72dff092df8b78645dcd3..8d3a0ebae4f78f0a29206e4f92ce252f01f02e42 100644 (file)
     noPowerPopup: ninja-no-power
   # core ninja suit stuff
   - type: NinjaSuit
+  - type: EmpResistance
+    resistance: 1
   - type: UseDelay
     delay: 5 # disable time
   - type: PowerCellSlot