Updates command AutoPilotLocal to accept a 1 vector or 3 args of location

This commit is contained in:
Madpeter 2020-05-01 23:23:34 +01:00
parent 851c99385c
commit d98272d484

View file

@ -2,47 +2,90 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using OpenMetaverse; using OpenMetaverse;
using BetterSecondBotShared.Static;
namespace BSB.Commands.Movement 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[] ArgTypes { get { return new[] { "Mixed","Number","number" }; } }
public override string[] ArgHints { get { return new[] { "0 to 255", "0 to 255","0 to 5000" }; } } 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"; } } public override string Helpfile { get { return "Make the bot auto pilot to X,Y,Z<br/>Example AutoPilotLocal|||<124,55,22>"; } }
public override bool CallFunction(string[] args) public override bool CallFunction(string[] args)
{ {
if (base.CallFunction(args) == true) 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); bot.GetClient.Self.AutoPilotLocal(x, y, z);
return true; return true;
} }
else else
{ {
return Failed("x,y,z cords are out of spec"); return Failed("Z cord is out of range");
} }
} }
else else
{ {
return Failed("arg 3 \"z\" is not vaild)"); return Failed("Y cord is out of range");
} }
} }
else else
{ {
return Failed("arg 2 \"y\" is not vaild)"); return Failed("X cord is out of range");
} }
} }
else else
{ {
return Failed("arg 1 \"x\" is not vaild)"); return Failed("Unknown issue");
} }
} }
return false; return false;