move hot plate item placement stuff into its own system (#18923)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-08-20 01:37:19 +01:00
committed by GitHub
parent f25813a098
commit 00bae110e1
9 changed files with 160 additions and 124 deletions

View File

@@ -10,6 +10,7 @@ using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Content.Shared.Audio;
using Content.Shared.DeviceLinking;
using Content.Shared.DeviceLinking.Events;
using Content.Shared.Placeable;
using Content.Shared.Popups;
using Content.Shared.Research.Components;
using Content.Shared.Xenoarchaeology.Equipment;
@@ -18,7 +19,6 @@ using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Events;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -45,7 +45,6 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ActiveScannedArtifactComponent, MoveEvent>(OnScannedMoved);
SubscribeLocalEvent<ActiveScannedArtifactComponent, ArtifactActivatedEvent>(OnArtifactActivated);
SubscribeLocalEvent<ActiveArtifactAnalyzerComponent, ComponentStartup>(OnAnalyzeStart);
@@ -54,8 +53,8 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
SubscribeLocalEvent<ArtifactAnalyzerComponent, UpgradeExamineEvent>(OnUpgradeExamine);
SubscribeLocalEvent<ArtifactAnalyzerComponent, RefreshPartsEvent>(OnRefreshParts);
SubscribeLocalEvent<ArtifactAnalyzerComponent, StartCollideEvent>(OnCollide);
SubscribeLocalEvent<ArtifactAnalyzerComponent, EndCollideEvent>(OnEndCollide);
SubscribeLocalEvent<ArtifactAnalyzerComponent, ItemPlacedEvent>(OnItemPlaced);
SubscribeLocalEvent<ArtifactAnalyzerComponent, ItemRemovedEvent>(OnItemRemoved);
SubscribeLocalEvent<ArtifactAnalyzerComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<AnalysisConsoleComponent, NewLinkEvent>(OnNewLink);
@@ -107,22 +106,18 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
}
/// <summary>
/// Goes through the current contacts on
/// Goes through the current entities on
/// the analyzer and returns a valid artifact
/// </summary>
/// <param name="uid"></param>
/// <param name="component"></param>
/// <param name="placer"></param>
/// <returns></returns>
private EntityUid? GetArtifactForAnalysis(EntityUid? uid, ArtifactAnalyzerComponent? component = null)
private EntityUid? GetArtifactForAnalysis(EntityUid? uid, ItemPlacerComponent? placer = null)
{
if (uid == null)
if (uid == null || !Resolve(uid.Value, ref placer))
return null;
if (!Resolve(uid.Value, ref component))
return null;
var validEnts = component.Contacts.Where(HasComp<ArtifactComponent>).ToHashSet();
return validEnts.FirstOrNull();
return placer.PlacedEntities.FirstOrNull();
}
/// <summary>
@@ -205,11 +200,12 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
artifact = analyzer.LastAnalyzedArtifact;
msg = GetArtifactScanMessage(analyzer);
totalTime = analyzer.AnalysisDuration * analyzer.AnalysisDurationMulitplier;
canScan = analyzer.Contacts.Any();
if (TryComp<ItemPlacerComponent>(component.AnalyzerEntity, out var placer))
canScan = placer.PlacedEntities.Any();
canPrint = analyzer.ReadyToPrint;
// the artifact that's actually on the scanner right now.
if (GetArtifactForAnalysis(component.AnalyzerEntity, analyzer) is { } current)
if (GetArtifactForAnalysis(component.AnalyzerEntity, placer) is { } current)
points = _artifact.GetResearchPointValue(current);
}
var analyzerConnected = component.AnalyzerEntity != null;
@@ -381,20 +377,6 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
CancelScan(uid);
}
/// <summary>
/// Checks to make sure that the currently scanned artifact isn't moved off of the scanner
/// </summary>
private void OnScannedMoved(EntityUid uid, ActiveScannedArtifactComponent component, ref MoveEvent args)
{
if (!TryComp<ArtifactAnalyzerComponent>(component.Scanner, out var analyzer))
return;
if (analyzer.Contacts.Contains(uid))
return;
CancelScan(uid, component, analyzer);
}
/// <summary>
/// Stops the current scan
/// </summary>
@@ -448,27 +430,16 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
args.AddPercentageUpgrade("analyzer-artifact-component-upgrade-analysis", component.AnalysisDurationMulitplier);
}
private void OnCollide(EntityUid uid, ArtifactAnalyzerComponent component, ref StartCollideEvent args)
private void OnItemPlaced(EntityUid uid, ArtifactAnalyzerComponent component, ref ItemPlacedEvent args)
{
var otherEnt = args.OtherEntity;
if (!HasComp<ArtifactComponent>(otherEnt))
return;
component.Contacts.Add(otherEnt);
if (component.Console != null)
if (component.Console != null && Exists(component.Console))
UpdateUserInterface(component.Console.Value);
}
private void OnEndCollide(EntityUid uid, ArtifactAnalyzerComponent component, ref EndCollideEvent args)
private void OnItemRemoved(EntityUid uid, ArtifactAnalyzerComponent component, ref ItemRemovedEvent args)
{
var otherEnt = args.OtherEntity;
if (!HasComp<ArtifactComponent>(otherEnt))
return;
component.Contacts.Remove(otherEnt);
// cancel the scan if the artifact moves off the analyzer
CancelScan(args.OtherEntity);
if (component.Console != null && Exists(component.Console))
UpdateUserInterface(component.Console.Value);
}

