Ejemplo n.º 1
0
        public Vector2 BuildTownHall(Builder builder)
        {
            GoldMine goldMine = NearGoldMine(builder);

            switch (TOWN_HALL)
            {
            case 1:
                if (goldMine != null)
                {
                    return(goldMine.position + new Vector2(0, 4 * 32));
                }
                else
                {
                    return(Functions.CleanPosition(managerMap, 128, 128));
                }

            case 2:
                return((ManagerBuildings.goldMines[0].position + ManagerBuildings.goldMines[1].position) / 2);

            case 3:
                return((ManagerBuildings.goldMines[0].position + ManagerBuildings.goldMines[1].position + ManagerBuildings.goldMines[2].position) / 3);

            default:
                return(Functions.CleanPosition(managerMap, 128, 128));
            }
        }
Ejemplo n.º 2
0
        public void ConvertGoldMineToDescriptor_Ok()
        {
            var goldMine = new GoldMine();

            var goldMineDescriptor = goldMine.ToGoldMineDescriptor();

            Assert.AreEqual(goldMine.Stock[ResourcesType.Gold], goldMineDescriptor.Stock[ResourcesType.Gold]);
        }
Ejemplo n.º 3
0
        public Miner(ManagerBuildings managerBuildings, Unit worker)
        {
            goldMine = managerBuildings.buildings.Find((b) => (b.information as InformationBuilding).Type == Util.Buildings.GOLD_MINE) as GoldMine;
            townHall = managerBuildings.buildings.Find((b) => (b.information as InformationBuilding).Type == Util.Buildings.TOWN_HALL) as TownHall;

            this.worker           = worker;
            this.managerBuildings = managerBuildings;
        }
Ejemplo n.º 4
0
 public Unit[][] GenerateGrid(int xSize, int ySize)
 {
     Console.WriteLine("===Abstract Factory===");
     goldMinePrototype = (GoldMine)mapFactory.CreateSuperObstacle("Gold Mine", 0, 0);
     wonderPrototype   = (Wonder)mapFactory.CreateSuperObstacle("Wonder", 0, 0);
     stonePrototype    = (Stone)mapFactory.CreateObstacle("Stone", 0, 0);
     Console.WriteLine("========");
     Console.WriteLine("===Prototype===");
     //----------Testavimui
     //stonePrototype.TakeUnit(new Player());
     //goldMinePrototype.TakeUnit(new Player());
     //----------
     Grid = new Unit[ySize][];
     for (int y = 0; y < ySize; y++)
     {
         Grid[y] = new Unit[xSize];
         for (int x = 0; x < xSize; x++)
         {
             double obstacleValue = random.NextDouble();
             if (obstacleValue > CWonderThreshold && !IsInOuterZone(x, y) && !isNearbyObstacle(x, y))
             {
                 Grid[y][x] = (Unit)wonderPrototype.ShallowCopy();
                 Grid[y][x].SetCoordinates(x, y);
                 //----------Testavimui
                 //Console.WriteLine("Wonder original address " + wonderPrototype.GetHashCode() + " Wonder copy address " + Grid[y][x].GetHashCode());
                 //----------
             }
             else if (obstacleValue > CGoldMineThreshold && !IsInOuterZone(x, y) && !isNearbyObstacle(x, y))
             {
                 Grid[y][x] = (Unit)goldMinePrototype.ShallowCopy();
                 Grid[y][x].SetCoordinates(x, y);
                 //----------Testavimui
                 //Console.WriteLine("Gold Mine original address " + goldMinePrototype.GetHashCode() + " Gold Mine copy address " + Grid[y][x].GetHashCode());
                 //Console.WriteLine("Gold Mine Player original address " + goldMinePrototype.GetPlayer().GetHashCode() + " Gold Mine Player copy address " + Grid[y][x].GetPlayer().GetHashCode());
                 //----------
             }
             else if (obstacleValue > CStoneThreshold && !IsInOuterZone(x, y) && !isNearbyObstacle(x, y))
             {
                 //----------Testavimui
                 //Grid[y][x] = (Unit)stonePrototype.DeepCopy();
                 //----------
                 Grid[y][x] = (Unit)stonePrototype.ShallowCopy();
                 Grid[y][x].SetCoordinates(x, y);
                 //----------Testavimui
                 //Console.WriteLine("Stone original address " + stonePrototype.GetHashCode() + " Stone copy address " + Grid[y][x].GetHashCode());
                 //Console.WriteLine("Stone Player original address " + stonePrototype.GetPlayer().GetHashCode() + " Stone Player copy address " + Grid[y][x].GetPlayer().GetHashCode());
                 //----------
             }
             else
             {
                 Grid[y][x] = new Unit(x, y);
             }
         }
     }
     Console.WriteLine("========");
     return(Grid);
 }
 static void Main(string[] args)
 {
     var goldMine1 = new GoldMine()
     {
         Gold = 50
     };
     var goldMine2 = new GoldMine()
     {
         Gold = 50
     };
 }
