2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.DragDrop;
|
2022-02-17 15:40:03 +13:00
|
|
|
using Content.Shared.Interaction;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
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
|
|
|
{
|
|
|
|
|
public enum StrapPosition
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// (Default) Makes no change to the buckled mob
|
|
|
|
|
/// </summary>
|
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Makes the mob stand up
|
|
|
|
|
/// </summary>
|
|
|
|
|
Stand,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Makes the mob lie down
|
|
|
|
|
/// </summary>
|
|
|
|
|
Down
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2021-01-11 22:14:01 +11:00
|
|
|
public abstract class SharedStrapComponent : Component, IDragDropOn
|
2020-06-25 15:52:24 +02:00
|
|
|
{
|
2022-07-16 13:51:52 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// The change in position to the strapped mob
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("position")]
|
|
|
|
|
public StrapPosition Position { get; set; } = StrapPosition.None;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The entity that is currently buckled here, synced from <see cref="BuckleComponent.BuckledTo"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly HashSet<EntityUid> BuckledEntities = new();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The distance above which a buckled entity will be automatically unbuckled.
|
|
|
|
|
/// Don't change it unless you really have to
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("maxBuckleDistance", required: false)]
|
|
|
|
|
public float MaxBuckleDistance = 0.1f;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets and clamps the buckle offset to MaxBuckleDistance
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Vector2 BuckleOffset => Vector2.Clamp(
|
|
|
|
|
BuckleOffsetUnclamped,
|
|
|
|
|
Vector2.One * -MaxBuckleDistance,
|
|
|
|
|
Vector2.One * MaxBuckleDistance);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The buckled entity will be offset by this amount from the center of the strap object.
|
|
|
|
|
/// If this offset it too big, it will be clamped to <see cref="MaxBuckleDistance"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("buckleOffset", required: false)]
|
|
|
|
|
public Vector2 BuckleOffsetUnclamped = Vector2.Zero;
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
bool IDragDropOn.CanDragDropOn(DragDropEvent eventArgs)
|
2021-01-11 22:14:01 +11:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(eventArgs.Dragged, out SharedBuckleComponent? buckleComponent)) return false;
|
2021-12-04 12:47:09 +01:00
|
|
|
bool Ignored(EntityUid entity) => entity == eventArgs.User || entity == eventArgs.Dragged || entity == eventArgs.Target;
|
2021-01-11 22:14:01 +11:00
|
|
|
|
2022-02-17 15:40:03 +13:00
|
|
|
return EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(eventArgs.Target, eventArgs.Dragged, buckleComponent.Range, predicate: Ignored);
|
2021-01-11 22:14:01 +11:00
|
|
|
}
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
public abstract bool DragDropOn(DragDropEvent eventArgs);
|
2020-07-07 00:04:30 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-26 12:12:53 +02:00
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public sealed class StrapComponentState : ComponentState
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The change in position that this strap makes to the strapped mob
|
|
|
|
|
/// </summary>
|
2022-07-16 13:51:52 +10:00
|
|
|
public StrapPosition Position;
|
|
|
|
|
|
|
|
|
|
public float MaxBuckleDistance;
|
|
|
|
|
public Vector2 BuckleOffsetClamped;
|
|
|
|
|
public HashSet<EntityUid> BuckledEntities;
|
|
|
|
|
|
|
|
|
|
public StrapComponentState(StrapPosition position, Vector2 offset, HashSet<EntityUid> buckled, float maxBuckleDistance)
|
|
|
|
|
{
|
|
|
|
|
Position = position;
|
|
|
|
|
BuckleOffsetClamped = offset;
|
|
|
|
|
BuckledEntities = buckled;
|
|
|
|
|
MaxBuckleDistance = maxBuckleDistance;
|
|
|
|
|
}
|
2020-07-26 12:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-07 00:04:30 +02:00
|
|
|
[Serializable, NetSerializable]
|
2021-12-29 15:57:20 +11:00
|
|
|
public enum StrapVisuals : byte
|
2020-07-07 00:04:30 +02:00
|
|
|
{
|
2021-12-29 15:57:20 +11:00
|
|
|
RotationAngle,
|
2022-08-08 13:44:16 +12:00
|
|
|
BuckledState,
|
|
|
|
|
State
|
2020-06-25 15:52:24 +02:00
|
|
|
}
|
|
|
|
|
}
|