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
9
Content.Client/Speech/EntitySystems/StutteringSystem.cs
Normal file
9
Content.Client/Speech/EntitySystems/StutteringSystem.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Content.Shared.Speech.EntitySystems;
|
||||
|
||||
namespace Content.Client.Speech.EntitySystems
|
||||
{
|
||||
public class StutteringSystem : SharedStutteringSystem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace Content.Server.Speech
|
||||
{
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
|
||||
public static readonly Regex SentenceRegex = new(@"(?<=[\.!\?])");
|
||||
public static readonly Regex SentenceRegex = new(@"(?<=[\.!\?])", RegexOptions.Compiled);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Speech.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class StutteringAccentComponent : Component
|
||||
{
|
||||
public override string Name => "StutteringAccent";
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Jittering;
|
||||
using Content.Server.PowerCell.Components;
|
||||
using Content.Server.Speech.EntitySystems;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.ActionBlocker;
|
||||
@@ -27,6 +28,7 @@ namespace Content.Server.Stunnable
|
||||
public class StunbatonSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly StunSystem _stunSystem = default!;
|
||||
[Dependency] private readonly StutteringSystem _stutteringSystem = default!;
|
||||
[Dependency] private readonly SharedJitteringSystem _jitterSystem = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
|
||||
@@ -139,7 +141,9 @@ namespace Content.Server.Stunnable
|
||||
_stunSystem.TrySlowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, status);
|
||||
}
|
||||
|
||||
_jitterSystem.DoJitter(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime));
|
||||
var slowdownTime = TimeSpan.FromSeconds(comp.SlowdownTime);
|
||||
_jitterSystem.DoJitter(entity.Uid, slowdownTime, status:status);
|
||||
_stutteringSystem.DoStutter(entity.Uid, slowdownTime, status);
|
||||
|
||||
if (!comp.Owner.TryGetComponent<PowerCellSlotComponent>(out var slot) || slot.Cell == null || !(slot.Cell.CurrentCharge < comp.EnergyPerUse))
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Speech.EntitySystems
|
||||
{
|
||||
public abstract class SharedStutteringSystem : EntitySystem
|
||||
{
|
||||
// For code in shared... I imagine we ain't getting accent prediction anytime soon so let's not bother.
|
||||
public virtual void DoStutter(EntityUid uid, TimeSpan time, StatusEffectsComponent? status = null, SharedAlertsComponent? alerts = null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,9 +213,11 @@ namespace Content.Shared.StatusEffect
|
||||
Resolve(uid, ref alerts, false);
|
||||
|
||||
var state = status.ActiveEffects[key];
|
||||
if (state.RelevantComponent != null)
|
||||
|
||||
// There are cases where a status effect component might be server-only, so TryGetRegistration...
|
||||
if (state.RelevantComponent != null && _componentFactory.TryGetRegistration(state.RelevantComponent, out var registration))
|
||||
{
|
||||
var type = _componentFactory.GetRegistration(state.RelevantComponent).Type;
|
||||
var type = registration.Type;
|
||||
|
||||
// Make sure the component is actually there first.
|
||||
// Maybe a badmin badminned the component away,
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
- Stun
|
||||
- KnockedDown
|
||||
- SlowedDown
|
||||
- Stutter
|
||||
# Other
|
||||
- type: Inventory
|
||||
- type: Clickable
|
||||
|
||||
@@ -15,3 +15,6 @@
|
||||
- type: statusEffect
|
||||
id: Jitter
|
||||
alwaysAllowed: true
|
||||
|
||||
- type: statusEffect
|
||||
id: Stutter
|
||||
|
||||
Reference in New Issue
Block a user