Adds Duration to EMP Event (#18437)
This commit is contained in:
@@ -27,16 +27,47 @@ public sealed class EmpSystem : SharedEmpSystem
|
||||
SubscribeLocalEvent<EmpDisabledComponent, SurveillanceCameraSetActiveAttemptEvent>(OnCameraSetActive);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers an EMP pulse at the given location, by first raising an <see cref="EmpAttemptEvent"/>, then a raising <see cref="EmpPulseEvent"/> on all entities in range.
|
||||
/// </summary>
|
||||
/// <param name="coordinates">The location to trigger the EMP pulse at.</param>
|
||||
/// <param name="range">The range of the EMP pulse.</param>
|
||||
/// <param name="energyConsumption">The amount of energy consumed by the EMP pulse.</param>
|
||||
/// <param name="duration">The duration of the EMP effects.</param>
|
||||
public void EmpPulse(MapCoordinates coordinates, float range, float energyConsumption, float duration)
|
||||
{
|
||||
foreach (var uid in _lookup.GetEntitiesInRange(coordinates, range))
|
||||
{
|
||||
TryEmpEffects(uid, energyConsumption, duration);
|
||||
}
|
||||
Spawn(EmpPulseEffectPrototype, coordinates);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to apply the effects of an EMP pulse onto an entity by first raising an <see cref="EmpAttemptEvent"/>, followed by raising a <see cref="EmpPulseEvent"/> on it.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity to apply the EMP effects on.</param>
|
||||
/// <param name="energyConsumption">The amount of energy consumed by the EMP.</param>
|
||||
/// <param name="duration">The duration of the EMP effects.</param>
|
||||
public void TryEmpEffects(EntityUid uid, float energyConsumption, float duration)
|
||||
{
|
||||
var attemptEv = new EmpAttemptEvent();
|
||||
RaiseLocalEvent(uid, attemptEv);
|
||||
if (attemptEv.Cancelled)
|
||||
continue;
|
||||
return;
|
||||
|
||||
var ev = new EmpPulseEvent(energyConsumption, false, false);
|
||||
DoEmpEffects(uid, energyConsumption, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the effects of an EMP pulse onto an entity by raising a <see cref="EmpPulseEvent"/> on it.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity to apply the EMP effects on.</param>
|
||||
/// <param name="energyConsumption">The amount of energy consumed by the EMP.</param>
|
||||
/// <param name="duration">The duration of the EMP effects.</param>
|
||||
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)
|
||||
{
|
||||
@@ -48,8 +79,6 @@ public sealed class EmpSystem : SharedEmpSystem
|
||||
disabled.DisabledUntil = Timing.CurTime + TimeSpan.FromSeconds(duration);
|
||||
}
|
||||
}
|
||||
Spawn(EmpPulseEffectPrototype, coordinates);
|
||||
}
|
||||
|
||||
public override void Update(float 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();
|
||||
|
||||
Reference in New Issue
Block a user