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:
@@ -17,7 +17,6 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<PlayerAttachSysMessage>(OnAttachedEntityChanged);
|
|
||||||
SubscribeLocalEvent<GeigerComponent, ComponentHandleState>(OnHandleState);
|
SubscribeLocalEvent<GeigerComponent, ComponentHandleState>(OnHandleState);
|
||||||
SubscribeLocalEvent<GeigerComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
|
SubscribeLocalEvent<GeigerComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
|
||||||
}
|
}
|
||||||
@@ -27,8 +26,6 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
if (args.Current is not GeigerComponentState state)
|
if (args.Current is not GeigerComponentState state)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UpdateGeigerSound(uid, state.IsEnabled, state.User, state.DangerLevel, false, component);
|
|
||||||
|
|
||||||
component.CurrentRadiation = state.CurrentRadiation;
|
component.CurrentRadiation = state.CurrentRadiation;
|
||||||
component.DangerLevel = state.DangerLevel;
|
component.DangerLevel = state.DangerLevel;
|
||||||
component.IsEnabled = state.IsEnabled;
|
component.IsEnabled = state.IsEnabled;
|
||||||
@@ -43,53 +40,4 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
|
|
||||||
args.Controls.Add(new GeigerItemControl(component));
|
args.Controls.Add(new GeigerItemControl(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAttachedEntityChanged(PlayerAttachSysMessage ev)
|
|
||||||
{
|
|
||||||
// need to go for each component known to client
|
|
||||||
// and update their geiger sound
|
|
||||||
foreach (var geiger in EntityQuery<GeigerComponent>())
|
|
||||||
{
|
|
||||||
ForceUpdateGeigerSound(geiger.Owner, geiger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ForceUpdateGeigerSound(EntityUid uid, GeigerComponent? component = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref component))
|
|
||||||
return;
|
|
||||||
UpdateGeigerSound(uid, component.IsEnabled, component.User, component.DangerLevel, true, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateGeigerSound(EntityUid uid, bool isEnabled, EntityUid? user,
|
|
||||||
GeigerDangerLevel dangerLevel, bool force = false, GeigerComponent? component = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref component))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// check if we even need to update sound
|
|
||||||
if (!force && isEnabled == component.IsEnabled &&
|
|
||||||
user == component.User && dangerLevel == component.DangerLevel)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
component.Stream?.Stop();
|
|
||||||
|
|
||||||
if (!isEnabled || user == null)
|
|
||||||
return;
|
|
||||||
if (!component.Sounds.TryGetValue(dangerLevel, out var sounds))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// check that that local player controls entity that is holding geiger counter
|
|
||||||
if (_playerManager.LocalPlayer == null)
|
|
||||||
return;
|
|
||||||
var attachedEnt = _playerManager.LocalPlayer.Session.AttachedEntity;
|
|
||||||
if (attachedEnt != user)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var sound = _audio.GetSound(sounds);
|
|
||||||
var param = sounds.Params.WithLoop(true).WithVolume(-4f);
|
|
||||||
component.Stream = _audio.Play(sound, Filter.Local(), uid, false, param);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ using Content.Shared.Inventory.Events;
|
|||||||
using Content.Shared.Radiation.Components;
|
using Content.Shared.Radiation.Components;
|
||||||
using Content.Shared.Radiation.Systems;
|
using Content.Shared.Radiation.Systems;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Player;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
|
||||||
namespace Content.Server.Radiation.Systems;
|
namespace Content.Server.Radiation.Systems;
|
||||||
|
|
||||||
@@ -13,6 +16,8 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly RadiationSystem _radiation = 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;
|
private static readonly float ApproxEqual = 0.01f;
|
||||||
|
|
||||||
@@ -107,6 +112,7 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
if (curLevel != newLevel)
|
if (curLevel != newLevel)
|
||||||
{
|
{
|
||||||
UpdateAppearance(uid, component);
|
UpdateAppearance(uid, component);
|
||||||
|
UpdateSound(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
@@ -119,6 +125,7 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
|
|
||||||
component.User = user;
|
component.User = user;
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
|
UpdateSound(component.Owner, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetEnabled(EntityUid uid, GeigerComponent component, bool isEnabled)
|
private void SetEnabled(EntityUid uid, GeigerComponent component, bool isEnabled)
|
||||||
@@ -136,6 +143,7 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
_radiation.SetCanReceive(uid, isEnabled);
|
_radiation.SetCanReceive(uid, isEnabled);
|
||||||
|
|
||||||
UpdateAppearance(uid, component);
|
UpdateAppearance(uid, component);
|
||||||
|
UpdateSound(uid, component);
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +157,28 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
_appearance.SetData(uid, GeigerVisuals.DangerLevel, component.DangerLevel, appearance);
|
_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)
|
public static GeigerDangerLevel RadsToLevel(float rads)
|
||||||
{
|
{
|
||||||
return rads switch
|
return rads switch
|
||||||
@@ -161,5 +191,3 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user