SpawnEntityListCommand.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Content.Shared.EntityList;
  4. using Robust.Shared.Console;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Server.EntityList
  7. {
  8. [AdminCommand(AdminFlags.Spawn)]
  9. public sealed class SpawnEntityListCommand : IConsoleCommand
  10. {
  11. public string Command => "spawnentitylist";
  12. public string Description => "Spawns a list of entities around you";
  13. public string Help => $"Usage: {Command} <entityListPrototypeId>";
  14. public void Execute(IConsoleShell shell, string argStr, string[] args)
  15. {
  16. if (args.Length != 1)
  17. {
  18. shell.WriteError($"Invalid arguments.\n{Help}");
  19. return;
  20. }
  21. if (shell.Player is not { } player)
  22. {
  23. shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
  24. return;
  25. }
  26. if (player.AttachedEntity is not {} attached)
  27. {
  28. shell.WriteError(Loc.GetString("shell-only-players-can-run-this-command"));
  29. return;
  30. }
  31. var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
  32. if (!prototypeManager.TryIndex(args[0], out EntityListPrototype? prototype))
  33. {
  34. shell.WriteError($"No {nameof(EntityListPrototype)} found with id {args[0]}");
  35. return;
  36. }
  37. var entityManager = IoCManager.Resolve<IEntityManager>();
  38. var i = 0;
  39. foreach (var entity in prototype.Entities(prototypeManager))
  40. {
  41. entityManager.SpawnEntity(entity.ID, entityManager.GetComponent<TransformComponent>(attached).Coordinates);
  42. i++;
  43. }
  44. shell.WriteLine($"Spawned {i} entities.");
  45. }
  46. }
  47. }