コード例 #1
0
    public async Task HopTo(List <TileControl> path, Dice_Control diceToMove, bool targetTileHasDice = true)
    {
        int pathLength = path.Count;

        if (targetTileHasDice)
        {
            pathLength--;
        }
        if (pathLength > 0)
        {
            //Debug.Log($"enter hopping to tile");
            for (int i = 0; i < pathLength; i++)
            {
                //todo, take 1 move from the player, and return if the number is 0
                Debug.Log($" > Hopping from {diceToMove.tileControl.tileIndex} too {path[i].tileIndex} ");
                await HopAnimation(diceToMove, path[i]);

                gameControl.audioManager.PlaySound("hop");
                await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.HOP_DELAY_TIME));
            }
            //Debug.Log($"exit hopping to tile");
        }
        else
        {
            //Debug.Log($"Dice already next to Target");
            if (targetTileHasDice == false)
            {
                UpdateBoardMeta(diceToMove.tileControl, path[0]);
            }
        }
    }
コード例 #2
0
    public void StartPlayerTurn(int actionsForPlayer)
    {
        int          dice_value;
        Dice_Control dice_Control;

        gameControl.ui_Control.UpdatePlayersTurnDisplay(activePlayer.playerName, activePlayer.playerColour);
        gameControl.ui_Control.UpdateMovesDisplay(activePlayer.numberOfMoves, actionsForPlayer);
        StartCoroutine(gameControl.cameraConrol.GlidePosition(activePlayer.cameraPosition));

        if (GlobalVariables.data.SHOW_FLASH_START_TURN && activePlayer.ai == null)
        {
            foreach (GameObject dice in activePlayer.diceOwned)
            {
                dice_Control = dice.GetComponent <Dice_Control>();
                dice_value   = dice_Control.currentValue;
                if (dice_Control.isBase)
                {
                    Dice_Control childDice = dice_Control.transform.GetChild(6).GetComponent <Dice_Control>();
                    StartCoroutine(childDice.FlashForNewTurn());
                }
                StartCoroutine(dice_Control.FlashForNewTurn());
            }
        }

        if (activePlayer.is_ai_player)
        {
            AiPlayersTurn(activePlayer);
        }
        else
        {
            gameControl.AllowInput();
        }
    }
コード例 #3
0
    private TileControl PickAjacentTileNearestToEnemy(List <TileControl> candidateTiles, Player player)
    {
        //take the tile, and get adjacent.
        // filter out the ones that have
        //if null ahhhhh error

        if (candidateTiles.Count == 0)
        {
            Debug.Log($"Logical Error. Need to move a piece in this case instead?");
            return(null);
        }
        else if (candidateTiles.Count == 1)
        {
            return(candidateTiles[0]);
        }
        else
        {
            TileControl        closesetToEnemy = null;
            List <TileControl> closentBuffer   = new List <TileControl>();

            int shortest = 9999999;
            foreach (TileControl tile in candidateTiles)
            {
                closentBuffer = pathFinding.FindPathToNearestEnemy(tile, player);
                if (closentBuffer.Count < shortest)
                {
                    shortest        = closentBuffer.Count;
                    closesetToEnemy = closentBuffer[0];
                }
            }
            target = closentBuffer[closentBuffer.Count - 1].diceOnTile;
            return(closesetToEnemy);
        }
    }
コード例 #4
0
    private async Task UpgradeWorkerOrCreateNew(List <TileControl> workersNextToPrimaryOutpost)
    {
        //TODO updatet to be a return bool, and create if false
        leiginToUse = null;
        foreach (TileControl workerTile in workersNextToPrimaryOutpost)
        {
            if (workerTile.diceOnTile.GetDiceValue() < workerValueThreshold)
            {
                leiginToUse = workerTile.diceOnTile;
                break;
            }
        }

        if (leiginToUse != null)
        {
            Debug.Log($"Adding 2 too worker at {leiginToUse.tileControl.tileIndex}");
            gameControl.boardControl.BaseReenforceAdjacent(leiginToUse);
            await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.AI_ACTION_SPEED));

            gameControl.boardControl.BaseReenforceAdjacent(leiginToUse);
        }
        else
        {
            Debug.Log($"No Workers to add 2 too, below worker value threshold {workerValueThreshold}");
            CreateWorkerNextToOupost(primaryOutpost);
        }
    }
コード例 #5
0
    private bool ReenforceSolder(Player player)
    {
        List <TileControl> soldiersNextToPrimaryOutpost = pathFinding.GetAjacentTiles(primaryOutpost.tileControl, GetAdjacentTilesType.AllFriendlySoldierDice, player);

        leiginToUse = null;
        foreach (TileControl soldierTile in soldiersNextToPrimaryOutpost)
        {
            if (soldierTile.diceOnTile.GetDiceValue() < soldierValueThreshold)
            {
                if (soldierTile.diceOnTile.GetDiceValue() != 6)
                {
                    leiginToUse = soldierTile.diceOnTile;
                    break;//stop looking
                }
            }
        }

        if (leiginToUse == null)
        {
            return(false);
        }
        else
        {
            Debug.Log($"Adding +1 to Solder {leiginToUse.tileControl.tileIndex} next to {primaryOutpost.tileControl.tileIndex}");
            gameControl.boardControl.BaseReenforceAdjacent(leiginToUse);
            return(true);
        }
    }
