2021-03-28 12:59:58 +02:00
|
|
|
|
using Content.Server.Administration;
|
|
|
|
|
|
using Content.Shared.Administration;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.EntityList;
|
2021-03-28 12:59:58 +02:00
|
|
|
|
using Robust.Shared.Console;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.EntityList
|
2021-03-28 12:59:58 +02:00
|
|
|
|
{
|
|
|
|
|
|
[AdminCommand(AdminFlags.Spawn)]
|
2025-06-18 20:03:28 -04:00
|
|
|
|
public sealed class SpawnEntityListCommand : LocalizedEntityCommands
|
2021-03-28 12:59:58 +02:00
|
|
|
|
{
|
2025-06-18 20:03:28 -04:00
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2021-03-28 12:59:58 +02:00
|
|
|
|
|
2025-06-18 20:03:28 -04:00
|
|
|
|
public override string Command => "spawnentitylist";
|
|
|
|
|
|
|
|
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
2021-03-28 12:59:58 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
|
{
|
2025-06-18 20:03:28 -04:00
|
|
|
|
shell.WriteError(Loc.GetString($"shell-need-exactly-one-argument"));
|
2021-03-28 12:59:58 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-28 09:59:53 +11:00
|
|
|
|
if (shell.Player is not { } player)
|
2021-03-28 12:59:58 +02:00
|
|
|
|
{
|
2024-08-11 09:46:57 +00:00
|
|
|
|
shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
|
2021-03-28 12:59:58 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-06 15:34:46 +01:00
|
|
|
|
if (player.AttachedEntity is not {} attached)
|
2021-03-28 12:59:58 +02:00
|
|
|
|
{
|
2024-08-11 09:46:57 +00:00
|
|
|
|
shell.WriteError(Loc.GetString("shell-only-players-can-run-this-command"));
|
2021-03-28 12:59:58 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-18 20:03:28 -04:00
|
|
|
|
if (!_prototypeManager.TryIndex(args[0], out EntityListPrototype? prototype))
|
2021-03-28 12:59:58 +02:00
|
|
|
|
{
|
2025-06-18 20:03:28 -04:00
|
|
|
|
shell.WriteError(Loc.GetString($"cmd-spawnentitylist-failed",
|
|
|
|
|
|
("prototype", nameof(EntityListPrototype)),
|
|
|
|
|
|
("id", args[0])));
|
2021-03-28 12:59:58 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
2025-07-09 20:06:51 -07:00
|
|
|
|
foreach (var entity in prototype.GetEntities(_prototypeManager))
|
2021-03-28 12:59:58 +02:00
|
|
|
|
{
|
2025-06-18 20:03:28 -04:00
|
|
|
|
EntityManager.SpawnEntity(entity.ID, EntityManager.GetComponent<TransformComponent>(attached).Coordinates);
|
2021-03-28 12:59:58 +02:00
|
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-18 20:03:28 -04:00
|
|
|
|
shell.WriteLine(Loc.GetString($"cmd-spawnentitylist-success", ("count", i)));
|
2021-03-28 12:59:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|