Lower speech noise volume & refactor system (#24579)
* Lower speech noise sounds & refactor system christ fuck * MORE
This commit is contained in:
@@ -24,51 +24,55 @@ namespace Content.Server.Speech
|
|||||||
SubscribeLocalEvent<SpeechComponent, EntitySpokeEvent>(OnEntitySpoke);
|
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;
|
if (ent.Comp.SpeechSounds == null)
|
||||||
|
return null;
|
||||||
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;
|
|
||||||
|
|
||||||
// Play speech sound
|
// Play speech sound
|
||||||
string contextSound;
|
SoundSpecifier? contextSound;
|
||||||
var prototype = _protoManager.Index<SpeechSoundsPrototype>(component.SpeechSounds);
|
var prototype = _protoManager.Index<SpeechSoundsPrototype>(ent.Comp.SpeechSounds);
|
||||||
var message = args.Message;
|
|
||||||
|
|
||||||
// Different sounds for ask/exclaim based on last character
|
// Different sounds for ask/exclaim based on last character
|
||||||
switch (args.Message[^1])
|
contextSound = message[^1] switch
|
||||||
{
|
{
|
||||||
case '?':
|
'?' => prototype.AskSound,
|
||||||
contextSound = prototype.AskSound.GetSound();
|
'!' => prototype.ExclaimSound,
|
||||||
break;
|
_ => prototype.SaySound
|
||||||
case '!':
|
};
|
||||||
contextSound = prototype.ExclaimSound.GetSound();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
contextSound = prototype.SaySound.GetSound();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use exclaim sound if most characters are uppercase.
|
// Use exclaim sound if most characters are uppercase.
|
||||||
int uppercaseCount = 0;
|
int uppercaseCount = 0;
|
||||||
for (int i = 0; i < message.Length; i++)
|
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))
|
if (uppercaseCount > (message.Length / 2))
|
||||||
{
|
{
|
||||||
contextSound = contextSound = prototype.ExclaimSound.GetSound();
|
contextSound = prototype.ExclaimSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scale = (float) _random.NextGaussian(1, prototype.Variation);
|
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;
|
component.LastTimeSoundPlayed = currentTime;
|
||||||
_audio.PlayPvs(contextSound, uid, pitchedAudioParams);
|
_audio.PlayPvs(sound, uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Server.Chat.Systems;
|
using Content.Server.Chat.Systems;
|
||||||
|
using Content.Server.Speech;
|
||||||
using Content.Shared.Speech;
|
using Content.Shared.Speech;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
@@ -14,6 +15,7 @@ namespace Content.Server.SurveillanceCamera;
|
|||||||
public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
|
public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||||
|
[Dependency] private readonly SpeechSoundSystem _speechSound = default!;
|
||||||
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
@@ -37,35 +39,12 @@ public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
|
|||||||
var cd = TimeSpan.FromSeconds(component.SpeechSoundCooldown);
|
var cd = TimeSpan.FromSeconds(component.SpeechSoundCooldown);
|
||||||
|
|
||||||
// this part's mostly copied from speech
|
// this part's mostly copied from speech
|
||||||
|
// what is wrong with you?
|
||||||
if (time - component.LastSoundPlayed < cd
|
if (time - component.LastSoundPlayed < cd
|
||||||
&& TryComp<SpeechComponent>(args.Speaker, out var speech)
|
&& TryComp<SpeechComponent>(args.Speaker, out var speech))
|
||||||
&& speech.SpeechSounds != null
|
|
||||||
&& _prototypeManager.TryIndex(speech.SpeechSounds, out SpeechSoundsPrototype? speechProto))
|
|
||||||
{
|
{
|
||||||
var sound = args.Message[^1] switch
|
var sound = _speechSound.GetSpeechSound((args.Speaker, speech), args.Message);
|
||||||
{
|
_audioSystem.PlayPvs(sound, uid);
|
||||||
'?' => 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);
|
|
||||||
|
|
||||||
component.LastSoundPlayed = time;
|
component.LastSoundPlayed = time;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace Content.Shared.Speech
|
|||||||
};
|
};
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public AudioParams AudioParams = AudioParams.Default.WithVolume(6f).WithRolloffFactor(4.5f);
|
public AudioParams AudioParams = AudioParams.Default.WithVolume(-2f).WithRolloffFactor(4.5f);
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField]
|
[DataField]
|
||||||
|
|||||||
Reference in New Issue
Block a user