Files
OldThink/Content.Server/Speech/EntitySystems/BarkAccentSystem.cs

51 lines
1.5 KiB
C#
Raw Normal View History

using System.Text.RegularExpressions;
using Content.Server.Speech.Components;
using Robust.Shared.Random;
namespace Content.Server.Speech.EntitySystems
{
public sealed class BarkAccentSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
private static readonly IReadOnlyList<string> Barks = new List<string>{
" Гав!", " ГАВ", " гав-гав" // WD EDIT
}.AsReadOnly();
private static readonly IReadOnlyDictionary<string, string> SpecialWords = new Dictionary<string, string>()
{
{ "ah", "arf" },
{ "Ah", "Arf" },
{ "oh", "oof" },
{ "Oh", "Oof" },
};
public override void Initialize()
{
SubscribeLocalEvent<BarkAccentComponent, AccentGetEvent>(OnAccent);
}
public string Accentuate(string message)
{
foreach (var (word, repl) in SpecialWords)
{
message = message.Replace(word, repl);
}
// WD EDIT START
message = Regex.Replace(message, "р{1,3}", "ррр");
message = Regex.Replace(message, "Р{1,3}", "РРР");
// WD EDIT END
return message.Replace("!", _random.Pick(Barks))
.Replace("l", "r").Replace("L", "R");
}
private void OnAccent(EntityUid uid, BarkAccentComponent component, AccentGetEvent args)
{
args.Message = Accentuate(args.Message);
}
}
}