public static void ReStartDemolishing(Account acc, Village vill) { if (vill.Build.DemolishTasks.Count > 0) { TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new DemolishBuilding() { vill = vill, ExecuteAt = DateTime.Now.AddSeconds(10) }); } }
/// <summary> /// Will (re)start troop research and improvement for this village /// </summary> /// <param name="acc">Account</param> /// <param name="vill">Village to start troops training</param> public static void ReStartResearchAndImprovement(Account acc, Village vill) { Classificator.TroopsEnum[] troops = { vill.Settings.BarracksTrain, vill.Settings.StableTrain, vill.Settings.WorkshopTrain }; foreach (var troop in troops) { if (troop == TroopsEnum.None) { continue; } // Research if (!vill.Troops.Researched.Contains(troop) && ((int)troop % 10) != 1) // Don't try to research 1. troops of each tribe (clubs, phalanx...) { if (TroopsHelper.AddBuildingsForTroop(acc, vill, troop)) { //we already have all required buildings to research this troop vill.Troops.ToResearch.Add(troop); vill.Troops.ToImprove.Add(troop); //We have all buildings needed to research the troop. Do it. var researchTask = new ResearchTroop() { Vill = vill, ExecuteAt = DateTime.Now }; TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, researchTask); } continue; } else { vill.Troops.ToResearch.Remove(troop); } // Improvement if (vill.Troops.Levels != null) { if (!vill.Troops.Levels.Exists(x => x.Troop == troop && x.Level == 20) && vill.Settings.AutoImprove) { vill.Troops.ToImprove.Add(troop); if (vill.Build.Buildings.Any(x => x.Type == BuildingEnum.Smithy)) { TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new ImproveTroop() { Vill = vill, ExecuteAt = DateTime.Now }); } } else { vill.Troops.ToImprove.Remove(troop); } } } }
public static void ReStartSendingToMain(Account acc, Village vill) { acc.Tasks.RemoveAll(x => x.GetType() == typeof(SendResToMain) && x.Vill == vill); if (vill.Settings.Type == VillType.Support && vill.Settings.SendRes) { TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new SendResToMain() { ExecuteAt = DateTime.Now, Vill = vill }); } }
public static void ReStartCelebration(Account acc, Village vill) { // If we don't want auto-celebrations, return if (vill.Expansion.Celebrations == CelebrationEnum.None) { return; } TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new Celebration() { ExecuteAt = vill.Expansion.CelebrationEnd.AddSeconds(7), Vill = vill }); }
public static bool UpdateVillages(HtmlAgilityPack.HtmlDocument htmlDoc, Account acc) { List <VillageChecked> foundVills = RightBarParser.GetVillages(htmlDoc); if (foundVills.Count == 0) { return(false); //some problem in GetVillages function! } for (int i = 0; i < acc.Villages.Count; i++) { var oldVill = acc.Villages[i]; var foundVill = foundVills.Where(x => x.Id == oldVill.Id).FirstOrDefault(); //Village was not found -> destroyed/chiefed if (foundVill == null) { acc.Villages.RemoveAt(i); i--; continue; } oldVill.Name = foundVill.Name; oldVill.Active = foundVill.Active; if (oldVill.UnderAttack != foundVill.UnderAttack && foundVill.UnderAttack && oldVill.Deffing.AlertType != Models.VillageModels.AlertTypeEnum.Disabled) { TaskExecutor.AddTaskIfNotExistInVillage(acc, oldVill, new CheckAttacks() { Vill = oldVill, Priority = Tasks.BotTask.TaskPriority.High }); } oldVill.UnderAttack = foundVill.UnderAttack; foundVills.Remove(foundVill); } //Any villages found and were not previously in acc.Villages should be added (new villages) foreach (var newVill in foundVills) { NewVillageFound(acc, newVill); } return(true); }
/// <summary> /// Initializes a new village model and creates the task to update the village /// </summary> /// <param name="acc">Account</param> /// <param name="newVill">new village</param> public static void NewVillageFound(Account acc, VillageChecked newVill) { var vill = new Village() { Active = newVill.Active, Coordinates = newVill.Coordinates, Id = newVill.Id, Name = newVill.Name, UnderAttack = newVill.UnderAttack, UnfinishedTasks = new List <VillUnfinishedTask>() // Move this inside Init()? }; vill.Init(acc); acc.Villages.Add(vill); // Update the village TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new UpdateVillage() { ExecuteAt = DateTime.Now.AddHours(-2), Vill = vill, ImportTasks = true }); DefaultConfigurations.SetDefaultTransitConfiguration(acc, vill); // Copy default settings to the new village. TODO: use automapper for this. //var defaultSettings = acc.NewVillages.DefaultSettings; //vill.Settings = new VillSettings() //{ // Type = defaultSettings.Type, // BarracksTrain = defaultSettings.BarracksTrain, // StableTrain = defaultSettings.StableTrain, // WorkshopTrain = defaultSettings.WorkshopTrain, // GreatBarracksTrain = defaultSettings.GreatBarracksTrain, // GreatStableTrain = defaultSettings.GreatStableTrain, // SendRes = defaultSettings.SendRes, // GetRes = defaultSettings.GetRes, //}; // Change village name var newVillageFromList = acc.NewVillages.Locations .FirstOrDefault(x => x.SettlersSent && x.Coordinates.x == vill.Coordinates.x && x.Coordinates.y == vill.Coordinates.y ); if (newVillageFromList != null) { if (string.IsNullOrEmpty(newVillageFromList.Name)) { newVillageFromList.Name = NewVillageHelper.GenerateName(acc); } acc.NewVillages.Locations.Remove(newVillageFromList); TaskExecutor.AddTaskIfNotExists(acc, new ChangeVillageName() { ExecuteAt = DateTime.Now, ChangeList = new List <(int, string)> { (vill.Id, newVillageFromList.Name) } });
public static void StartAccountTasks(Account acc) { // Get the server info (on first running the account) if (acc.AccInfo.ServerSpeed == 0 || acc.AccInfo.MapSize == 0) { TaskExecutor.AddTaskIfNotExists(acc, new GetServerInfo() { ExecuteAt = DateTime.MinValue.AddHours(2) }); } if (acc.AccInfo.Tribe == null) { TaskExecutor.AddTaskIfNotExists(acc, new GetTribe() { ExecuteAt = DateTime.MinValue.AddHours(3) }); } //FL if (acc.Farming.Enabled) { TaskExecutor.AddTaskIfNotExists(acc, new SendFLs() { ExecuteAt = DateTime.Now }); } // Bot sleep TaskExecutor.AddTaskIfNotExists(acc, new Sleep() { ExecuteAt = DateTime.Now + TimeHelper.GetWorkTime(acc), AutoSleep = true }); // Access change var nextAccessChange = TimeHelper.GetNextProxyChange(acc); if (nextAccessChange != TimeSpan.MaxValue) { TaskExecutor.AddTaskIfNotExists(acc, new ChangeAccess() { ExecuteAt = DateTime.Now + nextAccessChange }); } //research / improve / train troops foreach (var vill in acc.Villages) { //if (vill.Troops.Researched.Count == 0) TaskExecutor.AddTask(acc, new UpdateTroops() { ExecuteAt = DateTime.Now, vill = vill }); TroopsHelper.ReStartResearchAndImprovement(acc, vill); TroopsHelper.ReStartTroopTraining(acc, vill); BuildingHelper.ReStartBuilding(acc, vill); BuildingHelper.ReStartDemolishing(acc, vill); MarketHelper.ReStartSendingToMain(acc, vill); ReStartCelebration(acc, vill); VillageHelper.SetNextRefresh(acc, vill); if (vill.FarmingNonGold.OasisFarmingEnabled) { TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new AttackOasis() { Vill = vill }); } // Remove in later updates! if (vill.Settings.RefreshMin == 0) { vill.Settings.RefreshMin = 30; } if (vill.Settings.RefreshMax == 0) { vill.Settings.RefreshMax = 60; } } // Remove in later updates! if (acc.Hero.Settings.MinUpdate == 0) { acc.Hero.Settings.MinUpdate = 40; } if (acc.Hero.Settings.MaxUpdate == 0) { acc.Hero.Settings.MaxUpdate = 80; } // Hero update info if (acc.Hero.Settings.AutoRefreshInfo) { Random ran = new Random(); TaskExecutor.AddTask(acc, new HeroUpdateInfo() { ExecuteAt = DateTime.Now.AddMinutes(ran.Next(40, 80)), Priority = Tasks.BotTask.TaskPriority.Low }); } }
/// <summary> /// Will be called before each task to update resources/msg?,villages,quests,hero health, adventures num, gold/silver /// </summary> /// <param name="acc">Account</param> /// <returns>True if successful, false if error</returns> private static bool PreTaskRefresh(Account acc) { var html = acc.Wb.Html; try { //check & update dorf1/dorf2 if (!UpdateAccountObject.UpdateVillages(html, acc)) { return(false); //Web browser not initiali } var activeVill = acc.Villages.FirstOrDefault(x => x.Active); //update dorf1/dorf2 if (acc.Wb.CurrentUrl.Contains("dorf1")) { UpdateDorf1Info(acc); } else if (acc.Wb.CurrentUrl.Contains("dorf2")) { UpdateDorf2Info(acc); } acc.AccInfo.CulturePoints = RightBarParser.GetCulurePoints(html, acc.AccInfo.ServerVersion); var villExpansionReady = acc.Villages.FirstOrDefault(x => x.Expansion.ExpensionAvailable); if (acc.AccInfo.CulturePoints.MaxVillages > acc.AccInfo.CulturePoints.VillageCount && villExpansionReady != null) { villExpansionReady.Expansion.ExpensionAvailable = false; TaskExecutor.AddTaskIfNotExists(acc, new SendSettlers() { ExecuteAt = DateTime.Now, vill = villExpansionReady }); } acc.AccInfo.Tribe = LeftBarParser.GetAccountTribe(acc, html); acc.Quests = RightBarParser.GetQuests(html); var goldSilver = RightBarParser.GetGoldAndSilver(html, acc.AccInfo.ServerVersion); acc.AccInfo.Gold = goldSilver[0]; acc.AccInfo.Silver = goldSilver[1]; acc.AccInfo.PlusAccount = RightBarParser.HasPlusAccount(html, acc.AccInfo.ServerVersion); //Check reports/msg count if (MsgParser.UnreadMessages(html, acc.AccInfo.ServerVersion) > 0 && !acc.Wb.CurrentUrl.Contains("messages.php") && !IsTaskOnQueue(acc, typeof(ReadMessage))) { TaskExecutor.AddTask(acc, new ReadMessage() { ExecuteAt = DateTime.Now.AddMilliseconds(AccountHelper.Delay() * 30) }); } //update loyalty of village activeVill.Res.FreeCrop = RightBarParser.GetFreeCrop(html); activeVill.Res.Capacity = ResourceParser.GetResourceCapacity(html, acc.AccInfo.ServerVersion); activeVill.Res.Stored = ResourceParser.GetResources(html); float ratio = (float)activeVill.Res.Stored.Resources.Crop / activeVill.Res.Capacity.GranaryCapacity; if (ratio >= 0.99 && acc.AccInfo.Gold >= 3 && activeVill.Market.Npc.Enabled && (activeVill.Market.Npc.NpcIfOverflow || !MarketHelper.NpcWillOverflow(activeVill))) { //npc crop! TaskExecutor.AddTaskIfNotExistInVillage(acc, activeVill, new NPC() { ExecuteAt = DateTime.MinValue, vill = activeVill }); } if (acc.Settings.AutoActivateProductionBoost && CheckProductionBoost(acc)) { TaskExecutor.AddTask(acc, new TTWarsPlusAndBoost() { ExecuteAt = DateTime.Now.AddSeconds(1) }); } acc.Hero.AdventureNum = HeroParser.GetAdventureNum(html, acc.AccInfo.ServerVersion); acc.Hero.Status = HeroParser.HeroStatus(html, acc.AccInfo.ServerVersion); acc.Hero.HeroInfo.Health = HeroParser.GetHeroHealth(html, acc.AccInfo.ServerVersion); bool heroReady = (acc.Hero.HeroInfo.Health > acc.Hero.Settings.MinHealth && acc.Hero.Settings.AutoSendToAdventure && acc.Hero.Status == Hero.StatusEnum.Home && acc.Hero.NextHeroSend < DateTime.Now); // Update adventures if (heroReady && (acc.Hero.AdventureNum != acc.Hero.Adventures.Count() || HeroHelper.AdventureInRange(acc))) //update adventures { AddTaskIfNotExists(acc, new StartAdventure() { ExecuteAt = DateTime.Now.AddSeconds(10) }); } if (acc.Hero.AdventureNum == 0 && acc.Hero.Settings.BuyAdventures) //for UNL servers, buy adventures { AddTaskIfNotExists(acc, new TTWarsBuyAdventure() { ExecuteAt = DateTime.Now.AddSeconds(5) }); } if (acc.Hero.Status == Hero.StatusEnum.Dead && acc.Hero.Settings.AutoReviveHero) //if hero is dead, revive him { AddTaskIfNotExists(acc, new ReviveHero() { ExecuteAt = DateTime.Now.AddSeconds(5), vill = AccountHelper.GetHeroReviveVillage(acc) }); } if (HeroParser.LeveledUp(html) && acc.Hero.Settings.AutoSetPoints) { AddTaskIfNotExists(acc, new HeroSetPoints() { ExecuteAt = DateTime.Now }); } return(true); } catch (Exception e) { Console.WriteLine("Error in PreTask " + e.Message + "\n\nStack Trace: " + e.StackTrace + "\n-----------------------"); return(false); } }