mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* move-accents-to-shared * Update AccentSystem.cs * Update ListeningSystem.cs * aaaaaa * Update AccentSystem.cs * oh god * aaooao * // * review * fix * Update VocalSystem.cs
94 lines
3.6 KiB
C#
94 lines
3.6 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 MobsterAccentSystem : RelayAccentSystem<MobsterAccentComponent>
|
|
{
|
|
private static readonly Regex RegexIng = new(@"(?<=\w\w)(in)g(?!\w)", RegexOptions.IgnoreCase);
|
|
private static readonly Regex RegexLowerOr = new(@"(?<=\w)o[Rr](?=\w)");
|
|
private static readonly Regex RegexUpperOr = new(@"(?<=\w)O[Rr](?=\w)");
|
|
private static readonly Regex RegexLowerAr = new(@"(?<=\w)a[Rr](?=\w)");
|
|
private static readonly Regex RegexUpperAr = new(@"(?<=\w)A[Rr](?=\w)");
|
|
private static readonly Regex RegexFirstWord = new(@"^(\S+)");
|
|
private static readonly Regex RegexLastWord = new(@"(\S+)$");
|
|
private static readonly Regex RegexLastPunctuation = new(@"([.!?]+$)(?!.*[.!?])|(?<![.!?])$");
|
|
|
|
[Dependency] private IGameTiming _timing = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private ReplacementAccentSystem _replacement = default!;
|
|
|
|
public override string Accentuate(string message, Entity<MobsterAccentComponent>? ent = null)
|
|
{
|
|
// Order:
|
|
// Do text manipulations first
|
|
// Then prefix/suffix funnyies
|
|
|
|
var random = ent.HasValue
|
|
? SharedRandomExtensions.PredictedRandom(_timing, GetNetEntity(ent.Value))
|
|
: _random;
|
|
|
|
// direct word replacements
|
|
var msg = _replacement.ApplyReplacements(message, "mobster", ent?.Owner);
|
|
|
|
// thinking -> thinkin'
|
|
// king -> king
|
|
//Uses captures groups to make sure the captialization of IN is kept
|
|
msg = RegexIng.Replace(msg, "$1'");
|
|
|
|
// or -> uh and ar -> ah in the middle of words (fuhget, tahget)
|
|
msg = RegexLowerOr.Replace(msg, "uh");
|
|
msg = RegexUpperOr.Replace(msg, "UH");
|
|
msg = RegexLowerAr.Replace(msg, "ah");
|
|
msg = RegexUpperAr.Replace(msg, "AH");
|
|
|
|
// Prefix
|
|
if (random.Prob(0.15f))
|
|
{
|
|
//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 = !RegexFirstWord.Match(msg).Value.Any(char.IsLower);
|
|
var pick = random.Next(1, 2);
|
|
|
|
// Reverse sanitize capital
|
|
var prefix = Loc.GetString($"accent-mobster-prefix-{pick}");
|
|
if (!firstWordAllCaps)
|
|
msg = msg[0].ToString().ToLower() + msg.Remove(0, 1);
|
|
else
|
|
prefix = prefix.ToUpper();
|
|
msg = prefix + " " + msg;
|
|
}
|
|
|
|
// Sanitize capital again, in case we substituted a word that should be capitalized
|
|
msg = msg[0].ToString().ToUpper() + msg.Remove(0, 1);
|
|
|
|
// Suffixes
|
|
if (random.Prob(0.4f))
|
|
{
|
|
//Checks if the last word of the sentence is all caps
|
|
//So the suffix can be allcapped
|
|
var lastWordAllCaps = !RegexLastWord.Match(msg).Value.Any(char.IsLower);
|
|
string suffix;
|
|
if (ent.HasValue && ent.Value.Comp.IsBoss)
|
|
{
|
|
var pick = random.Next(1, 4);
|
|
suffix = Loc.GetString($"accent-mobster-suffix-boss-{pick}");
|
|
}
|
|
else
|
|
{
|
|
var pick = random.Next(1, 3);
|
|
suffix = Loc.GetString($"accent-mobster-suffix-minion-{pick}");
|
|
}
|
|
|
|
if (lastWordAllCaps)
|
|
suffix = suffix.ToUpper();
|
|
msg = RegexLastPunctuation.Replace(msg, suffix);
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
}
|