Pathological Liar (#27618)
* content * upgrade * n't * ye ya * Update speech-liar.ftl * Mith replacement ideas * fix * more! * Revert "more!" This reverts commit 6d10bdf694985c525a2b451ed39380f975059b44. * Update Content.Server/Speech/Components/ReplacementAccentComponent.cs --------- Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
@@ -24,6 +24,9 @@ namespace Content.Server.Speech.EntitySystems
|
||||
|
||||
private void OnAccent(EntityUid uid, ReplacementAccentComponent component, AccentGetEvent args)
|
||||
{
|
||||
if (!_random.Prob(component.ReplacementChance))
|
||||
return;
|
||||
|
||||
args.Message = ApplyReplacements(args.Message, component.Accent);
|
||||
}
|
||||
|
||||
@@ -46,6 +49,12 @@ namespace Content.Server.Speech.EntitySystems
|
||||
if (prototype.WordReplacements == null)
|
||||
return message;
|
||||
|
||||
// Prohibition of repeated word replacements.
|
||||
// All replaced words placed in the final message are placed here as dashes (___) with the same length.
|
||||
// The regex search goes through this buffer message, from which the already replaced words are crossed out,
|
||||
// ensuring that the replaced words cannot be replaced again.
|
||||
var maskMessage = message;
|
||||
|
||||
foreach (var (first, replace) in prototype.WordReplacements)
|
||||
{
|
||||
var f = _loc.GetString(first);
|
||||
@@ -53,10 +62,10 @@ namespace Content.Server.Speech.EntitySystems
|
||||
// this is kind of slow but its not that bad
|
||||
// essentially: go over all matches, try to match capitalization where possible, then replace
|
||||
// rather than using regex.replace
|
||||
for (int i = Regex.Count(message, $@"(?<!\w){f}(?!\w)", RegexOptions.IgnoreCase); i > 0; i--)
|
||||
for (int i = Regex.Count(maskMessage, $@"(?<!\w){f}(?!\w)", RegexOptions.IgnoreCase); i > 0; i--)
|
||||
{
|
||||
// fetch the match again as the character indices may have changed
|
||||
Match match = Regex.Match(message, $@"(?<!\w){f}(?!\w)", RegexOptions.IgnoreCase);
|
||||
Match match = Regex.Match(maskMessage, $@"(?<!\w){f}(?!\w)", RegexOptions.IgnoreCase);
|
||||
var replacement = r;
|
||||
|
||||
// Intelligently replace capitalization
|
||||
@@ -80,6 +89,8 @@ namespace Content.Server.Speech.EntitySystems
|
||||
|
||||
// In-place replace the match with the transformed capitalization replacement
|
||||
message = message.Remove(match.Index, match.Length).Insert(match.Index, replacement);
|
||||
string mask = new string('_', match.Length);
|
||||
maskMessage = message.Remove(match.Index, match.Length).Insert(match.Index, mask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user