From d55c9574c83c500f74d463b7936ebc74d945a026 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 30 Mar 2022 22:01:32 +1300 Subject: [PATCH] Fix sound-on-use spam (#7342) --- .../Components/EmitSoundOnUseComponent.cs | 11 +++++++++++ .../Components/EmitSoundOnActivateComponent.cs | 11 +++++++++++ Content.Server/Sound/EmitSoundSystem.cs | 14 ++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs b/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs index d39f5e4e85..a0224843c4 100644 --- a/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs +++ b/Content.Server/Interaction/Components/EmitSoundOnUseComponent.cs @@ -9,5 +9,16 @@ namespace Content.Server.Interaction.Components [RegisterComponent] public sealed class EmitSoundOnUseComponent : BaseEmitSoundComponent { + /// + /// Whether or not to mark an interaction as handled after playing the sound. Useful if this component is + /// used to play sound for some other component with on-use functionality + /// + /// + /// If false, you should be confident that the interaction will also be handled by some other system, as + /// otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was + /// handled. + /// + [DataField("handle")] + public bool Handle = true; } } diff --git a/Content.Server/Sound/Components/EmitSoundOnActivateComponent.cs b/Content.Server/Sound/Components/EmitSoundOnActivateComponent.cs index b86a10f4ff..b78009e5f1 100644 --- a/Content.Server/Sound/Components/EmitSoundOnActivateComponent.cs +++ b/Content.Server/Sound/Components/EmitSoundOnActivateComponent.cs @@ -8,5 +8,16 @@ namespace Content.Server.Sound.Components [RegisterComponent] public sealed class EmitSoundOnActivateComponent : BaseEmitSoundComponent { + /// + /// Whether or not to mark an interaction as handled after playing the sound. Useful if this component is + /// used to play sound for some other component with activation functionality. + /// + /// + /// If false, you should be confident that the interaction will also be handled by some other system, as + /// otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was + /// handled. + /// + [DataField("handle")] + public bool Handle = true; } } diff --git a/Content.Server/Sound/EmitSoundSystem.cs b/Content.Server/Sound/EmitSoundSystem.cs index 24cf39cfa8..f4a1b610de 100644 --- a/Content.Server/Sound/EmitSoundSystem.cs +++ b/Content.Server/Sound/EmitSoundSystem.cs @@ -41,10 +41,13 @@ namespace Content.Server.Sound TryEmitSound(component); } - private void HandleEmitSoundOnUseInHand(EntityUid eUI, BaseEmitSoundComponent component, UseInHandEvent arg) + private void HandleEmitSoundOnUseInHand(EntityUid eUI, EmitSoundOnUseComponent component, UseInHandEvent arg) { - // Intentionally not handling interaction. This component is an easy way to add sounds in addition to other behavior. + // Intentionally not checking whether the interaction has already been handled. TryEmitSound(component); + + if (component.Handle) + arg.Handled = true; } private void HandleEmitSoundOnThrown(EntityUid eUI, BaseEmitSoundComponent component, ThrownEvent arg) @@ -52,10 +55,13 @@ namespace Content.Server.Sound TryEmitSound(component); } - private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, BaseEmitSoundComponent component, ActivateInWorldEvent arg) + private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, EmitSoundOnActivateComponent component, ActivateInWorldEvent arg) { - // Intentionally not handling interaction. This component is an easy way to add sounds in addition to other behavior. + // Intentionally not checking whether the interaction has already been handled. TryEmitSound(component); + + if (component.Handle) + arg.Handled = true; } private void TryEmitSound(BaseEmitSoundComponent component)