BarkAccentSystem.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Server.Speech.Components;
  2. using Robust.Shared.Random;
  3. namespace Content.Server.Speech.EntitySystems
  4. {
  5. public sealed class BarkAccentSystem : EntitySystem
  6. {
  7. [Dependency] private readonly IRobustRandom _random = default!;
  8. private static readonly IReadOnlyList<string> Barks = new List<string>{
  9. " Woof!", " WOOF", " wof-wof"
  10. }.AsReadOnly();
  11. private static readonly IReadOnlyDictionary<string, string> SpecialWords = new Dictionary<string, string>()
  12. {
  13. { "ah", "arf" },
  14. { "Ah", "Arf" },
  15. { "oh", "oof" },
  16. { "Oh", "Oof" },
  17. };
  18. public override void Initialize()
  19. {
  20. SubscribeLocalEvent<BarkAccentComponent, AccentGetEvent>(OnAccent);
  21. }
  22. public string Accentuate(string message)
  23. {
  24. foreach (var (word, repl) in SpecialWords)
  25. {
  26. message = message.Replace(word, repl);
  27. }
  28. return message.Replace("!", _random.Pick(Barks))
  29. .Replace("l", "r").Replace("L", "R");
  30. }
  31. private void OnAccent(EntityUid uid, BarkAccentComponent component, AccentGetEvent args)
  32. {
  33. args.Message = Accentuate(args.Message);
  34. }
  35. }
  36. }