Esempio n. 1
0
    void MoveClick()
    {
        Clicker clicker = FindObjectOfType <Clicker>();

        BoardGenerator.Cell cell = m_moveControl.currentCell;
        clicker.setupClickBoard(cell, stats.getMoveSpeed, Clicker.TargetType.Empty, true, Move);
    }
Esempio n. 2
0
    void HolyCleaveClick()
    {
        Clicker clicker = FindObjectOfType <Clicker>();

        BoardGenerator.Cell cell = m_moveControl.currentCell;
        clicker.setupClickBoard(cell, stats.getAttackRange, Clicker.TargetType.Enemy, true, HolyCleave);
    }
Esempio n. 3
0
    void HealClick()
    {
        Clicker clicker = FindObjectOfType <Clicker>();

        BoardGenerator.Cell cell = m_moveControl.currentCell;
        clicker.setupClickBoard(cell, stats.getAttackRange, Clicker.TargetType.Ally, false, Heal);
    }
Esempio n. 4
0
 public void Move(BoardGenerator.Cell cell)
 {
     if (numMoves > 0)
     {
         GameManagerScript.getBoard().MoveToCell(cell.index, gameObject, m_moveControl);
         numMoves--;
         GameManagerScript.SubtractAction();
     }
     else if (numActions > 0)
     {
         GameManagerScript.getBoard().MoveToCell(cell.index, gameObject, m_moveControl);
         numActions--;
         GameManagerScript.SubtractAction();
     }
 }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (myTurn)
        {
            if (target == null || !target.GetComponent <Stats>().isAlive())
            {
                FindCloestTarget();
            }
            if (target == null)
            {
                Debug.Log("No target found");
                return;
            }

            delayTimer -= Time.deltaTime;
            if (delayTimer < 0)
            {
                Text text = GameObject.Find("EnemyText").GetComponent <Text>();
                s = text.text + "\n";
                BoardGenerator.Cell _cell = gmc.currentCell;
                int dis = bg.getCellWalkDistance(_cell.index, target.GetComponent <GridMovementController>().currentCell.index);

                if (stats.getAttackRange < dis)
                {
                    Walk(stats.getMoveSpeed);
                    movecount--;
                }
                else
                {
                    attack();
                    movecount -= 2;
                }
                text.text  = s;
                delayTimer = 3f;

                if (movecount <= 0)
                {
                    myTurn    = false;
                    movecount = 2;
                }
            }
        }
    }
Esempio n. 6
0
    void action()
    {
        Text text = GameObject.Find("EnemyText").GetComponent <Text>();

        s = text.text + "\n";
        if (target == null || !target.GetComponent <Stats>().isAlive())
        {
            FindCloestTarget();
        }
        if (target == null)
        {
            Debug.Log("No target found");
            return;
        }
        //s += "\n" + transform.name + " targeting " + target.name;
        BoardGenerator.Cell _cell = gmc.currentCell;
        int dis = bg.getCellWalkDistance(_cell.index, target.GetComponent <GridMovementController>().currentCell.index);
        //s += "\n" + transform.name + " Walk Distance away from " + target.name + " : " + dis;
        // check self walk distance + attack range
        int range = stats.getMoveSpeed + stats.getAttackRange;

        // if enough range
        if (range >= dis)
        {
            // if attack range too short, walk
            if (stats.getAttackRange < dis)
            {
                Walk(stats.getMoveSpeed);
            }
            // then attack
            // if within attack range, attack with most damage
            attack();
            myTurn = false;
        }
        // if distance too far, walk close to target
        else
        {
            Walk(stats.getMoveSpeed);
            Walk(stats.getMoveSpeed);
            myTurn = false;
        }
        text.text = s;
    }
