Files
OldThink/Content.Server/Sound/EmitSoundSystem.cs

64 lines
2.2 KiB
C#
Raw Normal View History

using Content.Server.Interaction.Components;
2021-06-27 21:55:18 +02:00
using Content.Server.Sound.Components;
using Content.Server.Throwing;
using Content.Shared.Audio;
using Content.Shared.Interaction;
2022-03-13 01:33:23 +13:00
using Content.Shared.Interaction.Events;
using Content.Shared.Throwing;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
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 sealed class EmitSoundSystem : EntitySystem
{
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
2021-07-12 13:38:05 +02:00
SubscribeLocalEvent<EmitSoundOnLandComponent, LandEvent>(HandleEmitSoundOnLand);
SubscribeLocalEvent<EmitSoundOnUseComponent, UseInHandEvent>(HandleEmitSoundOnUseInHand);
SubscribeLocalEvent<EmitSoundOnThrowComponent, ThrownEvent>(HandleEmitSoundOnThrown);
SubscribeLocalEvent<EmitSoundOnActivateComponent, ActivateInWorldEvent>(HandleEmitSoundOnActivateInWorld);
}
2021-07-12 13:38:05 +02:00
private void HandleEmitSoundOnLand(EntityUid eUI, BaseEmitSoundComponent component, LandEvent arg)
{
TryEmitSound(component);
}
private void HandleEmitSoundOnUseInHand(EntityUid eUI, BaseEmitSoundComponent component, UseInHandEvent arg)
{
2022-01-26 14:07:45 +11:00
if (arg.Handled) return;
arg.Handled = true;
2021-07-12 13:38:05 +02:00
TryEmitSound(component);
}
private void HandleEmitSoundOnThrown(EntityUid eUI, BaseEmitSoundComponent component, ThrownEvent arg)
{
TryEmitSound(component);
}
private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, BaseEmitSoundComponent component, ActivateInWorldEvent arg)
{
2022-01-26 14:07:45 +11:00
if (arg.Handled) return;
arg.Handled = true;
2021-07-12 13:38:05 +02:00
TryEmitSound(component);
}
private static void TryEmitSound(BaseEmitSoundComponent component)
{
SoundSystem.Play(Filter.Pvs(component.Owner), component.Sound.GetSound(), component.Owner, AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
}
}
}