remove a bunch of instances of component reference (#13164)
This commit is contained in:
@@ -4,15 +4,14 @@ using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Buckle.Components;
|
||||
|
||||
[NetworkedComponent]
|
||||
[Access(typeof(SharedBuckleSystem))]
|
||||
public abstract class SharedBuckleComponent : Component
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class BuckleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The range from which this entity can buckle to a <see cref="SharedStrapComponent"/>.
|
||||
/// The range from which this entity can buckle to a <see cref="StrapComponent"/>.
|
||||
/// </summary>
|
||||
[DataField("range")]
|
||||
public float Range { get; protected set; } = SharedInteractionSystem.InteractionRange / 1.4f;
|
||||
public float Range = SharedInteractionSystem.InteractionRange / 1.4f;
|
||||
|
||||
/// <summary>
|
||||
/// True if the entity is buckled, false otherwise.
|
||||
@@ -22,6 +21,36 @@ public abstract class SharedBuckleComponent : Component
|
||||
public EntityUid? LastEntityBuckledTo { get; set; }
|
||||
|
||||
public bool DontCollide { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time that must pass for this entity to
|
||||
/// be able to unbuckle after recently buckling.
|
||||
/// </summary>
|
||||
[DataField("delay")]
|
||||
public TimeSpan UnbuckleDelay = TimeSpan.FromSeconds(0.25f);
|
||||
|
||||
/// <summary>
|
||||
/// The time that this entity buckled at.
|
||||
/// </summary>
|
||||
[ViewVariables] public TimeSpan BuckleTime;
|
||||
|
||||
/// <summary>
|
||||
/// The strap that this component is buckled to.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public StrapComponent? BuckledTo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of space that this entity occupies in a
|
||||
/// <see cref="StrapComponent"/>.
|
||||
/// </summary>
|
||||
[DataField("size")]
|
||||
public int Size = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Used for client rendering
|
||||
/// </summary>
|
||||
public int? OriginalDrawDepth { get; set; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
@@ -1,3 +1,5 @@
|
||||
using Content.Shared.Alert;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -21,9 +23,8 @@ public enum StrapPosition
|
||||
Down
|
||||
}
|
||||
|
||||
[NetworkedComponent]
|
||||
[Access(typeof(SharedBuckleSystem))]
|
||||
public abstract class SharedStrapComponent : Component
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class StrapComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The change in position to the strapped mob
|
||||
@@ -58,6 +59,52 @@ public abstract class SharedStrapComponent : Component
|
||||
[DataField("buckleOffset", required: false)]
|
||||
[Access(Other = AccessPermissions.ReadWrite)]
|
||||
public Vector2 BuckleOffsetUnclamped = Vector2.Zero;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The angle in degrees to rotate the player by when they get strapped
|
||||
/// </summary>
|
||||
[DataField("rotation")]
|
||||
public int Rotation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The size of the strap which is compared against when buckling entities
|
||||
/// </summary>
|
||||
[DataField("size")]
|
||||
public int Size { get; set; } = 100;
|
||||
|
||||
/// <summary>
|
||||
/// If disabled, nothing can be buckled on this object, and it will unbuckle anything that's already buckled
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// You can specify the offset the entity will have after unbuckling.
|
||||
/// </summary>
|
||||
[DataField("unbuckleOffset", required: false)]
|
||||
public Vector2 UnbuckleOffset = Vector2.Zero;
|
||||
/// <summary>
|
||||
/// The sound to be played when a mob is buckled
|
||||
/// </summary>
|
||||
[DataField("buckleSound")]
|
||||
public SoundSpecifier BuckleSound { get; } = new SoundPathSpecifier("/Audio/Effects/buckle.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when a mob is unbuckled
|
||||
/// </summary>
|
||||
[DataField("unbuckleSound")]
|
||||
public SoundSpecifier UnbuckleSound { get; } = new SoundPathSpecifier("/Audio/Effects/unbuckle.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// ID of the alert to show when buckled
|
||||
/// </summary>
|
||||
[DataField("buckledAlertType")]
|
||||
public AlertType BuckledAlertType { get; } = AlertType.Buckled;
|
||||
|
||||
/// <summary>
|
||||
/// The sum of the sizes of all the buckled entities in this strap
|
||||
/// </summary>
|
||||
public int OccupiedSize { get; set; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
@@ -13,15 +13,15 @@ public abstract partial class SharedBuckleSystem
|
||||
{
|
||||
private void InitializeBuckle()
|
||||
{
|
||||
SubscribeLocalEvent<SharedBuckleComponent, PreventCollideEvent>(PreventCollision);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, DownAttemptEvent>(HandleDown);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, StandAttemptEvent>(HandleStand);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, ThrowPushbackAttemptEvent>(HandleThrowPushback);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, UpdateCanMoveEvent>(HandleMove);
|
||||
SubscribeLocalEvent<SharedBuckleComponent, ChangeDirectionAttemptEvent>(OnBuckleChangeDirectionAttempt);
|
||||
SubscribeLocalEvent<BuckleComponent, PreventCollideEvent>(PreventCollision);
|
||||
SubscribeLocalEvent<BuckleComponent, DownAttemptEvent>(HandleDown);
|
||||
SubscribeLocalEvent<BuckleComponent, StandAttemptEvent>(HandleStand);
|
||||
SubscribeLocalEvent<BuckleComponent, ThrowPushbackAttemptEvent>(HandleThrowPushback);
|
||||
SubscribeLocalEvent<BuckleComponent, UpdateCanMoveEvent>(HandleMove);
|
||||
SubscribeLocalEvent<BuckleComponent, ChangeDirectionAttemptEvent>(OnBuckleChangeDirectionAttempt);
|
||||
}
|
||||
|
||||
private void PreventCollision(EntityUid uid, SharedBuckleComponent component, ref PreventCollideEvent args)
|
||||
private void PreventCollision(EntityUid uid, BuckleComponent component, ref PreventCollideEvent args)
|
||||
{
|
||||
if (args.BodyB.Owner != component.LastEntityBuckledTo)
|
||||
return;
|
||||
@@ -30,25 +30,25 @@ public abstract partial class SharedBuckleSystem
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void HandleDown(EntityUid uid, SharedBuckleComponent component, DownAttemptEvent args)
|
||||
private void HandleDown(EntityUid uid, BuckleComponent component, DownAttemptEvent args)
|
||||
{
|
||||
if (component.Buckled)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void HandleStand(EntityUid uid, SharedBuckleComponent component, StandAttemptEvent args)
|
||||
private void HandleStand(EntityUid uid, BuckleComponent component, StandAttemptEvent args)
|
||||
{
|
||||
if (component.Buckled)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void HandleThrowPushback(EntityUid uid, SharedBuckleComponent component, ThrowPushbackAttemptEvent args)
|
||||
private void HandleThrowPushback(EntityUid uid, BuckleComponent component, ThrowPushbackAttemptEvent args)
|
||||
{
|
||||
if (component.Buckled)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void HandleMove(EntityUid uid, SharedBuckleComponent component, UpdateCanMoveEvent args)
|
||||
private void HandleMove(EntityUid uid, BuckleComponent component, UpdateCanMoveEvent args)
|
||||
{
|
||||
if (component.LifeStage > ComponentLifeStage.Running)
|
||||
return;
|
||||
@@ -58,13 +58,13 @@ public abstract partial class SharedBuckleSystem
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void OnBuckleChangeDirectionAttempt(EntityUid uid, SharedBuckleComponent component, ChangeDirectionAttemptEvent args)
|
||||
private void OnBuckleChangeDirectionAttempt(EntityUid uid, BuckleComponent component, ChangeDirectionAttemptEvent args)
|
||||
{
|
||||
if (component.Buckled)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
public bool IsBuckled(EntityUid uid, SharedBuckleComponent? component = null)
|
||||
public bool IsBuckled(EntityUid uid, BuckleComponent? component = null)
|
||||
{
|
||||
return Resolve(uid, ref component, false) && component.Buckled;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public abstract partial class SharedBuckleSystem
|
||||
/// <param name="buckleId">The entity to reattach.</param>
|
||||
/// <param name="strap">The strap to reattach to.</param>
|
||||
/// <param name="buckle">The buckle component of the entity to reattach.</param>
|
||||
public void ReAttach(EntityUid buckleId, SharedStrapComponent strap, SharedBuckleComponent? buckle = null)
|
||||
public void ReAttach(EntityUid buckleId, StrapComponent strap, BuckleComponent? buckle = null)
|
||||
{
|
||||
if (!Resolve(buckleId, ref buckle, false))
|
||||
return;
|
||||
|
||||
@@ -11,12 +11,12 @@ public abstract partial class SharedBuckleSystem
|
||||
|
||||
private void InitializeStrap()
|
||||
{
|
||||
SubscribeLocalEvent<SharedStrapComponent, MoveEvent>(OnStrapRotate);
|
||||
SubscribeLocalEvent<SharedStrapComponent, ComponentHandleState>(OnStrapHandleState);
|
||||
SubscribeLocalEvent<SharedStrapComponent, CanDragDropOnEvent>(OnStrapCanDragDropOn);
|
||||
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapRotate);
|
||||
SubscribeLocalEvent<StrapComponent, ComponentHandleState>(OnStrapHandleState);
|
||||
SubscribeLocalEvent<StrapComponent, CanDragDropOnEvent>(OnStrapCanDragDropOn);
|
||||
}
|
||||
|
||||
private void OnStrapHandleState(EntityUid uid, SharedStrapComponent component, ref ComponentHandleState args)
|
||||
private void OnStrapHandleState(EntityUid uid, StrapComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not StrapComponentState state)
|
||||
return;
|
||||
@@ -28,7 +28,7 @@ public abstract partial class SharedBuckleSystem
|
||||
component.MaxBuckleDistance = state.MaxBuckleDistance;
|
||||
}
|
||||
|
||||
private void OnStrapRotate(EntityUid uid, SharedStrapComponent component, ref MoveEvent args)
|
||||
private void OnStrapRotate(EntityUid uid, StrapComponent component, ref MoveEvent args)
|
||||
{
|
||||
// TODO: This looks dirty af.
|
||||
// On rotation of a strap, reattach all buckled entities.
|
||||
@@ -50,7 +50,7 @@ public abstract partial class SharedBuckleSystem
|
||||
|
||||
foreach (var buckledEntity in component.BuckledEntities)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(buckledEntity, out SharedBuckleComponent? buckled))
|
||||
if (!EntityManager.TryGetComponent(buckledEntity, out BuckleComponent? buckled))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -71,8 +71,8 @@ public abstract partial class SharedBuckleSystem
|
||||
EntityUid user,
|
||||
EntityUid target,
|
||||
EntityUid buckleId,
|
||||
SharedStrapComponent? strap = null,
|
||||
SharedBuckleComponent? buckle = null)
|
||||
StrapComponent? strap = null,
|
||||
BuckleComponent? buckle = null)
|
||||
{
|
||||
if (!Resolve(strapId, ref strap, false) ||
|
||||
!Resolve(buckleId, ref buckle, false))
|
||||
@@ -85,7 +85,7 @@ public abstract partial class SharedBuckleSystem
|
||||
return _interactions.InRangeUnobstructed(target, buckleId, buckle.Range, predicate: Ignored);
|
||||
}
|
||||
|
||||
private void OnStrapCanDragDropOn(EntityUid uid, SharedStrapComponent strap, CanDragDropOnEvent args)
|
||||
private void OnStrapCanDragDropOn(EntityUid uid, StrapComponent strap, CanDragDropOnEvent args)
|
||||
{
|
||||
args.CanDrop = StrapCanDragDropOn(args.Target, args.User, args.Target, args.Dragged, strap);
|
||||
args.Handled = true;
|
||||
|
||||
Reference in New Issue
Block a user