]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add clearer defib cooldowns! (#31251)
authorbeck-thompson <107373427+beck-thompson@users.noreply.github.com>
Fri, 20 Dec 2024 21:26:56 +0000 (13:26 -0800)
committerGitHub <noreply@github.com>
Fri, 20 Dec 2024 21:26:56 +0000 (22:26 +0100)
* 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
Content.Shared/Medical/DefibrillatorComponent.cs
Resources/Prototypes/Entities/Objects/Specific/Medical/defib.yml
Resources/Textures/Objects/Specific/Medical/defib.rsi/meta.json
Resources/Textures/Objects/Specific/Medical/defib.rsi/ready.png [deleted file]
Resources/Textures/Objects/Specific/Medical/defib.rsi/screen.png

index fa0ea26385d09760e9895749f5232544d3d537c1..6bd563101b3d5ff6f18a8965a294e292d70a1dc2 100644 (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;
-        }
-    }
 }
index e4cd8077d26c0fe4d18a2d5401a046db930f018f..f54348d771f7a7057008c7f21cfb5c9f3621ef6d 100644 (file)
@@ -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
 {
index fb0f3d52c681bcc4f6d718fdd6a084aaa7b5415d..e188794b81fac7b646a5cfe2e9117ac75b67e0d7 100644 (file)
@@ -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:
           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
index 441fd4f5feb0cf1f9728bfe70c031d13bd7b2d6a..0b08a6e6eeddca594af58ce92a604135866132e1 100644 (file)
@@ -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 (file)
index 9da205f..0000000
Binary files a/Resources/Textures/Objects/Specific/Medical/defib.rsi/ready.png and /dev/null differ
index 1a8680d32b3578510a77a05312acbe4962bee8d2..b203a6c2aafb3acbea8f1c7288392c0a7298b807 100644 (file)
Binary files a/Resources/Textures/Objects/Specific/Medical/defib.rsi/screen.png and b/Resources/Textures/Objects/Specific/Medical/defib.rsi/screen.png differ