Fix puncturase cauterizing bleeding (#38289)

fix puncturase cauterizing bleeding
This commit is contained in:
slarticodefast
2025-06-13 18:11:15 +02:00
committed by GitHub
parent 4f9e7fbc4d
commit ae8fdbfa51
3 changed files with 52 additions and 14 deletions

View File

@@ -205,10 +205,13 @@ public sealed class BloodstreamSystem : EntitySystem
} }
// TODO probably cache this or something. humans get hurt a lot // TODO probably cache this or something. humans get hurt a lot
if (!_prototypeManager.TryIndex<DamageModifierSetPrototype>(ent.Comp.DamageBleedModifiers, out var modifiers)) if (!_prototypeManager.TryIndex(ent.Comp.DamageBleedModifiers, out var modifiers))
return; return;
var bloodloss = DamageSpecifier.ApplyModifierSet(args.DamageDelta, modifiers); // some reagents may deal and heal different damage types in the same tick, which means DamageIncreased will be true
// but we only want to consider the dealt damage when causing bleeding
var damage = DamageSpecifier.GetPositive(args.DamageDelta);
var bloodloss = DamageSpecifier.ApplyModifierSet(damage, modifiers);
if (bloodloss.Empty) if (bloodloss.Empty)
return; return;
@@ -227,7 +230,7 @@ public sealed class BloodstreamSystem : EntitySystem
var prob = Math.Clamp(totalFloat / 25, 0, 1); var prob = Math.Clamp(totalFloat / 25, 0, 1);
if (totalFloat > 0 && _robustRandom.Prob(prob)) if (totalFloat > 0 && _robustRandom.Prob(prob))
{ {
TryModifyBloodLevel(ent, (-total) / 5, ent); TryModifyBloodLevel(ent, -total / 5, ent);
_audio.PlayPvs(ent.Comp.InstantBloodSound, ent); _audio.PlayPvs(ent.Comp.InstantBloodSound, ent);
} }

View File

@@ -23,7 +23,7 @@ namespace Content.Shared.Damage
[JsonPropertyName("types")] [JsonPropertyName("types")]
[DataField("types", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, DamageTypePrototype>))] [DataField("types", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, DamageTypePrototype>))]
[UsedImplicitly] [UsedImplicitly]
private Dictionary<string,FixedPoint2>? _damageTypeDictionary; private Dictionary<string, FixedPoint2>? _damageTypeDictionary;
[JsonPropertyName("groups")] [JsonPropertyName("groups")]
[DataField("groups", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, DamageGroupPrototype>))] [DataField("groups", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, DamageGroupPrototype>))]
@@ -152,7 +152,7 @@ namespace Content.Shared.Damage
if (modifierSet.Coefficients.TryGetValue(key, out var coefficient)) if (modifierSet.Coefficients.TryGetValue(key, out var coefficient))
newValue *= coefficient; // coefficients can heal you, e.g. cauterizing bleeding newValue *= coefficient; // coefficients can heal you, e.g. cauterizing bleeding
if(newValue != 0) if (newValue != 0)
newDamage.DamageDict[key] = FixedPoint2.New(newValue); newDamage.DamageDict[key] = FixedPoint2.New(newValue);
} }
@@ -183,6 +183,38 @@ namespace Content.Shared.Damage
return newDamage; return newDamage;
} }
/// <summary>
/// Returns a new DamageSpecifier that only contains the entries with positive value.
/// </summary>
public static DamageSpecifier GetPositive(DamageSpecifier damageSpec)
{
DamageSpecifier newDamage = new();
foreach (var (key, value) in damageSpec.DamageDict)
{
if (value > 0)
newDamage.DamageDict[key] = value;
}
return newDamage;
}
/// <summary>
/// Returns a new DamageSpecifier that only contains the entries with negative value.
/// </summary>
public static DamageSpecifier GetNegative(DamageSpecifier damageSpec)
{
DamageSpecifier newDamage = new();
foreach (var (key, value) in damageSpec.DamageDict)
{
if (value < 0)
newDamage.DamageDict[key] = value;
}
return newDamage;
}
/// <summary> /// <summary>
/// Remove any damage entries with zero damage. /// Remove any damage entries with zero damage.
/// </summary> /// </summary>

View File

@@ -237,21 +237,24 @@
# Represents which damage types should be modified # Represents which damage types should be modified
# in relation to how they cause bleed rate. # in relation to how they cause bleed rate.
# Make sure to add any new damage type here.
- type: damageModifierSet - type: damageModifierSet
id: BloodlossHuman id: BloodlossHuman
coefficients: coefficients:
Blunt: 0.08
Slash: 0.25
Piercing: 0.2
Shock: 0.0
Cold: 0.0
Heat: -0.5 # heat damage cauterizes wounds, but will still hurt obviously.
Poison: 0.0
Radiation: 0.0
Asphyxiation: 0.0 Asphyxiation: 0.0
Bloodloss: 0.0 # no double dipping Bloodloss: 0.0 # no double dipping
Cellular: 0.0 Blunt: 0.08
Caustic: 0.0 Caustic: 0.0
Cellular: 0.0
Cold: 0.0
Heat: -0.5 # heat damage cauterizes wounds, but will still hurt obviously.
Holy: 0
Piercing: 0.2
Poison: 0.0
Radiation: 0.0
Shock: 0.0
Slash: 0.25
Structural: 0.0
- type: damageModifierSet - type: damageModifierSet
id: SlimePet # Very survivable slimes id: SlimePet # Very survivable slimes