示例#1
0
        public static void AddBuildTasksFromFile(Account acc, Village vill, string location)
        {
            List <BuildingTask> tasks = new List <BuildingTask>();

            try
            {
                using (StreamReader sr = new StreamReader(location))
                {
                    // If .trbc file, decode into List<BuildTask>
                    if (Path.GetExtension(location).Equals(".TRBC", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var trbc = JsonConvert.DeserializeObject <TbRoot>(sr.ReadToEnd());
                        tasks = DecodeTrbc(trbc);
                    }
                    else
                    {
                        tasks = JsonConvert.DeserializeObject <List <BuildingTask> >(sr.ReadToEnd());
                    }
                }
            }
            catch (Exception e) { return; } // User canceled

            foreach (var task in tasks)
            {
                BuildingHelper.AddBuildingTask(acc, vill, task);
            }
            BuildingHelper.RemoveCompletedTasks(vill, acc);
        }
示例#2
0
        private static (string, bool) GetUrlGeneralTask(Village vill, BuildingTask task)
        {
            // Check if there is already a different building in this spot
            if (task.BuildingId == null || vill.Build.Buildings.FirstOrDefault(x => x.Id == task.BuildingId).Type != task.Building)
            {
                var targetBuilding = vill.Build.Buildings.FirstOrDefault(x => x.Type == task.Building);
                // Re-select the buildingId
                if (targetBuilding != null && !task.ConstructNew)
                {
                    task.BuildingId = targetBuilding.Id;
                }
                else // there's already a building in this spot, construct a building elsewhere
                {
                    if (!BuildingHelper.FindBuildingId(vill, task))
                    {
                        return(null, false);
                    }
                }
            }

            var url = task.BuildingId.ToString();

            bool constructNew = false;

            // If there is no building in that space currently, construct a new building
            if (vill.Build.Buildings.Any(x => x.Type == BuildingEnum.Site && x.Id == task.BuildingId))
            {
                url         += "&category=" + (int)BuildingsData.GetBuildingsCategory(task.Building);
                constructNew = true;
            }
            return(url, constructNew);
        }
示例#3
0
 public static void SupplyVillagePlan(Account acc, Village vill)
 {
     FarmVillagePlan(acc, vill);
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Marketplace, Level = 20
     });
     //market center?
 }
示例#4
0
        public static void AddBuildTasksFromFile(Account acc, Village vill, string location)
        {
            List <BuildingTask> tasks = null;

            try
            {
                using (StreamReader sr = new StreamReader(location))
                {
                    tasks = JsonConvert.DeserializeObject <List <BuildingTask> >(sr.ReadToEnd());
                }
            }
            catch (Exception e) { return; } // User canceled

            foreach (var task in tasks)
            {
                BuildingHelper.AddBuildingTask(acc, vill, task);
            }
            BuildingHelper.RemoveCompletedTasks(vill, acc);
        }
示例#5
0
 public static void DeffVillagePlan(Account acc, Village vill)
 {
     FarmVillagePlan(acc, vill);
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Barracks, Level = 20
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Academy, Level = 1
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Smithy, Level = 20
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Marketplace, Level = 15
     });
 }
示例#6
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);
                }
            }
            BuildingHelper.RemoveDuplicateBuildingTasks(vill);
            return(ret);
        }
 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
     }
 }
示例#8
0
 public static void OffVillagePlan(Account acc, Village vill)
 {
     DeffVillagePlan(acc, vill);
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Academy, Level = 15
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Stable, Level = 20
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Workshop, Level = 1
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.RallyPoint, Level = 15
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.TournamentSquare, Level = 1
     });
 }
