CatStation/Content.Shared/Speech/Muting/MutedStatusEffectSystem.cs
āda 232ac6d8bf
Prevent StatusEffect relay "collection modified" error (#45188)
* commit

* refactor: remove unused using in MutedStatusEffectSystem + early return for StatusEffectsSystem.RelayEvent

* refactor: one forgotten micro optimization!

---------

Co-authored-by: iaada <iaada@users.noreply.github.com>
Co-authored-by: Fildrance <fildrance@gmail.com>
2026-08-11 08:41:04 +00:00

55 lines
1.9 KiB
C#

using Content.Shared.Chat;
using Content.Shared.Chat.Prototypes;
using Content.Shared.Popups;
using Content.Shared.StatusEffectNew;
namespace Content.Shared.Speech.Muting;
/// <summary>
/// Handles the speech restrictions imposed by <see cref="MutedStatusEffectComponent"/>.
/// </summary>
public sealed partial class MutedStatusEffectSystem : EntitySystem
{
[Dependency] private SharedPopupSystem _popup = default!;
/// <inheritdoc />
public override void Initialize()
{
SubscribeLocalEvent<MutedStatusEffectComponent, StatusEffectRelayedEvent<SpeakAttemptEvent>>(OnSpeakAttempt);
SubscribeLocalEvent<MutedStatusEffectComponent, StatusEffectRelayedEvent<EmoteEvent>>(OnEmote);
SubscribeLocalEvent<MutedStatusEffectComponent, StatusEffectRelayedEvent<EmoteActionEvent>>(OnEmoteAction);
}
private void OnEmote(Entity<MutedStatusEffectComponent> ent, ref StatusEffectRelayedEvent<EmoteEvent> args)
{
if (args.Args.Handled)
return;
// Still leaves the text so it looks like they are pantomiming a laugh.
if (args.Args.Emote.Category.HasFlag(EmoteCategory.Vocal))
{
args.Args = args.Args with { Handled = true };
}
}
private void OnEmoteAction(Entity<MutedStatusEffectComponent> ent, ref StatusEffectRelayedEvent<EmoteActionEvent> args)
{
if (args.Args.Handled)
return;
_popup.PopupEntity(Loc.GetString(ent.Comp.ActionPopup), args.AppliedTo, args.AppliedTo);
args.Args.Handled = true;
}
private void OnSpeakAttempt(Entity<MutedStatusEffectComponent> ent, ref StatusEffectRelayedEvent<SpeakAttemptEvent> args)
{
if (args.Args.Cancelled)
return;
var target = args.Args.Uid;
_popup.PopupEntity(Loc.GetString(ent.Comp.SpeakPopup), target, target);
args.Args.Cancel();
}
}