Skip to content

Commit

Permalink
Merge pull request #476 from mazziechai/feature/slurred-speech-trait
Browse files Browse the repository at this point in the history
Drunkard Accent
  • Loading branch information
FoxxoTrystan authored Jan 11, 2025
2 parents 1a02689 + c714dcc commit 6a4b2c3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Server.FloofStation.Speech.Components;

[RegisterComponent]
public sealed partial class DrunkardAccentComponent : Component;
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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()
{
base.Initialize();

SubscribeLocalEvent<DrunkardAccentComponent, AccentGetEvent>(OnAccent);
}

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

foreach (var character in message)
{
if (_random.Prob(scale / 3))
{
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(scale * 3 / 20))
{
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)
{
// 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));
}
}
}
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/Floof/traits/traits.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions Resources/Prototypes/CharacterItemGroups/languageGroups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
id: ScottishAccent
- type: trait # Floof
id: GermanAccent
- type: trait # Floof
id: DrunkardAccent
11 changes: 11 additions & 0 deletions Resources/Prototypes/Floof/Traits/neutral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6a4b2c3

Please sign in to comment.