Files
crystall-punk-14/Content.Server/Speech/EntitySystems/MumbleAccentSystem.cs

43 lines
1.4 KiB
C#
Raw Normal View History

using Content.Server.Chat.Systems;
2025-01-14 19:10:39 -05:00
using Content.Server.Speech.Components;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Speech.Components;
2025-01-14 19:10:39 -05:00
namespace Content.Server.Speech.EntitySystems;
public sealed class MumbleAccentSystem : EntitySystem
{
[Dependency] private readonly ChatSystem _chat = default!;
2025-01-14 19:10:39 -05:00
[Dependency] private readonly ReplacementAccentSystem _replacement = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MumbleAccentComponent, AccentGetEvent>(OnAccentGet);
SubscribeLocalEvent<MumbleAccentComponent, EmoteEvent>(OnEmote, before: [typeof(VocalSystem)]);
}
private void OnEmote(Entity<MumbleAccentComponent> ent, ref EmoteEvent args)
{
if (args.Handled || !args.Emote.Category.HasFlag(EmoteCategory.Vocal))
return;
if (TryComp<VocalComponent>(ent.Owner, out var vocalComp))
{
// play a muffled version of the vocal emote
args.Handled = _chat.TryPlayEmoteSound(ent.Owner, vocalComp.EmoteSounds, args.Emote, ent.Comp.EmoteAudioParams);
}
2025-01-14 19:10:39 -05:00
}
public string Accentuate(string message, MumbleAccentComponent component)
{
return _replacement.ApplyReplacements(message, "mumble");
}
private void OnAccentGet(Entity<MumbleAccentComponent> ent, ref AccentGetEvent args)
2025-01-14 19:10:39 -05:00
{
args.Message = Accentuate(args.Message, ent.Comp);
2025-01-14 19:10:39 -05:00
}
}