Ejemplo n.º 6
0
 private GameObject MineWithGold()
 {
     foreach (GameObject mine in m_mines)
     {
         GoldMine goldMine = mine.GetComponent <GoldMine>();
         if (goldMine.goldLeft > 0)
         {
             return(mine);
         }
     }
     return(null);
 }
Ejemplo n.º 7
0
 void DetermineLocalBase()
 {
     if (hasAuthority)
     {
         baseMenu = BaseMenu.localBase.GetComponent <BaseMenu> ();
     }
     else
     {
         baseMenu = BaseMenu.otherBase.GetComponent <BaseMenu> ();
     }
     goldMine = baseMenu.goldMine.GetComponent <GoldMine>();
     target   = goldMine.gameObject;
 }
        public static void CalculateTargets()
        {
            collectors = ElixirCollector.Find();

            mines = GoldMine.Find();

            drills = DarkElixirDrill.Find();

            int collectorsCount = collectors != null?collectors.Count() : 0;

            int minesCount = mines != null?mines.Count() : 0;

            int drillsCount = drills != null?drills.Count() : 0;

            // Set total count of targets
            SmartFourFingersDeploy.TotalTargetsCount = collectorsCount + minesCount + drillsCount;

            // four corners
            var top    = new PointFT((float)GameGrid.DeployExtents.MaxX + 1, GameGrid.DeployExtents.MaxY + 4);
            var right  = new PointFT((float)GameGrid.DeployExtents.MaxX + 1, GameGrid.DeployExtents.MinY - 4);
            var bottom = new PointFT((float)GameGrid.DeployExtents.MinX - 1, GameGrid.DeployExtents.MinY - 4);
            var left   = new PointFT((float)GameGrid.DeployExtents.MinX - 1, GameGrid.DeployExtents.MaxY + 4);

            SetCore();

            var corners = new List <Tuple <PointFT, PointFT> >
            {
                new Tuple <PointFT, PointFT>(top, right),
                new Tuple <PointFT, PointFT>(bottom, right),
                new Tuple <PointFT, PointFT>(bottom, left),
                new Tuple <PointFT, PointFT>(top, left)
            };

            // loop throw the 4 sides and count targets on each side
            var targetsAtLine = new List <int>();

            foreach (var l in corners)
            {
                var colCount = collectors.Where(t => t.Location.GetCenter().
                                                IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0;
                var minCount = mines.Where(t => t.Location.GetCenter().
                                           IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0;
                var drillCount = drills.Where(t => t.Location.GetCenter().
                                              IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0;
                var total = colCount + minCount + drillCount;

                targetsAtLine.Add(total);
            }

            SmartFourFingersDeploy.TargetsAtLine = targetsAtLine;
        }
Ejemplo n.º 9
0
    public void GenerateMap(Transform toPos, int id, int level, Box box, bool isGoldPlayer = false)
    {
        int     typeGoldMine = (int)UnityEngine.Random.Range(0, 2.9f);
        int     randomAngle  = UnityEngine.Random.Range(0, 4);
        Vector3 _rotation;

        if (randomAngle == 0)
        {
            _rotation = new Vector3(0, 0, 0);
        }
        else if (randomAngle == 1)
        {
            _rotation = new Vector3(180, 0, 0);
        }
        else if (randomAngle == 2)
        {
            _rotation = new Vector3(0, 180, 0);
        }
        else
        {
            _rotation = new Vector3(180, 180, 0);
        }

        if (typeGoldMine == 3)
        {
            _rotation = new Vector3(0, 0, 0);
        }

        if (isGoldPlayer)
        {
            _rotation = new Vector3(0, 0, 0);
            GoldMine goldMine = Instantiate(prefabsBoxMap[2], toPos.position, Quaternion.Euler(_rotation), toPos).GetComponent <GoldMine>();
            goldMine.GetInfo(id, GameConfig.Instance.GetNameIsLand(), level, TypeGoldMine.Player, 2);
            goldMine.canvas.localRotation   = Quaternion.Euler(_rotation);
            goldMine.info.indexLoadGoldMine = 2;
            lsGoldMinePlayer.Add(goldMine);
            lsGoldMineManager.Add(goldMine);
            box.info.goldMine = goldMine;
        }
        else
        {
            GoldMine goldMine = Instantiate(prefabsBoxMap[typeGoldMine], toPos.position, Quaternion.Euler(_rotation), toPos).GetComponent <GoldMine>();
            goldMine.GetInfo(id, GameConfig.Instance.GetNameIsLand(), level, TypeGoldMine.Enemy, typeGoldMine);
            goldMine.canvas.localRotation   = Quaternion.Euler(_rotation);
            goldMine.info.indexLoadGoldMine = typeGoldMine;
            lsGoldMineEnemy.Add(goldMine);
            lsGoldMineManager.Add(goldMine);
            box.info.goldMine = goldMine;
        }
    }
Ejemplo n.º 10
0
        public void FetchResource_FetchesResource_Ok()
        {
            //
            var worker = new Worker();
            var mine   = new GoldMine(0, "mine", new Coordinates {
                x = 10, y = 10
            }, 2000);

            //
            Assert.AreEqual(0, worker.HoldedResources[ResourcesType.Gold]);
            worker.FetchResource(mine);

            //
            Thread.Sleep(mine.FetchTimeEllapse + 500);
            Assert.IsTrue(worker.HoldedResources[ResourcesType.Gold] > 0);
        }
        public static Target[] GenerateTargets(float minimumDistance, bool ignoreGold, bool ignoreElixir, CacheBehavior behavior = CacheBehavior.Default)
        {
            // Find all Collectors & storages just sitting around...
            List <Building> buildings = new List <Building>();

            if (!ignoreGold)
            {
                //User has Gold min set to ZERO - which means Dont include Gold Targets
                buildings.AddRange(GoldMine.Find(behavior));
                buildings.AddRange(GoldStorage.Find(behavior));
            }

            if (!ignoreElixir)
            {
                //User has Elixir min set to ZERO - which means Dont include Elixir Targets
                buildings.AddRange(ElixirCollector.Find(behavior));
                buildings.AddRange(ElixirStorage.Find(behavior));
            }

            //We always includ DarkElixir - Because who doesnt love dark Elixir?
            buildings.AddRange(DarkElixirDrill.Find(behavior));
            buildings.AddRange(DarkElixirStorage.Find(behavior));

            List <Target> targetList = new List <Target>();

            foreach (Building building in buildings)
            {
                Target current = new Target();

                current.TargetBuilding  = building;
                current.Center          = building.Location.GetCenter();
                current.NearestRedLine  = GameGrid.RedPoints.OrderBy(p => p.DistanceSq(current.Center)).First();
                current.CenterToRedline = current.Center.DistanceSq(current.NearestRedLine);
                Log.Debug($"[Berts Algorithms] DistanceSq from {current.Name} to red point: {current.CenterToRedline.ToString("F1")}");
                if (current.CenterToRedline < minimumDistance)                                                                              //Compare distance to Redline to the Minimum acceptable distance Passed in
                {
                    current.DeployGrunts = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _gruntDeployDistanceFromRedline);  //Barbs & Goblins
                    current.DeployRanged = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _rangedDeployDistanceFromRedline); //Archers & Minions

                    targetList.Add(current);
                }
            }

            Log.Debug($"[Berts Algorithms] Found {targetList.Count} deploy points");

            return(targetList.ToArray());
        }
Ejemplo n.º 12
0
        public static IGameDescriptor GenerateDefaultMap()
        {
            TownHall townHall = new TownHall("TownHall", 100, 100, false, null, new Coordinates {
                x = 13, y = 34
            });
            Carry carry = new Carry(0, "Carry1", new Coordinates {
                x = 1220, y = 620
            });
            //Tree tree = new Tree("Tree1", new Coordinates { x = 30, y = 30 });
            GoldMine mine = new GoldMine(0, "Gold mine1", new Coordinates {
                x = 1301, y = 82
            });
            Farm farm1 = new Farm(0, "Farm1", new Coordinates {
                x = 23, y = 557
            });
            Farm farm2 = new Farm(1, "Farm2", new Coordinates {
                x = 178, y = 557
            });
            Worker worker1 = new Worker(100, false, null, new Coordinates {
                x = 400, y = 400
            });
            Worker worker2 = new Worker(100, false, null, new Coordinates {
                x = 450, y = 450
            });

            var Resources = new SerializableDictionary <ResourcesType, int> {
                { ResourcesType.Gold, 1000 }, { ResourcesType.Stone, 1000 }, { ResourcesType.Wood, 1000 }
            };

            var game = new GameDescriptor();

            game.TownHalls.Add(townHall.ToTownHallDescriptor());
            game.Carries.Add(carry.ToCarryDescriptor());
            //game.Trees.Add(tree);
            game.GoldMines.Add(mine.ToGoldMineDescriptor());
            game.Farms.Add(farm1.ToFarmDescriptor());
            game.Farms.Add(farm2.ToFarmDescriptor());
            game.Workers.Add(worker1.ToWorkerDescriptor());
            game.Workers.Add(worker2.ToWorkerDescriptor());
            game.Resources        = Resources;
            game.MaxPopulation    = game.Farms.Count * game.Farms[0].PopulationIncrement;
            game.ActualPopulation = game.Workers.Count * game.Workers[0].PopulationSlots;

            return((IGameDescriptor)game);
        }
Ejemplo n.º 13
0
        private GoldMine NearGoldMine(Builder builder)
        {
            GoldMine goldMine = null;

            float maxDistance = float.MaxValue;

            for (int i = 0; i < ManagerBuildings.goldMines.Count; i++)
            {
                float distance = Vector2.Distance(ManagerBuildings.goldMines[i].Position, builder.Position);
                if (distance < maxDistance && ManagerBuildings.goldMines[i].QUANITY > 0)
                {
                    maxDistance = distance;
                    goldMine    = ManagerBuildings.goldMines[i];
                }
            }

            return(goldMine);
        }
        private void GenerateDeployPointsFromMinesToMilk(CacheBehavior behavior = CacheBehavior.Default)
        {
            // Find all mines
            List <Building> mines = new List <Building>();
            TownHall        th    = TownHall.Find();

            if (th != null)
            {
                mines.Add(th);
            }
            if (!resourcesFull.HasFlag(ResourcesFull.Gold))
            {
                mines.AddRange(GoldMine.Find(behavior));
            }
            if (!resourcesFull.HasFlag(ResourcesFull.Elixir))
            {
                mines.AddRange(ElixirCollector.Find(behavior));
            }
            if (!resourcesFull.HasFlag(ResourcesFull.Delixir))
            {
                mines.AddRange(DarkElixirDrill.Find(behavior));
            }

            List <PointFT> resultPoints = new List <PointFT>();

            foreach (Building mine in mines)
            {
                PointFT center     = mine.Location.GetCenter();
                PointFT closest    = GameGrid.RedPoints.OrderBy(p => p.DistanceSq(center)).First();
                float   distanceSq = center.DistanceSq(closest);
                Log.Debug("DistanceSq from " + mine.GetType().Name + " to red point: " + distanceSq.ToString("F1"));
                if (distanceSq < 9)  // 3 tiles (squared = 9) means there is no wall or building between us and the collector
                {
                    Log.Debug("Adding deploy point");
                    PointFT awayFromRedLine = closest.AwayFrom(center, 0.5f);
                    resultPoints.Add(awayFromRedLine);
                }
            }
            Log.Debug("Found " + resultPoints.Count + " deploy points");
            deployPoints = resultPoints.ToArray();
        }
Ejemplo n.º 15
0
 public void GenerateMapJson(Transform toPos, Box box, int typeGoldMine, Vector3 _rotation, GoldMineInfoST gInfo, bool isGoldPlayer = false)
 {
     if (isGoldPlayer)
     {
         _rotation = new Vector3(0, 0, 0);
         GoldMine goldMine = Instantiate(prefabsBoxMap[2], toPos.position, Quaternion.Euler(_rotation), toPos).GetComponent <GoldMine>();
         goldMine.GetInfoJson(gInfo);
         goldMine.canvas.localRotation = Quaternion.Euler(_rotation);
         lsGoldMinePlayer.Add(goldMine);
         lsGoldMineManager.Add(goldMine);
         box.info.goldMine = goldMine;
     }
     else
     {
         GoldMine goldMine = Instantiate(prefabsBoxMap[typeGoldMine], toPos.position, Quaternion.Euler(_rotation), toPos).GetComponent <GoldMine>();
         goldMine.GetInfoJson(gInfo);
         goldMine.canvas.localRotation = Quaternion.Euler(_rotation);
         lsGoldMineEnemy.Add(goldMine);
         lsGoldMineManager.Add(goldMine);
         box.info.goldMine = goldMine;
     }
 }
Ejemplo n.º 16
0
        public bool execute()
        {
            cityHall = managerBuildings.buildings.Find((b) =>
                                                       (b.information as InformationBuilding).Type == Util.Buildings.TOWN_HALL ||
                                                       (b.information as InformationBuilding).Type == Util.Buildings.GREAT_HALL) as CityHall;

            if (cityHall != null)
            {
                float maxDistance = float.MaxValue;
                for (int i = 0; i < ManagerBuildings.goldMines.Count; i++)
                {
                    float distance = Vector2.Distance(ManagerBuildings.goldMines[i].Position, cityHall.Position);
                    if (distance < maxDistance && ManagerBuildings.goldMines[i].QUANITY > 0)
                    {
                        maxDistance = distance;
                        goldMine    = ManagerBuildings.goldMines[i];
                    }
                }

                if (goldMine != null && goldMine.QUANITY > 0)
                {
                    started = true;

                    goldMine.workers.Add(worker as Builder);
                    worker.workState = WorkigState.GO_TO_WORK;
                    worker.Move((int)goldMine.Position.X / 32, (int)goldMine.Position.Y / 32);
                    worker.selected = false;

                    currentState = State.MINER;

                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Check to see how many collector and mine near to the redline by user defined distance
        /// </summary>
        /// <param name="userDistance">Minimum distance for exposed colloctors and mines</param>
        /// <param name="minCollectors">minimum exposed collectors</param>
        /// <param name="minMines">minimum exposed mines</param>
        /// <param name="AttackName">Attack name for logs and debugging</param>
        /// <param name="debug">debug mode in advanced settings</param>
        /// <returns>true if matches user defined min collectores and mines</returns>
        public static bool IsBaseMinCollectorsAndMinesOutside(int userDistance, int minCollectors, int minMines, string AttackName, int debug)
        {
            var distance = userDistance * userDistance;

            var redPoints = GameGrid.RedPoints.Where(
                point =>
                !(point.X > 18 && point.Y > 18 || point.X > 18 && point.Y < -18 || point.X < -18 && point.Y > 18 ||
                  point.X < -18 && point.Y < -18));

            collectors = ElixirCollector.Find().Where(c => c.Location.GetCenter()
                                                      .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter()))
                                                                  .FirstOrDefault()) <= distance);

            mines = GoldMine.Find().Where(c => c.Location.GetCenter()
                                          .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter()))
                                                      .FirstOrDefault()) <= distance);

            drills = DarkElixirDrill.Find().Where(c => c.Location.GetCenter()
                                                  .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter()))
                                                              .FirstOrDefault()) <= distance);

            int collectorsCount = collectors != null?collectors.Count() : 0;

            int minesCount = mines != null?mines.Count() : 0;

            int drillsCount = drills != null?drills.Count() : 0;

            // Set total count of targets
            SmartFourFingersDeploy.TotalTargetsCount = collectorsCount + minesCount + drillsCount;

            // four corners
            var top    = new PointFT((float)GameGrid.DeployExtents.MaxX + 1, GameGrid.DeployExtents.MaxY + 4);
            var right  = new PointFT((float)GameGrid.DeployExtents.MaxX + 1, GameGrid.DeployExtents.MinY - 4);
            var bottom = new PointFT((float)GameGrid.DeployExtents.MinX - 1, GameGrid.DeployExtents.MinY - 4);
            var left   = new PointFT((float)GameGrid.DeployExtents.MinX - 1, GameGrid.DeployExtents.MaxY + 4);

            SetCore();

            var corners = new List <Tuple <PointFT, PointFT> >
            {
                new Tuple <PointFT, PointFT>(top, right),
                new Tuple <PointFT, PointFT>(bottom, right),
                new Tuple <PointFT, PointFT>(bottom, left),
                new Tuple <PointFT, PointFT>(top, left)
            };

            // loop throw the 4 sides and count targets on each side
            var targetsAtLine = new List <int>();

            foreach (var l in corners)
            {
                var colCount = collectors.Where(t => t.Location.GetCenter().
                                                IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0;
                var minCount = mines.Where(t => t.Location.GetCenter().
                                           IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0;
                var drillCount = drills.Where(t => t.Location.GetCenter().
                                              IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0;
                var total = colCount + minCount + drillCount;

                targetsAtLine.Add(total);
            }

            SmartFourFingersDeploy.TargetsAtLine = targetsAtLine;

            var op = new Opponent(0);

            //if (!op.IsForcedAttack )
            {
                Log.Info($"{AttackName} NO. of Colloctors & mines near from red line:");
                Log.Info($"elixir colloctors is {collectorsCount}");
                Log.Info($"gold mines is {minesCount}");
                Log.Info($"----------------------------");
                Log.Info($"sum of all is {collectorsCount + minesCount}");

                if (debug == 1)
                {
                    using (Bitmap bmp = Screenshot.Capture())
                    {
                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            foreach (var c in collectors)
                            {
                                var point = c.Location.GetCenter();
                                Visualize.Target(bmp, point, 30, Color.Purple);
                            }

                            foreach (var c in mines)
                            {
                                var point = c.Location.GetCenter();
                                Visualize.Target(bmp, point, 30, Color.Gold);
                            }

                            foreach (var c in drills)
                            {
                                var point = c.Location.GetCenter();
                                Visualize.Target(bmp, point, 30, Color.Black);
                            }
                            DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, top);
                            DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, right);
                            DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, bottom);
                            DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, left);
                        }
                        var d = DateTime.UtcNow;
                        Screenshot.Save(bmp, "Collectors and Mines {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}");
                    }
                }
            }
            if (collectorsCount >= minCollectors && minesCount >= minMines)
            {
                return(true);
            }
            else
            {
                Log.Warning($"{AttackName} this base doesn't meets Collocetors & Mines requirements");
                return(false);
            }
        }
