public void Merchants35() { string pageSource = Misc.ReadContent("..\\..\\..\\Samples\\TestFiles\\build.php-newdid=73229-gid=17"); HtmlParser htmlParser = new HtmlParser(pageSource); Marketplace marketplace = new Marketplace(); const int villageId = 73229; marketplace.VillageId = villageId; htmlParser.ParseMarketplace(marketplace); Assert.AreEqual(0, marketplace.AvailableMerchants); Assert.AreEqual(20, marketplace.TotalMerchants); Assert.AreEqual(2000, marketplace.TotalCarry); Village village = new Village(villageId, "some name"); htmlParser.ParseVillageProduction(village); Assert.AreEqual(3736, village.WoodAvailable); Assert.AreEqual(1000, village.WoodProduction); Assert.AreEqual(3736, village.ClayAvailable); Assert.AreEqual(1000, village.ClayProduction); Assert.AreEqual(5036, village.IronAvailable); Assert.AreEqual(1000, village.IronProduction); Assert.AreEqual(15804, village.CropAvailable); Assert.AreEqual(442, village.CropProduction); Assert.AreEqual(160000, village.CapacityWarehouse); Assert.AreEqual(160000, village.CapacityGranary); }
private bool EnoughResources(SendResourcesParameters parameters) { string url = String.Format(CultureInfo.InvariantCulture, "{0}?newdid={1}", serverInfo.Dorf1Url, parameters.SourceVillageId); string pageSource = Http.SendData(url, null, serverInfo.CookieContainer, serverInfo.CookieCollection); HtmlParser htmlParser = new HtmlParser(pageSource); Village village = new Village(parameters.SourceVillageId, "noName"); htmlParser.ParseVillageProduction(village); if (village.WoodAvailable < parameters.WoodAmount || village.ClayAvailable < parameters.ClayAmount || village.IronAvailable < parameters.IronAmount || village.CropAvailable < parameters.CropAmount) { return false; } return true; }
public void ParseVillages(ServerInfo serverInfo) { //<a href="?newdid=83117">01</a> //<a href="?newdid=73913">01</a> 3.5 //<a href=\"\?newdid=([0-9]{0,7})\"\s?(accesskey=\"\w\")?>([\w\W\d\D\s\S]{0,50})<\/a> MatchCollection villagesCollection = Regex.Matches(pageSource, @"<a href="".newdid=([0-9]{0,7})""\s?(accesskey=""\w"")?>([\w\W\d\D\s\S]{0,50})<.a>"); int villageCount = villagesCollection.Count; //Console.WriteLine("villageCount=" + villageCount); for (int i = 0; i < villageCount; i++) { //Console.WriteLine(villagesCollection[i].Groups[0].Value); //Console.WriteLine(villagesCollection[i].Groups[1].Value); //Console.WriteLine(villagesCollection[i].Groups[3].Value); //102706" class="active_vl int villageId = Int32.Parse(Misc.GetOnlyNumbers(villagesCollection[i].Groups[1].Value)); string villageName = villagesCollection[i].Groups[3].Value.Trim(); Village village = new Village(villageId, villageName); serverInfo.Villages.Add(village); } if (villageCount < 2) { const string regVillageName = @"<div class=""dname""><h1>(.*)</h1></div>"; villagesCollection = Regex.Matches(pageSource, regVillageName); Village village = new Village(0, villagesCollection[0].Groups[1].Value.Trim()); serverInfo.Villages.Add(village); } }
public void ParseVillageProduction(Village village) { /* <div id="res"> <table> <tr> <td><img src="img/x.gif" class="r1" alt="Les" title="Les" /></td> <td id="l4" title="22">159274/400000</td> <td><img src="img/x.gif" class="r2" alt="Glina" title="Glina" /></td> <td id="l3" title="22">161168/400000</td> <td><img src="img/x.gif" class="r3" alt="Železo" title="Železo" /></td> <td id="l2" title="22">166435/400000</td> <td><img src="img/x.gif" class="r4" alt="Žito" title="Žito" /></td> <td id="l1" title="5955">53916/320000</td> </tr> <tr> <td colspan="6"></td> <td><img src="img/x.gif" class="r5" alt="Poraba žita" title="Poraba žita" /></td> <td>41070/47025</td> </tr> </table> </div> */ const string patternWood = @"<td id=""l4"" title=""(\d+)"">(\d+)/(\d+)</td>"; Regex wood = new Regex(patternWood); if (wood.IsMatch(pageSource)) { Match Mc = wood.Matches(pageSource)[0]; village.WoodAvailable = Int32.Parse(Mc.Groups[2].Value.Trim()); village.WoodProduction = Int32.Parse(Mc.Groups[1].Value.Trim()); village.CapacityWarehouse = Int32.Parse(Mc.Groups[3].Value.Trim()); } const string patternClay = @"<td id=""l3"" title=""(\d+)"">(\d+)/(\d+)</td>"; Regex clay = new Regex(patternClay); if (clay.IsMatch(pageSource)) { Match Mc = clay.Matches(pageSource)[0]; village.ClayAvailable = Int32.Parse(Mc.Groups[2].Value.Trim()); village.ClayProduction = Int32.Parse(Mc.Groups[1].Value.Trim()); village.CapacityWarehouse = Int32.Parse(Mc.Groups[3].Value.Trim()); } const string patternIron = @"<td id=""l2"" title=""(\d+)"">(\d+)/(\d+)</td>"; Regex iron = new Regex(patternIron); if (iron.IsMatch(pageSource)) { Match Mc = iron.Matches(pageSource)[0]; village.IronAvailable = Int32.Parse(Mc.Groups[2].Value.Trim()); village.IronProduction = Int32.Parse(Mc.Groups[1].Value.Trim()); village.CapacityWarehouse = Int32.Parse(Mc.Groups[3].Value.Trim()); } const string patternCrop = @"<td id=""l1"" title=""(\d+)"">(\d+)/(\d+)</td>"; Regex crop = new Regex(patternCrop); if (crop.IsMatch(pageSource)) { Match Mc = crop.Matches(pageSource)[0]; village.CropAvailable = Int32.Parse(Mc.Groups[2].Value.Trim()); village.CropProduction = Int32.Parse(Mc.Groups[1].Value.Trim()); village.CapacityGranary = Int32.Parse(Mc.Groups[3].Value.Trim()); } }