コード例 #6
0
    internal async void DeconstrucetBase(Dice_Control childDice, int remainingValue)
    {
        //Debug.Log($"destroying {childDice.gameObject.GetInstanceID()}");
        GameObject   parentObject = childDice.gameObject.transform.parent.gameObject;
        Dice_Control parentDice   = parentObject.GetComponent <Dice_Control>();

        parentDice.tileControl.SetDiceOnTile(parentDice);
        Destroy(childDice.gameObject);
        parentDice.isBase = false;
        parentDice.child  = null;
        //Debug.Log($"setting {parentDice.gameObject.GetInstanceID()} to {remainingValue}");
        await parentDice.AnimateDiceValueChange(remainingValue);
    }
コード例 #7
0
    internal async void BaseReenforceAdjacent(Dice_Control targetDice)
    {
        if (targetDice.currentValue < 6)
        {
            await targetDice.AnimateDiceValueChange(targetDice.currentValue + 1);

            gameControl.audioManager.PlaySound("reenforce");
            gameControl.playerControl.TakenMove();
        }
        else
        {
            //Debug.Log($"Invlaid Move {targetDice.value} at maximum");
            InvalidMove(targetDice.tileControl);
        }
    }
コード例 #8
0
    //------------------------------------------------------------------------------------------------------------------------------------------------------

    //private async Task EasyAi(Player player)
    //{
    //    Debug.Log($"In easy AI with {player.numberOfMoves}");
    //    //this.player = player;//gameControl.playerControl.activePlayer;

    //    //while actions > 0 && PlayerHasSoldier = false
    //    while (player.numberOfMoves > 0)
    //    {
    //        if (PlayerHasSoldier(player))
    //        {
    //            //find nearest enemy unit
    //            List<TileControl> path = pathFinding.FindPathToNearestEnemy(leiginToUse.tileControl, player);
    //            //int pathLength = path.Count;

    //            //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($"{leiginToUse.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}");

    //                await gameControl.boardControl.HopTo(pathProgress, leiginToUse, false);
    //                //await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.AI_ACTION_SPEED));
    //                gameControl.playerControl.TakenMove(player.numberOfMoves);
    //            }
    //            else
    //            {
    //                Debug.Log($"{leiginToUse.tileControl.tileIndex} can attack {path.Count} away, target {target.tileControl.tileIndex} {target.currentValue}");

    //                if (target.isBase)
    //                {
    //                    Debug.Log($"{leiginToUse.tileControl.tileIndex} {leiginToUse.currentValue} attacking Outpost {target.tileControl.tileIndex} {target.currentValue}");
    //                    gameControl.boardControl.CalculateAttackEnemyBase(leiginToUse, target, path);
    //                }
    //                else
    //                {
    //                    Debug.Log($"{leiginToUse.tileControl.tileIndex} {leiginToUse.currentValue} attacking {target.tileControl.tileIndex} {target.currentValue}");
    //                    await gameControl.boardControl.CalculateAttackEnemy(leiginToUse, target, path);
    //                }
    //                //gameControl.playerControl.TakeMovesFromPlayer(player, pathLength);
    //            }
    //            //for easy ai, just look back to start
    //            target = null;
    //            leiginToUse = null;
    //        }
    //        else
    //        {
    //            //if player has worker
    //            //add too worker,
    //            //else create dice
    //            // - pick random side to create dice

    //            leiginToUse = gameControl.playerControl.GetFirstPlayerWorker(player);
    //            if (leiginToUse == null)
    //            {
    //                Debug.Log($"No workers found for player: {player.name}");

    //                Dice_Control playerOutpost = gameControl.playerControl.GetFirstPlayerOutpost(player);
    //                if (playerOutpost != null)
    //                {
    //                    CreateWorkerNextToOupost(playerOutpost);
    //                }
    //                else
    //                {
    //                    Debug.Log($"{player.playerName} has no Outpost, or workers or soldiers, should be out of the game");
    //                }
    //            }
    //            else
    //            {
    //                Debug.Log($"At least 1 Worker found for player {player.playerName}");
    //                Dice_Control playerOutpost = gameControl.playerControl.GetFirstPlayerOutpost(player);//Note for multible outpost, will need to sync with FindWorkerBesideOutpost

    //                if (FindWorkerBesideOutpost(playerOutpost))
    //                {
    //                    Debug.Log($"Worker found, adding 1 to it -> {player.playerName}");
    //                    AddPlussOneToWorkerNextToOutPost(playerOutpost, leiginToUse, player);
    //                }
    //                else
    //                {
    //                    Debug.Log($"Worker is not next to a outpost");
    //                    CreateWorkerNextToOupost(playerOutpost);
    //                }
    //            }
    //        }
    //        await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.AI_ACTION_SPEED));//>>>>) actions taken
    //    }//end while
    //    //reset for next ai turn
    //    target = null;
    //    leiginToUse = null;
    //}

    //private void AddPlussOneToWorkerNextToOutPost(Dice_Control outpost, Dice_Control workerToAddToo, Player player)
    //{
    //    Debug.Log($"Adding + 1 to worker beside {outpost.tileControl} for {player.playerName}");
    //    gameControl.boardControl.BaseReenforceAdjacent(workerToAddToo);
    //}

    private bool CreateWorkerNextToOupost(Dice_Control outpost)
    {
        List <TileControl> candidateTiles = pathFinding.GetAjacentTiles(outpost.tileControl, GetAdjacentTilesType.AllEmpty);

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

        TileControl tileToCreateWorker = PickAjacentTileNearestToEnemy(candidateTiles, outpost.player);

        gameControl.boardControl.CreateDiceAt(tileToCreateWorker, outpost.player);
        Debug.Log($"creating worker next to outpost {outpost.tileControl.tileIndex} at {tileToCreateWorker.tileIndex}");
        gameControl.playerControl.TakenMove();
        return(true);
    }
