Fix radiation sound not working (#18282)

* Fix radiation sound not working

Signed-off-by: c4llv07e <kseandi@gmail.com>

* Make Geiger sound local

Signed-off-by: c4llv07e <kseandi@gmail.com>

---------

Signed-off-by: c4llv07e <kseandi@gmail.com>
This commit is contained in:
c4llv07e
2023-07-26 00:35:19 +00:00
committed by GitHub
parent 31607a0be0
commit 1b4373d567
2 changed files with 30 additions and 54 deletions

View File

@@ -6,6 +6,9 @@ using Content.Shared.Inventory.Events;
using Content.Shared.Radiation.Components;
using Content.Shared.Radiation.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Player;
using Robust.Server.GameObjects;
using Robust.Server.Player;
namespace Content.Server.Radiation.Systems;
@@ -13,6 +16,8 @@ public sealed class GeigerSystem : SharedGeigerSystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly RadiationSystem _radiation = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly IPlayerManager _player = default!;
private static readonly float ApproxEqual = 0.01f;
@@ -107,6 +112,7 @@ public sealed class GeigerSystem : SharedGeigerSystem
if (curLevel != newLevel)
{
UpdateAppearance(uid, component);
UpdateSound(uid, component);
}
Dirty(component);
@@ -119,6 +125,7 @@ public sealed class GeigerSystem : SharedGeigerSystem
component.User = user;
Dirty(component);
UpdateSound(component.Owner, component);
}
private void SetEnabled(EntityUid uid, GeigerComponent component, bool isEnabled)
@@ -136,6 +143,7 @@ public sealed class GeigerSystem : SharedGeigerSystem
_radiation.SetCanReceive(uid, isEnabled);
UpdateAppearance(uid, component);
UpdateSound(uid, component);
Dirty(component);
}
@@ -149,6 +157,28 @@ public sealed class GeigerSystem : SharedGeigerSystem
_appearance.SetData(uid, GeigerVisuals.DangerLevel, component.DangerLevel, appearance);
}
private void UpdateSound(EntityUid uid, GeigerComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return;
component.Stream?.Stop();
if (!component.Sounds.TryGetValue(component.DangerLevel, out var sounds))
return;
if (component.User == null)
return;
if (!_player.TryGetSessionByEntity(component.User.Value, out var session))
return;
var sound = _audio.GetSound(sounds);
var param = sounds.Params.WithLoop(true).WithVolume(-4f);
component.Stream = _audio.PlayGlobal(sound, session, param);
}
public static GeigerDangerLevel RadsToLevel(float rads)
{
return rads switch
@@ -161,5 +191,3 @@ public sealed class GeigerSystem : SharedGeigerSystem
};
}
}