-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from mazziechai/feature/slurred-speech-trait
Drunkard Accent
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
Content.Server/FloofStation/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.FloofStation.Speech.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class DrunkardAccentComponent : Component; |
84 changes: 84 additions & 0 deletions
84
Content.Server/FloofStation/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,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)); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ | |
id: ScottishAccent | ||
- type: trait # Floof | ||
id: GermanAccent | ||
- type: trait # Floof | ||
id: DrunkardAccent |
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