AddGasCommand.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Server.Administration;
  2. using Content.Server.Atmos.EntitySystems;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Atmos;
  5. using Robust.Shared.Console;
  6. using Robust.Shared.Map;
  7. using Robust.Shared.Map.Components;
  8. namespace Content.Server.Atmos.Commands
  9. {
  10. [AdminCommand(AdminFlags.Debug)]
  11. public sealed class AddGasCommand : IConsoleCommand
  12. {
  13. [Dependency] private readonly IEntityManager _entManager = default!;
  14. public string Command => "addgas";
  15. public string Description => "Adds gas at a certain position.";
  16. public string Help => "addgas <X> <Y> <GridEid> <Gas> <moles>";
  17. public void Execute(IConsoleShell shell, string argStr, string[] args)
  18. {
  19. if (args.Length < 5)
  20. return;
  21. if (!int.TryParse(args[0], out var x)
  22. || !int.TryParse(args[1], out var y)
  23. || !NetEntity.TryParse(args[2], out var netEnt)
  24. || !_entManager.TryGetEntity(netEnt, out var euid)
  25. || !(AtmosCommandUtils.TryParseGasID(args[3], out var gasId))
  26. || !float.TryParse(args[4], out var moles))
  27. {
  28. return;
  29. }
  30. if (!_entManager.HasComponent<MapGridComponent>(euid))
  31. {
  32. shell.WriteError($"Euid '{euid}' does not exist or is not a grid.");
  33. return;
  34. }
  35. var atmosphereSystem = _entManager.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
  36. var indices = new Vector2i(x, y);
  37. var tile = atmosphereSystem.GetTileMixture(euid, null, indices, true);
  38. if (tile == null)
  39. {
  40. shell.WriteLine("Invalid coordinates or tile.");
  41. return;
  42. }
  43. tile.AdjustMoles(gasId, moles);
  44. }
  45. }
  46. }