* Offbrand medical * what if we regrade * zombies are mostly there thats it thats a wrap xd * here's changeling * some bonus gut punches * start working on the guidebook * fix rsi and yaml lints * my agrichem so fits * we stay rejuvenated * my china so laked * debrute * fix suicide * fix the suicide tests * my surgery so requires laying down * the guidebook continues * READ KEB PAGES * keb vascular recoupler * read keb medicine * fix yaml lint * fix the EntityRemoveConstructionGraphStep * fix overlay init * scalpels are not a food tool * return of the programmer art * my line so nieuw * boxes deserve veins too * mrrrp yaml * what if we redid brain damage alerts * bloot pressure * kill mannitol drowsiness * get licensed * my read so me * get feedbacked nerd * fine-tune the heart stoppage conditions * cryostasis adjustments, guidebook adjustments, fix negative strain issues * my surgery so table * fix heart surgery and guidebook * medicine & defibrillator pass * iv bags and stands * prefills * janet gets very sidetracked * mostly finished iv stuff * what if we fixed the guidebook * halve decapoid cryostasis * my medicines so IV * finetune cryostasis * less logspam * metabolism-aware iv stands and cryopods * give people painkillers * yaml lint real * fix blood build * finish rebase * tidy up localization * clean up my yaml beasties... * soft curve after exceeding maximum damage * husks/bonedeaths Grabbag of Offmed fixes & improvements (#3461) * CPR moment * Mob AI fix * Fix brain oxygenation not updating on regeneration * sorry gamers you cannot resist the pull * Troll combat abilities more in softcrit praying rn (#3467) dont have CPR be 50% (#3468) Make offbrand murder easier to contend with (#3473) * e * disrupt people in softcrit when attacking them * ok gamers we're gaming * forgor Hopefully final pass before Offbrand merge (#3475) First pass of Offbrand adjustments (#3477) Swap blood pressure values in health analyzer (#3476) Systolic over diastolic Co-authored-by: Kip <32859367+kipdotnet@users.noreply.github.com> Offbrand pass 2: Mostly bugfixes (#3480) Fix zeds causing PVS reloads (#3482) Offbrand pass 3: I hate surgery I hate surgery I hate surgery I (#3481) * set up surgery ui * test fail real Pain/braingasps (#3487) Offmed bundle 5 - the evil one (#3489) * Evil cavity surgery * les borgues * nicotine moment * epinephrine RNG * legalese * test fail real * ok jamers cope with c4 Pass 6
270 lines
10 KiB
C#
270 lines
10 KiB
C#
using Content.Server.Atmos.Rotting;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.DoAfter;
|
|
using Content.Server.Electrocution;
|
|
using Content.Server.EUI;
|
|
using Content.Server.Ghost;
|
|
using Content.Server.Popups;
|
|
using Content.Server.PowerCell;
|
|
using Content.Shared.Traits.Assorted;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Interaction.Components;
|
|
using Content.Shared.Interaction.Events;
|
|
using Content.Shared.Item.ItemToggle;
|
|
using Content.Shared.Medical;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.PowerCell;
|
|
using Content.Shared.Timing;
|
|
using Content.Shared.Toggleable;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Player;
|
|
using Content.Shared._Offbrand.Wounds; // Offbrand
|
|
|
|
namespace Content.Server.Medical;
|
|
|
|
/// <summary>
|
|
/// This handles interactions and logic relating to <see cref="DefibrillatorComponent"/>
|
|
/// </summary>
|
|
public sealed class DefibrillatorSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ChatSystem _chatManager = default!;
|
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
|
[Dependency] private readonly DoAfterSystem _doAfter = default!;
|
|
[Dependency] private readonly ElectrocutionSystem _electrocution = default!;
|
|
[Dependency] private readonly EuiManager _euiManager = default!;
|
|
[Dependency] private readonly ISharedPlayerManager _player = default!;
|
|
[Dependency] private readonly ItemToggleSystem _toggle = default!;
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
|
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!;
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
[Dependency] private readonly PowerCellSystem _powerCell = default!;
|
|
[Dependency] private readonly RottingSystem _rotting = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedMindSystem _mind = default!;
|
|
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<DefibrillatorComponent, AfterInteractEvent>(OnAfterInteract);
|
|
SubscribeLocalEvent<DefibrillatorComponent, DefibrillatorZapDoAfterEvent>(OnDoAfter);
|
|
}
|
|
|
|
private void OnAfterInteract(EntityUid uid, DefibrillatorComponent component, AfterInteractEvent args)
|
|
{
|
|
if (args.Handled || args.Target is not { } target)
|
|
return;
|
|
|
|
args.Handled = TryStartZap(uid, target, args.User, component);
|
|
}
|
|
|
|
private void OnDoAfter(EntityUid uid, DefibrillatorComponent component, DefibrillatorZapDoAfterEvent args)
|
|
{
|
|
if (args.Handled || args.Cancelled)
|
|
return;
|
|
|
|
if (args.Target is not { } target)
|
|
return;
|
|
|
|
if (!CanZap(uid, target, args.User, component))
|
|
return;
|
|
|
|
args.Handled = true;
|
|
Zap(uid, target, args.User, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if you can actually defib a target.
|
|
/// </summary>
|
|
/// <param name="uid">Uid of the defib</param>
|
|
/// <param name="target">Uid of the target getting defibbed</param>
|
|
/// <param name="user">Uid of the entity using the defibrillator</param>
|
|
/// <param name="component">Defib component</param>
|
|
/// <param name="targetCanBeAlive">
|
|
/// If true, the target can be alive. If false, the function will check if the target is alive and will return false if they are.
|
|
/// </param>
|
|
/// <returns>
|
|
/// Returns true if the target is valid to be defibed, false otherwise.
|
|
/// </returns>
|
|
public bool CanZap(EntityUid uid, EntityUid target, EntityUid? user = null, DefibrillatorComponent? component = null, bool targetCanBeAlive = false)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return false;
|
|
|
|
if (!_toggle.IsActivated(uid))
|
|
{
|
|
if (user != null)
|
|
_popup.PopupEntity(Loc.GetString("defibrillator-not-on"), uid, user.Value);
|
|
return false;
|
|
}
|
|
|
|
if (!TryComp(uid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((uid, useDelay), component.DelayId))
|
|
return false;
|
|
|
|
if (!TryComp<MobStateComponent>(target, out var mobState))
|
|
return false;
|
|
|
|
if (!_powerCell.HasActivatableCharge(uid, user: user))
|
|
return false;
|
|
|
|
// Begin Offbrand
|
|
if (TryComp<HeartrateComponent>(target, out var heartrate) && heartrate.Running)
|
|
return false;
|
|
// End Offbrand
|
|
|
|
if (!targetCanBeAlive && heartrate is null && _mobState.IsAlive(target, mobState)) // Offbrand
|
|
return false;
|
|
|
|
if (!targetCanBeAlive && heartrate is null && !component.CanDefibCrit && _mobState.IsCritical(target, mobState)) // Offbrand
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to start defibrillating the target. If the target is valid, will start the defib do-after.
|
|
/// </summary>
|
|
/// <param name="uid">Uid of the defib</param>
|
|
/// <param name="target">Uid of the target getting defibbed</param>
|
|
/// <param name="user">Uid of the entity using the defibrillator</param>
|
|
/// <param name="component">Defib component</param>
|
|
/// <returns>
|
|
/// Returns true if the defibrillation do-after started, otherwise false.
|
|
/// </returns>
|
|
public bool TryStartZap(EntityUid uid, EntityUid target, EntityUid user, DefibrillatorComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return false;
|
|
|
|
if (!CanZap(uid, target, user, component))
|
|
return false;
|
|
|
|
_audio.PlayPvs(component.ChargeSound, uid);
|
|
return _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.DoAfterDuration, new DefibrillatorZapDoAfterEvent(),
|
|
uid, target, uid)
|
|
{
|
|
NeedHand = true,
|
|
BreakOnMove = !component.AllowDoAfterMovement
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to defibrillate the target with the given defibrillator.
|
|
/// </summary>
|
|
public void Zap(EntityUid uid, EntityUid target, EntityUid user, DefibrillatorComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (!_powerCell.TryUseActivatableCharge(uid, user: user))
|
|
return;
|
|
|
|
var selfEvent = new SelfBeforeDefibrillatorZapsEvent(user, uid, target);
|
|
RaiseLocalEvent(user, selfEvent);
|
|
|
|
target = selfEvent.DefibTarget;
|
|
|
|
// Ensure thet new target is still valid.
|
|
if (selfEvent.Cancelled || !CanZap(uid, target, user, component, true))
|
|
return;
|
|
|
|
var targetEvent = new TargetBeforeDefibrillatorZapsEvent(user, uid, target);
|
|
RaiseLocalEvent(target, targetEvent);
|
|
|
|
target = targetEvent.DefibTarget;
|
|
|
|
if (targetEvent.Cancelled || !CanZap(uid, target, user, component, true))
|
|
return;
|
|
|
|
var hasDefib = TryComp<HeartDefibrillatableComponent>(target, out var heartDefibrillatable); // Offbrand
|
|
if (!TryComp<MobStateComponent>(target, out var mob) ||
|
|
(!TryComp<MobThresholdsComponent>(target, out var thresholds) && !hasDefib)) // Offbrand
|
|
return;
|
|
|
|
_audio.PlayPvs(component.ZapSound, uid);
|
|
_electrocution.TryDoElectrocution(target, null, component.ZapDamage, component.WritheDuration, true, ignoreInsulation: true);
|
|
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;
|
|
|
|
var dead = true;
|
|
if (_rotting.IsRotten(target))
|
|
{
|
|
_chatManager.TrySendInGameICMessage(uid, Loc.GetString("defibrillator-rotten"),
|
|
InGameICChatType.Speak, true);
|
|
}
|
|
else if (heartDefibrillatable is null && TryComp<UnrevivableComponent>(target, out var unrevivable)) // Offbrand
|
|
{
|
|
_chatManager.TrySendInGameICMessage(uid, Loc.GetString(unrevivable.ReasonMessage),
|
|
InGameICChatType.Speak, true);
|
|
}
|
|
// Begin offbrand
|
|
else if (heartDefibrillatable is not null && _mobState.IsDead(target, mob))
|
|
{
|
|
_chatManager.TrySendInGameICMessage(uid, Loc.GetString(heartDefibrillatable.TargetIsDead),
|
|
InGameICChatType.Speak, true);
|
|
}
|
|
else if (heartDefibrillatable is not null)
|
|
{
|
|
var before = new BeforeTargetDefibrillatedEvent(new());
|
|
RaiseLocalEvent(target, ref before);
|
|
|
|
foreach (var message in before.Messages)
|
|
{
|
|
_chatManager.TrySendInGameICMessage(uid, Loc.GetString(message), InGameICChatType.Speak, true);
|
|
}
|
|
}
|
|
// End Offbrand
|
|
else
|
|
{
|
|
if (_mobState.IsDead(target, mob))
|
|
_damageable.TryChangeDamage(target, component.ZapHeal, true, origin: uid);
|
|
|
|
if (_mobThreshold.TryGetThresholdForState(target, MobState.Dead, out var threshold) &&
|
|
TryComp<DamageableComponent>(target, out var damageableComponent) &&
|
|
damageableComponent.TotalDamage < threshold)
|
|
{
|
|
_mobState.ChangeMobState(target, MobState.Critical, mob, uid);
|
|
dead = false;
|
|
}
|
|
|
|
if (_mind.TryGetMind(target, out _, out var mind) &&
|
|
_player.TryGetSessionById(mind.UserId, out var playerSession))
|
|
{
|
|
session = playerSession;
|
|
// notify them they're being revived.
|
|
if (mind.CurrentEntity != target)
|
|
{
|
|
_euiManager.OpenEui(new ReturnToBodyEui(mind, _mind, _player), session);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_chatManager.TrySendInGameICMessage(uid, Loc.GetString("defibrillator-no-mind"),
|
|
InGameICChatType.Speak, true);
|
|
}
|
|
}
|
|
|
|
var sound = dead || session == null
|
|
? component.FailureSound
|
|
: component.SuccessSound;
|
|
_audio.PlayPvs(sound, uid);
|
|
|
|
// if we don't have enough power left for another shot, turn it off
|
|
if (!_powerCell.HasActivatableCharge(uid))
|
|
_toggle.TryDeactivate(uid);
|
|
|
|
// TODO clean up this clown show above
|
|
var ev = new TargetDefibrillatedEvent(user, (uid, component));
|
|
RaiseLocalEvent(target, ref ev);
|
|
}
|
|
}
|