コード例 #9
0
 public void DestroySingleDice(Dice_Control diceToDestroy, bool removeTileDice = true, bool playSound = true)
 {
     if (removeTileDice)
     {
         diceToDestroy.tileControl.RemoveDiceOnTile();
     }
     diceToDestroy.SetDeselected();
     diceToDestroy.StopAllCoroutines();
     diceToDestroy.player.diceOwned.Remove(diceToDestroy.gameObject);
     Destroy(diceToDestroy.gameObject);
     if (playSound)
     {
         gameControl.audioManager.PlaySound("destroyDice");
     }
     //gameControl.AllowInput();//check here for if there is allow input issues
 }
コード例 #10
0
    //-----------------------------------------end dice actions

    public void UpdateBoardMeta(TileControl startingTile, TileControl targetTile, bool replaceTarget = true)
    {
        Dice_Control startingDice = startingTile.diceOnTile;
        Dice_Control targetDice   = targetTile.diceOnTile;

        if (replaceTarget)
        {
            targetTile.SetDiceOnTile(startingDice);
            startingTile.RemoveDiceOnTile();
            startingDice.SetTile(targetTile);
        }
        else
        {
            targetTile.SetDiceOnTile(targetDice);//ensure target is not considered for pathfinding
            startingTile.RemoveDiceOnTile();
        }
    }
コード例 #11
0
    internal async Task CalculateAttackEnemy(Dice_Control attackingDice, Dice_Control targetEnemyDice, List <TileControl> path)
    {
        if (attackingDice.currentValue % 2 == 0)
        {
            int remainder = targetEnemyDice.currentValue - attackingDice.currentValue;
            if (remainder < 0)
            {
                Debug.Log($"Attacker won {-remainder} remaining");
                await HopTo(path, attackingDice, true);

                DestroySingleDice(targetEnemyDice);
                await attackingDice.AnimateDiceValueChange(-remainder);

                await MoveToEmptyTile(new List <TileControl> {
                    path.Last()
                }, attackingDice);
            }
            else if (remainder == 0)
            {
                Debug.Log($"Tie, both destroyed");
                await HopTo(path, attackingDice, true);

                gameControl.audioManager.PlaySound("hitEnemy");
                DestroySingleDice(attackingDice, true, false);
                DestroySingleDice(targetEnemyDice, true, false);
            }
            else
            {
                Debug.Log($"Defender now at {remainder}");
                await HopTo(path, attackingDice, true);

                await targetEnemyDice.AnimateDiceValueChange(remainder);

                gameControl.audioManager.PlaySound("hitEnemy");
                DestroySingleDice(attackingDice, true, false);
            }
            gameControl.playerControl.TakenMove(path.Count);
            gameControl.AllowInput();
        }
        else
        {
            Debug.Log($"Invlaid Move {attackingDice.currentValue} not attacker");
            InvalidMove(targetEnemyDice.tileControl);
        }
    }
