Prevent certain foldable items from being unfolded on structures (#36687)

initial commit
This commit is contained in:
SlamBamActionman
2025-04-19 04:17:13 +02:00
committed by GitHub
parent 4d25907ba4
commit b6e101b96f
5 changed files with 41 additions and 7 deletions

View File

@@ -277,7 +277,10 @@ public sealed partial class AnchorableSystem : EntitySystem
return !attempt.Cancelled;
}
private bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
/// <summary>
/// Returns true if no hard anchored entities exist on the coordinate tile that would collide with the provided physics body.
/// </summary>
public bool TileFree(EntityCoordinates coordinates, PhysicsComponent anchorBody)
{
// Probably ignore CanCollide on the anchoring body?
var gridUid = _transformSystem.GetGrid(coordinates);

View File

@@ -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<FoldableComponent>(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;

View File

@@ -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<AlternativeVerb> 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")),

View File

@@ -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))
{

View File

@@ -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