NodeScannerSystem.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Content.Server.Popups;
  2. using Content.Server.Xenoarchaeology.Equipment.Components;
  3. using Content.Server.Xenoarchaeology.XenoArtifacts;
  4. using Content.Shared.Interaction;
  5. using Content.Shared.Timing;
  6. using Content.Shared.Verbs;
  7. namespace Content.Server.Xenoarchaeology.Equipment.Systems;
  8. public sealed class NodeScannerSystem : EntitySystem
  9. {
  10. [Dependency] private readonly UseDelaySystem _useDelay = default!;
  11. [Dependency] private readonly PopupSystem _popupSystem = default!;
  12. /// <inheritdoc/>
  13. public override void Initialize()
  14. {
  15. SubscribeLocalEvent<NodeScannerComponent, BeforeRangedInteractEvent>(OnBeforeRangedInteract);
  16. SubscribeLocalEvent<NodeScannerComponent, GetVerbsEvent<UtilityVerb>>(AddScanVerb);
  17. }
  18. private void OnBeforeRangedInteract(EntityUid uid, NodeScannerComponent component, BeforeRangedInteractEvent args)
  19. {
  20. if (args.Handled || !args.CanReach || args.Target is not {} target)
  21. return;
  22. if (!TryComp<ArtifactComponent>(target, out var artifact) || artifact.CurrentNodeId == null)
  23. return;
  24. CreatePopup(uid, target, artifact);
  25. args.Handled = true;
  26. }
  27. private void AddScanVerb(EntityUid uid, NodeScannerComponent component, GetVerbsEvent<UtilityVerb> args)
  28. {
  29. if (!args.CanAccess)
  30. return;
  31. if (!TryComp<ArtifactComponent>(args.Target, out var artifact) || artifact.CurrentNodeId == null)
  32. return;
  33. var verb = new UtilityVerb()
  34. {
  35. Act = () =>
  36. {
  37. CreatePopup(uid, args.Target, artifact);
  38. },
  39. Text = Loc.GetString("node-scan-tooltip")
  40. };
  41. args.Verbs.Add(verb);
  42. }
  43. private void CreatePopup(EntityUid uid, EntityUid target, ArtifactComponent artifact)
  44. {
  45. if (TryComp(uid, out UseDelayComponent? useDelay)
  46. && !_useDelay.TryResetDelay((uid, useDelay), true))
  47. return;
  48. _popupSystem.PopupEntity(Loc.GetString("node-scan-popup",
  49. ("id", $"{artifact.CurrentNodeId}")), target);
  50. }
  51. }