From 52cc6c9d4b0e99cbe38718279b2d2347cd6d1100 Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Sun, 22 Sep 2024 16:46:22 +1000 Subject: [PATCH] Make buckle mint - Fix the unbuckle mispredicts. - Fix unbuckle offset existing. - Fix interaction range not aligning with interactionoutline system. --- Content.Client/Buckle/BuckleSystem.cs | 16 ------------- .../Buckle/Components/BuckleComponent.cs | 18 ++++----------- .../Buckle/Components/StrapComponent.cs | 8 +------ .../Buckle/SharedBuckleSystem.Buckle.cs | 23 ++++++++++--------- .../Structures/Furniture/rollerbeds.yml | 1 - 5 files changed, 18 insertions(+), 48 deletions(-) diff --git a/Content.Client/Buckle/BuckleSystem.cs b/Content.Client/Buckle/BuckleSystem.cs index 6770899e0aa293..035e1300ca5394 100644 --- a/Content.Client/Buckle/BuckleSystem.cs +++ b/Content.Client/Buckle/BuckleSystem.cs @@ -15,7 +15,6 @@ public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnHandleState); SubscribeLocalEvent(OnAppearanceChange); SubscribeLocalEvent(OnStrapMoveEvent); } @@ -57,21 +56,6 @@ private void OnStrapMoveEvent(EntityUid uid, StrapComponent component, ref MoveE } } - private void OnHandleState(Entity ent, ref ComponentHandleState args) - { - if (args.Current is not BuckleState state) - return; - - ent.Comp.DontCollide = state.DontCollide; - ent.Comp.BuckleTime = state.BuckleTime; - var strapUid = EnsureEntity(state.BuckledTo, ent); - - SetBuckledTo(ent, strapUid == null ? null : new (strapUid.Value, null)); - - var (uid, component) = ent; - - } - private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args) { if (!TryComp(uid, out var rotVisuals)) diff --git a/Content.Shared/Buckle/Components/BuckleComponent.cs b/Content.Shared/Buckle/Components/BuckleComponent.cs index c4810e8af085bc..1518ccea9ba8f2 100644 --- a/Content.Shared/Buckle/Components/BuckleComponent.cs +++ b/Content.Shared/Buckle/Components/BuckleComponent.cs @@ -10,7 +10,7 @@ namespace Content.Shared.Buckle.Components; /// /// This component allows an entity to be buckled to an entity with a . /// -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause] [Access(typeof(SharedBuckleSystem))] public sealed partial class BuckleComponent : Component { @@ -20,7 +20,7 @@ public sealed partial class BuckleComponent : Component /// across a table two tiles away" problem. /// [DataField] - public float Range = SharedInteractionSystem.InteractionRange / 1.4f; + public float Range = SharedInteractionSystem.InteractionRange; /// /// True if the entity is buckled, false otherwise. @@ -31,7 +31,7 @@ public sealed partial class BuckleComponent : Component /// /// Whether or not collisions should be possible with the entity we are strapped to /// - [DataField] + [DataField, AutoNetworkedField] public bool DontCollide; /// @@ -50,13 +50,13 @@ public sealed partial class BuckleComponent : Component /// /// The time that this entity buckled at. /// - [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))] + [DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField, AutoNetworkedField] public TimeSpan? BuckleTime; /// /// The strap that this component is buckled to. /// - [DataField] + [DataField, AutoNetworkedField] public EntityUid? BuckledTo; /// @@ -72,14 +72,6 @@ public sealed partial class BuckleComponent : Component [ViewVariables] public int? OriginalDrawDepth; } -[Serializable, NetSerializable] -public sealed class BuckleState(NetEntity? buckledTo, bool dontCollide, TimeSpan? buckleTime) : ComponentState -{ - public readonly NetEntity? BuckledTo = buckledTo; - public readonly bool DontCollide = dontCollide; - public readonly TimeSpan? BuckleTime = buckleTime; -} - public sealed partial class UnbuckleAlertEvent : BaseAlertEvent; /// diff --git a/Content.Shared/Buckle/Components/StrapComponent.cs b/Content.Shared/Buckle/Components/StrapComponent.cs index 101c388a8bfcf8..ad5031356e5e4a 100644 --- a/Content.Shared/Buckle/Components/StrapComponent.cs +++ b/Content.Shared/Buckle/Components/StrapComponent.cs @@ -15,7 +15,7 @@ public sealed partial class StrapComponent : Component /// /// The entities that are currently buckled to this strap. /// - [ViewVariables] + [DataField, AutoNetworkedField] public HashSet BuckledEntities = new(); /// @@ -61,12 +61,6 @@ public sealed partial class StrapComponent : Component [DataField, AutoNetworkedField] public bool Enabled = true; - /// - /// You can specify the offset the entity will have after unbuckling. - /// - [DataField] - public Vector2 UnbuckleOffset = Vector2.Zero; - /// /// The sound to be played when a mob is buckled /// diff --git a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs index 7f6c39eafc0679..6d49602c84aa06 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs @@ -58,13 +58,6 @@ private void InitializeBuckle() { BuckleDoafterEarly((uid, comp), ev.Event, ev); }); - - SubscribeLocalEvent(OnGetState); - } - - private void OnGetState(Entity ent, ref ComponentGetState args) - { - args.State = new BuckleState(GetNetEntity(ent.Comp.BuckledTo), ent.Comp.DontCollide, ent.Comp.BuckleTime); } private void OnBuckleComponentShutdown(Entity ent, ref ComponentShutdown args) @@ -196,11 +189,15 @@ public bool IsBuckled(EntityUid uid, BuckleComponent? component = null) protected void SetBuckledTo(Entity buckle, Entity? strap) { if (TryComp(buckle.Comp.BuckledTo, out StrapComponent? old)) + { old.BuckledEntities.Remove(buckle); + Dirty(buckle.Comp.BuckledTo.Value, old); + } if (strap is {} strapEnt && Resolve(strapEnt.Owner, ref strapEnt.Comp)) { strapEnt.Comp.BuckledEntities.Add(buckle); + Dirty(strapEnt); _alerts.ShowAlert(buckle, strapEnt.Comp.BuckledAlertType); } else @@ -463,13 +460,17 @@ private void Unbuckle(Entity buckle, Entity str if (buckleXform.ParentUid == strap.Owner && !Terminating(buckleXform.ParentUid)) { - _container.AttachParentToContainerOrGrid((buckle, buckleXform)); + _transform.PlaceNextTo((buckle, buckleXform), (strap.Owner, oldBuckledXform)); + buckleXform.ActivelyLerping = false; var oldBuckledToWorldRot = _transform.GetWorldRotation(strap); - _transform.SetWorldRotation(buckleXform, oldBuckledToWorldRot); + _transform.SetWorldRotationNoLerp((buckle, buckleXform), oldBuckledToWorldRot); - if (strap.Comp.UnbuckleOffset != Vector2.Zero) - buckleXform.Coordinates = oldBuckledXform.Coordinates.Offset(strap.Comp.UnbuckleOffset); + // TODO: This is doing 4 moveevents this is why I left the warning in, if you're going to remove it make it only do 1 moveevent. + if (strap.Comp.BuckleOffset != Vector2.Zero) + { + buckleXform.Coordinates = oldBuckledXform.Coordinates.Offset(strap.Comp.BuckleOffset); + } } _rotationVisuals.ResetHorizontalAngle(buckle.Owner); diff --git a/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml b/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml index 965c8261cceb44..9f3fbd7c455b56 100644 --- a/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml +++ b/Resources/Prototypes/Entities/Structures/Furniture/rollerbeds.yml @@ -54,7 +54,6 @@ position: Down rotation: -90 buckleOffset: "0,0.15" - unbuckleOffset: "0,0.15" buckleOnInteractHand: False - type: Appearance - type: GenericVisualizer