Merge pull request #10721 from vulppine/air-alarm-fixup
Air sensors & air alarm fixup
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
using Content.Shared.Atmos.Monitor;
|
||||
using Content.Shared.Atmos.Monitor.Components;
|
||||
using Content.Shared.Atmos.Piping.Unary.Components;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor.Components
|
||||
namespace Content.Server.Atmos.Monitor.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class AirAlarmComponent : Component
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class AirAlarmComponent : Component
|
||||
{
|
||||
[ViewVariables] public AirAlarmMode CurrentMode { get; set; } = AirAlarmMode.Filtering;
|
||||
[ViewVariables] public AirAlarmMode CurrentMode { get; set; } = AirAlarmMode.Filtering;
|
||||
|
||||
// Remember to null this afterwards.
|
||||
[ViewVariables] public IAirAlarmModeUpdate? CurrentModeUpdater { get; set; }
|
||||
// Remember to null this afterwards.
|
||||
[ViewVariables] public IAirAlarmModeUpdate? CurrentModeUpdater { get; set; }
|
||||
|
||||
public Dictionary<string, IAtmosDeviceData> DeviceData = new();
|
||||
[ViewVariables] public AirAlarmTab CurrentTab { get; set; }
|
||||
|
||||
public HashSet<NetUserId> ActivePlayers = new();
|
||||
public readonly HashSet<string> KnownDevices = new();
|
||||
public readonly Dictionary<string, GasVentPumpData> VentData = new();
|
||||
public readonly Dictionary<string, GasVentScrubberData> ScrubberData = new();
|
||||
public readonly Dictionary<string, AtmosSensorData> SensorData = new();
|
||||
|
||||
public bool CanSync = true;
|
||||
}
|
||||
public HashSet<NetUserId> ActivePlayers = new();
|
||||
|
||||
public bool CanSync = true;
|
||||
}
|
||||
|
||||
@@ -1,41 +1,60 @@
|
||||
using Content.Shared.Atmos.Monitor;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor.Components
|
||||
namespace Content.Server.Atmos.Monitor.Components;
|
||||
// AtmosAlarmables are entities that can be alarmed
|
||||
// by a linked AtmosMonitor (alarmer?) if a threshold
|
||||
// is passed in some way. The intended use is to
|
||||
// do something in case something dangerous happens,
|
||||
// e.g., activate firelocks in case a temperature
|
||||
// threshold is reached
|
||||
//
|
||||
// It goes:
|
||||
//
|
||||
// AtmosMonitor -> AtmosDeviceUpdateEvent
|
||||
// -> Threshold calculation
|
||||
// -> AtmosAlarmEvent
|
||||
// -> Everything linked to that monitor (targetted)
|
||||
|
||||
/// <summary>
|
||||
/// A component to add to device network devices if you want them to be alarmed
|
||||
/// by an atmospheric alarmer. This will store every single alert received, and
|
||||
/// calculate the highest alert based on the alerts received. Equally, if you
|
||||
/// link other alarmables to this, it will store the alerts from them to
|
||||
/// calculate the highest network alert.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class AtmosAlarmableComponent : Component
|
||||
{
|
||||
// AtmosAlarmables are entities that can be alarmed
|
||||
// by a linked AtmosMonitor (alarmer?) if a threshold
|
||||
// is passed in some way. The intended use is to
|
||||
// do something in case something dangerous happens,
|
||||
// e.g., activate firelocks in case a temperature
|
||||
// threshold is reached
|
||||
//
|
||||
// It goes:
|
||||
//
|
||||
// AtmosMonitor -> AtmosDeviceUpdateEvent
|
||||
// -> Threshold calculation
|
||||
// -> AtmosMonitorAlarmEvent
|
||||
// -> Everything linked to that monitor (targetted)
|
||||
[ViewVariables]
|
||||
public readonly Dictionary<string, AtmosAlarmType> NetworkAlarmStates = new();
|
||||
|
||||
[ViewVariables] public AtmosAlarmType LastAlarmState = AtmosAlarmType.Normal;
|
||||
|
||||
[ViewVariables] public bool IgnoreAlarms { get; set; } = false;
|
||||
|
||||
[DataField("alarmSound")]
|
||||
public SoundSpecifier AlarmSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/alarm.ogg");
|
||||
|
||||
[DataField("alarmVolume")]
|
||||
public float AlarmVolume { get; set; } = -10;
|
||||
|
||||
/// <summary>
|
||||
/// A component to add to device network devices if you want them to be alarmed
|
||||
/// by an atmospheric monitor.
|
||||
/// List of tags to check for when synchronizing alarms.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class AtmosAlarmableComponent : Component
|
||||
{
|
||||
[ViewVariables]
|
||||
public List<EntityUid> LinkedMonitors { get; set; } = new();
|
||||
[DataField("syncWith", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<TagPrototype>))]
|
||||
public HashSet<string> SyncWithTags { get; } = new();
|
||||
|
||||
[ViewVariables] public AtmosMonitorAlarmType LastAlarmState = AtmosMonitorAlarmType.Normal;
|
||||
[ViewVariables] public AtmosMonitorAlarmType HighestNetworkState = AtmosMonitorAlarmType.Normal;
|
||||
[ViewVariables] public bool IgnoreAlarms { get; set; } = false;
|
||||
[DataField("monitorAlertTypes")]
|
||||
public HashSet<AtmosMonitorThresholdType>? MonitorAlertTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// List of prototypes that this alarmable can be
|
||||
/// alarmed by - must be a prototype with AtmosMonitor
|
||||
/// attached to it
|
||||
/// </summary>
|
||||
[DataField("alarmedBy")]
|
||||
public List<string> AlarmedByPrototypes { get; } = new();
|
||||
}
|
||||
/// <summary>
|
||||
/// If this device should receive only. If it can only
|
||||
/// receive, that means that attempting to sync outwards
|
||||
/// will result in nothing happening.
|
||||
/// </summary>
|
||||
[DataField("receiveOnly")]
|
||||
public bool ReceiveOnly { get; }
|
||||
}
|
||||
|
||||
@@ -3,98 +3,67 @@ using Content.Shared.Atmos.Monitor;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor.Components
|
||||
namespace Content.Server.Atmos.Monitor.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class AtmosMonitorComponent : Component
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class AtmosMonitorComponent : Component
|
||||
{
|
||||
// Whether this monitor can send alarms,
|
||||
// or recieve atmos command events.
|
||||
//
|
||||
// Useful for wires; i.e., pulsing a monitor wire
|
||||
// will make it send an alert, and cutting
|
||||
// it will make it so that alerts are no longer
|
||||
// sent/receieved.
|
||||
//
|
||||
// Note that this cancels every single network
|
||||
// event, including ones that may not be
|
||||
// related to atmos monitor events.
|
||||
[ViewVariables]
|
||||
public bool NetEnabled = true;
|
||||
// Whether this monitor can send alarms,
|
||||
// or recieve atmos command events.
|
||||
//
|
||||
// Useful for wires; i.e., pulsing a monitor wire
|
||||
// will make it send an alert, and cutting
|
||||
// it will make it so that alerts are no longer
|
||||
// sent/receieved.
|
||||
//
|
||||
// Note that this cancels every single network
|
||||
// event, including ones that may not be
|
||||
// related to atmos monitor events.
|
||||
[ViewVariables]
|
||||
public bool NetEnabled = true;
|
||||
|
||||
// Entities that the monitor will alarm. Stores only EntityUids, is populated
|
||||
// when this component starts up.
|
||||
[ViewVariables]
|
||||
public List<EntityUid> LinkedEntities = new();
|
||||
[DataField("temperatureThreshold", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThreshold>)))]
|
||||
public readonly string? TemperatureThresholdId;
|
||||
|
||||
[DataField("temperatureThreshold", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThreshold>)))]
|
||||
public readonly string? TemperatureThresholdId;
|
||||
[ViewVariables]
|
||||
public AtmosAlarmThreshold? TemperatureThreshold;
|
||||
|
||||
[ViewVariables]
|
||||
public AtmosAlarmThreshold? TemperatureThreshold;
|
||||
[DataField("pressureThreshold", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThreshold>)))]
|
||||
public readonly string? PressureThresholdId;
|
||||
|
||||
[DataField("pressureThreshold", customTypeSerializer: (typeof(PrototypeIdSerializer<AtmosAlarmThreshold>)))]
|
||||
public readonly string? PressureThresholdId;
|
||||
[ViewVariables]
|
||||
public AtmosAlarmThreshold? PressureThreshold;
|
||||
|
||||
[ViewVariables]
|
||||
public AtmosAlarmThreshold? PressureThreshold;
|
||||
// monitor fire - much different from temperature
|
||||
// since there's events for fire, setting this to true
|
||||
// will make the atmos monitor act like a smoke detector,
|
||||
// immediately signalling danger if there's a fire
|
||||
[DataField("monitorFire")]
|
||||
public bool MonitorFire = false;
|
||||
|
||||
// monitor fire - much different from temperature
|
||||
// since there's events for fire, setting this to true
|
||||
// will make the atmos monitor act like a smoke detector,
|
||||
// immediately signalling danger if there's a fire
|
||||
[DataField("monitorFire")]
|
||||
public bool MonitorFire = false;
|
||||
// really messy but this is parsed at runtime after
|
||||
// prototypes are initialized, there's no
|
||||
// way without implementing a new
|
||||
// type serializer
|
||||
[DataField("gasThresholds")]
|
||||
public Dictionary<Gas, string>? GasThresholdIds;
|
||||
|
||||
[DataField("displayMaxAlarmInNet")]
|
||||
public bool DisplayMaxAlarmInNet = false;
|
||||
[ViewVariables]
|
||||
public Dictionary<Gas, AtmosAlarmThreshold>? GasThresholds;
|
||||
|
||||
[DataField("alarmSound")]
|
||||
public SoundSpecifier AlarmSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/alarm.ogg");
|
||||
// Stores a reference to the gas on the tile this is on.
|
||||
[ViewVariables]
|
||||
public GasMixture? TileGas;
|
||||
|
||||
[DataField("alarmVolume")]
|
||||
public float AlarmVolume { get; set; } = -10;
|
||||
// Stores the last alarm state of this alarm.
|
||||
[ViewVariables]
|
||||
public AtmosAlarmType LastAlarmState = AtmosAlarmType.Normal;
|
||||
|
||||
// really messy but this is parsed at runtime after
|
||||
// prototypes are initialized, there's no
|
||||
// way without implementing a new
|
||||
// type serializer
|
||||
[DataField("gasThresholds")]
|
||||
public Dictionary<Gas, string>? GasThresholdIds;
|
||||
[ViewVariables] public HashSet<AtmosMonitorThresholdType> TrippedThresholds = new();
|
||||
|
||||
[ViewVariables]
|
||||
public Dictionary<Gas, AtmosAlarmThreshold>? GasThresholds;
|
||||
|
||||
// Stores a reference to the gas on the tile this is on.
|
||||
[ViewVariables]
|
||||
public GasMixture? TileGas;
|
||||
|
||||
// Stores the last alarm state of this alarm.
|
||||
[ViewVariables]
|
||||
public AtmosMonitorAlarmType LastAlarmState = AtmosMonitorAlarmType.Normal;
|
||||
|
||||
// feeling real dirty about this one
|
||||
// Caches the alarm states it recieves from the rest of the network.
|
||||
// This is so that the highest alarm in the network can be calculated
|
||||
// from any monitor without having to reping every alarm.
|
||||
[ViewVariables]
|
||||
public Dictionary<string, AtmosMonitorAlarmType> NetworkAlarmStates = new();
|
||||
|
||||
// Calculates the highest alarm in the network, including itself.
|
||||
[ViewVariables]
|
||||
public AtmosMonitorAlarmType HighestAlarmInNetwork
|
||||
{
|
||||
get
|
||||
{
|
||||
var state = AtmosMonitorAlarmType.Normal;
|
||||
foreach (var (_, netState) in NetworkAlarmStates)
|
||||
if (state < netState)
|
||||
state = netState;
|
||||
|
||||
if (LastAlarmState > state) state = LastAlarmState;
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Registered devices in this atmos monitor. Alerts will be sent directly
|
||||
/// to these devices.
|
||||
/// </summary>
|
||||
[ViewVariables] public HashSet<string> RegisteredDevices = new();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace Content.Server.Atmos.Monitor.Components
|
||||
namespace Content.Server.Atmos.Monitor.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class FireAlarmComponent : Component
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class FireAlarmComponent : Component
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,233 +5,168 @@ using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Monitor.Components;
|
||||
using Content.Shared.Atmos.Piping.Unary.Components;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor
|
||||
namespace Content.Server.Atmos.Monitor;
|
||||
|
||||
/// <summary>
|
||||
/// This is an interface that air alarm modes use
|
||||
/// in order to execute the defined modes.
|
||||
/// </summary>
|
||||
public interface IAirAlarmMode
|
||||
{
|
||||
// This is executed the moment the mode
|
||||
// is set. This is to ensure that 'dumb'
|
||||
// modes such as Filter/Panic are immediately
|
||||
// set.
|
||||
/// <summary>
|
||||
/// Executed the mode is set on an air alarm.
|
||||
/// This is to ensure that modes like Filter/Panic
|
||||
/// are immediately set.
|
||||
/// </summary>
|
||||
public void Execute(EntityUid uid);
|
||||
}
|
||||
|
||||
// IAirAlarmModeUpdate
|
||||
//
|
||||
// This is an interface that AirAlarmSystem uses
|
||||
// in order to 'update' air alarm modes so that
|
||||
// modes like Replace can be implemented.
|
||||
/// <summary>
|
||||
/// An interface that AirAlarmSystem uses
|
||||
/// in order to update air alarm modes that
|
||||
/// need updating (e.g., Replace)
|
||||
/// </summary>
|
||||
public interface IAirAlarmModeUpdate
|
||||
{
|
||||
/// <summary>
|
||||
/// This is an interface that air alarm modes use
|
||||
/// in order to execute the defined modes.
|
||||
/// This is checked by AirAlarmSystem when
|
||||
/// a mode is updated. This should be set
|
||||
/// to a DeviceNetwork address, or some
|
||||
/// unique identifier that ID's the
|
||||
/// owner of the mode's executor.
|
||||
/// </summary>
|
||||
public interface IAirAlarmMode
|
||||
{
|
||||
// This is executed the moment the mode
|
||||
// is set. This is to ensure that 'dumb'
|
||||
// modes such as Filter/Panic are immediately
|
||||
// set.
|
||||
/// <summary>
|
||||
/// Executed the mode is set on an air alarm.
|
||||
/// This is to ensure that modes like Filter/Panic
|
||||
/// are immediately set.
|
||||
/// </summary>
|
||||
public void Execute(EntityUid uid);
|
||||
}
|
||||
|
||||
// IAirAlarmModeUpdate
|
||||
//
|
||||
// This is an interface that AirAlarmSystem uses
|
||||
// in order to 'update' air alarm modes so that
|
||||
// modes like Replace can be implemented.
|
||||
public string NetOwner { get; set; }
|
||||
/// <summary>
|
||||
/// An interface that AirAlarmSystem uses
|
||||
/// in order to update air alarm modes that
|
||||
/// need updating (e.g., Replace)
|
||||
/// This is executed every time the air alarm
|
||||
/// update loop is fully executed. This should
|
||||
/// be where all the logic goes.
|
||||
/// </summary>
|
||||
public interface IAirAlarmModeUpdate
|
||||
{
|
||||
/// <summary>
|
||||
/// This is checked by AirAlarmSystem when
|
||||
/// a mode is updated. This should be set
|
||||
/// to a DeviceNetwork address, or some
|
||||
/// unique identifier that ID's the
|
||||
/// owner of the mode's executor.
|
||||
/// </summary>
|
||||
public string NetOwner { get; set; }
|
||||
/// <summary>
|
||||
/// This is executed every time the air alarm
|
||||
/// update loop is fully executed. This should
|
||||
/// be where all the logic goes.
|
||||
/// </summary>
|
||||
public void Update(EntityUid uid);
|
||||
}
|
||||
public void Update(EntityUid uid);
|
||||
}
|
||||
|
||||
public sealed class AirAlarmModeFactory
|
||||
{
|
||||
private static IAirAlarmMode _filterMode = new AirAlarmFilterMode();
|
||||
private static IAirAlarmMode _fillMode = new AirAlarmFillMode();
|
||||
private static IAirAlarmMode _panicMode = new AirAlarmPanicMode();
|
||||
private static IAirAlarmMode _noneMode = new AirAlarmNoneMode();
|
||||
public sealed class AirAlarmModeFactory
|
||||
{
|
||||
private static IAirAlarmMode _filterMode = new AirAlarmFilterMode();
|
||||
private static IAirAlarmMode _fillMode = new AirAlarmFillMode();
|
||||
private static IAirAlarmMode _panicMode = new AirAlarmPanicMode();
|
||||
private static IAirAlarmMode _noneMode = new AirAlarmNoneMode();
|
||||
|
||||
// still not a fan since ReplaceMode must have an allocation
|
||||
// but it's whatever
|
||||
public static IAirAlarmMode? ModeToExecutor(AirAlarmMode mode) => mode switch
|
||||
// still not a fan since ReplaceMode must have an allocation
|
||||
// but it's whatever
|
||||
public static IAirAlarmMode? ModeToExecutor(AirAlarmMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
AirAlarmMode.Filtering => _filterMode,
|
||||
AirAlarmMode.Fill => _fillMode,
|
||||
AirAlarmMode.Panic => _panicMode,
|
||||
AirAlarmMode.None => _noneMode,
|
||||
AirAlarmMode.Replace => new AirAlarmReplaceMode(),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// like a tiny little EntitySystem
|
||||
public abstract class AirAlarmModeExecutor : IAirAlarmMode
|
||||
// like a tiny little EntitySystem
|
||||
public abstract class AirAlarmModeExecutor : IAirAlarmMode
|
||||
{
|
||||
[Dependency] public readonly IEntityManager EntityManager = default!;
|
||||
public readonly DeviceNetworkSystem DeviceNetworkSystem;
|
||||
public readonly AirAlarmSystem AirAlarmSystem;
|
||||
|
||||
public abstract void Execute(EntityUid uid);
|
||||
|
||||
public AirAlarmModeExecutor()
|
||||
{
|
||||
[Dependency] public readonly IEntityManager EntityManager = default!;
|
||||
public readonly DeviceNetworkSystem DeviceNetworkSystem;
|
||||
public readonly AirAlarmSystem AirAlarmSystem;
|
||||
|
||||
public abstract void Execute(EntityUid uid);
|
||||
|
||||
public AirAlarmModeExecutor()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
DeviceNetworkSystem = EntitySystem.Get<DeviceNetworkSystem>();
|
||||
AirAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmNoneMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.DeviceData)
|
||||
{
|
||||
device.Enabled = false;
|
||||
AirAlarmSystem.SetData(uid, addr, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmFilterMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.DeviceData)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
case GasVentPumpData pumpData:
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentPumpData.FilterModePreset);
|
||||
break;
|
||||
case GasVentScrubberData scrubberData:
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentScrubberData.FilterModePreset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmPanicMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.DeviceData)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
case GasVentPumpData pumpData:
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentPumpData.PanicModePreset);
|
||||
break;
|
||||
case GasVentScrubberData scrubberData:
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentScrubberData.PanicModePreset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmFillMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.DeviceData)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
case GasVentPumpData pumpData:
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentPumpData.FillModePreset);
|
||||
break;
|
||||
case GasVentScrubberData scrubberData:
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentScrubberData.FillModePreset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmReplaceMode : AirAlarmModeExecutor, IAirAlarmModeUpdate
|
||||
{
|
||||
private Dictionary<string, IAtmosDeviceData> _devices = new();
|
||||
private float _lastPressure = Atmospherics.OneAtmosphere;
|
||||
private AtmosMonitorComponent? _monitor;
|
||||
private AtmosAlarmableComponent? _alarmable;
|
||||
|
||||
public string NetOwner { get; set; } = string.Empty;
|
||||
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm)
|
||||
|| !EntityManager.TryGetComponent(uid, out AtmosMonitorComponent? monitor)
|
||||
|| !EntityManager.TryGetComponent(uid, out AtmosAlarmableComponent? alarmable))
|
||||
return;
|
||||
|
||||
_devices = alarm.DeviceData;
|
||||
_monitor = monitor;
|
||||
_alarmable = alarmable;
|
||||
_alarmable.IgnoreAlarms = true;
|
||||
SetSiphon(uid);
|
||||
}
|
||||
|
||||
public void Update(EntityUid uid)
|
||||
{
|
||||
if (_monitor == null
|
||||
|| _alarmable == null
|
||||
|| _monitor.TileGas == null)
|
||||
return;
|
||||
|
||||
// just a little pointer
|
||||
var mixture = _monitor.TileGas;
|
||||
|
||||
_lastPressure = mixture.Pressure;
|
||||
if (_lastPressure <= 0.2f) // anything below and it might get stuck
|
||||
{
|
||||
_alarmable.IgnoreAlarms = false;
|
||||
AirAlarmSystem.SetMode(uid, NetOwner!, AirAlarmMode.Filtering, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSiphon(EntityUid uid)
|
||||
{
|
||||
foreach (var (addr, device) in _devices)
|
||||
{
|
||||
switch (device)
|
||||
{
|
||||
case GasVentPumpData pumpData:
|
||||
pumpData = GasVentPumpData.PanicModePreset;
|
||||
pumpData.IgnoreAlarms = true;
|
||||
AirAlarmSystem.SetData(uid, addr, pumpData);
|
||||
break;
|
||||
case GasVentScrubberData scrubberData:
|
||||
scrubberData = GasVentScrubberData.PanicModePreset;
|
||||
scrubberData.IgnoreAlarms = true;
|
||||
AirAlarmSystem.SetData(uid, addr, scrubberData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
DeviceNetworkSystem = EntitySystem.Get<DeviceNetworkSystem>();
|
||||
AirAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmNoneMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.VentData)
|
||||
{
|
||||
device.Enabled = false;
|
||||
AirAlarmSystem.SetData(uid, addr, device);
|
||||
}
|
||||
|
||||
foreach (var (addr, device) in alarm.ScrubberData)
|
||||
{
|
||||
device.Enabled = false;
|
||||
AirAlarmSystem.SetData(uid, addr, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmFilterMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.VentData)
|
||||
{
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentPumpData.FilterModePreset);
|
||||
}
|
||||
|
||||
foreach (var (addr, device) in alarm.ScrubberData)
|
||||
{
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentScrubberData.FilterModePreset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmPanicMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.VentData)
|
||||
{
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentPumpData.PanicModePreset);
|
||||
}
|
||||
|
||||
foreach (var (addr, device) in alarm.ScrubberData)
|
||||
{
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentScrubberData.PanicModePreset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AirAlarmFillMode : AirAlarmModeExecutor
|
||||
{
|
||||
public override void Execute(EntityUid uid)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out AirAlarmComponent? alarm))
|
||||
return;
|
||||
|
||||
foreach (var (addr, device) in alarm.VentData)
|
||||
{
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentPumpData.FillModePreset);
|
||||
}
|
||||
|
||||
foreach (var (addr, device) in alarm.ScrubberData)
|
||||
{
|
||||
AirAlarmSystem.SetData(uid, addr, GasVentScrubberData.FillModePreset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,316 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos.Monitor.Components;
|
||||
using Content.Server.DeviceNetwork;
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Atmos.Monitor;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor.Systems
|
||||
namespace Content.Server.Atmos.Monitor.Systems;
|
||||
|
||||
public sealed class AtmosAlarmableSystem : EntitySystem
|
||||
{
|
||||
public sealed class AtmosAlarmableSystem : EntitySystem
|
||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly AudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNet = default!;
|
||||
|
||||
/// <summary>
|
||||
/// An alarm. Has three valid states: Normal, Warning, Danger.
|
||||
/// Will attempt to fetch the tags from the alarming entity
|
||||
/// to send over.
|
||||
/// </summary>
|
||||
public const string AlertCmd = "atmos_alarm";
|
||||
|
||||
public const string AlertSource = "atmos_alarm_source";
|
||||
|
||||
public const string AlertTypes = "atmos_alarm_types";
|
||||
|
||||
/// <summary>
|
||||
/// Syncs alerts from this alarm receiver to other alarm receivers.
|
||||
/// Creates a network effect as a result. Note: if the alert receiver
|
||||
/// is not aware of the device beforehand, it will not sync.
|
||||
/// </summary>
|
||||
public const string SyncAlerts = "atmos_alarmable_sync_alerts";
|
||||
|
||||
public const string ResetAll = "atmos_alarmable_reset_all";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
public override void Initialize()
|
||||
SubscribeLocalEvent<AtmosAlarmableComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<AtmosAlarmableComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||
SubscribeLocalEvent<AtmosAlarmableComponent, PowerChangedEvent>(OnPowerChange);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, AtmosAlarmableComponent component, ComponentInit args)
|
||||
{
|
||||
TryUpdateAlert(
|
||||
uid,
|
||||
TryGetHighestAlert(uid, out var alarm) ? alarm.Value : AtmosAlarmType.Normal,
|
||||
component,
|
||||
false);
|
||||
}
|
||||
|
||||
private void OnPowerChange(EntityUid uid, AtmosAlarmableComponent component, PowerChangedEvent args)
|
||||
{
|
||||
if (!args.Powered)
|
||||
{
|
||||
SubscribeLocalEvent<AtmosAlarmableComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||
Reset(uid, component);
|
||||
}
|
||||
|
||||
private void OnPacketRecv(EntityUid uid, AtmosAlarmableComponent component, DeviceNetworkPacketEvent args)
|
||||
else
|
||||
{
|
||||
if (component.IgnoreAlarms) return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn))
|
||||
return;
|
||||
|
||||
if (args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd)
|
||||
&& cmd == AtmosMonitorSystem.AtmosMonitorAlarmCmd)
|
||||
{
|
||||
// does it have a state & network max state?
|
||||
// does it have a source?
|
||||
// and can this be alarmed by the source?
|
||||
// if so, raise an alarm
|
||||
if (args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out AtmosMonitorAlarmType state)
|
||||
&& args.Data.TryGetValue(AtmosMonitorSystem.AtmosMonitorAlarmNetMax, out AtmosMonitorAlarmType netMax)
|
||||
&& args.Data.TryGetValue(AtmosMonitorSystem.AtmosMonitorAlarmSrc, out string? source)
|
||||
&& component.AlarmedByPrototypes.Contains(source))
|
||||
{
|
||||
component.LastAlarmState = state;
|
||||
component.HighestNetworkState = netMax;
|
||||
RaiseLocalEvent(component.Owner, new AtmosMonitorAlarmEvent(state, netMax), true);
|
||||
}
|
||||
}
|
||||
TryUpdateAlert(
|
||||
uid,
|
||||
TryGetHighestAlert(uid, out var alarm) ? alarm.Value : AtmosAlarmType.Normal,
|
||||
component,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPacketRecv(EntityUid uid, AtmosAlarmableComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
if (component.IgnoreAlarms) return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn))
|
||||
return;
|
||||
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd)
|
||||
|| !args.Data.TryGetValue(AlertSource, out HashSet<string>? sourceTags))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var isValid = sourceTags.Any(source => component.SyncWithTags.Contains(source));
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case AlertCmd:
|
||||
// Set the alert state, and then cache it so we can calculate
|
||||
// the maximum alarm state at all times.
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out AtmosAlarmType state))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (args.Data.TryGetValue(AlertTypes, out HashSet<AtmosMonitorThresholdType>? types) && component.MonitorAlertTypes != null)
|
||||
{
|
||||
isValid = types.Any(type => component.MonitorAlertTypes.Contains(type));
|
||||
}
|
||||
|
||||
if (!component.NetworkAlarmStates.ContainsKey(args.SenderAddress))
|
||||
{
|
||||
if (!isValid)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
component.NetworkAlarmStates.Add(args.SenderAddress, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is because if the alert is no longer valid,
|
||||
// it may mean that the threshold we need to look at has
|
||||
// been removed from the threshold types passed:
|
||||
// basically, we need to reset this state to normal here.
|
||||
component.NetworkAlarmStates[args.SenderAddress] = isValid ? state : AtmosAlarmType.Normal;
|
||||
}
|
||||
|
||||
if (!TryGetHighestAlert(uid, out var netMax, component))
|
||||
{
|
||||
netMax = AtmosAlarmType.Normal;
|
||||
}
|
||||
|
||||
TryUpdateAlert(uid, netMax.Value, component);
|
||||
|
||||
break;
|
||||
case ResetAll:
|
||||
Reset(uid, component);
|
||||
break;
|
||||
case SyncAlerts:
|
||||
if (!args.Data.TryGetValue(SyncAlerts,
|
||||
out IReadOnlyDictionary<string, AtmosAlarmType>? alarms))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var (key, alarm) in alarms)
|
||||
{
|
||||
if (!component.NetworkAlarmStates.TryAdd(key, alarm))
|
||||
{
|
||||
component.NetworkAlarmStates[key] = alarm;
|
||||
}
|
||||
}
|
||||
|
||||
if (TryGetHighestAlert(uid, out var maxAlert, component))
|
||||
{
|
||||
TryUpdateAlert(uid, maxAlert.Value, component);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void TryUpdateAlert(EntityUid uid, AtmosAlarmType type, AtmosAlarmableComponent alarmable, bool sync = true)
|
||||
{
|
||||
if (alarmable.LastAlarmState == type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (sync)
|
||||
{
|
||||
SyncAlertsToNetwork(uid, null, alarmable);
|
||||
}
|
||||
|
||||
alarmable.LastAlarmState = type;
|
||||
UpdateAppearance(uid, type);
|
||||
PlayAlertSound(uid, type, alarmable);
|
||||
RaiseLocalEvent(uid, new AtmosAlarmEvent(type), true);
|
||||
}
|
||||
|
||||
public void SyncAlertsToNetwork(EntityUid uid, string? address = null, AtmosAlarmableComponent? alarmable = null, TagComponent? tags = null)
|
||||
{
|
||||
if (!Resolve(uid, ref alarmable, ref tags) || alarmable.ReceiveOnly)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = SyncAlerts,
|
||||
[SyncAlerts] = alarmable.NetworkAlarmStates,
|
||||
[AlertSource] = tags.Tags
|
||||
};
|
||||
|
||||
_deviceNet.QueuePacket(uid, address, payload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forces this alarmable to have a specific alert. This will not be reset until the alarmable
|
||||
/// is manually reset. This will store the alarmable as a device in its network states.
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="alarmType"></param>
|
||||
/// <param name="alarmable"></param>
|
||||
public void ForceAlert(EntityUid uid, AtmosAlarmType alarmType,
|
||||
AtmosAlarmableComponent? alarmable = null, DeviceNetworkComponent? devNet = null, TagComponent? tags = null)
|
||||
{
|
||||
if (!Resolve(uid, ref alarmable, ref devNet, ref tags))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TryUpdateAlert(uid, alarmType, alarmable, false);
|
||||
|
||||
if (alarmable.ReceiveOnly)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!alarmable.NetworkAlarmStates.TryAdd(devNet.Address, alarmType))
|
||||
{
|
||||
alarmable.NetworkAlarmStates[devNet.Address] = alarmType;
|
||||
}
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = AlertCmd,
|
||||
[DeviceNetworkConstants.CmdSetState] = alarmType,
|
||||
[AlertSource] = tags.Tags
|
||||
};
|
||||
|
||||
_deviceNet.QueuePacket(uid, null, payload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the state of this alarmable to normal.
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="alarmable"></param>
|
||||
public void Reset(EntityUid uid, AtmosAlarmableComponent? alarmable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref alarmable))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TryUpdateAlert(uid, AtmosAlarmType.Normal, alarmable, false);
|
||||
|
||||
alarmable.NetworkAlarmStates.Clear();
|
||||
}
|
||||
|
||||
public void ResetAllOnNetwork(EntityUid uid, AtmosAlarmableComponent? alarmable = null, TagComponent? tags = null)
|
||||
{
|
||||
if (!Resolve(uid, ref alarmable, ref tags) || alarmable.ReceiveOnly)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reset(uid, alarmable);
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = ResetAll,
|
||||
[AlertSource] = tags.Tags
|
||||
};
|
||||
|
||||
_deviceNet.QueuePacket(uid, null, payload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the highest possible alert stored in this alarm.
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="alarm"></param>
|
||||
/// <param name="alarmable"></param>
|
||||
/// <returns></returns>
|
||||
public bool TryGetHighestAlert(EntityUid uid, [NotNullWhen(true)] out AtmosAlarmType? alarm,
|
||||
AtmosAlarmableComponent? alarmable = null)
|
||||
{
|
||||
alarm = null;
|
||||
|
||||
if (!Resolve(uid, ref alarmable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var alarmState in alarmable.NetworkAlarmStates.Values)
|
||||
{
|
||||
alarm = alarm == null || alarm < alarmState ? alarmState : alarm;
|
||||
}
|
||||
|
||||
return alarm != null;
|
||||
}
|
||||
|
||||
private void PlayAlertSound(EntityUid uid, AtmosAlarmType alarm, AtmosAlarmableComponent alarmable)
|
||||
{
|
||||
if (alarm == AtmosAlarmType.Danger)
|
||||
{
|
||||
_audioSystem.PlayPvs(alarmable.AlarmSound, uid, AudioParams.Default.WithVolume(alarmable.AlarmVolume));
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, AtmosAlarmType alarm)
|
||||
{
|
||||
_appearance.SetData(uid, AtmosMonitorVisuals.AlarmType, alarm);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AtmosAlarmEvent : EntityEventArgs
|
||||
{
|
||||
public AtmosAlarmType AlarmType { get; }
|
||||
|
||||
public AtmosAlarmEvent(AtmosAlarmType netMax)
|
||||
{
|
||||
AlarmType = netMax;
|
||||
}
|
||||
}
|
||||
|
||||
55
Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs
Normal file
55
Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Content.Server.DeviceNetwork;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Shared.Atmos.Monitor.Components;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Generic device network commands useful for atmos devices,
|
||||
/// as well as some helper commands.
|
||||
/// </summary>
|
||||
public sealed class AtmosDeviceNetworkSystem : EntitySystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Register a device's address on this device.
|
||||
/// </summary>
|
||||
public const string RegisterDevice = "atmos_register_device";
|
||||
|
||||
/// <summary>
|
||||
/// Synchronize the data this device has with the sender.
|
||||
/// </summary>
|
||||
public const string SyncData = "atmos_sync_data";
|
||||
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNet = default!;
|
||||
|
||||
public void Register(EntityUid uid, string? address)
|
||||
{
|
||||
var registerPayload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = RegisterDevice
|
||||
};
|
||||
|
||||
_deviceNet.QueuePacket(uid, address, registerPayload);
|
||||
}
|
||||
|
||||
public void Sync(EntityUid uid, string? address)
|
||||
{
|
||||
var syncPayload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = SyncData
|
||||
};
|
||||
|
||||
_deviceNet.QueuePacket(uid, address, syncPayload);
|
||||
}
|
||||
|
||||
public void SetDeviceState(EntityUid uid, string address, IAtmosDeviceData data)
|
||||
{
|
||||
var payload = new NetworkPayload()
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = DeviceNetworkConstants.CmdSetState,
|
||||
[DeviceNetworkConstants.CmdSetState] = data
|
||||
};
|
||||
|
||||
_deviceNet.QueuePacket(uid, address, payload);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos.Monitor.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Atmos.Piping.EntitySystems;
|
||||
@@ -9,472 +10,372 @@ using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Atmos.Monitor;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor.Systems
|
||||
namespace Content.Server.Atmos.Monitor.Systems;
|
||||
|
||||
// AtmosMonitorSystem. Grabs all the AtmosAlarmables connected
|
||||
// to it via local APC net, and starts sending updates of the
|
||||
// current atmosphere. Monitors fire (which always triggers as
|
||||
// a danger), and atmos (which triggers based on set thresholds).
|
||||
public sealed class AtmosMonitorSystem : EntitySystem
|
||||
{
|
||||
// AtmosMonitorSystem. Grabs all the AtmosAlarmables connected
|
||||
// to it via local APC net, and starts sending updates of the
|
||||
// current atmosphere. Monitors fire (which always triggers as
|
||||
// a danger), and atmos (which triggers based on set thresholds).
|
||||
public sealed class AtmosMonitorSystem : EntitySystem
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Dependency] private readonly AtmosDeviceSystem _atmosDeviceSystem = default!;
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
// Commands
|
||||
public const string AtmosMonitorSetThresholdCmd = "atmos_monitor_set_threshold";
|
||||
|
||||
// Packet data
|
||||
public const string AtmosMonitorThresholdData = "atmos_monitor_threshold_data";
|
||||
|
||||
public const string AtmosMonitorThresholdDataType = "atmos_monitor_threshold_type";
|
||||
|
||||
public const string AtmosMonitorThresholdGasType = "atmos_monitor_threshold_gas";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Dependency] private readonly AtmosDeviceSystem _atmosDeviceSystem = default!;
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
|
||||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, ComponentInit>(OnAtmosMonitorInit);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, ComponentStartup>(OnAtmosMonitorStartup);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, AtmosDeviceUpdateEvent>(OnAtmosUpdate);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, TileFireEvent>(OnFireEvent);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, PowerChangedEvent>(OnPowerChangedEvent);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, BeforePacketSentEvent>(BeforePacketRecv);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||
}
|
||||
|
||||
// Commands
|
||||
/// <summary>
|
||||
/// Command to alarm the network that something has happened.
|
||||
/// </summary>
|
||||
public const string AtmosMonitorAlarmCmd = "atmos_monitor_alarm_update";
|
||||
private void OnAtmosMonitorInit(EntityUid uid, AtmosMonitorComponent component, ComponentInit args)
|
||||
{
|
||||
if (component.TemperatureThresholdId != null)
|
||||
component.TemperatureThreshold = new(_prototypeManager.Index<AtmosAlarmThreshold>(component.TemperatureThresholdId));
|
||||
|
||||
/// <summary>
|
||||
/// Command to sync this monitor's alarm state with the rest of the network.
|
||||
/// </summary>
|
||||
public const string AtmosMonitorAlarmSyncCmd = "atmos_monitor_alarm_sync";
|
||||
if (component.PressureThresholdId != null)
|
||||
component.PressureThreshold = new(_prototypeManager.Index<AtmosAlarmThreshold>(component.PressureThresholdId));
|
||||
|
||||
/// <summary>
|
||||
/// Command to reset all alarms on a network.
|
||||
/// </summary>
|
||||
public const string AtmosMonitorAlarmResetAllCmd = "atmos_monitor_alarm_reset_all";
|
||||
|
||||
// Packet data
|
||||
/// <summary>
|
||||
/// Data response that contains the threshold types in an atmos monitor alarm.
|
||||
/// </summary>
|
||||
public const string AtmosMonitorAlarmThresholdTypes = "atmos_monitor_alarm_threshold_types";
|
||||
|
||||
/// <summary>
|
||||
/// Data response that contains the source of an atmos alarm.
|
||||
/// </summary>
|
||||
public const string AtmosMonitorAlarmSrc = "atmos_monitor_alarm_source";
|
||||
|
||||
/// <summary>
|
||||
/// Data response that contains the maximum alarm in an atmos alarm network.
|
||||
/// </summary>
|
||||
public const string AtmosMonitorAlarmNetMax = "atmos_monitor_alarm_net_max";
|
||||
|
||||
public override void Initialize()
|
||||
if (component.GasThresholdIds != null)
|
||||
{
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, ComponentInit>(OnAtmosMonitorInit);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, ComponentStartup>(OnAtmosMonitorStartup);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, ComponentShutdown>(OnAtmosMonitorShutdown);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, AtmosDeviceUpdateEvent>(OnAtmosUpdate);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, TileFireEvent>(OnFireEvent);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, PowerChangedEvent>(OnPowerChangedEvent);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, BeforePacketSentEvent>(BeforePacketRecv);
|
||||
SubscribeLocalEvent<AtmosMonitorComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||
}
|
||||
|
||||
private void OnAtmosMonitorInit(EntityUid uid, AtmosMonitorComponent component, ComponentInit args)
|
||||
{
|
||||
if (component.TemperatureThresholdId != null)
|
||||
component.TemperatureThreshold = _prototypeManager.Index<AtmosAlarmThreshold>(component.TemperatureThresholdId);
|
||||
|
||||
if (component.PressureThresholdId != null)
|
||||
component.PressureThreshold = _prototypeManager.Index<AtmosAlarmThreshold>(component.PressureThresholdId);
|
||||
|
||||
if (component.GasThresholdIds != null)
|
||||
component.GasThresholds = new();
|
||||
foreach (var (gas, id) in component.GasThresholdIds)
|
||||
{
|
||||
component.GasThresholds = new();
|
||||
foreach (var (gas, id) in component.GasThresholdIds)
|
||||
if (_prototypeManager.TryIndex<AtmosAlarmThreshold>(id, out var gasThreshold))
|
||||
component.GasThresholds.Add(gas, gasThreshold);
|
||||
if (_prototypeManager.TryIndex<AtmosAlarmThreshold>(id, out var gasThreshold))
|
||||
component.GasThresholds.Add(gas, new(gasThreshold));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAtmosMonitorStartup(EntityUid uid, AtmosMonitorComponent component, ComponentStartup args)
|
||||
private void OnAtmosMonitorStartup(EntityUid uid, AtmosMonitorComponent component, ComponentStartup args)
|
||||
{
|
||||
if (!HasComp<ApcPowerReceiverComponent>(uid)
|
||||
&& TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
|
||||
{
|
||||
if (!HasComp<ApcPowerReceiverComponent>(uid)
|
||||
&& TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
|
||||
{
|
||||
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
|
||||
return;
|
||||
}
|
||||
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
|
||||
}
|
||||
}
|
||||
|
||||
_checkPos.Add(uid);
|
||||
private void BeforePacketRecv(EntityUid uid, AtmosMonitorComponent component, BeforePacketSentEvent args)
|
||||
{
|
||||
if (!component.NetEnabled) args.Cancel();
|
||||
}
|
||||
|
||||
private void OnPacketRecv(EntityUid uid, AtmosMonitorComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
// sync the internal 'last alarm state' from
|
||||
// the other alarms, so that we can calculate
|
||||
// the highest network alarm state at any time
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
private void OnAtmosMonitorShutdown(EntityUid uid, AtmosMonitorComponent component, ComponentShutdown args)
|
||||
switch (cmd)
|
||||
{
|
||||
if (_checkPos.Contains(uid)) _checkPos.Remove(uid);
|
||||
}
|
||||
|
||||
// hackiest shit ever but there's no PostStartup event
|
||||
private HashSet<EntityUid> _checkPos = new();
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var uid in _checkPos)
|
||||
OpenAirOrReposition(uid);
|
||||
}
|
||||
|
||||
private void OpenAirOrReposition(EntityUid uid, AtmosMonitorComponent? component = null, AppearanceComponent? appearance = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, ref appearance)) return;
|
||||
|
||||
var transform = Transform(component.Owner);
|
||||
|
||||
if (transform.GridUid == null)
|
||||
return;
|
||||
|
||||
// atmos alarms will first attempt to get the air
|
||||
// directly underneath it - if not, then it will
|
||||
// instead place itself directly in front of the tile
|
||||
// it is facing, and then visually shift itself back
|
||||
// via sprite offsets (SS13 style but fuck it)
|
||||
var coords = transform.Coordinates;
|
||||
var pos = _transformSystem.GetGridOrMapTilePosition(uid, transform);
|
||||
|
||||
if (_atmosphereSystem.IsTileAirBlocked(transform.GridUid.Value, pos))
|
||||
{
|
||||
var rotPos = transform.LocalRotation.RotateVec(new Vector2(0, -1));
|
||||
transform.Anchored = false;
|
||||
coords = coords.Offset(rotPos);
|
||||
transform.Coordinates = coords;
|
||||
|
||||
appearance.SetData(AtmosMonitorVisuals.Offset, - new Vector2i(0, -1));
|
||||
|
||||
transform.Anchored = true;
|
||||
}
|
||||
|
||||
GasMixture? air = _atmosphereSystem.GetContainingMixture(uid, true);
|
||||
component.TileGas = air;
|
||||
|
||||
_checkPos.Remove(uid);
|
||||
}
|
||||
|
||||
private void BeforePacketRecv(EntityUid uid, AtmosMonitorComponent component, BeforePacketSentEvent args)
|
||||
{
|
||||
if (!component.NetEnabled) args.Cancel();
|
||||
}
|
||||
|
||||
private void OnPacketRecv(EntityUid uid, AtmosMonitorComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
// sync the internal 'last alarm state' from
|
||||
// the other alarms, so that we can calculate
|
||||
// the highest network alarm state at any time
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd)
|
||||
|| !EntityManager.TryGetComponent(uid, out AtmosAlarmableComponent? alarmable)
|
||||
|| !EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn))
|
||||
return;
|
||||
|
||||
// ignore packets from self, ignore from different frequency
|
||||
if (netConn.Address == args.SenderAddress) return;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
// sync on alarm or explicit sync
|
||||
case AtmosMonitorAlarmCmd:
|
||||
case AtmosMonitorAlarmSyncCmd:
|
||||
if (args.Data.TryGetValue(AtmosMonitorAlarmSrc, out string? src)
|
||||
&& alarmable.AlarmedByPrototypes.Contains(src)
|
||||
&& args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out AtmosMonitorAlarmType state)
|
||||
&& !component.NetworkAlarmStates.TryAdd(args.SenderAddress, state))
|
||||
component.NetworkAlarmStates[args.SenderAddress] = state;
|
||||
break;
|
||||
case AtmosMonitorAlarmResetAllCmd:
|
||||
if (args.Data.TryGetValue(AtmosMonitorAlarmSrc, out string? resetSrc)
|
||||
&& alarmable.AlarmedByPrototypes.Contains(resetSrc))
|
||||
{
|
||||
component.LastAlarmState = AtmosMonitorAlarmType.Normal;
|
||||
component.NetworkAlarmStates.Clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (component.DisplayMaxAlarmInNet)
|
||||
{
|
||||
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent))
|
||||
appearanceComponent.SetData(AtmosMonitorVisuals.AlarmType, component.HighestAlarmInNetwork);
|
||||
|
||||
if (component.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger) PlayAlertSound(uid, component);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnPowerChangedEvent(EntityUid uid, AtmosMonitorComponent component, PowerChangedEvent args)
|
||||
{
|
||||
if (TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
|
||||
{
|
||||
if (!args.Powered)
|
||||
case AtmosDeviceNetworkSystem.RegisterDevice:
|
||||
component.RegisteredDevices.Add(args.SenderAddress);
|
||||
break;
|
||||
case AtmosAlarmableSystem.ResetAll:
|
||||
Reset(uid);
|
||||
// Don't clear alarm states here.
|
||||
break;
|
||||
case AtmosMonitorSetThresholdCmd:
|
||||
if (args.Data.TryGetValue(AtmosMonitorThresholdData, out AtmosAlarmThreshold? thresholdData)
|
||||
&& args.Data.TryGetValue(AtmosMonitorThresholdDataType, out AtmosMonitorThresholdType? thresholdType))
|
||||
{
|
||||
if (atmosDeviceComponent.JoinedGrid != null)
|
||||
{
|
||||
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
|
||||
component.TileGas = null;
|
||||
}
|
||||
|
||||
// clear memory when power cycled
|
||||
component.LastAlarmState = AtmosMonitorAlarmType.Normal;
|
||||
component.NetworkAlarmStates.Clear();
|
||||
args.Data.TryGetValue(AtmosMonitorThresholdGasType, out Gas? gas);
|
||||
SetThreshold(uid, thresholdType.Value, thresholdData, gas);
|
||||
}
|
||||
else if (args.Powered)
|
||||
|
||||
break;
|
||||
case AtmosDeviceNetworkSystem.SyncData:
|
||||
var payload = new NetworkPayload();
|
||||
payload.Add(DeviceNetworkConstants.Command, AtmosDeviceNetworkSystem.SyncData);
|
||||
if (component.TileGas != null)
|
||||
{
|
||||
if (atmosDeviceComponent.JoinedGrid == null)
|
||||
var gases = new Dictionary<Gas, float>();
|
||||
foreach (var gas in Enum.GetValues<Gas>())
|
||||
{
|
||||
_atmosDeviceSystem.JoinAtmosphere(atmosDeviceComponent);
|
||||
var air = _atmosphereSystem.GetContainingMixture(uid, true);
|
||||
component.TileGas = air;
|
||||
gases.Add(gas, component.TileGas.GetMoles(gas));
|
||||
}
|
||||
|
||||
payload.Add(AtmosDeviceNetworkSystem.SyncData, new AtmosSensorData(
|
||||
component.TileGas.Pressure,
|
||||
component.TileGas.Temperature,
|
||||
component.TileGas.TotalMoles,
|
||||
component.LastAlarmState,
|
||||
gases,
|
||||
component.PressureThreshold ?? new(),
|
||||
component.TemperatureThreshold ?? new(),
|
||||
component.GasThresholds ?? new()
|
||||
));
|
||||
}
|
||||
|
||||
_deviceNetSystem.QueuePacket(uid, args.SenderAddress, payload);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPowerChangedEvent(EntityUid uid, AtmosMonitorComponent component, PowerChangedEvent args)
|
||||
{
|
||||
if (TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent))
|
||||
{
|
||||
if (!args.Powered)
|
||||
{
|
||||
if (atmosDeviceComponent.JoinedGrid != null)
|
||||
{
|
||||
_atmosDeviceSystem.LeaveAtmosphere(atmosDeviceComponent);
|
||||
component.TileGas = null;
|
||||
}
|
||||
}
|
||||
else if (args.Powered)
|
||||
{
|
||||
if (atmosDeviceComponent.JoinedGrid == null)
|
||||
{
|
||||
_atmosDeviceSystem.JoinAtmosphere(atmosDeviceComponent);
|
||||
var air = _atmosphereSystem.GetContainingMixture(uid, true);
|
||||
component.TileGas = air;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent))
|
||||
appearanceComponent.SetData(AtmosMonitorVisuals.AlarmType, component.LastAlarmState);
|
||||
Alert(uid, component.LastAlarmState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFireEvent(EntityUid uid, AtmosMonitorComponent component, ref TileFireEvent args)
|
||||
{
|
||||
if (!this.IsPowered(uid, EntityManager))
|
||||
return;
|
||||
private void OnFireEvent(EntityUid uid, AtmosMonitorComponent component, ref TileFireEvent args)
|
||||
{
|
||||
if (!this.IsPowered(uid, EntityManager))
|
||||
return;
|
||||
|
||||
// if we're monitoring for atmos fire, then we make it similar to a smoke detector
|
||||
// and just outright trigger a danger event
|
||||
//
|
||||
// somebody else can reset it :sunglasses:
|
||||
if (component.MonitorFire
|
||||
&& component.LastAlarmState != AtmosMonitorAlarmType.Danger)
|
||||
Alert(uid, AtmosMonitorAlarmType.Danger, new []{ AtmosMonitorThresholdType.Temperature }, component); // technically???
|
||||
|
||||
// only monitor state elevation so that stuff gets alarmed quicker during a fire,
|
||||
// let the atmos update loop handle when temperature starts to reach different
|
||||
// thresholds and different states than normal -> warning -> danger
|
||||
if (component.TemperatureThreshold != null
|
||||
&& component.TemperatureThreshold.CheckThreshold(args.Temperature, out var temperatureState)
|
||||
&& temperatureState > component.LastAlarmState)
|
||||
Alert(uid, AtmosMonitorAlarmType.Danger, new []{ AtmosMonitorThresholdType.Temperature }, component);
|
||||
}
|
||||
|
||||
private void OnAtmosUpdate(EntityUid uid, AtmosMonitorComponent component, AtmosDeviceUpdateEvent args)
|
||||
{
|
||||
if (!this.IsPowered(uid, EntityManager))
|
||||
return;
|
||||
|
||||
// can't hurt
|
||||
// (in case something is making AtmosDeviceUpdateEvents
|
||||
// outside the typical device loop)
|
||||
if (!TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent)
|
||||
|| atmosDeviceComponent.JoinedGrid == null)
|
||||
return;
|
||||
|
||||
// if we're not monitoring atmos, don't bother
|
||||
if (component.TemperatureThreshold == null
|
||||
&& component.PressureThreshold == null
|
||||
&& component.GasThresholds == null)
|
||||
return;
|
||||
|
||||
UpdateState(uid, component.TileGas, component);
|
||||
}
|
||||
|
||||
// Update checks the current air if it exceeds thresholds of
|
||||
// any kind.
|
||||
// if we're monitoring for atmos fire, then we make it similar to a smoke detector
|
||||
// and just outright trigger a danger event
|
||||
//
|
||||
// If any threshold exceeds the other, that threshold
|
||||
// immediately replaces the current recorded state.
|
||||
//
|
||||
// If the threshold does not match the current state
|
||||
// of the monitor, it is set in the Alert call.
|
||||
private void UpdateState(EntityUid uid, GasMixture? air, AtmosMonitorComponent? monitor = null)
|
||||
// somebody else can reset it :sunglasses:
|
||||
if (component.MonitorFire
|
||||
&& component.LastAlarmState != AtmosAlarmType.Danger)
|
||||
{
|
||||
if (air == null) return;
|
||||
component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature);
|
||||
Alert(uid, AtmosAlarmType.Danger, null, component); // technically???
|
||||
}
|
||||
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
// only monitor state elevation so that stuff gets alarmed quicker during a fire,
|
||||
// let the atmos update loop handle when temperature starts to reach different
|
||||
// thresholds and different states than normal -> warning -> danger
|
||||
if (component.TemperatureThreshold != null
|
||||
&& component.TemperatureThreshold.CheckThreshold(args.Temperature, out var temperatureState)
|
||||
&& temperatureState > component.LastAlarmState)
|
||||
{
|
||||
component.TrippedThresholds.Add(AtmosMonitorThresholdType.Temperature);
|
||||
Alert(uid, AtmosAlarmType.Danger, null, component);
|
||||
}
|
||||
}
|
||||
|
||||
AtmosMonitorAlarmType state = AtmosMonitorAlarmType.Normal;
|
||||
List<AtmosMonitorThresholdType> alarmTypes = new();
|
||||
private void OnAtmosUpdate(EntityUid uid, AtmosMonitorComponent component, AtmosDeviceUpdateEvent args)
|
||||
{
|
||||
if (!this.IsPowered(uid, EntityManager))
|
||||
return;
|
||||
|
||||
if (monitor.TemperatureThreshold != null
|
||||
&& monitor.TemperatureThreshold.CheckThreshold(air.Temperature, out var temperatureState)
|
||||
&& temperatureState > state)
|
||||
// can't hurt
|
||||
// (in case something is making AtmosDeviceUpdateEvents
|
||||
// outside the typical device loop)
|
||||
if (!TryComp<AtmosDeviceComponent>(uid, out var atmosDeviceComponent)
|
||||
|| atmosDeviceComponent.JoinedGrid == null)
|
||||
return;
|
||||
|
||||
// if we're not monitoring atmos, don't bother
|
||||
if (component.TemperatureThreshold == null
|
||||
&& component.PressureThreshold == null
|
||||
&& component.GasThresholds == null)
|
||||
return;
|
||||
|
||||
UpdateState(uid, component.TileGas, component);
|
||||
}
|
||||
|
||||
// Update checks the current air if it exceeds thresholds of
|
||||
// any kind.
|
||||
//
|
||||
// If any threshold exceeds the other, that threshold
|
||||
// immediately replaces the current recorded state.
|
||||
//
|
||||
// If the threshold does not match the current state
|
||||
// of the monitor, it is set in the Alert call.
|
||||
private void UpdateState(EntityUid uid, GasMixture? air, AtmosMonitorComponent? monitor = null)
|
||||
{
|
||||
if (air == null) return;
|
||||
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
|
||||
var state = AtmosAlarmType.Normal;
|
||||
HashSet<AtmosMonitorThresholdType> alarmTypes = new(monitor.TrippedThresholds);
|
||||
|
||||
if (monitor.TemperatureThreshold != null
|
||||
&& monitor.TemperatureThreshold.CheckThreshold(air.Temperature, out var temperatureState))
|
||||
{
|
||||
if (temperatureState > state)
|
||||
{
|
||||
state = temperatureState;
|
||||
alarmTypes.Add(AtmosMonitorThresholdType.Temperature);
|
||||
}
|
||||
else if (temperatureState == AtmosAlarmType.Normal)
|
||||
{
|
||||
alarmTypes.Remove(AtmosMonitorThresholdType.Temperature);
|
||||
}
|
||||
}
|
||||
|
||||
if (monitor.PressureThreshold != null
|
||||
&& monitor.PressureThreshold.CheckThreshold(air.Pressure, out var pressureState)
|
||||
&& pressureState > state)
|
||||
if (monitor.PressureThreshold != null
|
||||
&& monitor.PressureThreshold.CheckThreshold(air.Pressure, out var pressureState)
|
||||
)
|
||||
{
|
||||
if (pressureState > state)
|
||||
{
|
||||
state = pressureState;
|
||||
alarmTypes.Add(AtmosMonitorThresholdType.Pressure);
|
||||
}
|
||||
|
||||
if (monitor.GasThresholds != null)
|
||||
else if (pressureState == AtmosAlarmType.Normal)
|
||||
{
|
||||
foreach (var (gas, threshold) in monitor.GasThresholds)
|
||||
alarmTypes.Remove(AtmosMonitorThresholdType.Pressure);
|
||||
}
|
||||
}
|
||||
|
||||
if (monitor.GasThresholds != null)
|
||||
{
|
||||
var tripped = false;
|
||||
foreach (var (gas, threshold) in monitor.GasThresholds)
|
||||
{
|
||||
var gasRatio = air.GetMoles(gas) / air.TotalMoles;
|
||||
if (threshold.CheckThreshold(gasRatio, out var gasState)
|
||||
&& gasState > state)
|
||||
{
|
||||
var gasRatio = air.GetMoles(gas) / air.TotalMoles;
|
||||
if (threshold.CheckThreshold(gasRatio, out var gasState)
|
||||
&& gasState > state)
|
||||
{
|
||||
state = gasState;
|
||||
alarmTypes.Add(AtmosMonitorThresholdType.Gas);
|
||||
}
|
||||
state = gasState;
|
||||
tripped = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if the state of the current air doesn't match the last alarm state,
|
||||
// we update the state
|
||||
if (state != monitor.LastAlarmState)
|
||||
if (tripped)
|
||||
{
|
||||
Alert(uid, state, alarmTypes, monitor);
|
||||
alarmTypes.Add(AtmosMonitorThresholdType.Gas);
|
||||
}
|
||||
else
|
||||
{
|
||||
alarmTypes.Remove(AtmosMonitorThresholdType.Gas);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alerts the network that the state of a monitor has changed.
|
||||
/// </summary>
|
||||
/// <param name="state">The alarm state to set this monitor to.</param>
|
||||
/// <param name="alarms">The alarms that caused this alarm state.</param>
|
||||
public void Alert(EntityUid uid, AtmosMonitorAlarmType state, IEnumerable<AtmosMonitorThresholdType>? alarms = null, AtmosMonitorComponent? monitor = null)
|
||||
// if the state of the current air doesn't match the last alarm state,
|
||||
// we update the state
|
||||
if (state != monitor.LastAlarmState || !alarmTypes.SetEquals(monitor.TrippedThresholds))
|
||||
{
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
monitor.LastAlarmState = state;
|
||||
if (EntityManager.TryGetComponent(monitor.Owner, out AppearanceComponent? appearanceComponent))
|
||||
appearanceComponent.SetData(AtmosMonitorVisuals.AlarmType, monitor.LastAlarmState);
|
||||
|
||||
BroadcastAlertPacket(monitor, alarms);
|
||||
|
||||
if (state == AtmosMonitorAlarmType.Danger) PlayAlertSound(uid, monitor);
|
||||
|
||||
if (EntityManager.TryGetComponent(monitor.Owner, out AtmosAlarmableComponent? alarmable)
|
||||
&& !alarmable.IgnoreAlarms)
|
||||
RaiseLocalEvent(monitor.Owner, new AtmosMonitorAlarmEvent(monitor.LastAlarmState, monitor.HighestAlarmInNetwork), true);
|
||||
// TODO: Central system that grabs *all* alarms from wired network
|
||||
}
|
||||
|
||||
private void PlayAlertSound(EntityUid uid, AtmosMonitorComponent? monitor = null)
|
||||
{
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
|
||||
SoundSystem.Play(monitor.AlarmSound.GetSound(), Filter.Pvs(uid), uid, AudioParams.Default.WithVolume(monitor.AlarmVolume));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets a single monitor's alarm.
|
||||
/// </summary>
|
||||
public void Reset(EntityUid uid) =>
|
||||
Alert(uid, AtmosMonitorAlarmType.Normal);
|
||||
|
||||
/// <summary>
|
||||
/// Resets a network's alarms, using this monitor as a source.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The resulting packet will have this monitor set as the source, using its prototype ID if it has one - otherwise just sending an empty string.
|
||||
/// </remarks>
|
||||
public void ResetAll(EntityUid uid, AtmosMonitorComponent? monitor = null)
|
||||
{
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
|
||||
var prototype = Prototype(monitor.Owner);
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = AtmosMonitorAlarmResetAllCmd,
|
||||
[AtmosMonitorAlarmSrc] = prototype != null ? prototype.ID : string.Empty
|
||||
};
|
||||
|
||||
_deviceNetSystem.QueuePacket(monitor.Owner, null, payload);
|
||||
monitor.NetworkAlarmStates.Clear();
|
||||
|
||||
Alert(uid, AtmosMonitorAlarmType.Normal, null, monitor);
|
||||
}
|
||||
|
||||
// (TODO: maybe just cache monitors in other monitors?)
|
||||
/// <summary>
|
||||
/// Syncs the current state of this monitor to the network (to avoid alerting other monitors).
|
||||
/// </summary>
|
||||
private void Sync(AtmosMonitorComponent monitor)
|
||||
{
|
||||
if (!monitor.NetEnabled) return;
|
||||
|
||||
var prototype = Prototype(monitor.Owner);
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = AtmosMonitorAlarmSyncCmd,
|
||||
[DeviceNetworkConstants.CmdSetState] = monitor.LastAlarmState,
|
||||
[AtmosMonitorAlarmSrc] = prototype != null ? prototype.ID : string.Empty
|
||||
};
|
||||
|
||||
_deviceNetSystem.QueuePacket(monitor.Owner, null, payload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts an alert packet to all devices on the network,
|
||||
/// which consists of the current alarm types,
|
||||
/// the highest alarm currently cached by this monitor,
|
||||
/// and the current alarm state of the monitor (so other
|
||||
/// alarms can sync to it).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Alarmables use the highest alarm to ensure that a monitor's
|
||||
/// state doesn't override if the alarm is lower. The state
|
||||
/// is synced between monitors the moment a monitor sends out an alarm,
|
||||
/// or if it is explicitly synced (see ResetAll/Sync).
|
||||
/// </remarks>
|
||||
private void BroadcastAlertPacket(AtmosMonitorComponent monitor, IEnumerable<AtmosMonitorThresholdType>? alarms = null)
|
||||
{
|
||||
if (!monitor.NetEnabled) return;
|
||||
|
||||
string source = string.Empty;
|
||||
if (alarms == null) alarms = new List<AtmosMonitorThresholdType>();
|
||||
var prototype = Prototype(monitor.Owner);
|
||||
if (prototype != null) source = prototype.ID;
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = AtmosMonitorAlarmCmd,
|
||||
[DeviceNetworkConstants.CmdSetState] = monitor.LastAlarmState,
|
||||
[AtmosMonitorAlarmNetMax] = monitor.HighestAlarmInNetwork,
|
||||
[AtmosMonitorAlarmThresholdTypes] = alarms,
|
||||
[AtmosMonitorAlarmSrc] = source
|
||||
};
|
||||
|
||||
_deviceNetSystem.QueuePacket(monitor.Owner, null, payload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a monitor's threshold.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of threshold to change.</param>
|
||||
/// <param name="threshold">Threshold data.</param>
|
||||
/// <param name="gas">Gas, if applicable.</param>
|
||||
public void SetThreshold(EntityUid uid, AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null, AtmosMonitorComponent? monitor = null)
|
||||
{
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case AtmosMonitorThresholdType.Pressure:
|
||||
monitor.PressureThreshold = threshold;
|
||||
break;
|
||||
case AtmosMonitorThresholdType.Temperature:
|
||||
monitor.TemperatureThreshold = threshold;
|
||||
break;
|
||||
case AtmosMonitorThresholdType.Gas:
|
||||
if (gas == null || monitor.GasThresholds == null) return;
|
||||
monitor.GasThresholds[(Gas) gas] = threshold;
|
||||
break;
|
||||
}
|
||||
|
||||
Alert(uid, state, alarmTypes, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AtmosMonitorAlarmEvent : EntityEventArgs
|
||||
/// <summary>
|
||||
/// Alerts the network that the state of a monitor has changed.
|
||||
/// </summary>
|
||||
/// <param name="state">The alarm state to set this monitor to.</param>
|
||||
/// <param name="alarms">The alarms that caused this alarm state.</param>
|
||||
public void Alert(EntityUid uid, AtmosAlarmType state, HashSet<AtmosMonitorThresholdType>? alarms = null, AtmosMonitorComponent? monitor = null)
|
||||
{
|
||||
public AtmosMonitorAlarmType Type { get; }
|
||||
public AtmosMonitorAlarmType HighestNetworkType { get; }
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
|
||||
public AtmosMonitorAlarmEvent(AtmosMonitorAlarmType type, AtmosMonitorAlarmType netMax)
|
||||
monitor.LastAlarmState = state;
|
||||
monitor.TrippedThresholds = alarms ?? monitor.TrippedThresholds;
|
||||
|
||||
BroadcastAlertPacket(monitor);
|
||||
|
||||
// TODO: Central system that grabs *all* alarms from wired network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets a single monitor's alarm.
|
||||
/// </summary>
|
||||
private void Reset(EntityUid uid)
|
||||
{
|
||||
Alert(uid, AtmosAlarmType.Normal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcasts an alert packet to all devices on the network,
|
||||
/// which consists of the current alarm types,
|
||||
/// the highest alarm currently cached by this monitor,
|
||||
/// and the current alarm state of the monitor (so other
|
||||
/// alarms can sync to it).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Alarmables use the highest alarm to ensure that a monitor's
|
||||
/// state doesn't override if the alarm is lower. The state
|
||||
/// is synced between monitors the moment a monitor sends out an alarm,
|
||||
/// or if it is explicitly synced (see ResetAll/Sync).
|
||||
/// </remarks>
|
||||
private void BroadcastAlertPacket(AtmosMonitorComponent monitor, TagComponent? tags = null)
|
||||
{
|
||||
if (!monitor.NetEnabled) return;
|
||||
|
||||
if (!Resolve(monitor.Owner, ref tags))
|
||||
{
|
||||
Type = type;
|
||||
HighestNetworkType = netMax;
|
||||
return;
|
||||
}
|
||||
|
||||
var payload = new NetworkPayload
|
||||
{
|
||||
[DeviceNetworkConstants.Command] = AtmosAlarmableSystem.AlertCmd,
|
||||
[DeviceNetworkConstants.CmdSetState] = monitor.LastAlarmState,
|
||||
[AtmosAlarmableSystem.AlertSource] = tags.Tags,
|
||||
[AtmosAlarmableSystem.AlertTypes] = monitor.TrippedThresholds
|
||||
};
|
||||
|
||||
foreach (var addr in monitor.RegisteredDevices)
|
||||
{
|
||||
_deviceNetSystem.QueuePacket(monitor.Owner, addr, payload);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a monitor's threshold.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of threshold to change.</param>
|
||||
/// <param name="threshold">Threshold data.</param>
|
||||
/// <param name="gas">Gas, if applicable.</param>
|
||||
public void SetThreshold(EntityUid uid, AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null, AtmosMonitorComponent? monitor = null)
|
||||
{
|
||||
if (!Resolve(uid, ref monitor)) return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case AtmosMonitorThresholdType.Pressure:
|
||||
monitor.PressureThreshold = threshold;
|
||||
break;
|
||||
case AtmosMonitorThresholdType.Temperature:
|
||||
monitor.TemperatureThreshold = threshold;
|
||||
break;
|
||||
case AtmosMonitorThresholdType.Gas:
|
||||
if (gas == null || monitor.GasThresholds == null) return;
|
||||
monitor.GasThresholds[(Gas) gas] = threshold;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.AlertLevel;
|
||||
using Content.Server.Atmos.Monitor.Components;
|
||||
using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.AlertLevel;
|
||||
@@ -8,50 +9,57 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Atmos.Monitor.Systems
|
||||
namespace Content.Server.Atmos.Monitor.Systems;
|
||||
|
||||
public sealed class FireAlarmSystem : EntitySystem
|
||||
{
|
||||
public sealed class FireAlarmSystem : EntitySystem
|
||||
[Dependency] private readonly AtmosDeviceNetworkSystem _atmosDevNet = default!;
|
||||
[Dependency] private readonly AtmosAlarmableSystem _atmosAlarmable = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
[Dependency] private readonly AtmosMonitorSystem _monitorSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
SubscribeLocalEvent<FireAlarmComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<FireAlarmComponent, DeviceListUpdateEvent>(OnDeviceListSync);
|
||||
SubscribeLocalEvent<FireAlarmComponent, GotEmaggedEvent>(OnEmagged);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
private void OnDeviceListSync(EntityUid uid, FireAlarmComponent component, DeviceListUpdateEvent args)
|
||||
{
|
||||
_atmosDevNet.Register(uid, null);
|
||||
_atmosDevNet.Sync(uid, null);
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, FireAlarmComponent component, InteractHandEvent args)
|
||||
{
|
||||
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
|
||||
return;
|
||||
|
||||
if (this.IsPowered(uid, EntityManager))
|
||||
{
|
||||
SubscribeLocalEvent<FireAlarmComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<FireAlarmComponent, GotEmaggedEvent>(OnEmagged);
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, FireAlarmComponent component, InteractHandEvent args)
|
||||
{
|
||||
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent(args.User, out ActorComponent? actor)
|
||||
&& EntityManager.TryGetComponent(uid, out AtmosMonitorComponent? monitor)
|
||||
&& this.IsPowered(uid, EntityManager))
|
||||
if (!_atmosAlarmable.TryGetHighestAlert(uid, out var alarm))
|
||||
{
|
||||
if (monitor.HighestAlarmInNetwork == AtmosMonitorAlarmType.Normal)
|
||||
{
|
||||
_monitorSystem.Alert(uid, AtmosMonitorAlarmType.Danger);
|
||||
}
|
||||
else
|
||||
{
|
||||
_monitorSystem.ResetAll(uid);
|
||||
}
|
||||
alarm = AtmosAlarmType.Normal;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEmagged(EntityUid uid, FireAlarmComponent component, GotEmaggedEvent args)
|
||||
{
|
||||
if (TryComp<AtmosMonitorComponent>(uid, out var atmosMonitor))
|
||||
if (alarm == AtmosAlarmType.Normal)
|
||||
{
|
||||
if (atmosMonitor?.MonitorFire == true)
|
||||
{
|
||||
atmosMonitor.MonitorFire = false;
|
||||
_monitorSystem.Alert(uid, AtmosMonitorAlarmType.Emagged);
|
||||
args.Handled = true;
|
||||
}
|
||||
_atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Danger);
|
||||
}
|
||||
else
|
||||
{
|
||||
_atmosAlarmable.ResetAllOnNetwork(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEmagged(EntityUid uid, FireAlarmComponent component, GotEmaggedEvent args)
|
||||
{
|
||||
if (TryComp<AtmosAlarmableComponent>(uid, out var alarmable))
|
||||
{
|
||||
// Remove the atmos alarmable component permanently from this device.
|
||||
_atmosAlarmable.ForceAlert(uid, AtmosAlarmType.Emagged, alarmable);
|
||||
RemCompDeferred<AtmosAlarmableComponent>(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public sealed class AirAlarmPanicWire : BaseWireAction
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_airAlarmSystem = EntitySystem.Get<AirAlarmSystem>();
|
||||
_airAlarmSystem = EntityManager.System<AirAlarmSystem>();
|
||||
}
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
|
||||
@@ -17,7 +17,7 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
private string _text = "NETW";
|
||||
private Color _color = Color.Orange;
|
||||
|
||||
private AtmosMonitorSystem _atmosMonitorSystem = default!;
|
||||
private AtmosAlarmableSystem _atmosAlarmableSystem = default!;
|
||||
|
||||
public override object StatusKey { get; } = AtmosMonitorAlarmWireActionKeys.Network;
|
||||
|
||||
@@ -27,7 +27,12 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
|
||||
if (IsPowered(wire.Owner) && EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
lightState = monitor.HighestAlarmInNetwork == AtmosMonitorAlarmType.Danger
|
||||
if (!_atmosAlarmableSystem.TryGetHighestAlert(wire.Owner, out var alarm))
|
||||
{
|
||||
alarm = AtmosAlarmType.Normal;
|
||||
}
|
||||
|
||||
lightState = alarm == AtmosAlarmType.Danger
|
||||
? StatusLightState.BlinkingFast
|
||||
: StatusLightState.On;
|
||||
}
|
||||
@@ -42,14 +47,14 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_atmosMonitorSystem = EntitySystem.Get<AtmosMonitorSystem>();
|
||||
_atmosAlarmableSystem = EntityManager.System<AtmosAlarmableSystem>();
|
||||
}
|
||||
|
||||
public override bool Cut(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor))
|
||||
if (EntityManager.TryGetComponent<AtmosAlarmableComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
monitor.NetEnabled = false;
|
||||
monitor.IgnoreAlarms = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -57,9 +62,9 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
|
||||
public override bool Mend(EntityUid user, Wire wire)
|
||||
{
|
||||
if (EntityManager.TryGetComponent<AtmosMonitorComponent>(wire.Owner, out var monitor))
|
||||
if (EntityManager.TryGetComponent<AtmosAlarmableComponent>(wire.Owner, out var monitor))
|
||||
{
|
||||
monitor.NetEnabled = true;
|
||||
monitor.IgnoreAlarms = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -69,7 +74,7 @@ public sealed class AtmosMonitorDeviceNetWire : BaseWireAction
|
||||
{
|
||||
if (_alarmOnPulse)
|
||||
{
|
||||
_atmosMonitorSystem.Alert(wire.Owner, AtmosMonitorAlarmType.Danger);
|
||||
_atmosAlarmableSystem.ForceAlert(wire.Owner, AtmosAlarmType.Danger);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -38,7 +38,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceUpdateEvent>(OnGasVentPumpUpdated);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceDisabledEvent>(OnGasVentPumpLeaveAtmosphere);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosDeviceEnabledEvent>(OnGasVentPumpEnterAtmosphere);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, AtmosAlarmEvent>(OnAtmosAlarm);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||
SubscribeLocalEvent<GasVentPumpComponent, ComponentInit>(OnInit);
|
||||
@@ -158,13 +158,13 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
UpdateState(uid, component);
|
||||
}
|
||||
|
||||
private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosMonitorAlarmEvent args)
|
||||
private void OnAtmosAlarm(EntityUid uid, GasVentPumpComponent component, AtmosAlarmEvent args)
|
||||
{
|
||||
if (args.HighestNetworkType == AtmosMonitorAlarmType.Danger)
|
||||
if (args.AlarmType == AtmosAlarmType.Danger)
|
||||
{
|
||||
component.Enabled = false;
|
||||
}
|
||||
else if (args.HighestNetworkType == AtmosMonitorAlarmType.Normal)
|
||||
else if (args.AlarmType == AtmosAlarmType.Normal)
|
||||
{
|
||||
component.Enabled = true;
|
||||
}
|
||||
@@ -181,7 +181,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
private void OnPacketRecv(EntityUid uid, GasVentPumpComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)
|
||||
|| !EntityManager.TryGetComponent(uid, out AtmosAlarmableComponent? alarmable)
|
||||
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
|
||||
return;
|
||||
|
||||
@@ -189,24 +188,19 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case AirAlarmSystem.AirAlarmSyncCmd:
|
||||
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSyncData);
|
||||
payload.Add(AirAlarmSystem.AirAlarmSyncData, component.ToAirAlarmData());
|
||||
case AtmosDeviceNetworkSystem.SyncData:
|
||||
payload.Add(DeviceNetworkConstants.Command, AtmosDeviceNetworkSystem.SyncData);
|
||||
payload.Add(AtmosDeviceNetworkSystem.SyncData, component.ToAirAlarmData());
|
||||
|
||||
_deviceNetSystem.QueuePacket(uid, args.SenderAddress, payload, device: netConn);
|
||||
|
||||
return;
|
||||
case AirAlarmSystem.AirAlarmSetData:
|
||||
if (!args.Data.TryGetValue(AirAlarmSystem.AirAlarmSetData, out GasVentPumpData? setData))
|
||||
case DeviceNetworkConstants.CmdSetState:
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out GasVentPumpData? setData))
|
||||
break;
|
||||
|
||||
component.FromAirAlarmData(setData);
|
||||
UpdateState(uid, component);
|
||||
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
|
||||
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
|
||||
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
|
||||
|
||||
_deviceNetSystem.QueuePacket(uid, null, payload, device: netConn);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceUpdateEvent>(OnVentScrubberUpdated);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceEnabledEvent>(OnVentScrubberEnterAtmosphere);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosDeviceDisabledEvent>(OnVentScrubberLeaveAtmosphere);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, AtmosAlarmEvent>(OnAtmosAlarm);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<GasVentScrubberComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
|
||||
}
|
||||
@@ -124,13 +124,13 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, AtmosMonitorAlarmEvent args)
|
||||
private void OnAtmosAlarm(EntityUid uid, GasVentScrubberComponent component, AtmosAlarmEvent args)
|
||||
{
|
||||
if (args.HighestNetworkType == AtmosMonitorAlarmType.Danger)
|
||||
if (args.AlarmType == AtmosAlarmType.Danger)
|
||||
{
|
||||
component.Enabled = false;
|
||||
}
|
||||
else if (args.HighestNetworkType == AtmosMonitorAlarmType.Normal)
|
||||
else if (args.AlarmType == AtmosAlarmType.Normal)
|
||||
{
|
||||
component.Enabled = true;
|
||||
}
|
||||
@@ -147,7 +147,6 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
private void OnPacketRecv(EntityUid uid, GasVentScrubberComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn)
|
||||
|| !EntityManager.TryGetComponent(uid, out AtmosAlarmableComponent? alarmable)
|
||||
|| !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
|
||||
return;
|
||||
|
||||
@@ -155,24 +154,19 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case AirAlarmSystem.AirAlarmSyncCmd:
|
||||
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSyncData);
|
||||
payload.Add(AirAlarmSystem.AirAlarmSyncData, component.ToAirAlarmData());
|
||||
case AtmosDeviceNetworkSystem.SyncData:
|
||||
payload.Add(DeviceNetworkConstants.Command, AtmosDeviceNetworkSystem.SyncData);
|
||||
payload.Add(AtmosDeviceNetworkSystem.SyncData, component.ToAirAlarmData());
|
||||
|
||||
_deviceNetSystem.QueuePacket(uid, args.SenderAddress, payload, device: netConn);
|
||||
|
||||
return;
|
||||
case AirAlarmSystem.AirAlarmSetData:
|
||||
if (!args.Data.TryGetValue(AirAlarmSystem.AirAlarmSetData, out GasVentScrubberData? setData))
|
||||
case DeviceNetworkConstants.CmdSetState:
|
||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.CmdSetState, out GasVentScrubberData? setData))
|
||||
break;
|
||||
|
||||
component.FromAirAlarmData(setData);
|
||||
UpdateState(uid, component);
|
||||
alarmable.IgnoreAlarms = setData.IgnoreAlarms;
|
||||
payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
|
||||
payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);
|
||||
|
||||
_deviceNetSystem.QueuePacket(uid, null, payload, device: netConn);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user