diff --git a/Content.Shared/Blocking/BlockingSystem.User.cs b/Content.Shared/Blocking/BlockingSystem.User.cs index aa892c815c39a5..dc3d63281d1099 100644 --- a/Content.Shared/Blocking/BlockingSystem.User.cs +++ b/Content.Shared/Blocking/BlockingSystem.User.cs @@ -1,5 +1,6 @@ using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; +using Content.Shared.Inventory; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Containers; @@ -10,6 +11,7 @@ public sealed partial class BlockingSystem { [Dependency] private readonly DamageableSystem _damageable = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly InventorySystem _inventory = default!; // SS220 equip shield on back private void InitializeUser() { SubscribeLocalEvent(OnUserDamageModified); @@ -52,6 +54,13 @@ private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component if (!TryComp(component.BlockingItem, out var dmgComp)) return; + // SS220 equip shield on back begin + if (_inventory.TryGetContainingSlot(component.BlockingItem.Value, out var slotDefinition) && blocking.AvaliableSlots.TryGetValue(slotDefinition.SlotFlags, out var coef)) + { + blockFraction *= coef; + } + // SS220 equip shield on back end + blockFraction = Math.Clamp(blockFraction, 0, 1); _damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage); diff --git a/Content.Shared/Blocking/BlockingSystem.cs b/Content.Shared/Blocking/BlockingSystem.cs index 0c94bd6c87ea5c..670ef3a7432baf 100644 --- a/Content.Shared/Blocking/BlockingSystem.cs +++ b/Content.Shared/Blocking/BlockingSystem.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using Content.Shared.Actions; using Content.Shared.Damage; using Content.Shared.Examine; @@ -22,6 +22,7 @@ using Robust.Shared.Timing; using Robust.Shared.Utility; using Content.Shared.Weapons.Reflect; +using Content.Shared.Inventory.Events; namespace Content.Shared.Blocking; @@ -48,6 +49,11 @@ public override void Initialize() SubscribeLocalEvent(OnUnequip); SubscribeLocalEvent(OnDrop); + // SS220 equip shield on back begin + SubscribeLocalEvent(OnGotEquip); + SubscribeLocalEvent(OnGotUnequipped); + // SS220 equip shield on back end + SubscribeLocalEvent(OnGetActions); SubscribeLocalEvent(OnToggleAction); @@ -77,6 +83,30 @@ private void OnEquip(EntityUid uid, BlockingComponent component, GotEquippedHand } } + // SS220 equip shield on back begin + private void OnGotEquip(EntityUid uid, BlockingComponent component, GotEquippedEvent args) + { + + if (!component.AvaliableSlots.ContainsKey(args.SlotFlags)) + return; + + component.User = args.Equipee; + Dirty(uid, component); + + if (TryComp(args.Equipee, out var physicsComponent) && physicsComponent.BodyType != BodyType.Static) + { + var userComp = EnsureComp(args.Equipee); + userComp.BlockingItem = uid; + userComp.OriginalBodyType = physicsComponent.BodyType; + } + } + + private void OnGotUnequipped(EntityUid uid, BlockingComponent component, GotUnequippedEvent args) + { + StopBlockingHelper(uid, component, args.Equipee); + } + // SS220 equip shield on back end + private void OnUnequip(EntityUid uid, BlockingComponent component, GotUnequippedHandEvent args) { StopBlockingHelper(uid, component, args.User); diff --git a/Content.Shared/Blocking/Components/BlockingComponent.cs b/Content.Shared/Blocking/Components/BlockingComponent.cs index f869c20679d2ef..f55e5a7a254a72 100644 --- a/Content.Shared/Blocking/Components/BlockingComponent.cs +++ b/Content.Shared/Blocking/Components/BlockingComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.Damage; +using Content.Shared.Inventory; using Robust.Shared.Audio; using Robust.Shared.GameStates; using Robust.Shared.Physics.Collision.Shapes; @@ -76,4 +77,13 @@ public sealed partial class BlockingComponent : Component /// [DataField("activeBlockFraction"), ViewVariables(VVAccess.ReadWrite)] public float ActiveBlockFraction = 1.0f; + + // SS220 equip shield on back begin + /// + /// The list of slots that supported a shield protection + /// and second arg it's protection efficiency of this slots + /// + [DataField] + public Dictionary AvaliableSlots = new(); + // SS220 equip shield on back end }