SharedResearchStealerSystem.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Content.Shared.DoAfter;
  2. using Content.Shared.Interaction;
  3. using Content.Shared.Ninja.Systems;
  4. using Content.Shared.Popups;
  5. using Content.Shared.Research.Components;
  6. using Robust.Shared.Serialization;
  7. namespace Content.Shared.Research.Systems;
  8. public abstract class SharedResearchStealerSystem : EntitySystem
  9. {
  10. [Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
  11. [Dependency] private readonly SharedNinjaGlovesSystem _gloves = default!;
  12. [Dependency] private readonly SharedPopupSystem _popup = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<ResearchStealerComponent, BeforeInteractHandEvent>(OnBeforeInteractHand);
  17. }
  18. /// <summary>
  19. /// Start do after for downloading techs from a r&d server.
  20. /// Will only try if there is at least 1 tech researched.
  21. /// </summary>
  22. private void OnBeforeInteractHand(EntityUid uid, ResearchStealerComponent comp, BeforeInteractHandEvent args)
  23. {
  24. // TODO: generic event
  25. if (args.Handled || !_gloves.AbilityCheck(uid, args, out var target))
  26. return;
  27. // can only hack the server, not a random console
  28. if (!TryComp<TechnologyDatabaseComponent>(target, out var database) || HasComp<ResearchClientComponent>(target))
  29. return;
  30. args.Handled = true;
  31. // fail fast if theres no techs to steal right now
  32. if (database.UnlockedTechnologies.Count == 0)
  33. {
  34. _popup.PopupClient(Loc.GetString("ninja-download-fail"), uid, uid);
  35. return;
  36. }
  37. var doAfterArgs = new DoAfterArgs(EntityManager, uid, comp.Delay, new ResearchStealDoAfterEvent(), target: target, used: uid, eventTarget: uid)
  38. {
  39. BreakOnDamage = true,
  40. BreakOnMove = true,
  41. MovementThreshold = 0.5f,
  42. };
  43. _doAfter.TryStartDoAfter(doAfterArgs);
  44. }
  45. }
  46. /// <summary>
  47. /// Raised on the research stealer when the doafter completes.
  48. /// </summary>
  49. [Serializable, NetSerializable]
  50. public sealed partial class ResearchStealDoAfterEvent : SimpleDoAfterEvent
  51. {
  52. }