fix airlocks inconsistently auto-closing after unbolting (#33524)

fix door auto close timer
This commit is contained in:
slarticodefast
2024-11-25 05:26:54 +01:00
committed by GitHub
parent d642ee7707
commit 3c6c5ab6c9
5 changed files with 29 additions and 2 deletions

View File

@@ -66,7 +66,7 @@ public sealed partial class DoorComponent : Component
/// <summary> /// <summary>
/// When the door is active, this is the time when the state will next update. /// When the door is active, this is the time when the state will next update.
/// </summary> /// </summary>
[AutoNetworkedField] [AutoNetworkedField, ViewVariables]
public TimeSpan? NextStateChange; public TimeSpan? NextStateChange;
/// <summary> /// <summary>

View File

@@ -15,6 +15,19 @@ namespace Content.Shared.Doors
} }
} }
/// <summary>
/// Raised when the door's bolt status was changed.
/// </summary>
public sealed class DoorBoltsChangedEvent : EntityEventArgs
{
public readonly bool BoltsDown;
public DoorBoltsChangedEvent(bool boltsDown)
{
BoltsDown = boltsDown;
}
}
/// <summary> /// <summary>
/// Raised when the door is determining whether it is able to open. /// Raised when the door is determining whether it is able to open.
/// Cancel to stop the door from being opened. /// Cancel to stop the door from being opened.

View File

@@ -22,6 +22,7 @@ public abstract class SharedAirlockSystem : EntitySystem
SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed); SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged); SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged);
SubscribeLocalEvent<AirlockComponent, DoorBoltsChangedEvent>(OnBoltsChanged);
SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened); SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied); SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<AirlockComponent, GetPryTimeModifierEvent>(OnGetPryMod); SubscribeLocalEvent<AirlockComponent, GetPryTimeModifierEvent>(OnGetPryMod);
@@ -70,6 +71,13 @@ public abstract class SharedAirlockSystem : EntitySystem
} }
} }
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) private void OnBeforeDoorOpened(EntityUid uid, AirlockComponent component, BeforeDoorOpenedEvent args)
{ {
if (!CanChangeState(uid, component)) if (!CanChangeState(uid, component))

View File

@@ -96,6 +96,10 @@ public abstract partial class SharedDoorSystem
Dirty(ent, ent.Comp); Dirty(ent, ent.Comp);
UpdateBoltLightStatus(ent); 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; var sound = value ? ent.Comp.BoltDownSound : ent.Comp.BoltUpSound;
if (predicted) if (predicted)
Audio.PlayPredicted(sound, ent, user: user); Audio.PlayPredicted(sound, ent, user: user);

View File

@@ -700,6 +700,8 @@ public abstract partial class SharedDoorSystem : EntitySystem
} }
door.NextStateChange = GameTiming.CurTime + delay.Value; door.NextStateChange = GameTiming.CurTime + delay.Value;
Dirty(uid, door);
_activeDoors.Add((uid, door)); _activeDoors.Add((uid, door));
} }