示例#9
0
        /// <summary>
        /// Upgrades storage of the village
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="vill">Village</param>
        /// <param name="building">Storage building</param>
        private static void UpgradeStorage(Account acc, Village vill, BuildingEnum building)
        {
            var task = new BuildingTask()
            {
                Building = building,
                TaskType = Classificator.BuildingType.General
            };

            var current = vill.Build.Buildings.FirstOrDefault(x =>
                                                              x.Type == building &&
                                                              (x.Level != 20 || (x.Level != 19 && x.UnderConstruction))
                                                              );

            if (current == null)
            {
                task.ConstructNew = true;
                task.Level        = 1;
            }
            else
            {
                task.Level = current.Level + 1;
            }
            BuildingHelper.AddBuildingTask(acc, vill, task, false);
        }
示例#10
0
 public static void FarmVillagePlan(Account acc, Village vill)
 {
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.AutoUpgradeResFields, Level = 10, ResourceType = ResTypeEnum.AllResources, BuildingStrategy = BuildingStrategyEnum.BasedOnRes
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Warehouse, Level = 1
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Granary, Level = 1
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.RallyPoint, Level = 1
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.MainBuilding, BuildingId = 26, Level = 5
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Warehouse, Level = 3
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Granary, Level = 3
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Residence, Level = 10
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Barracks, Level = 1
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.MainBuilding, BuildingId = 26, Level = 10
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Marketplace, Level = 1
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Warehouse, Level = 6
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Granary, Level = 6
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Warehouse, Level = 10
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Granary, Level = 10
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Warehouse, Level = 15
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Granary, Level = 15
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Warehouse, Level = 20
     });
     BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
     {
         TaskType = BuildingHelper.BuildingType.General, Building = Classificator.BuildingEnum.Granary, Level = 20
     });
 }
示例#11
0
        /// <summary>
        /// Method will create EquipHero BotTasks that will use resources needed
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="vill">Village to use resources in</param>
        /// <param name="neededRes">Needed resources</param>
        /// <param name="heroRes">Hero resources</param
        /// <param name="task">Potential BuildingTask that requires the resources</param>
        private static HeroEquip UseHeroResources(Account acc, Village vill, ref long[] neededRes, long[] heroRes, BuildingTask task = null)
        {
            var useRes = new List <(Classificator.HeroItemEnum, int)>();

            for (int i = 0; i < 4; i++)
            {
                if (neededRes[i] == 0 || heroRes[i] == 0)
                {
                    continue;
                }

                long resToBeUsed = RoundUpTo100(neededRes[i]);
                if (heroRes[i] < resToBeUsed)
                {
                    resToBeUsed = heroRes[i];
                }
                neededRes[i] -= resToBeUsed;

                HeroItemEnum item = HeroItemEnum.Others_Wood_0;
                switch (i)
                {
                case 0:
                    item = HeroItemEnum.Others_Wood_0;
                    break;

                case 1:
                    item = HeroItemEnum.Others_Clay_0;
                    break;

                case 2:
                    item = HeroItemEnum.Others_Iron_0;
                    break;

                case 3:
                    item = HeroItemEnum.Others_Crop_0;
                    break;
                }
                useRes.Add((item, (int)resToBeUsed));
            }

            var heroEquip = new HeroEquip()
            {
                Items     = useRes,
                ExecuteAt = DateTime.Now.AddHours(-2), // -2 since sendRes is -1
                Vill      = vill
            };

            TaskExecutor.AddTask(acc, heroEquip);

            // A BuildTask needed the resources. If it was auto-build res fields task, make a new
            // general building task - so resources actually get used for intended building upgrade
            if (task != null && task.TaskType == Classificator.BuildingType.AutoUpgradeResFields)
            {
                var building = vill.Build.Buildings.FirstOrDefault(x => x.Id == task.BuildingId);
                var lvl      = building.Level;
                if (building.UnderConstruction)
                {
                    lvl++;
                }
                BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
                {
                    TaskType   = Classificator.BuildingType.General,
                    Building   = task.Building,
                    BuildingId = task.BuildingId,
                    Level      = ++lvl
                }, false);
            }

            return(heroEquip);
        }
示例#12
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
                });
            }
        }