-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
3270d4d
commit f1a80f4
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
Content.Server/_DV/Speech/Components/DrunkardAccentComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace Content.Server._DV.Speech.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class DrunkardAccentComponent : Component; |
83 changes: 83 additions & 0 deletions
83
Content.Server/_DV/Speech/EntitySystems/DrunkardAccentSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Text; | ||
using Content.Server._DV.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._DV.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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters