122 lines
4.4 KiB
C#
122 lines
4.4 KiB
C#
using Content.Shared.Access.Systems;
|
|
using Content.Shared.Paper;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Tag;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
using Content.Shared._Goobstation.Devil;
|
|
using Content.Shared._Goobstation.Paper;
|
|
|
|
namespace Content.Shared._DV.Paper;
|
|
|
|
public sealed class SignatureSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedIdCardSystem _idCard = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly PaperSystem _paper = default!;
|
|
[Dependency] private readonly TagSystem _tag = default!;
|
|
|
|
public static readonly ProtoId<TagPrototype> WriteTag = "Write";
|
|
|
|
// The sprite used to visualize "signatures" on paper entities.
|
|
private const string SignatureStampState = "paper_stamp-signature";
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<PaperComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
|
|
}
|
|
|
|
private void OnGetAltVerbs(Entity<PaperComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
|
|
{
|
|
if (!args.CanAccess || !args.CanInteract)
|
|
return;
|
|
|
|
if (args.Using is not {} pen || !_tag.HasTag(pen, WriteTag))
|
|
return;
|
|
|
|
var user = args.User;
|
|
AlternativeVerb verb = new()
|
|
{
|
|
Act = () =>
|
|
{
|
|
TrySignPaper(ent, user, pen);
|
|
},
|
|
Text = Loc.GetString("paper-sign-verb"),
|
|
DoContactInteraction = true,
|
|
Priority = 10
|
|
};
|
|
args.Verbs.Add(verb);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries add add a signature to the paper with signer's name.
|
|
/// </summary>
|
|
public bool TrySignPaper(Entity<PaperComponent> paper, EntityUid signer, EntityUid pen)
|
|
{
|
|
var comp = paper.Comp;
|
|
|
|
var ev = new SignAttemptEvent(paper, signer);
|
|
RaiseLocalEvent(pen, ref ev);
|
|
if (ev.Cancelled)
|
|
return false;
|
|
|
|
var paperEvent = new BeingSignedAttemptEvent(paper, signer); // Goobstation
|
|
RaiseLocalEvent(paper.Owner, ref paperEvent);
|
|
if (paperEvent.Cancelled)
|
|
return false;
|
|
|
|
var signatureName = DetermineEntitySignature(signer);
|
|
|
|
var stampInfo = new StampDisplayInfo()
|
|
{
|
|
StampedName = signatureName,
|
|
StampedColor = Color.DarkSlateGray, // TODO: make configurable? Perhaps it should depend on the pen.
|
|
};
|
|
|
|
// TODO: remove redunant contains check when TryStamp isnt a meme
|
|
if (comp.StampedBy.Contains(stampInfo) || !_paper.TryStamp(paper, stampInfo, SignatureStampState))
|
|
{
|
|
// Show an error popup
|
|
_popup.PopupEntity(Loc.GetString("paper-signed-failure", ("target", paper.Owner)), signer, signer, PopupType.SmallCaution);
|
|
|
|
return false;
|
|
}
|
|
|
|
if (!HasComp<DevilComponent>(signer)) // Goobstation - Don't display popups for devils, it covers the others.
|
|
{
|
|
// Show popups and play a paper writing sound
|
|
var signedOtherMessage = Loc.GetString("paper-signed-other", ("user", signer), ("target", paper.Owner));
|
|
_popup.PopupEntity(signedOtherMessage, signer, Filter.PvsExcept(signer, entityManager: EntityManager), true);
|
|
|
|
var signedSelfMessage = Loc.GetString("paper-signed-self", ("target", paper.Owner));
|
|
_popup.PopupClient(signedSelfMessage, signer, signer);
|
|
}
|
|
|
|
_audio.PlayPredicted(comp.Sound, signer, signer);
|
|
|
|
var evSignSucessfulEvent = new SignSuccessfulEvent(paper, signer); // Goobstation - Devil Antagonist
|
|
RaiseLocalEvent(paper, ref evSignSucessfulEvent); // Goobstation - Devil Antagonist
|
|
|
|
return true;
|
|
}
|
|
|
|
private string DetermineEntitySignature(EntityUid uid)
|
|
{
|
|
// Goobstation - Allow devils to sign their true name.
|
|
if (TryComp<DevilComponent>(uid, out var devilComp) && !string.IsNullOrWhiteSpace(devilComp.TrueName))
|
|
return devilComp.TrueName;
|
|
|
|
// If the entity has an ID, use the name on it.
|
|
if (_idCard.TryFindIdCard(uid, out var id) && !string.IsNullOrWhiteSpace(id.Comp.FullName))
|
|
{
|
|
return id.Comp.FullName;
|
|
}
|
|
|
|
// Alternatively, return the entity name
|
|
return Name(uid);
|
|
}
|
|
}
|