1
0

ToolRefinableSystem.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Shared.Construction;
  2. using Content.Shared.Interaction;
  3. using Content.Shared.Storage;
  4. using Content.Shared.Tools.Components;
  5. using Robust.Shared.Network;
  6. using Robust.Shared.Random;
  7. namespace Content.Shared.Tools.Systems;
  8. public sealed class ToolRefinablSystem : EntitySystem
  9. {
  10. [Dependency] private readonly INetManager _net = default!;
  11. [Dependency] private readonly IRobustRandom _random = default!;
  12. [Dependency] private readonly SharedToolSystem _toolSystem = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<ToolRefinableComponent, InteractUsingEvent>(OnInteractUsing);
  17. SubscribeLocalEvent<ToolRefinableComponent, WelderRefineDoAfterEvent>(OnDoAfter);
  18. }
  19. private void OnInteractUsing(EntityUid uid, ToolRefinableComponent component, InteractUsingEvent args)
  20. {
  21. if (args.Handled)
  22. return;
  23. args.Handled = _toolSystem.UseTool(
  24. args.Used,
  25. args.User,
  26. uid,
  27. component.RefineTime,
  28. component.QualityNeeded,
  29. new WelderRefineDoAfterEvent(),
  30. fuel: component.RefineFuel);
  31. }
  32. private void OnDoAfter(EntityUid uid, ToolRefinableComponent component, WelderRefineDoAfterEvent args)
  33. {
  34. if (args.Cancelled)
  35. return;
  36. if (_net.IsClient)
  37. return;
  38. var xform = Transform(uid);
  39. var spawns = EntitySpawnCollection.GetSpawns(component.RefineResult, _random);
  40. foreach (var spawn in spawns)
  41. {
  42. SpawnNextToOrDrop(spawn, uid, xform);
  43. }
  44. Del(uid);
  45. }
  46. }