]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Muzzles reduce emote sound (#34444)
authorthemias <89101928+themias@users.noreply.github.com>
Thu, 5 Jun 2025 23:45:55 +0000 (19:45 -0400)
committerGitHub <noreply@github.com>
Thu, 5 Jun 2025 23:45:55 +0000 (19:45 -0400)
* Muzzles reduce emote sound

* update based on review comments

* review comments

Content.Server/Chat/Systems/ChatSystem.Emote.cs
Content.Server/Speech/Components/MumbleAccentComponent.cs
Content.Server/Speech/EntitySystems/MumbleAccentSystem.cs
Content.Server/Speech/Muting/MutingSystem.cs

index 707a0e0dc5d5887fe19526ceac5f2e392008bb89..75acd2493bbc606a06c5853f323abfac9df870aa 100644 (file)
@@ -1,6 +1,7 @@
 using System.Collections.Frozen;
 using Content.Shared.Chat.Prototypes;
 using Content.Shared.Speech;
+using Robust.Shared.Audio;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 
@@ -126,16 +127,16 @@ public partial class ChatSystem
     ///     Tries to find and play relevant emote sound in emote sounds collection.
     /// </summary>
     /// <returns>True if emote sound was played.</returns>
-    public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, EmotePrototype emote)
+    public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, EmotePrototype emote, AudioParams? audioParams = null)
     {
-        return TryPlayEmoteSound(uid, proto, emote.ID);
+        return TryPlayEmoteSound(uid, proto, emote.ID, audioParams);
     }
 
     /// <summary>
     ///     Tries to find and play relevant emote sound in emote sounds collection.
     /// </summary>
     /// <returns>True if emote sound was played.</returns>
-    public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, string emoteId)
+    public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, string emoteId, AudioParams? audioParams = null)
     {
         if (proto == null)
             return false;
@@ -149,8 +150,8 @@ public partial class ChatSystem
                 return false;
         }
 
-        // if general params for all sounds set - use them
-        var param = proto.GeneralParams ?? sound.Params;
+        // optional override params > general params for all sounds in set > individual sound params
+        var param = audioParams ?? proto.GeneralParams ?? sound.Params;
         _audio.PlayPvs(sound, uid, param);
         return true;
     }
index 0681ebab2f87599d5d02e6c381e2fa3bec53efdb..2577859b1586e8bd01aa1aff03b9d151d20428b6 100644 (file)
@@ -1,7 +1,14 @@
+using Robust.Shared.Audio;
+
 namespace Content.Server.Speech.Components;
 
 [RegisterComponent]
 public sealed partial class MumbleAccentComponent : Component
 {
-
+    /// <summary>
+    /// This modifies the audio parameters of emote sounds, screaming, laughing, etc.
+    /// By default, it reduces the volume and distance of emote sounds.
+    /// </summary>
+    [DataField]
+    public AudioParams EmoteAudioParams = AudioParams.Default.WithVolume(-8f).WithMaxDistance(5);
 }
index 757f31ad9ea24aa41318cd95a63ed0014c4b9e94..6b1af5c227eb0449dc11dc95e910e03570f5c710 100644 (file)
@@ -1,9 +1,13 @@
+using Content.Server.Chat.Systems;
 using Content.Server.Speech.Components;
+using Content.Shared.Chat.Prototypes;
+using Content.Shared.Speech.Components;
 
 namespace Content.Server.Speech.EntitySystems;
 
 public sealed class MumbleAccentSystem : EntitySystem
 {
+    [Dependency] private readonly ChatSystem _chat = default!;
     [Dependency] private readonly ReplacementAccentSystem _replacement = default!;
 
     public override void Initialize()
@@ -11,6 +15,19 @@ public sealed class MumbleAccentSystem : EntitySystem
         base.Initialize();
 
         SubscribeLocalEvent<MumbleAccentComponent, AccentGetEvent>(OnAccentGet);
+        SubscribeLocalEvent<MumbleAccentComponent, EmoteEvent>(OnEmote, before: [typeof(VocalSystem)]);
+    }
+
+    private void OnEmote(Entity<MumbleAccentComponent> ent, ref EmoteEvent args)
+    {
+        if (args.Handled || !args.Emote.Category.HasFlag(EmoteCategory.Vocal))
+            return;
+
+        if (TryComp<VocalComponent>(ent.Owner, out var vocalComp))
+        {
+            // play a muffled version of the vocal emote
+            args.Handled = _chat.TryPlayEmoteSound(ent.Owner, vocalComp.EmoteSounds, args.Emote, ent.Comp.EmoteAudioParams);
+        }
     }
 
     public string Accentuate(string message, MumbleAccentComponent component)
@@ -18,8 +35,8 @@ public sealed class MumbleAccentSystem : EntitySystem
         return _replacement.ApplyReplacements(message, "mumble");
     }
 
-    private void OnAccentGet(EntityUid uid, MumbleAccentComponent component, AccentGetEvent args)
+    private void OnAccentGet(Entity<MumbleAccentComponent> ent, ref AccentGetEvent args)
     {
-        args.Message = Accentuate(args.Message, component);
+        args.Message = Accentuate(args.Message, ent.Comp);
     }
 }
index 238d501e249d3b98e8e4d3f6438f17ceae72dc43..edf82bbfb2862eac9ddf0c528e0057f4eb7ecc48 100644 (file)
@@ -17,7 +17,7 @@ namespace Content.Server.Speech.Muting
         {
             base.Initialize();
             SubscribeLocalEvent<MutedComponent, SpeakAttemptEvent>(OnSpeakAttempt);
-            SubscribeLocalEvent<MutedComponent, EmoteEvent>(OnEmote, before: new[] { typeof(VocalSystem) });
+            SubscribeLocalEvent<MutedComponent, EmoteEvent>(OnEmote, before: new[] { typeof(VocalSystem), typeof(MumbleAccentSystem) });
             SubscribeLocalEvent<MutedComponent, ScreamActionEvent>(OnScreamAction, before: new[] { typeof(VocalSystem) });
         }