Example #1
0
    public float AIClear(PlayerStatePattern pl, DecisionEntery de)
    {
        //if desicion entery's special string isnt null then trigger the special.
        //the attack manager will then handle the rest.
        if (de.special != null)
        {
            AttackManager.Instance.ExecuteAbility(de.special, pl.playerStats);
        }

        //create the direction we want to kick the ball.
        Vector2 kickDirection = Vector2.zero;

        //check the goal zones.
        foreach (GoalZone gz in Field.Instance.gz)
        {
            //if the goal zone is not our own then create a vector between it an the player.
            if (gz.team != pl.playerStats.team)
            {
                kickDirection = (gz.transform.position - pl.transform.position);
            }
        }

        //normalize the kick direction and remove its Y component. we want to make it cross feild, not anything else.
        kickDirection.Normalize();
        kickDirection = new Vector2(kickDirection.x * pl.playerStats.pass * pl.playerStats.attackStrengthMultiplier * 2, 0);

        //finally shoot the ball when we are ready!
        GameManager.Instance.GetComponent <BallKick>().KickBall(kickDirection);
        pl.dePossessBall();

        Debug.Log("clear triggered");
        return(waitDelay);
    }
Example #2
0
    public IEnumerator CalculateAttack(PlayerStatePattern pl, DecisionEntery de, bool wait)
    {
        if (wait)
        {
            yield return(new WaitForSeconds(GameManager.Instance.universalAnimationDuration));
        }

        //set up the direction of the attack.
        Vector2 kickDirection;

        //base it off of the position of both players then normalize to only get the direction.
        kickDirection = (de.target.transform.position - pl.transform.position);
        kickDirection.Normalize();

        //take the direction and factor in player attack stats.
        kickDirection = new Vector2(kickDirection.x * pl.playerStats.attack * pl.playerStats.attackStrengthMultiplier * 4, kickDirection.y * pl.playerStats.attack * pl.playerStats.attackStrengthMultiplier);

        //calculate the damage the shot should do.
        float damage = pl.playerStats.attack;

        //FIRE IN THE HOLE!
        GameManager.Instance.GetComponent <BallKick>().KickBall(kickDirection);
        GameManager.Instance.ballReference.GetComponent <BallAttack>().DefaultAttack(damage, GameManager.Instance.defaultAttackDuration, pl.playerStats);
        pl.dePossessBall();

        Debug.Log("Attack Target is: " + de.target);
        Debug.Log("Attack triggered by " + pl.playerStats.playerName + " towards: " + kickDirection);

        yield return(null);
    }
Example #3
0
 public void GetPlayerChoice(PlayerStatePattern p, DecisionEntery[] de)
 {
     if (!userPollFlag)
     {
         StartCoroutine(PollUser(p, de));
     }
     else
     {
         Debug.LogError("Something went wrong. User was polled twice at once.");
     }
 }
Example #4
0
    public float AISteal(PlayerStatePattern pl, DecisionEntery de)
    {
        //Debug.Log("steal triggered by " + pl.playerStats.playerName);
        //return 0;

        attackerCombinedAttribute = pl.playerStats.speed + pl.playerStats.dribble; //attackers will be gaged by speed and dribble.
        defenderCombinedAttribute = de.target.defence + de.target.dribble;         //defenders will be gaged by defence and dribble.

        calcualtedRatio = defenderCombinedAttribute / attackerCombinedAttribute;

        if (calcualtedRatio > GameManager.Instance.stealStatThreshold)
        {
            //enemy stats are too high! stealing cant work against this target.
            successRoll = 10;
        }
        else if (calcualtedRatio > GameManager.Instance.stealStatThreshold + GameManager.Instance.stealStatLeanience)
        {
            //stats are nearly tied. its a 50/50
            successRoll = 50;
        }
        else if (calcualtedRatio > GameManager.Instance.stealStatThreshold - GameManager.Instance.stealStatLeanience)
        {
            //stats are nearly tied. its a 50/50
            successRoll = 50;
        }
        else
        {
            //your stats are far supirior, success is nearly garenteed!
            successRoll = 90;
        }

        finalRoll = Random.Range(0, 100);

        if (finalRoll < successRoll)
        {
            //steal successfull!!!
            de.target.SendMessage("BallStolen", true);
            pl.ballReference.UnpossessBall();
            pl.ballReference.PossessBall(pl.playerStats);
            return(waitDelay);
        }
        else
        {
            //steal failed!!! D:
            de.target.SendMessage("BallStolen", false);
            waitDelay = 1; //the penalty for failing a steal is waiting and doing nothing for a short time.
            return(waitDelay);
        }
    }
