Skip to content

Commit

Permalink
Cherry-picked commit b0ffed1 from space-wizards/space-station-14/master
Browse files Browse the repository at this point in the history
  • Loading branch information
nikthechampiongr authored and SimpleStation14 committed Apr 21, 2024
1 parent 3bf08c7 commit faaa2c2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Content.Shared/Blocking/BlockingSystem.User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DamageableComponent>(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);
}
Expand Down

0 comments on commit faaa2c2

Please sign in to comment.