Esempio n. 7
0
    public void setupClickBoard(BoardGenerator.Cell start, int range, TargetType type, bool Attack, System.Func <ClickerTile, int> func)
    {
        _func = func;
        foreach (var item in ClickTiles)
        {
            item.gameObject.SetActive(false);
        }

        int cx = (int)start.index.x, cy = (int)start.index.y; //get center xy

        switch (type)
        {
        case TargetType.Empty:
        {
            List <BoardGenerator.Cell> walkable = new List <BoardGenerator.Cell>();
            for (int x = cx - range; x <= cx + range; x++)         //from left to right
            {
                int val = cx - x;
                val = Mathf.Abs(val);
                val = range - val;          //closer to leftmost,rightmost, y range will be lowest
                for (int y = cy - val; y <= cy + val; y++)
                {
                    BoardGenerator.Cell temp = GameManagerScript.getBoard().isValidCell(new Vector2(x, y));
                    if (temp != null)
                    {
                        if (!temp.occupiedObject)
                        {
                            walkable.Add(temp);
                        }
                    }
                }
            }
            foreach (var cell in walkable)
            {
                ClickerTile temptile = null;
                //If have any available tile
                foreach (var tile in ClickTiles)
                {
                    if (!tile.used)
                    {
                        //get tile ref
                        temptile = tile;
                        break;
                    }
                }
                if (temptile == null)
                {
                    //else instantiate a new one
                    GameObject temp = Instantiate(dot, transform);
                    temptile = temp.GetComponent <ClickerTile>();
                    temptile.setClicker(this);
                    ClickTiles.Add(temptile);
                }
                //set position
                GridMovementController gmc = temptile.GetComponent <GridMovementController>();
                GameManagerScript.getBoard().MoveToCell(cell.index, temptile.gameObject, gmc);
                //set active
                temptile.TurnOn(ClickerTile.TileType.Walkable);
            }
            break;
        }

        case TargetType.Ally:
        case TargetType.Enemy:
        {
            List <BoardGenerator.Cell> withinRange = new List <BoardGenerator.Cell>();
            for (int x = cx - range; x <= cx + range; x++)         //from left to right
            {
                int val = cx - x;
                val = Mathf.Abs(val);
                val = range - val;          //closer to leftmost,rightmost, y range will be lowest
                for (int y = cy - val; y <= cy + val; y++)
                {
                    BoardGenerator.Cell temp = GameManagerScript.getBoard().isValidCell(new Vector2(x, y));
                    if (temp != null)
                    {
                        withinRange.Add(temp);
                    }
                }
            }
            foreach (var cell in withinRange)
            {
                ClickerTile temptile = null;
                //If have any available tile
                foreach (var tile in ClickTiles)
                {
                    if (!tile.used)
                    {
                        //get tile ref
                        temptile = tile;
                        break;
                    }
                }
                if (temptile == null)
                {
                    //else instantiate a new one
                    GameObject temp = Instantiate(dot, transform);
                    temptile = temp.GetComponent <ClickerTile>();
                    temptile.setClicker(this);
                    ClickTiles.Add(temptile);
                }
                //set position
                GridMovementController gmc = temptile.GetComponent <GridMovementController>();
                GameManagerScript.getBoard().MoveToCell(cell.index, temptile.gameObject, gmc);
                //set active
                if (!cell.occupiedObject)
                {
                    temptile.TurnOn(ClickerTile.TileType.Range);
                }
                else
                {
                    if (cell.occupiedObject.tag == "Ally")
                    {
                        if (type == TargetType.Ally)
                        {
                            if (Attack)
                            {
                                temptile.TurnOn(ClickerTile.TileType.Attackable);
                            }
                            else
                            {
                                temptile.TurnOn(ClickerTile.TileType.Healable);
                            }
                        }
                        else
                        {
                            temptile.TurnOn(ClickerTile.TileType.Range);
                        }
                    }
                    else if (cell.occupiedObject.tag == "Enemy")
                    {
                        if (type == TargetType.Enemy)
                        {
                            if (Attack)
                            {
                                temptile.TurnOn(ClickerTile.TileType.Attackable);
                            }
                            else
                            {
                                temptile.TurnOn(ClickerTile.TileType.Healable);
                            }
                        }
                        else
                        {
                            temptile.TurnOn(ClickerTile.TileType.Range);
                        }
                    }
                    else
                    {
                        temptile.TurnOn(ClickerTile.TileType.Range);
                    }
                }
            }
            break;
        }

        default:
            break;
        }
        //Search(start, range, type);

        //foreach (var item in availableCells)
        //{
        //    ClickerTile temptile = null;
        //    //If have any available tile
        //    foreach (var tile in ClickTiles)
        //    {
        //        if (!tile.used)
        //        {
        //            //get tile ref
        //            temptile = tile;
        //            break;
        //        }
        //    }
        //    if (temptile == null)
        //    {
        //        //else instantiate a new one
        //        GameObject temp = Instantiate(dot, transform);
        //        temptile = temp.GetComponent<ClickerTile>();
        //        temptile.setClicker(this);
        //        ClickTiles.Add(temptile);
        //    }
        //    //set position
        //    GridMovementController gmc = temptile.GetComponent<GridMovementController>();
        //    GameManagerScript.getBoard().MoveToCell(item.index, temptile.gameObject, gmc);
        //    //set active
        //    temptile.gameObject.SetActive(true);
        //    temptile.used = true;
        //}
    }
