CatStation/Content.Shared/Speech/EntitySystems/ScrambledAccentSystem.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

44 lines
1.4 KiB
C#

using System.Linq;
using System.Text.RegularExpressions;
using Content.Shared.Random.Helpers;
using Content.Shared.Speech.Components;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Shared.Speech.EntitySystems;
public sealed partial class ScrambledAccentSystem : RelayAccentSystem<ScrambledAccentComponent>
{
private static readonly Regex RegexLoneI = new(@"(?<=\ )i(?=[\ \.\?]|$)");
[Dependency] private IGameTiming _timing = default!;
[Dependency] private IRobustRandom _random = default!;
public override string Accentuate(string message, Entity<ScrambledAccentComponent>? ent = null)
{
var random = ent.HasValue
? SharedRandomExtensions.PredictedRandom(_timing, GetNetEntity(ent.Value))
: _random;
var words = message.ToLower().Split();
if (words.Length < 2)
{
var pick = random.Next(1, 8);
// If they try to weasel out of it by saying one word at a time we give them this.
return Loc.GetString($"accent-scrambled-words-{pick}");
}
// Scramble the words
var scrambled = words.OrderBy(_ => random.Next()).ToArray();
var msg = string.Join(" ", scrambled);
// First letter should be capital
msg = msg[0].ToString().ToUpper() + msg.Remove(0, 1);
// Capitalize lone i's
msg = RegexLoneI.Replace(msg, "I");
return msg;
}
}