Example #1
0
 /// <summary>
 /// Gets the available troops in village.
 /// </summary>
 /// <returns></returns>
 public Troops GetAvailableTroops()
 {
     Troops troops = new Troops();
     HtmlNode tableTroops = htmlDocument.DocumentNode.SelectSingleNode("//table[@id='troops']");
     if (tableTroops != null)
     {
         HtmlNodeCollection htmlNodeCollection = tableTroops.SelectNodes("./tbody//tr");
         if (htmlNodeCollection != null)
         {
             foreach (HtmlNode htmlNode in htmlNodeCollection)
             {
                 if (htmlNode != null)
                 {
                     HtmlNode element = htmlNode.Element("td").Element("a");
                     if (element != null)
                     {
                         string classAttribute = element.Element("img").Attributes["class"].Value;
                         int unitCount = Misc.String2Number(htmlNode.SelectSingleNode("./td[2]").InnerText);
                         string titleAttribute = htmlNode.SelectSingleNode("./td[3]").InnerText;
                         troops.AddTroopUnit(
                             new TroopUnit(titleAttribute, unitCount).AddHtmlClassName(classAttribute));
                     }
                 }
             }
         }
     }
     return troops;
 }
Example #2
0
        public void GaulsTroopsData()
        {
            Gauls gauls = new Gauls();
            gauls.Phalanx.AddTroopCount(11);
            gauls.Swordsman.AddTroopCount(22);
            Troops troops = new Troops();
            troops.AddTroopUnit(gauls.Phalanx).AddTroopUnit(gauls.Swordsman);

            Assert.IsNotNull(troops.TroopsList, "Troop list is null!");
            Assert.AreEqual(2, troops.TroopsList.Count, "Count!");
            Assert.AreEqual(11, troops.GetTroopCount("unit u21"), "Phalanx!");
            Assert.AreEqual(22, troops.GetTroopCount("unit u22"), "Swordsman!");
            Assert.AreEqual(0, troops.GetTroopCount("unit u23"), "Pathfinder!");
            Assert.AreNotEqual(gauls.Ram, troops.GetTroopInfo("unit u21"), "TroopInfo!");
            Assert.AreEqual(gauls.Phalanx, troops.GetTroopInfo("unit u21"), "TroopInfo!");
            Assert.AreEqual(gauls.Swordsman, troops.GetTroopInfo("unit u22"), "TroopInfo!");
        }
Example #3
0
 /// <summary>
 /// Gets troop movements from rally point.
 /// </summary>
 /// <returns><see cref="List{T}"/></returns>
 public List<TroopMovement> TroopMovements(Village village)
 {
     List<TroopMovement> troopMovement = new List<TroopMovement>();
     DateTime dt = new DateTime(DateTime.Now.Ticks);
     HtmlNodeCollection nodes = htmlDocument.DocumentNode.SelectNodes("//table[@class='troop_details']");
     if (nodes != null)
     {
         foreach (HtmlNode tableNode in nodes)
         {
             TroopMovement movement = new TroopMovement();
             //source and destination
             HtmlNodeCollection htmlNodeCollection = tableNode.SelectNodes(".//thead/tr/td//a");
             if (htmlNodeCollection != null)
             {
                 HtmlNode nodeSource = htmlNodeCollection[0];
                 movement.SetSource(nodeSource.InnerText,
                                    nodeSource.Attributes["href"].Value);
                 HtmlNode nodeDestination = htmlNodeCollection[1];
                 movement.SetDestination(nodeDestination.InnerText,
                                         nodeDestination.Attributes["href"].Value);
             }
             //units
             HtmlNodeCollection nodeCollection = tableNode.SelectNodes(".//tbody[@class='units']//td");
             if (nodeCollection != null)
             {
                 Troops troops = new Troops();
                 int totalUnits = nodeCollection.Count/2;
                 for (int i = 0; i < totalUnits; i++)
                 {
                     string classAttribute = nodeCollection[i].Element("img").Attributes["class"].Value;
                     string titleAttribute = nodeCollection[i].Element("img").Attributes["title"].Value;
                     int unitCount = Misc.String2Number(nodeCollection[i + totalUnits].InnerText);
                     troops.AddTroopUnit(new TroopUnit(titleAttribute, unitCount).AddHtmlClassName(classAttribute));
                 }
                 movement.AddTroops(troops);
             }
             //resoures
             HtmlNodeCollection arrivalSpan =
                 tableNode.SelectNodes(".//tbody[@class='infos']//span[starts-with(@id, 'timer')]");
             if (arrivalSpan != null)
             {
                 TimeSpan timeSpan = Misc.String2TimeSpan(arrivalSpan[0].InnerText);
                 movement.SetDate(dt + timeSpan);
                 if (movement.SourceVillageName.Equals(village.Name))
                 {
                     //own troops
                     string destinationVillageName = movement.DestinationVillageName;
                     if ((destinationVillageName.StartsWith(language.RallyPoint.AttackOut)) ||
                         (destinationVillageName.StartsWith(language.RallyPoint.RaidOut)))
                     {
                         movement.SetType(TroopMovementType.AttackOutgoing);
                     }
                     else if (destinationVillageName.StartsWith(language.RallyPoint.ReinforcementBack))
                     {
                         movement.SetType(TroopMovementType.ReinforcementIncomming);
                     }
                     else if (destinationVillageName.StartsWith(language.RallyPoint.Scout))
                     {
                         movement.SetType(TroopMovementType.Scouting);
                     }
                     else
                     {
                         movement.SetType(TroopMovementType.ReinforcementOutgoing);
                     }
                 }
                 else
                 {
                     string destinationVillageName = movement.DestinationVillageName;
                     if ((destinationVillageName.StartsWith(language.RallyPoint.AttackIn)) ||
                         (destinationVillageName.StartsWith(language.RallyPoint.RaidIn)))
                     {
                         movement.SetType(TroopMovementType.AttackIncomming);
                     }
                     else
                     {
                         movement.SetType(TroopMovementType.ReinforcementIncomming);
                     }
                 }
             }
             else
             {
                 movement.SetType(TroopMovementType.Idle);
                 movement.SetDestination("", "");
             }
             troopMovement.Add(movement);
         }
     }
     return troopMovement;
 }