コード例 #12
0
    private bool OutpostUnderAttack(Player player)
    {
        // if anyDice next to Outpost
        List <Dice_Control> playerOutposts = gameControl.playerControl.GetAllPlayerOutpost(player);
        List <TileControl>  adjacentTilesWithDice;

        if (playerOutposts.Count == 1)
        {
            Debug.Log($"1 Outpost for {player.playerName}");
            primaryOutpost        = playerOutposts[0];
            adjacentTilesWithDice = pathFinding.GetAjacentTiles(primaryOutpost.tileControl, GetAdjacentTilesType.AllEnemyDice, player);
            if (adjacentTilesWithDice.Count > 0)
            {
                Debug.Log($"Enemy Dice found next to outpost {primaryOutpost.tileControl.tileIndex}");
                if (adjacentTilesWithDice.Count == 1)
                {
                    gameControl.boardControl.CalculateBasesAttackEnemy(primaryOutpost, adjacentTilesWithDice[0].diceOnTile);
                }
                else
                {
                    //select best one to attack//for now, just select last
                    int last = adjacentTilesWithDice.Count;
                    gameControl.boardControl.CalculateBasesAttackEnemy(primaryOutpost, adjacentTilesWithDice[last - 1].diceOnTile);
                }
                return(true);
            }
            else
            {
                Debug.Log($"Oupost Safe at {primaryOutpost.tileControl.tileIndex}");
            }
        }
        else if (playerOutposts.Count > 1)
        {
            Debug.Log($"Multible Outposts for {player.playerName} TODO");
            //loop through each each outpost to see if enemy beside
        }
        else
        {
            Debug.Log($"No Outposts for {player.playerName}");
            primaryOutpost = null;
            return(false);
        }

        return(false);
    }
コード例 #13
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);
    }
コード例 #14
0
    private async Task MoveWorkerOneSquare(Player player)
    {
        //get all the workers beside the outpost
        List <TileControl> playersWorksNextToOutpost = pathFinding.GetAjacentTiles(primaryOutpost.tileControl, GetAdjacentTilesType.AllFriendlyWorkersDice, player);

        //nb should never have soldiers as, that was taken care of in a previous step.

        //move the last one to a corner tile of the outpost
        int last = playersWorksNextToOutpost.Count - 1;

        leiginToUse = playersWorksNextToOutpost[last].diceOnTile;

        List <TileControl> emptyTilesForLeigin = pathFinding.GetAjacentTiles(leiginToUse.tileControl, GetAdjacentTilesType.AllEmpty);

        Debug.Log($"moving dice {leiginToUse.tileControl} one square at {emptyTilesForLeigin [0].tileIndex}");
        await gameControl.boardControl.HopTo(new List <TileControl> {
            emptyTilesForLeigin [0]
        }, leiginToUse, false);
    }
コード例 #15
0
    private void CreateBase(Dice_Control selectedDice, Dice_Control targetDice)
    {
        selectedDice.transform.position = new Vector3(targetDice.transform.position.x, 2.75f, targetDice.transform.position.z);
        selectedDice.tileControl.RemoveDiceOnTile();

        //bottom
        targetDice.isBase    = true;
        targetDice.lowerDice = true;
        targetDice.tileControl.SetDiceOnTile(selectedDice);
        targetDice.child = selectedDice;

        //top
        selectedDice.isBase      = true;
        selectedDice.lowerDice   = false;
        selectedDice.tileControl = targetDice.tileControl;
        selectedDice.player.diceOwned.Remove(selectedDice.gameObject);
        selectedDice.gameObject.transform.SetParent(targetDice.gameObject.transform);
        selectedDice.gameObject.transform.localScale = new Vector3(1, 1, 1);

        gameControl.AllowInput();
    }
コード例 #16
0
    private void FindPrimaryOutPost(Player player)
    {
        List <Dice_Control> playerOutposts = gameControl.playerControl.GetAllPlayerOutpost(player);

        if (playerOutposts.Count == 1)
        {
            //Debug.Log($"1 Outpost for {player.playerName}");
            primaryOutpost = playerOutposts[0];
        }
        else if (playerOutposts.Count > 1)
        {
            Debug.Log($"Multible Outposts for {player.playerName} TODO");
            //for now just pick last
            int last = playerOutposts.Count;
            primaryOutpost = playerOutposts[last - 1];
        }
        else
        {
            Debug.Log($"No Outposts for {player.playerName}");
            primaryOutpost = null;
        }
    }
コード例 #17
0
 internal async void CalculateBasesAttackEnemy(Dice_Control OwenDice, Dice_Control targetDice)
 {
     if (targetDice.isBase)
     {
         //Debug.Log($"Invlaid Move bases can't attack bases");
         InvalidMove(targetDice.tileControl);
     }
     else
     {
         if (targetDice.currentValue > 1)
         {
             await targetDice.AnimateDiceValueChange(targetDice.currentValue - 1);//defending base attack value
         }
         else
         {
             targetDice.tileControl.RemoveDiceOnTile();
             DestroySingleDice(targetDice);
         }
         gameControl.audioManager.PlaySound("outpostAttack");
         gameControl.playerControl.TakenMove(1);
         gameControl.AllowInput();
     }
 }
コード例 #18
0
    public Dice_Control CreateDiceAt(TileControl targetTile, Player player, bool returnDice = false)
    {
        GameObject   newDice     = Instantiate(Dice, new Vector3(targetTile.transform.position.x, 2.5f, targetTile.transform.position.z), Quaternion.identity);
        Dice_Control diceControl = newDice.GetComponent <Dice_Control>();

        diceControl.diceColour   = player.playerColour;
        diceControl.player       = player;
        diceControl.currentValue = 1;
        diceControl.tileControl  = targetTile;
        targetTile.SetDiceOnTile(diceControl);
        newDice.name = player.name;
        newDice.transform.rotation = Quaternion.Euler(GlobalVariables.data.SIDE_ONE.x, GlobalVariables.data.SIDE_ONE.y, GlobalVariables.data.SIDE_ONE.z);
        newDice.transform.rotation.Normalize();
        newDice.transform.SetParent(player.transform);
        player.diceOwned.Add(newDice);
        gameControl.audioManager.PlaySound("createDice");

        if (player.ai == null)
        {
            gameControl.AllowInput();
        }

        return(returnDice == true ? diceControl : null);
    }
