diff --git a/Content.Shared/Blocking/BlockingSystem.cs b/Content.Shared/Blocking/BlockingSystem.cs index 0392428c3c..ceeb236359 100644 --- a/Content.Shared/Blocking/BlockingSystem.cs +++ b/Content.Shared/Blocking/BlockingSystem.cs @@ -1,9 +1,12 @@ using Content.Shared.Actions; using Content.Shared.Actions.ActionTypes; using Content.Shared.Buckle.Components; +using Content.Shared.Doors.Components; using Content.Shared.Hands; using Content.Shared.Hands.EntitySystems; using Content.Shared.IdentityManagement; +using Content.Shared.Maps; +using Content.Shared.MobState.Components; using Content.Shared.Physics; using Content.Shared.Popups; using Content.Shared.Toggleable; @@ -26,6 +29,7 @@ public sealed class BlockingSystem : EntitySystem [Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly SharedContainerSystem _containerSystem = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; public override void Initialize() { @@ -128,12 +132,33 @@ public sealed class BlockingSystem : EntitySystem if (component.BlockingToggleAction != null) { + //Don't allow someone to block if they're in a container. if (_containerSystem.IsEntityInContainer(user) || !_mapManager.TryFindGridAt(xform.MapPosition, out var grid)) { CantBlockError(user); return false; } + //Don't allow someone to block if someone else is on the same tile or if they're inside of a doorway + var playerTileRef = xform.Coordinates.GetTileRef(); + if (playerTileRef != null) + { + var intersecting = _lookup.GetEntitiesIntersecting(playerTileRef.Value); + var mobQuery = GetEntityQuery(); + var doorQuery = GetEntityQuery(); + var xformQuery = GetEntityQuery(); + + foreach (var uid in intersecting) + { + if (uid != user && mobQuery.HasComponent(uid) || xformQuery.GetComponent(uid).Anchored && doorQuery.HasComponent(uid)) + { + TooCloseError(user); + return false; + } + } + } + + //Don't allow someone to block if they're somehow not anchored. _transformSystem.AnchorEntity(xform); if (!xform.Anchored) { @@ -168,6 +193,12 @@ public sealed class BlockingSystem : EntitySystem _popupSystem.PopupEntity(msgError, user, Filter.Entities(user)); } + private void TooCloseError(EntityUid user) + { + var msgError = Loc.GetString("action-popup-blocking-user-too-close"); + _popupSystem.PopupEntity(msgError, user, Filter.Entities(user)); + } + /// /// Called where you want the user to stop blocking. /// diff --git a/Resources/Locale/en-US/actions/actions/blocking.ftl b/Resources/Locale/en-US/actions/actions/blocking.ftl index cc58e59610..123a5991d4 100644 --- a/Resources/Locale/en-US/actions/actions/blocking.ftl +++ b/Resources/Locale/en-US/actions/actions/blocking.ftl @@ -8,3 +8,5 @@ action-popup-blocking-other = {CAPITALIZE(THE($blockerName))} raises {POSS-ADJ($ action-popup-blocking-disabling-other = {CAPITALIZE(THE($blockerName))} lowers {POSS-ADJ($blockerName)} {$shield}! action-popup-blocking-user-cant-block = You tried to raise your shield, but it was no use. +action-popup-blocking-user-too-close = There's no room here to block. Try moving a bit! +