Muzzles reduce emote sound (#34444)
* Muzzles reduce emote sound * update based on review comments * review comments
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
|
||||
@@ -126,16 +127,16 @@ public partial class ChatSystem
|
||||
/// 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;
|
||||
@@ -149,8 +150,8 @@ public partial class ChatSystem
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
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()
|
||||
@@ -11,6 +15,19 @@ public sealed class MumbleAccentSystem : EntitySystem
|
||||
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)
|
||||
@@ -18,8 +35,8 @@ public sealed class MumbleAccentSystem : EntitySystem
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Content.Server.Speech.Muting
|
||||
{
|
||||
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) });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user