-using Content.Shared.Damage.Prototypes;
+using Content.Shared.Damage.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
/// </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]
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);
}
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 },
};
// 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)));
}