Esempio n. 1
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());
            }
        }
    }
Esempio n. 2
0
 public void UpdateTargetsOfWaitingPlayers()
 {
     foreach (Player Guy in Players)
     {
         if (Guy.GetRole() != PlayerRoles.GoalKeeper)
         {
             if (Guy.IsInState(Wait.Instance()) || Guy.IsInState(ReturnToHomeRegion.Instance()))
             {
                 Steer2D.Arrive Arr = (Steer2D.Arrive)Guy.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");
                 Arr.TargetPoint = Guy.HomePosition;
             }
         }
     }
 }
Esempio n. 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");
        }
    }
Esempio n. 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");
        }
    }
Esempio n. 5
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;
        }
    }
Esempio n. 6
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());
        }
    }
Esempio n. 7
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);
    }