From ce09327c73f2283fec0073defb5a93132bd1a3ee Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Sun, 24 Nov 2024 19:56:34 +0100 Subject: [PATCH] fix door auto close timer --- Content.Shared/Doors/Components/DoorComponent.cs | 2 +- Content.Shared/Doors/DoorEvents.cs | 13 +++++++++++++ Content.Shared/Doors/Systems/SharedAirlockSystem.cs | 10 +++++++++- .../Doors/Systems/SharedDoorSystem.Bolts.cs | 4 ++++ Content.Shared/Doors/Systems/SharedDoorSystem.cs | 2 ++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Doors/Components/DoorComponent.cs b/Content.Shared/Doors/Components/DoorComponent.cs index 21fad142b3a2..5e35045b109e 100644 --- a/Content.Shared/Doors/Components/DoorComponent.cs +++ b/Content.Shared/Doors/Components/DoorComponent.cs @@ -66,7 +66,7 @@ public sealed partial class DoorComponent : Component /// /// When the door is active, this is the time when the state will next update. /// - [AutoNetworkedField] + [AutoNetworkedField, ViewVariables] public TimeSpan? NextStateChange; /// diff --git a/Content.Shared/Doors/DoorEvents.cs b/Content.Shared/Doors/DoorEvents.cs index 08a2c8b18b10..849ea837303a 100644 --- a/Content.Shared/Doors/DoorEvents.cs +++ b/Content.Shared/Doors/DoorEvents.cs @@ -15,6 +15,19 @@ public DoorStateChangedEvent(DoorState state) } } + /// + /// Raised when the door's bolt status was changed. + /// + public sealed class DoorBoltsChangedEvent : EntityEventArgs + { + public readonly bool BoltsDown; + + public DoorBoltsChangedEvent(bool boltsDown) + { + BoltsDown = boltsDown; + } + } + /// /// Raised when the door is determining whether it is able to open. /// Cancel to stop the door from being opened. diff --git a/Content.Shared/Doors/Systems/SharedAirlockSystem.cs b/Content.Shared/Doors/Systems/SharedAirlockSystem.cs index e404a91bdd74..bdd119004e84 100644 --- a/Content.Shared/Doors/Systems/SharedAirlockSystem.cs +++ b/Content.Shared/Doors/Systems/SharedAirlockSystem.cs @@ -22,6 +22,7 @@ public override void Initialize() SubscribeLocalEvent(OnBeforeDoorClosed); SubscribeLocalEvent(OnStateChanged); + SubscribeLocalEvent(OnBoltsChanged); SubscribeLocalEvent(OnBeforeDoorOpened); SubscribeLocalEvent(OnBeforeDoorDenied); SubscribeLocalEvent(OnGetPryMod); @@ -70,6 +71,13 @@ private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorState } } + private void OnBoltsChanged(EntityUid uid, AirlockComponent component, DoorBoltsChangedEvent args) + { + // If unbolted, reset the auto close timer + if (!args.BoltsDown) + UpdateAutoClose(uid, component); + } + private void OnBeforeDoorOpened(EntityUid uid, AirlockComponent component, BeforeDoorOpenedEvent args) { if (!CanChangeState(uid, component)) @@ -145,7 +153,7 @@ public void SetEmergencyAccess(Entity ent, bool value, EntityU ent.Comp.EmergencyAccess = value; Dirty(ent, ent.Comp); // This only runs on the server apparently so we need this. UpdateEmergencyLightStatus(ent, ent.Comp); - + var sound = ent.Comp.EmergencyAccess ? ent.Comp.EmergencyOnSound : ent.Comp.EmergencyOffSound; if (predicted) Audio.PlayPredicted(sound, ent, user: user); diff --git a/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs b/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs index 13050616e1ba..d14b6c71906e 100644 --- a/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs +++ b/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs @@ -96,6 +96,10 @@ public bool TrySetBoltDown( Dirty(ent, ent.Comp); UpdateBoltLightStatus(ent); + // used to reset the auto-close timer after unbolting + var ev = new DoorBoltsChangedEvent(value); + RaiseLocalEvent(ent.Owner, ev); + var sound = value ? ent.Comp.BoltDownSound : ent.Comp.BoltUpSound; if (predicted) Audio.PlayPredicted(sound, ent, user: user); diff --git a/Content.Shared/Doors/Systems/SharedDoorSystem.cs b/Content.Shared/Doors/Systems/SharedDoorSystem.cs index 7fd5d61db7dd..835adb31c05b 100644 --- a/Content.Shared/Doors/Systems/SharedDoorSystem.cs +++ b/Content.Shared/Doors/Systems/SharedDoorSystem.cs @@ -700,6 +700,8 @@ public void SetNextStateChange(EntityUid uid, TimeSpan? delay, DoorComponent? do } door.NextStateChange = GameTiming.CurTime + delay.Value; + Dirty(uid, door); + _activeDoors.Add((uid, door)); }