From 1f8d82a2c64c94f19d790f81404a6342e6c5282c Mon Sep 17 00:00:00 2001 From: Preston Smith <92108534+thetolbean@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:06:39 -0600 Subject: [PATCH] Add Illeism trait (#199) * Port Illeism trait * Namespace change 1 Co-authored-by: FluffMe <1780586+FluffMe@users.noreply.github.com> Signed-off-by: Preston Smith <92108534+thetolbean@users.noreply.github.com> * namespace change 2 Co-authored-by: FluffMe <1780586+FluffMe@users.noreply.github.com> Signed-off-by: Preston Smith <92108534+thetolbean@users.noreply.github.com> * Import corrections --------- Signed-off-by: Preston Smith <92108534+thetolbean@users.noreply.github.com> Co-authored-by: FluffMe <1780586+FluffMe@users.noreply.github.com> --- .../Components/IlleismAccentComponent.cs | 8 ++ .../EntitySystems/IlleismAccentSystem.cs | 124 ++++++++++++++++++ .../Locale/en-US/_Harmony/traits/traits.ftl | 5 +- .../Prototypes/_Harmony/Traits/speech.yml | 9 ++ 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 Content.Server/_Harmony/Speech/Components/IlleismAccentComponent.cs create mode 100644 Content.Server/_Harmony/Speech/EntitySystems/IlleismAccentSystem.cs diff --git a/Content.Server/_Harmony/Speech/Components/IlleismAccentComponent.cs b/Content.Server/_Harmony/Speech/Components/IlleismAccentComponent.cs new file mode 100644 index 000000000000..a2e985e6dbf9 --- /dev/null +++ b/Content.Server/_Harmony/Speech/Components/IlleismAccentComponent.cs @@ -0,0 +1,8 @@ +using Content.Server._Harmony.Speech.EntitySystems; + +namespace Content.Server._Harmony.Speech.Components; + +[RegisterComponent] +[Access(typeof(IlleismAccentSystem))] +public sealed partial class IlleismAccentComponent : Component +{ } diff --git a/Content.Server/_Harmony/Speech/EntitySystems/IlleismAccentSystem.cs b/Content.Server/_Harmony/Speech/EntitySystems/IlleismAccentSystem.cs new file mode 100644 index 000000000000..637660d1a693 --- /dev/null +++ b/Content.Server/_Harmony/Speech/EntitySystems/IlleismAccentSystem.cs @@ -0,0 +1,124 @@ +using System.Text.RegularExpressions; +using System.Text; +using Content.Server.Speech; +using Content.Server.Speech.EntitySystems; +using Content.Server._Harmony.Speech.Components; + +namespace Content.Server._Harmony.Speech.EntitySystems; + +public sealed class IlleismAccentSystem : EntitySystem +{ + // I am going to Sec -> NAME is going to Sec + private static readonly Regex RegexIAmUpper = new(@"\bI\s*AM\b|\bI'?M\b"); + private static readonly Regex RegexIAmLower = new(@"\bi\s*am\b|\bI'?m\b", RegexOptions.IgnoreCase); + + // I have it -> NAME has it + private static readonly Regex RegexIHaveUpper = new(@"\bI\s*HAVE\b|\bI'?VE\b"); + private static readonly Regex RegexIHaveLower = new(@"\bi\s*have\b|\bI'?ve\b", RegexOptions.IgnoreCase); + + // I do! -> NAME does! + private static readonly Regex RegexIDoUpper = new(@"\bI\s*DO\b"); + private static readonly Regex RegexIDoLower = new(@"\bi\s*do\b", RegexOptions.IgnoreCase); + + // I don't! -> NAME doesn't! + private static readonly Regex RegexIDontUpper = new(@"\bI\s+DON'?T\b"); + private static readonly Regex RegexIDontLower = new(@"\bi\s+don'?t\b", RegexOptions.IgnoreCase); + + // I/Myself -> NAME + private static readonly Regex RegexMyselfUpper = new(@"\bMYSELF\b"); + private static readonly Regex RegexI = new(@"\bI\b|\bmyself\b", RegexOptions.IgnoreCase); + + // Me -> NAME + private static readonly Regex RegexMeUpper = new(@"\bME\b"); + private static readonly Regex RegexMeLower = new(@"\bme\b", RegexOptions.IgnoreCase); + + // My crowbar -> NAME's crowbar + // That's mine! -> That's NAME's + private static readonly Regex RegexMyUpper = new(@"\bMY\b|\bMINE\b"); + private static readonly Regex RegexMyLower = new(@"\bmy\b|\bmine\b", RegexOptions.IgnoreCase); + + // I'll do it -> NAME'll do it + private static readonly Regex RegexIllUpper = new(@"\bI'LL\b"); + private static readonly Regex RegexIllLower = new(@"\bi'll\b", RegexOptions.IgnoreCase); + + + [Dependency] private readonly ReplacementAccentSystem _replacement = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnAccent); + } + + private bool MostlyUppercase(string message) + { + int totalLetters = 0; + int uppercaseLetters = 0; + + // Iterate through each character in the string + foreach (char c in message) + { + if (char.IsLetter(c)) // Check if the character is a letter + { + totalLetters++; + if (char.IsUpper(c)) // Check if the letter is uppercase + { + uppercaseLetters++; + } + } + } + if (totalLetters < 2) + { + return false; + } + return uppercaseLetters > totalLetters / 2; + } + + private void OnAccent(EntityUid uid, IlleismAccentComponent component, AccentGetEvent args) + { + var message = args.Message; + var name = Name(uid).Split(' ')[0]; + var upperName = name.ToUpper(); + + // I am going to Sec -> NAME is going to Sec + message = RegexIAmUpper.Replace(message, upperName + " IS"); + message = RegexIAmLower.Replace(message, name + " is"); + + // I have it -> NAME has it + message = RegexIHaveUpper.Replace(message, upperName + " HAS"); + message = RegexIHaveLower.Replace(message, name + " has"); + + // I do! -> NAME does! + message = RegexIDoUpper.Replace(message, upperName + " DOES"); + message = RegexIDoLower.Replace(message, name + " does"); + + // I don't! -> NAME doesn't! + message = RegexIDontUpper.Replace(message, upperName + " DOESN'T"); + message = RegexIDontLower.Replace(message, name + " doesn't"); + + // I'll do it -> NAME will do it + message = RegexIllUpper.Replace(message, upperName + " WILL"); + message = RegexIllLower.Replace(message, name + " will"); + + // I/myself -> NAME + message = RegexMyselfUpper.Replace(message, upperName); + if (MostlyUppercase(message)) + { + message = RegexI.Replace(message, upperName); + } + else + { + message = RegexI.Replace(message, name); + } + + // Me -> NAME + message = RegexMeUpper.Replace(message, upperName); + message = RegexMeLower.Replace(message, name); + + // My crowbar -> NAME's crowbar + message = RegexMyUpper.Replace(message, upperName + "'S"); + message = RegexMyLower.Replace(message, name + "'s"); + + args.Message = message; + } +}; diff --git a/Resources/Locale/en-US/_Harmony/traits/traits.ftl b/Resources/Locale/en-US/_Harmony/traits/traits.ftl index 183589c50842..191eca3c2acc 100644 --- a/Resources/Locale/en-US/_Harmony/traits/traits.ftl +++ b/Resources/Locale/en-US/_Harmony/traits/traits.ftl @@ -47,4 +47,7 @@ trait-voxvocals-name = Voice of Vox trait-voxvocals-desc = You are somehow able to fully mimic Vox speech. (Replace speech sounds, verbs, and emote sounds) trait-hypophonia-name = Hypophonia -trait-hypophonia-desc = You can only whisper. \ No newline at end of file +trait-hypophonia-desc = You can only whisper. + +trait-illeism-name = Illeism +trait-illeism-desc = You seem to only be able to refer to yourself by name. diff --git a/Resources/Prototypes/_Harmony/Traits/speech.yml b/Resources/Prototypes/_Harmony/Traits/speech.yml index 1a2757d5d9c1..c28ed2cbb9e1 100644 --- a/Resources/Prototypes/_Harmony/Traits/speech.yml +++ b/Resources/Prototypes/_Harmony/Traits/speech.yml @@ -95,6 +95,15 @@ speechVerb: Vox speechSounds: Vox +- type: trait + id: HarmonyIlleism + name: trait-illeism-name + description: trait-illeism-desc + category: SpeechTraits + cost: 1 + components: + - type: IlleismAccent + # Full speech and vocal replacement traits - type: trait id: HarmonyArachnidVocals