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:
16
Content.Server/Forensics/Components/FiberComponent.cs
Normal file
16
Content.Server/Forensics/Components/FiberComponent.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
/// <summary>
|
||||
/// This controls fibers left by gloves on items,
|
||||
/// which the forensics system uses.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class FiberComponent : Component
|
||||
{
|
||||
[DataField("fiberMaterial")]
|
||||
public string FiberMaterial = "fibers-synthetic";
|
||||
|
||||
[DataField("fiberColor")]
|
||||
public string? FiberColor;
|
||||
}
|
||||
}
|
||||
12
Content.Server/Forensics/Components/FingerprintComponent.cs
Normal file
12
Content.Server/Forensics/Components/FingerprintComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
/// <summary>
|
||||
/// This component is for mobs that leave fingerprints.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class FingerprintComponent : Component
|
||||
{
|
||||
[DataField("fingerprint")]
|
||||
public string? Fingerprint;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
/// <summary>
|
||||
/// This component stops the entity from leaving finger prints,
|
||||
/// usually so fibres can be left instead.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class FingerprintMaskComponent : Component
|
||||
{}
|
||||
}
|
||||
19
Content.Server/Forensics/Components/ForensicPadComponent.cs
Normal file
19
Content.Server/Forensics/Components/ForensicPadComponent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Threading;
|
||||
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to take a sample of someone's fingerprints.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class ForensicPadComponent : Component
|
||||
{
|
||||
public CancellationTokenSource? CancelToken;
|
||||
|
||||
[DataField("scanDelay")]
|
||||
public float ScanDelay = 3.0f;
|
||||
|
||||
public bool Used = false;
|
||||
public String Sample = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Threading;
|
||||
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class ForensicScannerComponent : Component
|
||||
{
|
||||
public CancellationTokenSource? CancelToken;
|
||||
|
||||
/// <summary>
|
||||
/// A list of fingerprint GUIDs that the forensic scanner found from the <see cref="ForensicsComponent"/> on an entity.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public List<string> Fingerprints = new();
|
||||
/// <summary>
|
||||
/// A list of glove fibers that the forensic scanner found from the <see cref="ForensicsComponent"/> on an entity.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public List<string> Fibers = new();
|
||||
|
||||
/// <summary>
|
||||
/// The time (in seconds) that it takes to scan an entity.
|
||||
/// </summary>
|
||||
[DataField("scanDelay")]
|
||||
public float ScanDelay = 3.0f;
|
||||
}
|
||||
}
|
||||
12
Content.Server/Forensics/Components/ForensicsComponent.cs
Normal file
12
Content.Server/Forensics/Components/ForensicsComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class ForensicsComponent : Component
|
||||
{
|
||||
[DataField("fingerprints")]
|
||||
public HashSet<string> Fingerprints = new();
|
||||
|
||||
[DataField("fibers")]
|
||||
public HashSet<string> Fibers = new();
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
169
Content.Server/Forensics/Systems/ForensicScannerSystem.cs
Normal file
169
Content.Server/Forensics/Systems/ForensicScannerSystem.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System.Linq;
|
||||
using System.Text; // todo: remove this stinky LINQy
|
||||
using System.Threading;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Paper;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Forensics;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
public sealed class ForensicScannerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly PaperSystem _paperSystem = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ForensicScannerComponent, AfterInteractEvent>(OnAfterInteract);
|
||||
SubscribeLocalEvent<ForensicScannerComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
||||
SubscribeLocalEvent<ForensicScannerComponent, ForensicScannerPrintMessage>(OnPrint);
|
||||
SubscribeLocalEvent<TargetScanSuccessfulEvent>(OnTargetScanSuccessful);
|
||||
SubscribeLocalEvent<ScanCancelledEvent>(OnScanCancelled);
|
||||
}
|
||||
|
||||
private void OnScanCancelled(ScanCancelledEvent ev)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(ev.Scanner, out ForensicScannerComponent? scanner))
|
||||
return;
|
||||
scanner.CancelToken = null;
|
||||
}
|
||||
|
||||
private void OnTargetScanSuccessful(TargetScanSuccessfulEvent ev)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(ev.Scanner, out ForensicScannerComponent? scanner))
|
||||
return;
|
||||
|
||||
scanner.CancelToken = null;
|
||||
|
||||
if (!TryComp<ForensicsComponent>(ev.Target, out var forensics))
|
||||
return;
|
||||
|
||||
scanner.Fingerprints = forensics.Fingerprints.ToList();
|
||||
scanner.Fibers = forensics.Fibers.ToList();
|
||||
OpenUserInterface(ev.User, scanner);
|
||||
}
|
||||
|
||||
private void OnAfterInteract(EntityUid uid, ForensicScannerComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (component.CancelToken != null || args.Target == null || !args.CanReach)
|
||||
return;
|
||||
|
||||
component.CancelToken = new CancellationTokenSource();
|
||||
_doAfterSystem.DoAfter(new DoAfterEventArgs(args.User, component.ScanDelay, component.CancelToken.Token, target: args.Target)
|
||||
{
|
||||
BroadcastFinishedEvent = new TargetScanSuccessfulEvent(args.User, args.Target, component.Owner),
|
||||
BroadcastCancelledEvent = new ScanCancelledEvent(component.Owner),
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
BreakOnStun = true,
|
||||
NeedHand = true
|
||||
});
|
||||
}
|
||||
|
||||
private void OnAfterInteractUsing(EntityUid uid, ForensicScannerComponent component, AfterInteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled || !args.CanReach)
|
||||
return;
|
||||
|
||||
if (!TryComp<ForensicPadComponent>(args.Used, out var pad))
|
||||
return;
|
||||
|
||||
foreach (var fiber in component.Fibers)
|
||||
{
|
||||
if (fiber == pad.Sample)
|
||||
{
|
||||
SoundSystem.Play("/Audio/Machines/Nuke/angry_beep.ogg", Filter.Pvs(uid), uid);
|
||||
_popupSystem.PopupEntity(Loc.GetString("forensic-scanner-match-fiber"), uid, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var fingerprint in component.Fingerprints)
|
||||
{
|
||||
if (fingerprint == pad.Sample)
|
||||
{
|
||||
SoundSystem.Play("/Audio/Machines/Nuke/angry_beep.ogg", Filter.Pvs(uid), uid);
|
||||
_popupSystem.PopupEntity(Loc.GetString("forensic-scanner-match-fingerprint"), uid, Filter.Entities(args.User));
|
||||
return;
|
||||
}
|
||||
}
|
||||
SoundSystem.Play("/Audio/Machines/airlock_deny.ogg", Filter.Pvs(uid), uid);
|
||||
_popupSystem.PopupEntity(Loc.GetString("forensic-scanner-match-none"), uid, Filter.Entities(args.User));
|
||||
}
|
||||
|
||||
private void OpenUserInterface(EntityUid user, ForensicScannerComponent component)
|
||||
{
|
||||
if (!TryComp<ActorComponent>(user, out var actor))
|
||||
return;
|
||||
|
||||
var ui = _uiSystem.GetUi(component.Owner, ForensicScannerUiKey.Key);
|
||||
|
||||
ui.Open(actor.PlayerSession);
|
||||
ui.SendMessage(new ForensicScannerUserMessage(component.Fingerprints, component.Fibers));
|
||||
}
|
||||
|
||||
private void OnPrint(EntityUid uid, ForensicScannerComponent component, ForensicScannerPrintMessage args)
|
||||
{
|
||||
if (!args.Session.AttachedEntity.HasValue || (component.Fibers.Count == 0 && component.Fingerprints.Count == 0)) return;
|
||||
|
||||
// spawn a piece of paper.
|
||||
var printed = EntityManager.SpawnEntity("Paper", Transform(args.Session.AttachedEntity.Value).Coordinates);
|
||||
_handsSystem.PickupOrDrop(args.Session.AttachedEntity, printed, checkActionBlocker: false);
|
||||
|
||||
if (!TryComp<PaperComponent>(printed, out var paper))
|
||||
return;
|
||||
|
||||
MetaData(printed).EntityName = Loc.GetString("forensic-scanner-report-title");
|
||||
|
||||
var text = new StringBuilder();
|
||||
|
||||
text.AppendLine(Loc.GetString("forensic-scanner-interface-fingerprints"));
|
||||
foreach (var fingerprint in component.Fingerprints)
|
||||
{
|
||||
text.AppendLine(fingerprint);
|
||||
}
|
||||
text.AppendLine();
|
||||
text.AppendLine(Loc.GetString("forensic-scanner-interface-fibers"));
|
||||
foreach (var fiber in component.Fibers)
|
||||
{
|
||||
text.AppendLine(fiber);
|
||||
}
|
||||
|
||||
_paperSystem.SetContent(printed, text.ToString());
|
||||
}
|
||||
|
||||
private sealed class ScanCancelledEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Scanner;
|
||||
|
||||
public ScanCancelledEvent(EntityUid scanner)
|
||||
{
|
||||
Scanner = scanner;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class TargetScanSuccessfulEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid User;
|
||||
public EntityUid? Target;
|
||||
public EntityUid Scanner;
|
||||
public TargetScanSuccessfulEvent(EntityUid user, EntityUid? target, EntityUid scanner)
|
||||
{
|
||||
User = user;
|
||||
Target = target;
|
||||
Scanner = scanner;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Content.Server/Forensics/Systems/ForensicsSystem.cs
Normal file
49
Content.Server/Forensics/Systems/ForensicsSystem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Item;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Forensics
|
||||
{
|
||||
public sealed class ForensicsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<FingerprintComponent, UserInteractedWithItemEvent>(OnInteract);
|
||||
SubscribeLocalEvent<FingerprintComponent, ComponentInit>(OnInit);
|
||||
}
|
||||
|
||||
private void OnInteract(EntityUid uid, FingerprintComponent component, UserInteractedWithItemEvent args)
|
||||
{
|
||||
ApplyEvidence(args.User, args.Item);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, FingerprintComponent component, ComponentInit args)
|
||||
{
|
||||
component.Fingerprint = GenerateFingerprint();
|
||||
}
|
||||
|
||||
private string GenerateFingerprint()
|
||||
{
|
||||
byte[] fingerprint = new byte[16];
|
||||
_random.NextBytes(fingerprint);
|
||||
return Convert.ToHexString(fingerprint);
|
||||
}
|
||||
|
||||
private void ApplyEvidence(EntityUid user, EntityUid target)
|
||||
{
|
||||
var component = EnsureComp<ForensicsComponent>(target);
|
||||
if (_inventory.TryGetSlotEntity(user, "gloves", out var gloves))
|
||||
{
|
||||
if (TryComp<FiberComponent>(gloves, out var fiber) && !string.IsNullOrEmpty(fiber.FiberMaterial))
|
||||
component.Fibers.Add(string.IsNullOrEmpty(fiber.FiberColor) ? Loc.GetString("forensic-fibers", ("material", fiber.FiberMaterial)) : Loc.GetString("forensic-fibers-colored", ("color", fiber.FiberColor), ("material", fiber.FiberMaterial)));
|
||||
|
||||
if (HasComp<FingerprintMaskComponent>(gloves))
|
||||
return;
|
||||
}
|
||||
if (TryComp<FingerprintComponent>(user, out var fingerprint))
|
||||
component.Fingerprints.Add(fingerprint.Fingerprint ?? "");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user