Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
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));
    }