Esempio n. 1
0
    private async Task <bool> AttackNearestEnemy(Dice_Control soldier, Player player)
    {
        //find nearest enemy unit
        List <TileControl> path = pathFinding.FindPathToNearestEnemy(soldier.tileControl, player);

        if (path.Count == 0)
        {
            return(false);
        }

        //assign the target at the end of the path
        Debug.Log($"got path, setting target");
        target = path[path.Count - 1].diceOnTile;

        //first element, is own tile.
        path = path.GetRange(1, path.Count - 1);

        if (path.Count > player.numberOfMoves)
        {
            Debug.Log($"{soldier.tileControl.tileIndex} too far away from {target.tileControl.tileIndex} {path.Count} > {player.numberOfMoves}");
            //move the first x number of moves
            List <TileControl> pathProgress = path.GetRange(0, player.numberOfMoves);

            Debug.Log($"Moving {pathProgress.Count} our of {path.Count}");

            gameControl.playerControl.TakenMove(player.numberOfMoves);
            await gameControl.boardControl.HopTo(pathProgress, soldier, false);
        }
        else
        {
            Debug.Log($"{soldier.tileControl.tileIndex} can attack {path.Count} away, target {target.tileControl.tileIndex} {target.currentValue}");

            if (target.isBase)
            {
                Debug.Log($"{soldier.tileControl.tileIndex} {soldier.currentValue} attacking Outpost {target.tileControl.tileIndex} {target.currentValue}");
                gameControl.boardControl.CalculateAttackEnemyBase(soldier, target, path);
            }
            else
            {
                Debug.Log($"{soldier.tileControl.tileIndex} {soldier.currentValue} attacking {target.tileControl.tileIndex} {target.currentValue}");
                await gameControl.boardControl.CalculateAttackEnemy(soldier, target, path);
            }
        }
        return(true);
    }