Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Illeism as a speech trait #32643

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Content.Server/Speech/Components/IlleismAccentComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Server.Speech.EntitySystems;

namespace Content.Server.Speech.Components;

[RegisterComponent]
[Access(typeof(IlleismAccentSystem))]
public sealed partial class IlleismAccentComponent : Component
{ }
120 changes: 120 additions & 0 deletions Content.Server/Speech/EntitySystems/IlleismAccentSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System.Text.RegularExpressions;
using Content.Server.Speech.Components;

namespace Content.Server.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");
private static readonly Regex RegexIAmLower = new(@"\bi\s*am\b", RegexOptions.IgnoreCase);

// I have it -> NAME has it
private static readonly Regex RegexIHaveUpper = new(@"\bI\s*HAVE\b");
private static readonly Regex RegexIHaveLower = new(@"\bi\s*have\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");

// 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");
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
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 == 0)
{
return false;
}
return uppercaseLetters > totalLetters / 2;
}

private void OnAccent(EntityUid uid, IlleismAccentComponent component, AccentGetEvent args)
{
var entityManager = IoCManager.Resolve<IEntityManager>();
thetolbean marked this conversation as resolved.
Show resolved Hide resolved
var message = args.Message;

// I am going to Sec -> NAME is going to Sec
message = RegexIAmUpper.Replace(message, (Name(uid) + " is").ToUpper());
message = RegexIAmLower.Replace(message, Name(uid) + " is");

// I have it -> NAME has it
message = RegexIHaveUpper.Replace(message, (Name(uid) + " has").ToUpper());
message = RegexIHaveLower.Replace(message, Name(uid) + " has");

// I do! -> NAME does!
message = RegexIDoUpper.Replace(message, (Name(uid) + " does").ToUpper());
message = RegexIDoLower.Replace(message, Name(uid) + " does");

// I don't! -> NAME doesn't!
message = RegexIDontUpper.Replace(message, (Name(uid) + " doesn't").ToUpper());
message = RegexIDontLower.Replace(message, Name(uid) + " doesn't");

// I/myself -> NAME
message = RegexMyselfUpper.Replace(message, Name(uid).ToUpper());
if (MostlyUppercase(message))
{
message = RegexI.Replace(message, Name(uid).ToUpper());
}
else
{
message = RegexI.Replace(message, Name(uid));
}

// Me -> NAME
message = RegexMeUpper.Replace(message, Name(uid).ToUpper());
message = RegexMeLower.Replace(message, Name(uid));

// My crowbar -> NAME's crowbar
message = RegexMyUpper.Replace(message, (Name(uid) + "'s").ToUpper());
message = RegexMyLower.Replace(message, Name(uid) + "'s");

// I'll do it -> NAME'll do it
message = RegexIllUpper.Replace(message, (Name(uid) + "'ll").ToUpper());
message = RegexIllLower.Replace(message, Name(uid) + "'ll");

args.Message = message;
}
};
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/traits/traits.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ trait-snoring-desc = You will snore while sleeping.
trait-liar-name = Pathological liar
trait-liar-desc = You can hardly bring yourself to tell the truth. Sometimes you lie anyway.

trait-illeism-name = Illeism
trait-illeism-desc = You seem to only be able to refer to yourself by name.

trait-cowboy-name = Cowboy accent
trait-cowboy-desc = You speak with a distinct cowboy accent!

Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/Traits/speech.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@

# 1 Cost

- type: trait
id: illeism
name: trait-illeism-name
description: trait-illeism-desc
category: SpeechTraits
cost: 1
components:
- type: IlleismAccent

- type: trait
id: SouthernAccent
name: trait-southern-name
Expand Down
Loading