]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix cauterization (#23264)
authorthemias <89101928+themias@users.noreply.github.com>
Mon, 1 Jan 2024 08:08:25 +0000 (03:08 -0500)
committerGitHub <noreply@github.com>
Mon, 1 Jan 2024 08:08:25 +0000 (00:08 -0800)
* fix cauterization

* remove if statement

* revert DamageTest change

* fix

Content.Shared/Damage/DamageModifierSet.cs
Content.Shared/Damage/DamageSpecifier.cs
Content.Tests/Shared/DamageTest.cs

index bd074ec30f8a752527809728e6d601bdbdffbf0e..eaa6e93da4c1f61a591c9abf2c336f886cffe837 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Shared.Damage.Prototypes;
+using Content.Shared.Damage.Prototypes;
 using Robust.Shared.Serialization;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
 
@@ -12,7 +12,6 @@ namespace Content.Shared.Damage
     /// </summary>
     /// <remarks>
     /// The modifier will only ever be applied to damage that is being dealt. Healing is unmodified.
-    /// The modifier can also never convert damage into healing.
     /// </remarks>
     [DataDefinition]
     [Serializable, NetSerializable]
index 702b6fe3e9d5dbc10744beff5be150f5db31728e..872bad05514481932614033623f5837aa339b420 100644 (file)
@@ -151,12 +151,12 @@ namespace Content.Shared.Damage
                 float newValue = value.Float();
 
                 if (modifierSet.FlatReduction.TryGetValue(key, out var reduction))
-                    newValue -= reduction;
+                    newValue = Math.Max(0f, newValue - reduction); // flat reductions can't heal you
 
                 if (modifierSet.Coefficients.TryGetValue(key, out var coefficient))
-                    newValue *= coefficient;
+                    newValue *= coefficient; // coefficients can heal you, e.g. cauterizing bleeding
 
-                if (newValue > 0)
+                if(newValue != 0)
                     newDamage.DamageDict[key] = FixedPoint2.New(newValue);
             }
 
index 4221ff25a25d879db4965f3431a1aeda37ad081a..66f85cf1cce11433485692c871c9ca3207d6baba 100644 (file)
@@ -20,7 +20,7 @@ namespace Content.Tests.Shared
         private static Dictionary<string, float> _resistanceCoefficientDict = new()
         {
             // "missing" blunt entry
-            { "Piercing", -2 }, // negative multipliers just cause the damage to be ignored.
+            { "Piercing", -2 },// Turn Piercing into Healing
             { "Slash", 3 },
             { "Radiation", 1.5f },
         };
@@ -152,14 +152,14 @@ namespace Content.Tests.Shared
             // Apply once
             damageSpec = DamageSpecifier.ApplyModifierSet(damageSpec, modifierSet);
             Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(FixedPoint2.New(25)));
-            Assert.That(!damageSpec.DamageDict.ContainsKey("Piercing"));  // Cannot convert damage into healing.
+            Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(FixedPoint2.New(-40))); // became healing
             Assert.That(damageSpec.DamageDict["Slash"], Is.EqualTo(FixedPoint2.New(6)));
             Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(44.25)));
 
             // And again, checking for some other behavior
             damageSpec = DamageSpecifier.ApplyModifierSet(damageSpec, modifierSet);
             Assert.That(damageSpec.DamageDict["Blunt"], Is.EqualTo(FixedPoint2.New(30)));
-            Assert.That(!damageSpec.DamageDict.ContainsKey("Piercing"));
+            Assert.That(damageSpec.DamageDict["Piercing"], Is.EqualTo(FixedPoint2.New(-40))); // resistances don't apply to healing
             Assert.That(!damageSpec.DamageDict.ContainsKey("Slash"));  // Reduction reduced to 0, and removed from specifier
             Assert.That(damageSpec.DamageDict["Radiation"], Is.EqualTo(FixedPoint2.New(65.63)));
         }