From a0a405768ad07ec4ebb4717308eb2d6bfc0e22ea Mon Sep 17 00:00:00 2001
From: beck-thompson <107373427+beck-thompson@users.noreply.github.com>
Date: Fri, 20 Dec 2024 13:26:56 -0800
Subject: [PATCH] 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>
---
Content.Server/Medical/DefibrillatorSystem.cs | 29 ++++-----------
.../Medical/DefibrillatorComponent.cs | 33 +++++++-----------
.../Objects/Specific/Medical/defib.yml | 7 ----
.../Specific/Medical/defib.rsi/meta.json | 3 --
.../Specific/Medical/defib.rsi/ready.png | Bin 139 -> 0 bytes
.../Specific/Medical/defib.rsi/screen.png | Bin 160 -> 207 bytes
6 files changed, 20 insertions(+), 52 deletions(-)
delete mode 100644 Resources/Textures/Objects/Specific/Medical/defib.rsi/ready.png
diff --git a/Content.Server/Medical/DefibrillatorSystem.cs b/Content.Server/Medical/DefibrillatorSystem.cs
index fa0ea26385..6bd563101b 100644
--- a/Content.Server/Medical/DefibrillatorSystem.cs
+++ b/Content.Server/Medical/DefibrillatorSystem.cs
@@ -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;
///
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!;
///
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(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(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();
- 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;
- }
- }
}
diff --git a/Content.Shared/Medical/DefibrillatorComponent.cs b/Content.Shared/Medical/DefibrillatorComponent.cs
index e4cd8077d2..f54348d771 100644
--- a/Content.Shared/Medical/DefibrillatorComponent.cs
+++ b/Content.Shared/Medical/DefibrillatorComponent.cs
@@ -12,22 +12,9 @@ namespace Content.Shared.Medical;
/// person back into the world of the living.
/// Uses ItemToggleComponent
///
-[RegisterComponent, NetworkedComponent, AutoGenerateComponentPause]
+[RegisterComponent, NetworkedComponent]
public sealed partial class DefibrillatorComponent : Component
{
- ///
- /// The time at which the zap cooldown will be completed
- ///
- [DataField("nextZapTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
- [AutoPausedField]
- public TimeSpan? NextZapTime;
-
- ///
- /// The minimum time between zaps
- ///
- [DataField("zapDelay"), ViewVariables(VVAccess.ReadWrite)]
- public TimeSpan ZapDelay = TimeSpan.FromSeconds(5);
-
///
/// How much damage is healed from getting zapped.
///
@@ -46,6 +33,18 @@ public sealed partial class DefibrillatorComponent : Component
[DataField("writheDuration"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan WritheDuration = TimeSpan.FromSeconds(3);
+ ///
+ /// ID of the cooldown use delay.
+ ///
+ [DataField]
+ public string DelayId = "defib-delay";
+
+ ///
+ /// Cooldown after using the defibrillator.
+ ///
+ [DataField]
+ public TimeSpan ZapDelay = TimeSpan.FromSeconds(5);
+
///
/// How long the doafter for zapping someone takes
///
@@ -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
{
diff --git a/Resources/Prototypes/Entities/Objects/Specific/Medical/defib.yml b/Resources/Prototypes/Entities/Objects/Specific/Medical/defib.yml
index fb0f3d52c6..e188794b81 100644
--- a/Resources/Prototypes/Entities/Objects/Specific/Medical/defib.yml
+++ b/Resources/Prototypes/Entities/Objects/Specific/Medical/defib.yml
@@ -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
diff --git a/Resources/Textures/Objects/Specific/Medical/defib.rsi/meta.json b/Resources/Textures/Objects/Specific/Medical/defib.rsi/meta.json
index 441fd4f5fe..0b08a6e6ee 100644
--- a/Resources/Textures/Objects/Specific/Medical/defib.rsi/meta.json
+++ b/Resources/Textures/Objects/Specific/Medical/defib.rsi/meta.json
@@ -18,9 +18,6 @@
"name": "inhand-right",
"directions": 4
},
- {
- "name": "ready"
- },
{
"name": "screen"
}
diff --git a/Resources/Textures/Objects/Specific/Medical/defib.rsi/ready.png b/Resources/Textures/Objects/Specific/Medical/defib.rsi/ready.png
deleted file mode 100644
index 9da205f381f4400de0c6fdd523bf0bc7f4d0ecc7..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 139
zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}uAVNAArY;~
z2@7zyBS-dZ=n^xpCO}
zAXAnvkBtAbySgUtNW8mgDbI8~%
zUwzeU+vY8^6b^4=%Dc6kv4s6ay6sQ?O)@%9I=U~Xym-%$w5VlSpuww#ivkL2EDYbh
X)fM@cY~p4B0#8>zmvv4FO$-bG2p~qq
delta 131
zcmX@lxPWnjN)2Oikh>GZx^prw85kI%JY5_^B3hFZBv=%Zk4%M#}{l~qtwJ}e+2+N-!P?`BY2xWyNPz{`wJ7*@3%=vMcaxTYK3
h6