Example #4
0
        public void VillageData()
        {
            Production production = new Production();
            const int warehouse = 3100;
            const int granary = 4000;
            production
                .UpdateWarehouse(warehouse)
                .UpdateGranary(granary)
                .UpdateTotals(132, 213, 11, 223)
                .UpdatePerHour(100, 200, 300, 400);
            Assert.IsNotNull(production, "Production is null!");

            TroopUnit phalanx = new TroopUnit();
            phalanx.AddName("Phalanx").AddHtmlClassName("unit u23").AddTroopCount(11);
            TroopUnit axeman = new TroopUnit();
            axeman.AddName("Axeman").AddHtmlClassName("unit u3").AddTroopCount(22);
            Troops troops = new Troops();
            troops.AddTroopUnit(phalanx).AddTroopUnit(axeman);
            Assert.IsNotNull(troops.TroopsList, "Troop list is null!");

            const int villageId = 0;
            const string villageName = "asds";
            const int coordinateX = 13;
            const int coordinateY = -131;
            Village village = new Village();
            village
                .AddId(villageId)
                .AddName(villageName)
                .UpdateCoordinates(coordinateX, coordinateY)
                .UpdateProduction(production)
                .UpdateTroopsInVillage(troops);

            Assert.IsNotNull(village.Production, "Production is null!");
            Assert.IsNotNull(village.TroopsAvailable, "TroopsAvailable is null!");
            Assert.AreEqual(production, village.Production, "Village production!");
            Assert.AreEqual(troops, village.TroopsAvailable, "Village troops!");
            Assert.AreEqual(warehouse, village.Production.Warehouse, "Warehouse!");
            Assert.AreEqual(granary, village.Production.Granary, "Granary!");
            Assert.AreEqual(coordinateX, village.CoordinateX, "CoordinateX!");
            Assert.AreEqual(coordinateY, village.CoordinateY, "CoordinateY!");
            village
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit11", 12)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit12", 13)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit13", 14)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit14", 15)))
                                       .SetDate(new DateTime(2222, 12, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.AttackIncomming))
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit31", 1201)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit32", 1202)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit33", 1203)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit34", 1204)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit35", 1205)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit36", 1206)))
                                       .SetDate(new DateTime(2222, 10, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.AttackOutgoing))
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit21", 121)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit22", 122)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit23", 123)))
                                       .SetDate(new DateTime(2222, 11, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.AttackOutgoing))
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit4", 12000)))
                                       .SetDate(new DateTime(2222, 9, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.ReinforcementIncomming))
                ;

            Assert.IsNotNull(village.TroopMovement, "Troop movement!");
            Assert.AreEqual(4, village.TroopMovementCount, "Troop movement count!");
            Assert.AreEqual(2, village.OwnAttacks, "Own attacks!");
            Assert.Sorted(village.TroopMovement, SortOrder.Increasing, new TroopMovementComparer());
            village.ClearTroopMovementsList();
            Assert.AreEqual(0, village.TroopMovementCount, "Troop movement count!");
        }
