Example #1
0
    void Update()
    {
        //Stops ai if player has lost
        pHealth = PlayerProp.currentHealth;
        if (pHealth <= 0 || !RoundManager.startReady)
        {
            pauseAI = true;
        }
        else
        {
            pauseAI = false;
        }

        //If AI has not been paused
        if (!pauseAI)
        {
            decreaseTimers();

            if (!keepInput && breakTimer <= 0 && moveTimer <= 0)
            {
                MaxInput.ClearInput("Player2");
            }

            updateProperties();

            resetStateValues();

            calculateWeights();

            checkJump();

            if (delayTimer <= 0 && breakTimer <= 0 && moveTimer <= 0)
            {
                if (doingQCF > 0)
                {
                    AIInput.QCF();
                }
                else if (doingQCB > 0)
                {
                    AIInput.QCB();
                }
                else if (doingHCF > 0)
                {
                    AIInput.HCF();
                }
                else if (doingHCB > 0)
                {
                    AIInput.HCB();
                }
                else if (doingDP > 0)
                {
                    AIInput.DP();
                }
                else if (doing5L_1 > 0)
                {
                    AIInput.combo5L_1();
                }
                else if (doing2H_1 > 0)
                {
                    AIInput.combo2H_1();
                }
                else
                {
                    if (difficulty < 100)
                    {
                        if (delay())
                        {
                            return;
                        }
                    }

                    var max = states.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;   // Gets key with highest value
                    Debug.Log(max);

                    //If ai is on ground set jumping to false
                    if (GameObject.Find("Player2").transform.GetChild(0).transform.position.y <= 0)
                    {
                        isAirborne = false;
                    }

                    // Executes AI's state
                    if (aiCharacter == "Dhalia" || aiCharacter == "Achealis")
                    {
                        if (max == "Attack")
                        {
                            attack();
                        }
                        if (max == "Defend")
                        {
                            defend();
                        }
                        if (max == "Approach")
                        {
                            approach();
                        }
                        if (max == "Recover")
                        {
                            recover();
                        }
                    }

                    //testActions();  // REMEMBER TO COMMENT OUT WHEN DONE TESTING
                }
            }
        }
    }