From 042feae2e91f41f7d39e55340405e3c448903d61 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 4 Feb 2024 13:23:16 +1100 Subject: [PATCH] Predicted movement opening lockers (#24937) Relay wasn't really networked properly and this annoys me. EntityStorage is still pretty skrunkly but this fixes the main issue I think. --- .../Storage/Systems/EntityStorageSystem.cs | 1 + .../EntitySystems/EntityStorageSystem.cs | 1 + .../Components/SharedEntityStorageComponent.cs | 7 +++++-- .../EntitySystems/SharedEntityStorageSystem.cs | 17 +++++++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Content.Client/Storage/Systems/EntityStorageSystem.cs b/Content.Client/Storage/Systems/EntityStorageSystem.cs index 6d37beb0781773..dd3f8d386052c8 100644 --- a/Content.Client/Storage/Systems/EntityStorageSystem.cs +++ b/Content.Client/Storage/Systems/EntityStorageSystem.cs @@ -17,6 +17,7 @@ public sealed class EntityStorageSystem : SharedEntityStorageSystem public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnEntityUnpausedEvent); SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnComponentStartup); SubscribeLocalEvent(OnInteract, after: new[] { typeof(LockSystem) }); diff --git a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs index 176fd9b9ed21a7..8b31f598d0de40 100644 --- a/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/EntityStorageSystem.cs @@ -33,6 +33,7 @@ public override void Initialize() base.Initialize(); /* CompRef things */ + SubscribeLocalEvent(OnEntityUnpausedEvent); SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnComponentStartup); SubscribeLocalEvent(OnInteract, after: new[] { typeof(LockSystem) }); diff --git a/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs b/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs index b4cd18f4d5c62c..b02c97db711eab 100644 --- a/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs +++ b/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs @@ -14,7 +14,7 @@ public abstract partial class SharedEntityStorageComponent : Component public readonly float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage. public static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5); - public TimeSpan LastInternalOpenAttempt; + public TimeSpan NextInternalOpenAttempt; /// /// Collision masks that get removed when the storage gets opened. @@ -139,13 +139,16 @@ public sealed class EntityStorageComponentState : ComponentState public float EnteringRange; - public EntityStorageComponentState(bool open, int capacity, bool isCollidableWhenOpen, bool openOnMove, float enteringRange) + public TimeSpan NextInternalOpenAttempt; + + public EntityStorageComponentState(bool open, int capacity, bool isCollidableWhenOpen, bool openOnMove, float enteringRange, TimeSpan nextInternalOpenAttempt) { Open = open; Capacity = capacity; IsCollidableWhenOpen = isCollidableWhenOpen; OpenOnMove = openOnMove; EnteringRange = enteringRange; + NextInternalOpenAttempt = nextInternalOpenAttempt; } } diff --git a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs index 8f8707ccde8892..636c6038348097 100644 --- a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs @@ -48,13 +48,19 @@ public abstract class SharedEntityStorageSystem : EntitySystem public const string ContainerName = "entity_storage"; + protected void OnEntityUnpausedEvent(EntityUid uid, SharedEntityStorageComponent component, EntityUnpausedEvent args) + { + component.NextInternalOpenAttempt += args.PausedTime; + } + protected void OnGetState(EntityUid uid, SharedEntityStorageComponent component, ref ComponentGetState args) { args.State = new EntityStorageComponentState(component.Open, component.Capacity, component.IsCollidableWhenOpen, component.OpenOnMove, - component.EnteringRange); + component.EnteringRange, + component.NextInternalOpenAttempt); } protected void OnHandleState(EntityUid uid, SharedEntityStorageComponent component, ref ComponentHandleState args) @@ -66,6 +72,7 @@ protected void OnHandleState(EntityUid uid, SharedEntityStorageComponent compone component.IsCollidableWhenOpen = state.IsCollidableWhenOpen; component.OpenOnMove = state.OpenOnMove; component.EnteringRange = state.EnteringRange; + component.NextInternalOpenAttempt = state.NextInternalOpenAttempt; } protected virtual void OnComponentInit(EntityUid uid, SharedEntityStorageComponent component, ComponentInit args) @@ -123,10 +130,12 @@ protected void OnRelayMovement(EntityUid uid, SharedEntityStorageComponent compo if (!HasComp(args.Entity)) return; - if (_timing.CurTime < component.LastInternalOpenAttempt + SharedEntityStorageComponent.InternalOpenAttemptDelay) + if (_timing.CurTime < component.NextInternalOpenAttempt) return; - component.LastInternalOpenAttempt = _timing.CurTime; + component.NextInternalOpenAttempt = _timing.CurTime + SharedEntityStorageComponent.InternalOpenAttemptDelay; + Dirty(uid, component); + if (component.OpenOnMove) { TryOpenStorage(args.Entity, uid); @@ -259,7 +268,7 @@ public void CloseStorage(EntityUid uid, SharedEntityStorageComponent? component ModifyComponents(uid, component); if (_net.IsClient && _timing.IsFirstTimePredicted) _audio.PlayPvs(component.CloseSound, uid); - component.LastInternalOpenAttempt = default; + var afterev = new StorageAfterCloseEvent(); RaiseLocalEvent(uid, ref afterev); }