]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
EmpResistance cleanup (#42402)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Wed, 14 Jan 2026 00:59:19 +0000 (01:59 +0100)
committerGitHub <noreply@github.com>
Wed, 14 Jan 2026 00:59:19 +0000 (00:59 +0000)
* init

* yeah

* Update SharedEmpSystem.cs

Content.Shared/Emp/EmpResistanceComponent.cs
Content.Shared/Emp/SharedEmpSystem.cs
Resources/Prototypes/Entities/Clothing/Ears/headsets.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml

index 0768ad744fd2de02385d5f9f5f32e0422675dee6..9f83a1ad7b619c9f3636e891a721782109f355f2 100644 (file)
@@ -11,8 +11,14 @@ namespace Content.Shared.Emp;
 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.
+    /// The strength of the EMP gets multiplied by this value.
     /// </summary>
     [DataField, AutoNetworkedField]
-    public FixedPoint2 Resistance = FixedPoint2.Zero;
+    public float StrengthMultiplier = 1f;
+
+    /// <summary>
+    /// The duration of the EMP gets multiplied by this value.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float DurationMultiplier = 1f;
 }
index d1c773dd90988d5d77655ee65286818db9c4211a..cc1895b20ff43ea1473a030c29b2cac162ae4d84 100644 (file)
@@ -19,6 +19,7 @@ public abstract class SharedEmpSystem : EntitySystem
     [Dependency] private readonly SharedTransformSystem _transform = default!;
 
     private HashSet<EntityUid> _entSet = new();
+    private EntityQuery<EmpResistanceComponent> _resistanceQuery;
 
     public override void Initialize()
     {
@@ -29,7 +30,8 @@ public abstract class SharedEmpSystem : EntitySystem
         SubscribeLocalEvent<EmpDisabledComponent, RejuvenateEvent>(OnRejuvenate);
 
         SubscribeLocalEvent<EmpResistanceComponent, EmpAttemptEvent>(OnResistEmpAttempt);
-        SubscribeLocalEvent<EmpResistanceComponent, EmpPulseEvent>(OnResistEmpPulse);
+
+        _resistanceQuery = GetEntityQuery<EmpResistanceComponent>();
     }
 
     public static readonly EntProtoId EmpPulseEffectPrototype = "EffectEmpPulse";
@@ -109,7 +111,14 @@ public abstract class SharedEmpSystem : EntitySystem
     /// <returns>If the entity was affected by the EMP.</returns>
     public bool DoEmpEffects(EntityUid uid, float energyConsumption, TimeSpan duration, EntityUid? user = null)
     {
-        var ev = new EmpPulseEvent(energyConsumption, false, false, duration, user);
+        var strMultiplier = 1f;
+        var durMultiplier = 1f;
+        if (_resistanceQuery.TryComp(uid, out var resistance))
+        {
+            strMultiplier = resistance.StrengthMultiplier;
+            durMultiplier = resistance.DurationMultiplier;
+        }
+        var ev = new EmpPulseEvent(energyConsumption * strMultiplier, false, false, duration * durMultiplier, user);
         RaiseLocalEvent(uid, ref ev);
 
         // TODO: replace with PredictedSpawn once it works with animated sprites
@@ -120,7 +129,7 @@ public abstract class SharedEmpSystem : EntitySystem
             return ev.Affected;
 
         var disabled = EnsureComp<EmpDisabledComponent>(uid);
-        disabled.DisabledUntil = Timing.CurTime + duration;
+        disabled.DisabledUntil = Timing.CurTime + duration * durMultiplier;
         Dirty(uid, disabled);
 
         return ev.Affected;
@@ -159,20 +168,11 @@ public abstract class SharedEmpSystem : EntitySystem
 
     private void OnResistEmpAttempt(Entity<EmpResistanceComponent> ent, ref EmpAttemptEvent args)
     {
-        if (ent.Comp.Resistance >= 1)
+        // We only cancel if the strength multiplier is 0, because then the effect basically doesn't exist.
+        // Allows us to make things resistant to the duration, but still lose charge to the EMP.
+        if (ent.Comp.StrengthMultiplier <= 0)
             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 30c5c9f29534a9cac909fe46ed47a9d343350b48..c5c4f269f145b5e95fea94c75847dccb9bc25b25 100644 (file)
   - type: Clothing
     sprite: Clothing/Ears/Headsets/ninja.rsi
   - type: EmpResistance
-    resistance: 1
+    strengthMultiplier: 0
index 8d3a0ebae4f78f0a29206e4f92ce252f01f02e42..4625aa1106b3d769f291776966c5bfd942c739a5 100644 (file)
   # core ninja suit stuff
   - type: NinjaSuit
   - type: EmpResistance
-    resistance: 1
+    strengthMultiplier: 0
   - type: UseDelay
     delay: 5 # disable time
   - type: PowerCellSlot