/// <summary>
    /// Conducts field play.
    /// </summary>
    /// <param name="isRandom"></param>
    public void FieldPlay(bool isRandom = true)
    {
        if (isRandom)
        {
            float random = UnityEngine.Random.Range(0f, 10f);

            //FlyOut
            if (0 <= random && random <= 3.5f)
            {
                AtPlate.AddOut(AtPlate.Out.FLY_BALL);
            }
            //GroundBall
            else if (3.5f <= random && random <= 7f)
            {
                AtPlate.AddOut(AtPlate.Out.GROUND_BALL);
            }
            //Hit
            else if (7f <= random && random <= 10f)
            {
                random = UnityEngine.Random.Range(0, 10);
                if (0 <= random && random <= 4)
                {
                    Hitting.AddHit(Hitting.Hit.SINGLE);
                }
                else if (5 <= random && random <= 7)
                {
                    Hitting.AddHit(Hitting.Hit.DOUBLE);
                }
                else if (8 <= random && random <= 8)
                {
                    Hitting.AddHit(Hitting.Hit.TRIPLE);
                }
                else if (9 <= random && random <= 9)
                {
                    Hitting.AddHit(Hitting.Hit.HOME_RUN);
                }
            }
        }
    }
示例#2
0
    IEnumerator Start()
    {
        fight = Fight.Idle;

        animation.Stop();
        animation.wrapMode = WrapMode.Loop;

        animationComponent["Hands_Idle3"].layer = 1;

        animationComponent["Hands_Idle1"].layer = 1;
        animationComponent["Hands_Idle1"].speed = 0.5f;
        animationComponent["Hands_Idle1"].wrapMode = WrapMode.Once;
        animationComponent["Hands_Idle1"].blendMode = AnimationBlendMode.Additive;

        animationComponent["Hands_Idle2"].layer = 2;
        animationComponent["Hands_Idle2"].weight = 1f;
        animationComponent["Hands_Idle2"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Idle4"].layer = 1;

        animationComponent["Hands_Idle5"].layer = 1;

        animationComponent["Hands_Idle_AfterPunch1"].layer = 2;
        animationComponent["Hands_Idle_AfterPunch1"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Idle_AfterPunch2"].layer = 2;
        animationComponent["Hands_Idle_AfterPunch2"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Punch1"].layer = 2;
        animationComponent["Hands_Punch1"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Punch2"].layer = 2;
        animationComponent["Hands_Punch2"].wrapMode = WrapMode.Once;

        animationComponent.CrossFade("Hands_Idle2");

        //Problem with not hitting properly sometimes is because still crossfading to Idle3

        while(true)
        {
            bashCube.renderer.material.color = Color.grey;

            switch(fight)
            {
            case Fight.Idle:

                animationComponent.CrossFade("Hands_Idle3",0.25f);

                if(Input.GetButtonDown("Fire1"))
                {
                    fight = Fight.Hitting;
                    hitting = Hitting.Punch;

                    animationComponent.CrossFade("Hands_Idle4");
                    animationComponent["Hands_Punch1"].speed = 0f;
                    animationComponent.CrossFade("Hands_Punch1");
                }
                else if(Input.GetButtonDown("Fire2"))
                {
                    fight = Fight.Hitting;
                    hitting = Hitting.Chop;

                    animationComponent.CrossFade("Hands_Idle5");
                    animationComponent["Hands_Punch2"].speed = 0f;
                    animationComponent.CrossFade("Hands_Punch2");
                }

                break;

            case Fight.Hitting:

                RaycastHit hit;

                switch(hitting)
                {
                case Hitting.Punch:

                    if(Physics.Raycast(hitCube.position,hitCube.forward,out hit, 0.25f))
                    {
                        bashCube.renderer.material.color = Color.red;
                        animationComponent.CrossFade("Hands_Idle_AfterPunch1",0.3f);
                    }

                    if(animationComponent["Hands_Punch1"].weight > 0.99f) animationComponent["Hands_Punch1"].speed = 1f;

                    timer += Time.deltaTime;

                    if(Input.GetButtonDown("Fire1"))
                    {
                        timer = 0;
                        Debug.DrawRay(hitCube.position,hitCube.forward,Color.blue);
                        animationComponent.CrossFadeQueued("Hands_Punch1", 0.1f,QueueMode.PlayNow);
                    }

                    if(Input.GetButtonDown("Fire2"))
                    {
                        hitting = Hitting.Chop;

                        animationComponent.CrossFade("Hands_Idle5");
                        animationComponent["Hands_Punch2"].speed = 0f;
                        animationComponent.CrossFade("Hands_Punch2");
                    }

                    if(!animationComponent.IsPlaying("Hands_Punch1"))
                    {
                        if(timer >= animationComponent["Hands_Punch1"].length) timer = 0;

                        if(timer <= 0.5f)
                        {
                            timer += Time.deltaTime;
                            }
                        else fight = Fight.Idle;
                    }

                    break;
                case Hitting.Chop:

                    Debug.DrawRay(hitCube.position,-hitCube.right,Color.blue);

                    if(Physics.Raycast(hitCube.position,-hitCube.right,out hit, 0.25f))
                    {
                        bashCube.renderer.material.color = Color.red;
                        animationComponent.CrossFade("Hands_Idle_AfterPunch2",0.3f);
                    }

                    if(animationComponent["Hands_Punch2"].weight > 0.99f) animationComponent["Hands_Punch2"].speed = 1f;

                    timer += Time.deltaTime;

                    if(Input.GetButtonDown("Fire2"))
                    {
                        timer = 0;

                        animationComponent.CrossFadeQueued("Hands_Punch2", 0.1f,QueueMode.PlayNow);
                    }

                    if(Input.GetButtonDown("Fire1"))
                    {
                        hitting = Hitting.Punch;

                        animationComponent.CrossFade("Hands_Idle4");
                        animationComponent["Hands_Punch1"].speed = 0f;
                        animationComponent.CrossFade("Hands_Punch1");
                    }

                    if(!animationComponent.IsPlaying("Hands_Punch2"))
                    {
                        if(timer >= animationComponent["Hands_Punch2"].length) timer = 0;

                        if(timer <= -0.2f)
                        {
                            timer += Time.deltaTime;
                            }
                        else fight = Fight.Idle;
                    }

                    break;
                }

                break;
            }
            yield return 0;
        }
    }
    /// <summary>
    /// A single turn.
    /// </summary>
    public void Turn()
    {
        if (isUIEnabled)
        {
            //InningPanel
            InGameObjects.inningPanel.UpdateLayout();

            //OutPanel
            InGameObjects.outPanelLayout.ClearLayout();
            InGameObjects.outPanelLayout.UpdateLayout();

            //BasePanel
            InGameObjects.basePanel.UpdateLayout();
            InGameObjects.basePanel.UpdateStealing();

            //ScorePanel
            InGameObjects.scorePanel.UpdateLayout();

            //BoardPanel
            InGameObjects.boardPanel.UpdateLayout();

            //Field_Condition
            InGameObjects.PlayerUIApply.SetPlayers(true);
        }

        //Initializes stealingAttempts array to false.
        for (int i = 0; i < 4; ++i)
        {
            stealingAttempts[i] = false;
        }
        //First, determine whether runners in bases attempt to steal base or not.
        for (int i = 1; i <= 3; ++i)
        {
            bool isBaseStealing = BaseRunning.BaseStealDetermine(runnerInBases[i], true);
            if (isBaseStealing)
            {
                Debug.Log("BASE " + i + "TRYING TO STEAL");
                //If a runner is going to steal base, change stealingAttempt bool to true.
                stealingAttempts[i] = true;
            }
        }

        if (isUIEnabled)
        {
            //This is a stealingAttempts UI update.
            InGameObjects.basePanel.UpdateStealing();
        }

        //Then, a pitcher determines whether pick off the ball or not.
        bool isPickedOff = PickingOff.PickOffDetermine(out int whichBase, true);

        if (isPickedOff)
        {
            Debug.Log("PICK OFF");
            //If the pitcher picks off the ball, a pickoff function starts and control goes to ball in play.
            PickingOff.PickOff(-1, true);
            BallInPlay(BallInPlayMode.PICKOFF, true, whichBase);
            return;
        }
        else
        {
            //If not picked off, pitcher pitches, and sets wildpitch and hitbypitch bool variables.
            Pitching.Pitch(out bool isWildPitch, out bool isHitByPitch, true);
            if (isWildPitch)
            {
                Debug.Log("WILD PITCHED");
                //If a pitcher wild pitched, control goes to ball in play.
                PitchedWild.WildPitch(currentPitcher);
                BallInPlay(BallInPlayMode.WILD_PITCH);
                return;
            }
            else
            {
                //If not wild pitched, determine wheter a batter swung or not.
                bool isSwung = AtPlate.SwingDetermine(true);
                if (isHitByPitch)
                {
                    //If a batter got a hit-by-pitch ball, advances runner by 1 base, and the turn ends.
                    AtPlate.AddBall(true);
                    return;
                }
                else
                {
                    //If not hit-by-pitch ball, check if a batter swung.
                    if (isSwung)
                    {
                        Debug.Log("He Swings!");
                        //If swung, determine whether a swing hit or not.
                        bool isHit = Hitting.HitDetermine(true);
                        if (isHit)
                        {
                            //If hit, control goes to ball in play.
                            BallInPlay(BallInPlayMode.NORMAL);
                            return;
                        }
                        else
                        {
                            //If not hit, adds a strike.
                            AtPlate.AddStrike();
                            return;
                        }
                    }
                    else
                    {
                        //If not swung, determine whether a ball is strike or ball.
                        bool isInStrike = Pitching.InStrikeZoneDetermine(true);
                        if (isInStrike)
                        {
                            //If a ball is in strikezone, adds a strike.
                            AtPlate.AddStrike();
                            return;
                        }
                        else
                        {
                            //If not in strikezone, adds a ball.
                            AtPlate.AddBall();
                            return;
                        }
                    }
                }
            }
        }
    }
示例#4
0
    IEnumerator Start()
    {
        fight = Fight.Idle;

        animation.Stop();
        animation.wrapMode = WrapMode.Loop;

        animationComponent["Hands_Idle3"].layer = 1;

        animationComponent["Hands_Idle1"].layer     = 1;
        animationComponent["Hands_Idle1"].speed     = 0.5f;
        animationComponent["Hands_Idle1"].wrapMode  = WrapMode.Once;
        animationComponent["Hands_Idle1"].blendMode = AnimationBlendMode.Additive;

        animationComponent["Hands_Idle2"].layer    = 2;
        animationComponent["Hands_Idle2"].weight   = 1f;
        animationComponent["Hands_Idle2"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Idle4"].layer = 1;

        animationComponent["Hands_Idle5"].layer = 1;

        animationComponent["Hands_Idle_AfterPunch1"].layer    = 2;
        animationComponent["Hands_Idle_AfterPunch1"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Idle_AfterPunch2"].layer    = 2;
        animationComponent["Hands_Idle_AfterPunch2"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Punch1"].layer    = 2;
        animationComponent["Hands_Punch1"].wrapMode = WrapMode.Once;

        animationComponent["Hands_Punch2"].layer    = 2;
        animationComponent["Hands_Punch2"].wrapMode = WrapMode.Once;

        animationComponent.CrossFade("Hands_Idle2");

        //Problem with not hitting properly sometimes is because still crossfading to Idle3

        while (true)
        {
            bashCube.renderer.material.color = Color.grey;

            switch (fight)
            {
            case Fight.Idle:

                animationComponent.CrossFade("Hands_Idle3", 0.25f);

                if (Input.GetButtonDown("Fire1"))
                {
                    fight   = Fight.Hitting;
                    hitting = Hitting.Punch;

                    animationComponent.CrossFade("Hands_Idle4");
                    animationComponent["Hands_Punch1"].speed = 0f;
                    animationComponent.CrossFade("Hands_Punch1");
                }
                else if (Input.GetButtonDown("Fire2"))
                {
                    fight   = Fight.Hitting;
                    hitting = Hitting.Chop;

                    animationComponent.CrossFade("Hands_Idle5");
                    animationComponent["Hands_Punch2"].speed = 0f;
                    animationComponent.CrossFade("Hands_Punch2");
                }

                break;

            case Fight.Hitting:

                RaycastHit hit;

                switch (hitting)
                {
                case Hitting.Punch:

                    if (Physics.Raycast(hitCube.position, hitCube.forward, out hit, 0.25f))
                    {
                        bashCube.renderer.material.color = Color.red;
                        animationComponent.CrossFade("Hands_Idle_AfterPunch1", 0.3f);
                    }

                    if (animationComponent["Hands_Punch1"].weight > 0.99f)
                    {
                        animationComponent["Hands_Punch1"].speed = 1f;
                    }

                    timer += Time.deltaTime;

                    if (Input.GetButtonDown("Fire1"))
                    {
                        timer = 0;
                        Debug.DrawRay(hitCube.position, hitCube.forward, Color.blue);
                        animationComponent.CrossFadeQueued("Hands_Punch1", 0.1f, QueueMode.PlayNow);
                    }

                    if (Input.GetButtonDown("Fire2"))
                    {
                        hitting = Hitting.Chop;

                        animationComponent.CrossFade("Hands_Idle5");
                        animationComponent["Hands_Punch2"].speed = 0f;
                        animationComponent.CrossFade("Hands_Punch2");
                    }

                    if (!animationComponent.IsPlaying("Hands_Punch1"))
                    {
                        if (timer >= animationComponent["Hands_Punch1"].length)
                        {
                            timer = 0;
                        }

                        if (timer <= 0.5f)
                        {
                            timer += Time.deltaTime;
                        }
                        else
                        {
                            fight = Fight.Idle;
                        }
                    }

                    break;

                case Hitting.Chop:

                    Debug.DrawRay(hitCube.position, -hitCube.right, Color.blue);

                    if (Physics.Raycast(hitCube.position, -hitCube.right, out hit, 0.25f))
                    {
                        bashCube.renderer.material.color = Color.red;
                        animationComponent.CrossFade("Hands_Idle_AfterPunch2", 0.3f);
                    }

                    if (animationComponent["Hands_Punch2"].weight > 0.99f)
                    {
                        animationComponent["Hands_Punch2"].speed = 1f;
                    }

                    timer += Time.deltaTime;

                    if (Input.GetButtonDown("Fire2"))
                    {
                        timer = 0;

                        animationComponent.CrossFadeQueued("Hands_Punch2", 0.1f, QueueMode.PlayNow);
                    }

                    if (Input.GetButtonDown("Fire1"))
                    {
                        hitting = Hitting.Punch;

                        animationComponent.CrossFade("Hands_Idle4");
                        animationComponent["Hands_Punch1"].speed = 0f;
                        animationComponent.CrossFade("Hands_Punch1");
                    }

                    if (!animationComponent.IsPlaying("Hands_Punch2"))
                    {
                        if (timer >= animationComponent["Hands_Punch2"].length)
                        {
                            timer = 0;
                        }

                        if (timer <= -0.2f)
                        {
                            timer += Time.deltaTime;
                        }
                        else
                        {
                            fight = Fight.Idle;
                        }
                    }

                    break;
                }

                break;
            }
            yield return(0);
        }
    }