Exemplo n.º 1
0
    void CheckForConfusion()
    {
        confusedTimer.Decrement();
        if (confusedTimer.Count() == 0)
        {
            //assess weather we need to switch states
            if (directionSwitchedCount > 4)
            {
                //we are confused. store the current state so we can figure out how to deal with the confusion
                //PopText.Create("Confusion Detected!", Color.white, 120,this.transform.position);
                if (myState != AIState.ConfusedState)
                {
                    confusedState = myState;
                    //PopText.Create("STATE: " + confusedState.ToString(), Color.white, 120,this.transform.position);
                }
                myState = AIState.ConfusedState;
            }
            directionSwitchedCount = 0;
            confusedTimer.Reset();


            if (myState != AIState.ConfusedState)
            {
                //PopText.Create("My State: " + myState.ToString(), Color.white, 120,this.transform.position);
            }
            else
            {
                //PopText.Create("Confused State: " + confusedState.ToString(), Color.white, 120,this.transform.position);
            }
        }
    }
Exemplo n.º 2
0
    void Confused()
    {
        int maxFloor = AIP.MaxFloor();

        if (confusedState == AIState.BombOnGround)
        {
            myLSB = GameObject.FindObjectOfType <LocalStickyBomb> ();

            if (myLSB == null)
            {
                if (myPlayer.hasStickyBomb)
                {
                    //i have the bomb again, switch states
                    myState = AIState.IHaveBomb;

                    //find a target based off of distance away
                    chasePlayer = FindClosestPlayer();

                    if (chasePlayer == null)
                    {
                        Debug.LogError("There is no player that is closest to this AI.");
                    }
                }
                else
                {
                    //either someone else picked it up, or it exploded.
                    crate = GameObject.FindObjectOfType <StickyCrate> ();

                    if (crate != null)
                    {
                        //it exploded because a new crate spawned.
                        myState = AIState.CrateAvailable;
                    }
                    else
                    {
                        //no new crate - someone else picked it up
                        myState = AIState.SomeoneElseHasBomb;
                        PlayerController hbp = PlayerController.GetPlayerWithBomb();

                        if (hbp.playerID != myPlayer.playerID)
                        {
                            hasBombPlayer = hbp;
                        }
                    }
                }
            }
            else
            {
                AIP cM = AIP.FindClosestMaster(maxFloor, myLSB.transform.position);
                MoveTowards(cM.gameObject);
                //PopText.Create("Master", Color.gray, 50, cM.transform.position);

                if (Vector3.Distance(cM.transform.position, this.transform.position) < .5f)
                {
                    //our work here is done.
                    myState = AIState.BombOnGround;
                }
            }
        }
        else if (confusedState == AIState.IHaveBomb)
        {
            playerChaseTimer.Decrement();

            if (playerChaseTimer.Count() == 0)
            {
                //ree-evaluate closest player
                chasePlayer = FindClosestPlayer();
                playerChaseTimer.Reset();
            }

            //go to the max floor and figure it out from there.
            if (chasePlayer != null)
            {
                AIP cM = AIP.FindClosestMaster(maxFloor, chasePlayer.transform.position);
                MoveTowards(cM.gameObject);
                //PopText.Create("Master", Color.red, 50, cM.transform.position);
            }
        }
        else if (confusedState == AIState.SomeoneElseHasBomb)
        {
            //go to the max floor and figure it out from there.
            if (hasBombPlayer != null)
            {
                AIP cM = AIP.FindClosestMaster(maxFloor, hasBombPlayer.transform.position);
                MoveTowards(cM.gameObject);
            }
        }
        else if (confusedState == AIState.CrateAvailable)
        {
            myState = AIState.Idle;
        }
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        CheckForConfusion();

        if (movementFrozen)
        {
            freezeTimer.Decrement();

            if (freezeTimer.Count() == 0)
            {
                movementFrozen = false;
                fmState        = FMState.None;
            }

            FrozenMove();
        }

        if (justJumped)
        {
            jumpTimer.Decrement();

            if (jumpTimer.Count() == 0)
            {
                justJumped = false;
                jumpTimer.Reset();
            }
        }

        switch (myState)
        {
        case AIState.Idle:
            Idle();
            break;

        case AIState.CrateAvailable:
            GoToCrate();
            break;

        case AIState.IHaveBomb:
            IHaveBomb();
            break;

        case AIState.IThrewBomb:
            IThrewBomb();
            break;

        case AIState.SomeoneElseStuck:
            RunFromStuckPlayer();
            break;

        case AIState.SomeoneElseHasBomb:
            SomeoneElseHasBomb();
            break;

        case AIState.BombOnGround:
            GoToBomb();
            break;

        case AIState.IAmStuck:
            IAmStuck();
            break;

        case AIState.SomeoneElseThrewBomb:
            AvoidBombMidAir();
            break;

        case AIState.ConfusedState:
            Confused();
            break;
        }

        //always check for if u get stuck
        if (myState != AIState.IAmStuck)
        {
            if (myPlayer.isStuck)
            {
                myState     = AIState.IAmStuck;
                chasePlayer = FindClosestPlayer();
            }
        }

        RealizeErrors();
    }