Example #5
0
    public float AIAttack(PlayerStatePattern pl, DecisionEntery de)
    {
        //if desicion entery's special string isnt null then trigger the special.
        //the attack manager will then handle the rest.
        if (de.special != null)
        {
            AttackManager.Instance.ExecuteAbility(de.special, pl.playerStats);
            new Task(CalculateAttack(pl, de, true));
        }
        else
        {
            new Task(CalculateAttack(pl, de, false));
        }

        return(waitDelay);
    }
Example #6
0
    private IEnumerator PollUser(PlayerStatePattern p, DecisionEntery[] de)
    {
        //engage user poll flag.
        userPollFlag  = true;
        currentPlayer = p;
        slowTimer     = GameManager.Instance.timeSlowDuration;

        //enable player choice UI. (un-hide or un-grey or whatever needs to be done.)
        //TODO I actually have an incredible amount of flexibility here. I can make the buttons dynamically generated if i so choose.
        foreach (DecisionEntery d in de)
        {
            if (d != null)
            {
                ActivateUIElements(d.name);
            }
        }

        //display options based on player. (If attack show X, if defence show Y)
        //Display Specials as well...?

        yield return(null);

        timerImage.fillAmount = 1;

        //engage while loop and wait for user input. (break if user input is not null)
        while (slowTimer > 0 && userDecision == null)
        {
            //Debug.LogWarning("Doing a thing" + slowTimer + Time.deltaTime);
            slowTimer            -= Time.deltaTime;
            timerImage.fillAmount = (slowTimer / GameManager.Instance.timeSlowDuration);
            yield return(null);
        }
        //Debug.LogWarning("Finished a thing");
        //take user input and send back in the form of a callback.
        p.sPlayerActionDecision.userDecision = userDecision;
        if (p.sPlayerActionDecision.userDecision == null)
        {
            //TOO SLOW!!! ***************************************************************************************************
        }
        //if there is no input or input is invalid simply return null. put UI element on screen saying "TOO SLOW!"

        userPollFlag = false;
        DisableAllUIElements();
        ClearTimer();
        clearAll();
        yield return(null);
    }
Example #7
0
    /// <summary>
    /// initializes player. MUST BE CALLED WHEN INSTANCING A PLAYER OR ELSE DEFAULT VALUES WILL BE GIVEN.
    /// </summary>
    /// <param name="initSpeed">starting speed</param>
    /// <param name="initAttack">starting attack</param>
    /// <param name="initDefence">starting defence</param>
    /// <param name="initShoot">starting shooting skill</param>
    /// <param name="initPass">starting passing skill</param>
    /// <param name="initDribble">starting dribbling skill</param>
    /// /// <param name="initPlayerName">players name for UI reference</param>
    public void SetPlayerStartingValues(float initSpeed, float initAttack, float initDefence, float initShoot, float initPass, float initDribble, int initTeam, int initPosition, Vector2 initLocation, string initPlayerName, bool initAI)
    {
        //set our class variables.
        speed         = initSpeed;
        attack        = initAttack;
        defence       = initDefence;
        shoot         = initShoot;
        pass          = initPass;
        team          = initTeam;
        dribble       = initDribble;
        position      = initPosition;
        playerName    = initPlayerName;
        StartLocation = initLocation;
        AI            = initAI;

        //set player health
        currentHealth = maxHealth;

        //name the game object the same name as ME! this makes troublshooting easier.
        this.gameObject.name = initPlayerName;


        //find our movement class.
        pm = GetComponent <PlayerMove>();

        //find our AI controller
        psp = GetComponent <PlayerStatePattern>();

        // if we found the movement class set its speed to relate to the cards speed stat. otherwise throw an error.
        if (pm != null)
        {
            UpdateSpeed(speed);
            UpdateUI();
        }
        else
        {
            throw new UnityException("PlayerMove Script not found. (Initialization) Please consult programmer for troubleshooting help.");
        }

        //move player into specified starting position.
        transform.position = initLocation;

        SPAttacks = new Dictionary <string, int>();
    }
