From f615e07e547ed5e9fb7cf0e8369bd49e337a3fcd Mon Sep 17 00:00:00 2001 From: Mazzie Date: Fri, 10 Jan 2025 22:01:18 -0800 Subject: [PATCH 1/2] feat: drunkard accent trait this uses a modified version of SlurredSystem's Accentuate for the trait with hardcoded values and removing the burping and "huh" additions. the functionality *could* be extracted into a static method, however it would require changing code in non-Floof code when this works perfectly fine --- .../Components/DrunkardAccentComponent.cs | 4 ++ .../EntitySystems/DrunkardAccentSystem.cs | 65 +++++++++++++++++++ .../Locale/en-US/Floof/traits/traits.ftl | 3 + .../CharacterItemGroups/languageGroups.yml | 2 + Resources/Prototypes/Floof/Traits/neutral.yml | 11 ++++ 5 files changed, 85 insertions(+) create mode 100644 Content.Server/FloofStation/Speech/Components/DrunkardAccentComponent.cs create mode 100644 Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs diff --git a/Content.Server/FloofStation/Speech/Components/DrunkardAccentComponent.cs b/Content.Server/FloofStation/Speech/Components/DrunkardAccentComponent.cs new file mode 100644 index 00000000000..c792e9bb0da --- /dev/null +++ b/Content.Server/FloofStation/Speech/Components/DrunkardAccentComponent.cs @@ -0,0 +1,4 @@ +namespace Content.Server.FloofStation.Speech.Components; + +[RegisterComponent] +public sealed partial class DrunkardAccentComponent : Component; diff --git a/Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs b/Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs new file mode 100644 index 00000000000..8f3a17bca61 --- /dev/null +++ b/Content.Server/FloofStation/Speech/EntitySystems/DrunkardAccentSystem.cs @@ -0,0 +1,65 @@ +using System.Text; +using Content.Server.FloofStation.Speech.Components; +using Content.Server.Speech; +using Robust.Shared.Random; + + +namespace Content.Server.FloofStation.Speech.EntitySystems; + + +public sealed class DrunkardAccentSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnAccent); + } + + // A modified copy of SlurredSystem's Accentuate. + public string Accentuate(string message) + { + var sb = new StringBuilder(); + + foreach (var character in message) + { + if (_random.Prob(0.1f)) + { + var lower = char.ToLowerInvariant(character); + var newString = lower switch + { + 'o' => "u", + 's' => "ch", + 'a' => "ah", + 'u' => "oo", + 'c' => "k", + _ => $"{character}", + }; + + sb.Append(newString); + } + + if (!_random.Prob(0.05f)) + { + sb.Append(character); + continue; + } + + var next = _random.Next(1, 3) switch + { + 1 => "'", + 2 => $"{character}{character}", + _ => $"{character}{character}{character}", + }; + + sb.Append(next); + } + + return sb.ToString(); + } + + private void OnAccent(EntityUid uid, DrunkardAccentComponent component, AccentGetEvent args) => + args.Message = Accentuate(args.Message); +} diff --git a/Resources/Locale/en-US/Floof/traits/traits.ftl b/Resources/Locale/en-US/Floof/traits/traits.ftl index f460e259114..c5818e27075 100644 --- a/Resources/Locale/en-US/Floof/traits/traits.ftl +++ b/Resources/Locale/en-US/Floof/traits/traits.ftl @@ -26,3 +26,6 @@ trait-description-Lightweight = trait-name-GermanAccent = German accent trait-description-GermanAccent = You seem to come from space Germany. + +trait-name-DrunkardAccent = Drunkard accent +trait-description-DrunkardAccent = You always sound like you're drunk. diff --git a/Resources/Prototypes/CharacterItemGroups/languageGroups.yml b/Resources/Prototypes/CharacterItemGroups/languageGroups.yml index c2eee269c4b..3a2ec85ea12 100644 --- a/Resources/Prototypes/CharacterItemGroups/languageGroups.yml +++ b/Resources/Prototypes/CharacterItemGroups/languageGroups.yml @@ -35,3 +35,5 @@ id: ScottishAccent - type: trait # Floof id: GermanAccent + - type: trait # Floof + id: DrunkardAccent diff --git a/Resources/Prototypes/Floof/Traits/neutral.yml b/Resources/Prototypes/Floof/Traits/neutral.yml index 14e11ed5f3a..e28506698e7 100644 --- a/Resources/Prototypes/Floof/Traits/neutral.yml +++ b/Resources/Prototypes/Floof/Traits/neutral.yml @@ -8,3 +8,14 @@ - !type:TraitAddComponent components: - type: GermanAccent + +- type: trait + id: DrunkardAccent + category: TraitsSpeechAccents + requirements: + - !type:CharacterItemGroupRequirement + group: TraitsAccents + functions: + - !type:TraitAddComponent + components: + - type: DrunkardAccent From c714dccbfa61fbc8b35817dc1db57d831e8ba630 Mon Sep 17 00:00:00 2001 From: Mazzie Date: Fri, 10 Jan 2025 23:06:14 -0800 Subject: [PATCH 2/2] 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 8f3a17bca61..9619ed6b2a3 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)); + } + } }