Skip to content

Commit

Permalink
Add defib event, add fields to be able to disable crit defib and do a…
Browse files Browse the repository at this point in the history
…fter movement (#28174)

* Add defib event, add fields to be able to disable crit defib and do after movement

* Fix check
  • Loading branch information
DrSmugleaf authored May 21, 2024
1 parent 68a0e56 commit dbb7dcd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Content.Server/Medical/DefibrillatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
});
}

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Medical/DefibrillatorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// The sound when someone is zapped.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/Medical/TargetDefibrillatedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Shared.Medical;

[ByRefEvent]
public readonly record struct TargetDefibrillatedEvent(EntityUid User, Entity<DefibrillatorComponent> Defibrillator);

0 comments on commit dbb7dcd

Please sign in to comment.