From c714dccbfa61fbc8b35817dc1db57d831e8ba630 Mon Sep 17 00:00:00 2001 From: Mazzie Date: Fri, 10 Jan 2025 23:06:14 -0800 Subject: [PATCH] feat: check SlurredSpeech if its effect is greater than DrunkardAccent if the SlurredSpeech probability scale is higher than the base value for DrunkardAccent, use that instead of the base value --- .../EntitySystems/DrunkardAccentSystem.cs | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs b/Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs index 8f3a17bca6..9619ed6b2a 100644 --- a/Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs +++ b/Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs @@ -1,7 +1,10 @@ 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; @@ -9,7 +12,9 @@ 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() { @@ -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 @@ -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; @@ -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)); + } + } }