public void ParseOases() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\karte.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); List<Valley> oases = htmlParser.GetOasesFromMap(); Assert.AreEqual(7, oases.Count, "Oases count!"); }
public void Read() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\berichte.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); List<Report> list = htmlParser.GetReports(); Assert.AreEqual(10, list.Count, "Count"); }
public void NoTroops() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\dorf1.php.1.village.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Troops troops = htmlParser.GetAvailableTroops(); Assert.IsNotNull(troops, "troops is null!"); Assert.AreEqual(0, troops.GetTroopCount("unit u21"), "Falanga!"); }
public void ParseMap() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\karte.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); List<Valley> valleys = htmlParser.GetVillagesFromMap(); Assert.IsNotNull(valleys, "valleys is null!"); Assert.AreEqual(4, valleys.Count, "Valleys count!"); }
public void CalculatorSourceOverPercent() { DeserializeLanguage(); Language language = Languages.GetLanguage("sl-SI"); Assert.IsNotNull(language, "Language is null!"); HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\Marketplace.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument, language); MarketPlace marketPlaceDestination = htmlParser.MarketPlace(); Assert.IsNotNull(marketPlaceDestination, "NULL"); Village destinationVillage = new Village(); destinationVillage.AddId(123).AddName("01"); Production productionDestination = htmlParser.GetProduction(); Assert.IsNotNull(productionDestination, "NULL"); destinationVillage.UpdateProduction(productionDestination); htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\Marketplace.idle.php.html"); htmlParser = new HtmlParser(htmlDocument, language); MarketPlace marketPlaceSource = htmlParser.MarketPlace(); Assert.IsNotNull(marketPlaceSource, "NULL"); Village sourceVillage = new Village(); sourceVillage.AddId(321).AddName("02"); Production productionSource = htmlParser.GetProduction(); Assert.IsNotNull(productionSource, "NULL"); sourceVillage.UpdateProduction(productionSource); DateTime dt = new DateTime(DateTime.Now.Ticks); MarketPlaceQueue queue = new MarketPlaceQueue { DestinationVillage = destinationVillage, SourceVillage = sourceVillage, Goods = 50, GoodsToSend = 750, SendWood = true, SendClay = true, SendIron = true, SendCrop = true, SendGoodsType = SendGoodsType.SourceOverPercent, LastSend = dt.AddHours(-2), RepeatMinutes = 10, }; MarketPlaceCalculator calculator = new MarketPlaceCalculator { Destination = destinationVillage, Source = sourceVillage, MarketPlaceDestination = marketPlaceDestination, MarketPlaceSource = marketPlaceSource, Queue = queue, }; calculator.CalculateSourceOver(); Assert.AreEqual("&r1=750&r2=750&r3=0&r4=750", calculator.PostParameters, "PostParameters"); Assert.IsTrue(calculator.TimeToSend(dt), "Last send time"); }
public void ParseCenterBuildings() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\dorf2.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Village village = new Village(); village.AddId(123).AddName("01"); List<Buildings> buildings = htmlParser.GetCenterBuildings(village); Assert.IsNotNull(buildings, "NULL"); Assert.AreEqual(22, buildings.Count, "COUNT"); }
public void NotEnoughResourcesForUpgrade() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\build.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); ResourcesForUpgrade resourcesForUpgrade = htmlParser.GetResourcesForNextLevel(); Assert.AreEqual(2190, resourcesForUpgrade.Wood, "Wood"); Assert.AreEqual(2095, resourcesForUpgrade.Clay, "Clay"); Assert.AreEqual(2190, resourcesForUpgrade.Iron, "Iron"); Assert.AreEqual(750, resourcesForUpgrade.Crop, "Crop"); Assert.AreEqual(4, resourcesForUpgrade.CurrentLevel, "current level"); }
public void EnoughResourcesForUpgrade() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\build.possible.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); ResourcesForUpgrade resourcesForUpgrade = htmlParser.GetResourcesForNextLevel(); Assert.AreEqual(945, resourcesForUpgrade.Wood, "Wood"); Assert.AreEqual(1180, resourcesForUpgrade.Clay, "Clay"); Assert.AreEqual(825, resourcesForUpgrade.Iron, "Iron"); Assert.AreEqual(235, resourcesForUpgrade.Crop, "Crop"); Assert.AreEqual("dorf2.php?a=19&c=238d2f", resourcesForUpgrade.UpgradeUrl, "url"); Assert.AreEqual(10, resourcesForUpgrade.CurrentLevel, "current level"); }
public void HtmlParserAvailableTroops() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\dorf1.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Troops troops = htmlParser.GetAvailableTroops(); Assert.IsNotNull(troops, "troops is null!"); Assert.AreEqual(1, troops.GetTroopCount("unit u21"), "Falanga!"); Assert.AreEqual(1, troops.GetTroopCount("unit uhero"), "Heroj!"); Assert.AreEqual(5, troops.GetTroopCount("unit u23"), "Stezosledcev!"); Assert.AreEqual(30, troops.GetTroopCount("unit u25"), "Druidov!"); Assert.AreEqual(0, troops.GetTroopCount("unit xxx"), "Crap!"); }
public void OccupiedOasisInfo() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\karte.ocupied.oases.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Valley valley = htmlParser.GetOasesDetails(); Assert.IsNotNull(valley, "valley is null!"); Assert.AreEqual(-85, valley.X, "X coordinate!"); Assert.AreEqual(59, valley.Y, "Y coordinate!"); Assert.AreEqual("Thor[+25% zita na uro]", valley.Name, "Name"); Assert.AreEqual("LegacyTM", valley.Alliance, "Alliance"); Assert.AreEqual("Olaf", valley.Player, "Player"); Assert.AreEqual(ValleyType.OccupiedOasis, valley.ValleyType, "ValleyType.UnoccupiedOasis"); }
public void UnoccupiedOasisInfo() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\karte.unoccupied.oases.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Valley valley = htmlParser.GetOasesDetails(); Assert.IsNotNull(valley, "valley is null!"); Assert.AreEqual(-85, valley.X, "X coordinate!"); Assert.AreEqual(61, valley.Y, "Y coordinate!"); Assert.AreEqual("+25% zeleza na uro", valley.Name, "Name"); Assert.AreEqual("Nezasedena pokrajina", valley.Alliance, "Alliance"); Assert.AreEqual(0, valley.AllianceId, "Alliance Id"); Assert.AreEqual("Nezasedena pokrajina", valley.Player, "Player"); Assert.AreEqual(0, valley.PlayerId, "Player Id"); Assert.AreEqual(ValleyType.UnoccupiedOasis, valley.ValleyType, "ValleyType.UnoccupiedOasis"); }
public void HtmlParserTroopMovements() { DeserializeLanguage(); Language language = Languages.GetLanguage("sl-SI"); Assert.IsNotNull(language, "Language is null!"); HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\RallyPoint.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument, language); List<TroopMovement> troopMovements = htmlParser.TroopMovements(new Village().AddId(1).AddName("02")); Assert.IsNotNull(troopMovements, "TroopMovement is null!"); Village village = new Village(); village.SetTroopMovements(troopMovements); Assert.AreEqual(23, village.TroopMovementCount, "Troop movement count!"); Assert.Sorted(village.TroopMovement, SortOrder.Increasing, new TroopMovementComparer()); village.ClearTroopMovementsList(); Assert.AreEqual(0, village.TroopMovementCount, "Troop movement count!"); }
public void Attacks() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\berichte.attack.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Report reportDetails = htmlParser.GetReportDetails(); Assert.AreEqual("kepek", reportDetails.AttackerName, "AttackerName"); Assert.AreEqual("00", reportDetails.AttackerVillage, "AttackerVillage"); Assert.AreEqual("karte.php?d=340795&c=99", reportDetails.AttackerUrl, "AttackerUrl"); Assert.AreEqual("16/240", reportDetails.CarryText, "CarryText"); Assert.AreEqual(240, reportDetails.CarryTotal, "CarryTotal"); Assert.AreEqual(16, reportDetails.CarryAmount, "CarryAmount"); Assert.AreEqual("21 | 62 | 23 | 64", reportDetails.ResourcesText, "ResourcesText"); Assert.AreEqual(21, reportDetails.ResourcesWood, "ResourcesWood"); Assert.AreEqual(62, reportDetails.ResourcesClay, "ResourcesClay"); Assert.AreEqual(23, reportDetails.ResourcesIron, "ResourcesIron"); Assert.AreEqual(64, reportDetails.ResourcesCrop, "ResourcesCrop"); }
public void ParseAvailableVillages() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\dorf1.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); List<Village> villages = htmlParser.GetAvailableVillages(); Assert.IsNotNull(villages, "villages is null!"); Assert.AreEqual(2, villages.Count, "Villages count!"); Assert.AreEqual(-82, villages[0].CoordinateX, "CoordinateX!"); Assert.AreEqual(64, villages[0].CoordinateY, "CoordinateY!"); htmlDocument.Load("..\\..\\Test Files\\dorf1.php.1.village.html"); htmlParser = new HtmlParser(htmlDocument); villages = htmlParser.GetAvailableVillages(); Assert.IsNotNull(villages, "villages is null!"); Assert.AreEqual(1, villages.Count, "Villages count!"); Assert.AreEqual(0, villages[0].CoordinateX, "CoordinateX!"); Assert.AreEqual(0, villages[0].CoordinateY, "CoordinateY!"); }
public void VillageInfo() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\village.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Valley valley = htmlParser.GetVillageDetails(); Assert.IsNotNull(valley, "valley is null!"); Assert.AreEqual("gajo123", valley.Name, "Name!"); Assert.AreEqual(267054, valley.VillageId, "Vilalge id!"); Assert.AreEqual(-80, valley.X, "X coordinate!"); Assert.AreEqual(67, valley.Y, "Y coordinate!"); Assert.AreEqual("allianz.php?aid=0", valley.AllianceUrl, "Alliance url!"); Assert.AreEqual(0, valley.AllianceId, "Alliance Id!"); Assert.AreEqual("", valley.Alliance, "Alliance name!"); Assert.AreEqual("novakm", valley.Player, "Player name!"); Assert.AreEqual("spieler.php?uid=11436", valley.PlayerUrl, "Player url!"); Assert.AreEqual(11436, valley.PlayerId, "User id!"); Assert.AreEqual(36, valley.Population, "Village Population!"); Assert.AreEqual("a2b.php?z=267054", valley.SendTroopsUrl, "SendTroopsUrl!"); //UNICODE CRAP //Assert.AreEqual("» Pošlji enote", valley.SendTroopsText, "SendTroopsText!"); }
public void ParseProduction() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\dorf1.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Village village = new Village(); village.AddId(123).AddName("01"); Production production = htmlParser.GetProduction(); Assert.IsNotNull(production, "NULL"); village.UpdateProduction(production); Assert.AreEqual(production, village.Production, "production"); Assert.AreEqual(575, village.Production.WoodPerHour, "wood per hour"); Assert.AreEqual(590, village.Production.ClayPerHour, "clay per hour"); Assert.AreEqual(525, village.Production.IronPerHour, "iron per hour"); Assert.AreEqual(359, village.Production.CropPerHour, "crop per hour"); Assert.AreEqual(4675, village.Production.WoodTotal, "wood total"); Assert.AreEqual(3343, village.Production.ClayTotal, "clay total"); Assert.AreEqual(4463, village.Production.IronTotal, "iron total"); Assert.AreEqual(5236, village.Production.CropTotal, "crop total"); Assert.AreEqual(14400, village.Production.Warehouse, "warehouse"); Assert.AreEqual(11800, village.Production.Granary, "granary"); }
public void VillageInfoProtection() { HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\karte.php.protection.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument); Valley valley = htmlParser.GetVillageDetails(); Assert.IsNotNull(valley, "valley is null!"); Assert.AreEqual("", valley.SendTroopsUrl, "SendTroopsUrl!"); Assert.AreEqual("Začetniška zaščita do 05.06.10 18:33.", valley.SendTroopsText, "SendTroopsText!"); }
private void PopulateBuildQueueForVillage(Village village) { string servername = settings.LoginData.Servername; string url = String.Format(CultureInfo.InvariantCulture, "{0}dorf1.php?newdid={1}", servername, village.Id); htmlDocument = htmlWeb.Load(url); HtmlParser htmlParser = new HtmlParser(htmlDocument); List<Buildings> resources = htmlParser.GetResourceBuildings(); url = String.Format(CultureInfo.InvariantCulture, "{0}dorf2.php?newdid={1}", servername, village.Id); htmlDocument = htmlWeb.Load(url); htmlParser = new HtmlParser(htmlDocument); List<Buildings> center = htmlParser.GetCenterBuildings(village); ArrayList list = new ArrayList(); list.AddRange(resources); list.AddRange(center); UpdateComboBoxQueues(comboBoxBuildQueueBuilding, list); }
private void PopulateRallyPoint(Village village) { Language language = languages.GetLanguage(settings.LanguageId); string servername = settings.LoginData.Servername; //http://s1.travian.com/build.php?newdid=75579&gid=16&id=39 string url = String.Format(CultureInfo.InvariantCulture, "{0}build.php?newdid={1}&gid=16&id=39", servername, village.Id); htmlDocument = htmlWeb.Load(url); HtmlParser htmlParser = new HtmlParser(htmlDocument, language); List<TroopMovement> troopMovements = htmlParser.TroopMovements(village); //ArrayList list = new ArrayList(); //list.AddRange(troopMovements); UpdateDataGridViewRallyPoint(dataGridViewRallyPoint, troopMovements); UpdateStatus(String.Format(CultureInfo.InvariantCulture, "Populate Rally Point in {0}", village.Name)); }
public void Idle() { DeserializeLanguage(); Language language = Languages.GetLanguage("sl-SI"); Assert.IsNotNull(language, "Language is null!"); HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\Marketplace.idle.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument, language); MarketPlace marketPlace = htmlParser.MarketPlace(); Assert.IsNotNull(marketPlace, "NULL"); Assert.AreEqual(3, marketPlace.AvailableMerchants, "AvailableMerchants"); Assert.AreEqual(6, marketPlace.TotalMerchants, "TotalMerchants"); Assert.AreEqual(750, marketPlace.TotalCarry, "TotalCarry"); }
private void GetMapInfoAt(int x, int y) { string servername = settings.LoginData.Servername; string url = String.Format(CultureInfo.InvariantCulture, "{0}karte.php?xp={1}&yp={2}&s1.x=32&s1.y=11&s1=ok", servername, x, y); htmlDocument = htmlWeb.Load(url); HtmlParser htmlParser = new HtmlParser(htmlDocument); List<Valley> villagesFromMap = htmlParser.GetVillagesFromMap(); List<Valley> oasesFromMap = htmlParser.GetOasesFromMap(); List<Valley> updatedValleys = new List<Valley>(); //List<Valley> existingValleys = map.Valleys; foreach (Valley valley in villagesFromMap) { url = String.Format(CultureInfo.InvariantCulture, "{0}{1}", servername, valley.VillageUrl); htmlDocument = htmlWeb.Load(url); htmlParser = new HtmlParser(htmlDocument); Valley villageDetails = htmlParser.GetVillageDetails(); ValleyType valleyType = GetValleyType(villageDetails); //UpdateStatus(valleyType.ToString()); villageDetails.AddUrl(valley.VillageUrl).AddType(valleyType); updatedValleys.Add(villageDetails); } foreach (Valley valley in oasesFromMap) { url = String.Format(CultureInfo.InvariantCulture, "{0}{1}", servername, valley.VillageUrl); htmlDocument = htmlWeb.Load(url); htmlParser = new HtmlParser(htmlDocument); Valley oasesDetails = htmlParser.GetOasesDetails(); updatedValleys.Add(oasesDetails); } map.AddVillages(updatedValleys); //map.AddVillages(oasesFromMap); UpdateStatus(String.Format(CultureInfo.InvariantCulture, "Found {2} villages and {3} oases around ({0}|{1})", x, y, villagesFromMap.Count, oasesFromMap.Count)); }
public void IncommingTransport() { DeserializeLanguage(); Language language = Languages.GetLanguage("sl-SI"); Assert.IsNotNull(language, "Language is null!"); HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument.Load("..\\..\\Test Files\\Marketplace.php.html"); HtmlParser htmlParser = new HtmlParser(htmlDocument, language); MarketPlace marketPlace = htmlParser.MarketPlace(); Assert.IsNotNull(marketPlace, "NULL"); Assert.AreEqual(11, marketPlace.AvailableMerchants, "AvailableMerchants"); Assert.AreEqual(15, marketPlace.TotalMerchants, "TotalMerchants"); Assert.AreEqual(750, marketPlace.TotalCarry, "TotalCarry"); Assert.AreEqual(2, marketPlace.TotalIncommingTransports, "TotalIncommingTransports"); Assert.AreEqual(3750, marketPlace.TotalIncommingWood, "TotalIncommingWood"); Assert.AreEqual(750, marketPlace.TotalIncommingClay, "TotalIncommingClay"); Assert.AreEqual(750, marketPlace.TotalIncommingIron, "TotalIncommingIron"); Assert.AreEqual(750, marketPlace.TotalIncommingCrop, "TotalIncommingCrop"); }
/// <summary> /// Updates the account info. /// </summary> private void UpdateAccountInfo() { UpdateStatus("UpdateAccountInfo"); HtmlParser htmlParser = new HtmlParser(htmlDocument); List<Village> villages = htmlParser.GetAvailableVillages(); string servername = settings.LoginData.Servername; if (villages.Count == 1) { string url = String.Format(CultureInfo.InvariantCulture, "{0}karte.php", servername); htmlDocument = htmlWeb.Load(url); //<h1>Zemljevid(<span id="x">-31</span>|<span id="y">-25</span>)</h1> HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//h1"); if (htmlNode != null) { HtmlNode nodeX = htmlDocument.DocumentNode.SelectSingleNode("//span[@id='x']"); if (nodeX != null) { villages[0].CoordinateX = Misc.String2Number(nodeX.InnerText.Trim()); } HtmlNode nodeY = htmlDocument.DocumentNode.SelectSingleNode("//span[@id='y']"); if (nodeY != null) { villages[0].CoordinateY = Misc.String2Number(nodeY.InnerText.Trim()); } } } account.UpdateVillages(villages); foreach (Village village in villages) { string url = String.Format(CultureInfo.InvariantCulture, "{0}dorf1.php?newdid={1}", servername, village.Id); htmlDocument = htmlWeb.Load(url); htmlParser = new HtmlParser(htmlDocument); Production production = htmlParser.GetProduction(); village.UpdateProduction(production); Troops availableTroops = htmlParser.GetAvailableTroops(); village.UpdateTroopsInVillage(availableTroops); } List<BuildQueue> list = new List<BuildQueue>(); foreach (BuildQueue buildQueue in actions.BuildQueue) { string url = String.Format(CultureInfo.InvariantCulture, "{0}build.php?newdid={1}&id={2}", servername, buildQueue.VillageId, buildQueue.BuildingId); htmlDocument = htmlWeb.Load(url); htmlParser = new HtmlParser(htmlDocument); buildQueue.Resources = htmlParser.GetResourcesForNextLevel(); if (buildQueue.Level > buildQueue.Resources.CurrentLevel) { list.Add(buildQueue); } else { UpdateStatus("Removing " + buildQueue); } } actions.BuildQueue = list; SerializeActions(); UpdateListBoxBuildQueues(listBoxBuildQueues); UpdateComboBoxVillages(comboBoxMapVillages); UpdateComboBoxVillages(comboBoxRallyPointVillages); UpdateComboBoxVillages(comboBoxBuildQueueVillages); UpdateComboBoxVillages(comboBoxMarketPlaceSourceVillage); UpdateComboBoxVillages(comboBoxMarketPlaceDestinationVillage); UpdateComboBoxVillages(comboBoxMarketPlaceRepeatSourceVillage); }
public void ParseUnknownDestination() { parseSucceeded = false; if (language == null) return; source = account.GetVillage(queue.SourceVillage.Id); if (source == null) return; string url = String.Format(CultureInfo.InvariantCulture, "{0}build.php?newdid={1}&gid=17", settings.LoginData.Servername, source.Id); htmlDocument = htmlWeb.Load(url); if (htmlDocument == null) return; HtmlParser htmlParser = new HtmlParser(htmlDocument, language); marketPlaceSource = htmlParser.MarketPlace(); if (marketPlaceSource == null) return; destination = queue.DestinationVillage; parseSucceeded = true; }