public bool TroopsCountRecieved(Account acc, int[] troopsAtHome) { // Attack with all offensive troops for (int i = 0; i < 10; i++) { var troop = TroopsHelper.TroopFromInt(acc, i); if (!TroopsData.IsTroopOffensive(troop)) { continue; } base.TroopsMovement.Troops[i] = troopsAtHome[i]; } // Hero if (troopsAtHome.Length == 11 && troopsAtHome[10] == 1) { base.TroopsMovement.Troops[10] = 1; } // Check if we have enough offensive troops to send var upkeep = TroopsHelper.GetTroopsUpkeep(acc, base.TroopsMovement.Troops); if (upkeep < this.Vill.FarmingNonGold.MinTroops) { var log = $"Village {Vill.Name} does not have enough offensive troops to attack the oasis!"; log += $"Required {this.Vill.FarmingNonGold.MinTroops}, but only {upkeep} (crop consumption) "; log += "of off was in the village. Bot won't send the attack."; acc.Wb.Log(log); return(false); } return(true); }
/// <summary> /// Populate the troops array with negative values - which means bot will send /// all available units of that type /// </summary> private int[] SendAllTroops() { var ret = new int[11]; var acc = GetSelectedAcc(); for (int i = 0; i < 10; i++) { if (TroopsData.IsTroopOffensive(acc, i) || i == 6 /* Rams */) { ret[i] = -1; } } return(ret); }
/// <summary> /// When user wants to train a new troop, we need to first upgrade buildings required and then research+improve the troop /// </summary> /// <param name="acc">Account</param> /// <param name="vill">Village</param> /// <param name="troop">Troop we want to research</param> /// <return>True if we have all prerequisite buildings, false otherwise</return> public static bool AddBuildingsForTroop(Account acc, Village vill, TroopsEnum troop) { bool ret = true; //TODO: finish this. If already on the BuildingList, just add the link for PostTask that after the last building gets built to research the unit var prerequisites = TroopsData.GetBuildingPrerequisites(troop); if (prerequisites.Count == 0) { return(ret); } foreach (var prerequisite in prerequisites) { if (!vill.Build.Buildings.Any(x => x.Level >= prerequisite.Level && x.Type == prerequisite.Building)) { ret = false; AddBuildingPrerequisites(acc, vill, prerequisite.Building); } } return(ret); }
public bool TroopsCountRecieved(Account acc, int[] troopsAtHome) { int upkeepSent = 0; for (int i = 0; i < 10; i++) { var troop = TroopsHelper.TroopFromInt(acc, i); if (!TroopsData.IsTroopDefensive(troop) || troopsAtHome[i] == 0) { continue; } var upkeep = TroopSpeed.GetTroopUpkeep(troop); int sendAmount = troopsAtHome[i]; int toSend = this.DeffAmount.Amount / upkeep; bool finished = false; if (toSend - upkeepSent < sendAmount) { // If we have enough troops, no other tasks need to be executed this.NextTask = null; finished = true; sendAmount = toSend; } base.TroopsMovement.Troops[i] = sendAmount; upkeepSent += sendAmount * upkeep; if (finished) { break; } } this.DeffAmount.Amount -= upkeepSent; acc.Wb.Log($"Bot will send {upkeepSent} deff (in upkeep) from {this.Vill.Name} to {this.TargetVillage}. Still needed {this.DeffAmount.Amount} deff"); return(true); }
public override async Task <TaskRes> Execute(Account acc) { TaskExecutor.RemoveTaskTypes(acc, typeof(UpdateDorf1), Vill, this); TaskExecutor.RemoveTaskTypes(acc, typeof(UpdateDorf2), Vill, this); await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); // Update dorf1 await Task.Delay(AccountHelper.Delay()); await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); // Update dorf2 // On new village import the building tasks if (ImportTasks && !string.IsNullOrEmpty(acc.NewVillages.BuildingTasksLocationNewVillage)) { IoHelperCore.AddBuildTasksFromFile(acc, Vill, acc.NewVillages.BuildingTasksLocationNewVillage); } await UpdateTroopsResearchedAndLevels(acc); await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); await Task.Delay(AccountHelper.Delay()); await UpdateTroopsTraining(acc); var firstTroop = TroopsData.TribeFirstTroop(acc.AccInfo.Tribe); Vill.Troops.TroopToTrain = firstTroop; Vill.Troops.Researched.Add(firstTroop); if (await VillageHelper.EnterBuilding(acc, Vill, Classificator.BuildingEnum.TownHall)) { // Village has town hall, parse celebration duration Vill.Expansion.CelebrationEnd = TimeParser.GetCelebrationTime(acc.Wb.Html); } return(TaskRes.Executed); }
public override async Task <TaskRes> Execute(Account acc) { var building = Vill.Build.Buildings .FirstOrDefault(x => x.Type == Classificator.BuildingEnum.Residence || x.Type == Classificator.BuildingEnum.Palace || x.Type == Classificator.BuildingEnum.CommandCenter ); if (!await VillageHelper.EnterBuilding(acc, building, "&s=1")) { return(TaskRes.Executed); } var settler = TroopsData.TribeSettler(acc.AccInfo.Tribe); var troopNode = acc.Wb.Html.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("u" + (int)settler)); if (troopNode == null) { acc.Wb.Log("No new settler can be trained, probably because 3 settlers are already (being) trained"); SendSettlersTask(acc); return(TaskRes.Executed); } while (!troopNode.HasClass("details")) { troopNode = troopNode.ParentNode; } var div = troopNode.Descendants("div"); Vill.Troops.Settlers = (int)Parser.RemoveNonNumeric(div.FirstOrDefault(x => x.HasClass("tit")).Descendants("span").FirstOrDefault().InnerText); string innertext = ""; switch (acc.AccInfo.ServerVersion) { case Classificator.ServerVersionEnum.T4_4: innertext = troopNode.ChildNodes.First(x => x.Name == "a").InnerText; break; case Classificator.ServerVersionEnum.T4_5: // no expansion slot if (div.FirstOrDefault(x => x.HasClass("noExpansionSlot")) != null) { if (Vill.Troops.Settlers >= 3) { if (acc.NewVillages.AutoSettleNewVillages) { TaskExecutor.AddTaskIfNotExists(acc, new SendSettlers() { ExecuteAt = DateTime.Now.AddHours(-3), Vill = this.Vill, // For high speed servers, you want to train settlers asap Priority = 1000 < acc.AccInfo.ServerSpeed ? TaskPriority.High : TaskPriority.Medium, }); } acc.Wb.Log("Have enoung settlers"); } else { acc.Wb.Log("Don't have enough expansion slot or settlers are training."); } return(TaskRes.Executed); } innertext = div.FirstOrDefault(x => x.HasClass("cta")).Descendants("a").FirstOrDefault().InnerText; break; } var maxNum = Parser.RemoveNonNumeric(innertext); Vill.Troops.Settlers = (int)TroopsParser.ParseAvailable(troopNode); var costNode = troopNode.Descendants("div").FirstOrDefault(x => x.HasClass("resourceWrapper")); var cost = ResourceParser.GetResourceCost(costNode); if (!ResourcesHelper.IsEnoughRes(Vill, cost.ToArray())) { ResourcesHelper.NotEnoughRes(acc, Vill, cost, this); return(TaskRes.Executed); } acc.Wb.Driver.ExecuteScript($"document.getElementsByName('t10')[0].value='{maxNum}'"); await Task.Delay(AccountHelper.Delay()); // Click Train button await TbsCore.Helpers.DriverHelper.ExecuteScript(acc, "document.getElementById('s1').click()"); Vill.Troops.Settlers += (int)maxNum; if (Vill.Troops.Settlers < 3) { // random train next settlers after 30 - 60 mins var ran = new Random(); this.NextExecute = DateTime.Now.AddMinutes(ran.Next(30, 60)); } else { if (acc.NewVillages.AutoSettleNewVillages) { SendSettlersTask(acc); } } return(TaskRes.Executed); }
public override async Task <TaskRes> Execute(Account acc) { var building = Vill.Build.Buildings .FirstOrDefault(x => x.Type == Classificator.BuildingEnum.Residence || x.Type == Classificator.BuildingEnum.Palace || x.Type == Classificator.BuildingEnum.CommandCenter ); if (!await VillageHelper.EnterBuilding(acc, Vill, building, "&s=1")) { return(TaskRes.Executed); } var settler = TroopsData.TribeSettler(acc.AccInfo.Tribe); var troopNode = acc.Wb.Html.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("u" + (int)settler)); if (troopNode == null) { acc.Wb.Log("No new settler can be trained, probably because 3 settlers are already (being) trained"); SendSettlersTask(acc); return(TaskRes.Executed); } while (!troopNode.HasClass("details")) { troopNode = troopNode.ParentNode; } var maxNum = Parser.RemoveNonNumeric(troopNode.ChildNodes.First(x => x.Name == "a").InnerText); var available = TroopsParser.ParseAvailable(troopNode); var costNode = acc.Wb.Html.DocumentNode.Descendants("div").FirstOrDefault(x => x.HasClass("resourceWrapper")); var cost = ResourceParser.GetResourceCost(costNode); if (!ResourcesHelper.IsEnoughRes(Vill, cost.ToArray())) { ResourcesHelper.NotEnoughRes(acc, Vill, cost, this); return(TaskRes.Executed); } acc.Wb.Driver.ExecuteScript($"document.getElementsByName('t10')[0].value='{maxNum}'"); await Task.Delay(AccountHelper.Delay()); // Click Train button await TbsCore.Helpers.DriverHelper.ExecuteScript(acc, "document.getElementById('s1').click()"); Vill.Troops.Settlers = (int)available + (int)maxNum; var training = TroopsHelper.TrainingDuration(acc.Wb.Html); if (training < DateTime.Now) { training = DateTime.Now; } if (Vill.Troops.Settlers < 3) { //In 1 minute, do the same task (to get total of 3 settlers) this.NextExecute = training.AddSeconds(3); } else { if (acc.NewVillages.AutoSettleNewVillages) { SendSettlersTask(acc); } } return(TaskRes.Executed); }