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

@@ -17,7 +17,6 @@ public sealed class GeigerSystem : SharedGeigerSystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlayerAttachSysMessage>(OnAttachedEntityChanged);
SubscribeLocalEvent<GeigerComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<GeigerComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
}
@@ -27,8 +26,6 @@ public sealed class GeigerSystem : SharedGeigerSystem
if (args.Current is not GeigerComponentState state)
return;
UpdateGeigerSound(uid, state.IsEnabled, state.User, state.DangerLevel, false, component);
component.CurrentRadiation = state.CurrentRadiation;
component.DangerLevel = state.DangerLevel;
component.IsEnabled = state.IsEnabled;
@@ -43,53 +40,4 @@ public sealed class GeigerSystem : SharedGeigerSystem
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);
}
}