Files
tbd-station-14/Content.Server/Speech/EntitySystems/BarkAccentSystem.cs
Ed 088d39f7ac Bread dog (#22548)
* add content

* add new bark accent
2023-12-16 01:30:20 -07:00

44 lines
1.3 KiB
C#

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>{
" 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);
}
}
}