2022-12-20 17:55:35 +13:00
|
|
|
using Content.Server.Popups;
|
2022-12-19 22:53:54 -05:00
|
|
|
using Content.Server.Xenoarchaeology.Equipment.Components;
|
|
|
|
|
using Content.Server.Xenoarchaeology.XenoArtifacts;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Timing;
|
2024-06-14 05:01:32 +03:00
|
|
|
using Content.Shared.Verbs;
|
2022-12-19 22:53:54 -05:00
|
|
|
|
|
|
|
|
namespace Content.Server.Xenoarchaeology.Equipment.Systems;
|
|
|
|
|
|
|
|
|
|
public sealed class NodeScannerSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
|
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2024-06-14 05:01:32 +03:00
|
|
|
SubscribeLocalEvent<NodeScannerComponent, BeforeRangedInteractEvent>(OnBeforeRangedInteract);
|
|
|
|
|
SubscribeLocalEvent<NodeScannerComponent, GetVerbsEvent<UtilityVerb>>(AddScanVerb);
|
2022-12-19 22:53:54 -05:00
|
|
|
}
|
|
|
|
|
|
2024-06-14 05:01:32 +03:00
|
|
|
private void OnBeforeRangedInteract(EntityUid uid, NodeScannerComponent component, BeforeRangedInteractEvent args)
|
2022-12-19 22:53:54 -05:00
|
|
|
{
|
2024-06-14 05:01:32 +03:00
|
|
|
if (args.Handled || !args.CanReach || args.Target is not {} target)
|
2022-12-19 22:53:54 -05:00
|
|
|
return;
|
|
|
|
|
|
2024-06-14 05:01:32 +03:00
|
|
|
if (!TryComp<ArtifactComponent>(target, out var artifact) || artifact.CurrentNodeId == null)
|
2022-12-19 22:53:54 -05:00
|
|
|
return;
|
|
|
|
|
|
2024-06-14 05:01:32 +03:00
|
|
|
CreatePopup(uid, target, artifact);
|
2022-12-19 22:53:54 -05:00
|
|
|
args.Handled = true;
|
2024-06-14 05:01:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddScanVerb(EntityUid uid, NodeScannerComponent component, GetVerbsEvent<UtilityVerb> args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.CanAccess)
|
|
|
|
|
return;
|
2022-12-19 22:53:54 -05:00
|
|
|
|
2024-06-14 05:01:32 +03:00
|
|
|
if (!TryComp<ArtifactComponent>(args.Target, out var artifact) || artifact.CurrentNodeId == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var verb = new UtilityVerb()
|
|
|
|
|
{
|
|
|
|
|
Act = () =>
|
|
|
|
|
{
|
|
|
|
|
CreatePopup(uid, args.Target, artifact);
|
|
|
|
|
},
|
|
|
|
|
Text = Loc.GetString("node-scan-tooltip")
|
|
|
|
|
};
|
2024-01-03 21:33:09 -04:00
|
|
|
|
2024-06-14 05:01:32 +03:00
|
|
|
args.Verbs.Add(verb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreatePopup(EntityUid uid, EntityUid target, ArtifactComponent artifact)
|
|
|
|
|
{
|
2024-01-03 21:33:09 -04:00
|
|
|
if (TryComp(uid, out UseDelayComponent? useDelay)
|
|
|
|
|
&& !_useDelay.TryResetDelay((uid, useDelay), true))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-12-19 22:53:54 -05:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("node-scan-popup",
|
2023-03-23 22:50:24 -04:00
|
|
|
("id", $"{artifact.CurrentNodeId}")), target);
|
2022-12-19 22:53:54 -05:00
|
|
|
}
|
|
|
|
|
}
|