2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.DragDrop;
|
|
|
|
|
using Content.Shared.Interaction;
|
2022-07-16 13:51:52 +10:00
|
|
|
using Content.Shared.Standing;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2022-10-16 17:38:04 +11:00
|
|
|
using Robust.Shared.Map;
|
2020-06-25 15:52:24 +02:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Buckle.Components
|
2020-06-25 15:52:24 +02:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2021-10-24 23:43:49 -07:00
|
|
|
public abstract class SharedBuckleComponent : Component, IDraggable
|
2020-06-25 15:52:24 +02:00
|
|
|
{
|
2022-07-16 13:51:52 +10:00
|
|
|
[Dependency] protected readonly IEntityManager EntMan = default!;
|
|
|
|
|
|
2021-01-11 22:14:01 +11:00
|
|
|
/// <summary>
|
2021-02-12 13:04:19 +01:00
|
|
|
/// The range from which this entity can buckle to a <see cref="SharedStrapComponent"/>.
|
2021-01-11 22:14:01 +11:00
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("range")]
|
|
|
|
|
public float Range { get; protected set; } = SharedInteractionSystem.InteractionRange / 1.4f;
|
2021-01-11 22:14:01 +11:00
|
|
|
|
2020-07-17 10:43:10 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// True if the entity is buckled, false otherwise.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract bool Buckled { get; }
|
2021-02-12 13:04:19 +01:00
|
|
|
|
2020-12-18 20:12:53 +01:00
|
|
|
public EntityUid? LastEntityBuckledTo { get; set; }
|
2020-07-02 23:36:06 +02:00
|
|
|
|
2020-12-18 20:12:53 +01:00
|
|
|
public bool DontCollide { get; set; }
|
2020-10-14 15:24:07 +02:00
|
|
|
|
2021-12-03 11:15:41 -08:00
|
|
|
public abstract bool TryBuckle(EntityUid user, EntityUid to);
|
2020-12-18 20:12:53 +01:00
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
bool IDraggable.CanDrop(CanDropEvent args)
|
2020-10-14 15:24:07 +02:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
return IoCManager.Resolve<IEntityManager>().HasComponent<SharedStrapComponent>(args.Target);
|
2020-10-14 15:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
bool IDraggable.Drop(DragDropEvent args)
|
2020-10-14 15:24:07 +02:00
|
|
|
{
|
2020-10-17 19:53:52 +11:00
|
|
|
return TryBuckle(args.User, args.Target);
|
2020-10-14 15:24:07 +02:00
|
|
|
}
|
2022-07-16 13:51:52 +10:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reattaches this entity to the strap, modifying its position and rotation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="strap">The strap to reattach to.</param>
|
|
|
|
|
public void ReAttach(SharedStrapComponent strap)
|
|
|
|
|
{
|
|
|
|
|
var ownTransform = EntMan.GetComponent<TransformComponent>(Owner);
|
|
|
|
|
var strapTransform = EntMan.GetComponent<TransformComponent>(strap.Owner);
|
|
|
|
|
|
2022-10-16 17:38:04 +11:00
|
|
|
ownTransform.Coordinates = new EntityCoordinates(strapTransform.Owner, strap.BuckleOffset);
|
|
|
|
|
|
|
|
|
|
// Buckle subscribes to move for <reasons> so this might fail.
|
|
|
|
|
// TODO: Make buckle not do that.
|
|
|
|
|
if (ownTransform.ParentUid != strapTransform.Owner)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-16 13:51:52 +10:00
|
|
|
ownTransform.LocalRotation = Angle.Zero;
|
|
|
|
|
|
|
|
|
|
switch (strap.Position)
|
|
|
|
|
{
|
|
|
|
|
case StrapPosition.None:
|
|
|
|
|
break;
|
|
|
|
|
case StrapPosition.Stand:
|
|
|
|
|
EntitySystem.Get<StandingStateSystem>().Stand(Owner);
|
|
|
|
|
break;
|
|
|
|
|
case StrapPosition.Down:
|
|
|
|
|
EntitySystem.Get<StandingStateSystem>().Down(Owner, false, false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-17 10:43:10 +02:00
|
|
|
}
|
2020-07-02 23:36:06 +02:00
|
|
|
|
2020-07-17 10:43:10 +02:00
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class BuckleComponentState : ComponentState
|
|
|
|
|
{
|
2022-07-27 04:22:49 +12:00
|
|
|
public BuckleComponentState(bool buckled, EntityUid? lastEntityBuckledTo, bool dontCollide)
|
2020-07-02 23:36:06 +02:00
|
|
|
{
|
2020-07-17 10:43:10 +02:00
|
|
|
Buckled = buckled;
|
2020-12-18 20:12:53 +01:00
|
|
|
LastEntityBuckledTo = lastEntityBuckledTo;
|
|
|
|
|
DontCollide = dontCollide;
|
2020-07-02 23:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 10:43:10 +02:00
|
|
|
public bool Buckled { get; }
|
2020-12-18 20:12:53 +01:00
|
|
|
public EntityUid? LastEntityBuckledTo { get; }
|
|
|
|
|
public bool DontCollide { get; }
|
2020-07-17 10:43:10 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-15 20:04:33 -07:00
|
|
|
public sealed class BuckleChangeEvent : EntityEventArgs
|
2020-07-26 12:12:53 +02:00
|
|
|
{
|
2022-02-15 20:04:33 -07:00
|
|
|
public EntityUid Strap;
|
2022-04-15 18:53:52 -04:00
|
|
|
|
|
|
|
|
public EntityUid BuckledEntity;
|
2022-02-15 20:04:33 -07:00
|
|
|
public bool Buckling;
|
2020-07-26 12:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
2022-02-15 20:04:33 -07:00
|
|
|
public enum BuckleVisuals
|
2020-07-26 12:12:53 +02:00
|
|
|
{
|
2022-02-15 20:04:33 -07:00
|
|
|
Buckled
|
2020-07-26 12:12:53 +02:00
|
|
|
}
|
2020-06-25 15:52:24 +02:00
|
|
|
}
|