Files
wwdpublic/Content.Shared/Doors/Systems/SharedAirlockSystem.cs
SimpleStation14 3fcc530118 Mirror: Fix misprediction of emergency access (#139)
## Mirror of PR #25973: [Fix misprediction of emergency
access](https://github.com/space-wizards/space-station-14/pull/25973)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `deac5a6842a88944b06c0b4d75da751880ddf12b`

PR opened by <img
src="https://avatars.githubusercontent.com/u/32041239?v=4"
width="16"/><a href="https://github.com/nikthechampiongr">
nikthechampiongr</a> at 2024-03-10 18:09:35 UTC
PR merged by <img
src="https://avatars.githubusercontent.com/u/19864447?v=4"
width="16"/><a href="https://github.com/web-flow"> web-flow</a> at
2024-03-11 01:50:09 UTC

---

PR changed 2 files with 2 additions and 1 deletions.

The PR had the following labels:


---

<details open="true"><summary><h1>Original Body</h1></summary>

> fixes #25800
> fixes #25900
> 
> <!-- Please read these guidelines before opening your PR:
https://docs.spacestation14.io/en/getting-started/pr-guideline -->
> <!-- The text between the arrows are comments - they will not be
visible on your PR. -->
> 
> ## About the PR
> <!-- What did you change in this PR? -->
> The client now actually knows when an airlock is in emergency access.
> 
> ## Technical details
> <!-- If this is a code change, summarize at high level how your new
code works. This makes it easier to review. -->
> The EmergencyAccess bool was not getting synced to the client. Made it
AutoNetworked. Also dirtied the airlock component on the function that
actually sets it since it's only called on the server when you use a
remote and as such doesn't sync to the client otherwise.
> 
> ## Media
> <!-- 
> PRs which make ingame changes (adding clothing, items, new features,
etc) are required to have media attached that showcase the changes.
> Small fixes/refactors are exempt.
> Any media may be used in SS14 progress reports, with clear credit
given.
> 
> If you're unsure whether your PR will require media, ask a maintainer.
> 
> Check the box below to confirm that you have in fact seen this (put an
X in the brackets, like [X]):
> -->
> 
> - [x] I have added screenshots/videos to this PR showcasing its
changes ingame, **or** this PR does not require an ingame showcase
> 
> ## Breaking changes
> <!--
> List any breaking changes, including namespace, public
class/method/field changes, prototype renames; and provide instructions
for fixing them. This will be pasted in #codebase-changes.
> -->
> 
> **Changelog**
> <!--
> Make players aware of new features and changes that could affect how
they play the game by adding a Changelog entry. Please read the
Changelog guidelines located at:
https://docs.spacestation14.io/en/getting-started/pr-guideline#changelog
> -->
> 
> <!--
> Make sure to take this Changelog template out of the comment block in
order for it to show up.
> 🆑
> - add: Added fun!
> - remove: Removed fun!
> - tweak: Changed fun!
> - fix: Fixed fun!
> -->
> no cl no fun


</details>

Co-authored-by: nikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
2024-05-04 19:35:38 -04:00

151 lines
5.1 KiB
C#

using Content.Shared.Doors.Components;
using Content.Shared.Popups;
using Content.Shared.Prying.Components;
using Content.Shared.Wires;
namespace Content.Shared.Doors.Systems;
public abstract class SharedAirlockSystem : EntitySystem
{
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
[Dependency] protected readonly SharedDoorSystem DoorSystem = default!;
[Dependency] protected readonly SharedPopupSystem Popup = default!;
[Dependency] private readonly SharedWiresSystem _wiresSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged);
SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<AirlockComponent, GetPryTimeModifierEvent>(OnGetPryMod);
SubscribeLocalEvent<AirlockComponent, BeforePryEvent>(OnBeforePry);
}
private void OnBeforeDoorClosed(EntityUid uid, AirlockComponent airlock, BeforeDoorClosedEvent args)
{
if (args.Cancelled)
return;
if (!airlock.Safety)
args.PerformCollisionCheck = false;
// only block based on bolts / power status when initially closing the door, not when its already
// mid-transition. Particularly relevant for when the door was pried-closed with a crowbar, which bypasses
// the initial power-check.
if (TryComp(uid, out DoorComponent? door)
&& !door.Partial
&& !CanChangeState(uid, airlock))
{
args.Cancel();
}
}
private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args)
{
// Only show the maintenance panel if the airlock is closed
if (TryComp<WiresPanelComponent>(uid, out var wiresPanel))
{
_wiresSystem.ChangePanelVisibility(uid, wiresPanel, component.OpenPanelVisible || args.State != DoorState.Open);
}
// If the door is closed, we should look if the bolt was locked while closing
UpdateAutoClose(uid, component);
// Make sure the airlock auto closes again next time it is opened
if (args.State == DoorState.Closed)
component.AutoClose = true;
}
private void OnBeforeDoorOpened(EntityUid uid, AirlockComponent component, BeforeDoorOpenedEvent args)
{
if (!CanChangeState(uid, component))
args.Cancel();
}
private void OnBeforeDoorDenied(EntityUid uid, AirlockComponent component, BeforeDoorDeniedEvent args)
{
if (!CanChangeState(uid, component))
args.Cancel();
}
private void OnGetPryMod(EntityUid uid, AirlockComponent component, ref GetPryTimeModifierEvent args)
{
if (component.Powered)
args.PryTimeModifier *= component.PoweredPryModifier;
if (DoorSystem.IsBolted(uid))
args.PryTimeModifier *= component.BoltedPryModifier;
}
/// <summary>
/// Updates the auto close timer.
/// </summary>
public void UpdateAutoClose(EntityUid uid, AirlockComponent? airlock = null, DoorComponent? door = null)
{
if (!Resolve(uid, ref airlock, ref door))
return;
if (door.State != DoorState.Open)
return;
if (!airlock.AutoClose)
return;
if (!CanChangeState(uid, airlock))
return;
var autoev = new BeforeDoorAutoCloseEvent();
RaiseLocalEvent(uid, autoev);
if (autoev.Cancelled)
return;
DoorSystem.SetNextStateChange(uid, airlock.AutoCloseDelay * airlock.AutoCloseDelayModifier);
}
private void OnBeforePry(EntityUid uid, AirlockComponent component, ref BeforePryEvent args)
{
if (args.Cancelled)
return;
if (!component.Powered || args.PryPowered)
return;
args.Message = "airlock-component-cannot-pry-is-powered-message";
args.Cancelled = true;
}
public void UpdateEmergencyLightStatus(EntityUid uid, AirlockComponent component)
{
Appearance.SetData(uid, DoorVisuals.EmergencyLights, component.EmergencyAccess);
}
public void ToggleEmergencyAccess(EntityUid uid, AirlockComponent component)
{
component.EmergencyAccess = !component.EmergencyAccess;
Dirty(uid, component); // This only runs on the server apparently so we need this.
UpdateEmergencyLightStatus(uid, component);
}
public void SetAutoCloseDelayModifier(AirlockComponent component, float value)
{
if (component.AutoCloseDelayModifier.Equals(value))
return;
component.AutoCloseDelayModifier = value;
}
public void SetSafety(AirlockComponent component, bool value)
{
component.Safety = value;
}
public bool CanChangeState(EntityUid uid, AirlockComponent component)
{
return component.Powered && !DoorSystem.IsBolted(uid);
}
}