Files
tbd-station-14/Content.Shared/Doors/Systems/SharedDoorSystem.Bolts.cs
Fildrance 4bcf3c3c0e Station AI ability to electricute doors (#32012)
* Boom! Emergency access!

* Emergency access sound

* locale

* Updated sounds

* bleh

* Door electrify base

* feat: popups on attempt to activate AI action when wires cut

* refactor: use SharedApcPowerReceiverComponent to check if AI can interact with door

* refactor: added icon and sound for door overcharge

* meta.json should use tabs not spaces

* refactor: extracted sounds for airlock overcharge to static field in system

* refactor: cleanup, ScarKy0 mentions for resources

* refactor: removed unused textures

* feat: now notification is displayed when AI attempting to interact with door which have wire cut

* StationAiWhitelistComponent is properly gating  BUI OnMessageAttempt, SharedPowerReceiverSystem.IsPowered is now used to check if device powered

* refactor: use PlayLocal to play electrify sound only for AI player

* refactor: SetBoltsDown now uses TrySetBoltDown, checks for power.

* bolts now check for power using SharedPowerReceiverSystem

* electrify localization and louder electrify sounds

* extracted ShowDeviceNotRespondingPopup, reverted airlocks not opening/closing when ai wire was cut

* refactor: cleanup

* New sprites and fixes

* Copyright

* even more sprite changes

* refactore: cleanup, rename overcharge => electrify

---------

Co-authored-by: ScarKy0 <scarky0@onet.eu>
Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-09-27 17:22:17 +10:00

123 lines
3.6 KiB
C#

using Content.Shared.Doors.Components;
using Content.Shared.Prying.Components;
namespace Content.Shared.Doors.Systems;
public abstract partial class SharedDoorSystem
{
public void InitializeBolts()
{
base.Initialize();
SubscribeLocalEvent<DoorBoltComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<DoorBoltComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
SubscribeLocalEvent<DoorBoltComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<DoorBoltComponent, BeforePryEvent>(OnDoorPry);
SubscribeLocalEvent<DoorBoltComponent, DoorStateChangedEvent>(OnStateChanged);
}
private void OnDoorPry(EntityUid uid, DoorBoltComponent component, ref BeforePryEvent args)
{
if (args.Cancelled)
return;
if (!component.BoltsDown || args.Force)
return;
args.Message = "airlock-component-cannot-pry-is-bolted-message";
args.Cancelled = true;
}
private void OnBeforeDoorOpened(EntityUid uid, DoorBoltComponent component, BeforeDoorOpenedEvent args)
{
if (component.BoltsDown)
args.Cancel();
}
private void OnBeforeDoorClosed(EntityUid uid, DoorBoltComponent component, BeforeDoorClosedEvent args)
{
if (component.BoltsDown)
args.Cancel();
}
private void OnBeforeDoorDenied(EntityUid uid, DoorBoltComponent component, BeforeDoorDeniedEvent args)
{
if (component.BoltsDown)
args.Cancel();
}
public void SetBoltWireCut(Entity<DoorBoltComponent> ent, bool value)
{
ent.Comp.BoltWireCut = value;
Dirty(ent, ent.Comp);
}
public void UpdateBoltLightStatus(Entity<DoorBoltComponent> ent)
{
AppearanceSystem.SetData(ent, DoorVisuals.BoltLights, GetBoltLightsVisible(ent));
}
public bool GetBoltLightsVisible(Entity<DoorBoltComponent> ent)
{
return ent.Comp.BoltLightsEnabled &&
ent.Comp.BoltsDown &&
ent.Comp.Powered;
}
public void SetBoltLightsEnabled(Entity<DoorBoltComponent> ent, bool value)
{
if (ent.Comp.BoltLightsEnabled == value)
return;
ent.Comp.BoltLightsEnabled = value;
Dirty(ent, ent.Comp);
UpdateBoltLightStatus(ent);
}
public void SetBoltsDown(Entity<DoorBoltComponent> ent, bool value, EntityUid? user = null, bool predicted = false)
{
TrySetBoltDown(ent, value, user, predicted);
}
public bool TrySetBoltDown(
Entity<DoorBoltComponent> ent,
bool value,
EntityUid? user = null,
bool predicted = false
)
{
if (!_powerReceiver.IsPowered(ent.Owner))
return false;
if (ent.Comp.BoltsDown == value)
return false;
ent.Comp.BoltsDown = value;
Dirty(ent, ent.Comp);
UpdateBoltLightStatus(ent);
var sound = value ? ent.Comp.BoltDownSound : ent.Comp.BoltUpSound;
if (predicted)
Audio.PlayPredicted(sound, ent, user: user);
else
Audio.PlayPvs(sound, ent);
return true;
}
private void OnStateChanged(Entity<DoorBoltComponent> entity, ref DoorStateChangedEvent args)
{
// If the door is closed, we should look if the bolt was locked while closing
UpdateBoltLightStatus(entity);
}
public bool IsBolted(EntityUid uid, DoorBoltComponent? component = null)
{
if (!Resolve(uid, ref component))
{
return false;
}
return component.BoltsDown;
}
}