Example #1
0
    void Update()
    {
        switch (StateMachine.GetCurrentStateName("Round"))
        {
        case "RoundStart":
            if (isPlayerTurn)
            {
                isPlayerTurn = false;
            }
            else
            {
                isPlayerTurn = true;
            }
            StateMachine.ChangeState("Round", "BeforeAttack");
            break;

        case "BeforeAttack":
            StateMachine.ChangeState("Round", "Attack");
            break;

        case "Attack":
            bool ret;
            if (isPlayerTurn)
            {
                ret = player.Attack(monster);
            }
            else
            {
                ret = monster.Attack(player);
            }
            if (battleSound && Game.sound && !pass)
            {
                battleSound.Play();
            }
            if (ret)
            {
                StateMachine.ChangeState("Round", "BeforeDamage");
            }
            else
            {
                StateMachine.ChangeState("Round", "AfterAttack");
            }
            break;

        case "BeforeDamage":
            StateMachine.ChangeState("Round", "Damaged");
            break;

        case "Damaged":
            Damage.AciveAllDamages();
            StateMachine.ChangeState("Round", "AfterDamage");
            break;

        case "AfterDamage":
            StateMachine.ChangeState("Round", "AfterAttack");
            break;

        case "AfterAttack":
            if (monster.hpComponent.GetCurrentHp() <= 0)
            {
                StateMachine.ChangeState("Round", "BattleEnd");
                StateMachine.ChangeState("Battle", "Win");
            }
            else if (player.hpComponent.GetCurrentHp() <= 0)
            {
                StateMachine.ChangeState("Round", "BattleEnd");
                StateMachine.ChangeState("Battle", "Fail");
            }
            else
            {
                StateMachine.ChangeState("Round", "RoundEnd");
            }
            break;

        case "RoundEnd":
            if (UnityEngine.Time.time - lastRoundTime > roundSpace || pass)
            {
                StateMachine.ChangeState("Round", "RoundStart");
            }
            else
            {
                StateMachine.ChangeState("Round", "RoundWait");
            }
            //StateMachine.ChangeState("Round", "BattleEnd");
            break;

        case "RoundWait":
            if (UnityEngine.Time.time - lastRoundTime > roundSpace)
            {
                StateMachine.ChangeState("Round", "RoundStart");
            }
            break;

        default:
            break;
        }
    }