public static bool Parse(Player p, PlayerBot bot, string ai) { string path = "bots/" + ai; if (!File.Exists(path)) { p.Message("Could not find specified AI."); return(false); } string[] instructions = File.ReadAllLines(path); if (instructions.Length == 0) { p.Message("No instructions in the AI."); return(false); } bot.AIName = ai; bot.Instructions.Clear(); bot.cur = 0; bot.countdown = 0; bot.movementSpeed = 3; foreach (string line in instructions) { if (line.IsCommentLine()) { continue; } string[] args = line.SplitSpaces(); try { BotInstruction ins = BotInstruction.Find(args[0]); if (ins == null) { continue; } InstructionData data = ins.Parse(args); data.Name = args[0]; bot.Instructions.Add(data); } catch { p.Message("AI file corrupt."); return(false); } } return(true); }
public static bool Parse(Player p, PlayerBot bot, string file) { if (!File.Exists(file)) { Player.Message(p, "Could not find specified AI."); return(false); } string[] instructions = File.ReadAllLines(file); if (instructions.Length == 0 || !instructions[0].CaselessEq("#Version 2")) { Player.Message(p, "Invalid file version. Remake"); return(false); } bot.Instructions.Clear(); bot.cur = 0; bot.countdown = 0; bot.movementSpeed = 3; foreach (string line in instructions) { if (line.Length == 0 || line[0] == '#') { continue; } string[] args = line.SplitSpaces(); try { BotInstruction ins = BotInstruction.Find(args[0]); if (ins == null) { continue; } InstructionData data = ins.Parse(args); data.Name = args[0]; bot.Instructions.Add(data); } catch { Player.Message(p, "AI file corrupt."); return(false); } } return(true); }