Exemplo n.º 1
0
    void BotUpdate()
    {
        if (myAiState != oldAiState)
        {
            isNewAiState = true; oldAiState = myAiState;
        }
        else
        {
            isNewAiState = false;
        }
        botHandler.isVisible(transform.position, attackTarget, botFov);
        if (targetVisible && !botHandler.isVisible(transform.position, attackTarget, botFov))
        {
            targetVisible = false;
            //Debug.Log("cannot see");
        }
        else if (!targetVisible && botHandler.isVisible(transform.position, attackTarget, botFov))
        {
            targetVisible = true;
            //Debug.Log("can see");
        }

        myController.isBraking = false;

        switch (myAiState)
        {
        case BotLogic.aiState.wander:
            if (isNewAiState)
            {
                Debug.Log("is wandering");
                bufferAiState = BotLogic.aiState.wander;
                navList       = navSystem.GetRandomPath(transform.position);
                botHandler.PlotCourse(ref navList);
                audioSource.clip = wander[0];
                audioSource.Play();
            }
            //if(botHandler.AtPosition())
            else if (botHandler.AtNavTarget(botFov, true, 10, 10))
            {
                navList = navSystem.GetRandomPath(transform.position);
                botHandler.PlotCourse(ref navList);
            }
            if (botHandler.BeginAttack(ref attackTarget, ref enemies, botFov))
            {
                myAiState = BotLogic.aiState.attack;
            }
            break;

        case BotLogic.aiState.getAmmo:
            if (isNewAiState)
            {
                Debug.Log("getting ammo");
                if (!botHandler.GetNavItem(ref navTarget, ref ammoRestore))
                {
                    myAiState = bufferAiState;
                    break;
                }
                navList = navSystem.GetPath(transform.position, navTarget.transform.position);
                botHandler.PlotCourse(ref navList);
                audioSource.clip = getAmmo[0];
                audioSource.Play();
            }
            else if (botHandler.AtNavTarget())
            {
                myAiState = bufferAiState;
            }
            break;

        case BotLogic.aiState.getShield:
            if (isNewAiState)
            {
                Debug.Log("getting shield");
                if (!botHandler.GetNavItem(ref navTarget, ref shieldRecharge))
                {
                    myAiState = bufferAiState; break;
                }
                navList = navSystem.GetPath(transform.position, navTarget.transform.position);
                botHandler.PlotCourse(ref navList);
                audioSource.clip = getShield[0];
                audioSource.Play();
            }
            else if (botHandler.AtNavTarget())
            {
                myAiState = bufferAiState;
            }
            break;

        case BotLogic.aiState.attack:
            if (isNewAiState)
            {
                Debug.Log("attacking!");
                bufferAiState    = BotLogic.aiState.attack;
                audioSource.clip = attack[0];
                audioSource.Play();
            }

            //this is where attack behavior comes in
            //options are:
            //1: try to ram player
            //2: keep at some operative distance
            //3: hit and run tactics
            //4: try to use special weapon
            //where possible bots should rotate to show players undamaged shields. maybe don't do explicily
            //some bots should be smart enough to investigate the lights and lasers of players
            //bots should also be able to hear player's engines and especially boosting
            switch (myAttackType)
            {
            case BotLogic.attackState.rush:
                botHandler.AtPosition(attackTarget.transform.position, true, true, true, 10);
                if (!botHandler.isVisible(transform.position, attackTarget, botFov))
                {
                    myAiState = BotLogic.aiState.investigate;
                }
                break;

            case BotLogic.attackState.holdPosition:
                break;

            case BotLogic.attackState.hitAndRun:
                break;

            case BotLogic.attackState.nimble:
                break;

            case BotLogic.attackState.circler:
                if (myController.isFire2Down)
                {
                    myController.isFire2Up = true; myController.isFire2Down = false;
                }
                else if (targetInCrosshair)
                //else if (botHandler.isVisible(transform.position, attackTarget, 1))
                {
                    if (bombTimer == -1)
                    {
                        bombTimer = Random.Range(minBombTime, maxBombTime);
                    }
                    else if (bombTimer < 0)
                    {
                        bombTimer = -1;
                        myController.isFire2Down = true;
                    }
                    else
                    {
                        bombTimer -= Time.deltaTime;
                    }
                    myController.isFire2Up = false;
                }
                if (myController.isFire1Down)
                {
                    myController.isFire1Up = true; myController.isFire1Down = false;
                }
                //else if (botHandler.isVisible(transform.position, attackTarget, 1))
                else if (targetInCrosshair)
                {
                    if (gunTimer == -1)
                    {
                        gunTimer = Random.Range(minGunTime, maxGunTime);
                    }
                    else if (gunTimer < 0)
                    {
                        gunTimer = -1;
                        myController.isFire1Down = true;
                    }
                    else
                    {
                        gunTimer -= Time.deltaTime;
                    }
                    myController.isFire1Up = false;
                }
                if (targetInCrosshair && Vector3.Magnitude(attackTarget.transform.position - transform.position) < 30)
                {
                    myController.isBraking = true;
                }
                else if (botHandler.AtPosition(attackTarget.transform.position, true, true, true, 30, false))
                {
                    botHandler.AtPosition(attackTarget.transform.position, false, false, true, 0, false);
                    myController.isBraking = true;
                }
                else
                {
                    needRandomVec = true;
                }
                if (!botHandler.isVisible(transform.position, attackTarget, botFov))
                {
                    myAiState = BotLogic.aiState.investigate;
                }
                break;

            default:
                break;
            }
            break;

        case BotLogic.aiState.investigate:
            if (isNewAiState)
            {
                Debug.Log("investigating point");
                navPoint         = attackTarget.transform.position;
                audioSource.clip = investigate[0];
                audioSource.Play();
            }
            if (targetVisible)
            {
                myAiState = BotLogic.aiState.attack;
            }
            else if (botHandler.AtPosition(navPoint, true, true, true, 0.5f))
            {
                myAiState = BotLogic.aiState.wander;
            }
            break;

        case BotLogic.aiState.guard:
            break;

        case BotLogic.aiState.flee:
            if (isNewAiState)
            {
                Debug.Log("fleeing");
                bufferAiState = BotLogic.aiState.wander;
                navList       = navSystem.GetRandomPath(transform.position);
                botHandler.PlotCourse(ref navList);
                audioSource.clip = flee[0];
                audioSource.Play();
            }
            else if (botHandler.AtNavTarget(botFov, true, 10, 10))
            {
                myAiState = BotLogic.aiState.wander;
            }
            break;

        case BotLogic.aiState.none:
            //botHandler.ResetReactionTime();
            //botHandler.isLookingAt(enemies[0].transform.position, 0, 1, true);
            //botHandler.AtPosition(enemies[0].transform.position, true, true, true, 10);
            break;

        default:
            break;
        }
    }