From faaa2c2bef636909c789979000346ad6f9ff7000 Mon Sep 17 00:00:00 2001 From: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:55:19 +1100 Subject: [PATCH] Cherry-picked commit b0ffed1607452a2d4186228fc2343d10035611e5 from space-wizards/space-station-14/master --- Content.Shared/Blocking/BlockingSystem.User.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Blocking/BlockingSystem.User.cs b/Content.Shared/Blocking/BlockingSystem.User.cs index 87f285597f8..2cd1db7f1fe 100644 --- a/Content.Shared/Blocking/BlockingSystem.User.cs +++ b/Content.Shared/Blocking/BlockingSystem.User.cs @@ -47,13 +47,23 @@ private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component if (args.Damage.GetTotal() <= 0) return; + // A shield should only block damage it can itself absorb. To determine that we need the Damageable component on it. + if (!TryComp(component.BlockingItem, out var dmgComp)) + return; + var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction; blockFraction = Math.Clamp(blockFraction, 0, 1); _damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage); - args.Damage *= (1 - blockFraction); + var modify = new DamageModifierSet(); + foreach (var key in dmgComp.Damage.DamageDict.Keys) + { + modify.Coefficients.TryAdd(key, 1 - blockFraction); + } + + args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modify); - if (blocking.IsBlocking) + if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage)) { _audio.PlayPvs(blocking.BlockSound, uid); }