public override async Task <TaskRes> Execute(HtmlDocument htmlDoc, ChromeDriver wb, Files.Models.AccModels.Account acc) { await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?tt=2&id=39"); int[] troopsAtHome = TroopsMovementParser.GetTroopsInRallyPoint(htmlDoc); for (int i = 0; i < 10; i++) { var troop = TroopsHelper.TroopFromInt(acc, i); if (TroopsHelper.IsTroopDefensive(troop)) { var upkeep = TroopSpeed.GetTroopUpkeep(troop); int sendAmount = troopsAtHome[i]; if (this.DeffAmount.DeffCount != null) { if (sendAmount * upkeep > this.DeffAmount.DeffCount) { // We have sent all needed deff sendAmount = (this.DeffAmount.DeffCount ?? 0) / upkeep; // Remove all other (linked) SendDeff bot tasks var list = new List <SendDeff> { this.NextDeffTask }; while (list.Last() != null) { list.Add(list.Last().NextDeffTask); } foreach (var task in list) { if (task == null) { continue; } acc.Tasks.Remove(task); } } else { this.DeffAmount.DeffCount -= sendAmount * upkeep; } } wb.ExecuteScript($"document.getElementsByName('t{i + 1 }')[0].value='{sendAmount}'"); } } //select coordinates wb.ExecuteScript($"document.getElementById('xCoordInput').value='{TargetVillage.x}'"); wb.ExecuteScript($"document.getElementById('yCoordInput').value='{TargetVillage.y}'"); await Task.Delay(AccountHelper.Delay()); //Select reinforcement string script = "var radio = document.getElementsByClassName(\"radio\");for(var i = 0; i < radio.length; i++){"; script += $"if(radio[i].value == '2') radio[i].checked = \"checked\"}}"; wb.ExecuteScript(script); await Task.Delay(2 *AccountHelper.Delay()); wb.ExecuteScript($"document.getElementById('btn_ok').click()"); await Task.Delay(2 *AccountHelper.Delay()); // Confirm wb.ExecuteScript($"document.getElementById('btn_ok').click()"); //Click send return(TaskRes.Executed); }