diff --git a/Content.Shared/Blocking/BlockingSystem.User.cs b/Content.Shared/Blocking/BlockingSystem.User.cs index e660e7f3b0..8967b91fd4 100644 --- a/Content.Shared/Blocking/BlockingSystem.User.cs +++ b/Content.Shared/Blocking/BlockingSystem.User.cs @@ -12,8 +12,8 @@ public sealed partial class BlockingSystem private void InitializeUser() { - SubscribeLocalEvent(OnDamageChanged); SubscribeLocalEvent(OnUserDamageModified); + SubscribeLocalEvent(OnDamageModified); SubscribeLocalEvent(OnParentChanged); SubscribeLocalEvent(OnInsertAttempt); @@ -39,27 +39,37 @@ public sealed partial class BlockingSystem UserStopBlocking(uid, component); } - private void OnDamageChanged(EntityUid uid, BlockingUserComponent component, DamageChangedEvent args) - { - if (args.DamageDelta != null && args.DamageIncreased) - _damageable.TryChangeDamage(component.BlockingItem, args.DamageDelta, origin: args.Origin); - } - private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component, DamageModifyEvent args) { - if (TryComp(component.BlockingItem, out var blockingComponent)) + if (TryComp(component.BlockingItem, out var blocking)) { - if (_proto.TryIndex(blockingComponent.PassiveBlockDamageModifer, out DamageModifierSetPrototype? passiveblockModifier) && !blockingComponent.IsBlocking) - args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, passiveblockModifier); + var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction; + blockFraction = Math.Clamp(blockFraction, 0, 1); + _damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage); - if (_proto.TryIndex(blockingComponent.ActiveBlockDamageModifier, out DamageModifierSetPrototype? activeBlockModifier) && blockingComponent.IsBlocking) + args.Damage *= (1 - blockFraction); + + if (blocking.IsBlocking) { - args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, activeBlockModifier); - _audio.PlayPvs(blockingComponent.BlockSound, component.Owner, AudioParams.Default.WithVariation(0.2f)); + _audio.PlayPvs(blocking.BlockSound, uid, AudioParams.Default.WithVariation(0.2f)); } } } + private void OnDamageModified(EntityUid uid, BlockingComponent component, DamageModifyEvent args) + { + _proto.TryIndex(component.PassiveBlockDamageModifer, out var passiveblockModifier); + _proto.TryIndex(component.ActiveBlockDamageModifier, out var activeBlockModifier); + + var modifier = component.IsBlocking ? activeBlockModifier : passiveblockModifier; + if (modifier == null) + { + return; + } + + args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modifier); + } + private void OnEntityTerminating(EntityUid uid, BlockingUserComponent component, ref EntityTerminatingEvent args) { if (!TryComp(component.BlockingItem, out var blockingComponent)) diff --git a/Content.Shared/Blocking/Components/BlockingComponent.cs b/Content.Shared/Blocking/Components/BlockingComponent.cs index 2468becf84..dfa22d323e 100644 --- a/Content.Shared/Blocking/Components/BlockingComponent.cs +++ b/Content.Shared/Blocking/Components/BlockingComponent.cs @@ -59,4 +59,18 @@ public sealed class BlockingComponent : Component /// [DataField("blockSound")] public SoundSpecifier BlockSound = new SoundPathSpecifier("/Audio/Weapons/block_metal1.ogg"); + + /// + /// Fraction of original damage shield will take instead of user + /// when not blocking + /// + [DataField("passiveBlockFraction"), ViewVariables(VVAccess.ReadWrite)] + public float PassiveBlockFraction = 0.5f; + + /// + /// Fraction of original damage shield will take instead of user + /// when blocking + /// + [DataField("activeBlockFraction"), ViewVariables(VVAccess.ReadWrite)] + public float ActiveBlockFraction = 1.0f; } diff --git a/Content.Shared/Damage/Systems/DamageableSystem.cs b/Content.Shared/Damage/Systems/DamageableSystem.cs index f2644d647c..98e0ce0117 100644 --- a/Content.Shared/Damage/Systems/DamageableSystem.cs +++ b/Content.Shared/Damage/Systems/DamageableSystem.cs @@ -313,10 +313,12 @@ namespace Content.Shared.Damage // Whenever locational damage is a thing, this should just check only that bit of armour. public SlotFlags TargetSlots { get; } = ~SlotFlags.POCKET; + public readonly DamageSpecifier OriginalDamage; public DamageSpecifier Damage; public DamageModifyEvent(DamageSpecifier damage) { + OriginalDamage = damage; Damage = damage; } }