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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,22 +12,9 @@ namespace Content.Shared.Medical;
|
||||
/// 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>
|
||||
@@ -46,6 +33,18 @@ public sealed partial class DefibrillatorComponent : Component
|
||||
[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>
|
||||
@@ -80,12 +79,6 @@ public sealed partial class DefibrillatorComponent : Component
|
||||
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
|
||||
{
|
||||
|
||||
@@ -13,9 +13,6 @@
|
||||
map: [ "enum.ToggleVisuals.Layer" ]
|
||||
visible: false
|
||||
shader: unshaded
|
||||
- state: ready
|
||||
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||
shader: unshaded
|
||||
- type: Appearance
|
||||
- type: GenericVisualizer
|
||||
visuals:
|
||||
@@ -23,10 +20,6 @@
|
||||
enum.ToggleVisuals.Layer:
|
||||
True: { visible: true }
|
||||
False: { visible: false }
|
||||
enum.DefibrillatorVisuals.Ready:
|
||||
enum.PowerDeviceVisualLayers.Powered:
|
||||
True: { visible: true }
|
||||
False: { visible: false }
|
||||
- type: Item
|
||||
size: Large
|
||||
- type: Speech
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
"name": "inhand-right",
|
||||
"directions": 4
|
||||
},
|
||||
{
|
||||
"name": "ready"
|
||||
},
|
||||
{
|
||||
"name": "screen"
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 139 B |
Binary file not shown.
|
Before Width: | Height: | Size: 160 B After Width: | Height: | Size: 207 B |
Reference in New Issue
Block a user