Skip to content

Commit

Permalink
Silence ringtones on invisible PDAs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tayrtahn committed Jul 7, 2024
1 parent eab93cb commit afc1041
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Content.Server/PDA/Ringer/RingerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<NetUserId, TimeSpan> _lastSetRingtoneAt = new();

private EntityQuery<VisibilityComponent> _visibilityQuery;

public override void Initialize()
{
base.Initialize();
Expand All @@ -44,6 +48,8 @@ public override void Initialize()
SubscribeLocalEvent<RingerComponent, RingerRequestUpdateInterfaceMessage>(UpdateRingerUserInterfaceDriver);

SubscribeLocalEvent<RingerComponent, CurrencyInsertAttemptEvent>(OnCurrencyInsert);

_visibilityQuery = GetEntityQuery<VisibilityComponent>();
}

//Event Functions
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit afc1041

Please sign in to comment.