diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs index 2368b17890..cb565712e9 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs @@ -1,3 +1,4 @@ +using System.Linq; using Content.Server.Atmos.Monitor.Components; using Content.Server.Atmos.Piping.Components; using Content.Server.DeviceNetwork; @@ -158,6 +159,26 @@ namespace Content.Server.Atmos.Monitor.Systems _deviceNet.QueuePacket(uid, address, payload); } + private void SetThreshold(EntityUid uid, string address, AtmosMonitorThresholdType type, + AtmosAlarmThreshold threshold, Gas? gas = null) + { + var payload = new NetworkPayload + { + [DeviceNetworkConstants.Command] = AtmosMonitorSystem.AtmosMonitorSetThresholdCmd, + [AtmosMonitorSystem.AtmosMonitorThresholdDataType] = type, + [AtmosMonitorSystem.AtmosMonitorThresholdData] = threshold, + }; + + if (gas != null) + { + payload.Add(AtmosMonitorSystem.AtmosMonitorThresholdGasType, gas); + } + + _deviceNet.QueuePacket(uid, address, payload); + + SyncDevice(uid, address); + } + /// /// Sync this air alarm's mode with the rest of the network. /// @@ -273,7 +294,7 @@ namespace Content.Server.Atmos.Monitor.Systems private void OnUpdateThreshold(EntityUid uid, AirAlarmComponent component, AirAlarmUpdateAlarmThresholdMessage args) { if (AccessCheck(uid, args.Session.AttachedEntity, component)) - SetThreshold(uid, args.Threshold, args.Type, args.Gas); + SetThreshold(uid, args.Address, args.Type, args.Threshold, args.Gas); else UpdateUI(uid, component); } @@ -339,20 +360,6 @@ namespace Content.Server.Atmos.Monitor.Systems #region Air Alarm Settings - /// - /// Set a threshold on an air alarm. - /// - /// New threshold data. - public void SetThreshold(EntityUid uid, AtmosAlarmThreshold threshold, AtmosMonitorThresholdType type, Gas? gas = null, AirAlarmComponent? controller = null) - { - if (!Resolve(uid, ref controller)) return; - - _atmosMonitorSystem.SetThreshold(uid, type, threshold, gas); - - // TODO: Use BUI states instead... - _uiSystem.TrySendUiMessage(uid, SharedAirAlarmInterfaceKey.Key, new AirAlarmUpdateAlarmThresholdMessage(type, threshold, gas)); - } - /// /// Set an air alarm's mode. /// @@ -413,45 +420,6 @@ namespace Content.Server.Atmos.Monitor.Systems SetData(uid, address, devData); } - private void OnAtmosAlarm(EntityUid uid, AirAlarmComponent component, NetworkPayload args) - { - if (component.ActivePlayers.Count != 0) - { - SyncAllDevices(uid); - } - - string addr = string.Empty; - if (TryComp(uid, out DeviceNetworkComponent? netConn)) - { - addr = netConn.Address; - } - - if (!args.TryGetValue(AtmosMonitorSystem.AtmosMonitorAlarmNetMax, out AtmosMonitorAlarmType? highestNetworkType)) - { - return; - } - - if (highestNetworkType == AtmosMonitorAlarmType.Danger) - { - SetMode(uid, addr, AirAlarmMode.None, true); - // set mode to off to mimic the vents/scrubbers being turned off - // update UI - // - // no, the mode isn't processed here - it's literally just - // set to what mimics 'off' - } - else if (highestNetworkType == AtmosMonitorAlarmType.Normal) - { - // if the mode is still set to off, set it to filtering instead - // alternatively, set it to the last saved mode - // - // no, this still doesn't execute the mode - SetMode(uid, addr, AirAlarmMode.Filtering, true); - } - - UpdateUI(uid, component); - } - private void OnPacketRecv(EntityUid uid, AirAlarmComponent controller, DeviceNetworkPacketEvent args) { if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd)) @@ -539,6 +507,16 @@ namespace Content.Server.Atmos.Monitor.Systems alarm.CurrentModeUpdater.Update(uid); } + private float CalculatePressureAverage(AirAlarmComponent alarm) + { + return alarm.SensorData.Values.Select(v => v.Pressure).Average(); + } + + private float CalculateTemperatureAverage(AirAlarmComponent alarm) + { + return alarm.SensorData.Values.Select(v => v.Temperature).Average(); + } + public void UpdateUI(EntityUid uid, AirAlarmComponent? alarm = null, AtmosAlarmableComponent? alarmable = null) { if (!Resolve(uid, ref alarm, ref alarmable)) @@ -546,6 +524,8 @@ namespace Content.Server.Atmos.Monitor.Systems return; } + var pressure = CalculatePressureAverage(uid, alarm); + var temperature = CalculateTemperatureAverage(uid, alarm); var dataToSend = new Dictionary(); if (alarm.CurrentTab != AirAlarmTab.Settings) @@ -579,7 +559,7 @@ namespace Content.Server.Atmos.Monitor.Systems _uiSystem.TrySetUiState( uid, SharedAirAlarmInterfaceKey.Key, - new AirAlarmUIState(dataToSend, alarm.CurrentMode, alarm.CurrentTab, alarmable.HighestNetworkState)); + new AirAlarmUIState(pressure, temperature, dataToSend, alarm.CurrentMode, alarm.CurrentTab, alarmable.HighestNetworkState)); } private const float _delay = 8f; diff --git a/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs b/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs index b7075ee976..3e9e21ffe8 100644 --- a/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs +++ b/Content.Shared/Atmos/Monitor/Components/SharedAirAlarmComponent.cs @@ -27,27 +27,6 @@ namespace Content.Shared.Atmos.Monitor.Components DeviceSync } - [Serializable, NetSerializable] - public readonly struct AirAlarmAirData - { - public readonly float? Pressure { get; } - public readonly float? Temperature { get; } - public readonly float? TotalMoles { get; } - public readonly AtmosMonitorAlarmType AlarmState { get; } - - private readonly Dictionary? _gases; - public readonly IReadOnlyDictionary? Gases { get => _gases; } - - public AirAlarmAirData(float? pressure, float? temperature, float? moles, AtmosMonitorAlarmType state, Dictionary? gases) - { - Pressure = pressure; - Temperature = temperature; - TotalMoles = moles; - AlarmState = state; - _gases = gases; - } - } - public interface IAtmosDeviceData { public bool Enabled { get; set; } @@ -58,14 +37,18 @@ namespace Content.Shared.Atmos.Monitor.Components [Serializable, NetSerializable] public sealed class AirAlarmUIState : BoundUserInterfaceState { - public AirAlarmUIState(Dictionary deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosMonitorAlarmType alarmType) + public AirAlarmUIState(float pressureAverage, float temperatureAverage, Dictionary deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosMonitorAlarmType alarmType) { + PressureAverage = pressureAverage; + TemperatureAverage = temperatureAverage; DeviceData = deviceData; Mode = mode; Tab = tab; AlarmType = alarmType; } + public float PressureAverage { get; } + public float TemperatureAverage { get; } /// /// Every single device data that can be seen from this /// air alarm. This includes vents, scrubbers, and sensors. @@ -81,6 +64,11 @@ namespace Content.Shared.Atmos.Monitor.Components [Serializable, NetSerializable] public sealed class AirAlarmTabSetMessage : BoundUserInterfaceMessage { + public AirAlarmTabSetMessage(AirAlarmTab tab) + { + Tab = tab; + } + public AirAlarmTab Tab { get; } } @@ -88,28 +76,6 @@ namespace Content.Shared.Atmos.Monitor.Components public sealed class AirAlarmResyncAllDevicesMessage : BoundUserInterfaceMessage {} - [Serializable, NetSerializable] - public sealed class AirAlarmSetAddressMessage : BoundUserInterfaceMessage - { - public string Address { get; } - - public AirAlarmSetAddressMessage(string address) - { - Address = address; - } - } - - [Serializable, NetSerializable] - public sealed class AirAlarmUpdateAirDataMessage : BoundUserInterfaceMessage - { - public AirAlarmAirData AirData; - - public AirAlarmUpdateAirDataMessage(AirAlarmAirData airData) - { - AirData = airData; - } - } - [Serializable, NetSerializable] public sealed class AirAlarmUpdateAlarmModeMessage : BoundUserInterfaceMessage { @@ -137,12 +103,14 @@ namespace Content.Shared.Atmos.Monitor.Components [Serializable, NetSerializable] public sealed class AirAlarmUpdateAlarmThresholdMessage : BoundUserInterfaceMessage { + public string Address { get; } public AtmosAlarmThreshold Threshold { get; } public AtmosMonitorThresholdType Type { get; } public Gas? Gas { get; } - public AirAlarmUpdateAlarmThresholdMessage(AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null) + public AirAlarmUpdateAlarmThresholdMessage(string address, AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null) { + Address = address; Threshold = threshold; Type = type; Gas = gas;