diff --git a/Content.Server/Speech/Components/SlowAccentComponent.cs b/Content.Server/Speech/Components/SlowAccentComponent.cs new file mode 100644 index 0000000000..1222475cb2 --- /dev/null +++ b/Content.Server/Speech/Components/SlowAccentComponent.cs @@ -0,0 +1,7 @@ +namespace Content.Server.Speech.Components; + +/// +/// Makes... the... entity... talk... like... this... +/// +[RegisterComponent] +public sealed partial class SlowAccentComponent : Component; diff --git a/Content.Server/Speech/EntitySystems/SlowAccentSystem.cs b/Content.Server/Speech/EntitySystems/SlowAccentSystem.cs new file mode 100644 index 0000000000..5a94b0a4d6 --- /dev/null +++ b/Content.Server/Speech/EntitySystems/SlowAccentSystem.cs @@ -0,0 +1,41 @@ +using System.Text.RegularExpressions; +using Content.Server.Speech.Components; + +namespace Content.Server.Speech.EntitySystems; + +public sealed partial class SlowAccentSystem : EntitySystem +{ + /// + /// Matches whitespace characters or commas (with or without a space after them). + /// + private static readonly Regex WordEndings = new("\\s|, |,"); + + /// + /// Matches the end of the string only if the last character is a "word" character. + /// + private static readonly Regex NoFinalPunctuation = new("\\w\\z"); + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnAccentGet); + } + + private void OnAccentGet(Entity ent, ref AccentGetEvent args) + { + args.Message = Accentuate(ent, args.Message); + } + + public string Accentuate(Entity ent, string message) + { + // Add... some... delay... between... each... word + message = WordEndings.Replace(message, "... "); + + // Add "..." to the end, if the last character is part of a word... + if (NoFinalPunctuation.IsMatch(message)) + message += "..."; + + return message; + } +} diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml index f57d87ed2f..967dda00db 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml @@ -3266,6 +3266,7 @@ - type: Grammar attributes: gender: epicene + - type: SlowAccent - type: Tag tags: - VimPilot