Skip to content

Commit

Permalink
Add Illeism trait (#199)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
thetolbean and FluffMe authored Nov 20, 2024
1 parent 1de5a7b commit 1f8d82a
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
{ }
124 changes: 124 additions & 0 deletions Content.Server/_Harmony/Speech/EntitySystems/IlleismAccentSystem.cs
Original file line number Diff line number Diff line change
@@ -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<IlleismAccentComponent, AccentGetEvent>(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;
}
};
5 changes: 4 additions & 1 deletion Resources/Locale/en-US/_Harmony/traits/traits.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
9 changes: 9 additions & 0 deletions Resources/Prototypes/_Harmony/Traits/speech.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f8d82a

Please sign in to comment.