Example #8
0
    private IEnumerator calculateDecisionWithTarget(PlayerStatePattern p, int name)
    {
        calculatingDecision = true;
        Vector2 shotTarget = Vector2.zero;

        //as long as there is no target and there is still time keep polling for a user generated target.
        while (slowTimer > 0 && shotTarget == Vector2.zero)
        {
            shotTarget = GetLastTouchLocation();
            yield return(null);
        }
        if (shotTarget != Vector2.zero)
        {
            userDecision            = new DecisionEntery(name);
            userDecision.shotTarget = shotTarget;
        }
        calculatingDecision = false;
        yield return(null);
    }
Example #9
0
    //construct with a readonly directive telling what AI owns this instance. could be usefull.
    public PlayerActionDecision(PlayerStatePattern playerStatePatern)
    {
        player = playerStatePatern;

        attack  = new Attack();
        steal   = new Steal();
        Pass    = new Pass();
        dribble = new Dribble();
        cross   = new Cross();
        clear   = new Clear();
        shoot   = new Shoot();

        //fieldMask = Field.Instance.gameObject.layer;
        playerMask = player.gameObject.layer;
        //BallMask = player.ballReference.gameObject.layer;

        options = new DecisionEntery[10];

        teamsArentSet = true;
    }
Example #10
0
    private IEnumerator calculateDecisionWithTarget(bool mt, PlayerStatePattern p, int name)
    {
        calculatingDecision = true;
        Player target = null;

        //as long as there is no target and there is still time keep polling for a user generated target.
        while (slowTimer > 0 && target == null)
        {
            target = ChooseTarget(mt, p);
            yield return(null);
        }

        if (target != null)
        {
            userDecision        = new DecisionEntery(name);
            userDecision.target = target;
        }

        calculatingDecision = false;
        yield return(null);
    }
Example #11
0
    public float AIPass(PlayerStatePattern pl, DecisionEntery de)
    {
        //if desicion entery's special string isnt null then trigger the special.
        //the attack manager will then handle the rest.
        if (de.special != null)
        {
            AttackManager.Instance.ExecuteAbility(de.special, pl.playerStats);
        }

        Vector2 kickDirection;

        kickDirection = (de.target.transform.position - pl.transform.position);
        kickDirection.Normalize();

        kickDirection = new Vector2(kickDirection.x * pl.playerStats.pass * pl.playerStats.attackStrengthMultiplier, kickDirection.y * pl.playerStats.pass * pl.playerStats.attackStrengthMultiplier);

        GameManager.Instance.GetComponent <BallKick>().KickBall(kickDirection);
        de.target.SendMessage("IncomingPass");
        pl.dePossessBall();

        Debug.Log("pass triggered");
        return(waitDelay);
    }
Example #12
0
 //construct with a readonly directive telling what AI owns this instance. could be usefull.
 public PlayerDead(PlayerStatePattern playerStatePatern)
 {
     player = playerStatePatern;
 }
 public GrabblerState(PlayerStatePattern pattern)
 {
     player = pattern;
 }
 //construct with a readonly directive telling what AI owns this instance. could be usefull.
 public PlayerChaseBall(PlayerStatePattern playerStatePatern)
 {
     player = playerStatePatern;
 }
