Files
space-station-14/Content.Server/Speech/EntitySystems/MonkeyAccentSystem.cs
2025-07-21 00:27:46 +07:00

67 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Text;
using Content.Server.Speech.Components;
using Content.Shared.Speech;
using Robust.Shared.Random;
namespace Content.Server.Speech.EntitySystems;
public sealed class MonkeyAccentSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
SubscribeLocalEvent<MonkeyAccentComponent, AccentGetEvent>(OnAccent);
}
public string Accentuate(string message)
{
var words = message.Split();
var accentedMessage = new StringBuilder(message.Length + 2);
for (var i = 0; i < words.Length; i++)
{
var word = words[i];
if (_random.NextDouble() >= 0.5)
{
if (word.Length > 1)
{
foreach (var _ in word)
{
accentedMessage.Append('У'); // Corvax-Localization
}
if (_random.NextDouble() >= 0.3)
accentedMessage.Append('К'); // Corvax-Localization
}
else
accentedMessage.Append('У'); // Corvax-Localization
}
else
{
foreach (var _ in word)
{
if (_random.NextDouble() >= 0.8)
accentedMessage.Append('Г'); // Corvax-Localization
else
accentedMessage.Append('А'); // Corvax-Localization
}
}
if (i < words.Length - 1)
accentedMessage.Append(' ');
}
accentedMessage.Append('!');
return accentedMessage.ToString();
}
private void OnAccent(EntityUid uid, MonkeyAccentComponent component, AccentGetEvent args)
{
args.Message = Accentuate(args.Message);
}
}