2021-03-21 09:12:03 -07:00
|
|
|
using Content.Shared.Audio;
|
2020-07-18 22:51:56 -07:00
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2019-07-31 15:02:36 +02:00
|
|
|
using Robust.Shared.Audio;
|
2019-06-03 23:16:47 +05:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-11-25 12:23:03 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2019-06-03 23:16:47 +05:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Sound
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Simple sound emitter that emits sound on use in hand
|
|
|
|
|
/// </summary>
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2019-06-03 23:16:47 +05:00
|
|
|
public class EmitSoundOnUseComponent : Component, IUse
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
2019-07-31 15:02:36 +02:00
|
|
|
///
|
2019-06-03 23:16:47 +05:00
|
|
|
public override string Name => "EmitSoundOnUse";
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("sound")] public string? _soundName;
|
2021-03-05 01:08:38 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float _pitchVariation;
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("semitoneVariation")] public int _semitoneVariation;
|
2019-06-03 23:16:47 +05:00
|
|
|
|
|
|
|
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(_soundName))
|
|
|
|
|
{
|
2020-05-03 11:20:03 +02:00
|
|
|
if (_pitchVariation > 0.0)
|
|
|
|
|
{
|
2021-03-21 09:12:03 -07:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
|
2020-05-03 11:20:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-11-25 12:23:03 +02:00
|
|
|
if (_semitoneVariation > 0)
|
|
|
|
|
{
|
2021-03-21 09:12:03 -07:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioHelpers.WithSemitoneVariation(_semitoneVariation).WithVolume(-2f));
|
2020-11-25 12:23:03 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2021-03-21 09:12:03 -07:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioParams.Default.WithVolume(-2f));
|
2019-06-03 23:16:47 +05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|