]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
[Add] Repeatable healing items (#15613)
authorOctoRocket <88291550+OctoRocket@users.noreply.github.com>
Mon, 24 Apr 2023 04:34:18 +0000 (23:34 -0500)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 04:34:18 +0000 (21:34 -0700)
* 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
Resources/Locale/en-US/medical/components/healing-component.ftl [new file with mode: 0644]

index 7f442e8ec81379ea7d198531722c5bec31f5b1ca..438bb38456d13b3d370a6353aa518e2cfa757a6d 100644 (file)
@@ -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<BloodstreamComponent>(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<DamageableComponent>(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<StackComponent>(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 (file)
index 0000000..5c2aaaa
--- /dev/null
@@ -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