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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user