1
0

KnappingSystem.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Server.DoAfter;
  2. using Content.Shared.Rocks;
  3. using Content.Shared.Interaction;
  4. using Content.Shared.DoAfter;
  5. using Robust.Server.GameObjects;
  6. using Content.Shared.Popups;
  7. using Content.Shared.Hands.EntitySystems;
  8. namespace Content.Server.Rocks;
  9. public sealed partial class KnappingSystem : EntitySystem
  10. {
  11. [Dependency] private readonly DoAfterSystem _doAfter = default!;
  12. [Dependency] private readonly SharedPopupSystem _popup = default!;
  13. [Dependency] private readonly SharedHandsSystem _hands = default!;
  14. public override void Initialize()
  15. {
  16. base.Initialize();
  17. SubscribeLocalEvent<KnappingComponent, AfterInteractEvent>(OnAfterInteract);
  18. SubscribeLocalEvent<KnappingComponent, KnappingDoAfterEvent>(OnDoAfter);
  19. }
  20. private void OnAfterInteract(EntityUid uid, KnappingComponent component, AfterInteractEvent args)
  21. {
  22. if (args.Target == null || !args.CanReach || !HasComp<KnappingAnchoredComponent>(args.Target))
  23. return;
  24. _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, component.HitTime, new KnappingDoAfterEvent(), uid, target: args.Target, used: uid)
  25. {
  26. Broadcast = true,
  27. BreakOnMove = true,
  28. NeedHand = true,
  29. });
  30. }
  31. private void OnDoAfter(EntityUid flintUid, KnappingComponent component, ref KnappingDoAfterEvent args)
  32. {
  33. if (args.Cancelled || args.Handled)
  34. return;
  35. component.CurrentHits++;
  36. if (component.CurrentHits >= component.HitsRequired)
  37. {
  38. var result = Spawn(component.ResultPrototype, Transform(flintUid).MapPosition);
  39. QueueDel(flintUid);
  40. _hands.TryPickupAnyHand(args.Args.User, result);
  41. }
  42. args.Handled = true;
  43. }
  44. }