Example #5
0
        public void RomansTroopsData()
        {
            Romans romans = new Romans();
            romans.BatteringRam.AddTroopCount(11);
            romans.Imperian.AddTroopCount(22);
            Troops troops = new Troops();
            troops.AddTroopUnit(romans.BatteringRam).AddTroopUnit(romans.Imperian);

            Assert.IsNotNull(troops.TroopsList, "Troop list is null!");
            Assert.AreEqual(2, troops.TroopsList.Count, "Count!");
            Assert.AreEqual(11, troops.GetTroopCount("unit u7"), "BatteringRam!");
            Assert.AreEqual(22, troops.GetTroopCount("unit u3"), "Imperian!");
            Assert.AreEqual(0, troops.GetTroopCount("unit u23"), "Pathfinder!");
            Assert.AreNotEqual(romans.Hero, troops.GetTroopInfo("unit u7"), "TroopInfo!");
            Assert.AreEqual(romans.Imperian, troops.GetTroopInfo("unit u3"), "TroopInfo!");
            Assert.AreEqual(romans.BatteringRam, troops.GetTroopInfo("unit u7"), "TroopInfo!");
        }
Example #6
0
        public void TroopMovements()
        {
            Tribes tribes = new Tribes();
            TroopUnit unit = tribes.GetUnit("unit u21");
            Assert.IsNotNull(unit, "Unit not found!");
            Assert.AreEqual(unit.Name, "Phalanx", "Unit not found!");
            unit.AddTroopCount(123).AddName("Falanga");
            Assert.AreEqual(unit.Name, "Falanga", "Unit not found!");
            Troops troops = new Troops();
            troops.AddTroopUnit(unit);
            unit = tribes.GetUnit("unit u22");
            unit.AddTroopCount(321).AddName("Mecevalec");
            troops.AddTroopUnit(unit);

            TroopMovement troopMovement = new TroopMovement();
            DateTime arrivalDateTime = new DateTime(9999, 12, 31, 1, 2, 3);
            const string villageNameDestination = "01";
            const string villageNameSource = "00";
            const string urlDestination = "http://speed.travian.com/karte.php?id=123";
            const string urlSource = "http://asd.php";
            troopMovement
                .AddTroops(troops)
                .SetDate(arrivalDateTime)
                .SetType(TroopMovementType.AttackOutgoing)
                .SetDestination(villageNameDestination, urlDestination)
                .SetSource(villageNameSource, urlSource);

            Assert.IsNotNull(troopMovement, "TroopMovement");
            Assert.AreEqual(TroopMovementType.AttackOutgoing, troopMovement.Type, "Type");
            Assert.AreEqual(arrivalDateTime, troopMovement.DateTime, "arrivalDateTime");
            Assert.AreEqual(villageNameDestination, troopMovement.DestinationVillageName, "villageNameDestination");
            Assert.AreEqual(urlDestination, troopMovement.DestinationVillageUrl, "urlDestination");
            Assert.AreEqual(villageNameSource, troopMovement.SourceVillageName, "villageNameSource");
            Assert.AreEqual(urlSource, troopMovement.SourceVillageUrl, "urlSource");
            Assert.AreEqual(troops, troopMovement.Troops, "troops");
        }
Example #7
0
        public void TeutonsTroopsData()
        {
            Teutons teutons = new Teutons();
            teutons.Axeman.AddTroopCount(11);
            teutons.Paladin.AddTroopCount(22);
            Troops troops = new Troops();
            troops.AddTroopUnit(teutons.Axeman).AddTroopUnit(teutons.Paladin);

            Assert.IsNotNull(troops.TroopsList, "Troop list is null!");
            Assert.AreEqual(2, troops.TroopsList.Count, "Count!");
            Assert.AreEqual(11, troops.GetTroopCount("unit u13"), "Axeman!");
            Assert.AreEqual(22, troops.GetTroopCount("unit u15"), "Paladin!");
            Assert.AreEqual(0, troops.GetTroopCount("unit u23"), "Pathfinder!");
            Assert.AreNotEqual(teutons.Hero, troops.GetTroopInfo("unit u17"), "TroopInfo!");
            Assert.AreEqual(teutons.Axeman, troops.GetTroopInfo("unit u13"), "TroopInfo!");
            Assert.AreEqual(teutons.Paladin, troops.GetTroopInfo("unit u15"), "TroopInfo!");
        }
