Files
wwdpublic/Content.Server/Forensics/Systems/ForensicPadSystem.cs
ScarKy0 715cf4694f Move FingerprintComponent and FingerprintMaskComponent to shared (#35451)
* init

* review

* whoopsie

(cherry picked from commit 88308356db1616af98a82c0e11d43cb61d15a99e)
2025-10-04 12:51:43 +03:00

136 lines
5.2 KiB
C#

using Content.Server.Labels;
using Content.Server.Popups;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Forensics;
using Content.Shared.Forensics.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Inventory;
namespace Content.Server.Forensics
{
/// <summary>
/// Used to transfer fingerprints from entities to forensic pads.
/// </summary>
public sealed class ForensicPadSystem : EntitySystem
{
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly LabelSystem _label = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ForensicPadComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<ForensicPadComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<ForensicPadComponent, ForensicPadDoAfterEvent>(OnDoAfter);
}
private void OnExamined(EntityUid uid, ForensicPadComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
if (!component.Used)
{
args.PushMarkup(Loc.GetString("forensic-pad-unused"));
return;
}
args.PushMarkup(Loc.GetString("forensic-pad-sample", ("sample", component.Sample)));
}
private void OnAfterInteract(EntityUid uid, ForensicPadComponent component, AfterInteractEvent args)
{
if (!args.CanReach || args.Target == null)
return;
if (HasComp<ForensicScannerComponent>(args.Target))
return;
args.Handled = true;
if (component.Used)
{
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-already-used"), args.Target.Value, args.User);
return;
}
if (_inventory.TryGetSlotEntity(args.Target.Value, "gloves", out var gloves))
{
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-gloves", ("target", Identity.Entity(args.Target.Value, EntityManager))), args.Target.Value, args.User);
return;
}
if (TryComp<FingerprintComponent>(args.Target, out var fingerprint)) // WWDP
{
if (args.User != args.Target)
{
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-start-scan-user", ("target", Identity.Entity(args.Target.Value, EntityManager))), args.Target.Value, args.User);
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-start-scan-target", ("user", Identity.Entity(args.User, EntityManager))), args.Target.Value, args.Target.Value);
}
StartScan(uid, args.User, args.Target.Value, component, fingerprint.Fingerprint);
return;
}
if (TryComp<FiberComponent>(args.Target, out var fiber))
StartScan(uid, args.User, args.Target.Value, component, string.IsNullOrEmpty(fiber.FiberColor) ? Loc.GetString("forensic-fibers", ("material", fiber.FiberMaterial)) : Loc.GetString("forensic-fibers-colored", ("color", fiber.FiberColor), ("material", fiber.FiberMaterial)));
}
private void StartScan(EntityUid used, EntityUid user, EntityUid target, ForensicPadComponent pad, string? sample) // WWDP
{
var ev = new ForensicPadDoAfterEvent(sample);
var doAfterEventArgs = new DoAfterArgs(EntityManager, user, pad.ScanDelay, ev, used, target: target, used: used)
{
NeedHand = true,
BreakOnMove = true,
};
_doAfterSystem.TryStartDoAfter(doAfterEventArgs);
}
private void OnDoAfter(EntityUid uid, ForensicPadComponent padComponent, ForensicPadDoAfterEvent args)
{
if (args.Handled || args.Cancelled)
{
return;
}
// WWDP EDIT
if (args.Args.Target == null)
{
args.Handled = true;
return;
}
var name = "forensic-pad-gloves-name";
var sample = "";
if (TryComp<FingerprintComponent>(args.Args.Target, out var fingerprint))
{
if (fingerprint.NotLeavingFingerprints || args.Sample == null)
{
var message = Loc.GetString("forensic-pad-no-fingerprints", ("target", Identity.Entity(args.Args.Target.Value, EntityManager)));
_popupSystem.PopupEntity(message, (EntityUid)args.Args.Target, args.User);
args.Handled = true;
return;
}
sample = args.Sample;
}
string label = Identity.Name(args.Args.Target.Value, EntityManager);
_label.Label(uid, label);
padComponent.Sample = sample;
// WWDP EDIT END
padComponent.Used = true;
args.Handled = true;
}
}
}