Exemplo n.º 1
0
        public override async Task <TaskRes> Execute(HtmlDocument htmlDoc, ChromeDriver wb, Files.Models.AccModels.Account acc)
        {
            var building = vill.Build.Buildings.FirstOrDefault(x => x.Type == Classificator.BuildingEnum.Marketplace);

            if (building == null)
            {
                //update dorg, no buildingId found?
                TaskExecutor.AddTask(acc, new UpdateDorf2()
                {
                    ExecuteAt = DateTime.Now, vill = vill
                });
                Console.WriteLine($"There is no {building} in this village!");
                return(TaskRes.Executed);
            }
            await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id={building.Id}&t=5");

            //get troop resource/time cost
            var troopCost = TroopCost.GetResourceCost(TrainTask.Troop, TrainTask.Great);

            var trainNum = TroopsHelper.TroopsToFill(acc, TargetVill, TrainTask.Troop, TrainTask.Great);

            //how many troops we can train with resources that we have
            var mainVillResStored   = ResourcesHelper.ResourcesToArray(vill.Res.Stored.Resources);
            var targetVillStoredRes = ResourcesHelper.ResourcesToArray(TargetVill.Res.Stored.Resources);

            // Max troops we can train with resources that we have
            var maxTroopsToTrain = ResourcesHelper.MaxTroopsToTrain(mainVillResStored, targetVillStoredRes, troopCost);

            // If we don't have enough rsoruces to train the number of troops that we want, we will train max number of troops that we can
            if (maxTroopsToTrain < trainNum)
            {
                trainNum = maxTroopsToTrain;
            }

            //calculate how many resources we need to train trainNum of troops
            long[] neededRes = troopCost.Select(x => x * trainNum).ToArray();

            //if we have already enough resources in the target village, no need to send anything
            if (ResourcesHelper.EnoughRes(targetVillStoredRes, neededRes))
            {
                this.TrainTask.ExecuteAt = DateTime.Now;
                TaskExecutor.ReorderTaskList(acc);
                return(TaskRes.Executed);
            }

            //amount of resources we want to transit to target village
            var sendRes = ResourcesHelper.SendAmount(targetVillStoredRes, neededRes);

            // Check how many merchants we have. If we have 0, wait till some come back.

            var transitTimespan = await MarketHelper.MarketSendResource(acc, sendRes, TargetVill, this);

            //train the troops in the target village after we send the needed
            this.TrainTask.ExecuteAt = DateTime.Now.Add(transitTimespan).AddSeconds(5);
            TaskExecutor.ReorderTaskList(acc);

            //TODO: Update marketplace sending
            return(TaskRes.Executed);
        }
Exemplo n.º 2
0
        public override async Task <TaskRes> Execute(Account acc)
        {
            await base.Execute(acc);

            if (!await VillageHelper.EnterBuilding(acc, Vill, Classificator.BuildingEnum.Marketplace, "&t=5"))
            {
                return(TaskRes.Executed);
            }


            //get troop resource/time cost
            var troopCost = TroopCost.GetResourceCost(TrainTask.Troop, TrainTask.Great);

            var trainNum = TroopsHelper.TroopsToFill(acc, TargetVill, TrainTask.Troop, TrainTask.Great);

            //how many troops we can train with resources that we have
            var mainVillResStored   = Vill.Res.Stored.Resources.ToArray();
            var targetVillStoredRes = TargetVill.Res.Stored.Resources.ToArray();

            // Max troops we can train with resources that we have
            var maxTroopsToTrain = ResourcesHelper.MaxTroopsToTrain(mainVillResStored, targetVillStoredRes, troopCost);

            // If we don't have enough rsoruces to train the number of troops that we want, we will train max number of troops that we can
            if (maxTroopsToTrain < trainNum)
            {
                trainNum = maxTroopsToTrain;
            }

            //calculate how many resources we need to train trainNum of troops
            long[] neededRes = troopCost.Select(x => x * trainNum).ToArray();

            //if we have already enough resources in the target village, no need to send anything
            if (ResourcesHelper.IsEnoughRes(targetVillStoredRes, neededRes))
            {
                this.TrainTask.ExecuteAt = DateTime.Now;
                TaskExecutor.ReorderTaskList(acc);
                return(TaskRes.Executed);
            }

            //amount of resources we want to transit to target village
            var sendRes = ResourcesHelper.SendAmount(targetVillStoredRes, neededRes);

            // Check how many merchants we have. If we have 0, wait till some come back.

            var transitTimespan = await MarketHelper.MarketSendResource(acc, sendRes, TargetVill, this);

            //train the troops in the target village after we send the needed
            this.TrainTask.ExecuteAt = DateTime.Now.Add(transitTimespan).AddSeconds(5);
            TaskExecutor.ReorderTaskList(acc);

            //TODO: Update marketplace sending
            return(TaskRes.Executed);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return the number of troops that should be trained to fill up the training building
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="vill">Village where we want to train the troops</param>
        /// <param name="troop">Troop enumeration</param>
        /// <param name="great">GB/GS</param>
        /// <returns></returns>
        internal static long TroopsToFill(Account acc, Village vill, TroopsEnum troop, bool great)
        {
            var troopCost = TroopCost.GetResourceCost(troop, great);
            var trainTime = TroopCost.GetTrainingTime(acc, vill, troop, great);

            //how many troops we want to train
            // Take into account how many troop are already training
            var trainBuilding = TroopsHelper.GetTroopBuilding(troop, great);
            var trainingTime  = TroopsHelper.GetTrainingTimeForBuilding(trainBuilding, vill);

            var currentlyTrainingHours = (trainingTime - DateTime.Now).TotalHours;

            var fillForHours = acc.Settings.FillFor + acc.Settings.FillInAdvance - currentlyTrainingHours;

            return((long)Math.Ceiling(fillForHours / trainTime.TotalHours));
        }