diff --git a/Content.Shared/Construction/EntitySystems/AnchorableSystem.cs b/Content.Shared/Construction/EntitySystems/AnchorableSystem.cs index a291473b30..ec8edea474 100644 --- a/Content.Shared/Construction/EntitySystems/AnchorableSystem.cs +++ b/Content.Shared/Construction/EntitySystems/AnchorableSystem.cs @@ -277,7 +277,10 @@ public sealed partial class AnchorableSystem : EntitySystem return !attempt.Cancelled; } - private bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody) + /// + /// Returns true if no hard anchored entities exist on the coordinate tile that would collide with the provided physics body. + /// + public bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody) { // Probably ignore CanCollide on the anchoring body? var gridUid = _transformSystem.GetGrid(coordinates); diff --git a/Content.Shared/Foldable/DeployFoldableSystem.cs b/Content.Shared/Foldable/DeployFoldableSystem.cs index 16315cde69..a83518dfa3 100644 --- a/Content.Shared/Foldable/DeployFoldableSystem.cs +++ b/Content.Shared/Foldable/DeployFoldableSystem.cs @@ -1,7 +1,10 @@ +using Content.Shared.Construction.EntitySystems; using Content.Shared.DragDrop; using Content.Shared.Hands.Components; using Content.Shared.Hands.EntitySystems; using Content.Shared.Interaction; +using Content.Shared.Popups; +using Robust.Shared.Physics.Components; namespace Content.Shared.Foldable; @@ -9,6 +12,8 @@ public sealed class DeployFoldableSystem : EntitySystem { [Dependency] private readonly SharedHandsSystem _hands = default!; [Dependency] private readonly FoldableSystem _foldable = default!; + [Dependency] private readonly AnchorableSystem _anchorable = default!; + [Dependency] private readonly SharedPopupSystem _popup = default!; public override void Initialize() { @@ -57,6 +62,13 @@ public sealed class DeployFoldableSystem : EntitySystem if (!TryComp(ent, out var foldable)) return; + if (!TryComp(ent.Owner, out PhysicsComponent? anchorBody) + || !_anchorable.TileFree(args.ClickLocation, anchorBody)) + { + _popup.PopupPredicted(Loc.GetString("foldable-deploy-fail", ("object", ent)), ent, args.User); + return; + } + if (!TryComp(args.User, out HandsComponent? hands) || !_hands.TryDrop(args.User, args.Used, targetDropLocation: args.ClickLocation, handsComp: hands)) return; diff --git a/Content.Shared/Foldable/FoldableSystem.cs b/Content.Shared/Foldable/FoldableSystem.cs index 3ba4201e79..73916f1c15 100644 --- a/Content.Shared/Foldable/FoldableSystem.cs +++ b/Content.Shared/Foldable/FoldableSystem.cs @@ -1,9 +1,11 @@ -using Content.Shared.Body.Components; using Content.Shared.Buckle; using Content.Shared.Buckle.Components; +using Content.Shared.Construction.EntitySystems; +using Content.Shared.Popups; using Content.Shared.Storage.Components; using Content.Shared.Verbs; using Robust.Shared.Containers; +using Robust.Shared.Physics.Components; using Robust.Shared.Serialization; using Robust.Shared.Utility; @@ -15,6 +17,8 @@ public sealed class FoldableSystem : EntitySystem [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedBuckleSystem _buckle = default!; [Dependency] private readonly SharedContainerSystem _container = default!; + [Dependency] private readonly AnchorableSystem _anchorable = default!; + [Dependency] private readonly SharedPopupSystem _popup = default!; public override void Initialize() { @@ -83,9 +87,17 @@ public sealed class FoldableSystem : EntitySystem args.Cancel(); } - public bool TryToggleFold(EntityUid uid, FoldableComponent comp) + public bool TryToggleFold(EntityUid uid, FoldableComponent comp, EntityUid? folder = null) { - return TrySetFolded(uid, comp, !comp.IsFolded); + var result = TrySetFolded(uid, comp, !comp.IsFolded); + if (!result && folder != null) + { + if (comp.IsFolded) + _popup.PopupPredicted(Loc.GetString("foldable-unfold-fail", ("object", uid)), uid, folder.Value); + else + _popup.PopupPredicted(Loc.GetString("foldable-fold-fail", ("object", uid)), uid, folder.Value); + } + return result; } public bool CanToggleFold(EntityUid uid, FoldableComponent? fold = null) @@ -97,6 +109,10 @@ public sealed class FoldableSystem : EntitySystem if (_container.IsEntityInContainer(uid) && !fold.CanFoldInsideContainer) return false; + if (!TryComp(uid, out PhysicsComponent? body) || + !_anchorable.TileFree(Transform(uid).Coordinates, body)) + return false; + var ev = new FoldAttemptEvent(fold); RaiseLocalEvent(uid, ref ev); return !ev.Cancelled; @@ -121,12 +137,12 @@ public sealed class FoldableSystem : EntitySystem private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetVerbsEvent args) { - if (!args.CanAccess || !args.CanInteract || args.Hands == null || !CanToggleFold(uid, component)) + if (!args.CanAccess || !args.CanInteract || args.Hands == null) return; AlternativeVerb verb = new() { - Act = () => TryToggleFold(uid, component), + Act = () => TryToggleFold(uid, component, args.User), Text = component.IsFolded ? Loc.GetString(component.UnfoldVerbText) : Loc.GetString(component.FoldVerbText), Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/fold.svg.192dpi.png")), diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 00246bafcd..eeb961537b 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -855,7 +855,7 @@ namespace Content.Shared.Interaction { // If the target is an item, we ignore any colliding entities. Currently done so that if items get stuck // inside of walls, users can still pick them up. - ignored.UnionWith(_broadphase.GetEntitiesIntersectingBody(target, (int) collisionMask, false, physics)); + ignored.UnionWith(_broadphase.GetEntitiesIntersectingBody(target, (int) collisionMask, false, physics)); // Note: This also bypasses items underneath doors, which may be problematic if it'd cause undesirable behavior. } else if (_wallMountQuery.TryComp(target, out var wallMount)) { diff --git a/Resources/Locale/en-US/foldable/components/foldable-component.ftl b/Resources/Locale/en-US/foldable/components/foldable-component.ftl index 525820920b..1221efbdf0 100644 --- a/Resources/Locale/en-US/foldable/components/foldable-component.ftl +++ b/Resources/Locale/en-US/foldable/components/foldable-component.ftl @@ -1,5 +1,8 @@ # Foldable +foldable-fold-fail = You can't fold the {$object} here. +foldable-unfold-fail = You can't unfold the {$object} here. + foldable-deploy-fail = You can't deploy the {$object} here. fold-verb = Fold unfold-verb = Unfold