Forensics (#8451)
* Port forensics from nyanotrasen * port updates * printing * Update Resources/Locale/en-US/forensics/forensics.ftl Co-authored-by: Veritius <veritiusgaming@gmail.com> * Update Content.Server/Forensics/Components/ForensicPadComponent.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Update Content.Server/Forensics/Systems/ForensicPadSystem.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Update Content.Server/Forensics/Systems/ForensicScannerSystem.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * partially address reviews * comments * redo the events * handle it * rewrite loc * master fixes Co-authored-by: ike709 <ike709@github.com> Co-authored-by: Veritius <veritiusgaming@gmail.com> Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
140
Content.Server/Forensics/Systems/ForensicPadSystem.cs
Normal file
140
Content.Server/Forensics/Systems/ForensicPadSystem.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System.Threading;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Popups;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to transfer fingerprints from entities to forensic pads.
|
||||
/// </summary>
|
||||
public sealed class ForensicPadSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ForensicPadComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<ForensicPadComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<TargetPadSuccessfulEvent>(OnTargetPadSuccessful);
|
||||
SubscribeLocalEvent<PadCancelledEvent>(OnPadCancelled);
|
||||
}
|
||||
|
||||
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 (component.CancelToken != null || !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, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inventory.TryGetSlotEntity(args.Target.Value, "gloves", out var gloves))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-gloves", ("target", args.Target.Value)), args.Target.Value, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<FingerprintComponent>(args.Target, out var fingerprint) && fingerprint.Fingerprint != null)
|
||||
{
|
||||
if (args.User != args.Target)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-start-scan-user", ("target", args.Target.Value)), args.Target.Value, Filter.Entities(args.User));
|
||||
_popupSystem.PopupEntity(Loc.GetString("forensic-pad-start-scan-target", ("user", args.User)), args.Target.Value, Filter.Entities(args.Target.Value));
|
||||
}
|
||||
StartScan(args.User, args.Target.Value, component, fingerprint.Fingerprint);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<FiberComponent>(args.Target, out var fiber))
|
||||
StartScan(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 user, EntityUid target, ForensicPadComponent pad, string sample)
|
||||
{
|
||||
pad.CancelToken = new CancellationTokenSource();
|
||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(user, pad.ScanDelay, pad.CancelToken.Token, target: target)
|
||||
{
|
||||
BroadcastFinishedEvent = new TargetPadSuccessfulEvent(user, target, pad.Owner, sample),
|
||||
BroadcastCancelledEvent = new PadCancelledEvent(pad.Owner),
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
NeedHand = true
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the forensic pad is successfully used, take their fingerprint sample and flag the pad as used.
|
||||
/// </summary>
|
||||
private void OnTargetPadSuccessful(TargetPadSuccessfulEvent ev)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(ev.Pad, out ForensicPadComponent? component))
|
||||
return;
|
||||
|
||||
component.CancelToken = null;
|
||||
component.Sample = ev.Sample;
|
||||
component.Used = true;
|
||||
}
|
||||
private void OnPadCancelled(PadCancelledEvent ev)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(ev.Pad, out ForensicPadComponent? component))
|
||||
return;
|
||||
component.CancelToken = null;
|
||||
}
|
||||
|
||||
private sealed class PadCancelledEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Pad;
|
||||
|
||||
public PadCancelledEvent(EntityUid pad)
|
||||
{
|
||||
Pad = pad;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class TargetPadSuccessfulEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid User;
|
||||
public EntityUid? Target;
|
||||
public EntityUid Pad;
|
||||
public string Sample = string.Empty;
|
||||
|
||||
public TargetPadSuccessfulEvent(EntityUid user, EntityUid? target, EntityUid pad, string sample)
|
||||
{
|
||||
User = user;
|
||||
Target = target;
|
||||
Pad = pad;
|
||||
Sample = sample;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user