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:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user