Add-d-ds s-s-stut-ttering t-to the g-gam-me (#4901)
This commit is contained in:
committed by
GitHub
parent
50802b123f
commit
3001ea38cc
84
Content.Server/Speech/EntitySystems/StutteringSystem.cs
Normal file
84
Content.Server/Speech/EntitySystems/StutteringSystem.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.Speech.Components;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Speech.EntitySystems;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Speech.EntitySystems
|
||||
{
|
||||
public class StutteringSystem : SharedStutteringSystem
|
||||
{
|
||||
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
private const string StutterKey = "Stutter";
|
||||
|
||||
// Regex of characters to stutter.
|
||||
private static readonly Regex Stutter = new(@"[b-df-hj-np-tv-wxyz]",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<StutteringAccentComponent, AccentGetEvent>(OnAccent);
|
||||
}
|
||||
|
||||
public override void DoStutter(EntityUid uid, TimeSpan time, StatusEffectsComponent? status = null, SharedAlertsComponent? alerts = null)
|
||||
{
|
||||
if (!Resolve(uid, ref status, false))
|
||||
return;
|
||||
|
||||
if (!_statusEffectsSystem.HasStatusEffect(uid, StutterKey, status))
|
||||
_statusEffectsSystem.TryAddStatusEffect<StutteringAccentComponent>(uid, StutterKey, time, status, alerts);
|
||||
else
|
||||
_statusEffectsSystem.TryAddTime(uid, StutterKey, time, status);
|
||||
}
|
||||
|
||||
private void OnAccent(EntityUid uid, StutteringAccentComponent component, AccentGetEvent args)
|
||||
{
|
||||
args.Message = Accentuate(args.Message);
|
||||
}
|
||||
|
||||
public string Accentuate(string message)
|
||||
{
|
||||
var length = message.Length;
|
||||
|
||||
var finalMessage = new StringBuilder();
|
||||
|
||||
string newLetter;
|
||||
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
newLetter = message[i].ToString();
|
||||
if (Stutter.IsMatch(newLetter) && _random.Prob(0.8f))
|
||||
{
|
||||
if (_random.Prob(0.1f))
|
||||
{
|
||||
newLetter = $"{newLetter}-{newLetter}-{newLetter}-{newLetter}";
|
||||
}
|
||||
else if (_random.Prob(0.2f))
|
||||
{
|
||||
newLetter = $"{newLetter}-{newLetter}-{newLetter}";
|
||||
}
|
||||
else if (_random.Prob(0.05f))
|
||||
{
|
||||
newLetter = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
newLetter = $"{newLetter}-{newLetter}";
|
||||
}
|
||||
}
|
||||
|
||||
finalMessage.Append(newLetter);
|
||||
}
|
||||
|
||||
return finalMessage.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user