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
This commit is contained in:
DrSmugleaf
2024-05-21 05:11:49 -07:00
committed by GitHub
parent 68a0e568e4
commit dbb7dcd16d
3 changed files with 19 additions and 1 deletions

View File

@@ -162,6 +162,9 @@ public sealed class DefibrillatorSystem : EntitySystem
if (_mobState.IsAlive(target, mobState)) if (_mobState.IsAlive(target, mobState))
return false; return false;
if (!component.CanDefibCrit && _mobState.IsCritical(target, mobState))
return false;
return true; return true;
} }
@@ -179,7 +182,8 @@ public sealed class DefibrillatorSystem : EntitySystem
{ {
BlockDuplicate = true, BlockDuplicate = true,
BreakOnHandChange = true, BreakOnHandChange = true,
NeedHand = true NeedHand = true,
BreakOnMove = !component.AllowDoAfterMovement
}); });
} }
@@ -254,6 +258,10 @@ public sealed class DefibrillatorSystem : EntitySystem
// if we don't have enough power left for another shot, turn it off // if we don't have enough power left for another shot, turn it off
if (!_powerCell.HasActivatableCharge(uid)) if (!_powerCell.HasActivatableCharge(uid))
TryDisable(uid, component); 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) public override void Update(float frameTime)

View File

@@ -60,6 +60,12 @@ public sealed partial class DefibrillatorComponent : Component
[DataField("doAfterDuration"), ViewVariables(VVAccess.ReadWrite)] [DataField("doAfterDuration"), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan DoAfterDuration = TimeSpan.FromSeconds(3); public TimeSpan DoAfterDuration = TimeSpan.FromSeconds(3);
[DataField]
public bool AllowDoAfterMovement = true;
[DataField]
public bool CanDefibCrit = true;
/// <summary> /// <summary>
/// The sound when someone is zapped. /// The sound when someone is zapped.
/// </summary> /// </summary>

View File

@@ -0,0 +1,4 @@
namespace Content.Shared.Medical;
[ByRefEvent]
public readonly record struct TargetDefibrillatedEvent(EntityUid User, Entity<DefibrillatorComponent> Defibrillator);