forked from DeltaV-Station/Delta-v
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] CPR Impovements (DeltaV-Station#1405)
# Description Moved the whole CPR code to the server. There was no need for it to be on shared. Now CPR automatically repeats itself until the person is alive. CPR can now be performed without getting you mask off. You just need to lower it down like when trying to eat/drink. Fixed popups repeating itself x100 times. Removed cvars and moved everything to CPRTraining component. Why would anyone place them in cvars anyway?.. --- # Changelog :cl: - add: CPR now automatically repeats itself. - add: CPR no longer requires you to take the mask off. You can now simply lower it instead. - fix: Fixed CPR repeating popups x100 times. Signed-off-by: Remuchi <[email protected]>
- Loading branch information
Showing
6 changed files
with
161 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using Content.Server.Atmos.Rotting; | ||
using Content.Server.DoAfter; | ||
using Content.Server.Nutrition.EntitySystems; | ||
using Content.Server.Popups; | ||
using Content.Shared.Atmos.Rotting; | ||
using Content.Shared.Damage; | ||
using Content.Shared.DoAfter; | ||
using Content.Shared.Inventory; | ||
using Content.Shared.Medical; | ||
using Content.Shared.Mobs; | ||
using Content.Shared.Mobs.Components; | ||
using Content.Shared.Mobs.Systems; | ||
using Content.Shared.Verbs; | ||
using Robust.Server.Audio; | ||
using Robust.Shared.Audio; | ||
using Robust.Shared.Random; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Server.Medical.CPR; | ||
|
||
public sealed class CPRSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly PopupSystem _popupSystem = default!; | ||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!; | ||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!; | ||
[Dependency] private readonly FoodSystem _foodSystem = default!; | ||
[Dependency] private readonly DamageableSystem _damageable = default!; | ||
[Dependency] private readonly MobThresholdSystem _mobThreshold = default!; | ||
[Dependency] private readonly IRobustRandom _robustRandom = default!; | ||
[Dependency] private readonly RottingSystem _rottingSystem = default!; | ||
[Dependency] private readonly InventorySystem _inventory = default!; | ||
[Dependency] private readonly AudioSystem _audio = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<CPRTrainingComponent, GetVerbsEvent<InnateVerb>>(AddCPRVerb); | ||
SubscribeLocalEvent<CPRTrainingComponent, CPRDoAfterEvent>(OnCPRDoAfter); | ||
} | ||
|
||
private void AddCPRVerb(Entity<CPRTrainingComponent> performer, ref GetVerbsEvent<InnateVerb> args) | ||
{ | ||
if (!args.CanInteract || !args.CanAccess || !TryComp<MobStateComponent>(args.Target, out var targetState) | ||
|| targetState.CurrentState == MobState.Alive) | ||
return; | ||
|
||
var target = args.Target; | ||
InnateVerb verb = new() | ||
{ | ||
Act = () => { StartCPR(performer, target); }, | ||
Text = Loc.GetString("cpr-verb"), | ||
Icon = new SpriteSpecifier.Rsi(new("Interface/Alerts/human_alive.rsi"), "health4"), | ||
Priority = 2 | ||
}; | ||
|
||
args.Verbs.Add(verb); | ||
} | ||
|
||
private void StartCPR(Entity<CPRTrainingComponent> performer, EntityUid target) | ||
{ | ||
if (HasComp<RottingComponent>(target)) | ||
{ | ||
_popupSystem.PopupEntity(Loc.GetString("cpr-target-rotting", ("entity", target)), performer, performer); | ||
return; | ||
} | ||
|
||
if (_inventory.TryGetSlotEntity(target, "outerClothing", out var outer)) | ||
{ | ||
_popupSystem.PopupEntity(Loc.GetString("cpr-must-remove", ("clothing", outer)), performer, performer); | ||
return; | ||
} | ||
|
||
if (_foodSystem.IsMouthBlocked(performer, performer) || _foodSystem.IsMouthBlocked(target, performer)) | ||
return; | ||
|
||
_popupSystem.PopupEntity(Loc.GetString("cpr-start-second-person", ("target", target)), target, performer); | ||
_popupSystem.PopupEntity(Loc.GetString("cpr-start-second-person-patient", ("user", performer)), target, target); | ||
|
||
var doAfterArgs = new DoAfterArgs( | ||
EntityManager, performer, performer.Comp.DoAfterDuration, new CPRDoAfterEvent(), performer, target, | ||
performer) | ||
{ | ||
BreakOnMove = true, | ||
NeedHand = true, | ||
BlockDuplicate = true | ||
}; | ||
|
||
_doAfterSystem.TryStartDoAfter(doAfterArgs); | ||
|
||
var playingStream = _audio.PlayPvs(performer.Comp.CPRSound, performer, AudioParams.Default.WithLoop(true)); | ||
if (!playingStream.HasValue) | ||
return; | ||
|
||
performer.Comp.CPRPlayingStream = playingStream.Value.Entity; | ||
} | ||
|
||
private void OnCPRDoAfter(Entity<CPRTrainingComponent> performer, ref CPRDoAfterEvent args) | ||
{ | ||
if (args.Cancelled || args.Handled || !args.Target.HasValue) | ||
{ | ||
performer.Comp.CPRPlayingStream = _audio.Stop(performer.Comp.CPRPlayingStream); | ||
return; | ||
} | ||
|
||
if (!performer.Comp.CPRHealing.Empty) | ||
_damageable.TryChangeDamage(args.Target, performer.Comp.CPRHealing, true, origin: performer); | ||
|
||
if (performer.Comp.RotReductionMultiplier > 0) | ||
_rottingSystem.ReduceAccumulator( | ||
(EntityUid)args.Target, performer.Comp.DoAfterDuration * performer.Comp.RotReductionMultiplier); | ||
|
||
if (_robustRandom.Prob(performer.Comp.ResuscitationChance) | ||
&& _mobThreshold.TryGetThresholdForState((EntityUid)args.Target, MobState.Dead, out var threshold) | ||
&& TryComp<DamageableComponent>(args.Target, out var damageableComponent) | ||
&& TryComp<MobStateComponent>(args.Target, out var state) | ||
&& damageableComponent.TotalDamage < threshold) | ||
_mobStateSystem.ChangeMobState(args.Target.Value, MobState.Critical, state, performer); | ||
|
||
var isAlive = _mobStateSystem.IsAlive(args.Target.Value); | ||
args.Repeat = !isAlive; | ||
if (isAlive) | ||
performer.Comp.CPRPlayingStream = _audio.Stop(performer.Comp.CPRPlayingStream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Content.Shared.Damage; | ||
using Robust.Shared.Audio; | ||
|
||
namespace Content.Server.Medical.CPR; | ||
|
||
[RegisterComponent] | ||
public sealed partial class CPRTrainingComponent : Component | ||
{ | ||
[DataField] | ||
public SoundSpecifier CPRSound = new SoundPathSpecifier("/Audio/Effects/CPR.ogg"); | ||
|
||
[DataField] | ||
public TimeSpan DoAfterDuration = TimeSpan.FromSeconds(3); | ||
|
||
[DataField] public DamageSpecifier CPRHealing = new() | ||
{ | ||
DamageDict = | ||
{ | ||
["Asphyxiation"] = -6 | ||
} | ||
}; | ||
|
||
[DataField] public float CrackRibsModifier = 1f; | ||
|
||
[DataField] public float ResuscitationChance = 0.1f; | ||
|
||
[DataField] public float RotReductionMultiplier; | ||
|
||
public EntityUid? CPRPlayingStream; | ||
} |
33 changes: 0 additions & 33 deletions
33
Content.Shared/Medical/CPR/Components/CPRTrainingComponent.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using Content.Shared.DoAfter; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Medical; | ||
|
||
[Serializable, NetSerializable] | ||
public sealed partial class CPRDoAfterEvent : SimpleDoAfterEvent; |