using System.Collections.Frozen;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Speech;
+using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
/// Tries to find and play relevant emote sound in emote sounds collection.
/// </summary>
/// <returns>True if emote sound was played.</returns>
- public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, EmotePrototype emote)
+ public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, EmotePrototype emote, AudioParams? audioParams = null)
{
- return TryPlayEmoteSound(uid, proto, emote.ID);
+ return TryPlayEmoteSound(uid, proto, emote.ID, audioParams);
}
/// <summary>
/// Tries to find and play relevant emote sound in emote sounds collection.
/// </summary>
/// <returns>True if emote sound was played.</returns>
- public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, string emoteId)
+ public bool TryPlayEmoteSound(EntityUid uid, EmoteSoundsPrototype? proto, string emoteId, AudioParams? audioParams = null)
{
if (proto == null)
return false;
return false;
}
- // if general params for all sounds set - use them
- var param = proto.GeneralParams ?? sound.Params;
+ // optional override params > general params for all sounds in set > individual sound params
+ var param = audioParams ?? proto.GeneralParams ?? sound.Params;
_audio.PlayPvs(sound, uid, param);
return true;
}
+using Robust.Shared.Audio;
+
namespace Content.Server.Speech.Components;
[RegisterComponent]
public sealed partial class MumbleAccentComponent : Component
{
-
+ /// <summary>
+ /// This modifies the audio parameters of emote sounds, screaming, laughing, etc.
+ /// By default, it reduces the volume and distance of emote sounds.
+ /// </summary>
+ [DataField]
+ public AudioParams EmoteAudioParams = AudioParams.Default.WithVolume(-8f).WithMaxDistance(5);
}
+using Content.Server.Chat.Systems;
using Content.Server.Speech.Components;
+using Content.Shared.Chat.Prototypes;
+using Content.Shared.Speech.Components;
namespace Content.Server.Speech.EntitySystems;
public sealed class MumbleAccentSystem : EntitySystem
{
+ [Dependency] private readonly ChatSystem _chat = default!;
[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);
+ }
}
public string Accentuate(string message, MumbleAccentComponent component)
return _replacement.ApplyReplacements(message, "mumble");
}
- private void OnAccentGet(EntityUid uid, MumbleAccentComponent component, AccentGetEvent args)
+ private void OnAccentGet(Entity<MumbleAccentComponent> ent, ref AccentGetEvent args)
{
- args.Message = Accentuate(args.Message, component);
+ args.Message = Accentuate(args.Message, ent.Comp);
}
}
{
base.Initialize();
SubscribeLocalEvent<MutedComponent, SpeakAttemptEvent>(OnSpeakAttempt);
- SubscribeLocalEvent<MutedComponent, EmoteEvent>(OnEmote, before: new[] { typeof(VocalSystem) });
+ SubscribeLocalEvent<MutedComponent, EmoteEvent>(OnEmote, before: new[] { typeof(VocalSystem), typeof(MumbleAccentSystem) });
SubscribeLocalEvent<MutedComponent, ScreamActionEvent>(OnScreamAction, before: new[] { typeof(VocalSystem) });
}