Files
tbd-station-14/Content.Server/Speech/EntitySystems/SkeletonAccentSystem.cs
Princess Cheeseballs 367ff79006 Accents Event to Shared (#38948)
* 27 file diff

* 27 file diff 2

* Apply suggestions from code review

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2025-07-12 22:52:51 +02:00

52 lines
1.6 KiB
C#

using System.Text.RegularExpressions;
using Content.Server.Speech.Components;
using Content.Shared.Speech;
using Robust.Shared.Random;
namespace Content.Server.Speech.EntitySystems;
public sealed partial class SkeletonAccentSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ReplacementAccentSystem _replacement = default!;
[GeneratedRegex(@"(?<!\w)[^aeiou]one", RegexOptions.IgnoreCase, "en-US")]
private static partial Regex BoneRegex();
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SkeletonAccentComponent, AccentGetEvent>(OnAccentGet);
}
public string Accentuate(string message, SkeletonAccentComponent component)
{
// Order:
// Do character manipulations first
// Then direct word/phrase replacements
// Then prefix/suffix
var msg = message;
// Character manipulations:
// At the start of words, any non-vowel + "one" becomes "bone", e.g. tone -> bone ; lonely -> bonely; clone -> clone (remains unchanged).
msg = BoneRegex().Replace(msg, "bone");
// apply word replacements
msg = _replacement.ApplyReplacements(msg, "skeleton");
// Suffix:
if (_random.Prob(component.ackChance))
{
msg += (" " + Loc.GetString("skeleton-suffix")); // e.g. "We only want to socialize. ACK ACK!"
}
return msg;
}
private void OnAccentGet(EntityUid uid, SkeletonAccentComponent component, AccentGetEvent args)
{
args.Message = Accentuate(args.Message, component);
}
}