예제 #1
0
 public void AddTroop(TroopList troops)
 {
     if (!availableTroops.Contains(troops))
     {
         availableTroops.Add(troops);
     }
 }
예제 #2
0
 public void AddTroopsForVillage(Village village,
     TroopList troops)
 {
     if (troopList4Village.ContainsKey(village))
     {
         troopList4Village.Remove(village);
     }
     troopList4Village.Add(village, troops.TroopsForVillage as List<TroopList>);
 }
예제 #3
0
 private TroopList GetTroopList()
 {
     TroopList troopList = new TroopList();
     Table tableTroops = browser.Table(Find.ById("troops"));
     if (tableTroops.Exists)
     {
         foreach (TableRow tableRow in tableTroops.TableRows)
         {
             TableCell tableCell = tableRow.TableCell(Find.ByClass("ico"));
             if (tableCell.Exists)
             {
                 Link unitLink = tableCell.Link(Find.ByUrl(new Regex("build.php.gid=16")));
                 string troopClass = unitLink.Image(Find.BySrc(new Regex("img.x.gif"))).ClassName;
                 int troopCount = Int32.Parse(tableRow.TableCell(Find.ByClass("num")).Text);
                 troopList.AddTroop(new TroopList(troopClass, troopCount));
             }
         }
     }
     return troopList;
 }
예제 #4
0
 private void RaidFarms(TroopList troopList,
     DefaultPage browserPage,
     KeyValuePair<Village, List<TroopList>> unitInVillage,
     string textBox)
 {
     Log.Debug("RaidFarms");
     int availableUnits = troopList.Count;
     foreach (MapCoordinates mapCoordinate in farmList)
     {
         Map map = browserPage.MapPage();
         if (!map.GetVillageDetails(mapCoordinate))
         {
             dataBase.DeleteVillage(mapCoordinate.VillageId);
             Log.InfoFormat("Removed village : {0}", mapCoordinate);
             raidedFarms.Add(mapCoordinate);
         }
         else
         {
             dataBase.SaveVillageToDb(mapCoordinate);
             Log.DebugFormat("Updated village : {0}", mapCoordinate);
             if (mapCoordinate.PlayerEnabled)
             {
                 Log.InfoFormat("availableUnits : {0}", availableUnits);
                 if (availableUnits >= minUnits4Send)
                 {
                     Random random = new Random();
                     int randomUnitCount = random.Next(minUnits4Send,
                                                       maxUnits4Send);
                     if (randomUnitCount > availableUnits)
                     {
                         randomUnitCount = availableUnits;
                     }
                     SendTroops sendTroops = browserPage.SendTroopsPage();
                     if (sendTroops.Attack(new AttackSettings(mapCoordinate.VillageId, AttackType.Raid, textBox,
                                                              randomUnitCount.ToString())))
                     {
                         availableUnits -= randomUnitCount;
                         raidedFarms.Add(mapCoordinate);
                         Log.InfoFormat(
                             "Attacked '{3}' from '{0}' with {1} '{2}'",
                             unitInVillage.Key.Name, randomUnitCount, troopList.TroopClass,
                             mapCoordinate.VillageName);
                     }
                     else
                     {
                         Log.WarnFormat("Attack to '{0}' failed.", mapCoordinate.VillageName);
                         return;
                     }
                 }
                 else
                 {
                     Log.Info("No more units for farming...");
                     return;
                 }
             }
             else
             {
                 raidedFarms.Add(mapCoordinate);
             }
         }
     }
 }