diff --git a/Content.Server/PDA/Ringer/RingerSystem.cs b/Content.Server/PDA/Ringer/RingerSystem.cs index 0cc4ea86c2210b..009069b48918e0 100644 --- a/Content.Server/PDA/Ringer/RingerSystem.cs +++ b/Content.Server/PDA/Ringer/RingerSystem.cs @@ -15,6 +15,7 @@ using Robust.Shared.Timing; using Robust.Shared.Utility; using Robust.Server.Audio; +using Robust.Shared.Containers; namespace Content.Server.PDA.Ringer { @@ -27,9 +28,12 @@ public sealed class RingerSystem : SharedRingerSystem [Dependency] private readonly AudioSystem _audio = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly TransformSystem _transform = default!; + [Dependency] private readonly SharedContainerSystem _containerSystem = default!; private readonly Dictionary _lastSetRingtoneAt = new(); + private EntityQuery _visibilityQuery; + public override void Initialize() { base.Initialize(); @@ -44,6 +48,8 @@ public override void Initialize() SubscribeLocalEvent(UpdateRingerUserInterfaceDriver); SubscribeLocalEvent(OnCurrencyInsert); + + _visibilityQuery = GetEntityQuery(); } //Event Functions @@ -216,9 +222,17 @@ public bool ToggleRingerUI(EntityUid uid, EntityUid actor) ringer.TimeElapsed -= NoteDelay; var ringerXform = Transform(uid); + // If the PDA is in something with a visibility layer, only play sounds for players who can see it + var visLayer = 1U; + VisibilityComponent? visibility = null; + if (_containerSystem.TryFindComponentOnEntityContainerOrParent(uid, _visibilityQuery, ref visibility)) + { + visLayer = visibility.Layer; + } + _audio.PlayEntity( GetSound(ringer.Ringtone[ringer.NoteCount]), - Filter.Empty().AddInRange(_transform.GetMapCoordinates(uid, ringerXform), ringer.Range), + Filter.Empty().AddInRange(_transform.GetMapCoordinates(uid, ringerXform), ringer.Range).RemoveByVisibility(visLayer), uid, true, AudioParams.Default.WithMaxDistance(ringer.Range).WithVolume(ringer.Volume)