SetSolutionCapacity.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Content.Shared.Chemistry.EntitySystems;
  2. using Content.Shared.Administration;
  3. using Content.Shared.Chemistry.Components.SolutionManager;
  4. using Content.Shared.FixedPoint;
  5. using Robust.Shared.Console;
  6. using System.Linq;
  7. namespace Content.Server.Administration.Commands
  8. {
  9. [AdminCommand(AdminFlags.Fun)]
  10. public sealed class SetSolutionCapacity : IConsoleCommand
  11. {
  12. [Dependency] private readonly IEntityManager _entManager = default!;
  13. public string Command => "setsolutioncapacity";
  14. public string Description => "Set the capacity (maximum volume) of some solution.";
  15. public string Help => $"Usage: {Command} <target> <solution> <new capacity>";
  16. public void Execute(IConsoleShell shell, string argStr, string[] args)
  17. {
  18. if (args.Length < 3)
  19. {
  20. shell.WriteLine($"Not enough arguments.\n{Help}");
  21. return;
  22. }
  23. if (!NetEntity.TryParse(args[0], out var uidNet))
  24. {
  25. shell.WriteLine($"Invalid entity id.");
  26. return;
  27. }
  28. if (!_entManager.TryGetEntity(uidNet, out var uid) || !_entManager.TryGetComponent(uid, out SolutionContainerManagerComponent? man))
  29. {
  30. shell.WriteLine($"Entity does not have any solutions.");
  31. return;
  32. }
  33. var solutionContainerSystem = _entManager.System<SharedSolutionContainerSystem>();
  34. if (!solutionContainerSystem.TryGetSolution((uid.Value, man), args[1], out var solution))
  35. {
  36. var validSolutions = string.Join(", ", solutionContainerSystem.EnumerateSolutions((uid.Value, man)).Select(s => s.Name));
  37. shell.WriteLine($"Entity does not have a \"{args[1]}\" solution. Valid solutions are:\n{validSolutions}");
  38. return;
  39. }
  40. if (!float.TryParse(args[2], out var quantityFloat))
  41. {
  42. shell.WriteLine($"Failed to parse new capacity.");
  43. return;
  44. }
  45. if (quantityFloat < 0.0f)
  46. {
  47. shell.WriteLine($"Cannot set the maximum volume of a solution to a negative number.");
  48. return;
  49. }
  50. var quantity = FixedPoint2.New(quantityFloat);
  51. solutionContainerSystem.SetCapacity(solution.Value, quantity);
  52. }
  53. }
  54. }