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;