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