From d98272d4842618cf203a697b229286f70e0b9344 Mon Sep 17 00:00:00 2001 From: Madpeter Date: Fri, 1 May 2020 23:23:34 +0100 Subject: [PATCH] Updates command AutoPilotLocal to accept a 1 vector or 3 args of location --- Core/Commands/Movement/AutoPilotLocal.cs | 69 +++++++++++++++++++----- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/Core/Commands/Movement/AutoPilotLocal.cs b/Core/Commands/Movement/AutoPilotLocal.cs index c0b70a2..9f57924 100644 --- a/Core/Commands/Movement/AutoPilotLocal.cs +++ b/Core/Commands/Movement/AutoPilotLocal.cs @@ -2,47 +2,90 @@ using System.Collections.Generic; using System.Text; using OpenMetaverse; +using BetterSecondBotShared.Static; namespace BSB.Commands.Movement { - public class AutoPilotLocal : CoreCommand_3arg + public class AutoPilotLocal : CoreCommand_1arg { - public override string[] ArgTypes { get { return new[] { "Number","Number","number" }; } } - public override string[] ArgHints { get { return new[] { "0 to 255", "0 to 255","0 to 5000" }; } } - public override string Helpfile { get { return "Make the bot auto pilot to X,Y,Z"; } } + public override string[] ArgTypes { get { return new[] { "Mixed","Number","number" }; } } + public override string[] ArgHints { get { return new[] { "Vector [OR] 0 to 255", "0 to 255","0 to 5000" }; } } + public override string Helpfile { get { return "Make the bot auto pilot to X,Y,Z
Example AutoPilotLocal|||<124,55,22>"; } } public override bool CallFunction(string[] args) { if (base.CallFunction(args) == true) { - if (int.TryParse(args[0], out int x) == true) + bool ok = false; + int x = 0; + int y = 0; + float z = 0; + if (args.Length == 3) { - if (int.TryParse(args[1], out int y) == true) + if (int.TryParse(args[0], out x) == true) { - if (float.TryParse(args[2], out float z) == true) + if (int.TryParse(args[1], out y) == true) { - if ((x >= 0) && (x <= 255) && (y >= 0) && (y <= 255) && (z >= 0) && (z <= 5000)) + if (float.TryParse(args[2], out z) == true) + { + ok = true; + } + else + { + return Failed("Unable to process Z cord"); + } + } + else + { + return Failed("Unable to process Y cord"); + } + } + else + { + return Failed("Unable to process X cord"); + } + } + else if (args.Length == 1) + { + if (Vector3.TryParse(args[0], out Vector3 pos) == true) + { + x = (int)Math.Round(pos.X); + y = (int)Math.Round(pos.Y); + z = pos.Z; + ok = true; + } + else + { + return Failed("Unable to process vector"); + } + } + if (ok == true) + { + if (helpers.inrange(x, 0, 255) == true) + { + if (helpers.inrange(y, 0, 255) == true) + { + if (helpers.inrange(z, 0, 5000) == true) { - bot.GetClient.Self.Chat("Attempting to walk to " + x.ToString() + " " + y.ToString() + " " + z.ToString() + "",0,ChatType.Normal); bot.GetClient.Self.AutoPilotLocal(x, y, z); return true; } else { - return Failed("x,y,z cords are out of spec"); + return Failed("Z cord is out of range"); } } else { - return Failed("arg 3 \"z\" is not vaild)"); + return Failed("Y cord is out of range"); } } else { - return Failed("arg 2 \"y\" is not vaild)"); + return Failed("X cord is out of range"); } } else { - return Failed("arg 1 \"x\" is not vaild)"); + return Failed("Unknown issue"); } } return false;