Exemple #1
0
 public void IncommingAttack3()
 {
     GetBrowser("dorf1.attack.html");
     gameData = new GameData();
     village = new Village(0, "00");
     dorf1Page = new Helper.Dorf1(Browser, gameData)
     {
         Village = village,
         RemoveTroopsTimeSpan = new TimeSpan(0, 0, 53),
     };
     dorf1Page.ParseTroopMovements();
     List<TroopMovements> troopMovements = gameData.GetTroopMovements4Village(village);
     Assert.AreEqual(1, troopMovements[0].Number);
     Assert.AreEqual(5, troopMovements[1].Number);
     Assert.AreEqual(3, troopMovements[2].Number);
     Assert.AreEqual(new TimeSpan(0, 0, 53), troopMovements[0].ArrivalTime);
     Assert.AreEqual(new TimeSpan(0, 0, 44), troopMovements[1].ArrivalTime);
     Assert.AreEqual(new TimeSpan(0, 2, 12), troopMovements[2].ArrivalTime);
     Assert.AreEqual(TroopMovementType.AttackIncoming, troopMovements[0].Type);
     Assert.AreEqual(TroopMovementType.ReinforcementIncomming, troopMovements[1].Type);
     Assert.AreEqual(TroopMovementType.AttackOutgoing, troopMovements[2].Type);
     Assert.AreEqual(new TimeSpan(0, 0, 53), dorf1Page.NextCheck);
     Assert.AreEqual(53000, dorf1Page.NextCheck.TotalMilliseconds);
     Assert.IsTrue(dorf1Page.RemoveTroops);
 }
Exemple #2
0
 public void AddVillage(Village village)
 {
     if (!villages.Contains(village))
     {
         villages.Add(village);
     }
 }
Exemple #3
0
 public void AddTroopsForVillage(Village village,
     TroopList troops)
 {
     if (troopList4Village.ContainsKey(village))
     {
         troopList4Village.Remove(village);
     }
     troopList4Village.Add(village, troops.TroopsForVillage as List<TroopList>);
 }
Exemple #4
0
 public void AddTroopMovementsForVillage(Village village,
     List<TroopMovements> troopMovements)
 {
     if (troopMovements4Village.ContainsKey(village))
     {
         troopMovements4Village.Remove(village);
     }
     troopMovements4Village.Add(village, troopMovements);
 }
Exemple #5
0
 public void AddProductionForVillage(Village village,
     Production production)
 {
     if (production4Village.ContainsKey(village))
     {
         production4Village.Remove(village);
     }
     production4Village.Add(village, production);
 }
Exemple #6
0
 public Production GetProduction4Village(Village village)
 {
     foreach (KeyValuePair<Village, Production> keyValuePair in production4Village)
     {
         if (keyValuePair.Key.Equals(village))
         {
             return keyValuePair.Value;
         }
     }
     return null;
 }
Exemple #7
0
 public List<TroopMovements> GetTroopMovements4Village(Village village)
 {
     foreach (KeyValuePair<Village, List<TroopMovements>> keyValuePair in troopMovements4Village)
     {
         if (keyValuePair.Key.Equals(village))
         {
             return keyValuePair.Value;
         }
     }
     return null;
 }
Exemple #8
0
 public void ClickRallyPoint(Village village)
 {
     Console.WriteLine("Navigating to RallyPoint in Village '{0}'", village.Name);
     string url = String.Format(CultureInfo.InvariantCulture, "{0}build.php?newdid={1}&gid=16&id=39", Server, village.Id);
     browser.GoTo(url);
 }
Exemple #9
0
        public void PlayGame()
        {
            using (browser)
            {
                Log.InfoFormat("Report reader : {0}, Raid : {1}", report, raid);
                DefaultPage browserPage = new DefaultPage(browser, server, username, password, defaultVillageId)
                                          {
                                              DefaultVillageId = 0,
                                          };
                browserPage.LoginPage().LoginToGame();
                isLoggedIn = browserPage.IsLogedIn;
                if (isLoggedIn)
                {
                    int repeatCount = 0;
                    int loginCount = 0;

                    Village village = new Village(attackVillageId, attackVillageName);
                    gameData.AddVillage(village);
                    gameData.GameSettings(language);
                    Dorf1 dorf1Page = browserPage.Dorf1Page(gameData);
                    dorf1Page.Village = village;
                    dorf1Page.ClickDorf1Link();

                    do
                    {
                        if (isLoggedIn)
                        {
                            loginCount = 0;
                            farmList = LoadVillagesFromXml();
                            if (farmList.Count == 0)
                            {
                                Log.Info("Getting new farm list...");
                                farmList = dataBase.GetFarmList();
                            }
                            if (raid)
                            {
                                if (!SleepTime())
                                {
                                    dorf1Page.ClickDorf1Link();
                                    Raid(browserPage);
                                }
                            }
                            if (report)
                            {
                                IReportReader reportReader = browserPage.AttackReport(gameData);
                                reportReader.Collect();
                                reportReader.Parse();
                                reportReader.Save();
                                if (!raid)
                                {
                                    int count = 0;
                                    foreach (MapCoordinates mapCoordinate in farmList)
                                    {
                                        Map map = browserPage.MapPage();
                                        if (!map.GetVillageDetails(mapCoordinate))
                                        {
                                            dataBase.DeleteVillage(mapCoordinate.VillageId);
                                            Log.InfoFormat("Removed village : {0}", mapCoordinate);
                                        }
                                        else
                                        {
                                            dataBase.SaveVillageToDb(mapCoordinate);
                                            Log.InfoFormat("Updated village : {0}", mapCoordinate);
                                        }
                                        raidedFarms.Add(mapCoordinate);
                                        if (count++ > 5)
                                        {
                                            break;
                                        }
                                    }
                                    RemoveRaidedFarms();
                                }
                            }
                            dorf1Page.ClickDorf1Link();
                        }
                        else
                        {
                            loginCount++;
                            if (!isLoggedIn)
                            {
                                Log.Warn("Not loged in. Sleep for 60 seconds...");
                                Thread.Sleep(60000);
                                if (loginCount > 3)
                                {
                                    Log.Warn("Failed to login!");
                                    break;
                                }
                            }
                        }
                        repeatCount++;
                        if (repeatCount > 100)
                        {
                            repeatCount = 0;
                        }
                        Log.InfoFormat("Sleep for {0}", dorf1Page.NextCheck);
                        Thread.Sleep(dorf1Page.NextCheck);
                    } while (repeatCount < 1000);
                }
                else
                {
                    Log.Warn("Login failed!!!");
                }
            }
            browser.Dispose();
        }
Exemple #10
0
 public void Production()
 {
     GetBrowser("dorf1.html");
     gameData = new GameData();
     village = new Village(0, "00");
     dorf1Page = new Helper.Dorf1(Browser, gameData) { Village = village };
     dorf1Page.ParseProduction();
     Production production = gameData.GetProduction4Village(village);
     Assert.IsNotNull(production, "Production is null!");
     Assert.AreEqual(167, production.Wood);
     Assert.AreEqual(459, production.Clay);
     Assert.AreEqual(782, production.Iron);
     Assert.AreEqual(670, production.Crop);
     Assert.AreEqual(8, production.WoodPerHour);
     Assert.AreEqual(16, production.ClayPerHour);
     Assert.AreEqual(24, production.IronPerHour);
     Assert.AreEqual(-22, production.CropPerHour);
     Assert.AreEqual(2300, production.WarehouseCapacity);
     Assert.AreEqual(1200, production.GranaryCapacity);
 }