using Content.Shared.Toggleable;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
-using Robust.Shared.Timing;
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!;
[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()
{
if (args.Handled || args.Target is not { } target)
return;
+
args.Handled = TryStartZap(uid, target, args.User, component);
}
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))
_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;
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;
- }
- }
}
/// person back into the world of the living.
/// Uses <c>ItemToggleComponent</c>
/// </summary>
-[RegisterComponent, NetworkedComponent, AutoGenerateComponentPause]
+[RegisterComponent, NetworkedComponent]
public sealed partial class DefibrillatorComponent : Component
{
- /// <summary>
- /// The time at which the zap cooldown will be completed
- /// </summary>
- [DataField("nextZapTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
- [AutoPausedField]
- public TimeSpan? NextZapTime;
-
- /// <summary>
- /// The minimum time between zaps
- /// </summary>
- [DataField("zapDelay"), ViewVariables(VVAccess.ReadWrite)]
- public TimeSpan ZapDelay = TimeSpan.FromSeconds(5);
-
/// <summary>
/// How much damage is healed from getting zapped.
/// </summary>
[DataField("writheDuration"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan WritheDuration = TimeSpan.FromSeconds(3);
+ /// <summary>
+ /// ID of the cooldown use delay.
+ /// </summary>
+ [DataField]
+ public string DelayId = "defib-delay";
+
+ /// <summary>
+ /// Cooldown after using the defibrillator.
+ /// </summary>
+ [DataField]
+ public TimeSpan ZapDelay = TimeSpan.FromSeconds(5);
+
/// <summary>
/// How long the doafter for zapping someone takes
/// </summary>
public SoundSpecifier? ReadySound = new SoundPathSpecifier("/Audio/Items/Defib/defib_ready.ogg");
}
-[Serializable, NetSerializable]
-public enum DefibrillatorVisuals : byte
-{
- Ready
-}
-
[Serializable, NetSerializable]
public sealed partial class DefibrillatorZapDoAfterEvent : SimpleDoAfterEvent
{