1
0

CritMobActionsSystem.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Content.Server.Administration;
  2. using Content.Server.Chat.Systems;
  3. using Content.Server.Popups;
  4. using Content.Server.Speech.Muting;
  5. using Content.Shared.Mobs;
  6. using Content.Shared.Mobs.Components;
  7. using Content.Shared.Mobs.Systems;
  8. using Robust.Server.Console;
  9. using Robust.Shared.Player;
  10. using Content.Shared.Speech.Muting;
  11. namespace Content.Server.Mobs;
  12. /// <summary>
  13. /// Handles performing crit-specific actions.
  14. /// </summary>
  15. public sealed class CritMobActionsSystem : EntitySystem
  16. {
  17. [Dependency] private readonly ChatSystem _chat = default!;
  18. [Dependency] private readonly DeathgaspSystem _deathgasp = default!;
  19. [Dependency] private readonly IServerConsoleHost _host = default!;
  20. [Dependency] private readonly MobStateSystem _mobState = default!;
  21. [Dependency] private readonly PopupSystem _popupSystem = default!;
  22. [Dependency] private readonly QuickDialogSystem _quickDialog = default!;
  23. private const int MaxLastWordsLength = 30;
  24. public override void Initialize()
  25. {
  26. base.Initialize();
  27. SubscribeLocalEvent<MobStateActionsComponent, CritSuccumbEvent>(OnSuccumb);
  28. SubscribeLocalEvent<MobStateActionsComponent, CritFakeDeathEvent>(OnFakeDeath);
  29. SubscribeLocalEvent<MobStateActionsComponent, CritLastWordsEvent>(OnLastWords);
  30. }
  31. private void OnSuccumb(EntityUid uid, MobStateActionsComponent component, CritSuccumbEvent args)
  32. {
  33. if (!TryComp<ActorComponent>(uid, out var actor) || !_mobState.IsCritical(uid))
  34. return;
  35. _host.ExecuteCommand(actor.PlayerSession, "ghost");
  36. args.Handled = true;
  37. }
  38. private void OnFakeDeath(EntityUid uid, MobStateActionsComponent component, CritFakeDeathEvent args)
  39. {
  40. if (!_mobState.IsCritical(uid))
  41. return;
  42. if (HasComp<MutedComponent>(uid))
  43. {
  44. _popupSystem.PopupEntity(Loc.GetString("fake-death-muted"), uid, uid);
  45. return;
  46. }
  47. args.Handled = _deathgasp.Deathgasp(uid);
  48. }
  49. private void OnLastWords(EntityUid uid, MobStateActionsComponent component, CritLastWordsEvent args)
  50. {
  51. if (!TryComp<ActorComponent>(uid, out var actor))
  52. return;
  53. _quickDialog.OpenDialog(actor.PlayerSession, Loc.GetString("action-name-crit-last-words"), "",
  54. (string lastWords) =>
  55. {
  56. // Intentionally does not check for muteness
  57. if (actor.PlayerSession.AttachedEntity != uid
  58. || !_mobState.IsCritical(uid))
  59. return;
  60. if (lastWords.Length > MaxLastWordsLength)
  61. {
  62. lastWords = lastWords.Substring(0, MaxLastWordsLength);
  63. }
  64. lastWords += "...";
  65. _chat.TrySendInGameICMessage(uid, lastWords, InGameICChatType.Whisper, ChatTransmitRange.Normal, checkRadioPrefix: false, ignoreActionBlocker: true);
  66. _host.ExecuteCommand(actor.PlayerSession, "ghost");
  67. });
  68. args.Handled = true;
  69. }
  70. }