예제 #1
0
        /// <summary>
        /// PostTask. Repeats sending resources and training troops. Needs to fill up training above X hours.
        /// </summary>
        /// <param name="htmlDoc">html of the page</param>
        /// <param name="acc">Account</param>
        public void RepeatTrainingCycle(HtmlDocument htmlDoc, Account acc)
        {
            var trainingEnds = TroopsHelper.GetTrainingTimeForBuilding(building, vill);

            // If sendRes is activated and there are some resources left to send
            if (vill.Settings.SendRes && MarketHelper.GetResToMainVillage(this.vill).Sum() > 0)
            {
                // Check If all troops are filled in this vill before sending resources back to main village
                if (TroopsHelper.EverythingFilled(acc, vill))
                {
                    TaskExecutor.AddTask(acc, new SendResToMain()
                    {
                        vill = this.vill, ExecuteAt = DateTime.MinValue.AddHours(1)
                    });
                }
            }
            if (vill.Settings.GetRes)
            {
                var nextCycle = trainingEnds.AddHours(-acc.Settings.FillInAdvance);
                if (nextCycle < DateTime.Now)
                {
                    // Send resources asap.
                    nextCycle = DateTime.MinValue.AddHours(3);
                }
                else
                {
                    TaskExecutor.AddTask(acc, new UpdateDorf1()
                    {
                        ExecuteAt = nextCycle,
                        vill      = this.vill
                    });
                }

                TaskExecutor.AddTask(acc, new SendResFillTroops()
                {
                    ExecuteAt  = nextCycle.AddMilliseconds(1),
                    vill       = AccountHelper.GetMainVillage(acc),
                    TargetVill = this.vill,
                    TrainTask  = this
                });
                this.NextExecute = nextCycle.AddMinutes(30); //will get overwritten in sendResFillTroops
                TaskExecutor.ReorderTaskList(acc);
            }
            else
            {
                var later = DateTime.Now.AddMinutes(1);
                // Don't training again sooner than after 10min
                if (later > trainingEnds)
                {
                    trainingEnds = later;
                }

                this.NextExecute = trainingEnds;
            }
        }