Files
tbd-station-14/Content.Server/Speech/EntitySystems/BarkAccentSystem.cs
Princess Cheeseballs 367ff79006 Accents Event to Shared (#38948)
* 27 file diff

* 27 file diff 2

* Apply suggestions from code review

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2025-07-12 22:52:51 +02:00

45 lines
1.3 KiB
C#

using Content.Server.Speech.Components;
using Content.Shared.Speech;
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>{
" Woof!", " WOOF", " wof-wof"
}.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);
}
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);
}
}
}