Files
wwdpublic/Content.Server/DeltaV/Paper/SignatureSystem.cs
Kai5 ae1c1c39dd Port Devil (#2454)
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

This PR ports
https://github.com/Goob-Station/Goob-Station/pull/2409
https://github.com/Goob-Station/Goob-Station/pull/2591
https://github.com/Goob-Station/Goob-Station/pull/2599

This PR was initially intended to be merged into White Dream repo, so my
changes are marked as WD edit.

<!--
A list of everything you have to do before this PR is "complete"
You probably won't have to complete everything before merging but it's
good to leave future references
-->

- [ ] Port pain numbness
- [ ] Port nullrods
- [ ] Port tile movement

---

<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>

![image](https://github.com/user-attachments/assets/ee4679d1-fc07-4dc3-8063-e0220bc0d728)

![image](https://github.com/user-attachments/assets/25f590b9-6bf3-43bd-aca3-80452f27b0dd)

![image](https://github.com/user-attachments/assets/1ffb5bb3-e0c7-4827-8193-83bd8480e555)

![image](https://github.com/user-attachments/assets/4ed8c762-1e51-4bd8-9800-6495c12ac68f)

</p>
</details>

---

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- add: Ported Devil antag from Goobstation

---------

Signed-off-by: Kai5 <68296202+Kai518@users.noreply.github.com>
Signed-off-by: VMSolidus <evilexecutive@gmail.com>
Co-authored-by: Solstice <solsticeofthewinter@gmail.com>
Co-authored-by: VMSolidus <evilexecutive@gmail.com>
2025-07-20 13:37:35 +10:00

122 lines
4.3 KiB
C#

using Content.Shared._Goobstation.Paper;
using Content.Shared._Goobstation.Devil;
using Content.Server.Access.Systems;
using Content.Server.Paper;
using Content.Server.Popups;
using Content.Shared.Paper;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Content.Shared.Verbs;
using Robust.Server.Audio;
using Robust.Shared.Player;
namespace Content.Server.DeltaV.Paper;
public sealed class SignatureSystem : EntitySystem
{
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly IdCardSystem _idCard = default!;
[Dependency] private readonly PaperSystem _paper = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly TagSystem _tags = default!;
// 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 || !_tags.HasTag(pen, "Write"))
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 to 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 this configurable depending on the pen.
};
if (!comp.StampedBy.Contains(stampInfo) && _paper.TryStamp((paper, comp), stampInfo, SignatureStampState))
{
// Show popups and play a paper writing sound
if (!HasComp<DevilComponent>(signer)) // Goobstation - Don't display popups for devils, it covers the others.
{
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.PopupEntity(signedSelfMessage, signer, signer);
}
_audio.PlayPvs(comp.Sound, signer);
_paper.UpdateUserInterface((paper, comp));
var evSignSucessfulEvent = new SignSuccessfulEvent(paper, signer); // Goobstation - Devil Antagonist
RaiseLocalEvent(paper, ref evSignSucessfulEvent); // Goobstation - Devil Antagonist
return true;
}
else
{
// Show an error popup
_popup.PopupEntity(Loc.GetString("paper-signed-failure", ("target", paper.Owner)), signer, signer, PopupType.SmallCaution);
return false;
}
}
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);
}
}