Beispiel #1
0
    /// <summary>
    /// Performs the specified move of the <c>current</c> monster.
    /// Will switch to either the player's turn or the enemy's turn depending on the <c>state</c>.
    /// </summary>
    /// <param name="current">The monster that is attacking.</param>
    /// <param name="target">The monster that is being attacked.</param>
    /// <param name="index">The move that is being used.</param>
    IEnumerator PerformMove(Monster current, Monster target, int index)
    {
        hudHolder.SetActive(false);
        int  uses         = current.moves[index].uses;
        bool isTargetDead = current.moves[index].PerformMove(current, target);

        playerHUD.UpdateUsesHUD(playerMonster);

        playerHUD.SetHP(playerMonster.currentHP);
        enemyHUD.SetHP(enemyMonster.currentHP);

        dialoogText.text = $"{current.monsterName} used {current.moves[index].moveName}.";
        if (uses == 0)
        {
            dialoogText.text += "\nBut it was out of uses!";
        }
        else if (current.moves[index].type == MoveType.Attack)
        {
            dialoogText.text += $"\nIt hit for {current.moves[index].GetCalculatedValue(target.element)} damage!";
            audioSource.clip  = attackSfx;
            audioSource.Play();
            StartCoroutine(DamageBlink(target));
        }
        else if (current.moves[index].type == MoveType.Recover)
        {
            dialoogText.text += $"\nIt recovered {current.moves[index].GetCalculatedValue(target.element)} life points!";
            audioSource.clip  = healSfx;
            audioSource.Play();
            StartCoroutine(FlashColor(current, Color.green));
        }

        yield return(new WaitForSeconds(waitTimePlayer));

        bool isCurrentDead = current.currentHP <= 0;

        bool playerWon = (state == BattleState.PlayerTurn && isTargetDead) || (state == BattleState.EnemyTurn && isCurrentDead);
        bool enemyWon  = (state == BattleState.EnemyTurn && isTargetDead) || (state == BattleState.PlayerTurn && isCurrentDead);

        if (playerWon)
        {
            state = BattleState.Won;
            StartCoroutine(EndBattle());
        }
        else if (enemyWon)
        {
            // See if we can switch to our second monster
            GameObject otherMonster = playerInventory.GetMonster(true);
            if (otherMonster && otherMonster.GetComponent <Monster>().currentHP > 0)
            {
                StartCoroutine(PerformSwitch(true, BattleState.PlayerTurn));
            }
            else
            {
                state = BattleState.Lost;
                StartCoroutine(EndBattle());
            }
        }
        else if (state == BattleState.PlayerTurn)
        {
            state = BattleState.EnemyTurn;

            StartCoroutine(PerformMove(target, current, EnemyChooseMove()));
        }
        else
        {
            state = BattleState.PlayerTurn;
            PlayerTurn();
        }
    }