View File

@@ -5,7 +5,7 @@ using Content.Server.Xenoarchaeology.Equipment.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Robust.Shared.Physics.Events;
using Content.Shared.Placeable;
using Robust.Shared.Player;
using Robust.Shared.Timing;
@@ -13,8 +13,8 @@ namespace Content.Server.Xenoarchaeology.Equipment.Systems;
public sealed class TraversalDistorterSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly PopupSystem _popup = default!;
/// <inheritdoc/>
public override void Initialize()
@@ -26,8 +26,8 @@ public sealed class TraversalDistorterSystem : EntitySystem
SubscribeLocalEvent<TraversalDistorterComponent, RefreshPartsEvent>(OnRefreshParts);
SubscribeLocalEvent<TraversalDistorterComponent, UpgradeExamineEvent>(OnUpgradeExamine);
SubscribeLocalEvent<TraversalDistorterComponent, StartCollideEvent>(OnCollide);
SubscribeLocalEvent<TraversalDistorterComponent, EndCollideEvent>(OnEndCollide);
SubscribeLocalEvent<TraversalDistorterComponent, ItemPlacedEvent>(OnItemPlaced);
SubscribeLocalEvent<TraversalDistorterComponent, ItemRemovedEvent>(OnItemRemoved);
}
private void OnInit(EntityUid uid, TraversalDistorterComponent component, MapInitEvent args)
@@ -88,24 +88,15 @@ public sealed class TraversalDistorterSystem : EntitySystem
args.AddPercentageUpgrade("traversal-distorter-upgrade-bias", component.BiasChance / component.BaseBiasChance);
}
private void OnCollide(EntityUid uid, TraversalDistorterComponent component, ref StartCollideEvent args)
private void OnItemPlaced(EntityUid uid, TraversalDistorterComponent component, ref ItemPlacedEvent args)
{
var otherEnt = args.OtherEntity;
if (!HasComp<ArtifactComponent>(otherEnt))
return;
var bias = EnsureComp<BiasedArtifactComponent>(otherEnt);
var bias = EnsureComp<BiasedArtifactComponent>(args.OtherEntity);
bias.Provider = uid;
}
private void OnEndCollide(EntityUid uid, TraversalDistorterComponent component, ref EndCollideEvent args)
private void OnItemRemoved(EntityUid uid, TraversalDistorterComponent component, ref ItemRemovedEvent args)
{
var otherEnt = args.OtherEntity;
if (!HasComp<ArtifactComponent>(otherEnt))
return;
if (TryComp<BiasedArtifactComponent>(otherEnt, out var bias) && bias.Provider == uid)
RemComp(otherEnt, bias);
}