MutingSystem.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Content.Server.Abilities.Mime;
  2. using Content.Server.Chat.Systems;
  3. using Content.Server.Popups;
  4. using Content.Server.Speech.Components;
  5. using Content.Server.Speech.EntitySystems;
  6. using Content.Shared.Chat.Prototypes;
  7. using Content.Shared.Puppet;
  8. using Content.Shared.Speech;
  9. using Content.Shared.Speech.Muting;
  10. namespace Content.Server.Speech.Muting
  11. {
  12. public sealed class MutingSystem : EntitySystem
  13. {
  14. [Dependency] private readonly PopupSystem _popupSystem = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<MutedComponent, SpeakAttemptEvent>(OnSpeakAttempt);
  19. SubscribeLocalEvent<MutedComponent, EmoteEvent>(OnEmote, before: new[] { typeof(VocalSystem) });
  20. SubscribeLocalEvent<MutedComponent, ScreamActionEvent>(OnScreamAction, before: new[] { typeof(VocalSystem) });
  21. }
  22. private void OnEmote(EntityUid uid, MutedComponent component, ref EmoteEvent args)
  23. {
  24. if (args.Handled)
  25. return;
  26. //still leaves the text so it looks like they are pantomiming a laugh
  27. if (args.Emote.Category.HasFlag(EmoteCategory.Vocal))
  28. args.Handled = true;
  29. }
  30. private void OnScreamAction(EntityUid uid, MutedComponent component, ScreamActionEvent args)
  31. {
  32. if (args.Handled)
  33. return;
  34. if (HasComp<MimePowersComponent>(uid))
  35. _popupSystem.PopupEntity(Loc.GetString("mime-cant-speak"), uid, uid);
  36. else
  37. _popupSystem.PopupEntity(Loc.GetString("speech-muted"), uid, uid);
  38. args.Handled = true;
  39. }
  40. private void OnSpeakAttempt(EntityUid uid, MutedComponent component, SpeakAttemptEvent args)
  41. {
  42. // TODO something better than this.
  43. if (HasComp<MimePowersComponent>(uid))
  44. _popupSystem.PopupEntity(Loc.GetString("mime-cant-speak"), uid, uid);
  45. else if (HasComp<VentriloquistPuppetComponent>(uid))
  46. _popupSystem.PopupEntity(Loc.GetString("ventriloquist-puppet-cant-speak"), uid, uid);
  47. else
  48. _popupSystem.PopupEntity(Loc.GetString("speech-muted"), uid, uid);
  49. args.Cancel();
  50. }
  51. }
  52. }