Add gatherable break sounds (#19360)

This commit is contained in:
metalgearsloth
2023-08-21 07:05:43 +10:00
committed by GitHub
parent 3fb9624bf3
commit d7abbab082
10 changed files with 48 additions and 17 deletions

View File

@@ -0,0 +1,19 @@
using Content.Shared.Audio;
using Robust.Shared.Audio;
namespace Content.Server.Gatherable.Components;
/// <summary>
/// Plays the specified sound when this entity is gathered.
/// </summary>
[RegisterComponent, Access(typeof(GatherableSystem))]
public sealed class SoundOnGatherComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("sound")]
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Effects/break_stone.ogg")
{
Params = AudioParams.Default
.WithVariation(SharedContentAudioSystem.DefaultVariation)
.WithVolume(-3f),
};
}

View File

@@ -43,14 +43,18 @@ public sealed partial class GatherableSystem : EntitySystem
Gather(uid, args.User, component);
}
public void Gather(EntityUid gatheredUid, EntityUid? gatherer = null, GatherableComponent? component = null, SoundSpecifier? sound = null)
public void Gather(EntityUid gatheredUid, EntityUid? gatherer = null, GatherableComponent? component = null)
{
if (!Resolve(gatheredUid, ref component))
return;
if (TryComp<SoundOnGatherComponent>(gatheredUid, out var soundComp))
{
_audio.PlayPvs(soundComp.Sound, Transform(gatheredUid).Coordinates);
}
// Complete the gathering process
_destructible.DestroyEntity(gatheredUid);
_audio.PlayPvs(sound, gatheredUid);
// Spawn the loot!
if (component.MappedLoot == null)