From b771d2423aac6923ad8dbc327931318b0b89cb70 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Fri, 2 Dec 2022 04:02:37 +1300 Subject: [PATCH] Fix ambient sound error (#12808) --- Content.Client/Audio/AmbientSoundSystem.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Content.Client/Audio/AmbientSoundSystem.cs b/Content.Client/Audio/AmbientSoundSystem.cs index 48a3c0bda4..2c3f73c7c0 100644 --- a/Content.Client/Audio/AmbientSoundSystem.cs +++ b/Content.Client/Audio/AmbientSoundSystem.cs @@ -175,9 +175,9 @@ namespace Content.Client.Audio _playingSounds.Clear(); } - private Dictionary> GetNearbySources(TransformComponent playerXform, MapCoordinates coords, EntityQuery xformQuery) + private Dictionary> GetNearbySources(TransformComponent playerXform, MapCoordinates coords, EntityQuery xformQuery) { - var sourceDict = new Dictionary>(16); + var sourceDict = new Dictionary>(16); var ambientQuery = GetEntityQuery(); // TODO add variant of GetComponentsInRange that also returns the transform component. @@ -205,7 +205,7 @@ namespace Content.Client.Audio var list = sourceDict.GetOrNew(key); // Prioritize far away & loud sounds. - list.Add(-range * (ambientComp.Volume + 32), ambientComp); + list.Add((range * (ambientComp.Volume + 32), ambientComp)); } return sourceDict; @@ -252,7 +252,9 @@ namespace Content.Client.Audio if (_playingCount.TryGetValue(key, out var playingCount) && playingCount >= MaxSingleSound) continue; - foreach (var comp in sources.Values) + sources.Sort(static (a, b) => b.Importance.CompareTo(a.Importance)); + + foreach (var (_, comp) in sources) { if (_playingSounds.ContainsKey(comp)) continue;