2021-06-19 11:35:56 +02:00
|
|
|
using Content.Server.Interaction.Components;
|
2021-06-27 21:55:18 +02:00
|
|
|
using Content.Server.Sound.Components;
|
2021-06-19 11:35:56 +02:00
|
|
|
using Content.Server.Throwing;
|
2021-07-10 11:20:23 +02:00
|
|
|
using Content.Shared.Audio;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Throwing;
|
2021-06-19 11:35:56 +02:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-06-27 21:27:59 +02:00
|
|
|
using Robust.Shared.Log;
|
2021-07-10 11:20:23 +02:00
|
|
|
using Robust.Shared.Player;
|
2021-06-19 11:35:56 +02:00
|
|
|
|
2021-06-27 21:48:57 +02:00
|
|
|
namespace Content.Server.Sound
|
2021-06-19 11:35:56 +02:00
|
|
|
{
|
2021-07-10 11:20:23 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Will play a sound on various events if the affected entity has a component derived from BaseEmitSoundComponent
|
|
|
|
|
/// </summary>
|
2021-06-19 11:35:56 +02:00
|
|
|
[UsedImplicitly]
|
|
|
|
|
public 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-06-19 11:35:56 +02:00
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
2021-06-19 11:35:56 +02:00
|
|
|
{
|
2021-07-12 13:45:35 +02:00
|
|
|
if (component.Sound.TryGetSound(out var sound))
|
2021-07-10 17:35:33 +02:00
|
|
|
{
|
2021-07-12 13:45:35 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(component.Owner), sound, component.Owner, AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
|
2021-06-27 21:30:28 +02:00
|
|
|
}
|
2021-06-27 21:27:59 +02:00
|
|
|
else
|
|
|
|
|
{
|
2021-07-10 11:20:23 +02:00
|
|
|
Logger.Warning($"{nameof(component)} Uid:{component.Owner.Uid} has no {nameof(component.Sound)} to play.");
|
2021-06-27 21:27:59 +02:00
|
|
|
}
|
2021-06-19 11:35:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|