CatStation/Content.Server/Corvax/Speech/EntitySystems/GrowlingAccentSystem.cs
2023-12-10 15:42:57 +03:00

50 lines
1.3 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.RegularExpressions;
using Content.Server.Corvax.Speech.Components;
using Content.Server.Speech;
using Robust.Shared.Random;
namespace Content.Server.Corvax.Speech.EntitySystems;
public sealed class GrowlingAccentSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GrowlingAccentComponent, AccentGetEvent>(OnAccent);
}
private void OnAccent(EntityUid uid, GrowlingAccentComponent component, AccentGetEvent args)
{
var message = args.Message;
// r => rrr
message = Regex.Replace(
message,
"r+",
_random.Pick(new List<string> { "rr", "rrr" })
);
// R => RRR
message = Regex.Replace(
message,
"R+",
_random.Pick(new List<string> { "RR", "RRR" })
);
// р => ррр
message = Regex.Replace(
message,
"р+",
_random.Pick(new List<string> { "рр", "ррр" })
);
// Р => РРР
message = Regex.Replace(
message,
"Р+",
_random.Pick(new List<string> { "РР", "РРР" })
);
args.Message = message;
}
}