コード例 #19
0
    private async Task <bool> GetSolderAndAttackEnemy(Player player)
    {
        List <Dice_Control> playerSoldiers = gameControl.playerControl.GetAllPlayerSoldiers(player);

        if (playerSoldiers.Count == 0)
        {
            return(false);
        }
        else if (playerSoldiers.Count == 1)
        {
            leiginToUse = playerSoldiers[0];
            Debug.Log($"Soldier {leiginToUse.GetDiceValue()} found at {leiginToUse.tileControl.tileIndex}");
            await AttackNearestEnemy(leiginToUse, player);
        }
        else
        {
            Debug.Log($"Multible Soldiers found at {playerSoldiers.Count}");
            //loop through solders to get closes to enemy
            //for now just pick last
            int last = playerSoldiers.Count;
            await AttackNearestEnemy(playerSoldiers[last - 1], player);
        }
        return(true);
    }
コード例 #20
0
    internal async void CalculateAttackEnemyBase(Dice_Control attackingDice, Dice_Control targetEnemyBaseChild, List <TileControl> path)
    {
        if (attackingDice.currentValue % 2 == 0)
        {
            await HopTo(path, attackingDice, true);

            int remainder = targetEnemyBaseChild.currentValue - attackingDice.currentValue;
            if (remainder < 0)
            {
                Debug.Log($"base destoryed and left {6 - -remainder}");
                DestroySingleDice(attackingDice);
                DeconstrucetBase(targetEnemyBaseChild, 6 - -remainder);
            }
            else if (remainder == 0)
            {
                Debug.Log($"base destoryed");
                DestroySingleDice(attackingDice);
                DeconstrucetBase(targetEnemyBaseChild, 6);
            }
            else
            {
                Debug.Log($"base now at {remainder}");
                await targetEnemyBaseChild.AnimateDiceValueChange(remainder);

                DestroySingleDice(attackingDice);
            }
            gameControl.playerControl.TakenMove(path.Count);
            gameControl.AllowInput();
        }
        else
        {
            Debug.Log($"Invlaid Move {attackingDice.currentValue} not attacker");
            InvalidMove(targetEnemyBaseChild.tileControl);
        }
        //each case either has destroy base, that allows input, or is invalid, and set allow input
    }
コード例 #21
0
    //-----------------------------------------end path logic
    //-----------------------------------------start hop logic

    private async Task HopAnimation(Dice_Control diceToMove, TileControl tile)
    {
        //Debug.Log($"Starting to Hop from {diceToMove.tileControl.tileIndex} too {tile.tileIndex}");
        float   startTime     = Time.time;
        Vector3 origin        = diceToMove.transform.position;
        Vector3 destination   = tile.transform.position;
        float   journeyLength = 1;
        float   distCovered;
        float   fractionOfJourney = 0;

        origin.y = GlobalVariables.data.BOARD_CLEARANCE;
        diceToMove.transform.position = origin;

        destination.y = GlobalVariables.data.TILE_CLEARANCE;

        while (fractionOfJourney <= 1)
        {
            distCovered = (Time.time - startTime) * GlobalVariables.data.MOVE_SPEED;

            fractionOfJourney             = distCovered / journeyLength;
            diceToMove.transform.position = Vector3.Lerp(origin, destination, fractionOfJourney);

            if (fractionOfJourney >= 1)
            {
                //snap to tile logic
                diceToMove.transform.position = new Vector3((float)Mathf.Round(destination.x),
                                                            diceToMove.transform.position.y,
                                                            (float)Mathf.Round(destination.z));
            }
            else
            {
                await Task.Yield();
            }
        }
        UpdateBoardMeta(diceToMove.tileControl, tile);
    }
コード例 #22
0
 public void SetToDefault()
 {
     allowInput       = false;
     currentySelected = null;
     clickedObject    = null;
 }
