NPC refactor (#10122)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
46
Content.Server/NPC/Commands/AddNPCCommand.cs
Normal file
46
Content.Server/NPC/Commands/AddNPCCommand.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.NPC.HTN;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.NPC.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public sealed class AddNPCCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
public string Command => "addnpc";
|
||||
public string Description => "Add a HTN NPC component with a given root task";
|
||||
public string Help => "Usage: addnpc <entityId> <rootTask>"
|
||||
+ "\n entityID: Uid of entity to add the AiControllerComponent to. Open its VV menu to find this."
|
||||
+ "\n rootTask: Name of a behaviorset to add to the component on initialize.";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.WriteError("Wrong number of args.");
|
||||
return;
|
||||
}
|
||||
|
||||
var entId = new EntityUid(int.Parse(args[0]));
|
||||
|
||||
if (!_entities.EntityExists(entId))
|
||||
{
|
||||
shell.WriteError($"Unable to find entity with uid {entId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_entities.HasComponent<HTNComponent>(entId))
|
||||
{
|
||||
shell.WriteError("Entity already has an NPC component.");
|
||||
return;
|
||||
}
|
||||
|
||||
var comp = _entities.AddComponent<HTNComponent>(entId);
|
||||
comp.RootTask = args[1];
|
||||
shell.WriteLine("AI component added.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user