2023-07-08 14:08:32 +10:00
|
|
|
using System.Numerics;
|
2022-03-17 20:13:31 +13:00
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2021-08-20 10:21:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2023-09-28 16:20:29 -07:00
|
|
|
using Content.Shared.Storage.Components;
|
2021-08-20 10:21:39 +02:00
|
|
|
|
|
|
|
|
namespace Content.Shared.Placeable
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class PlaceableSurfaceSystem : EntitySystem
|
2021-08-20 10:21:39 +02:00
|
|
|
{
|
2022-03-17 20:13:31 +13:00
|
|
|
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
|
|
|
|
2021-08-20 10:21:39 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2022-02-05 15:39:01 +13:00
|
|
|
SubscribeLocalEvent<PlaceableSurfaceComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
2022-05-08 15:50:31 +10:00
|
|
|
}
|
|
|
|
|
|
2021-10-06 11:40:05 +02:00
|
|
|
public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceComponent? surface = null)
|
2021-08-20 10:21:39 +02:00
|
|
|
{
|
2023-02-26 07:44:30 -05:00
|
|
|
if (!Resolve(uid, ref surface, false))
|
2021-10-06 11:40:05 +02:00
|
|
|
return;
|
|
|
|
|
|
2021-08-20 10:21:39 +02:00
|
|
|
surface.IsPlaceable = isPlaceable;
|
2023-09-28 16:20:29 -07:00
|
|
|
Dirty(uid, surface);
|
2021-08-20 10:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-06 11:40:05 +02:00
|
|
|
public void SetPlaceCentered(EntityUid uid, bool placeCentered, PlaceableSurfaceComponent? surface = null)
|
2021-08-20 10:21:39 +02:00
|
|
|
{
|
2021-10-06 11:40:05 +02:00
|
|
|
if (!Resolve(uid, ref surface))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-08-20 10:21:39 +02:00
|
|
|
surface.PlaceCentered = placeCentered;
|
2023-09-28 16:20:29 -07:00
|
|
|
Dirty(uid, surface);
|
2021-08-20 10:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-06 11:40:05 +02:00
|
|
|
public void SetPositionOffset(EntityUid uid, Vector2 offset, PlaceableSurfaceComponent? surface = null)
|
2021-08-20 10:21:39 +02:00
|
|
|
{
|
2021-10-06 11:40:05 +02:00
|
|
|
if (!Resolve(uid, ref surface))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-08-20 10:21:39 +02:00
|
|
|
surface.PositionOffset = offset;
|
2023-09-28 16:20:29 -07:00
|
|
|
Dirty(uid, surface);
|
2021-08-20 10:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:39:01 +13:00
|
|
|
private void OnAfterInteractUsing(EntityUid uid, PlaceableSurfaceComponent surface, AfterInteractUsingEvent args)
|
2021-08-20 10:21:39 +02:00
|
|
|
{
|
2022-02-05 15:39:01 +13:00
|
|
|
if (args.Handled || !args.CanReach)
|
2021-08-20 10:21:39 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!surface.IsPlaceable)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-05-03 23:00:22 -04:00
|
|
|
// 99% of the time they want to dump the stuff inside on the table, they can manually place with q if they really need to.
|
|
|
|
|
// Just causes prediction CBT otherwise.
|
|
|
|
|
if (HasComp<DumpableComponent>(args.Used))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-03-17 20:13:31 +13:00
|
|
|
if (!_handsSystem.TryDrop(args.User, args.Used))
|
2021-08-20 10:21:39 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (surface.PlaceCentered)
|
2023-09-01 12:30:29 +10:00
|
|
|
Transform(args.Used).LocalPosition = Transform(uid).LocalPosition + surface.PositionOffset;
|
2021-08-20 10:21:39 +02:00
|
|
|
else
|
2023-09-01 12:30:29 +10:00
|
|
|
Transform(args.Used).Coordinates = args.ClickLocation;
|
2021-08-20 10:21:39 +02:00
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|