public UnovaPokemon[] GetBattleTeam() { //TODO: unsafe, add error checking var cmd1 = Web.Xajax(Urls.UrlMap + "?map=1&zone=1", "getBattleTeam", "", true).ToArray(); var cmd = cmd1.First(a => a.Command == "as"); string html = cmd.Value.Text; //extract from html return(UnovaPokemon.FromHtml(html)); }
internal static UnovaPokemon[] FromHtml(string html) { //split all by closing li string[] split = html.Split(new [] { "</li>" }, StringSplitOptions.RemoveEmptyEntries); UnovaPokemon[] arr = new UnovaPokemon[split.Length - 1]; //skip last string, which isn't needed for (int i = 0; i < split.Length - 1; i++) { string str = split[i]; var up = new UnovaPokemon(); //get name up.Name = RegexName.Match(str).Groups[1].Value; //get status Match m = RegexStatus.Match(str); up.UniqueId = long.Parse(m.Groups["uid"].Value); up.Experience = int.Parse(m.Groups["exp"].Value); up.Level = int.Parse(m.Groups["lvl"].Value); up.HpCurrent = int.Parse(m.Groups["hpCur"].Value); up.HpMax = int.Parse(m.Groups["hpMax"].Value); up.Status = m.Groups["status"].Value; //get moves MatchCollection matches = RegexMoves.Matches(str); for (int j = 0; j < matches.Count; j++) { string name = matches[j].Groups["name"].Value; int pp = int.Parse(matches[j].Groups["ppCur"].Value); up.MovesPP[name] = pp; } arr[i] = up; } return(arr); }