set threshold on server, pressure/temperature average from all sensors sent with air alarm state
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Linq;
|
||||||
using Content.Server.Atmos.Monitor.Components;
|
using Content.Server.Atmos.Monitor.Components;
|
||||||
using Content.Server.Atmos.Piping.Components;
|
using Content.Server.Atmos.Piping.Components;
|
||||||
using Content.Server.DeviceNetwork;
|
using Content.Server.DeviceNetwork;
|
||||||
@@ -158,6 +159,26 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
_deviceNet.QueuePacket(uid, address, payload);
|
_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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sync this air alarm's mode with the rest of the network.
|
/// Sync this air alarm's mode with the rest of the network.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -273,7 +294,7 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
private void OnUpdateThreshold(EntityUid uid, AirAlarmComponent component, AirAlarmUpdateAlarmThresholdMessage args)
|
private void OnUpdateThreshold(EntityUid uid, AirAlarmComponent component, AirAlarmUpdateAlarmThresholdMessage args)
|
||||||
{
|
{
|
||||||
if (AccessCheck(uid, args.Session.AttachedEntity, component))
|
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
|
else
|
||||||
UpdateUI(uid, component);
|
UpdateUI(uid, component);
|
||||||
}
|
}
|
||||||
@@ -339,20 +360,6 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
|
|
||||||
#region Air Alarm Settings
|
#region Air Alarm Settings
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set a threshold on an air alarm.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="threshold">New threshold data.</param>
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set an air alarm's mode.
|
/// Set an air alarm's mode.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -413,45 +420,6 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
SetData(uid, address, devData);
|
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)
|
private void OnPacketRecv(EntityUid uid, AirAlarmComponent controller, DeviceNetworkPacketEvent args)
|
||||||
{
|
{
|
||||||
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd))
|
if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? cmd))
|
||||||
@@ -539,6 +507,16 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
alarm.CurrentModeUpdater.Update(uid);
|
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)
|
public void UpdateUI(EntityUid uid, AirAlarmComponent? alarm = null, AtmosAlarmableComponent? alarmable = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref alarm, ref alarmable))
|
if (!Resolve(uid, ref alarm, ref alarmable))
|
||||||
@@ -546,6 +524,8 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pressure = CalculatePressureAverage(uid, alarm);
|
||||||
|
var temperature = CalculateTemperatureAverage(uid, alarm);
|
||||||
var dataToSend = new Dictionary<string, IAtmosDeviceData>();
|
var dataToSend = new Dictionary<string, IAtmosDeviceData>();
|
||||||
|
|
||||||
if (alarm.CurrentTab != AirAlarmTab.Settings)
|
if (alarm.CurrentTab != AirAlarmTab.Settings)
|
||||||
@@ -579,7 +559,7 @@ namespace Content.Server.Atmos.Monitor.Systems
|
|||||||
_uiSystem.TrySetUiState(
|
_uiSystem.TrySetUiState(
|
||||||
uid,
|
uid,
|
||||||
SharedAirAlarmInterfaceKey.Key,
|
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;
|
private const float _delay = 8f;
|
||||||
|
|||||||
@@ -27,27 +27,6 @@ namespace Content.Shared.Atmos.Monitor.Components
|
|||||||
DeviceSync
|
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<Gas, float>? _gases;
|
|
||||||
public readonly IReadOnlyDictionary<Gas, float>? Gases { get => _gases; }
|
|
||||||
|
|
||||||
public AirAlarmAirData(float? pressure, float? temperature, float? moles, AtmosMonitorAlarmType state, Dictionary<Gas, float>? gases)
|
|
||||||
{
|
|
||||||
Pressure = pressure;
|
|
||||||
Temperature = temperature;
|
|
||||||
TotalMoles = moles;
|
|
||||||
AlarmState = state;
|
|
||||||
_gases = gases;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IAtmosDeviceData
|
public interface IAtmosDeviceData
|
||||||
{
|
{
|
||||||
public bool Enabled { get; set; }
|
public bool Enabled { get; set; }
|
||||||
@@ -58,14 +37,18 @@ namespace Content.Shared.Atmos.Monitor.Components
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class AirAlarmUIState : BoundUserInterfaceState
|
public sealed class AirAlarmUIState : BoundUserInterfaceState
|
||||||
{
|
{
|
||||||
public AirAlarmUIState(Dictionary<string, IAtmosDeviceData> deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosMonitorAlarmType alarmType)
|
public AirAlarmUIState(float pressureAverage, float temperatureAverage, Dictionary<string, IAtmosDeviceData> deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosMonitorAlarmType alarmType)
|
||||||
{
|
{
|
||||||
|
PressureAverage = pressureAverage;
|
||||||
|
TemperatureAverage = temperatureAverage;
|
||||||
DeviceData = deviceData;
|
DeviceData = deviceData;
|
||||||
Mode = mode;
|
Mode = mode;
|
||||||
Tab = tab;
|
Tab = tab;
|
||||||
AlarmType = alarmType;
|
AlarmType = alarmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float PressureAverage { get; }
|
||||||
|
public float TemperatureAverage { get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Every single device data that can be seen from this
|
/// Every single device data that can be seen from this
|
||||||
/// air alarm. This includes vents, scrubbers, and sensors.
|
/// air alarm. This includes vents, scrubbers, and sensors.
|
||||||
@@ -81,6 +64,11 @@ namespace Content.Shared.Atmos.Monitor.Components
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class AirAlarmTabSetMessage : BoundUserInterfaceMessage
|
public sealed class AirAlarmTabSetMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
|
public AirAlarmTabSetMessage(AirAlarmTab tab)
|
||||||
|
{
|
||||||
|
Tab = tab;
|
||||||
|
}
|
||||||
|
|
||||||
public AirAlarmTab Tab { get; }
|
public AirAlarmTab Tab { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,28 +76,6 @@ namespace Content.Shared.Atmos.Monitor.Components
|
|||||||
public sealed class AirAlarmResyncAllDevicesMessage : BoundUserInterfaceMessage
|
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]
|
[Serializable, NetSerializable]
|
||||||
public sealed class AirAlarmUpdateAlarmModeMessage : BoundUserInterfaceMessage
|
public sealed class AirAlarmUpdateAlarmModeMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
@@ -137,12 +103,14 @@ namespace Content.Shared.Atmos.Monitor.Components
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class AirAlarmUpdateAlarmThresholdMessage : BoundUserInterfaceMessage
|
public sealed class AirAlarmUpdateAlarmThresholdMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
|
public string Address { get; }
|
||||||
public AtmosAlarmThreshold Threshold { get; }
|
public AtmosAlarmThreshold Threshold { get; }
|
||||||
public AtmosMonitorThresholdType Type { get; }
|
public AtmosMonitorThresholdType Type { get; }
|
||||||
public Gas? Gas { 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;
|
Threshold = threshold;
|
||||||
Type = type;
|
Type = type;
|
||||||
Gas = gas;
|
Gas = gas;
|
||||||
|
|||||||
Reference in New Issue
Block a user