From dbb7dcd16d97d7cf7a7d1430a07bb24cce55c3d9 Mon Sep 17 00:00:00 2001
From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Date: Tue, 21 May 2024 05:11:49 -0700
Subject: [PATCH] Add defib event, add fields to be able to disable crit defib
and do after movement (#28174)
* Add defib event, add fields to be able to disable crit defib and do after movement
* Fix check
---
Content.Server/Medical/DefibrillatorSystem.cs | 10 +++++++++-
Content.Shared/Medical/DefibrillatorComponent.cs | 6 ++++++
Content.Shared/Medical/TargetDefibrillatedEvent.cs | 4 ++++
3 files changed, 19 insertions(+), 1 deletion(-)
create mode 100644 Content.Shared/Medical/TargetDefibrillatedEvent.cs
diff --git a/Content.Server/Medical/DefibrillatorSystem.cs b/Content.Server/Medical/DefibrillatorSystem.cs
index 64861fdc515..4373532f018 100644
--- a/Content.Server/Medical/DefibrillatorSystem.cs
+++ b/Content.Server/Medical/DefibrillatorSystem.cs
@@ -162,6 +162,9 @@ public bool CanZap(EntityUid uid, EntityUid target, EntityUid? user = null, Defi
if (_mobState.IsAlive(target, mobState))
return false;
+ if (!component.CanDefibCrit && _mobState.IsCritical(target, mobState))
+ return false;
+
return true;
}
@@ -179,7 +182,8 @@ public bool TryStartZap(EntityUid uid, EntityUid target, EntityUid user, Defibri
{
BlockDuplicate = true,
BreakOnHandChange = true,
- NeedHand = true
+ NeedHand = true,
+ BreakOnMove = !component.AllowDoAfterMovement
});
}
@@ -254,6 +258,10 @@ public void Zap(EntityUid uid, EntityUid target, EntityUid user, DefibrillatorCo
// if we don't have enough power left for another shot, turn it off
if (!_powerCell.HasActivatableCharge(uid))
TryDisable(uid, component);
+
+ // TODO clean up this clown show above
+ var ev = new TargetDefibrillatedEvent(user, (uid, component));
+ RaiseLocalEvent(target, ref ev);
}
public override void Update(float frameTime)
diff --git a/Content.Shared/Medical/DefibrillatorComponent.cs b/Content.Shared/Medical/DefibrillatorComponent.cs
index 2da52852854..61a02187d09 100644
--- a/Content.Shared/Medical/DefibrillatorComponent.cs
+++ b/Content.Shared/Medical/DefibrillatorComponent.cs
@@ -60,6 +60,12 @@ public sealed partial class DefibrillatorComponent : Component
[DataField("doAfterDuration"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan DoAfterDuration = TimeSpan.FromSeconds(3);
+ [DataField]
+ public bool AllowDoAfterMovement = true;
+
+ [DataField]
+ public bool CanDefibCrit = true;
+
///
/// The sound when someone is zapped.
///
diff --git a/Content.Shared/Medical/TargetDefibrillatedEvent.cs b/Content.Shared/Medical/TargetDefibrillatedEvent.cs
new file mode 100644
index 00000000000..60d1a215845
--- /dev/null
+++ b/Content.Shared/Medical/TargetDefibrillatedEvent.cs
@@ -0,0 +1,4 @@
+namespace Content.Shared.Medical;
+
+[ByRefEvent]
+public readonly record struct TargetDefibrillatedEvent(EntityUid User, Entity Defibrillator);