PlanetCommand.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Linq;
  2. using Content.Server.Administration;
  3. using Content.Server.Atmos;
  4. using Content.Server.Atmos.Components;
  5. using Content.Server.Atmos.EntitySystems;
  6. using Content.Server.Parallax;
  7. using Content.Shared.Administration;
  8. using Content.Shared.Atmos;
  9. using Content.Shared.Gravity;
  10. using Content.Shared.Movement.Components;
  11. using Content.Shared.Parallax.Biomes;
  12. using Robust.Shared.Audio;
  13. using Robust.Shared.Console;
  14. using Robust.Shared.Map;
  15. using Robust.Shared.Map.Components;
  16. using Robust.Shared.Prototypes;
  17. using Robust.Shared.Random;
  18. namespace Content.Server.Maps;
  19. /// <summary>
  20. /// Converts the supplied map into a "planet" with defaults.
  21. /// </summary>
  22. [AdminCommand(AdminFlags.Mapping)]
  23. public sealed class PlanetCommand : IConsoleCommand
  24. {
  25. [Dependency] private readonly IEntityManager _entManager = default!;
  26. [Dependency] private readonly IMapManager _mapManager = default!;
  27. [Dependency] private readonly IPrototypeManager _protoManager = default!;
  28. public string Command => "planet";
  29. public string Description => Loc.GetString("cmd-planet-desc");
  30. public string Help => Loc.GetString("cmd-planet-help", ("command", Command));
  31. public void Execute(IConsoleShell shell, string argStr, string[] args)
  32. {
  33. if (args.Length != 2)
  34. {
  35. shell.WriteError(Loc.GetString($"cmd-planet-args"));
  36. return;
  37. }
  38. if (!int.TryParse(args[0], out var mapInt))
  39. {
  40. shell.WriteError(Loc.GetString($"cmd-planet-map", ("map", mapInt)));
  41. return;
  42. }
  43. var mapId = new MapId(mapInt);
  44. if (!_mapManager.MapExists(mapId))
  45. {
  46. shell.WriteError(Loc.GetString($"cmd-planet-map", ("map", mapId)));
  47. return;
  48. }
  49. if (!_protoManager.TryIndex<BiomeTemplatePrototype>(args[1], out var biomeTemplate))
  50. {
  51. shell.WriteError(Loc.GetString("cmd-planet-map-prototype", ("prototype", args[1])));
  52. return;
  53. }
  54. var biomeSystem = _entManager.System<BiomeSystem>();
  55. var mapUid = _mapManager.GetMapEntityId(mapId);
  56. biomeSystem.EnsurePlanet(mapUid, biomeTemplate);
  57. shell.WriteLine(Loc.GetString("cmd-planet-success", ("mapId", mapId)));
  58. }
  59. public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
  60. {
  61. if (args.Length == 1)
  62. return CompletionResult.FromHintOptions(CompletionHelper.MapIds(_entManager), "Map Id");
  63. if (args.Length == 2)
  64. {
  65. var options = _protoManager.EnumeratePrototypes<BiomeTemplatePrototype>()
  66. .Select(o => new CompletionOption(o.ID, "Biome"));
  67. return CompletionResult.FromOptions(options);
  68. }
  69. return CompletionResult.Empty;
  70. }
  71. }