diff --git a/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs b/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs
index c4f2070b78..a90eef8d76 100644
--- a/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs
+++ b/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs
@@ -1,4 +1,4 @@
-using Content.Server.Sound;
+using Content.Server.Sound.Components;
using Robust.Shared.GameObjects;
namespace Content.Server.Interaction.Components
diff --git a/Content.Server/Light/Components/ExpendableLightComponent.cs b/Content.Server/Light/Components/ExpendableLightComponent.cs
index 0e8be41061..1f1c4a9df5 100644
--- a/Content.Server/Light/Components/ExpendableLightComponent.cs
+++ b/Content.Server/Light/Components/ExpendableLightComponent.cs
@@ -1,6 +1,6 @@
using Content.Server.Clothing.Components;
using Content.Server.Items;
-using Content.Server.Sound;
+using Content.Server.Sound.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
diff --git a/Content.Server/Sound/BaseEmitSoundComponent.cs b/Content.Server/Sound/BaseEmitSoundComponent.cs
deleted file mode 100644
index a1a4df3a56..0000000000
--- a/Content.Server/Sound/BaseEmitSoundComponent.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Robust.Shared.GameObjects;
-using Robust.Shared.Serialization.Manager.Attributes;
-using Robust.Shared.ViewVariables;
-
-namespace Content.Server.Sound
-{
- ///
- /// Base sound emitter which defines most of the data fields.
- ///
- public abstract class BaseEmitSoundComponent : Component
- {
- [ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float PitchVariation { get; set; } = 0.0f;
- [ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection", required: true)] public string SoundCollectionName { get; set; } = default!;
- }
-}
diff --git a/Content.Server/Sound/Components/BaseEmitSoundComponent.cs b/Content.Server/Sound/Components/BaseEmitSoundComponent.cs
new file mode 100644
index 0000000000..6b9ee8ff75
--- /dev/null
+++ b/Content.Server/Sound/Components/BaseEmitSoundComponent.cs
@@ -0,0 +1,22 @@
+using Content.Shared.Sound;
+using Robust.Shared.GameObjects;
+using Robust.Shared.Serialization.Manager.Attributes;
+using Robust.Shared.ViewVariables;
+
+namespace Content.Server.Sound.Components
+{
+ ///
+ /// Base sound emitter which defines most of the data fields.
+ /// Accepts both single sounds and sound collections.
+ ///
+ public abstract class BaseEmitSoundComponent : Component
+ {
+ [ViewVariables(VVAccess.ReadWrite)]
+ [DataField("sound")]
+ public SoundSpecifier Sound { get; set; } = default!;
+
+ [ViewVariables(VVAccess.ReadWrite)]
+ [DataField("variation")]
+ public float PitchVariation { get; set; } = 0.0f;
+ }
+}
diff --git a/Content.Server/Sound/EmitSoundOnActivateComponent.cs b/Content.Server/Sound/Components/EmitSoundOnActivateComponent.cs
similarity index 88%
rename from Content.Server/Sound/EmitSoundOnActivateComponent.cs
rename to Content.Server/Sound/Components/EmitSoundOnActivateComponent.cs
index fdbb9f7aed..2cbc83516a 100644
--- a/Content.Server/Sound/EmitSoundOnActivateComponent.cs
+++ b/Content.Server/Sound/Components/EmitSoundOnActivateComponent.cs
@@ -1,6 +1,6 @@
using Robust.Shared.GameObjects;
-namespace Content.Server.Sound
+namespace Content.Server.Sound.Components
{
///
/// Simple sound emitter that emits sound on ActivateInWorld
diff --git a/Content.Server/Sound/EmitSoundOnLandComponent.cs b/Content.Server/Sound/Components/EmitSoundOnLandComponent.cs
similarity index 88%
rename from Content.Server/Sound/EmitSoundOnLandComponent.cs
rename to Content.Server/Sound/Components/EmitSoundOnLandComponent.cs
index 1d6286abdd..96782fe985 100644
--- a/Content.Server/Sound/EmitSoundOnLandComponent.cs
+++ b/Content.Server/Sound/Components/EmitSoundOnLandComponent.cs
@@ -1,6 +1,6 @@
using Robust.Shared.GameObjects;
-namespace Content.Server.Sound
+namespace Content.Server.Sound.Components
{
///
/// Simple sound emitter that emits sound on LandEvent
diff --git a/Content.Server/Sound/LoopingLoopingSoundComponent.cs b/Content.Server/Sound/Components/LoopingLoopingSoundComponent.cs
similarity index 98%
rename from Content.Server/Sound/LoopingLoopingSoundComponent.cs
rename to Content.Server/Sound/Components/LoopingLoopingSoundComponent.cs
index 38796fe874..4230e39d8e 100644
--- a/Content.Server/Sound/LoopingLoopingSoundComponent.cs
+++ b/Content.Server/Sound/Components/LoopingLoopingSoundComponent.cs
@@ -3,7 +3,7 @@ using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Network;
-namespace Content.Server.Sound
+namespace Content.Server.Sound.Components
{
[RegisterComponent]
public class LoopingLoopingSoundComponent : SharedLoopingSoundComponent
diff --git a/Content.Server/Sound/EmitSoundSystem.cs b/Content.Server/Sound/EmitSoundSystem.cs
index 3459522a3e..240ee28f3d 100644
--- a/Content.Server/Sound/EmitSoundSystem.cs
+++ b/Content.Server/Sound/EmitSoundSystem.cs
@@ -1,55 +1,63 @@
+using Content.Server.Interaction.Components;
+using Content.Server.Sound.Components;
+using Content.Server.Throwing;
using Content.Shared.Audio;
using Content.Shared.Interaction;
using Content.Shared.Throwing;
-using Content.Server.Interaction.Components;
-using Content.Server.Throwing;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Prototypes;
+using Robust.Shared.Log;
using Robust.Shared.Player;
-using Robust.Shared.Random;
namespace Content.Server.Sound
{
+ ///
+ /// Will play a sound on various events if the affected entity has a component derived from BaseEmitSoundComponent
+ ///
[UsedImplicitly]
public class EmitSoundSystem : EntitySystem
{
- [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
- [Dependency] private readonly IRobustRandom _random = default!;
-
///
public override void Initialize()
{
base.Initialize();
- SubscribeLocalEvent((eUI, comp, arg) => PlaySound(comp));
- SubscribeLocalEvent((eUI, comp, arg) => PlaySound(comp));
- SubscribeLocalEvent((eUI, comp, arg) => PlaySound(comp));
- SubscribeLocalEvent((eUI, comp, args) => PlaySound(comp));
+ SubscribeLocalEvent(HandleEmitSoundOnLand);
+ SubscribeLocalEvent(HandleEmitSoundOnUseInHand);
+ SubscribeLocalEvent(HandleEmitSoundOnThrown);
+ SubscribeLocalEvent(HandleEmitSoundOnActivateInWorld);
}
- private void PlaySound(BaseEmitSoundComponent component)
+ private void HandleEmitSoundOnLand(EntityUid eUI, BaseEmitSoundComponent component, LandEvent arg)
{
- PlayRandomSoundFromCollection(component);
+ TryEmitSound(component);
}
- private void PlayRandomSoundFromCollection(BaseEmitSoundComponent component)
+ private void HandleEmitSoundOnUseInHand(EntityUid eUI, BaseEmitSoundComponent component, UseInHandEvent arg)
{
- var file = SelectRandomSoundFromSoundCollection(component.SoundCollectionName!);
- PlaySingleSound(file, component);
+ TryEmitSound(component);
}
- private string SelectRandomSoundFromSoundCollection(string soundCollectionName)
+ private void HandleEmitSoundOnThrown(EntityUid eUI, BaseEmitSoundComponent component, ThrownEvent arg)
{
- var soundCollection = _prototypeManager.Index(soundCollectionName);
- return _random.Pick(soundCollection.PickFiles);
+ TryEmitSound(component);
}
- private static void PlaySingleSound(string soundName, BaseEmitSoundComponent component)
+ private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, BaseEmitSoundComponent component, ActivateInWorldEvent arg)
{
- SoundSystem.Play(Filter.Pvs(component.Owner), soundName, component.Owner,
- AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
+ TryEmitSound(component);
+ }
+
+ private static void TryEmitSound(BaseEmitSoundComponent component)
+ {
+ if (!string.IsNullOrWhiteSpace(component.Sound.GetSound()))
+ {
+ SoundSystem.Play(Filter.Pvs(component.Owner), component.Sound.GetSound(), component.Owner, AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
+ }
+ else
+ {
+ Logger.Warning($"{nameof(component)} Uid:{component.Owner.Uid} has no {nameof(component.Sound)} to play.");
+ }
}
}
}
diff --git a/Content.Server/Throwing/EmitSoundOnThrowComponent.cs b/Content.Server/Throwing/EmitSoundOnThrowComponent.cs
index d56af69811..d0b75d8d2b 100644
--- a/Content.Server/Throwing/EmitSoundOnThrowComponent.cs
+++ b/Content.Server/Throwing/EmitSoundOnThrowComponent.cs
@@ -1,4 +1,4 @@
-using Content.Server.Sound;
+using Content.Server.Sound.Components;
using Robust.Shared.GameObjects;
namespace Content.Server.Throwing
diff --git a/Content.Server/Toys/ToysComponent.cs b/Content.Server/Toys/ToysComponent.cs
deleted file mode 100644
index e8deeee074..0000000000
--- a/Content.Server/Toys/ToysComponent.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using Content.Shared.Audio;
-using Content.Shared.Interaction;
-using Content.Shared.Throwing;
-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.Manager.Attributes;
-using Robust.Shared.ViewVariables;
-
-namespace Content.Server.Toys
-{
- [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(_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();
- }
- }
-}
-
diff --git a/Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml b/Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml
index 43f8a2db91..c40ec6ebe6 100644
--- a/Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml
+++ b/Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml
@@ -14,7 +14,8 @@
QuickEquip: false
- type: ItemCooldown
- type: EmitSoundOnUse
- soundCollection: BikeHorn
+ sound:
+ collection: BikeHorn
semitoneVariation: 6
- type: UseDelay
delay: 0.5
diff --git a/Resources/Prototypes/Entities/Objects/Fun/skub.yml b/Resources/Prototypes/Entities/Objects/Fun/skub.yml
index d885ac09a7..e4695f5062 100644
--- a/Resources/Prototypes/Entities/Objects/Fun/skub.yml
+++ b/Resources/Prototypes/Entities/Objects/Fun/skub.yml
@@ -12,6 +12,7 @@
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/skub.ogg
+ sound:
+ path: /Audio/Items/skub.ogg
- type: UseDelay
delay: 2.0
diff --git a/Resources/Prototypes/Entities/Objects/Fun/toys.yml b/Resources/Prototypes/Entities/Objects/Fun/toys.yml
index 442133249c..0d8babe815 100644
--- a/Resources/Prototypes/Entities/Objects/Fun/toys.yml
+++ b/Resources/Prototypes/Entities/Objects/Fun/toys.yml
@@ -5,11 +5,14 @@
id: BasePlushie
components:
- type: EmitSoundOnUse
- soundCollection: ToySqueak
+ sound:
+ collection: ToySqueak
- type: EmitSoundOnLand
- soundCollection: ToySqueak
+ sound:
+ collection: ToySqueak
- type: EmitSoundOnActivate
- soundCollection: ToySqueak
+ sound:
+ collection: ToySqueak
- type: LoopingSound
- type: ItemCooldown
- type: UseDelay
@@ -90,7 +93,8 @@
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/rattle.ogg
+ sound:
+ path: /Audio/Items/Toys/rattle.ogg
- type: UseDelay
delay: 1.0
@@ -106,7 +110,8 @@
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/mousesqueek.ogg
+ sound:
+ path: /Audio/Items/Toys/mousesqueek.ogg
- type: UseDelay
delay: 1.0
@@ -122,7 +127,8 @@
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Voice/Vox/shriek1.ogg
+ sound:
+ path: /Audio/Voice/Vox/shriek1.ogg
- type: UseDelay
delay: 1.0
@@ -142,11 +148,13 @@
- type: Item
sprite: Objects/Misc/carvings.rsi
- type: EmitSoundOnThrow
- sound: /Audio/Items/Toys/helpme.ogg
+ sound:
+ path: /Audio/Items/Toys/helpme.ogg
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/helpme.ogg
+ sound:
+ path: /Audio/Items/Toys/helpme.ogg
- type: UseDelay
delay: 1.0
@@ -162,11 +170,13 @@
- type: Item
sprite: Objects/Misc/carvings.rsi
- type: EmitSoundOnThrow
- sound: /Audio/Items/Toys/hellothere.ogg
+ sound:
+ path: /Audio/Items/Toys/hellothere.ogg
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/hellothere.ogg
+ sound:
+ path: /Audio/Items/Toys/hellothere.ogg
- type: UseDelay
delay: 1.0
@@ -182,11 +192,13 @@
- type: Item
sprite: Objects/Misc/carvings.rsi
- type: EmitSoundOnThrow
- sound: /Audio/Items/Toys/thankyou.ogg
+ sound:
+ path: /Audio/Items/Toys/thankyou.ogg
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/thankyou.ogg
+ sound:
+ path: /Audio/Items/Toys/thankyou.ogg
- type: UseDelay
delay: 1.0
@@ -202,11 +214,13 @@
- type: Item
sprite: Objects/Misc/carvings.rsi
- type: EmitSoundOnThrow
- sound: /Audio/Items/Toys/verygood.ogg
+ sound:
+ path: /Audio/Items/Toys/verygood.ogg
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/verygood.ogg
+ sound:
+ path: /Audio/Items/Toys/verygood.ogg
- type: UseDelay
delay: 1.0
@@ -222,11 +236,13 @@
- type: Item
sprite: Objects/Misc/carvings.rsi
- type: EmitSoundOnThrow
- sound: /Audio/Items/Toys/imsorry.ogg
+ sound:
+ path: /Audio/Items/Toys/imsorry.ogg
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/imsorry.ogg
+ sound:
+ path: /Audio/Items/Toys/imsorry.ogg
- type: UseDelay
delay: 1.0
@@ -297,7 +313,8 @@
- type: ItemCooldown
- type: LoopingSound
- type: EmitSoundOnUse
- sound: /Audio/Items/Toys/ian.ogg
+ sound:
+ path: /Audio/Items/Toys/ian.ogg
- type: UseDelay
delay: 1.0