private static bool parseRecipe(string rec, List <Recipe> newlist) { // 1 2 3 4 Regex regexp = new Regex(@"{([^}]+)}{}{([^@]+)@([^@]+)@([^@]*)@([^@]*)@([^@]*)@([^@]*)@([^@]+)@([^}]*)}"); Match match = regexp.Match(rec); if (!match.Success) { return(false); } // 1 pid // 2 name // 3 description // 4 view // 5 craft // 6 items // 7 tools // 8 output // 9 exp and script Recipe newr = new Recipe(); newr.number = uint.Parse(match.Groups[1].Value); newr.name = match.Groups[2].Value; newr.desc = match.Groups[3].Value; Regex rx = new Regex(@"([A-Z0-9_]+) ([0-9]+)([&|]?)"); MatchCollection ms = rx.Matches(match.Groups[4].Value); foreach (Match m in ms) { newr.AddView(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); } ms = rx.Matches(match.Groups[5].Value); foreach (Match m in ms) { newr.AddCraft(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); } ms = rx.Matches(match.Groups[6].Value); foreach (Match m in ms) { newr.AddItem(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); } ms = rx.Matches(match.Groups[7].Value); foreach (Match m in ms) { newr.AddTool(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); } ms = rx.Matches(match.Groups[8].Value); foreach (Match m in ms) { newr.AddOutput(m.Groups[1].Value, uint.Parse(m.Groups[2].Value)); } string[] last = match.Groups[9].Value.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (last.Length < 2) { return(false); } if (last[0] != "exp") { return(false); } newr.exp = uint.Parse(last[1]); if (last.Length % 2 != 0) { return(false); } if (last.Length > 2) { if (last[2] != "script") { return(false); } newr.script = last[3]; } else { newr.script = ""; } newlist.Add(newr); return(true); }
private static bool parseRecipe(string rec, List<Recipe> newlist) { // 1 2 3 4 Regex regexp = new Regex(@"{([^}]+)}{}{([^@]+)@([^@]+)@([^@]*)@([^@]*)@([^@]*)@([^@]*)@([^@]+)@([^}]*)}"); Match match = regexp.Match(rec); if(!match.Success) return false; // 1 pid // 2 name // 3 description // 4 view // 5 craft // 6 items // 7 tools // 8 output // 9 exp and script Recipe newr = new Recipe(); newr.number = uint.Parse(match.Groups[1].Value); newr.name = match.Groups[2].Value; newr.desc = match.Groups[3].Value; Regex rx = new Regex(@"([A-Z0-9_]+) ([0-9]+)([&|]?)"); MatchCollection ms = rx.Matches(match.Groups[4].Value); foreach(Match m in ms) newr.AddView(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); ms = rx.Matches(match.Groups[5].Value); foreach(Match m in ms) newr.AddCraft(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); ms = rx.Matches(match.Groups[6].Value); foreach(Match m in ms) newr.AddItem(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); ms = rx.Matches(match.Groups[7].Value); foreach(Match m in ms) newr.AddTool(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|"); ms = rx.Matches(match.Groups[8].Value); foreach(Match m in ms) newr.AddOutput(m.Groups[1].Value, uint.Parse(m.Groups[2].Value)); string[] last = match.Groups[9].Value.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if(last.Length < 2) return false; if(last[0] != "exp") return false; newr.exp = uint.Parse(last[1]); if(last.Length % 2 != 0) return false; if(last.Length > 2) { if(last[2] != "script") return false; newr.script = last[3]; } else newr.script = ""; newlist.Add(newr); return true; }