Ejemplo n.º 18
0
 private void Awake()
 {
     hpManager   = GetComponent <HpManager>();
     goldManager = GetComponent <GoldMine>();
 }
 public void BeforeTest()
 {
     this.goldMine = new GoldMine();
 }
        /// <summary>
        /// Check to see how many collector and mine near to the redline by user defined distance
        /// </summary>
        /// <param name="userDistance">Minimum distance for exposed colloctors and mines</param>
        /// <param name="minCollectors">minimum exposed collectors</param>
        /// <param name="minMines">minimum exposed mines</param>
        /// <param name="AttackName">Attack name for logs and debugging</param>
        /// <param name="debug">debug mode in advanced settings</param>
        /// <returns>true if matches user defined min collectores and mines</returns>
        public static bool IsBaseMinCollectorsAndMinesOutside(int userDistance, int minCollectors, int minMines, string AttackName, int debug)
        {
            var distance = userDistance * userDistance;

            var redPoints = GameGrid.RedPoints.Where(
                point =>
                !(point.X > 18 && point.Y > 18 || point.X > 18 && point.Y < -18 || point.X < -18 && point.Y > 18 ||
                  point.X < -18 && point.Y < -18));

            var collectors = ElixirCollector.Find().Where(c => c.Location.GetCenter()
                                                          .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter()))
                                                                      .FirstOrDefault()) <= distance);

            var mines = GoldMine.Find().Where(c => c.Location.GetCenter()
                                              .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter()))
                                                          .FirstOrDefault()) <= distance);

            int collectorsCount = collectors != null?collectors.Count() : 0;

            int minesCount = mines != null?mines.Count() : 0;

            Log.Info($"{AttackName} NO. of Colloctors & mines near from red line:");
            Log.Info($"elixir colloctors is {collectorsCount}");
            Log.Info($"gold mines is {minesCount}");
            Log.Info($"----------------------------");
            Log.Info($"sum of all is {collectorsCount + minesCount}");

            if (debug == 1)
            {
                using (Bitmap bmp = Screenshot.Capture())
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        foreach (var c in collectors)
                        {
                            var point = c.Location.GetCenter();
                            Visualize.RectangleT(bmp, new RectangleT((int)point.X, (int)point.Y, 2, 2), new Pen(Color.Blue));
                        }


                        foreach (var c in mines)
                        {
                            var point = c.Location.GetCenter();
                            Visualize.RectangleT(bmp, new RectangleT((int)point.X, (int)point.Y, 2, 2), new Pen(Color.White));
                        }
                    }
                    var d = DateTime.UtcNow;
                    Screenshot.Save(bmp, "Collectors and Mines {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}");
                }
            }

            if (collectorsCount >= minCollectors && minesCount >= minMines)
            {
                return(true);
            }
            else
            {
                Log.Warning($"{AttackName} this base doesn't meets Collocetors & Mines requirements");
                return(false);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FacadeExample"/> class.
        /// </summary>
        /// <param name="goldMine">The <see cref="GoldMine"/> to use in this example.</param>
        public FacadeExample(GoldMine goldMine)
        {
            ParameterValidation.IsNotNull(goldMine, nameof(goldMine));

            this.goldMine = goldMine;
        }
Ejemplo n.º 22
0
 public static GoldMineDescriptor ToGoldMineDescriptor(this GoldMine goldMine)
 {
     return(Mapper.Map <GoldMineDescriptor>(goldMine));
 }
Ejemplo n.º 23
0
        public static Target[] GenerateTargets(string algorithmName, float minimumDistance, bool ignoreGold, bool ignoreElixir, string AttackId, out double avgFillstate, out double avgCollectorLvl, CacheBehavior behavior = CacheBehavior.Default, bool outputDebugImage = false, bool activeBase = false)
        {
            // Find all Collectors & storages just sitting around...
            List <Building> buildings = new List <Building>();

            //Get a list of Gold Mines.
            List <GoldMine> goldMines = new List <GoldMine>();

            goldMines.AddRange(GoldMine.Find(behavior));

            //Get a list of Elixir Collectors.
            List <ElixirCollector> elixirCollectors = new List <ElixirCollector>();

            elixirCollectors.AddRange(ElixirCollector.Find(behavior));
            avgFillstate = 0;

            //Get the Average Fill State of all the Elixir Collectors - From this we can tell what percentage of the loot is in Collectors.
            if (elixirCollectors.Count > 1)
            {
                avgFillstate = elixirCollectors.Average(c => c.FillState);
            }

            //Log the Average Fill State of aLL elixir Collectors...
            Log.Debug($"[Berts Algorithms] - Fill State Average of ALL Elixir Collectors: {(avgFillstate * 10).ToString("F1")}");

            if (!ignoreGold)
            {
                buildings.AddRange(goldMines);
                if (activeBase)
                {
                    buildings.AddRange(GoldStorage.Find(behavior));
                }
            }
            if (!ignoreElixir)
            {
                buildings.AddRange(elixirCollectors);
                if (activeBase)
                {
                    buildings.AddRange(ElixirStorage.Find(behavior));
                }
            }

            //Determine the Average Collector Level.
            avgCollectorLvl = 0;

            if (ignoreGold && !ignoreElixir)
            {
                if (elixirCollectors.Count(c => c.Level.HasValue) > 1)
                {
                    avgCollectorLvl = elixirCollectors.Where(c => c.Level.HasValue).Average(c => (int)c.Level);
                }
            }
            else if (ignoreElixir && !ignoreGold)
            {
                if (goldMines.Count(c => c.Level.HasValue) > 1)
                {
                    avgCollectorLvl = goldMines.Where(c => c.Level.HasValue).Average(c => (int)c.Level);
                }
            }
            else if (!ignoreElixir && !ignoreGold)
            {
                if (buildings.Count(c => c.Level.HasValue) > 1)
                {
                    avgCollectorLvl = buildings.Where(c => c.Level.HasValue).Average(c => (int)c.Level);
                }
            }

            //We always includ DarkElixir - Because who doesnt love dark Elixir?
            buildings.AddRange(DarkElixirDrill.Find(behavior));
            if (activeBase)
            {
                buildings.AddRange(DarkElixirStorage.Find(behavior));
            }

            List <Target> targetList = new List <Target>();

            foreach (Building building in buildings)
            {
                Target current = new Target();

                current.TargetBuilding  = building;
                current.Center          = building.Location.GetCenter();
                current.Edge            = Origin.PointOnLineAwayFromEnd(current.Center, 1.0f);
                current.NearestRedLine  = AllPoints.OrderBy(p => p.DistanceSq(current.Edge)).First();
                current.CenterToRedline = current.Center.DistanceSq(current.NearestRedLine);
                if (current.CenterToRedline < minimumDistance)  //Compare distance to Redline to the Minimum acceptable distance Passed in
                {
                    Log.Debug($"[Berts Algorithms] Distance from {current.Name} to red point: {Math.Sqrt(current.CenterToRedline).ToString("F1")}, Min Distance: {Math.Sqrt(minimumDistance).ToString("F1")} - GO!");
                    current.DeployGrunts = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _gruntDeployDistanceFromRedline);  //Barbs & Goblins
                    current.DeployRanged = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _rangedDeployDistanceFromRedline); //Archers & Minions

                    targetList.Add(current);
                }
                else
                {
                    Log.Debug($"[Berts Algorithms] Distance from {current.Name} to red point: {Math.Sqrt(current.CenterToRedline).ToString("F1")}, Min Distance: {Math.Sqrt(minimumDistance).ToString("F1")} - TOO FAR!");
                }
            }

            if (outputDebugImage)
            {
                OutputDebugImage(algorithmName, buildings, targetList, AttackId);
            }

            return(targetList.ToArray());
        }
        public static Target[] GenerateTargets(float minimumDistance, bool ignoreGold, bool ignoreElixir, CacheBehavior behavior = CacheBehavior.Default, bool outputDebugImage = false)
        {
            // Find all Collectors & storages just sitting around...
            List <Building> buildings = new List <Building>();

            if (!ignoreGold)
            {
                //User has Gold min set to ZERO - which means Dont include Gold Targets
                buildings.AddRange(GoldMine.Find(behavior));
                buildings.AddRange(GoldStorage.Find(behavior));
            }

            if (!ignoreElixir)
            {
                //User has Elixir min set to ZERO - which means Dont include Elixir Targets
                buildings.AddRange(ElixirCollector.Find(behavior));
                buildings.AddRange(ElixirStorage.Find(behavior));
            }

            //We always includ DarkElixir - Because who doesnt love dark Elixir?
            buildings.AddRange(DarkElixirDrill.Find(behavior));
            buildings.AddRange(DarkElixirStorage.Find(behavior));

            List <Target> targetList = new List <Target>();

            foreach (Building building in buildings)
            {
                Target current = new Target();

                current.TargetBuilding  = building;
                current.Center          = building.Location.GetCenter();
                current.NearestRedLine  = GameGrid.RedPoints.OrderBy(p => p.DistanceSq(current.Center)).First();
                current.CenterToRedline = current.Center.DistanceSq(current.NearestRedLine);
                Log.Debug($"[Berts Algorithms] DistanceSq from {current.Name} to red point: {current.CenterToRedline.ToString("F1")}");
                if (current.CenterToRedline < minimumDistance)                                                                              //Compare distance to Redline to the Minimum acceptable distance Passed in
                {
                    current.DeployGrunts = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _gruntDeployDistanceFromRedline);  //Barbs & Goblins
                    current.DeployRanged = current.Center.PointOnLineAwayFromEnd(current.NearestRedLine, _rangedDeployDistanceFromRedline); //Archers & Minions

                    targetList.Add(current);
                }
            }

            if (outputDebugImage)
            {
                var d             = DateTime.UtcNow;
                var debugFileName = $"Human Barch {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}";
                //Get a screen Capture of all targets we found...
                using (Bitmap canvas = Screenshot.Capture())
                {
                    Screenshot.Save(canvas, $"{debugFileName}_1");

                    foreach (var building in buildings)
                    {
                        var color = Color.White;
                        if (building.GetType() == typeof(ElixirCollector) || building.GetType() == typeof(ElixirStorage))
                        {
                            color = Color.Violet;
                        }
                        if (building.GetType() == typeof(GoldMine) || building.GetType() == typeof(GoldStorage))
                        {
                            color = Color.Gold;
                        }
                        if (building.GetType() == typeof(DarkElixirDrill) || building.GetType() == typeof(DarkElixirStorage))
                        {
                            color = Color.Brown;
                        }

                        //Draw a target on each building.
                        Visualize.Target(canvas, building.Location.GetCenter(), 40, color);
                    }
                    //Save the Image to the Debug Folder...
                    Screenshot.Save(canvas, $"{debugFileName}_2");
                }

                //Get a screen Capture of all targets we found...
                using (Bitmap canvas = Screenshot.Capture())
                {
                    foreach (var target in targetList)
                    {
                        var color = Color.White;
                        if (target.TargetBuilding.GetType() == typeof(ElixirCollector) || target.TargetBuilding.GetType() == typeof(ElixirStorage))
                        {
                            color = Color.Violet;
                        }
                        if (target.TargetBuilding.GetType() == typeof(GoldMine) || target.TargetBuilding.GetType() == typeof(GoldStorage))
                        {
                            color = Color.Gold;
                        }
                        if (target.TargetBuilding.GetType() == typeof(DarkElixirDrill) || target.TargetBuilding.GetType() == typeof(DarkElixirStorage))
                        {
                            color = Color.Brown;
                        }

                        //Draw a target on each building.
                        Visualize.Target(canvas, target.TargetBuilding.Location.GetCenter(), 40, color);
                        Visualize.Target(canvas, target.DeployGrunts, 20, color);
                        Visualize.Target(canvas, target.DeployRanged, 20, color);
                    }
                    //Save the Image to the Debug Folder...
                    Screenshot.Save(canvas, $"{debugFileName}_3");
                }

                Log.Debug("[Berts Algorithms] Collector/Storage & Target Debug Images Saved!");
            }

            Log.Debug($"[Berts Algorithms] Found {targetList.Count} deploy points");

            return(targetList.ToArray());
        }