Files
crystall-punk-14/Content.Server/Construction/Completions/PlaySound.cs
Víctor Aguilera Puerto 745401a41e Data-oriented Construction System (#2152)
- Powerful
- Data-oriented
- Approved by PJB
- Powered by node graphs and AI pathfinding
- Coded by the same nerd who brought you atmos

Co-authored-by: Exp <theexp111@gmail.com>
2020-10-08 17:41:23 +02:00

40 lines
1.3 KiB
C#

#nullable enable
using System.Threading.Tasks;
using Content.Shared.Audio;
using Content.Shared.Construction;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Server.Construction.Completions
{
[UsedImplicitly]
public class PlaySound : IGraphAction
{
public string SoundCollection { get; private set; } = string.Empty;
public string Sound { get; private set; } = string.Empty;
public void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(this, x => x.Sound, "sound", string.Empty);
serializer.DataField(this, x => x.SoundCollection, "soundCollection", string.Empty);
}
public async Task PerformAction(IEntity entity, IEntity? user)
{
var sound = GetSound();
if (string.IsNullOrEmpty(sound)) return;
EntitySystem.Get<AudioSystem>().PlayFromEntity(sound, entity, AudioHelpers.WithVariation(0.125f));
}
private string GetSound()
{
return !string.IsNullOrEmpty(SoundCollection) ? AudioHelpers.GetRandomFileFromSoundCollection(SoundCollection) : Sound;
}
}
}