Add clearer defib cooldowns! (#31251)

* First commit

* Fix silly test

* Swiched stuff up

* Update Content.Shared/Medical/DefibrillatorComponent.cs

* remove unneeded visuals

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
beck-thompson
2024-12-20 13:26:56 -08:00
committed by GitHub
parent 0e850ab370
commit a0a405768a
6 changed files with 20 additions and 52 deletions

View File

@@ -23,7 +23,6 @@ using Content.Shared.Timing;
using Content.Shared.Toggleable;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Timing;
namespace Content.Server.Medical;
@@ -32,7 +31,6 @@ namespace Content.Server.Medical;
/// </summary>
public sealed class DefibrillatorSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ChatSystem _chatManager = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!;
@@ -44,9 +42,9 @@ public sealed class DefibrillatorSystem : EntitySystem
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
/// <inheritdoc/>
public override void Initialize()
@@ -59,6 +57,7 @@ public sealed class DefibrillatorSystem : EntitySystem
{
if (args.Handled || args.Target is not { } target)
return;
args.Handled = TryStartZap(uid, target, args.User, component);
}
@@ -102,7 +101,7 @@ public sealed class DefibrillatorSystem : EntitySystem
return false;
}
if (_timing.CurTime < component.NextZapTime)
if (!TryComp(uid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((uid, useDelay), component.DelayId))
return false;
if (!TryComp<MobStateComponent>(target, out var mobState))
@@ -181,8 +180,10 @@ public sealed class DefibrillatorSystem : EntitySystem
_audio.PlayPvs(component.ZapSound, uid);
_electrocution.TryDoElectrocution(target, null, component.ZapDamage, component.WritheDuration, true, ignoreInsulation: true);
component.NextZapTime = _timing.CurTime + component.ZapDelay;
_appearance.SetData(uid, DefibrillatorVisuals.Ready, false);
if (!TryComp<UseDelayComponent>(uid, out var useDelay))
return;
_useDelay.SetLength((uid, useDelay), component.ZapDelay, component.DelayId);
_useDelay.TryResetDelay((uid, useDelay), id: component.DelayId);
ICommonSession? session = null;
@@ -240,20 +241,4 @@ public sealed class DefibrillatorSystem : EntitySystem
var ev = new TargetDefibrillatedEvent(user, (uid, component));
RaiseLocalEvent(target, ref ev);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<DefibrillatorComponent>();
while (query.MoveNext(out var uid, out var defib))
{
if (defib.NextZapTime == null || _timing.CurTime < defib.NextZapTime)
continue;
_audio.PlayPvs(defib.ReadySound, uid);
_appearance.SetData(uid, DefibrillatorVisuals.Ready, true);
defib.NextZapTime = null;
}
}
}