Example #15
0
 //construct with a readonly directive telling what AI owns this instance. could be usefull.
 public PlayerMovingToPosition(PlayerStatePattern playerStatePatern)
 {
     player = playerStatePatern;
     t      = 0.5f;
 }
 //construct with a readonly directive telling what AI owns this instance. could be usefull.
 public PlayerRunAndDribble(PlayerStatePattern playerStatePatern)
 {
     player = playerStatePatern;
 }
Example #17
0
 public void TriggerGameSlow(PlayerStatePattern p)
 {
     //Debug.LogWarning("IT WAS I, DIO");
     StartCoroutine(p.sPlayerActionDecision.UpdateStateTest());
 }
Example #18
0
    /// <summary>
    /// Prompts player to pick a target out of a set group of players.
    /// </summary>
    /// <param name="mt">will function include both teams? (If false: only use friendly players.)</param>
    /// <returns></returns>
    private Player ChooseTarget(bool mt, PlayerStatePattern p)
    {
        Player  Target       = null;
        float   lastDistance = 0;
        Vector2 userChoice   = Vector2.zero;

        //get position from user. (touch ended phase. or mouse click for debugging purposes.)
        //************************************************************************************************************************************************

        userChoice = GetLastTouchLocation();

        if (userChoice != Vector2.zero)
        {
            //pick closest unit to the end location.
            foreach (Player pl in GameManager.Instance.GetPlayers())
            {
                //check any entery that isnt null and Isnt the calling instance.
                if (pl != null && pl.gameObject.GetInstanceID() != p.gameObject.GetInstanceID())
                {
                    //if we are looking at my team then filter out enemies.
                    if (mt)
                    {
                        if (pl.team == p.playerStats.team)
                        {
                            //check distance
                            float d = Vector2.Distance(pl.gameObject.transform.position, userChoice);
                            //if the last distance is 0 or is greater than this one then replace it and set the target.
                            if (lastDistance == 0 || d < lastDistance)
                            {
                                lastDistance = d;
                                Target       = pl;
                            }
                        }
                    }
                    else//if we only want to look at opponants then we need to filter out teammates.
                    {
                        //only proceed for foes.
                        if (pl.team != p.playerStats.team)
                        {
                            //check distance
                            float d = Vector3.Distance(pl.gameObject.transform.position, userChoice);
                            //if the last distance is 0 or is greater than this one then replace it and set the target.
                            if (lastDistance == 0 || d < lastDistance)
                            {
                                lastDistance = d;
                                Target       = pl;
                            }
                        }
                    }
                }
            }
        }
        //return player.
        if (Target != null)
        {
            return(Target);
        }

        //if no value was found, user was too slow. return null and fail the operation.
        return(null);
    }
Example #19
0
 void clearAll()
 {
     userDecision  = null;
     currentPlayer = null;
 }
Example #20
0
 public float AICross(PlayerStatePattern pl, DecisionEntery de)
 {
     Debug.Log("cross triggered");
     return(waitDelay);
 }
Example #21
0
 public float AIDribble(PlayerStatePattern pl, DecisionEntery de)
 {
     Debug.Log("Dribble triggered");
     //for now im going to leave this blank. The end goal is to make the player do a shorter than averge move command that adds a defensive stat bonus for its duration so players cant steal from a dribbling player.
     return(waitDelay);
 }
 public JumpingState(PlayerStatePattern pattern)
 {
     player = pattern;
 }
Example #23
0
 public float UserPass(PlayerStatePattern pl, DecisionEntery de)
 {
     return(waitDelay);
 }
Example #24
0
 //construct with a readonly directive telling what AI owns this instance. could be usefull.
 public PlayerMovementDecision(PlayerStatePattern playerStatePatern)
 {
     player = playerStatePatern;
 }
 public WalkingState(PlayerStatePattern statePattern)
 {
     player = statePattern;
 }
Example #26
0
 //construct with a readonly directive telling what AI owns this instance. could be usefull.
 public PlayerWait(PlayerStatePattern playerStatePatern)
 {
     player = playerStatePatern;
     rb     = player.GetComponent <Rigidbody2D>();
 }