CatStation/Content.Shared/Speech/EntitySystems/PirateAccentSystem.cs
Pok 7a8fab78e3
Move Accents to Shared v2 (#44772)
* move-accents-to-shared

* Update AccentSystem.cs

* Update ListeningSystem.cs

* aaaaaa

* Update AccentSystem.cs

* oh god

* aaooao

* //

* review

* fix

* Update VocalSystem.cs
2026-07-25 22:29:39 +00:00

48 lines
1.8 KiB
C#

using System.Linq;
using Content.Shared.Random.Helpers;
using Content.Shared.Speech.Components;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using System.Text.RegularExpressions;
namespace Content.Shared.Speech.EntitySystems;
public sealed partial class PirateAccentSystem : RelayAccentSystem<PirateAccentComponent>
{
private static readonly Regex FirstWordAllCapsRegex = new(@"^(\S+)");
[Dependency] private IGameTiming _timing = default!;
[Dependency] private IRobustRandom _random = default!;
[Dependency] private ReplacementAccentSystem _replacement = default!;
// Converts left word when typed into the right word. For example typing you becomes ye.
public override string Accentuate(string message, Entity<PirateAccentComponent>? ent = null)
{
var random = ent.HasValue
? SharedRandomExtensions.PredictedRandom(_timing, GetNetEntity(ent.Value))
: _random;
var msg = _replacement.ApplyReplacements(message, "pirate", ent?.Owner);
if (!random.Prob(ent.HasValue ? ent.Value.Comp.YarrChance : 0.5f))
return msg;
// Checks if the first word of the sentence is all caps
// So the prefix can be allcapped and to not resanitize the captial
var firstWordAllCaps = !FirstWordAllCapsRegex.Match(msg).Value.Any(char.IsLower);
if (ent.HasValue)
{
var pick = random.Pick(ent.Value.Comp.PirateWords);
var pirateWord = Loc.GetString(pick);
// Reverse sanitize capital
if (!firstWordAllCaps)
msg = msg[0].ToString().ToLower() + msg.Remove(0, 1);
else
pirateWord = pirateWord.ToUpper();
msg = pirateWord + " " + msg;
}
return msg;
}
}