예제 #1
0
    //default state actions. frame by fram actions.
    public IEnumerator UpdateStateTest()
    {
        //Debug.Log(player.playerStats.playerName + " Decision began.");
        //make sure all shared values are cleared at the beginning of operations. just as a precaution.
        ClearAll();
        //make sure team arrays are populated for future use.
        if (teamsArentSet)
        {
            //quickly set our team arrays.
            setTeamArrays();
            teamsArentSet = false;
        }
        //weigh options.
        //Debug.Log(player.playerStats.playerName + " Calculating options");
        CalculateOptions(options);
        i = 0;
        j = 0;


        //decide if user should be involved.******************************************************************************************************
        //TODO add antitheft flag?
        //TODO consider higher probabilities effecting player choice time?

        //if im not an AI consider letting the player do stuff. dont trigger for any desicion that doesnt involve the ball.
        if (!player.playerStats.AI && player.isPossessing())
        {
            //if there are 3 options at 100% then ALWAYS grab the user
            //Heavily favor shooting.
            //if there are 3 options at 0% then NEVER grab the user
            n = 0; //averge weight
            j = 0; //number of valid enteries
            foreach (DecisionEntery de in options)
            {
                if (de != null)
                {
                    n += de.weight;
                    j++;
                }
            }
            n /= j; //the total weight / number of options = averge weight.
            //j has now changed to a random float for us.
            j = Random.Range(1, 100);

            //Debug.LogWarning("Averge Weight: " + n);
            //Debug.LogWarning("random chosen: " + j);
            if (j > n)
            {
                //call user
                //Debug.LogWarning("SUPER CALLED O.O");


                //if the player is involved

                //open player gui & display options
                //Debug.LogWarning("Wait for iiiiiittttt!");

                //slow the game
                PlayerManager.Instance.SlowTime();

                //wait for player responce (display timer)
                PlayerManager.Instance.GetPlayerChoice(player, options);

                // our timer. count down to zero OR break when a user desicion has been made.
                userWaitTimer = GameManager.Instance.timeSlowDuration;
                while (userWaitTimer > 0 && userDecision == null)
                {
                    userWaitTimer -= Time.deltaTime;
                    yield return(null);
                }
                userWaitTimer = 0;

                //Debug.LogWarning("Done!!!!");
                //reset game speed
                PlayerManager.Instance.ResetTime();

                //deploy user selected option -OR- choose WORST option
                if (userDecision == null)
                {
                    ChooseOption(false);
                }
                else//user chose an option! *************************************************************************************
                {
                    //perhaps change this?
                    chosenOption = userDecision;
                }
            }
        }

        //If the AI hasn't Been given an option choose one.
        if (chosenOption == null)
        {
            chosenOption = ChooseOption(true);
        }

        if (chosenOption != null)//if it skips this code then no option was seen. this is more than likely an error.
        {
            //TODO fix this complete hack. :(

            //do a "quick" check then engage the special flag if needed.

            #region SpecialAttackCheck
            //if your an AI check for special.
            if (player.playerStats.AI == true)
            {
                //check if the chosen option has a comperable special.
                foreach (KeyValuePair <string, int> attacks in player.playerStats.SPAttacks)
                {
                    //if there is not a special already saved check to grab one. (this means if you have 2 specials matching the type you get 2 rolls to use them. (at 50% to get a second roll.))
                    if (chosenOption.special == null || Random.Range(0, 2) > 0)
                    {
                        //here is our direct comparison. if they do not match then they are not compatable types.
                        if (AttackManager.Instance.GetAttackParentAction(attacks.Key) == chosenOption.name)
                        {
                            //check weighting, small random draw. MAGIC NUMBERS. CHANGE LATER!
                            if (chosenOption.weight > 60 && Random.Range(0, 10) > 3)
                            {
                                //if the weight is above 60 and a random of 70% is proc'ed then allow the special to trigger.
                                chosenOption.special = attacks.Key;
                            }
                            //check special remaining count.
                            if (attacks.Value <= 0)
                            {
                                //if you have no uses left null the special(It then cant be triggered) and continue.
                                chosenOption.special = null;
                            }
                        }
                    }
                }
            }

            #endregion

            //call action here
            //I WOULDVE RATHERED USE A SWITCH STATEMENT BUT I GUESS C# DOESNT LIKE USING THOSE WITH DICTIONARIES >.> #sass
            if (chosenOption.name == GameManager.Instance.AIActions["Attack"])
            {
                waitDelay = attack.AIAttack(player, chosenOption);
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["Pass"])
            {
                waitDelay = Pass.AIPass(player, chosenOption);
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["Shoot"])
            {
                waitDelay = shoot.AIShoot(player, chosenOption);
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["Dribble"])
            {
                waitDelay = dribble.AIDribble(player, chosenOption);
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["Cross"])
            {
                waitDelay = cross.AICross(player, chosenOption);
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["Clear"])
            {
                waitDelay = clear.AIClear(player, chosenOption);
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["Steal"])
            {
                waitDelay = steal.AISteal(player, chosenOption);
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["NotOpen"])
            {
                //Debug.Log(player.playerStats.playerName + " has decided he is open");
            }
            else if (chosenOption.name == GameManager.Instance.AIActions["Dive"])
            {
            }
            else
            {
                Debug.LogError("Something went wrong when choosing an action. Chosen option name is invalid. Please check chosen option name.");
            }
        }
        else
        {
            Debug.LogError("No valid choosenOption Available. Operation skipped.");
        }

        //reset option list.
        options = new DecisionEntery[options.Length];

        //move to wait state.
        //Debug.Log(player.playerStats.playerName + " Decision completed.");
        ToPlayerWait(waitDelay);
        updateExecuting = false;
        yield return(null);
    }