SetSolutionThermalEnergy.cs 2.6 KB

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