1
0

SetSolutionTemperature.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 SetSolutionTemperature : IConsoleCommand
  10. {
  11. [Dependency] private readonly IEntityManager _entManager = default!;
  12. public string Command => "setsolutiontemperature";
  13. public string Description => "Set the temperature of some solution.";
  14. public string Help => $"Usage: {Command} <target> <solution> <new temperature>";
  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 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 temperature.");
  42. return;
  43. }
  44. if (quantity <= 0.0f)
  45. {
  46. shell.WriteLine($"Cannot set the temperature of a solution to a non-positive number.");
  47. return;
  48. }
  49. solutionContainerSystem.SetTemperature(solution.Value, quantity);
  50. }
  51. }
  52. }