Prevent certain foldable items from being unfolded on structures (#36687)
initial commit
This commit is contained in:
@@ -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")),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user