Example #8
0
 /// <summary>
 /// Adds the troops to the list.
 /// </summary>
 /// <param name="troopList">The new troops.</param>
 /// <returns></returns>
 public TroopMovement AddTroops(Troops troopList)
 {
     troops = troopList;
     return this;
 }
Example #9
0
 /// <summary>
 /// Updates the troops in village.
 /// </summary>
 /// <param name="troops">The troops.</param>
 /// <returns></returns>
 public Village UpdateTroopsInVillage(Troops troops)
 {
     troopsAvailable = troops;
     return this;
 }
Example #10
0
        public void Account()
        {
            Account account = new Account();
            const string accountName = "kekec";
            const int accountId = 123;
            const TribeTypes accountTribe = TribeTypes.Gauls;
            account.AddName(accountName).AddId(accountId).AddTribe(accountTribe);
            Assert.IsNotNull(account, "Account is null!");
            Assert.AreEqual(accountName, account.Name);
            Assert.AreEqual(accountId, account.Id);
            Assert.AreEqual(accountTribe, account.TribeType);

            Village firstVillage = new Village();
            const int firstVillageId = 0;
            const string firstVillageName = "01";
            firstVillage.AddId(firstVillageId).AddName(firstVillageName);
            account.AddVillage(firstVillage);
            Assert.IsNotNull(account.Villages, "Village list!");
            Assert.AreEqual(1, account.Villages.Count, "Village list count!");
            Assert.AreEqual(firstVillageId, account.Villages[0].Id, "Village id!");
            Assert.AreEqual(firstVillageName, account.Villages[0].Name, "Village name!");

            Village secondVillage = new Village();
            const int secondVillageId = 1324;
            const string secondVillageName = "02";
            secondVillage.AddId(secondVillageId).AddName(secondVillageName);
            Production production = new Production();
            production
                .UpdateWarehouse(3100)
                .UpdateGranary(4000)
                .UpdateTotals(132, 213, 11, 223)
                .UpdatePerHour(100, 200, 300, 400);
            secondVillage.UpdateProduction(production);
            account.AddVillage(secondVillage);

            Assert.AreEqual(2, account.Villages.Count, "Village list count!");

            Village firstAccountVillage = account.GetVillage(firstVillageId);
            Assert.IsNotNull(firstAccountVillage, "Village not found!");
            Assert.AreEqual(firstVillageId, firstAccountVillage.Id, "Village id!");
            Assert.AreEqual(firstVillageName, firstAccountVillage.Name, "Village name!");
            Assert.IsNull(firstAccountVillage.Production, "Village production!");
            Assert.IsNull(firstAccountVillage.TroopsAvailable, "Village troops!");

            Village secondAccountVillage = account.GetVillage(secondVillageId);
            Assert.IsNotNull(secondAccountVillage, "Village not found!");
            Assert.AreEqual(secondVillageId, secondAccountVillage.Id, "Village id!");
            Assert.AreEqual(secondVillageName, secondAccountVillage.Name, "Village name!");
            Assert.AreEqual(production, secondAccountVillage.Production, "Village production!");
            Assert.IsNull(secondAccountVillage.TroopsAvailable, "Village troops!");

            Gauls gauls = new Gauls();
            TroopUnit phalanx = gauls.Phalanx.AddTroopCount(123);
            TroopUnit haeduan = gauls.Haeduan.AddTroopCount(13);
            Romans romans = new Romans();
            TroopUnit legionnaire = romans.Legionnaire.AddTroopCount(2222);
            TroopUnit praetorian = romans.Praetorian.AddTroopCount(45632);
            Teutons teutons = new Teutons();
            TroopUnit spearman = teutons.Spearman.AddTroopCount(5123);
            Troops troops = new Troops();
            troops
                .AddTroopUnit(phalanx).AddTroopUnit(haeduan)
                .AddTroopUnit(legionnaire).AddTroopUnit(praetorian)
                .AddTroopUnit(spearman);
            secondAccountVillage.UpdateTroopsInVillage(troops);
            Assert.IsNull(firstAccountVillage.TroopsAvailable, "Village troops!");
            Assert.IsNotNull(secondAccountVillage.TroopsAvailable, "Village troops!");
            Assert.AreEqual(13, secondAccountVillage.TroopsAvailable.GetTroopCount("unit u26"), "Haeduan count!");
        }