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(); }
private DefaultPage Login() { DefaultPage browserPage = new DefaultPage(browser, server, username, password, defaultVillageId); browserPage.LoginPage().LoginToGame(); isLoggedIn = browserPage.IsLogedIn; return browserPage; }