diff --git a/Content.Shared/Blocking/BlockingSystem.cs b/Content.Shared/Blocking/BlockingSystem.cs index d70f12430e..0392428c3c 100644 --- a/Content.Shared/Blocking/BlockingSystem.cs +++ b/Content.Shared/Blocking/BlockingSystem.cs @@ -1,11 +1,14 @@ using Content.Shared.Actions; using Content.Shared.Actions.ActionTypes; +using Content.Shared.Buckle.Components; using Content.Shared.Hands; using Content.Shared.Hands.EntitySystems; using Content.Shared.IdentityManagement; using Content.Shared.Physics; using Content.Shared.Popups; using Content.Shared.Toggleable; +using Robust.Shared.Containers; +using Robust.Shared.Map; using Robust.Shared.Physics; using Robust.Shared.Physics.Dynamics; using Robust.Shared.Player; @@ -21,6 +24,8 @@ public sealed class BlockingSystem : EntitySystem [Dependency] private readonly FixtureSystem _fixtureSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly SharedContainerSystem _containerSystem = default!; public override void Initialize() { @@ -71,6 +76,17 @@ public sealed class BlockingSystem : EntitySystem if(args.Handled) return; + foreach (var shield in _handsSystem.EnumerateHeld(args.Performer)) + { + if (shield == uid) + continue; + if (TryComp(shield, out var otherBlockComp) && otherBlockComp.IsBlocking) + { + CantBlockError(args.Performer); + return; + } + } + if (component.IsBlocking) StopBlocking(uid, component, args.Performer); else @@ -112,11 +128,16 @@ public sealed class BlockingSystem : EntitySystem if (component.BlockingToggleAction != null) { + if (_containerSystem.IsEntityInContainer(user) || !_mapManager.TryFindGridAt(xform.MapPosition, out var grid)) + { + CantBlockError(user); + return false; + } + _transformSystem.AnchorEntity(xform); if (!xform.Anchored) { - var msgError = Loc.GetString("action-popup-blocking-user-cant-block"); - _popupSystem.PopupEntity(msgError, user, Filter.Entities(user)); + CantBlockError(user); return false; } _actionsSystem.SetToggled(component.BlockingToggleAction, true); @@ -141,6 +162,12 @@ public sealed class BlockingSystem : EntitySystem return true; } + private void CantBlockError(EntityUid user) + { + var msgError = Loc.GetString("action-popup-blocking-user-cant-block"); + _popupSystem.PopupEntity(msgError, user, Filter.Entities(user)); + } + /// /// Called where you want the user to stop blocking. /// @@ -166,7 +193,9 @@ public sealed class BlockingSystem : EntitySystem if (component.BlockingToggleAction != null && TryComp(user, out var blockingUserComponent) && TryComp(user, out var physicsComponent)) { - _transformSystem.Unanchor(xform); + if (xform.Anchored) + _transformSystem.Unanchor(xform); + _actionsSystem.SetToggled(component.BlockingToggleAction, false); _fixtureSystem.DestroyFixture(physicsComponent, BlockingComponent.BlockFixtureID); physicsComponent.BodyType = blockingUserComponent.OriginalBodyType; @@ -181,6 +210,7 @@ public sealed class BlockingSystem : EntitySystem /// /// Called where you want someone to stop blocking and to remove the from them + /// Won't remove the if they're holding another blocking item /// /// The item the component is attached to /// The @@ -190,6 +220,15 @@ public sealed class BlockingSystem : EntitySystem if (component.IsBlocking) StopBlocking(uid, component, user); + foreach (var shield in _handsSystem.EnumerateHeld(user)) + { + if (HasComp(shield) && TryComp(user, out var blockingUserComponent)) + { + blockingUserComponent.BlockingItem = shield; + return; + } + } + RemComp(user); component.User = null; } diff --git a/Content.Shared/Blocking/BlockingUserSystem.cs b/Content.Shared/Blocking/BlockingUserSystem.cs index a14d42c293..7cc6ad7025 100644 --- a/Content.Shared/Blocking/BlockingUserSystem.cs +++ b/Content.Shared/Blocking/BlockingUserSystem.cs @@ -1,8 +1,10 @@ using Content.Shared.Audio; +using Content.Shared.Buckle.Components; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; using Content.Shared.Hands.EntitySystems; using Robust.Shared.Audio; +using Robust.Shared.Containers; using Robust.Shared.Player; using Robust.Shared.Prototypes; @@ -21,12 +23,30 @@ public sealed class BlockingUserSystem : EntitySystem SubscribeLocalEvent(OnDamageChanged); SubscribeLocalEvent(OnUserDamageModified); + SubscribeLocalEvent(OnParentChanged); + SubscribeLocalEvent(OnInsertAttempt); SubscribeLocalEvent(OnAnchorChanged); } + private void OnParentChanged(EntityUid uid, BlockingUserComponent component, ref EntParentChangedMessage args) + { + if (TryComp(component.BlockingItem, out var blockComp) && blockComp.IsBlocking) + { + _blockingSystem.StopBlocking(component.BlockingItem.Value, blockComp, uid); + } + } + + private void OnInsertAttempt(EntityUid uid, BlockingUserComponent component, ContainerGettingInsertedAttemptEvent args) + { + if (TryComp(component.BlockingItem, out var blockComp) && blockComp.IsBlocking) + { + _blockingSystem.StopBlocking(component.BlockingItem.Value, blockComp, uid); + } + } + private void OnAnchorChanged(EntityUid uid, BlockingUserComponent component, ref AnchorStateChangedEvent args) { - if (!args.Anchored) + if (args.Anchored) return; if (TryComp(component.BlockingItem, out var blockComp) && blockComp.IsBlocking) diff --git a/Resources/Locale/en-US/actions/actions/blocking.ftl b/Resources/Locale/en-US/actions/actions/blocking.ftl index 6cfe9314a9..cc58e59610 100644 --- a/Resources/Locale/en-US/actions/actions/blocking.ftl +++ b/Resources/Locale/en-US/actions/actions/blocking.ftl @@ -7,4 +7,4 @@ action-popup-blocking-disabling-user = You lower your {$shield}! action-popup-blocking-other = {CAPITALIZE(THE($blockerName))} raises {POSS-ADJ($blockerName)} {$shield}! action-popup-blocking-disabling-other = {CAPITALIZE(THE($blockerName))} lowers {POSS-ADJ($blockerName)} {$shield}! -action-popup-blocking-user-cant-block = The gravity here prevents you from blocking. +action-popup-blocking-user-cant-block = You tried to raise your shield, but it was no use.