1
0

PrayerSystem.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Content.Server.Administration;
  2. using Content.Server.Administration.Logs;
  3. using Content.Server.Bible.Components;
  4. using Content.Server.Chat.Managers;
  5. using Content.Server.Popups;
  6. using Content.Shared.Database;
  7. using Content.Shared.Popups;
  8. using Content.Shared.Chat;
  9. using Content.Shared.Prayer;
  10. using Content.Shared.Verbs;
  11. using Robust.Server.GameObjects;
  12. using Robust.Shared.Player;
  13. namespace Content.Server.Prayer;
  14. /// <summary>
  15. /// System to handle subtle messages and praying
  16. /// </summary>
  17. /// <remarks>
  18. /// Rain is a professional developer and this did not take 2 PRs to fix subtle messages
  19. /// </remarks>
  20. public sealed class PrayerSystem : EntitySystem
  21. {
  22. [Dependency] private readonly IAdminLogManager _adminLogger = default!;
  23. [Dependency] private readonly PopupSystem _popupSystem = default!;
  24. [Dependency] private readonly IChatManager _chatManager = default!;
  25. [Dependency] private readonly QuickDialogSystem _quickDialog = default!;
  26. public override void Initialize()
  27. {
  28. base.Initialize();
  29. SubscribeLocalEvent<PrayableComponent, GetVerbsEvent<ActivationVerb>>(AddPrayVerb);
  30. }
  31. private void AddPrayVerb(EntityUid uid, PrayableComponent comp, GetVerbsEvent<ActivationVerb> args)
  32. {
  33. // if it doesn't have an actor and we can't reach it then don't add the verb
  34. if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
  35. return;
  36. // this is to prevent ghosts from using it
  37. if (!args.CanInteract)
  38. return;
  39. var prayerVerb = new ActivationVerb
  40. {
  41. Text = Loc.GetString(comp.Verb),
  42. Icon = comp.VerbImage,
  43. Act = () =>
  44. {
  45. if (comp.BibleUserOnly && !EntityManager.TryGetComponent<BibleUserComponent>(args.User, out var bibleUser))
  46. {
  47. _popupSystem.PopupEntity(Loc.GetString("prayer-popup-notify-pray-locked"), uid, actor.PlayerSession, PopupType.Large);
  48. return;
  49. }
  50. _quickDialog.OpenDialog(actor.PlayerSession, Loc.GetString(comp.Verb), Loc.GetString("prayer-popup-notify-pray-ui-message"), (string message) =>
  51. {
  52. // Make sure the player's entity and the Prayable entity+component still exist
  53. if (actor?.PlayerSession != null && HasComp<PrayableComponent>(uid))
  54. Pray(actor.PlayerSession, comp, message);
  55. });
  56. },
  57. Impact = LogImpact.Low,
  58. };
  59. prayerVerb.Impact = LogImpact.Low;
  60. args.Verbs.Add(prayerVerb);
  61. }
  62. /// <summary>
  63. /// Subtly messages a player by giving them a popup and a chat message.
  64. /// </summary>
  65. /// <param name="target">The IPlayerSession that you want to send the message to</param>
  66. /// <param name="source">The IPlayerSession that sent the message</param>
  67. /// <param name="messageString">The main message sent to the player via the chatbox</param>
  68. /// <param name="popupMessage">The popup to notify the player, also prepended to the messageString</param>
  69. public void SendSubtleMessage(ICommonSession target, ICommonSession source, string messageString, string popupMessage)
  70. {
  71. if (target.AttachedEntity == null)
  72. return;
  73. var message = popupMessage == "" ? "" : popupMessage + (messageString == "" ? "" : $" \"{messageString}\"");
  74. _popupSystem.PopupEntity(popupMessage, target.AttachedEntity.Value, target, PopupType.Large);
  75. _chatManager.ChatMessageToOne(ChatChannel.Local, messageString, message, EntityUid.Invalid, false, target.Channel);
  76. _adminLogger.Add(LogType.AdminMessage, LogImpact.Low, $"{ToPrettyString(target.AttachedEntity.Value):player} received subtle message from {source.Name}: {message}");
  77. }
  78. /// <summary>
  79. /// Sends a message to the admin channel with a message and username
  80. /// </summary>
  81. /// <param name="sender">The IPlayerSession who sent the original message</param>
  82. /// <param name="comp">Prayable component used to make the prayer</param>
  83. /// <param name="message">Message to be sent to the admin chat</param>
  84. /// <remarks>
  85. /// You may be wondering, "Why the admin chat, specifically? Nobody even reads it!"
  86. /// Exactly.
  87. /// </remarks>
  88. public void Pray(ICommonSession sender, PrayableComponent comp, string message)
  89. {
  90. if (sender.AttachedEntity == null)
  91. return;
  92. _popupSystem.PopupEntity(Loc.GetString(comp.SentMessage), sender.AttachedEntity.Value, sender, PopupType.Medium);
  93. _chatManager.SendAdminAnnouncement($"{Loc.GetString(comp.NotificationPrefix)} <{sender.Name}>: {message}");
  94. _adminLogger.Add(LogType.AdminMessage, LogImpact.Low, $"{ToPrettyString(sender.AttachedEntity.Value):player} sent prayer ({Loc.GetString(comp.NotificationPrefix)}): {message}");
  95. }
  96. }