Exemple #1
0
    private void GenerateAIUnits(AIBehavior attackingAI)
    {
        //find a tower to attack
        TowerBehavior destination = attackController.FindTowerToSendTroops(attackingAI);

        float percentage;

        AIConstants.ReasonFailed reason;

        //call attack simulation to see if an attack would succeed
        if (decisionController.ShouldAIAttack(attackingAI.myTower, destination, out percentage, out reason))
        {
            //if starting attack wasn't successful
            if (!attackingAI.StartAttack(destination, percentage, 1f))
            {
                //enqueue tower
                myQueue.EnqueueTower(attackingAI);
            }
        }


        else
        {
            //random chance to not try a power attack
            int randNum = UnityEngine.Random.Range(0, 101);
            if (randNum <= AIGameStateManager.ChanceToQueue)
            {
                myQueue.EnqueueTower(attackingAI);
            }

            //see if a tower is waiting for a power attack, power attack can only be done if the reason for a failed attack
            //was because of the number of units
            else if (myQueue.IsTowerWaiting() == true && reason == AIConstants.ReasonFailed.Units)
            {
                //get our second tower
                AIBehavior secondTowerAttacking = myQueue.GetTowerWaiting();
                float      queuePerc;
                //if power attack isn't possible, try overload attack
                if (decisionController.CanTwoAttack
                        (destination, attackingAI.myTower, secondTowerAttacking.myTower, percentage, out queuePerc) == false)
                {
                    List <MultiAttackInfo> info = new List <MultiAttackInfo>();
                    info.Add(new MultiAttackInfo(attackingAI, percentage));
                    info.Add(new MultiAttackInfo(secondTowerAttacking, queuePerc));

                    //if we can't overload, just enqueue the towers
                    if (decisionController.CanOverloadAttack(info) == false)
                    {
                        myQueue.EnqueueTower(secondTowerAttacking);
                        myQueue.EnqueueTower(attackingAI);
                    }

                    //if we can overload, try to start the overload attack
                    else
                    {
                        //if we can't start the overload attack for some reason, enqueue the towers
                        if (AIBehavior.StartOverLoadAttack(destination, info) == false)
                        {
                            myQueue.EnqueueTower(secondTowerAttacking);
                            myQueue.EnqueueTower(attackingAI);
                        }

                        //if Overload attack is successfully Happening, then set the timer for the second tower,
                        //the first timer is set after this function returns
                        else
                        {
                            secondTowerAttacking.SetMyTimer(gameStateManager.GetAIAttackTimer());
                        }
                    }
                }
                else
                {
                    List <MultiAttackInfo> info = new List <MultiAttackInfo>();
                    info.Add(new MultiAttackInfo(attackingAI, percentage));
                    info.Add(new MultiAttackInfo(secondTowerAttacking, queuePerc));

                    if (!AIBehavior.StartMultiAttack(destination, info))
                    {
                        myQueue.EnqueueTower(secondTowerAttacking);
                        myQueue.EnqueueTower(attackingAI);
                    }

                    //we are successfully attacking, so set the timer of the second attacking tower
                    else
                    {
                        secondTowerAttacking.SetMyTimer(gameStateManager.GetAIAttackTimer());
                    }
                }
            }

            //if distance,both, or notEnoughToSend
            else
            {
                myQueue.EnqueueTower(attackingAI);
            }
        }
    }