mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* What sitting on code does to a branch + no mo owner v2 * Replacing ViewVariables with AutoNetworkedField + Missed One V2 * Removing Virtual Methods & Renaming ForensicsSystem to SharedForensicsSystem (Also made it abstract) V2 * IProduceWidgets Review Changes & some of my own V2 * Lil Cleanup V2 * Part 1 of Review Changes (Only thing left is the BUI stuff and the constructor) V2 * It now WORKS!!! (Still needs the BUI and constuctor changes, ill figure it out later) * Test (Removal of ServerSide VomitSystem.cs) * Ok... * Moved System BloodstreamSystem.cs to SharedBloodstreamSystem.cs & deleted client BloodStreamSystem.cs to make SharedBloodstreamSystem.cs sealed. (No Unregistered errors) * Prediction * Fix? * No mo log error? * Revert "No mo log error?" This reverts commit 50c15a3deab6af9dffd7baed45820bae5558e41f. * Constructor going up * No ForensicScannerBoundUserInterface.cs (It doesnt wanna scan anymore but it doesnt crash) * For Conflicts * Guh * Yea * Organization & no ErrorHell (maybe) * Dirtying * Dirtying take 2 * Revert "Dirtying take 2" This reverts commit 5735012e21f43808db3ae010fce268eac24d0583. * the dirties dont do much here * For Conflict * Readded * Another Conflict Commit Fix * Conflict Fix Thrice * Empty Space * Keep it simple * Add it back in * Move BloodstreamSystem stuff thats causing the error back to system. This'll prob fix the conflict * Conflict fix? * Trust the fix * Looked at other prediction PR's, they had better code. * To not mix up the system in client * Removing Conflict * For conflict * For the conflic fix, will be removed later * Scuffed Fix * Removal & Adding the Decouple * Took some HEAVY pointers from SirWarocks work. The Roadblock has been CLEARED, DOAFTERS WORK NOW!! * Cleanup & Optimizing, mostly comps. * More Optimization, most of this is just imported Warock Code, his QOL included. Did not want to remove SolutionDNA's tho, mostly due to a Log.Debug in OnPrint. * Forgot that the Print Refreshes, more of Warocks work. * Removing Loc.GetString * All of BloodStream to Shared, hopefully no errors. * Sketchy Dirty Removed * Removed Timer.Spawn, added FrameUpdate cause anything else only updated when the window opened, & a bit of cleanup. * No mo Mispredict * GenerateDnaEvent Predicted * Forgot the user * I knew it was real, bloodstutter is REAL and now GONE. * Cant dirty NewEntityBloodData due to potential stutter, so its safer to put it all back into server. again... * Clearer * Thank you leahcat, no more identity leak. * Routine Maintenance * sealing the class * it checks for this now?! * While im here, FileScope Namespaces & removing unused namespaces * Update Attribute Type (SirWarock Import), it works and is much easier to read. * Forever Fixing Conflicts * Readonly Genocide & Partial Maxing * LGTM, BloodstreamSystem moved to SharedBloodstreamSystem! * Sohn * If OG Github back push this commit * One Billionth Commit Fix * Removed client/server stuff * Made implicit * NewLine & comment on why AutoGenCompState is true * Updatin the rest of the Popups to use Entity * I think that's what they meant? It looks cleaner at least. * Mass Attribute for LocalEvents that are safe to change. * Putting it back as abstract * maybe? * Guhh, rolling back empty client/server of BloodStream * Removed Client/Server BloodstreamSystems, changed access modifier from protected to private, & renamed SharedBloodstreamSystem to BloodstreamSystem * From Protected to Private * Removed comment & made it explicit on what changed to true * Guh, hopefully thats all of it... * Forgot * Review * Test Push * Line 316 in SharedForensicsSystem was causing the errors, better to play it safe * Review Changes * Update Content.Shared/Forensics/Events.cs Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com> * The only thing SolutionDNAs does is search and clears itself. I see no reason to keep it * The print.disabled didnt properly disable when cleared. So ill just use the old if check * Figured out the rest of the SubscribeLocalEvents and networking BloodData cause its fully in Shared --------- Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com>
260 lines
9.5 KiB
C#
260 lines
9.5 KiB
C#
using System.Linq;
|
|
using System.Text;
|
|
using Content.Shared.UserInterface;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Hands.EntitySystems;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Paper;
|
|
using Content.Shared.Verbs;
|
|
using Content.Shared.Tag;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Timing;
|
|
using Content.Shared.Forensics.Components;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.Prototypes;
|
|
// todo: remove this stinky LINQy
|
|
|
|
namespace Content.Shared.Forensics.Systems;
|
|
|
|
public sealed partial class SharedForensicScannerSystem : EntitySystem
|
|
{
|
|
[Dependency] private IGameTiming _gameTiming = default!;
|
|
[Dependency] private SharedDoAfterSystem _doAfterSystem = default!;
|
|
[Dependency] private SharedUserInterfaceSystem _uiSystem = default!;
|
|
[Dependency] private SharedPopupSystem _popupSystem = default!;
|
|
[Dependency] private PaperSystem _paperSystem = default!;
|
|
[Dependency] private SharedHandsSystem _handsSystem = default!;
|
|
[Dependency] private SharedAudioSystem _audioSystem = default!;
|
|
[Dependency] private MetaDataSystem _metaData = default!;
|
|
[Dependency] private SharedForensicsSystem _forensicsSystem = default!;
|
|
[Dependency] private TagSystem _tag = default!;
|
|
|
|
private static readonly ProtoId<TagPrototype> DNASolutionScannableTag = "DNASolutionScannable";
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnScannerUpdate(Entity<ForensicScannerComponent> scanner, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
UpdateUi(scanner);
|
|
}
|
|
|
|
private void UpdateUi(Entity<ForensicScannerComponent> scanner)
|
|
{
|
|
if (_uiSystem.TryGetOpenUi(scanner.Owner, ForensicScannerUiKey.Key, out var bui))
|
|
{
|
|
bui.Update();
|
|
}
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnDoAfter(Entity<ForensicScannerComponent> scanner, ref ForensicScannerDoAfterEvent args)
|
|
{
|
|
if (args.Handled || args.Cancelled)
|
|
return;
|
|
|
|
if (args.Args.Target != null)
|
|
{
|
|
if (TryComp<ForensicsComponent>(args.Args.Target, out var forensics))
|
|
{
|
|
scanner.Comp.Fingerprints = forensics.Fingerprints.ToList();
|
|
scanner.Comp.Fibers = forensics.Fibers.ToList();
|
|
scanner.Comp.DNAs = forensics.DNAs.ToList();
|
|
scanner.Comp.Residues = forensics.Residues.ToList();
|
|
}
|
|
else
|
|
{
|
|
scanner.Comp.Fingerprints = [];
|
|
scanner.Comp.Fibers = [];
|
|
scanner.Comp.DNAs = [];
|
|
scanner.Comp.Residues = [];
|
|
}
|
|
|
|
if (_tag.HasTag(args.Args.Target.Value, DNASolutionScannableTag))
|
|
{
|
|
scanner.Comp.DNAs.AddRange(_forensicsSystem.GetSolutionsDNA(args.Args.Target.Value));
|
|
}
|
|
|
|
scanner.Comp.LastScannedName = Identity.Name(args.Args.Target.Value, EntityManager, args.Args.User);
|
|
|
|
DirtyFields(scanner.AsNullable(),
|
|
null,
|
|
nameof(ForensicScannerComponent.Fingerprints),
|
|
nameof(ForensicScannerComponent.Fibers),
|
|
nameof(ForensicScannerComponent.DNAs),
|
|
nameof(ForensicScannerComponent.Residues),
|
|
nameof(ForensicScannerComponent.LastScannedName));
|
|
}
|
|
|
|
OpenUserInterface(args.Args.User, scanner);
|
|
}
|
|
|
|
/// <remarks>
|
|
/// Hosts logic common between OnUtilityVerb and OnAfterInteract.
|
|
/// </remarks>
|
|
private void StartScan(Entity<ForensicScannerComponent> scanner, EntityUid user, EntityUid target)
|
|
{
|
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, scanner.Comp.ScanDelay, new ForensicScannerDoAfterEvent(), scanner, target: target, used: scanner)
|
|
{
|
|
BreakOnMove = true,
|
|
NeedHand = true,
|
|
});
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnUtilityVerb(Entity<ForensicScannerComponent> scanner, ref GetVerbsEvent<UtilityVerb> args)
|
|
{
|
|
if (!args.CanInteract || !args.CanAccess)
|
|
return;
|
|
|
|
var evArgs = args;
|
|
|
|
var verb = new UtilityVerb()
|
|
{
|
|
Act = () => StartScan(scanner, evArgs.User, evArgs.Target),
|
|
IconEntity = GetNetEntity(scanner),
|
|
Text = Loc.GetString("forensic-scanner-verb-text"),
|
|
Message = Loc.GetString("forensic-scanner-verb-message"),
|
|
// This is important because if its true using the scanner will count as touching the object.
|
|
DoContactInteraction = false,
|
|
};
|
|
|
|
args.Verbs.Add(verb);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnAfterInteract(Entity<ForensicScannerComponent> scanner, ref AfterInteractEvent args)
|
|
{
|
|
if (args.Target == null || !args.CanReach)
|
|
return;
|
|
|
|
StartScan(scanner, args.User, args.Target.Value);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnAfterInteractUsing(Entity<ForensicScannerComponent> scanner, ref AfterInteractUsingEvent args)
|
|
{
|
|
if (args.Handled || !args.CanReach)
|
|
return;
|
|
|
|
if (!TryComp<ForensicPadComponent>(args.Used, out var pad))
|
|
return;
|
|
|
|
foreach (var fiber in scanner.Comp.Fibers)
|
|
{
|
|
if (fiber != pad.Sample)
|
|
continue;
|
|
|
|
_audioSystem.PlayPredicted(scanner.Comp.SoundMatch, scanner.Owner, args.User);
|
|
_popupSystem.PopupEntity(Loc.GetString("forensic-scanner-match-fiber"), scanner, args.User);
|
|
return;
|
|
}
|
|
|
|
foreach (var fingerprint in scanner.Comp.Fingerprints)
|
|
{
|
|
if (fingerprint != pad.Sample)
|
|
continue;
|
|
|
|
_audioSystem.PlayPredicted(scanner.Comp.SoundMatch, scanner.Owner, args.User);
|
|
_popupSystem.PopupEntity(Loc.GetString("forensic-scanner-match-fingerprint"), scanner, args.User);
|
|
return;
|
|
}
|
|
|
|
_audioSystem.PlayPredicted(scanner.Comp.SoundNoMatch, scanner.Owner, args.User);
|
|
_popupSystem.PopupEntity(Loc.GetString("forensic-scanner-match-none"), scanner, args.User);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnBeforeActivatableUIOpen(Entity<ForensicScannerComponent> scanner, ref BeforeActivatableUIOpenEvent args)
|
|
{
|
|
UpdateUi(scanner);
|
|
}
|
|
|
|
private void OpenUserInterface(EntityUid user, Entity<ForensicScannerComponent> scanner)
|
|
{
|
|
_uiSystem.OpenUi(scanner.Owner, ForensicScannerUiKey.Key, user, true);
|
|
|
|
UpdateUi(scanner);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnPrint(Entity<ForensicScannerComponent> scanner, ref ForensicScannerPrintMessage args)
|
|
{
|
|
var user = args.Actor;
|
|
|
|
if (_gameTiming.CurTime < scanner.Comp.PrintReadyAt)
|
|
{
|
|
// This shouldn't occur due to the UI guarding against it, but
|
|
// if it does, tell the user why nothing happened.
|
|
_popupSystem.PopupEntity(Loc.GetString("forensic-scanner-printer-not-ready"), scanner, user);
|
|
return;
|
|
}
|
|
|
|
// Spawn a piece of paper.
|
|
var printed = PredictedSpawnAtPosition(scanner.Comp.PaperPrototypeID, Transform(scanner).Coordinates);
|
|
_handsSystem.PickupOrDrop(user, printed, checkActionBlocker: false);
|
|
|
|
if (!TryComp<PaperComponent>(printed, out var paperComp))
|
|
{
|
|
Log.Error("Printed paper did not have PaperComponent.");
|
|
return;
|
|
}
|
|
|
|
_metaData.SetEntityName(printed, Loc.GetString("forensic-scanner-report-title", ("entity", scanner.Comp.LastScannedName)));
|
|
|
|
var text = new StringBuilder();
|
|
|
|
text.AppendLine(Loc.GetString("forensic-scanner-interface-fingerprints"));
|
|
foreach (var fingerprint in scanner.Comp.Fingerprints)
|
|
{
|
|
text.AppendLine(fingerprint);
|
|
}
|
|
text.AppendLine();
|
|
text.AppendLine(Loc.GetString("forensic-scanner-interface-fibers"));
|
|
foreach (var fiber in scanner.Comp.Fibers)
|
|
{
|
|
text.AppendLine(fiber);
|
|
}
|
|
text.AppendLine();
|
|
text.AppendLine(Loc.GetString("forensic-scanner-interface-dnas"));
|
|
foreach (var dna in scanner.Comp.DNAs)
|
|
{
|
|
text.AppendLine(dna);
|
|
}
|
|
text.AppendLine();
|
|
text.AppendLine(Loc.GetString("forensic-scanner-interface-residues"));
|
|
foreach (var residue in scanner.Comp.Residues)
|
|
{
|
|
text.AppendLine(residue);
|
|
}
|
|
|
|
_paperSystem.SetContent((printed, paperComp), text.ToString());
|
|
var audioParams = scanner.Comp.SoundPrint?.Params ?? AudioParams.Default;
|
|
audioParams = audioParams.WithVariation(0.25f).AddVolume(3f).WithRolloffFactor(2.8f).WithMaxDistance(4.5f);
|
|
_audioSystem.PlayPredicted(scanner.Comp.SoundPrint, scanner, user, audioParams);
|
|
|
|
scanner.Comp.PrintReadyAt = _gameTiming.CurTime + scanner.Comp.PrintCooldown;
|
|
|
|
DirtyField(scanner.AsNullable(), nameof(ForensicScannerComponent.PrintReadyAt));
|
|
|
|
UpdateUi(scanner);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnClear(Entity<ForensicScannerComponent> scanner, ref ForensicScannerClearMessage args)
|
|
{
|
|
scanner.Comp.Fingerprints = [];
|
|
scanner.Comp.Fibers = [];
|
|
scanner.Comp.DNAs = [];
|
|
scanner.Comp.LastScannedName = string.Empty;
|
|
|
|
DirtyFields(scanner.AsNullable(),
|
|
null,
|
|
nameof(ForensicScannerComponent.Fingerprints),
|
|
nameof(ForensicScannerComponent.Fibers),
|
|
nameof(ForensicScannerComponent.DNAs),
|
|
nameof(ForensicScannerComponent.LastScannedName));
|
|
|
|
UpdateUi(scanner);
|
|
}
|
|
}
|