Skip to content

Commit

Permalink
feat: check SlurredSpeech if its effect is greater than DrunkardAccent
Browse files Browse the repository at this point in the history
if the SlurredSpeech probability scale is higher than the base value for DrunkardAccent, use that instead of the base value
  • Loading branch information
mazziechai committed Jan 11, 2025
1 parent f615e07 commit c714dcc
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
using System.Text;
using Content.Server.FloofStation.Speech.Components;
using Content.Server.Speech;
using Content.Shared.Drunk;
using Content.Shared.StatusEffect;
using Robust.Shared.Random;
using Robust.Shared.Timing;


namespace Content.Server.FloofStation.Speech.EntitySystems;


public sealed class DrunkardAccentSystem : EntitySystem
{
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IGameTiming _timing = default!;

public override void Initialize()
{
Expand All @@ -19,13 +24,13 @@ public override void Initialize()
}

// A modified copy of SlurredSystem's Accentuate.
public string Accentuate(string message)
public string Accentuate(string message, float scale)
{
var sb = new StringBuilder();

foreach (var character in message)
{
if (_random.Prob(0.1f))
if (_random.Prob(scale / 3))
{
var lower = char.ToLowerInvariant(character);
var newString = lower switch
Expand All @@ -41,7 +46,7 @@ public string Accentuate(string message)
sb.Append(newString);
}

if (!_random.Prob(0.05f))
if (!_random.Prob(scale * 3 / 20))
{
sb.Append(character);
continue;
Expand All @@ -60,6 +65,20 @@ public string Accentuate(string message)
return sb.ToString();
}

private void OnAccent(EntityUid uid, DrunkardAccentComponent component, AccentGetEvent args) =>
args.Message = Accentuate(args.Message);
private void OnAccent(EntityUid uid, DrunkardAccentComponent component, AccentGetEvent args)
{
// Drunk status effect calculations, ripped directly from SlurredSystem B)
if (!_statusEffectsSystem.TryGetTime(uid, SharedDrunkSystem.DrunkKey, out var time))
{
args.Message = Accentuate(args.Message, 0.25f);
}
else
{
var curTime = _timing.CurTime;
var timeLeft = (float) (time.Value.Item2 - curTime).TotalSeconds;
var drunkScale = Math.Clamp((timeLeft - 80) / 1100, 0f, 1f);

args.Message = Accentuate(args.Message, Math.Max(0.25f, drunkScale));
}
}
}

0 comments on commit c714dcc

Please sign in to comment.