From 6dd579a385b92ac9d425f9113298255d4af8db9f Mon Sep 17 00:00:00 2001 From: Pspritechologist <81725545+Pspritechologist@users.noreply.github.com> Date: Mon, 18 Sep 2023 08:28:05 -0400 Subject: [PATCH] Adds Duration to EMP Event (#18437) --- Content.Server/Emp/EmpSystem.cs | 63 ++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/Content.Server/Emp/EmpSystem.cs b/Content.Server/Emp/EmpSystem.cs index c95be2501e..02a18284e8 100644 --- a/Content.Server/Emp/EmpSystem.cs +++ b/Content.Server/Emp/EmpSystem.cs @@ -27,30 +27,59 @@ public sealed class EmpSystem : SharedEmpSystem SubscribeLocalEvent(OnCameraSetActive); } + /// + /// Triggers an EMP pulse at the given location, by first raising an , then a raising on all entities in range. + /// + /// The location to trigger the EMP pulse at. + /// The range of the EMP pulse. + /// The amount of energy consumed by the EMP pulse. + /// The duration of the EMP effects. public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption, float duration) { foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range)) { - var attemptEv = new EmpAttemptEvent(); - RaiseLocalEvent(uid, attemptEv); - if (attemptEv.Cancelled) - continue; - - var ev = new EmpPulseEvent(energyConsumption, false, false); - RaiseLocalEvent(uid, ref ev); - if (ev.Affected) - { - Spawn(EmpDisabledEffectPrototype, Transform(uid).Coordinates); - } - if (ev.Disabled) - { - var disabled = EnsureComp(uid); - disabled.DisabledUntil = Timing.CurTime + TimeSpan.FromSeconds(duration); - } + TryEmpEffects(uid, energyConsumption, duration); } Spawn(EmpPulseEffectPrototype, coordinates); } + /// + /// Attempts to apply the effects of an EMP pulse onto an entity by first raising an , followed by raising a on it. + /// + /// The entity to apply the EMP effects on. + /// The amount of energy consumed by the EMP. + /// The duration of the EMP effects. + public void TryEmpEffects(EntityUid uid, float energyConsumption, float duration) + { + var attemptEv = new EmpAttemptEvent(); + RaiseLocalEvent(uid, attemptEv); + if (attemptEv.Cancelled) + return; + + DoEmpEffects(uid, energyConsumption, duration); + } + + /// + /// Applies the effects of an EMP pulse onto an entity by raising a on it. + /// + /// The entity to apply the EMP effects on. + /// The amount of energy consumed by the EMP. + /// The duration of the EMP effects. + public void DoEmpEffects(EntityUid uid, float energyConsumption, float duration) + { + var ev = new EmpPulseEvent(energyConsumption, false, false, TimeSpan.FromSeconds(duration)); + RaiseLocalEvent(uid, ref ev); + if (ev.Affected) + { + Spawn(EmpDisabledEffectPrototype, Transform(uid).Coordinates); + } + if (ev.Disabled) + { + var disabled = EnsureComp(uid); + disabled.DisabledUntil = Timing.CurTime + TimeSpan.FromSeconds(duration); + } + } + public override void Update(float frameTime) { base.Update(frameTime); @@ -113,7 +142,7 @@ public sealed partial class EmpAttemptEvent : CancellableEntityEventArgs } [ByRefEvent] -public record struct EmpPulseEvent(float EnergyConsumption, bool Affected, bool Disabled); +public record struct EmpPulseEvent(float EnergyConsumption, bool Affected, bool Disabled, TimeSpan Duration); [ByRefEvent] public record struct EmpDisabledRemoved(); -- 2.51.2