]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Lower speech noise volume & refactor system (#24579)
authorKara <lunarautomaton6@gmail.com>
Sun, 28 Jan 2024 10:49:55 +0000 (03:49 -0700)
committerGitHub <noreply@github.com>
Sun, 28 Jan 2024 10:49:55 +0000 (21:49 +1100)
* Lower speech noise sounds & refactor system christ fuck

* MORE

Content.Server/Speech/SpeechNoiseSystem.cs
Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSpeakerSystem.cs
Content.Shared/Speech/SpeechComponent.cs

index 4f66a0828bd412af5c5f02164b784bb33e489e76..5530f3fe57a317641beceada71f13383b9331be4 100644 (file)
@@ -24,51 +24,55 @@ namespace Content.Server.Speech
             SubscribeLocalEvent<SpeechComponent, EntitySpokeEvent>(OnEntitySpoke);
         }
 
-        private void OnEntitySpoke(EntityUid uid, SpeechComponent component, EntitySpokeEvent args)
+        public SoundSpecifier? GetSpeechSound(Entity<SpeechComponent> ent, string message)
         {
-            if (component.SpeechSounds == null) return;
-
-            var currentTime = _gameTiming.CurTime;
-            var cooldown = TimeSpan.FromSeconds(component.SoundCooldownTime);
-
-            // Ensure more than the cooldown time has passed since last speaking
-            if (currentTime - component.LastTimeSoundPlayed < cooldown) return;
+            if (ent.Comp.SpeechSounds == null)
+                return null;
 
             // Play speech sound
-            string contextSound;
-            var prototype = _protoManager.Index<SpeechSoundsPrototype>(component.SpeechSounds);
-            var message = args.Message;
+            SoundSpecifier? contextSound;
+            var prototype = _protoManager.Index<SpeechSoundsPrototype>(ent.Comp.SpeechSounds);
 
             // Different sounds for ask/exclaim based on last character
-            switch (args.Message[^1])
+            contextSound = message[^1] switch
             {
-                case '?':
-                    contextSound = prototype.AskSound.GetSound();
-                    break;
-                case '!':
-                    contextSound = prototype.ExclaimSound.GetSound();
-                    break;
-                default:
-                    contextSound = prototype.SaySound.GetSound();
-                    break;
-            }
+                '?' => prototype.AskSound,
+                '!' => prototype.ExclaimSound,
+                _ => prototype.SaySound
+            };
 
             // Use exclaim sound if most characters are uppercase.
             int uppercaseCount = 0;
             for (int i = 0; i < message.Length; i++)
             {
-                if (char.IsUpper(message[i])) uppercaseCount++;
+                if (char.IsUpper(message[i]))
+                    uppercaseCount++;
             }
             if (uppercaseCount > (message.Length / 2))
             {
-                contextSound = contextSound = prototype.ExclaimSound.GetSound();
+                contextSound = prototype.ExclaimSound;
             }
 
             var scale = (float) _random.NextGaussian(1, prototype.Variation);
-            var pitchedAudioParams = component.AudioParams.WithPitchScale(scale);
+            contextSound.Params = ent.Comp.AudioParams.WithPitchScale(scale);
+            return contextSound;
+        }
+
+        private void OnEntitySpoke(EntityUid uid, SpeechComponent component, EntitySpokeEvent args)
+        {
+            if (component.SpeechSounds == null)
+                return;
+
+            var currentTime = _gameTiming.CurTime;
+            var cooldown = TimeSpan.FromSeconds(component.SoundCooldownTime);
+
+            // Ensure more than the cooldown time has passed since last speaking
+            if (currentTime - component.LastTimeSoundPlayed < cooldown)
+                return;
 
+            var sound = GetSpeechSound((uid, component), args.Message);
             component.LastTimeSoundPlayed = currentTime;
-            _audio.PlayPvs(contextSound, uid, pitchedAudioParams);
+            _audio.PlayPvs(sound, uid);
         }
     }
 }
index ce3d8568ab3b77aa5f0df11c7d0d7c110ba4f186..7544fc376ba94cb04f66fb5f7d0f8152f77205a6 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Server.Chat.Systems;
+using Content.Server.Speech;
 using Content.Shared.Speech;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
@@ -14,6 +15,7 @@ namespace Content.Server.SurveillanceCamera;
 public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
 {
     [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
+    [Dependency] private readonly SpeechSoundSystem _speechSound = default!;
     [Dependency] private readonly ChatSystem _chatSystem = default!;
     [Dependency] private readonly IGameTiming _gameTiming = default!;
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
@@ -37,35 +39,12 @@ public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
         var cd = TimeSpan.FromSeconds(component.SpeechSoundCooldown);
 
         // this part's mostly copied from speech
+        //     what is wrong with you?
         if (time - component.LastSoundPlayed < cd
-            && TryComp<SpeechComponent>(args.Speaker, out var speech)
-            && speech.SpeechSounds != null
-            && _prototypeManager.TryIndex(speech.SpeechSounds, out SpeechSoundsPrototype? speechProto))
+            && TryComp<SpeechComponent>(args.Speaker, out var speech))
         {
-            var sound = args.Message[^1] switch
-            {
-                '?' => speechProto.AskSound,
-                '!' => speechProto.ExclaimSound,
-                _ => speechProto.SaySound
-            };
-
-            var uppercase = 0;
-            for (var i = 0; i < args.Message.Length; i++)
-            {
-                if (char.IsUpper(args.Message[i]))
-                {
-                    uppercase++;
-                }
-            }
-
-            if (uppercase > args.Message.Length / 2)
-            {
-                sound = speechProto.ExclaimSound;
-            }
-
-            var scale = (float) _random.NextGaussian(1, speechProto.Variation);
-            var param = speech.AudioParams.WithPitchScale(scale);
-            _audioSystem.PlayPvs(sound, uid, param);
+            var sound = _speechSound.GetSpeechSound((args.Speaker, speech), args.Message);
+            _audioSystem.PlayPvs(sound, uid);
 
             component.LastSoundPlayed = time;
         }
index 96e05502ad604c7c1ce81bf7efd2635612630c9b..272d9ef8cab45bb044ef7738448f0d1f5455537d 100644 (file)
@@ -41,7 +41,7 @@ namespace Content.Shared.Speech
         };
 
         [DataField]
-        public AudioParams AudioParams = AudioParams.Default.WithVolume(6f).WithRolloffFactor(4.5f);
+        public AudioParams AudioParams = AudioParams.Default.WithVolume(-2f).WithRolloffFactor(4.5f);
 
         [ViewVariables(VVAccess.ReadWrite)]
         [DataField]