コード例 #23
0
    private async Task AiLogic(Player player)
    {
        await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.AI_ACTION_SPEED));

        Debug.Log($"In {difficulty} AI {player.playerName} income: {player.income} <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        while (player.numberOfMoves > 0)
        {
            //Rand chance for this ?
            if (OutpostUnderAttack(player))
            {
                await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.AI_ACTION_SPEED));

                continue;// skip to next iteration
            }

            //dependant on income < threshold (recalculated when action is taken)
            if (player.income < incomeValueThreshold)
            {
                //will make new or add to workers if income less than threshold
                Debug.Log($"Player {player.playerName} Income Below {incomeValueThreshold}");
                FindPrimaryOutPost(player);

                if (primaryOutpost == null)
                {
                    Dice_Control dice_Control;
                    int          playerValue = 0;
                    foreach (GameObject dice in player.diceOwned)
                    {
                        dice_Control = dice.GetComponent <Dice_Control>();
                        playerValue += dice_Control.GetDiceValue();
                        if (playerValue >= 12)
                        {
                            break;
                        }
                    }

                    if (playerValue >= 12)
                    {
                        Debug.Log($"Player {player.playerName} value greater than 12, can make another outpost");
                        TryToCreateNewOutpost(player);
                    }
                    else
                    {
                        Debug.Log($"Player {player.playerName} < 12 attack enemy");

                        if (await GetSolderAndAttackEnemy(player) == false)
                        {
                            //create soldier from workers
                            //get worker nearest enemy, get workers nearest to that one, then combine to create a soldier
                            Debug.Log($"Player {player.playerName} only has workers >>>>> not implemented to find nearby workers, to make a solder, to attack");
                        }
                        //List<Dice_Control> playerSoldiers = gameControl.playerControl.GetAllPlayerSoldiers(player);
                        //if(playerSoldiers.Count == 0)
                        //{
                        //    //create soldier from workers
                        //    //get worker nearest enemy, get workers nearest to that one, then combine to create a soldier
                        //    Debug.Log($"Player {player.playerName} only has workers >>>>> not implemented to find nearby workers, to make a solder, to attack");
                        //} else
                        //{
                        //    await AttackNearestEnemy(playerSoldiers[0], player);
                        //}
                    }
                }
                else
                {
                    if (player.numberOfMoves >= 2)
                    {
                        //todo, loop through all outposts and add together
                        Debug.Log($"Trying to Add 2 too value 1 workers near outpost at {primaryOutpost.tileControl.tileIndex}");
                        List <TileControl> workersNextToPrimaryOutpost = pathFinding.GetAjacentTiles(primaryOutpost.tileControl, GetAdjacentTilesType.AllFriendlyWorkersDice, player);

                        //is there workers with value lower than threshold
                        await UpgradeWorkerOrCreateNew(workersNextToPrimaryOutpost);
                    }
                    else
                    {
                        //for when the player only has one move left
                        DetermineLastMove(player);
                    }
                }
            }
            else
            {
                // start to attack
                List <Dice_Control> playerSoldiers = gameControl.playerControl.GetAllPlayerSoldiers(player);
                Debug.Log($"Player {player.playerName} Income Avove {incomeValueThreshold} -> attack with {playerSoldiers.Count} soldiers");

                if (playerSoldiers.Count == 0)
                {
                    Debug.Log($"No soldier found for {player.playerName}");
                    List <TileControl> playersWorksNextToOutpost = pathFinding.GetAjacentTiles(primaryOutpost.tileControl, GetAdjacentTilesType.AllFriendlyWorkersDice, player);

                    leiginToUse = null;
                    foreach (TileControl worker in playersWorksNextToOutpost)
                    {
                        if (worker.diceOnTile.GetDiceValue() <= soldierValueThreshold)
                        {
                            //soldierTile.diceOnTile.GetDiceValue() != 6
                            leiginToUse = worker.diceOnTile;
                            //break;//stop looking
                        }
                    }

                    if (leiginToUse == null)
                    {
                        //will have to check for empty spaces first, else move a dice ?
                        Debug.Log($"No workers next to outpost {primaryOutpost.tileControl.tileIndex}, below threshold {soldierValueThreshold}");
                        CreateWorkerNextToOupost(primaryOutpost);
                    }
                    else
                    {
                        Debug.Log($"Adding +1 to make Soldier {leiginToUse.tileControl.tileIndex} next to {primaryOutpost.tileControl.tileIndex}");
                        gameControl.boardControl.BaseReenforceAdjacent(leiginToUse);
                    }
                }
                else if (playerSoldiers.Count == 1)
                {
                    leiginToUse = playerSoldiers[0];
                    Debug.Log($"Soldier {leiginToUse.GetDiceValue()} found at {leiginToUse.tileControl.tileIndex}");
                    await AttackNearestEnemy(leiginToUse, player);
                }
                else
                {
                    Debug.Log($"Multible Soldiers found at {playerSoldiers.Count}");
                    //loop through solders to get closes to enemy
                    //for now just pick last
                    int last = playerSoldiers.Count;
                    await AttackNearestEnemy(playerSoldiers[last - 1], player);
                }
            }
            await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.AI_ACTION_SPEED));
        }
        await Task.Delay(TimeSpan.FromSeconds(GlobalVariables.data.AI_ACTION_SPEED));
    }
