PuddleSystem.Transfers.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Content.Shared.Chemistry.Components;
  2. using Content.Shared.DragDrop;
  3. using Content.Shared.FixedPoint;
  4. using Content.Shared.Fluids;
  5. namespace Content.Server.Fluids.EntitySystems;
  6. public sealed partial class PuddleSystem
  7. {
  8. private void InitializeTransfers()
  9. {
  10. SubscribeLocalEvent<RefillableSolutionComponent, DragDropDraggedEvent>(OnRefillableDragged);
  11. }
  12. private void OnRefillableDragged(Entity<RefillableSolutionComponent> entity, ref DragDropDraggedEvent args)
  13. {
  14. if (!_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.Solution, out var soln, out var solution) || solution.Volume == FixedPoint2.Zero)
  15. {
  16. _popups.PopupEntity(Loc.GetString("mopping-system-empty", ("used", entity.Owner)), entity, args.User);
  17. return;
  18. }
  19. // Dump reagents into DumpableSolution
  20. if (TryComp<DumpableSolutionComponent>(args.Target, out var dump))
  21. {
  22. if (!_solutionContainerSystem.TryGetDumpableSolution((args.Target, dump, null), out var dumpableSoln, out var dumpableSolution))
  23. return;
  24. bool success = true;
  25. if (dump.Unlimited)
  26. {
  27. var split = _solutionContainerSystem.SplitSolution(soln.Value, solution.Volume);
  28. dumpableSolution.AddSolution(split, _prototypeManager);
  29. }
  30. else
  31. {
  32. var split = _solutionContainerSystem.SplitSolution(soln.Value, dumpableSolution.AvailableVolume);
  33. success = _solutionContainerSystem.TryAddSolution(dumpableSoln.Value, split);
  34. }
  35. if (success)
  36. {
  37. _audio.PlayPvs(AbsorbentComponent.DefaultTransferSound, args.Target);
  38. }
  39. else
  40. {
  41. _popups.PopupEntity(Loc.GetString("mopping-system-full", ("used", args.Target)), args.Target, args.User);
  42. }
  43. return;
  44. }
  45. // Take reagents from target
  46. if (!TryComp<DrainableSolutionComponent>(args.Target, out var drainable))
  47. {
  48. if (!_solutionContainerSystem.TryGetDrainableSolution((args.Target, drainable, null), out var drainableSolution, out _))
  49. return;
  50. var split = _solutionContainerSystem.SplitSolution(drainableSolution.Value, solution.AvailableVolume);
  51. if (_solutionContainerSystem.TryAddSolution(soln.Value, split))
  52. {
  53. _audio.PlayPvs(AbsorbentComponent.DefaultTransferSound, entity);
  54. }
  55. else
  56. {
  57. _popups.PopupEntity(Loc.GetString("mopping-system-full", ("used", entity.Owner)), entity, args.User);
  58. }
  59. }
  60. }
  61. }