2024-01-22 23:14:13 +01:00
using Content.Server.Administration ;
2023-01-11 02:15:47 -06:00
using Content.Server.Administration.Logs ;
2022-11-09 05:02:14 +08:00
using Content.Server.Bible.Components ;
using Content.Server.Chat.Managers ;
using Content.Server.Popups ;
using Content.Shared.Database ;
using Content.Shared.Popups ;
using Content.Shared.Chat ;
2023-05-29 10:44:11 +10:00
using Content.Shared.Prayer ;
2022-11-09 05:02:14 +08:00
using Content.Shared.Verbs ;
using Robust.Server.GameObjects ;
2023-10-28 09:59:53 +11:00
using Robust.Shared.Player ;
2022-11-09 05:02:14 +08:00
namespace Content.Server.Prayer ;
/// <summary>
/// System to handle subtle messages and praying
/// </summary>
2022-11-29 12:49:20 +08:00
/// <remarks>
/// Rain is a professional developer and this did not take 2 PRs to fix subtle messages
/// </remarks>
public sealed class PrayerSystem : EntitySystem
2022-11-09 05:02:14 +08:00
{
2023-01-11 02:15:47 -06:00
[Dependency] private readonly IAdminLogManager _adminLogger = default ! ;
2022-11-09 05:02:14 +08:00
[Dependency] private readonly PopupSystem _popupSystem = default ! ;
[Dependency] private readonly IChatManager _chatManager = default ! ;
[Dependency] private readonly QuickDialogSystem _quickDialog = default ! ;
public override void Initialize ( )
{
base . Initialize ( ) ;
SubscribeLocalEvent < PrayableComponent , GetVerbsEvent < ActivationVerb > > ( AddPrayVerb ) ;
}
private void AddPrayVerb ( EntityUid uid , PrayableComponent comp , GetVerbsEvent < ActivationVerb > args )
{
// if it doesn't have an actor and we can't reach it then don't add the verb
2023-08-24 03:10:55 -07:00
if ( ! EntityManager . TryGetComponent ( args . User , out ActorComponent ? actor ) )
2022-11-09 05:02:14 +08:00
return ;
2022-11-29 12:49:20 +08:00
// this is to prevent ghosts from using it
2022-11-09 05:02:14 +08:00
if ( ! args . CanAccess )
return ;
2022-11-29 12:49:20 +08:00
var prayerVerb = new ActivationVerb
2022-11-09 05:02:14 +08:00
{
2023-01-17 12:42:20 -06:00
Text = Loc . GetString ( comp . Verb ) ,
2023-02-26 18:48:57 +11:00
Icon = comp . VerbImage ,
2022-11-29 12:49:20 +08:00
Act = ( ) = >
2022-11-09 05:02:14 +08:00
{
2022-11-29 12:49:20 +08:00
if ( comp . BibleUserOnly & & ! EntityManager . TryGetComponent < BibleUserComponent > ( args . User , out var bibleUser ) )
{
2023-05-13 15:27:15 +03:00
_popupSystem . PopupEntity ( Loc . GetString ( "prayer-popup-notify-pray-locked" ) , uid , actor . PlayerSession , PopupType . Large ) ;
2022-11-29 12:49:20 +08:00
return ;
}
2023-01-17 12:42:20 -06:00
_quickDialog . OpenDialog ( actor . PlayerSession , Loc . GetString ( comp . Verb ) , "Message" , ( string message ) = >
2022-11-29 12:49:20 +08:00
{
2023-01-17 12:42:20 -06:00
Pray ( actor . PlayerSession , comp , message ) ;
2022-11-29 12:49:20 +08:00
} ) ;
} ,
Impact = LogImpact . Low ,
2022-11-09 05:02:14 +08:00
} ;
prayerVerb . Impact = LogImpact . Low ;
args . Verbs . Add ( prayerVerb ) ;
}
/// <summary>
/// Subtly messages a player by giving them a popup and a chat message.
/// </summary>
/// <param name="target">The IPlayerSession that you want to send the message to</param>
2023-01-11 02:15:47 -06:00
/// <param name="source">The IPlayerSession that sent the message</param>
2022-11-09 05:02:14 +08:00
/// <param name="messageString">The main message sent to the player via the chatbox</param>
/// <param name="popupMessage">The popup to notify the player, also prepended to the messageString</param>
2023-10-28 09:59:53 +11:00
public void SendSubtleMessage ( ICommonSession target , ICommonSession source , string messageString , string popupMessage )
2022-11-09 05:02:14 +08:00
{
if ( target . AttachedEntity = = null )
return ;
2023-01-17 12:42:20 -06:00
var message = popupMessage = = "" ? "" : popupMessage + ( messageString = = "" ? "" : $" \" { messageString } \ "" ) ;
2022-11-29 12:49:20 +08:00
2022-12-19 10:41:47 +13:00
_popupSystem . PopupEntity ( popupMessage , target . AttachedEntity . Value , target , PopupType . Large ) ;
2024-01-22 23:14:13 +01:00
_chatManager . ChatMessageToOne ( ChatChannel . Local , messageString , message , EntityUid . Invalid , false , target . Channel ) ;
2023-01-11 02:15:47 -06:00
_adminLogger . Add ( LogType . AdminMessage , LogImpact . Low , $"{ToPrettyString(target.AttachedEntity.Value):player} received subtle message from {source.Name}: {message}" ) ;
2022-11-09 05:02:14 +08:00
}
/// <summary>
/// Sends a message to the admin channel with a message and username
/// </summary>
/// <param name="sender">The IPlayerSession who sent the original message</param>
2023-01-17 12:42:20 -06:00
/// <param name="comp">Prayable component used to make the prayer</param>
2022-11-09 05:02:14 +08:00
/// <param name="message">Message to be sent to the admin chat</param>
/// <remarks>
/// You may be wondering, "Why the admin chat, specifically? Nobody even reads it!"
/// Exactly.
/// </remarks>
2023-10-28 09:59:53 +11:00
public void Pray ( ICommonSession sender , PrayableComponent comp , string message )
2022-11-09 05:02:14 +08:00
{
if ( sender . AttachedEntity = = null )
return ;
2023-01-17 12:42:20 -06:00
_popupSystem . PopupEntity ( Loc . GetString ( comp . SentMessage ) , sender . AttachedEntity . Value , sender , PopupType . Medium ) ;
2022-11-09 05:02:14 +08:00
2023-05-29 10:44:11 +10:00
_chatManager . SendAdminAnnouncement ( $"{Loc.GetString(comp.NotificationPrefix)} <{sender.Name}>: {message}" ) ;
_adminLogger . Add ( LogType . AdminMessage , LogImpact . Low , $"{ToPrettyString(sender.AttachedEntity.Value):player} sent prayer ({Loc.GetString(comp.NotificationPrefix)}): {message}" ) ;
2022-11-09 05:02:14 +08:00
}
}