From 9115994abf15401bca84b9695cb543cb518e1c68 Mon Sep 17 00:00:00 2001 From: themias <89101928+themias@users.noreply.github.com> Date: Mon, 1 Jan 2024 03:08:25 -0500 Subject: [PATCH] fix cauterization (#23264) * fix cauterization * remove if statement * revert DamageTest change * fix --- Content.Shared/Damage/DamageModifierSet.cs | 3 +-- Content.Shared/Damage/DamageSpecifier.cs | 6 +++--- Content.Tests/Shared/DamageTest.cs | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Content.Shared/Damage/DamageModifierSet.cs b/Content.Shared/Damage/DamageModifierSet.cs index bd074ec30f..eaa6e93da4 100644 --- a/Content.Shared/Damage/DamageModifierSet.cs +++ b/Content.Shared/Damage/DamageModifierSet.cs @@ -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 /// /// /// 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. /// [DataDefinition] [Serializable, NetSerializable] diff --git a/Content.Shared/Damage/DamageSpecifier.cs b/Content.Shared/Damage/DamageSpecifier.cs index 702b6fe3e9..872bad0551 100644 --- a/Content.Shared/Damage/DamageSpecifier.cs +++ b/Content.Shared/Damage/DamageSpecifier.cs @@ -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); } diff --git a/Content.Tests/Shared/DamageTest.cs b/Content.Tests/Shared/DamageTest.cs index 4221ff25a2..66f85cf1cc 100644 --- a/Content.Tests/Shared/DamageTest.cs +++ b/Content.Tests/Shared/DamageTest.cs @@ -20,7 +20,7 @@ namespace Content.Tests.Shared private static Dictionary _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))); } -- 2.51.2