示例#1
0
        public void CalculatorDestinationBellowPercent()
        {
            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 = 80,
                    SendWood = true,
                    SendClay = true,
                    SendIron = true,
                    SendCrop = true,
                    SendGoodsType = SendGoodsType.DestinationBellowPercent,
                    LastSend = dt.AddDays(-1),
                    RepeatMinutes = 10,
                };

            MarketPlaceCalculator calculator = new MarketPlaceCalculator
                {
                    Destination = destinationVillage,
                    Source = sourceVillage,
                    MarketPlaceDestination = marketPlaceDestination,
                    MarketPlaceSource = marketPlaceSource,
                    Queue = queue,
                };
            calculator.Calculate();
            Assert.AreEqual("&r1=0&r2=1246&r3=1004&r4=0", calculator.PostParameters, "PostParameters");
            Assert.IsTrue(calculator.TimeToSend(dt), "Last send time");
        }
示例#2
0
 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");
 }
示例#3
0
 /// <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);
 }