Beispiel #1
0
    public virtual CSoccerPlayerController GetSoccerHaveBall()
    {
        int i = 0;

        for (i = 0; i < this.m_StrikerSoccers.Length; i++)
        {
            if (this.m_StrikerSoccers [i].HaveBall())
            {
                this.m_SoccerHaveBall = this.m_StrikerSoccers [i];
                return(this.m_StrikerSoccers [i]);
            }
        }
        for (i = 0; i < this.m_DefenderSoccers.Length; i++)
        {
            if (this.m_DefenderSoccers [i].HaveBall())
            {
                this.m_SoccerHaveBall = this.m_DefenderSoccers [i];
                return(this.m_DefenderSoccers [i]);
            }
        }
        for (i = 0; i < this.m_GoalKeeperSoccers.Length; i++)
        {
            if (this.m_GoalKeeperSoccers [i].HaveBall())
            {
                this.m_SoccerHaveBall = this.m_GoalKeeperSoccers [i];
                return(this.m_GoalKeeperSoccers [i]);
            }
        }
        return(null);
    }
Beispiel #2
0
    public virtual void UpdateBall(CSoccerPlayerController value)
    {
        if (this.isBallActive == false)
        {
            return;
        }
        if (this.m_Soccers.Contains(value) == false)
        {
            this.m_Soccers.Add(value);
        }
        CSoccerPlayerController soccerSelected = null;
        var soccerBiggestScore = 0f;

        for (int i = 0; i < this.m_Soccers.Count; i++)
        {
            var direction = this.m_Soccers [i].GetPosition() - this.GetPosition();
            if (direction.sqrMagnitude <= this.m_BallRadius * this.m_BallRadius)
            {
                if (this.m_Soccers [i].ballValue >= soccerBiggestScore)
                {
                    soccerBiggestScore = this.m_Soccers [i].ballValue;
                    soccerSelected     = this.m_Soccers [i];
                }
            }
        }
        if (soccerSelected != null)
        {
            this.m_Soccer      = soccerSelected;
            this.m_Soccer.Ball = this;
        }
    }
Beispiel #3
0
 public virtual void SetBallTo(CSoccerPlayerController target)
 {
     if (this.m_Soccer == target)
     {
         return;
     }
     this.m_IsBallActive = false;
     StartCoroutine(this.HandleSetUpBallTo(target));
 }
Beispiel #4
0
    protected virtual IEnumerator HandleSetUpBallTo(CSoccerPlayerController target)
    {
        var direction = target.ballWorldPosition.transform.position - this.GetPosition();
        var maxLength = direction.sqrMagnitude;

        this.m_Soccer      = target;
        this.m_Soccer.Ball = this;
        while (direction.sqrMagnitude >= 0.2f)
        {
            this.m_Transform.position += direction.normalized * 10f * Time.deltaTime;
            direction = target.ballWorldPosition.transform.position - this.GetPosition();
            var currentLength   = 1f - (direction.sqrMagnitude / maxLength);
            var currentPosition = this.m_BallObject.transform.localPosition;
            currentPosition.y = Mathf.Lerp(currentPosition.y, m_BallCurve.Evaluate(currentLength) * 3f, 0.75f);
            this.m_BallObject.transform.localPosition = currentPosition;
            yield return(WaitHelper.WaitFixedUpdate);
        }
        this.m_IsBallActive = true;
    }
Beispiel #5
0
    public override void StartState()
    {
        base.StartState();
        this.m_Controller.WalkSpeed();
        // STAND BY
        this.m_Controller.SetTargetPosition(this.m_Controller.GetPosition());
        // FIND ALLY
        var soccerColliders = Physics.OverlapSphere(
            this.m_Controller.GetPosition(),
            this.m_Controller.interactiveRadius,
            this.m_Controller.targetLayerMask);
        var goal = this.m_Controller.Team.EnemyGoal;
        // IF ALLY NEAREST ENEMY GOAL
        var allyPlayers = soccerColliders
                          .Where((x) => {
            var objController = x.GetComponent <CSoccerPlayerController> ();
            return(objController != null &&
                   objController != this.m_Controller &&
                   objController.Team.teamName == this.m_Controller.Team.teamName);
        }).OrderBy((a) => {
            if (a.gameObject == this.m_Controller.gameObject)
            {
                return(9999f);
            }
            var distance = (goal.GetPosition() - a.transform.position).sqrMagnitude;
            return(distance);
        }).ToArray();
        // SET UP BALL
        var ball = this.m_Controller.Team.Ball;

        ball.isBallActive = false;
        CSoccerPlayerController nearestAlly = null;

        if (allyPlayers.Length > 0)
        {
            nearestAlly = allyPlayers [0].GetComponent <CSoccerPlayerController> ();
            nearestAlly.WalkSpeed();
            ball.SetBallTo(nearestAlly);
            this.m_Controller.Ball = null;
        }
    }
Beispiel #6
0
    public virtual CSoccerPlayerController GetSoccerNearest(CSoccerPlayerController value)
    {
        var nearestLength = 9999f;
        int i             = 0;
        CSoccerPlayerController target = this.m_StrikerSoccers[0];
        Vector3 direction = Vector3.zero;

        for (i = 0; i < this.m_StrikerSoccers.Length; i++)
        {
            direction = this.m_StrikerSoccers [i].GetPosition() - value.GetPosition();
            if (direction.sqrMagnitude <= nearestLength)
            {
                target        = this.m_StrikerSoccers [i];
                nearestLength = direction.sqrMagnitude;
            }
        }
        for (i = 0; i < this.m_DefenderSoccers.Length; i++)
        {
            direction = this.m_DefenderSoccers [i].GetPosition() - value.GetPosition();
            if (direction.sqrMagnitude <= nearestLength)
            {
                target        = this.m_DefenderSoccers [i];
                nearestLength = direction.sqrMagnitude;
            }
        }
        for (i = 0; i < this.m_GoalKeeperSoccers.Length; i++)
        {
            direction = this.m_GoalKeeperSoccers [i].GetPosition() - value.GetPosition();
            if (direction.sqrMagnitude <= nearestLength)
            {
                target        = this.m_GoalKeeperSoccers [i];
                nearestLength = direction.sqrMagnitude;
            }
        }
        return(target);
    }
 public FSMSoccerChaseBallState(IContext context) : base(context)
 {
     this.m_Controller = context as CSoccerPlayerController;
 }