From 705d7ccf54a89a82b7c926c3c26e10351a75d0c2 Mon Sep 17 00:00:00 2001 From: OctoRocket <88291550+OctoRocket@users.noreply.github.com> Date: Sun, 23 Apr 2023 23:34:18 -0500 Subject: [PATCH] [Add] Repeatable healing items (#15613) * repeatable healing items * comments and break * simplified and improved * added messages * improved messages * stops when bleeding stops and won't give popup when clicking on an unhealable object * should actually stop when bleeding stops now * rerun tests please github * changes made * rerun tests please github * remove braces * fix --- Content.Server/Medical/HealingSystem.cs | 51 +++++++++++++++++-- .../medical/components/healing-component.ftl | 3 ++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 Resources/Locale/en-US/medical/components/healing-component.ftl diff --git a/Content.Server/Medical/HealingSystem.cs b/Content.Server/Medical/HealingSystem.cs index 7f442e8ec8..438bb38456 100644 --- a/Content.Server/Medical/HealingSystem.cs +++ b/Content.Server/Medical/HealingSystem.cs @@ -1,4 +1,5 @@ using Content.Server.Administration.Logs; +using Content.Server.Body.Components; using Content.Server.Body.Systems; using Content.Server.Medical.Components; using Content.Server.Stack; @@ -14,6 +15,7 @@ using Content.Shared.Mobs; using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Systems; using Content.Shared.Stacks; +using Content.Server.Popups; using Robust.Shared.Random; namespace Content.Server.Medical; @@ -30,6 +32,7 @@ public sealed class HealingSystem : EntitySystem [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; [Dependency] private readonly MobStateSystem _mobStateSystem = default!; [Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!; + [Dependency] private readonly PopupSystem _popupSystem = default!; public override void Initialize() { @@ -41,6 +44,8 @@ public sealed class HealingSystem : EntitySystem private void OnDoAfter(EntityUid uid, DamageableComponent component, HealingDoAfterEvent args) { + var dontRepeat = false; + if (!TryComp(args.Used, out HealingComponent? healing)) return; @@ -52,7 +57,17 @@ public sealed class HealingSystem : EntitySystem // Heal some bloodloss damage. if (healing.BloodlossModifier != 0) + { + if (!TryComp(uid, out var bloodstream)) + return; + var isBleeding = bloodstream.BleedAmount > 0; _bloodstreamSystem.TryModifyBleedAmount(uid, healing.BloodlossModifier); + if (isBleeding != bloodstream.BleedAmount > 0) + { + dontRepeat = true; + _popupSystem.PopupEntity(Loc.GetString("medical-item-stop-bleeding"), uid); + } + } // Restores missing blood if (healing.ModifyBloodLevel != 0) @@ -65,21 +80,44 @@ public sealed class HealingSystem : EntitySystem var total = healed?.Total ?? FixedPoint2.Zero; - // Reverify that we can heal the damage. + // Re-verify that we can heal the damage. _stacks.Use(args.Used.Value, 1); if (uid != args.User) + { _adminLogger.Add(LogType.Healed, $"{EntityManager.ToPrettyString(args.User):user} healed {EntityManager.ToPrettyString(uid):target} for {total:damage} damage"); + } else + { _adminLogger.Add(LogType.Healed, $"{EntityManager.ToPrettyString(args.User):user} healed themselves for {total:damage} damage"); + } _audio.PlayPvs(healing.HealingEndSound, uid, AudioHelpers.WithVariation(0.125f, _random).WithVolume(-5f)); + // Logic to determine the whether or not to repeat the healing action + args.Repeat = (HasDamage(component, healing) && !dontRepeat); + if (!args.Repeat && !dontRepeat) + _popupSystem.PopupEntity(Loc.GetString("medical-item-finished-using", ("item", args.Used)), uid); args.Handled = true; } + private bool HasDamage(DamageableComponent component, HealingComponent healing) + { + var damageableDict = component.Damage.DamageDict; + var healingDict = healing.Damage.DamageDict; + foreach (var type in healingDict) + { + if (damageableDict[type.Key].Value > 0) + { + return true; + } + } + + return false; + } + private void OnHealingUse(EntityUid uid, HealingComponent component, UseInHandEvent args) { if (args.Handled) @@ -103,9 +141,6 @@ public sealed class HealingSystem : EntitySystem if (_mobStateSystem.IsDead(target) || !TryComp(target, out var targetDamage)) return false; - if (targetDamage.TotalDamage == 0) - return false; - if (component.DamageContainerID is not null && !component.DamageContainerID.Equals(targetDamage.DamageContainerID)) return false; @@ -116,9 +151,17 @@ public sealed class HealingSystem : EntitySystem if (!TryComp(uid, out var stack) || stack.Count < 1) return false; + if (!HasDamage(targetDamage, component)) + { + _popupSystem.PopupEntity(Loc.GetString("medical-item-cant-use", ("item", uid)), uid); + return false; + } + if (component.HealingBeginSound != null) + { _audio.PlayPvs(component.HealingBeginSound, uid, AudioHelpers.WithVariation(0.125f, _random).WithVolume(-5f)); + } var isNotSelf = user != target; diff --git a/Resources/Locale/en-US/medical/components/healing-component.ftl b/Resources/Locale/en-US/medical/components/healing-component.ftl new file mode 100644 index 0000000000..5c2aaaabd9 --- /dev/null +++ b/Resources/Locale/en-US/medical/components/healing-component.ftl @@ -0,0 +1,3 @@ +medical-item-finished-using = You have finished healing with the {$item} +medical-item-cant-use = There is no damage you can heal with the {$item} +medical-item-stop-bleeding = They have stopped bleeding