/// <summary> /// Parses the details from the village match /// </summary> private void HandleMatch(Dictionary <int, Village> ownVillages, Match match, DateTime serverTime) { int villageId; if (CommonParsers.ParseInt(match.Groups["id"].Value, out villageId)) { Village vil = null; if (ownVillages.ContainsKey(villageId)) { vil = ownVillages[villageId]; } else { // newly conquered village: change owner foreach (Village village in World.Default.Villages.Values) { if (village.Id == villageId) { vil = village; vil.Player = World.Default.You; } } } if (vil != null) { CurrentSituation situation = vil.Reports.CurrentSituation; int tempInt; if (CommonParsers.ParseInt(match.Groups["points"].Value, out tempInt)) { vil.Points = tempInt; } string pattern = string.Format(@"(\<img src="".*\.png(\?1)?"" title=""({0}|{1}|{2})"" alt="""" /\>(\<span class=""warn""\>)?(?<res>(\d*<span class=""grey""\>\.\</span\>)?\d*)(\</span\>)?\s*)", TWWords.Wood, TWWords.Clay, TWWords.Iron); var res = new Regex(pattern); MatchCollection resMatches = res.Matches(match.Groups["res"].Value); if (resMatches.Count == 3) { if (CommonParsers.ParseInt(resMatches[0].Groups["res"].Value, out tempInt)) { situation.Resources.Wood = tempInt; } if (CommonParsers.ParseInt(resMatches[1].Groups["res"].Value, out tempInt)) { situation.Resources.Clay = tempInt; } if (CommonParsers.ParseInt(resMatches[2].Groups["res"].Value, out tempInt)) { situation.Resources.Iron = tempInt; } situation.ResourcesDate = serverTime; } vil.Reports.Save(); } } }
/// <summary> /// Parses the details from the village match /// </summary> private void HandleMatch(Dictionary <int, Village> ownVillages, Match match, DateTime serverTime) { int villageId; if (CommonParsers.ParseInt(match.Groups["id"].Value, out villageId)) { Village vil = ownVillages[villageId]; CurrentSituation situation = vil.Reports.CurrentSituation; int tempInt; if (CommonParsers.ParseInt(match.Groups["points"].Value, out tempInt)) { vil.Points = tempInt; } // groups: warehouse, population / farm //System.Diagnostics.Debug.Print(vil.ToString()); string pattern = string.Format(@"\<img src="".*\.png(\?1)?"" title=""({0}|{1}|{2})"" alt="""" /\>(?<res>(\d*<span class=""grey""\>\.\</span\>)?\d*)\s*", TWWords.Wood, TWWords.Clay, TWWords.Iron); var res = new Regex(pattern); MatchCollection resMatches = res.Matches(match.Groups["res"].Value); if (resMatches.Count == 3) { if (CommonParsers.ParseInt(resMatches[0].Groups["res"].Value, out tempInt)) { situation.Resources.Wood = tempInt; } if (CommonParsers.ParseInt(resMatches[1].Groups["res"].Value, out tempInt)) { situation.Resources.Clay = tempInt; } if (CommonParsers.ParseInt(resMatches[2].Groups["res"].Value, out tempInt)) { situation.Resources.Iron = tempInt; } situation.ResourcesDate = serverTime; } vil.Reports.Save(); } }