Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix airlocks inconsistently auto-closing after unbolting #33524

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Shared/Doors/Components/DoorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public sealed partial class DoorComponent : Component
/// <summary>
/// When the door is active, this is the time when the state will next update.
/// </summary>
[AutoNetworkedField]
[AutoNetworkedField, ViewVariables]
public TimeSpan? NextStateChange;

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/Doors/DoorEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ public DoorStateChangedEvent(DoorState state)
}
}

/// <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>
/// Raised when the door is determining whether it is able to open.
/// Cancel to stop the door from being opened.
Expand Down
10 changes: 9 additions & 1 deletion Content.Shared/Doors/Systems/SharedAirlockSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public override void Initialize()

SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged);
SubscribeLocalEvent<AirlockComponent, DoorBoltsChangedEvent>(OnBoltsChanged);
SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<AirlockComponent, GetPryTimeModifierEvent>(OnGetPryMod);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -145,7 +153,7 @@ public void SetEmergencyAccess(Entity<AirlockComponent> 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);
Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Content.Shared/Doors/Systems/SharedDoorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Loading