public void Cast_AttackTiles()
    {
        if (gameObject.GetComponent <UnitAttributes>().LoS)
        {
            foreach (GameObject item in Coordinates)
            {
                item.GetComponent <TerrainProperty>().Reset();
            }

            GetCoordinate();
            SitCoordinate.LoSAttackGrid(gameObject, Vector3.forward, gameObject.GetComponent <UnitAttributes>().Range + 1);
            SitCoordinate.LoSAttackGrid(gameObject, Vector3.right, gameObject.GetComponent <UnitAttributes>().Range + 1);
            SitCoordinate.LoSAttackGrid(gameObject, Vector3.back, gameObject.GetComponent <UnitAttributes>().Range + 1);
            SitCoordinate.LoSAttackGrid(gameObject, Vector3.left, gameObject.GetComponent <UnitAttributes>().Range + 1);
        }
        else
        {
            foreach (GameObject item in Coordinates)
            {
                item.GetComponent <TerrainProperty>().ViableTargetGrid(gameObject);
            }

            GetCoordinate();                                               //Pulls current position
            Queue <TerrainProperty> queue = new Queue <TerrainProperty>(); //Assigns a queue order to create an area check

            queue.Enqueue(SitCoordinate);                                  //Assigns the current position
            SitCoordinate.isAccounted = true;                              //to be ignored during grid check as it's already assigned

            while (queue.Count > 0)
            {
                TerrainProperty terrain = queue.Dequeue();//Assigns it already
                ValidSpace.Add(terrain);
                terrain.isValid = true;

                if (terrain.Range < gameObject.GetComponent <UnitAttributes>().Range)
                {
                    //Pulls each connected tile into a loop that will then assign them within the queue
                    //This creates a loop that will run until the all connected tiles are no longer in range
                    foreach (TerrainProperty item in terrain.AttackRangeList)
                    {
                        if (!item.isAccounted)
                        {
                            item.parent      = terrain;
                            item.isAccounted = true;
                            item.Range       = terrain.Range + 1;
                            if (item.Range <= gameObject.GetComponent <UnitAttributes>().Range)
                            {
                                queue.Enqueue(item);
                            }
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    //Line of Sight based Attacks
    public void LoSAttackGrid(GameObject Searcher, Vector3 Direction, int Distance)
    {
        Vector3 halfExtents = new Vector3(0.25f, 0.25f, 0.25f);

        Collider[] colliders = Physics.OverlapBox(transform.position + Direction, halfExtents);
        isValid   = true;
        isHostile = true;
        Range     = Distance;

        foreach (Collider item in colliders)
        {
            TerrainProperty terrain = item.GetComponent <TerrainProperty>();
            if (terrain != null)
            {
                AttackRangeList.Add(terrain);
                terrain.parent = gameObject.GetComponent <TerrainProperty>();
                if (Range > 1)
                {
                    terrain.LoSAttackGrid(Searcher, Direction, Range - 1);
                }
            }
        }
    }