alert sounds from alarmables, sensor data ctor

This commit is contained in:
vulppine
2022-08-18 02:37:12 -07:00
parent 1c651f051f
commit 068527b13c
7 changed files with 78 additions and 24 deletions

View File

@@ -4,12 +4,14 @@ using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.Atmos.Monitor;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
namespace Content.Server.Atmos.Monitor.Systems
{
public sealed class AtmosAlarmableSystem : EntitySystem
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<AtmosAlarmableComponent, DeviceNetworkPacketEvent>(OnPacketRecv);
@@ -37,11 +39,20 @@ namespace Content.Server.Atmos.Monitor.Systems
component.LastAlarmState = state;
component.HighestNetworkState = netMax;
UpdateAppearance(uid, netMax);
PlayAlertSound(uid, netMax, component);
RaiseLocalEvent(component.Owner, new AtmosMonitorAlarmEvent(state, netMax), true);
}
}
}
private void PlayAlertSound(EntityUid uid, AtmosMonitorAlarmType alarm, AtmosAlarmableComponent alarmable)
{
if (alarm == AtmosMonitorAlarmType.Danger)
{
_audioSystem.PlayPvs(alarmable.AlarmSound, uid, AudioParams.Default.WithVolume(alarmable.AlarmVolume));
}
}
private void UpdateAppearance(EntityUid uid, AtmosMonitorAlarmType alarm)
{
_appearance.SetData(uid, AtmosMonitorVisuals.AlarmType, alarm);