Files
OldThink/Content.Server/Medical/DefibrillatorSystem.cs
MJSailor a95fe13180 Goida revert (#600)
* Revert "- fix: YAML linter fixes. (#598)"

This reverts commit 012bf3c357.

* Revert "Automatic changelog update"

This reverts commit cf1c3a9af5.

* Revert "[Fix] Base Layer Prototype (#597)"

This reverts commit b000423999.

* Revert "Modules update (#596)"

This reverts commit 00fbdead77.

* Revert "Automatic changelog update"

This reverts commit 0d7a12b2a2.

* Revert "Fixes (#593)"

This reverts commit 943c77031c.

* Revert "minor loadout fixes (#594)"

This reverts commit 143c010a89.

* Revert "Update DryDock.yml (#595)"

This reverts commit 4cd0100ac7.

* Revert "Automatic changelog update"

This reverts commit 08eadc690f.

* Revert "fix: Maximum message size (#591)"

This reverts commit 343f3612eb.

* Revert "Черри пики 7 (#592)"

This reverts commit 3f97bdce2f.

* Revert "Automatic changelog update"

This reverts commit 0678eca250.

* Revert "Рандомфиксы (#590)"

This reverts commit 2b9e5e2437.

* Revert "Нижнее бельё в лодауты (#580)"

This reverts commit e01a47b089.

* Revert "add lathe sounds (#588)"

This reverts commit c80a2985f2.

* Revert "Добавил параметр группы для некоторых реагентов (#585)"

This reverts commit 713b16bb98.

* Revert "add hrp ++++ aspect (#587)"

This reverts commit a6a69cc60f.

* Revert "Новые амбиенты и пару песен (#586)"

This reverts commit 48c86bd846.

* Revert "Сообщения в ПДА 2 (#583)"

This reverts commit cced3cc98b.

* Revert "Automatic changelog update"

This reverts commit abf435b11d.

* Revert "Chem stuff and more (#584)"

This reverts commit 3608960f5c.

* Revert "JobRequiremet refactor (#579)"

This reverts commit 9a9c9598e0.

* Revert "Revert "Reapply "Нижнее бельё в лодауты"""

This reverts commit 44447d573f.

* Revert "Reapply "Нижнее бельё в лодауты""

This reverts commit 0c4d082ad3.

* Revert "Revert "Нижнее бельё в лодауты""

This reverts commit 56473c5492.

* Revert "Нижнее бельё в лодауты"

This reverts commit d1cb0cb364.

* Revert "DryDock and WhiteMoose update (#578)"

This reverts commit 14755808af.

* Revert "Automatic changelog update"

This reverts commit 0133f82722.

* Revert "Fixes (#576)"

This reverts commit b7cc49896c.

* Revert "порт системы регенерации солюшена цинки (#574)"

This reverts commit a22cf3d50b.

* Revert "Воровские перчатки (#573)"

This reverts commit bb7140f3d4.

* Revert "mood resprite (#572)"

This reverts commit 4db96dc569.

* Revert "fix missing letter (#571)"

This reverts commit 94ea756794.

* Revert "Сообщения в ПДА (#564)"

This reverts commit d023d29e54.

* Revert "- fix: No visible aghost."

This reverts commit 27e7f25f7e.

* Revert "- tweak: Nerf cult shield."

This reverts commit 6a384246b8.
2024-08-09 19:09:22 +03:00

305 lines
11 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.Server.Traits.Assorted;
using Content.Shared._White.Item.DelayedKnockdown;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.DoAfter;
using Content.Shared.Emag.Systems;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Components;
using Content.Shared.Interaction.Events;
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 Content.Shared.Weapons.Melee;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Timing;
namespace Content.Server.Medical;
/// <summary>
/// This handles interactions and logic relating to <see cref="DefibrillatorComponent"/>
/// </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!;
[Dependency] private readonly ElectrocutionSystem _electrocution = default!;
[Dependency] private readonly EuiManager _euiManager = default!;
[Dependency] private readonly RottingSystem _rotting = 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 SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<DefibrillatorComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<DefibrillatorComponent, PowerCellSlotEmptyEvent>(OnPowerCellSlotEmpty);
SubscribeLocalEvent<DefibrillatorComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<DefibrillatorComponent, DefibrillatorZapDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<DefibrillatorComponent, StaminaDamageOnHitAttemptEvent>(OnStaminaHitAttempt); // WD
}
// WD START
private void OnStaminaHitAttempt(Entity<DefibrillatorComponent> ent, ref StaminaDamageOnHitAttemptEvent args)
{
var (uid, comp) = ent;
if (comp.Enabled && _powerCell.TryUseActivatableCharge(uid))
{
if (!_powerCell.HasActivatableCharge(uid))
TryDisable(uid, comp);
return;
}
args.Cancelled = true;
}
// WD END
private void OnUseInHand(EntityUid uid, DefibrillatorComponent component, UseInHandEvent args)
{
if (args.Handled || !TryComp(uid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((uid, useDelay)))
return;
if (!TryToggle(uid, component, args.User))
return;
args.Handled = true;
_useDelay.TryResetDelay((uid, useDelay));
}
private void OnPowerCellSlotEmpty(EntityUid uid, DefibrillatorComponent component, ref PowerCellSlotEmptyEvent args)
{
if (!TerminatingOrDeleted(uid))
TryDisable(uid, component);
}
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);
}
public bool TryToggle(EntityUid uid, DefibrillatorComponent? component = null, EntityUid? user = null)
{
if (!Resolve(uid, ref component))
return false;
return component.Enabled
? TryDisable(uid, component)
: TryEnable(uid, component, user);
}
public bool TryEnable(EntityUid uid, DefibrillatorComponent? component = null, EntityUid? user = null)
{
if (!Resolve(uid, ref component))
return false;
if (component.Enabled)
return false;
if (!_powerCell.HasActivatableCharge(uid))
return false;
component.Enabled = true;
_appearance.SetData(uid, ToggleVisuals.Toggled, true);
_audio.PlayPvs(component.PowerOnSound, uid);
return true;
}
public bool TryDisable(EntityUid uid, DefibrillatorComponent? component = null)
{
if (!Resolve(uid, ref component))
return false;
if (!component.Enabled)
return false;
component.Enabled = false;
_appearance.SetData(uid, ToggleVisuals.Toggled, false);
_audio.PlayPvs(component.PowerOffSound, uid);
return true;
}
public bool CanZap(EntityUid uid, EntityUid target, EntityUid? user = null, DefibrillatorComponent? component = null)
{
if (!Resolve(uid, ref component))
return false;
if (!component.Enabled)
{
if (user != null)
_popup.PopupEntity(Loc.GetString("defibrillator-not-on"), uid, user.Value);
return false;
}
if (_timing.CurTime < component.NextZapTime)
return false;
if (!TryComp<MobStateComponent>(target, out var mobState))
return false;
if (!_powerCell.HasActivatableCharge(uid, user: user))
return false;
// if (_mobState.IsAlive(target, mobState))
// return false;
return true;
}
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)
{
BreakOnMove = user == target, // WD EDIT
BlockDuplicate = true,
BreakOnHandChange = true,
NeedHand = true
});
}
public void Zap(EntityUid uid, EntityUid target, EntityUid user, DefibrillatorComponent? component = null, MobStateComponent? mob = null, MobThresholdsComponent? thresholds = null)
{
if (!Resolve(uid, ref component) || !Resolve(target, ref mob, ref thresholds, false))
return;
// clowns zap themselves
if (HasComp<ClumsyComponent>(user) && user != target)
{
Zap(uid, user, user, component);
return;
}
if (!_powerCell.TryUseActivatableCharge(uid, user: user))
return;
_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);
ICommonSession? session = null;
var dead = true;
// WD EDIT START
var alive = false;
if (_mobState.IsAlive(target))
{
alive = true;
}
else if (_rotting.IsRotten(target)) // WD EDIT END
{
_chatManager.TrySendInGameICMessage(uid, Loc.GetString("defibrillator-rotten"),
InGameICChatType.Speak, true);
}
else if (HasComp<UnrevivableComponent>(target))
{
_chatManager.TrySendInGameICMessage(uid, Loc.GetString("defibrillator-unrevivable"),
InGameICChatType.Speak, true);
}
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) &&
mind.Session is { } playerSession)
{
session = playerSession;
// notify them they're being revived.
if (mind.CurrentEntity != target)
{
_euiManager.OpenEui(new ReturnToBodyEui(mind, _mind), session);
}
}
else
{
_chatManager.TrySendInGameICMessage(uid, Loc.GetString("defibrillator-no-mind"),
InGameICChatType.Speak, true);
}
}
var sound = !alive && (dead || session == null) // WD EDIT
? 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))
TryDisable(uid, component);
}
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;
}
}
}