Esempio n. 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);
        }
Esempio n. 2
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?
 }
Esempio n. 3
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);
        }
Esempio n. 4
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
     });
 }
Esempio n. 5
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
     });
 }
Esempio n. 6
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);
        }
Esempio n. 7
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
     });
 }
Esempio n. 8
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);
        }