예제 #1
0
        /// <summary>
        /// Calculates total upkeep of the troops int[]
        /// </summary>
        public static long GetTroopsUpkeep(Account acc, int[] troops)
        {
            if (troops.Length < 10)
            {
                throw new Exception("Troops length not not enough!");
            }
            long upkeep = 0;

            for (int i = 0; i < 10; i++)
            {
                var troop = TroopsHelper.TroopFromInt(acc, i);
                upkeep += troops[i] * TroopSpeed.GetTroopUpkeep(troop);
            }
            return(upkeep);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }