コード例 #1
0
    /**
     *   this will execute when the state is entered
     */
    public override void Enter(GameObject CallingObject)
    {
        //Set as recieving and controlling player
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        PlayerScript.GetTeam().SetControllingPlayer(PlayerScript);
        PlayerScript.GetTeam().RecievingPlayer = PlayerScript;

        //TODO - maybe add more to this if statement
        //If player is close
        if (!PlayerScript.IsOppenentWithinRadius())
        {
            PlayerScript.GetSteeringController().TurnOn(Behaviour.Arrive);
        }
        else
        {
            PlayerScript.GetSteeringController().TurnOn(Behaviour.Pursue);

            Steer2D.Pursue Pur = (Steer2D.Pursue)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Pursue");
            Pur.TargetAgent = PlayerScript.Ball;
        }

        if (PlayerScript.DebugOn)
        {
            Debug.Log("Entering recieve ball state");
        }
    }
コード例 #2
0
    /**
     *   this will execute when the state is exited
     */
    public override void Exit(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        PlayerScript.GetSteeringController().TurnOff(Behaviour.Arrive);
        PlayerScript.GetSteeringController().TurnOff(Behaviour.Pursue);

        PlayerScript.GetTeam().RecievingPlayer = null;

        if (PlayerScript.DebugOn)
        {
            Debug.Log("Exiting Receive ball state");
        }
    }
コード例 #3
0
    /**
     *   this will execute when the state is entered
     */
    public override void Enter(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        PlayerScript.GetSteeringController().TurnOn(Behaviour.Arrive);

        Steer2D.Arrive Arr = (Steer2D.Arrive)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");

        Arr.TargetPoint = PlayerScript.GetTeam().GetSupportSpot();

        if (PlayerScript.DebugOn)
        {
            Debug.Log("Entering Support Attacker State");
        }
    }
コード例 #4
0
    /**
     *   this will execute when the state is entered
     */
    public override void Enter(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        PlayerScript.GetSteeringController().TurnOn(Behaviour.Arrive);

        Steer2D.Arrive Arr = (Steer2D.Arrive)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");

        Arr.TargetPoint = PlayerScript.HomePosition;

        if (PlayerScript.DebugOn)
        {
            Debug.Log("Entering Player Return to home state");
        }
    }
コード例 #5
0
    /**
     *   this is the updated fucntion for the state
     */
    public override void Excute(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        if (PlayerScript.BallInReceivingRange() || !PlayerScript.GetTeam().InControl())
        {
            PlayerScript.ChangeState(CallingObject, ChaseBall.Instance());

            return;
        }

        Steer2D.Arrive Arr = (Steer2D.Arrive)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");

        if (Arr.AtTarget)
        {
            //PlayerScript.ChangeState(CallingObject, Wait.Instance());
            //PlayerScript.GetSteeringController().TurnOff(Behaviour.Arrive);
            // PlayerScript.GetSteeringController().TurnOff(Behaviour.Pursue);
            PlayerScript.TrackBall();

            if (PlayerScript.IsClosestTeamMemberToBall())
            {
                PlayerScript.ChangeState(CallingObject, ChaseBall.Instance());
            }
        }
    }
コード例 #6
0
    /**
     *   this is the updated fucntion for the state
     */
    public override void Excute(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        if (PlayerScript.BallInKickingRange())
        {
            PlayerScript.ChangeState(CallingObject, KickBall.Instance());

            return;
        }


        if (PlayerScript.IsClosestTeamMemberToBall())
        {
            Steer2D.Seek S = (Steer2D.Seek)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Seek");

            if (S)
            {
                S.TargetPoint = PlayerScript.Ball.transform.position;
            }

            return;
        }

        PlayerScript.ChangeState(CallingObject, ReturnToHomeRegion.Instance());
    }
コード例 #7
0
    /**
     *   this is the updated fucntion for the state
     */
    public override void Excute(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        if (!PlayerScript.GetTeam().InControl())
        {
            PlayerScript.ChangeState(CallingObject, ReturnToHomeRegion.Instance());
            return;
        }


        Steer2D.Arrive Arr = (Steer2D.Arrive)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");

        if (Arr.TargetPoint != PlayerScript.GetTeam().GetSupportSpot())
        {
            PlayerScript.GetSteeringController().TurnOn(Behaviour.Arrive);
            Arr.TargetPoint = PlayerScript.GetTeam().GetSupportSpot();
        }

        Vector2 ShootingTarget = new Vector2();

        if (PlayerScript.GetTeam().CanShoot(CallingObject.transform.position, out ShootingTarget, PlayerScript.MaxShootingForce)) //TODO ?Need Confidence here?
        {
            PlayerScript.GetTeam().RequestPass(CallingObject);
        }

        if (Arr.AtTarget)
        {
            //PlayerScript.GetSteeringController().TurnOff(Behaviour.Arrive);

            PlayerScript.TrackBall();

            if (!PlayerScript.IsThreatened())
            {
                PlayerScript.GetTeam().RequestPass(CallingObject);
            }
        }

        //If closest to ball and not in goalkeepers hands... Chase the ball
        if (PlayerScript.IsClosestTeamMemberToBall() && (!PlayerScript.GetTeam().GetPitch().GoalKeeperHasBall()))
        {
            PlayerScript.ChangeState(CallingObject, ChaseBall.Instance());
            return;
        }
    }
コード例 #8
0
    /**
     *   this will execute when the state is exited
     */
    public override void Exit(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        PlayerScript.GetSteeringController().TurnOff(Behaviour.Arrive);

        if (PlayerScript.DebugOn)
        {
            Debug.Log("Exiting Player Return to home state");
        }
    }
コード例 #9
0
    /**
     *   this will execute when the state is entered
     */
    public override void Enter(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        PlayerScript.GetSteeringController().TurnOn(Behaviour.Seek);

        if (PlayerScript.DebugOn)
        {
            Debug.Log("Entering Player Chase Ball State");
        }
    }
コード例 #10
0
    /**
     *   this will execute when the state is entered
     */
    public override void Enter(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        if (PlayerScript.DebugOn)
        {
            Debug.Log("Entering Wait State");
        }

        PlayerScript.GetSteeringController().TurnOn(Behaviour.Arrive);

        //Empty
    }
コード例 #11
0
    /**
     *   this will execute when the state is exited
     */
    public override void Exit(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        PlayerScript.GetTeam().SupportingPlayer = null;

        PlayerScript.GetSteeringController().TurnOff(Behaviour.Arrive);


        if (PlayerScript.DebugOn)
        {
            Debug.Log("Exiting Support Attacker State");
        }
    }
コード例 #12
0
    /**
     *   this is the updated fucntion for the state
     */
    public override void Excute(GameObject CallingObject)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();

        if (PlayerScript.GetTeam().GetPitch().GetGameInPlay())
        {
            //If closest to ball and not in goalkeepers hands... Chase the ball
            if (PlayerScript.IsClosestTeamMemberToBall() && (!PlayerScript.GetTeam().GetPitch().GoalKeeperHasBall()))
            {
                PlayerScript.ChangeState(CallingObject, ChaseBall.Instance());
                return;
            }
        }

        Steer2D.Arrive Arr = (Steer2D.Arrive)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");

        if (Arr.AtTarget)
        {
            PlayerScript.ChangeState(CallingObject, Wait.Instance());
        }
    }
コード例 #13
0
    public override bool OnMessage(GameObject CallingObject, Message Msg)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();


        switch (Msg.Msg)
        {
        case PlayerMessages.ReceiveBall:
        {
            //GCHandle Handle = (GCHandle)Msg.ExtraInfo;
            //Vector2 Pos = (Vector2)Handle.Target;

            Steer2D.Arrive Arr = (Steer2D.Arrive)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");
            Arr.TargetPoint = Msg.ExtraInfo;

            PlayerScript.ChangeState(CallingObject, ReceiveBall.Instance());
            return(true);
        }

        case PlayerMessages.SupportAttacker:
        {
            if (PlayerScript.IsInState(SupportAttacker.Instance()))
            {
                return(true);
            }

            //TODO Behaviour
            PlayerScript.ChangeState(CallingObject, SupportAttacker.Instance());
            return(true);
        }


        case PlayerMessages.Wait:
        {
            PlayerScript.ChangeState(CallingObject, Wait.Instance());
            return(true);
        }

        case PlayerMessages.PassToMe:
        {
            GameObject Reciever = Msg.Sender;

            //If there is already a recieving player or the ball isnt in range then cant pass pall to requesting player
            if (PlayerScript.GetTeam().RecievingPlayer != null || !PlayerScript.BallInKickingRange())
            {
                //Debug.Log("Can't make requested Pass");
                return(true);
            }

            //TODO double check this

            Vector2 PassTarget = PlayerScript.AddNoiseToTarget(Reciever.gameObject.transform.position);

            //Get the direction of the shot
            Vector2 KickDir = (PassTarget - (Vector2)PlayerScript.Ball.transform.position).normalized;

            float dot       = Vector3.Dot(CallingObject.transform.right, (PlayerScript.Ball.transform.position - CallingObject.transform.position).normalized);
            float KickPower = PlayerScript.PassingForce * dot;

            //Add force to the ball

            if (!PlayerScript.IsReadyForNextKick())
            {
                return(true);
            }

            PlayerScript.Ball.GetComponent <Football>().AddForce(KickDir * KickPower, PassTarget, "Passing To Reqested Pass");



            //GCHandle Handle = GCHandle.Alloc(Reciever.transform.position);
            //System.IntPtr PositionPtr = (System.IntPtr)Handle;

            Dispatcher.Instance().DispatchMessage(0, CallingObject, Reciever, PlayerMessages.ReceiveBall, PassTarget);

            PlayerScript.ChangeState(CallingObject, Wait.Instance());

            PlayerScript.FindSupport();

            return(true);
        }

        case PlayerMessages.GoHome:
        {
            PlayerScript.SetDefaultHomeRegion();
            PlayerScript.ChangeState(CallingObject, ReturnToHomeRegion.Instance());
            return(true);
        }
        }


        return(false);
    }