Files
tbd-station-14/Content.Shared/Trigger/Systems/EmitSoundOnTriggerSystem.cs
Princess Cheeseballs c01ec294d0 Reduce Triggers Boilerplate. (#41086)
* Push 1

* cleanup + master merge

* launchontrigger

* A crumb of cleanup

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-10-25 00:00:55 +00:00

41 lines
1.3 KiB
C#

using Content.Shared.Trigger.Components.Effects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Network;
namespace Content.Shared.Trigger.Systems;
public sealed class EmitSoundOnTriggerSystem : XOnTriggerSystem<EmitSoundOnTriggerComponent>
{
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
protected override void OnTrigger(Entity<EmitSoundOnTriggerComponent> ent, EntityUid target, ref TriggerEvent args)
{
args.Handled |= TryEmitSound(ent, target, args.User);
}
private bool TryEmitSound(Entity<EmitSoundOnTriggerComponent> ent, EntityUid target, EntityUid? user = null)
{
if (ent.Comp.Sound == null)
return false;
if (ent.Comp.Positional)
{
var coords = Transform(target).Coordinates;
if (ent.Comp.Predicted)
_audio.PlayPredicted(ent.Comp.Sound, coords, user);
else if (_netMan.IsServer)
_audio.PlayPvs(ent.Comp.Sound, coords);
}
else
{
if (ent.Comp.Predicted)
_audio.PlayPredicted(ent.Comp.Sound, target, user);
else if (_netMan.IsServer)
_audio.PlayPvs(ent.Comp.Sound, target);
}
return true;
}
}