예제 #1
0
        /// <summary>
        /// Will (re)start troop research and improvement for this village
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="vill">Village to start troops training</param>
        public static void ReStartResearchAndImprovement(Account acc, Village vill)
        {
            Classificator.TroopsEnum[] troops = { vill.Settings.BarracksTrain, vill.Settings.StableTrain, vill.Settings.WorkshopTrain };
            foreach (var troop in troops)
            {
                if (troop == TroopsEnum.None)
                {
                    continue;
                }

                // Research
                if (!vill.Troops.Researched.Contains(troop) &&
                    ((int)troop % 10) != 1)    // Don't try to research 1. troops of each tribe (clubs, phalanx...)
                {
                    if (TroopsHelper.AddBuildingsForTroop(acc, vill, troop))
                    {
                        //we already have all required buildings to research this troop
                        vill.Troops.ToResearch.Add(troop);
                        vill.Troops.ToImprove.Add(troop);
                        //We have all buildings needed to research the troop. Do it.
                        var researchTask = new ResearchTroop()
                        {
                            Vill = vill, ExecuteAt = DateTime.Now
                        };
                        TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, researchTask);
                    }
                    continue;
                }
                else
                {
                    vill.Troops.ToResearch.Remove(troop);
                }

                // Improvement
                if (vill.Troops.Levels != null)
                {
                    if (!vill.Troops.Levels.Exists(x => x.Troop == troop && x.Level == 20) && vill.Settings.AutoImprove)
                    {
                        vill.Troops.ToImprove.Add(troop);
                        if (vill.Build.Buildings.Any(x => x.Type == BuildingEnum.Smithy))
                        {
                            TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new ImproveTroop()
                            {
                                Vill = vill, ExecuteAt = DateTime.Now
                            });
                        }
                    }
                    else
                    {
                        vill.Troops.ToImprove.Remove(troop);
                    }
                }
            }
        }
예제 #2
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);
        }
예제 #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));
        }
예제 #4
0
        /// <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 = TroopsHelper.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);
        }
예제 #5
0
 public static void StartAccountTasks(Account acc)
 {
     // If we don't know server speed, go and get it
     if (acc.AccInfo.ServerSpeed == 0)
     {
         TaskExecutor.AddTaskIfNotExists(acc, new GetServerSpeed()
         {
             ExecuteAt = DateTime.MinValue.AddHours(2)
         });
     }
     if (acc.AccInfo.MapSize == 0)
     {
         TaskExecutor.AddTaskIfNotExists(acc, new GetMapSize()
         {
             ExecuteAt = DateTime.MinValue.AddHours(2)
         });
     }
     //FL
     if (acc.Farming.Enabled)
     {
         TaskExecutor.AddTaskIfNotExists(acc, new SendFLs()
         {
             ExecuteAt = DateTime.Now
         });
     }
     //research / improve / train troops
     foreach (var vill in acc.Villages)
     {
         //if (vill.Troops.Researched.Count == 0) TaskExecutor.AddTask(acc, new UpdateTroops() { ExecuteAt = DateTime.Now, vill = vill });
         TroopsHelper.ReStartResearchAndImprovement(acc, vill);
         if (!TroopsHelper.EverythingFilled(acc, vill))
         {
             TroopsHelper.ReStartTroopTraining(acc, vill);
         }
         BuildingHelper.ReStartBuilding(acc, vill);
         BuildingHelper.ReStartDemolishing(acc, vill);
         MarketHelper.ReStartSendingToMain(acc, vill);
         //todo
     }
 }
예제 #6
0
        public static void StartAccountTasks(Account acc)
        {
            // Get the server info (on first running the account)
            if (acc.AccInfo.ServerSpeed == 0 || acc.AccInfo.MapSize == 0)
            {
                TaskExecutor.AddTaskIfNotExists(acc, new GetServerInfo()
                {
                    ExecuteAt = DateTime.MinValue.AddHours(2)
                });
            }

            if (acc.AccInfo.Tribe == null)
            {
                TaskExecutor.AddTaskIfNotExists(acc, new GetTribe()
                {
                    ExecuteAt = DateTime.MinValue.AddHours(3)
                });
            }

            //FL
            if (acc.Farming.Enabled)
            {
                TaskExecutor.AddTaskIfNotExists(acc, new SendFLs()
                {
                    ExecuteAt = DateTime.Now
                });
            }

            // Bot sleep
            TaskExecutor.AddTaskIfNotExists(acc, new Sleep()
            {
                ExecuteAt = DateTime.Now + TimeHelper.GetWorkTime(acc),
                AutoSleep = true
            });

            // Access change
            var nextAccessChange = TimeHelper.GetNextProxyChange(acc);

            if (nextAccessChange != TimeSpan.MaxValue)
            {
                TaskExecutor.AddTaskIfNotExists(acc, new ChangeAccess()
                {
                    ExecuteAt = DateTime.Now + nextAccessChange
                });
            }
            //research / improve / train troops
            foreach (var vill in acc.Villages)
            {
                //if (vill.Troops.Researched.Count == 0) TaskExecutor.AddTask(acc, new UpdateTroops() { ExecuteAt = DateTime.Now, vill = vill });
                TroopsHelper.ReStartResearchAndImprovement(acc, vill);
                TroopsHelper.ReStartTroopTraining(acc, vill);
                BuildingHelper.ReStartBuilding(acc, vill);
                BuildingHelper.ReStartDemolishing(acc, vill);
                MarketHelper.ReStartSendingToMain(acc, vill);
                ReStartCelebration(acc, vill);
                VillageHelper.SetNextRefresh(acc, vill);
                if (vill.FarmingNonGold.OasisFarmingEnabled)
                {
                    TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new AttackOasis()
                    {
                        Vill = vill
                    });
                }

                // Remove in later updates!
                if (vill.Settings.RefreshMin == 0)
                {
                    vill.Settings.RefreshMin = 30;
                }
                if (vill.Settings.RefreshMax == 0)
                {
                    vill.Settings.RefreshMax = 60;
                }
            }
            // Remove in later updates!
            if (acc.Hero.Settings.MinUpdate == 0)
            {
                acc.Hero.Settings.MinUpdate = 40;
            }
            if (acc.Hero.Settings.MaxUpdate == 0)
            {
                acc.Hero.Settings.MaxUpdate = 80;
            }

            // Hero update info
            if (acc.Hero.Settings.AutoRefreshInfo)
            {
                Random ran = new Random();
                TaskExecutor.AddTask(acc, new HeroUpdateInfo()
                {
                    ExecuteAt = DateTime.Now.AddMinutes(ran.Next(40, 80)),
                    Priority  = Tasks.BotTask.TaskPriority.Low
                });
            }
        }