Files
ss14-wega/Content.Server/Speech/EntitySystems/RandomAccentuator.cs
qwerltaz 20c962aae1 [april fools] The world feels different today. You examine objects around you but can't quite make out what's in front of you. (#35879)
* maybeAccentuate

* accentuate examine nodes

* working prototype

* random accentuator

* fix SingleAccentuator.cs

* french, mumble, slurred

* mobster, pirate, stutter

* remove examine prediction (for one day)

* random accents per examine, not per sentence

* Revert "random accents per examine, not per sentence"

This reverts commit 0dfa644bb760e4b3f760f43db8870f43ea75e64d.

* crew manifest

* tweak examine reaccentuation chance

* alert level announcement

* event centcom announcements

* tweak accent system signatures

* nuke annoucement, tweak manifest chance

* accentuation rarer and a bit more messed up

* examine tooltips

* more centcom announcements

* reformat

* sophisticated reformatting

* less

* tweak

---------

Co-authored-by: Milon <milonpl.git@proton.me>
2025-03-31 14:35:12 +02:00

67 lines
2.1 KiB
C#

using Robust.Shared.Random;
using Robust.Shared.Utility;
namespace Content.Server.Speech.EntitySystems;
public static class RandomAccentuator
{
private const float DefaultAccentuationChance = 0.25f;
private const float DefaultReaccentuationChance = 0.15f;
private const float MaxReaccentuations = 4;
public static string MaybeAccentuate(string message,
float chance = DefaultAccentuationChance,
float reaccentuationChance = DefaultReaccentuationChance)
{
var random = IoCManager.Resolve<IRobustRandom>();
var singleAccentuator = new SingleAccentuator();
return random.Prob(chance)
? MaybeAccentuateDirect(message, singleAccentuator, random, reaccentuationChance)
: message;
}
public static FormattedMessage MaybeAccentuate(FormattedMessage message,
float chance = DefaultAccentuationChance,
float reaccentuationChance = DefaultReaccentuationChance)
{
var random = IoCManager.Resolve<IRobustRandom>();
var singleAccentuator = new SingleAccentuator();
var newMessage = new FormattedMessage();
foreach (var node in message)
{
if (random.Prob(chance) && node.Name is null && node.Value.TryGetString(out var text) &&
!string.IsNullOrWhiteSpace(text))
{
var accentedText = MaybeAccentuateDirect(text, singleAccentuator, random, reaccentuationChance);
newMessage.PushTag(new MarkupNode(accentedText));
}
else
{
newMessage.PushTag(node);
}
}
return newMessage;
}
private static string MaybeAccentuateDirect(string message,
SingleAccentuator singleAccentuator,
IRobustRandom random,
float reaccentuationChance)
{
for (var i = 0; i < MaxReaccentuations; i++)
{
if (i > 0 && !random.Prob(reaccentuationChance))
continue;
singleAccentuator.NextSystem();
message = singleAccentuator.Accentuate(message);
}
return message;
}
}