2021-07-17 02:37:09 +02:00
|
|
|
|
using Content.Server.Administration;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Server.AI.Components;
|
2021-02-20 17:37:17 +11:00
|
|
|
|
using Content.Server.AI.Utility;
|
|
|
|
|
|
using Content.Server.AI.Utility.AiLogic;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
using Content.Shared.Administration;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Movement.Components;
|
2021-02-01 16:49:43 -08:00
|
|
|
|
using Robust.Shared.Console;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.AI.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
[AdminCommand(AdminFlags.Fun)]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class AddAiCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
|
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
|
public string Command => "addai";
|
|
|
|
|
|
public string Description => "Add an ai component with a given processor to an entity.";
|
2021-02-20 17:37:17 +11:00
|
|
|
|
public string Help => "Usage: addai <entityId> <behaviorSet1> <behaviorSet2>..."
|
|
|
|
|
|
+ "\n entityID: Uid of entity to add the AiControllerComponent to. Open its VV menu to find this."
|
|
|
|
|
|
+ "\n behaviorSet: Name of a behaviorset to add to the component on initialize.";
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-02-20 17:37:17 +11:00
|
|
|
|
if(args.Length < 1)
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("Wrong number of args.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-20 17:37:17 +11:00
|
|
|
|
var entId = new EntityUid(int.Parse(args[0]));
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (!_entities.EntityExists(entId))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-02-20 17:37:17 +11:00
|
|
|
|
shell.WriteLine($"Unable to find entity with uid {entId}");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-02-20 17:37:17 +11:00
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (_entities.HasComponent<AiControllerComponent>(entId))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("Entity already has an AI component.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-20 17:37:17 +11:00
|
|
|
|
// TODO: IMover refffaaccctttooorrr
|
2021-12-05 18:09:01 +01:00
|
|
|
|
if (_entities.HasComponent<IMoverComponent>(entId))
|
2020-12-03 03:40:47 +01:00
|
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
|
_entities.RemoveComponent<IMoverComponent>(entId);
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
var comp = _entities.AddComponent<UtilityAi>(entId);
|
2021-02-20 17:37:17 +11:00
|
|
|
|
var behaviorManager = IoCManager.Resolve<INpcBehaviorManager>();
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 1; i < args.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var bSet = args[i];
|
|
|
|
|
|
behaviorManager.AddBehaviorSet(comp, bSet, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
behaviorManager.RebuildActions(comp);
|
2021-02-01 16:49:43 -08:00
|
|
|
|
shell.WriteLine("AI component added.");
|
2020-12-03 03:40:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|