| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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);
- // 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);
- 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;
- }
- }
|