From 5f030cdf93212fd139ec2630c2336f1baeb8071c Mon Sep 17 00:00:00 2001 From: moneyl <8206401+Moneyl@users.noreply.github.com> Date: Sun, 16 Feb 2020 18:21:15 -0500 Subject: [PATCH] Improve addai error handling and help message (#708) * Improve addai error handling and help message Fix client crash from giving addai an invalid processorId argument and improved it's help message to describe each parameter. * Only IoC resolve when addai is run Makes the code simpler. No need to cache it since it's going to be run so infrequently. --- .../GameObjects/EntitySystems/AiSystem.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Content.Server/GameObjects/EntitySystems/AiSystem.cs b/Content.Server/GameObjects/EntitySystems/AiSystem.cs index 3ccf140d3e..61ad3d759f 100644 --- a/Content.Server/GameObjects/EntitySystems/AiSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AiSystem.cs @@ -79,11 +79,17 @@ namespace Content.Server.GameObjects.EntitySystems throw new ArgumentException($"Processor type {name} could not be found.", nameof(name)); } + public bool ProcessorTypeExists(string name) => _processorTypes.ContainsKey(name); + + private class AddAiCommand : IClientCommand { public string Command => "addai"; public string Description => "Add an ai component with a given processor to an entity."; - public string Help => "addai "; + public string Help => "Usage: addai " + + "\n processorId: Class that inherits AiLogicProcessor and has an AiLogicProcessor attribute." + + "\n entityID: Uid of entity to add the AiControllerComponent to. Open its VV menu to find this."; + public void Execute(IConsoleShell shell, IPlayerSession player, string[] args) { if(args.Length != 2) @@ -95,7 +101,13 @@ namespace Content.Server.GameObjects.EntitySystems var processorId = args[0]; var entId = new EntityUid(int.Parse(args[1])); var ent = IoCManager.Resolve().GetEntity(entId); + var aiSystem = IoCManager.Resolve().GetEntitySystem(); + if (!aiSystem.ProcessorTypeExists(processorId)) + { + shell.SendText(player, "Invalid processor type. Processor must inherit AiLogicProcessor and have an AiLogicProcessor attribute."); + return; + } if (ent.HasComponent()) { shell.SendText(player, "Entity already has an AI component.");