From 6bb3b83bf1dace5b13f763462778db308d3b3635 Mon Sep 17 00:00:00 2001 From: Quantum-cross <7065792+Quantum-cross@users.noreply.github.com> Date: Wed, 7 May 2025 20:44:36 -0400 Subject: [PATCH] For DamagedSiliconAccent use Destructible threshold for default "DamageAtMaxThreshold" (#37252) * set DamageAtMaxCorruption as nullable with null default and use destructible trigger threshold for this if null. * fix documentation * these really don't need to be passed by reference --- .../DamagedSiliconAccentSystem.cs | 25 ++++++++++++++----- .../DamagedSiliconAccentComponent.cs | 5 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Content.Server/Speech/EntitySystems/DamagedSiliconAccentSystem.cs b/Content.Server/Speech/EntitySystems/DamagedSiliconAccentSystem.cs index 757d668127..47f36cafc4 100644 --- a/Content.Server/Speech/EntitySystems/DamagedSiliconAccentSystem.cs +++ b/Content.Server/Speech/EntitySystems/DamagedSiliconAccentSystem.cs @@ -1,4 +1,5 @@ using System.Text; +using Content.Server.Destructible; using Content.Server.PowerCell; using Content.Shared.Speech.Components; using Content.Shared.Damage; @@ -11,6 +12,7 @@ public sealed class DamagedSiliconAccentSystem : EntitySystem { [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly PowerCellSystem _powerCell = default!; + [Dependency] private readonly DestructibleSystem _destructibleSystem = default!; public override void Initialize() { @@ -35,7 +37,7 @@ public sealed class DamagedSiliconAccentSystem : EntitySystem } currentChargeLevel = Math.Clamp(currentChargeLevel, 0.0f, 1.0f); // Corrupt due to low power (drops characters on longer messages) - args.Message = CorruptPower(args.Message, currentChargeLevel, ref ent.Comp); + args.Message = CorruptPower(args.Message, currentChargeLevel, ent.Comp); } if (ent.Comp.EnableDamageCorruption) @@ -50,11 +52,11 @@ public sealed class DamagedSiliconAccentSystem : EntitySystem damage = damageable.TotalDamage; } // Corrupt due to damage (drop, repeat, replace with symbols) - args.Message = CorruptDamage(args.Message, damage, ref ent.Comp); + args.Message = CorruptDamage(args.Message, damage, ent); } } - public string CorruptPower(string message, float chargeLevel, ref DamagedSiliconAccentComponent comp) + public string CorruptPower(string message, float chargeLevel, DamagedSiliconAccentComponent comp) { // The first idxMin characters are SAFE var idxMin = comp.StartPowerCorruptionAtCharIdx; @@ -104,12 +106,23 @@ public sealed class DamagedSiliconAccentSystem : EntitySystem return outMsg.ToString(); } - private string CorruptDamage(string message, FixedPoint2 totalDamage, ref DamagedSiliconAccentComponent comp) + private string CorruptDamage(string message, FixedPoint2 totalDamage, Entity ent) { var outMsg = new StringBuilder(); + + // If this is not specified, use the Destructible threshold for destruction or breakage + var damageAtMaxCorruption = ent.Comp.DamageAtMaxCorruption; + if (damageAtMaxCorruption is null) + { + if (!TryComp(ent, out var destructible)) + return message; + + damageAtMaxCorruption = _destructibleSystem.DestroyedAt(ent, destructible); + } + // Linear interpolation of character damage probability - var damagePercent = Math.Clamp((float)totalDamage / (float)comp.DamageAtMaxCorruption, 0, 1); - var chanceToCorruptLetter = damagePercent * comp.MaxDamageCorruption; + var damagePercent = Math.Clamp((float)totalDamage / (float)damageAtMaxCorruption, 0, 1); + var chanceToCorruptLetter = damagePercent * ent.Comp.MaxDamageCorruption; foreach (var letter in message) { if (_random.Prob(chanceToCorruptLetter)) // Corrupt! diff --git a/Content.Shared/Speech/Components/DamagedSiliconAccentComponent.cs b/Content.Shared/Speech/Components/DamagedSiliconAccentComponent.cs index fa1377b379..2bc8645e72 100644 --- a/Content.Shared/Speech/Components/DamagedSiliconAccentComponent.cs +++ b/Content.Shared/Speech/Components/DamagedSiliconAccentComponent.cs @@ -27,10 +27,11 @@ public sealed partial class DamagedSiliconAccentComponent : Component /// /// Probability of character corruption will increase linearly to once until - /// total damage is at or above this value. + /// total damage is at or above this value. If null, it will use the value returned by + /// DestructibleSystem.DestroyedAt, which is the damage threshold for destruction or breakage. /// [DataField] - public FixedPoint2 DamageAtMaxCorruption = 300; + public FixedPoint2? DamageAtMaxCorruption; /// /// Enable charge level corruption effects -- 2.51.2