コード例 #24
0
    internal async void CombineFriendlyDice(Dice_Control selectedDice, Dice_Control targetDice, List <TileControl> path)
    {
        if (selectedDice.GetInstanceID() == targetDice.GetInstanceID())
        {
            InvalidMove(targetDice.tileControl);
            return;
        }

        int sum = selectedDice.currentValue + targetDice.currentValue;

        if (targetDice.isBase)
        {
            if (targetDice.GetDiceValue() == 6)
            {
                InvalidMove(targetDice.tileControl);
                return;
            }

            if (sum > 6)
            {
                Debug.Log($"Reenforcing outpost from {targetDice.currentValue} to 6");
                await HopTo(path, selectedDice);

                await targetDice.AnimateDiceValueChange(6);

                await selectedDice.AnimateDiceValueChange(sum - 6);
            }
            else if (sum == 6)
            {
                Debug.Log($"Absorbing unit, from {targetDice.currentValue} to 6");
                await HopTo(path, selectedDice);

                await targetDice.AnimateDiceValueChange(6);

                DestroySingleDice(selectedDice, true, false);
                UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl, false);
            }
            else
            {
                Debug.Log($"Reenforcing outpost from {targetDice.currentValue} to " + sum);
                await HopTo(path, selectedDice);

                await targetDice.AnimateDiceValueChange(sum);

                DestroySingleDice(selectedDice, true, false);
                UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl, false);
            }
            //targetDice.SetSelected();//crashes here
            //gameControl.currentySelected = targetDice;
            gameControl.audioManager.PlaySound("combine");
            gameControl.playerControl.TakenMove(path.Count);
            gameControl.AllowInput();
            return;
        }
        else if (sum >= 12)
        {
            if (targetDice.isBase)
            {
                Debug.Log($"Target already base {targetDice.tileControl.tileIndex}");
                InvalidMove(targetDice.tileControl);
                return;
            }
            gameControl.currentySelected = null;
            await HopTo(path, selectedDice);

            UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl);
            Debug.Log($"Making new Base at {targetDice.tileControl.tileIndex}");
            CreateBase(selectedDice, targetDice);
        }
        else if (sum > 6)
        {
            if (targetDice.currentValue == 6)
            {
                Debug.Log($"Invlaid Move target at maximum");
                InvalidMove(targetDice.tileControl);
                return;
            }
            Debug.Log($"Setting target from {targetDice.currentValue} to 6");
            await HopTo(path, selectedDice);

            await targetDice.AnimateDiceValueChange(6);

            await selectedDice.AnimateDiceValueChange(sum - 6);
        }
        else if (sum <= 6)
        {
            await HopTo(path, selectedDice);

            Debug.Log($"Combining dice, {sum}");
            await targetDice.AnimateDiceValueChange(sum);

            DestroySingleDice(selectedDice, true, false);
            UpdateBoardMeta(selectedDice.tileControl, targetDice.tileControl, false);
        }
        selectedDice.SetDeselected();
        targetDice.SetSelected();
        gameControl.currentySelected = targetDice;
        gameControl.audioManager.PlaySound("combine");
        gameControl.playerControl.TakenMove(path.Count);
        gameControl.AllowInput();
    }
コード例 #25
0
    //-----------------------------------------end hop logic
    //-----------------------------------------start dice actions

    internal async Task MoveToEmptyTile(List <TileControl> path, Dice_Control diceToMove)
    {
        //Debug.Log($"Moving to Empty Tile");
        //gameControl.playerControl.TakenMove(path.Count);
        await HopTo(path, diceToMove, false);
    }
コード例 #26
0
 public void RemoveDiceOnTile()
 {
     this.diceOnTile = null;
     SetIsEmptyTile();
     SetValidPathfing();
 }
