Files
OldThink/Content.Server/Construction/Completions/PlaySound.cs
2021-07-16 17:37:09 -07:00

34 lines
1.1 KiB
C#

using System.Threading.Tasks;
using Content.Shared.Audio;
using Content.Shared.Construction;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Construction.Completions
{
[UsedImplicitly]
[DataDefinition]
public class PlaySound : IGraphAction
{
[DataField("soundCollection")] public string SoundCollection { get; private set; } = string.Empty;
[DataField("sound")] public string Sound { get; private set; } = string.Empty;
public async Task PerformAction(IEntity entity, IEntity? user)
{
var sound = GetSound();
if (string.IsNullOrEmpty(sound)) return;
SoundSystem.Play(Filter.Pvs(entity), sound, entity, AudioHelpers.WithVariation(0.125f));
}
private string GetSound()
{
return !string.IsNullOrEmpty(SoundCollection) ? AudioHelpers.GetRandomFileFromSoundCollection(SoundCollection) : Sound;
}
}
}