ScriptFile.Append is no longer hardcoded.

This commit is contained in:
UnknownShadow200 2016-09-09 23:36:05 +10:00
parent 89f08dad70
commit 7b6be7923b
6 changed files with 48 additions and 51 deletions

View File

@ -48,6 +48,12 @@ namespace MCGalaxy.Bots {
data.Metadata = meta;
return data;
}
public override void Output(Player p, string[] args, StreamWriter w) {
string time = args.Length > 3 ? args[3] : "10";
string speed = args.Length > 4 ? args[4] : "2";
w.WriteLine(Name + " " + short.Parse(time) + " " + byte.Parse(speed));
}
}
/// <summary> Causes the bot to nod down up and down for a certain interval. </summary>

View File

@ -60,7 +60,6 @@ namespace MCGalaxy.Bots {
public struct InstructionData {
public string Name;
public int seconds, rotspeed;
public object Metadata;
}
}

View File

@ -16,6 +16,7 @@
permissions and limitations under the Licenses.
*/
using System;
using System.IO;
namespace MCGalaxy.Bots {
@ -44,6 +45,10 @@ namespace MCGalaxy.Bots {
return data;
}
public override void Output(Player p, string[] args, StreamWriter w) {
w.WriteLine(Name + " " + p.pos[0] + " " + p.pos[1] + " " + p.pos[2] + " " + p.rot[0] + " " + p.rot[1]);
}
protected struct Coords {
public ushort X, Y, Z;
public byte RotX, RotY;
@ -96,5 +101,10 @@ namespace MCGalaxy.Bots {
data.Metadata = short.Parse(args[1]);
return data;
}
public override void Output(Player p, string[] args, StreamWriter w) {
string time = args.Length > 3 ? args[3] : "10";
w.WriteLine(Name + " " + short.Parse(time));
}
}
}

View File

@ -56,6 +56,15 @@ namespace MCGalaxy.Bots {
data.Metadata = args[1];
return data;
}
public override void Output(Player p, string[] args, StreamWriter w) {
string script = args.Length > 3 ? args[3] : "";
if (script == "") {
Player.Message(p, "LinkScript requires a script name as a parameter");
} else {
w.WriteLine(Name + " " + script);
}
}
}
/// <summary> Causes the bot to wait/do nothing for a certain interval. </summary>
@ -78,5 +87,10 @@ namespace MCGalaxy.Bots {
data.Metadata = short.Parse(args[1]);
return data;
}
public override void Output(Player p, string[] args, StreamWriter w) {
string time = args.Length > 3 ? args[3] : "10";
w.WriteLine(Name + " " + short.Parse(time));
}
}
}

View File

@ -48,37 +48,16 @@ namespace MCGalaxy.Bots {
return true;
}
public static void Append(Player p, string ai, string action = "",
string extra = "10", string more = "2") {
public static void Append(Player p, string ai, string action, string[] args) {
using (StreamWriter w = new StreamWriter("bots/" + ai, true)) {
switch (action.ToLower()) {
case "":
case "walk":
w.WriteLine("walk " + p.pos[0] + " " + p.pos[1] + " " + p.pos[2] + " " + p.rot[0] + " " + p.rot[1]);
break;
case "teleport":
case "tp":
w.WriteLine("teleport " + p.pos[0] + " " + p.pos[1] + " " + p.pos[2] + " " + p.rot[0] + " " + p.rot[1]);
break;
case "wait":
w.WriteLine("wait " + int.Parse(extra)); break;
case "nod":
w.WriteLine("nod " + int.Parse(extra) + " " + int.Parse(more)); break;
case "speed":
w.WriteLine("speed " + int.Parse(extra)); break;
case "remove":
w.WriteLine("remove"); break;
case "reset":
w.WriteLine("reset"); break;
case "spin":
w.WriteLine("spin " + int.Parse(extra) + " " + int.Parse(more)); break;
case "linkscript":
if (extra != "10") w.WriteLine("linkscript " + extra); else Player.Message(p, "Linkscript requires a script as a parameter");
break;
case "jump":
w.WriteLine("jump"); break;
default:
Player.Message(p, "Could not find \"" + action + "\""); break;
if (action == "") action = "walk";
if (action.CaselessEq("tp")) action = "teleport";
BotInstruction ins = BotInstruction.Find(action);
if (ins == null) {
Player.Message(p, "Could not find instruction \"" + action + "\"");
} else {
ins.Output(p, args, w);
}
}
}

View File

@ -40,21 +40,10 @@ namespace MCGalaxy.Commands
if (ai == "hunt" || ai == "kill") { Player.Message(p, "Reserved for special AI."); return; }
switch (args[0].ToLower()) {
case "add":
if (args.Length == 2) HandleAdd(p, ai);
else if (args.Length == 3) HandleAdd(p, ai, args[2]);
else if (args.Length == 4) HandleAdd(p, ai, args[2], args[3]);
else HandleAdd(p, ai, args[2], args[3], args[4]);
break;
case "del":
HandleDelete(p, ai, args);
break;
case "info":
HandleInfo(p, ai);
break;
default:
Help(p);
return;
case "add": HandleAdd(p, ai, args); break;
case "del": HandleDelete(p, ai, args); break;
case "info": HandleInfo(p, ai); break;
default: Help(p); break;
}
}
@ -68,7 +57,7 @@ namespace MCGalaxy.Commands
for (int attempt = 0; attempt < 10; attempt++) {
try {
if (args.Length == 2) {
DeleteAI(p, ai); return;
DeleteAI(p, ai, attempt); return;
} else if (args[2].ToLower() == "last") {
DeleteLast(p, ai); return;
} else {
@ -99,7 +88,7 @@ namespace MCGalaxy.Commands
Player.Message(p, "Deleted the last instruction from " + ai);
}
void HandleAdd(Player p, string ai, string action = "", string extra = "10", string more = "2") {
void HandleAdd(Player p, string ai, string[] args) {
string[] allLines;
try { allLines = File.ReadAllLines("bots/" + ai); }
catch { allLines = new string[1]; }
@ -122,8 +111,9 @@ namespace MCGalaxy.Commands
}
try {
if (action != "reverse") {
ScriptFile.Append(p, ai, action, extra, more); return;
string action = args.Length > 2 ? args[2] : "";
if (action != "reverse") {
ScriptFile.Append(p, ai, action, args); return;
}
using (StreamWriter w = new StreamWriter("bots/" + ai, true)) {
@ -131,7 +121,6 @@ namespace MCGalaxy.Commands
if (allLines[i][0] != '#' && allLines[i] != "")
w.WriteLine(allLines[i]);
}
return;
}
} catch {
Player.Message(p, "Invalid parameter");