コード例 #27
0
    private async void MouseControl()
    {
        ray = mainCamera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 100))
        {
            clickedObject = hit.transform.gameObject;
            if (currentySelected == null)
            {
                if (clickedObject.name == playerControl.activePlayer.name)
                {
                    Dice_Control clickedDice = clickedObject.GetComponent <Dice_Control>();
                    if (clickedDice.lowerDice == false && clickedDice.isBase)
                    {
                        clickedDice = clickedObject.transform.parent.GetComponent <Dice_Control>();
                    }
                    currentySelected = clickedDice;
                    clickedDice.SetSelected();
                }
                AllowInput();
            }
            else
            {
                if (currentySelected.isBase)
                {
                    if (currentySelected.gameObject.GetInstanceID() == clickedObject.GetInstanceID() ||
                        currentySelected.child.gameObject.GetInstanceID() == clickedObject.GetInstanceID())
                    {
                        print("Deselecting currently seleted");
                        currentySelected.SetDeselected();
                        currentySelected = null;
                        AllowInput();
                        return;
                    }

                    float distance = Vector3.Distance(currentySelected.transform.position, clickedObject.transform.position);
                    //print("current distance to clicked object is: " + distance);
                    if (distance <= GlobalVariables.data.BASE_SPAWN_DISTANCE)
                    {
                        if (clickedObject.name == GlobalVariables.data.TILE_NAME || clickedObject.name == currentySelected.player.name)
                        {
                            TileControl clickedTile = clickedObject.GetComponent <TileControl>();
                            if (clickedTile == null)
                            {
                                clickedTile = clickedObject.GetComponent <Dice_Control>().tileControl;
                            }
                            if (clickedTile.diceOnTile == null)
                            {
                                boardControl.CreateDiceAt(clickedTile, currentySelected.player);
                                playerControl.TakenMove();
                            }
                            else
                            {
                                Dice_Control diceOneTile = clickedTile.diceOnTile;
                                if (currentySelected.player.name == diceOneTile.player.name)
                                {
                                    boardControl.BaseReenforceAdjacent(diceOneTile);
                                }
                                else
                                {
                                    boardControl.CalculateBasesAttackEnemy(currentySelected, diceOneTile);
                                }
                            }
                        }
                        else if (clickedObject.GetComponent <Dice_Control>() != null)
                        {
                            boardControl.CalculateBasesAttackEnemy(currentySelected, clickedObject.GetComponent <Dice_Control>());
                        }
                        else
                        {
                            print("the user clicked a non player, not board object");
                            AllowInput();
                        }
                    }
                    else
                    {
                        TileControl clickedTile = clickedObject.GetComponent <TileControl>();
                        if (clickedTile == null)
                        {
                            Debug.Log($"object too far to consider Creating dice");
                            Dice_Control dice_Control = clickedObject.GetComponent <Dice_Control>();
                            if (dice_Control != null)
                            {
                                boardControl.InvalidMove(dice_Control.tileControl);
                            }
                            AllowInput();
                        }
                        else
                        {
                            boardControl.InvalidMove(clickedTile);
                        }
                    }
                }
                else
                {
                    if (currentySelected.gameObject.GetInstanceID() == clickedObject.GetInstanceID())
                    {
                        print("Deselected currently seleted");
                        currentySelected.SetDeselected();
                        currentySelected = null;
                        AllowInput();
                        return;
                    }

                    if (clickedObject.name == GlobalVariables.data.TILE_NAME || clickedObject.name == currentySelected.player.name)
                    {
                        //handles if dice was clicked, get the assosicated tile
                        TileControl clickedTile = clickedObject.GetComponent <TileControl>();
                        if (clickedTile == null)
                        {
                            clickedTile = clickedObject.GetComponent <Dice_Control>().tileControl;
                        }

                        List <TileControl> path = boardControl.Pathfind(currentySelected.tileControl, clickedTile, playerControl.activePlayer.numberOfMoves);
                        if (path == null)
                        {
                            AllowInput();
                            return;
                        }
                        else
                        {
                            PrintPath(path);
                            if (clickedTile.diceOnTile == null)
                            {
                                await boardControl.MoveToEmptyTile(path, currentySelected);

                                playerControl.TakenMove();
                                AllowInput();
                            }
                            else
                            {
                                Dice_Control diceOneTile = clickedTile.diceOnTile;
                                if (currentySelected.player.name == diceOneTile.player.name)
                                {
                                    //this gets the child dice when a base is the target
                                    if (diceOneTile.isBase && diceOneTile.lowerDice)
                                    {
                                        boardControl.CombineFriendlyDice(currentySelected, diceOneTile.transform.GetChild(6).GetComponent <Dice_Control>(), path);
                                    }
                                    else
                                    {
                                        boardControl.CombineFriendlyDice(currentySelected, diceOneTile, path);
                                    }
                                }
                                else
                                {
                                    if (diceOneTile.isBase)
                                    {
                                        boardControl.CalculateAttackEnemyBase(currentySelected, diceOneTile.transform.GetChild(6).GetComponent <Dice_Control>(), path);
                                    }
                                    else
                                    {
                                        await boardControl.CalculateAttackEnemy(currentySelected, diceOneTile, path);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Dice_Control clickedDice = clickedObject.GetComponent <Dice_Control>();
                        if (clickedDice != null)
                        {
                            List <TileControl> path = boardControl.Pathfind(currentySelected.tileControl, clickedDice.tileControl, playerControl.activePlayer.numberOfMoves);
                            if (path == null)
                            {
                                AllowInput();
                                return;
                            }
                            else
                            {
                                PrintPath(path);
                                if (clickedDice.isBase)
                                {
                                    if (clickedDice.lowerDice)
                                    {
                                        boardControl.CalculateAttackEnemyBase(currentySelected, clickedDice.transform.GetChild(6).GetComponent <Dice_Control>(), path);
                                    }
                                    else
                                    {
                                        boardControl.CalculateAttackEnemyBase(currentySelected, clickedDice, path);
                                    }
                                }
                                else
                                {
                                    await boardControl.CalculateAttackEnemy(currentySelected, clickedDice, path);
                                }
                            }
                        }
                        else
                        {
                            AllowInput();
                            print("the user clicked a non player, not board object");
                        }
                    }
                }
            }
        }
        else
        {
            AllowInput();
        }
    }
コード例 #28
0
 public void SetDiceOnTile(Dice_Control diceOnTile)
 {
     this.diceOnTile = diceOnTile;
     SetHasPieceOnTile();
     SetCanNotPassThrough();
 }