Exemplo n.º 1
0
    IEnumerator DoPlay()
    {
        if (animator)
        {
            animator.gameObject.SetActive(true);

            //ready animation countdown thing
            if (!string.IsNullOrEmpty(takeEnter))
            {
                yield return(animator.PlayWait(takeEnter));
            }

            yield return(new WaitForSeconds(readyDelay));

            if (!string.IsNullOrEmpty(takeExit))
            {
                yield return(animator.PlayWait(takeExit));
            }

            animator.gameObject.SetActive(false);
        }

        //attack animation towards defender
        mAttacker.action = CombatCharacterController.Action.Attack;
        mDefender.action = CombatCharacterController.Action.Defend;

        while (mAttacker.isBusy)
        {
            yield return(null);
        }
        //

        //show interfaces
        opsWidget.gameObject.SetActive(true);
        opsWidget.Show();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        if (timerWidget)
        {
            timerWidget.Show();
        }
        //

        //timerWidget.ResetValue();

        mAnswerNumber = new MixedNumber();

        defenseTotalNumber = new MixedNumber();

        var waitBrief = new WaitForSeconds(0.3f);

        while (!IsTimerExpired())
        {
            //show and fill deck
            if (deckWidget)
            {
                deckWidget.gameObject.SetActive(true);
                deckWidget.Show();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }
            }

            FillSlots();
            yield return(waitBrief);

            if (timerWidget)
            {
                timerWidget.SetActive(true);
            }
            //

            //listen for answer
            mIsAnswerSubmitted     = false;
            signalAnswer.callback += OnAnswerSubmit;

            //wait for correct answer, or time expired
            while (!IsTimerExpired())
            {
                if (mIsAnswerSubmitted)
                {
                    if (mIsAnswerCorrect)
                    {
                        break;
                    }

                    mIsAnswerSubmitted = false;
                }

                yield return(null);
            }

            //ready for next
            if (timerWidget)
            {
                timerWidget.SetActive(false);
            }

            signalAnswer.callback -= OnAnswerSubmit;

            if (deckWidget)
            {
                deckWidget.Clear();

                deckWidget.Hide();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }

                deckWidget.gameObject.SetActive(false);
            }
            //

            //add answer if submitted and correct, move to first operand
            if (mIsAnswerSubmitted && mIsAnswerCorrect)
            {
                for (int i = 1; i < opsWidget.operation.operands.Length; i++)
                {
                    defenseTotalNumber += opsWidget.operation.operands[i].number;
                }

                if (mAnswerNumber.fValue <= 0f) //no longer need to accumulate
                {
                    break;
                }

                opsWidget.MoveAnswerToOperand(0);
            }

            yield return(waitBrief);
        }

        if (mAnswerNumber.fValue == 0f)
        {
            mAnswerNumber = mOperations.operands[0].number;
        }

        //hide interfaces
        if (timerWidget)
        {
            timerWidget.Hide();
        }

        opsWidget.Hide();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        opsWidget.gameObject.SetActive(false);
        //

        //hurt defender based on final answer
        var fval = mAnswerNumber.fValue;

        if (fval < 0f)
        {
            fval = 0f;
        }

        if (fval > 0f)
        {
            //show defender's hp
            mDefender.hpWidget.Show();
            while (mDefender.hpWidget.isBusy)
            {
                yield return(null);
            }

            mDefender.hpCurrent -= fval;
            mDefender.action     = CombatCharacterController.Action.Hurt;

            M8.SoundPlaylist.instance.Play(audioHit, false);

            //do fancy hit effect
            if (damageFloater)
            {
                damageFloater.Play(damageFloaterAnchor.position, mAnswerNumber);
            }

            //fancy floaty number
            yield return(new WaitForSeconds(postHurtDelay));

            //hide defender's hp
            mDefender.hpWidget.Hide();
        }

        mAttacker.action = CombatCharacterController.Action.Idle;
        while (mAttacker.isBusy)
        {
            yield return(null);
        }

        if (mDefender.hpCurrent > 0f)
        {
            mDefender.action = CombatCharacterController.Action.Idle;
        }
        else
        {
            M8.SoundPlaylist.instance.Play(audioDeath, false);

            mDefender.action = CombatCharacterController.Action.Death;
        }

        if (postDefenseDelay > 0f)
        {
            yield return(new WaitForSeconds(postDefenseDelay));
        }

        mRout = null;
    }
