Files
crystall-punk-14/Content.Shared/Silicons/StationAi/SharedStationAiSystem.Airlock.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

95 lines
3.3 KiB
C#

using Content.Shared.Doors.Components;
using Robust.Shared.Serialization;
using Content.Shared.Electrocution;
namespace Content.Shared.Silicons.StationAi;
public abstract partial class SharedStationAiSystem
{
// Handles airlock radial
private void InitializeAirlock()
{
SubscribeLocalEvent<DoorBoltComponent, StationAiBoltEvent>(OnAirlockBolt);
SubscribeLocalEvent<AirlockComponent, StationAiEmergencyAccessEvent>(OnAirlockEmergencyAccess);
SubscribeLocalEvent<ElectrifiedComponent, StationAiElectrifiedEvent>(OnElectrified);
}
/// <summary>
/// Attempts to bolt door. If wire was cut (AI or for bolts) or its not powered - notifies AI and does nothing.
/// </summary>
private void OnAirlockBolt(EntityUid ent, DoorBoltComponent component, StationAiBoltEvent args)
{
if (component.BoltWireCut)
{
ShowDeviceNotRespondingPopup(args.User);
return;
}
var setResult = _doors.TrySetBoltDown((ent, component), args.Bolted, args.User, predicted: true);
if (!setResult)
{
ShowDeviceNotRespondingPopup(args.User);
}
}
/// <summary>
/// Attempts to bolt door. If wire was cut (AI) or its not powered - notifies AI and does nothing.
/// </summary>
private void OnAirlockEmergencyAccess(EntityUid ent, AirlockComponent component, StationAiEmergencyAccessEvent args)
{
if (!PowerReceiver.IsPowered(ent))
{
ShowDeviceNotRespondingPopup(args.User);
return;
}
_airlocks.SetEmergencyAccess((ent, component), args.EmergencyAccess, args.User, predicted: true);
}
/// <summary>
/// Attempts to bolt door. If wire was cut (AI or for one of power-wires) or its not powered - notifies AI and does nothing.
/// </summary>
private void OnElectrified(EntityUid ent, ElectrifiedComponent component, StationAiElectrifiedEvent args)
{
if (
component.IsWireCut
|| !PowerReceiver.IsPowered(ent)
)
{
ShowDeviceNotRespondingPopup(args.User);
return;
}
_electrify.SetElectrified((ent, component), args.Electrified);
var soundToPlay = component.Enabled
? component.AirlockElectrifyDisabled
: component.AirlockElectrifyEnabled;
_audio.PlayLocal(soundToPlay, ent, args.User);
}
}
/// <summary> Event for StationAI attempt at bolting/unbolting door. </summary>
[Serializable, NetSerializable]
public sealed class StationAiBoltEvent : BaseStationAiAction
{
/// <summary> Marker, should be door bolted or unbolted. </summary>
public bool Bolted;
}
/// <summary> Event for StationAI attempt at setting emergency access for door on/off. </summary>
[Serializable, NetSerializable]
public sealed class StationAiEmergencyAccessEvent : BaseStationAiAction
{
/// <summary> Marker, should door have emergency access on or off. </summary>
public bool EmergencyAccess;
}
/// <summary> Event for StationAI attempt at electrifying/de-electrifying door. </summary>
[Serializable, NetSerializable]
public sealed class StationAiElectrifiedEvent : BaseStationAiAction
{
/// <summary> Marker, should door be electrified or no. </summary>
public bool Electrified;
}