Files
tbd-station-14/Content.Server/GameObjects/Components/Items/ToysComponent.cs
Acruid 9459400002 SoundSystem Improvements (#3697)
* Refactor all audio to use the new SoundSystem.

* Update submodule

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2021-03-21 17:12:03 +01:00

61 lines
1.7 KiB
C#

using Content.Shared.Audio;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Items
{
[RegisterComponent]
public class ToysComponent : Component, IActivate, IUse, ILand
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override string Name => "Toys";
[ViewVariables]
[DataField("toySqueak")]
public string _soundCollectionName = "ToySqueak";
public void Squeak()
{
PlaySqueakEffect();
}
public void PlaySqueakEffect()
{
if (!string.IsNullOrWhiteSpace(_soundCollectionName))
{
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>(_soundCollectionName);
var file = _random.Pick(soundCollection.PickFiles);
SoundSystem.Play(Filter.Pvs(Owner), file, Owner, AudioParams.Default);
}
}
void IActivate.Activate(ActivateEventArgs eventArgs)
{
Squeak();
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
Squeak();
return false;
}
void ILand.Land(LandEventArgs eventArgs)
{
Squeak();
}
}
}