Exemplo n.º 2
0
    IEnumerator DoPlay()
    {
        if (animator)
        {
            animator.gameObject.SetActive(true);

            //ready animation countdown thing
            if (!string.IsNullOrEmpty(takeEnter))
            {
                yield return(animator.PlayWait(takeEnter));
            }

            yield return(new WaitForSeconds(readyDelay));

            if (!string.IsNullOrEmpty(takeExit))
            {
                yield return(animator.PlayWait(takeExit));
            }

            animator.gameObject.SetActive(false);
        }

        //show interfaces
        opsWidget.gameObject.SetActive(true);

        opsWidget.Show();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        if (timerWidget)
        {
            timerWidget.Show();
        }
        if (counterWidget)
        {
            counterWidget.Show();
        }
        //

        //timerWidget.ResetValue();

        attackTotalNumber = new MixedNumber();

        var waitBrief = new WaitForSeconds(0.3f);

        //loop
        for (int attackIndex = 0; attackIndex < attackCount; attackIndex++)
        {
            //show and fill deck
            if (deckWidget)
            {
                deckWidget.gameObject.SetActive(true);
                deckWidget.Show();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }
            }

            FillSlots();
            yield return(waitBrief);

            if (timerWidget)
            {
                timerWidget.SetActive(true);
            }
            //

            //listen for answer
            mIsAnswerSubmitted     = false;
            signalAnswer.callback += OnAnswerSubmit;

            //wait for correct answer, or time expired
            while (true)
            {
                if (mIsAnswerSubmitted)
                {
                    if (mIsAnswerCorrect)
                    {
                        mCurNumbersIndex++;
                        if (mCurNumbersIndex == numberGroups.Length)
                        {
                            mCurNumbersIndex = 0;
                        }

                        break;
                    }

                    mIsAnswerSubmitted = false;
                }

                //ignore timer expire if we are at first attack
                if (attackIndex > 0 && IsTimerExpired())
                {
                    break;
                }

                yield return(null);
            }

            //ready for next
            if (timerWidget)
            {
                timerWidget.SetActive(false);
            }

            signalAnswer.callback -= OnAnswerSubmit;

            RefreshOperands();

            if (deckWidget)
            {
                deckWidget.Clear();

                deckWidget.Hide();
                while (deckWidget.isBusy)
                {
                    yield return(null);
                }

                deckWidget.gameObject.SetActive(false);
            }
            //

            //add answer if submitted and correct
            if (mIsAnswerSubmitted && mIsAnswerCorrect)
            {
                mAttackNumbers.Add(mAnswerNumber);
                attackTotalNumber += mAnswerNumber;

                if (counterWidget)
                {
                    counterWidget.FillIncrement();
                }
            }

            //check if time expired
            if (IsTimerExpired())
            {
                break;
            }
        }

        //hide interfaces
        if (timerWidget)
        {
            timerWidget.Hide();
        }
        if (counterWidget)
        {
            counterWidget.Hide();
        }

        opsWidget.Hide();
        while (opsWidget.isBusy)
        {
            yield return(null);
        }

        opsWidget.gameObject.SetActive(false);
        //

        //do attack routine
        mAttacker.action = CombatCharacterController.Action.AttackEnter;
        mDefender.action = CombatCharacterController.Action.Defend;

        while (mAttacker.isBusy)
        {
            yield return(null);
        }

        mAttacker.action = CombatCharacterController.Action.Attack;
        mDefender.action = CombatCharacterController.Action.Hurt;

        while (mAttacker.isBusy)
        {
            yield return(null);
        }

        //show defender's hp
        mDefender.hpWidget.Show();
        while (mDefender.hpWidget.isBusy)
        {
            yield return(null);
        }

        //do hits
        var waitHit = new WaitForSeconds(hitPerDelay);

        for (int i = 0; i < mAttackNumbers.Count; i++)
        {
            var attackNum = mAttackNumbers[i];

            mDefender.hpCurrent -= attackNum.fValue;

            M8.SoundPlaylist.instance.Play(audioHit, false);

            //do fancy hit effect
            if (damageFloater)
            {
                damageFloater.Play(damageFloaterAnchor.position, attackNum);
            }

            yield return(waitHit);
        }

        //return to idle, death for defender if hp = 0
        mAttacker.action = CombatCharacterController.Action.Idle;

        yield return(waitHit);

        //hide defender's hp
        mDefender.hpWidget.Hide();

        if (mDefender.hpCurrent > 0f)
        {
            mDefender.action = CombatCharacterController.Action.Idle;
        }
        else
        {
            M8.SoundPlaylist.instance.Play(audioDeath, false);

            mDefender.action = CombatCharacterController.Action.Death;
        }

        while (mAttacker.isBusy || mDefender.isBusy)
        {
            yield return(null);
        }
        //

        if (postAttackDelay > 0f)
        {
            yield return(new WaitForSeconds(postAttackDelay));
        }

        mRout = null;
    }