| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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);
- }
- }
- }
|