2020-09-08 13:30:22 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2020-08-18 14:39:08 +02:00
|
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-07-25 15:11:16 +02:00
|
|
|
|
using Content.Shared.GameObjects.Components;
|
2020-07-18 22:51:56 -07:00
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2019-04-25 22:22:51 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2019-04-17 23:26:00 +02:00
|
|
|
|
using Robust.Shared.Serialization;
|
2020-09-08 13:30:22 +02:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2019-04-17 23:26:00 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components
|
|
|
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
|
[RegisterComponent]
|
2020-10-14 15:24:07 +02:00
|
|
|
|
[ComponentReference(typeof(SharedPlaceableSurfaceComponent))]
|
2020-07-06 14:27:03 -07:00
|
|
|
|
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent, IInteractUsing
|
2019-04-17 23:26:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
private bool _isPlaceable;
|
2020-10-14 15:24:07 +02:00
|
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2020-10-14 15:24:07 +02:00
|
|
|
|
public override bool IsPlaceable
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _isPlaceable;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isPlaceable == value)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_isPlaceable = value;
|
|
|
|
|
|
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables]
|
2020-08-16 14:58:36 +02:00
|
|
|
|
int IInteractUsing.Priority => 1;
|
2020-08-13 20:14:07 +02:00
|
|
|
|
|
2019-04-17 23:26:00 +02:00
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ExposeData(serializer);
|
|
|
|
|
|
|
|
|
|
|
|
serializer.DataField(ref _isPlaceable, "IsPlaceable", true);
|
|
|
|
|
|
}
|
2020-07-25 15:11:16 +02:00
|
|
|
|
|
2020-10-14 15:24:07 +02:00
|
|
|
|
public override ComponentState GetComponentState()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new PlaceableSurfaceComponentState(_isPlaceable);
|
|
|
|
|
|
}
|
2020-08-18 14:39:08 +02:00
|
|
|
|
|
|
|
|
|
|
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
2019-04-25 22:22:51 +01:00
|
|
|
|
{
|
2020-02-09 06:42:12 -03:00
|
|
|
|
if (!IsPlaceable)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2019-04-25 22:22:51 +01:00
|
|
|
|
if(!eventArgs.User.TryGetComponent<HandsComponent>(out var handComponent))
|
|
|
|
|
|
{
|
2020-02-09 06:42:12 -03:00
|
|
|
|
return false;
|
2019-04-25 22:22:51 +01:00
|
|
|
|
}
|
2020-05-23 17:23:25 +02:00
|
|
|
|
handComponent.Drop(eventArgs.Using);
|
|
|
|
|
|
eventArgs.Using.Transform.WorldPosition = eventArgs.ClickLocation.Position;
|
2019-04-25 22:22:51 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|