Files
OldThink/Content.Server/_White/_Engi/PacifiedOnChaplainAction/PacifiedOnChaplainActionSystem.cs
BIGZi0348 2945473db0 Maybe
2024-12-31 13:58:00 +03:00

117 lines
3.8 KiB
C#

using Content.Shared.ActionBlocker;
using Content.Server.Popups;
using Robust.Shared.Audio.Systems;
using Content.Shared.Interaction;
using Content.Shared.Verbs;
using Content.Server.Bible.Components;
using Content.Shared.Timing;
using Content.Shared.CombatMode.Pacification;
using Content.Server.Administration.Logs;
using Content.Shared.Database;
namespace Content.Server._White._Engi.PacifiedOnChaplainAction
{
/// <summary>
/// WD
/// </summary>
public sealed class PacifiedOnChaplainAction : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly UseDelaySystem _delay = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PacifiedOnChaplainActionComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<PacifiedOnChaplainActionComponent, GetVerbsEvent<AlternativeVerb>>(AddPacifiedOnChaplainVerb);
}
private void Action(PacifiedOnChaplainActionComponent component, EntityUid target, EntityUid user)
{
if (!HasComp<PacifiedOnChaplainActionComponent>(target))
return;
var popup = "";
if (HasComp<PacifiedComponent>(target))
{
popup = "unpacified-by-chaplain";
RemComp<PacifiedComponent>(target);
}
else
{
popup = "pacified-by-chaplain";
EnsureComp<PacifiedComponent>(target);
}
_adminLogger.Add(LogType.Verb,
LogImpact.Medium,
$"{ToPrettyString(target):target} {popup} {ToPrettyString(user):user}");
_popupSystem.PopupEntity(Loc.GetString(popup, ("target", target)), user, user);
_audio.PlayPvs(component.ActionSound, user);
}
private void OnAfterInteract(EntityUid uid, PacifiedOnChaplainActionComponent component, AfterInteractEvent args)
{
if (!args.CanReach)
return;
if (!TryComp(uid, out UseDelayComponent? useDelay) || _delay.IsDelayed((uid, useDelay)))
return;
if (args.Target == null)
return;
if (!HasComp<BibleUserComponent>(args.User))
return;
Action(component, (EntityUid) args.Target, args.User);
_delay.TryResetDelay((uid, useDelay));
return;
}
private void AddPacifiedOnChaplainVerb(EntityUid uid, PacifiedOnChaplainActionComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
if (!HasComp<BibleUserComponent>(args.User))
return;
if (!_blocker.CanInteract(args.User, uid))
return;
var verbName = "";
if (HasComp<PacifiedComponent>(args.Target))
verbName = Loc.GetString("unpacify-by-chaplain");
else
verbName = Loc.GetString("pacify-by-chaplain");
AlternativeVerb verb = new()
{
Act = () =>
{
if (!TryComp(uid, out UseDelayComponent? useDelay) || _delay.IsDelayed((uid, useDelay)))
return;
Action(component, args.Target, args.User);
_delay.TryResetDelay((uid, useDelay));
},
Text = verbName,
Priority = 2
};
args.Verbs.Add(verb);
}
}
}