Files
tbd-station-14/Content.Shared/Buckle/Components/BuckleComponent.cs
metalgearsloth 8f06155028 Make buckle mint (#32370)
- Fix the unbuckle mispredicts.
- Fix unbuckle offset existing.
- Fix interaction range not aligning with interactionoutline system.
2024-09-22 18:21:40 +10:00

158 lines
4.6 KiB
C#

using System.Diagnostics.CodeAnalysis;
using Content.Shared.Alert;
using Content.Shared.Interaction;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Buckle.Components;
/// <summary>
/// This component allows an entity to be buckled to an entity with a <see cref="StrapComponent"/>.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
[Access(typeof(SharedBuckleSystem))]
public sealed partial class BuckleComponent : Component
{
/// <summary>
/// The range from which this entity can buckle to a <see cref="StrapComponent"/>.
/// Separated from normal interaction range to fix the "someone buckled to a strap
/// across a table two tiles away" problem.
/// </summary>
[DataField]
public float Range = SharedInteractionSystem.InteractionRange;
/// <summary>
/// True if the entity is buckled, false otherwise.
/// </summary>
[MemberNotNullWhen(true, nameof(BuckledTo))]
public bool Buckled => BuckledTo != null;
/// <summary>
/// Whether or not collisions should be possible with the entity we are strapped to
/// </summary>
[DataField, AutoNetworkedField]
public bool DontCollide;
/// <summary>
/// Whether or not we should be allowed to pull the entity we are strapped to
/// </summary>
[DataField]
public bool PullStrap;
/// <summary>
/// The amount of time that must pass for this entity to
/// be able to unbuckle after recently buckling.
/// </summary>
[DataField]
public TimeSpan Delay = TimeSpan.FromSeconds(0.25f);
/// <summary>
/// The time that this entity buckled at.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField, AutoNetworkedField]
public TimeSpan? BuckleTime;
/// <summary>
/// The strap that this component is buckled to.
/// </summary>
[DataField, AutoNetworkedField]
public EntityUid? BuckledTo;
/// <summary>
/// The amount of space that this entity occupies in a
/// <see cref="StrapComponent"/>.
/// </summary>
[DataField]
public int Size = 100;
/// <summary>
/// Used for client rendering
/// </summary>
[ViewVariables] public int? OriginalDrawDepth;
}
public sealed partial class UnbuckleAlertEvent : BaseAlertEvent;
/// <summary>
/// Event raised directed at a strap entity before some entity gets buckled to it.
/// </summary>
[ByRefEvent]
public record struct StrapAttemptEvent(
Entity<StrapComponent> Strap,
Entity<BuckleComponent> Buckle,
EntityUid? User,
bool Popup)
{
public bool Cancelled;
}
/// <summary>
/// Event raised directed at a buckle entity before it gets buckled to some strap entity.
/// </summary>
[ByRefEvent]
public record struct BuckleAttemptEvent(
Entity<StrapComponent> Strap,
Entity<BuckleComponent> Buckle,
EntityUid? User,
bool Popup)
{
public bool Cancelled;
}
/// <summary>
/// Event raised directed at a strap entity before some entity gets unbuckled from it.
/// </summary>
[ByRefEvent]
public record struct UnstrapAttemptEvent(
Entity<StrapComponent> Strap,
Entity<BuckleComponent> Buckle,
EntityUid? User,
bool Popup)
{
public bool Cancelled;
}
/// <summary>
/// Event raised directed at a buckle entity before it gets unbuckled.
/// </summary>
[ByRefEvent]
public record struct UnbuckleAttemptEvent(
Entity<StrapComponent> Strap,
Entity<BuckleComponent> Buckle,
EntityUid? User,
bool Popup)
{
public bool Cancelled;
}
/// <summary>
/// Event raised directed at a strap entity after something has been buckled to it.
/// </summary>
[ByRefEvent]
public readonly record struct StrappedEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
/// <summary>
/// Event raised directed at a buckle entity after it has been buckled.
/// </summary>
[ByRefEvent]
public readonly record struct BuckledEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
/// <summary>
/// Event raised directed at a strap entity after something has been unbuckled from it.
/// </summary>
[ByRefEvent]
public readonly record struct UnstrappedEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
/// <summary>
/// Event raised directed at a buckle entity after it has been unbuckled from some strap entity.
/// </summary>
[ByRefEvent]
public readonly record struct UnbuckledEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
[Serializable, NetSerializable]
public enum BuckleVisuals
{
Buckled
}