Esempio n. 8
0
    void Walk(int steps)
    {
        // Priority, equal to attack range > within attack range > away from attack range
        BoardGenerator.Cell _cell = gmc.currentCell;
        // Find all walkable tiles, aka destination
        List <BoardGenerator.Cell> walkableCells = new List <BoardGenerator.Cell>();

        int[] dis; //distance away from target
        int   range = steps;
        int   cx = (int)_cell.index.x, cy = (int)_cell.index.y;

        for (int x = cx - range; x <= cx + range; x++)
        {
            int val = cx - x;
            val = Mathf.Abs(val);
            val = range - val;
            for (int y = cy - val; y <= cy + val; y++)
            {
                BoardGenerator.Cell temp = GameManagerScript.getBoard().isValidCell(new Vector2(x, y));
                if (temp != null)
                {
                    if (!temp.occupiedObject)
                    {
                        walkableCells.Add(temp);
                    }
                }
            }
        }
        Vector2 targetCellIndex = target.GetComponent <GridMovementController>().currentCell.index;
        List <BoardGenerator.Cell> bestoptions = new List <BoardGenerator.Cell>();

        dis = new int[walkableCells.Count];
        for (int i = 0; i < walkableCells.Count; i++)
        {
            dis[i] = bg.getCellWalkDistance(walkableCells[i].index, targetCellIndex);
            if (dis[i] == stats.getAttackRange)
            {
                bestoptions.Add(walkableCells[i]);
            }
        }
        // For each des
        if (bestoptions.Count > 0)
        {
            int index = Random.Range(0, bestoptions.Count);
            skillTree.Move(bestoptions[index]);
        }
        else
        {
            for (int i = 0; i < dis.Length; i++)
            {
                if (dis[i] <= stats.getAttackRange)
                {
                    bestoptions.Add(walkableCells[i]);
                }
            }
            if (bestoptions.Count > 0)
            {
                int index = Random.Range(0, bestoptions.Count);
                skillTree.Move(bestoptions[index]);
            }
            else
            {
                int min = int.MaxValue;
                for (int i = 0; i < dis.Length; i++)
                {
                    if (dis[i] < min)
                    {
                        min = dis[i];
                    }
                }
                for (int i = 0; i < dis.Length; i++)
                {
                    if (dis[i] == min)
                    {
                        bestoptions.Add(walkableCells[i]);
                    }
                }
                int index = Random.Range(0, bestoptions.Count);
                skillTree.Move(bestoptions[index]);
            }
        }
        s += "\n" + transform.name + " walked ";
    }
Esempio n. 9
0
 public BoardGenerator.Cell currentCell; //keeps a reference to the cur position on board
 // Start is called before the first frame update
 void Awake()
 {
     m_boardManagerRef = GameObject.FindObjectOfType <BoardGenerator>();
     currentCell       = m_boardManagerRef.SnapObject(transform);
 }