using System.Numerics;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
+using Content.Shared.Storage;
using Content.Shared.Storage.Components;
namespace Content.Shared.Placeable;
public sealed class PlaceableSurfaceSystem : EntitySystem
{
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
+ [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlaceableSurfaceComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
+ SubscribeLocalEvent<PlaceableSurfaceComponent, StorageInteractUsingAttemptEvent>(OnStorageInteractUsingAttempt);
+ SubscribeLocalEvent<PlaceableSurfaceComponent, StorageAfterOpenEvent>(OnStorageAfterOpen);
+ SubscribeLocalEvent<PlaceableSurfaceComponent, StorageAfterCloseEvent>(OnStorageAfterClose);
}
public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceComponent? surface = null)
if (!Resolve(uid, ref surface, false))
return;
+ if (surface.IsPlaceable == isPlaceable)
+ return;
+
surface.IsPlaceable = isPlaceable;
Dirty(uid, surface);
}
if (!_handsSystem.TryDrop(args.User, args.Used))
return;
- if (surface.PlaceCentered)
- Transform(args.Used).LocalPosition = Transform(uid).LocalPosition + surface.PositionOffset;
- else
- Transform(args.Used).Coordinates = args.ClickLocation;
+ _transformSystem.SetCoordinates(args.Used,
+ surface.PlaceCentered ? Transform(uid).Coordinates.Offset(surface.PositionOffset) : args.ClickLocation);
args.Handled = true;
}
+
+ private void OnStorageInteractUsingAttempt(Entity<PlaceableSurfaceComponent> ent, ref StorageInteractUsingAttemptEvent args)
+ {
+ args.Cancelled = true;
+ }
+
+ private void OnStorageAfterOpen(Entity<PlaceableSurfaceComponent> ent, ref StorageAfterOpenEvent args)
+ {
+ SetPlaceable(ent.Owner, true, ent.Comp);
+ }
+
+ private void OnStorageAfterClose(Entity<PlaceableSurfaceComponent> ent, ref StorageAfterCloseEvent args)
+ {
+ SetPlaceable(ent.Owner, false, ent.Comp);
+ }
}
if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert, false))
return;
- if (HasComp<PlaceableSurfaceComponent>(uid))
+ var attemptEv = new StorageInteractUsingAttemptEvent();
+ RaiseLocalEvent(uid, ref attemptEv);
+ if (attemptEv.Cancelled)
return;
PlayerInsertHeldEntity((uid, storageComp), args.User);