Exemplo n.º 1
0
 private Building[] InitializeArray(int length, Account acc)
 {
     Building[] array = new Building[length];
     for (int i = 0; i < length; ++i)
     {
         var building = new Building();
         building.Init(i + 1, 0, 0, false);
         array[i] = building;
     }
     array[39].Type = BuildingsData.GetTribesWall(acc.AccInfo.Tribe);
     array[38].Type = Classificator.BuildingEnum.RallyPoint;
     return(array);
 }
        public static List <Building> GetBuildings(Account acc, HtmlAgilityPack.HtmlDocument htmlDoc)
        {
            List <Building> buildings = new List <Building>();
            var             villMap   = htmlDoc.GetElementbyId("village_map");

            if (villMap == null)
            {
                return(buildings);
            }

            var fields = villMap.ChildNodes.Where(x => x.Name == "div").ToList();

            for (byte i = 0; i < fields.Count; i++)
            {
                var vals = fields[i].GetAttributeValue("class", "").Split(' ');

                var location = (int)Parser.RemoveNonNumeric(vals.FirstOrDefault(x => x.StartsWith("a")));
                if (location <= 18 || location > 40)
                {
                    continue;
                }

                var gid = Convert.ToByte(vals.FirstOrDefault(x => x.StartsWith("g")).Replace("g", ""));

                byte lvl;
                // TODO: aid
                var lvlNode = fields[i].Descendants().FirstOrDefault(x => x.HasClass("aid" + location));
                if (lvlNode == null)
                {
                    lvl = 0;
                }
                else
                {
                    lvl = Convert.ToByte(lvlNode.InnerText);
                }

                var uc = fields[i].Descendants().FirstOrDefault(x => x.HasClass("underConstruction")) != null;
                //var b = fields[i].Child
                var building = new Building();
                buildings.Add(building.Init(
                                  location,
                                  lvl,//Convert.ToByte(vals[4].Replace("level", "")),
                                  gid,
                                  uc
                                  ));
            }
            buildings.FirstOrDefault(x => x.Id == 39).Type = Classificator.BuildingEnum.RallyPoint;
            buildings.FirstOrDefault(x => x.Id == 40).Type = BuildingsData.GetTribesWall(acc.AccInfo.Tribe);
            return(buildings);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the building task to the village list of building tasks. Restarts BotTask UpgradeBuilding if needed.
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="vill">Village</param>
        /// <param name="task">BuildingTask to add</param>
        /// <param name="bottom">Whether to insert the BuildingTask on the bottom of the list</param>
        /// <returns>Whether the method completed successfully</returns>
        public static bool AddBuildingTask(Account acc, Village vill, BuildingTask task, bool bottom = true, bool restart = true)
        {
            if (vill == null)
            {
                return(false);
            }

            //check wall
            if (IsWall(task.Building))
            {
                var wall = BuildingsData.GetTribesWall(acc.AccInfo.Tribe);
                // check type
                if (task.Building != wall)
                {
                    task.Building = wall;
                }
                // check position
                if (task.BuildingId != 40)
                {
                    task.BuildingId = 40;
                }
            }
            // check rally point
            else if (task.Building == BuildingEnum.Site)
            {
                // check position
                if (task.BuildingId != 39)
                {
                    task.BuildingId = 39;
                }
            }
            // other building
            else if (task.BuildingId == null ||
                     vill.Build.Buildings.Any(x => x.Id == task.BuildingId &&
                                              x.Type != task.Building &&
                                              x.Type != BuildingEnum.Site))
            {
                //Check if bot has any space to build new buildings, otherwise return
                if (!FindBuildingId(vill, task))
                {
                    return(false);
                }
            }

            // checking multiple building
            // you need at least one at level 20 before building other
            if (BuildingsData.CanHaveMultipleBuildings(task.Building))
            {
                if (task.ConstructNew)
                {
                    // Highest level building
                    var highestLvl = vill.Build
                                     .Buildings
                                     .Where(x => x.Type == task.Building)
                                     .OrderByDescending(x => x.Level)
                                     .FirstOrDefault();

                    if (highestLvl != null &&
                        highestLvl.Level != BuildingsData.MaxBuildingLevel(acc, task.Building))
                    {
                        task.BuildingId = highestLvl.Id;
                    }
                }
            }
            else if (!IsResourceField(task.Building))
            {
                var buildings = vill.Build.Buildings.Where(x => x.Type == task.Building);
                if (buildings.Count() > 0)
                {
                    var id = buildings.First().Id;
                    if (id != task.BuildingId)
                    {
                        task.BuildingId = id;
                    }
                }
            }

            if (bottom)
            {
                vill.Build.Tasks.Add(task);
            }
            else
            {
                vill.Build.Tasks.Insert(0, task);
            }

            if (acc.Wb != null && restart)
            {
                ReStartBuilding(acc, vill);
            }
            return(true);
        }