Beispiel #1
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");
        }
Beispiel #2
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;
 }
Beispiel #3
0
 /// <summary>
 /// Updates the troops movement in village.
 /// </summary>
 /// <param name="troops">The troops.</param>
 /// <returns></returns>
 public Village AddTroopsMovement(TroopMovement troops)
 {
     troopMovement.Add(troops);
     return this;
 }