Files
tbd-station-14/Content.Server/Sound/EmitSoundSystem.cs
Galactic Chimp 10af8efc0e #4219 emit sound system add single sound support (#4237)
* Revert "#3935 implemented suggestions from PR"

This reverts commit a9b1c7b96333ca570067d6a9df1954481005892a.

* #4219 revert of single sound removal in EmitSoundSystem

* #4219 single sounds in EmitSoundSystem should work now

* #4219 some small project tweaks

* #4219 upgraded EmitSoundSystem to use SoundSpecifier

* #4219 pr tweaks

* #4219 pr tweak

* #4219 missing bike horn .yaml change
2021-07-25 04:37:01 -07:00

65 lines
2.3 KiB
C#

using Content.Server.Interaction.Components;
using Content.Server.Sound.Components;
using Content.Server.Throwing;
using Content.Shared.Audio;
using Content.Shared.Interaction;
using Content.Shared.Throwing;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Player;
namespace Content.Server.Sound
{
/// <summary>
/// Will play a sound on various events if the affected entity has a component derived from BaseEmitSoundComponent
/// </summary>
[UsedImplicitly]
public class EmitSoundSystem : EntitySystem
{
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EmitSoundOnLandComponent, LandEvent>(HandleEmitSoundOnLand);
SubscribeLocalEvent<EmitSoundOnUseComponent, UseInHandEvent>(HandleEmitSoundOnUseInHand);
SubscribeLocalEvent<EmitSoundOnThrowComponent, ThrownEvent>(HandleEmitSoundOnThrown);
SubscribeLocalEvent<EmitSoundOnActivateComponent, ActivateInWorldEvent>(HandleEmitSoundOnActivateInWorld);
}
private void HandleEmitSoundOnLand(EntityUid eUI, BaseEmitSoundComponent component, LandEvent arg)
{
TryEmitSound(component);
}
private void HandleEmitSoundOnUseInHand(EntityUid eUI, BaseEmitSoundComponent component, UseInHandEvent arg)
{
TryEmitSound(component);
}
private void HandleEmitSoundOnThrown(EntityUid eUI, BaseEmitSoundComponent component, ThrownEvent arg)
{
TryEmitSound(component);
}
private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, BaseEmitSoundComponent component, ActivateInWorldEvent arg)
{
TryEmitSound(component);
}
private static void TryEmitSound(BaseEmitSoundComponent component)
{
if (!string.IsNullOrWhiteSpace(component.Sound.GetSound()))
{
SoundSystem.Play(Filter.Pvs(component.Owner), component.Sound.GetSound(), component.Owner, AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
}
else
{
Logger.Warning($"{nameof(component)} Uid:{component.Owner.Uid} has no {nameof(component.Sound)} to play.");
}
}
}
}