Example #1
0
    public IEnumerator HitEnemy(EnemyCombatBehaviour e)
    {
        e.EnemyHit();
        StartCoroutine(AudioManager.instance.WaitUntilNextBeat(Math.Round(AudioManager.instance.songPositionInBeats, MidpointRounding.AwayFromZero)));

        yield return(new WaitUntil(() => AudioManager.instance.nextBeat));

        AudioManager.instance.nextBeat = false;

        if (e.healthSlider.value <= 0)
        {
            e.EnemyDeath();
        }
        else
        {
            e.Idle();
        }
    }
Example #2
0
    public IEnumerator DealDamageToEnemy(int enemyAttacked = 0, bool isItem = false)
    {
        //check if it we're using "good" or "bad" splash screens
        var   splashScreen = amountHit >= (totalHits / 2) ? CombatController.instance.splashScreensGood : CombatController.instance.splashScreensBad;
        float damage       = 0;

        //enemy attacking
        e = CombatController.instance._inBattle[enemyAttacked].GetComponent <EnemyCombatBehaviour>();
        var e2 = e;
        var e3 = e;

        if (CombatController.instance.isMultiple)
        {
            e2 = CombatController.instance._inBattle[CombatController.instance.enemy2].GetComponent <EnemyCombatBehaviour>();
            e3 = CombatController.instance._inBattle[CombatController.instance.enemy3].GetComponent <EnemyCombatBehaviour>();
        }

        //if using an item, otherwise calculate damage and show splash screens
        if (isItem)
        {
            damage = itemUsed.delta;
            ApplyItemEffect();
        }
        else
        {
            damage = PlayerDamageModifier(_attackDamage[(int)CombatController.instance.selectedActionType]);
            splashScreen[action].gameObject.SetActive(true);

            string animation = "Base Layer." + splashScreen[action].gameObject.name;
            CombatController.instance.SplashAnim.Play(animation, 0, 0f);

            yield return(new WaitForSecondsRealtime(2f));

            splashScreen[action].gameObject.SetActive(false);
        }

        Debug.Log("Damage: " + damage);
        Debug.Log("Enemy: " + CombatController.instance._inBattle[enemyAttacked]);

        if (CombatController.instance.selectedActionType == ActionType.Heal)
        {
            UpdatePlayerHealth(damage);
            yield return(new WaitForSecondsRealtime(0.75f));
        }
        else
        {
            Debug.Log("Hit Enemy");
            //Show hit Animation
            e.EnemyHit();
            enemyHealth[enemyAttacked] -= damage;
            e.UpdateHealth(damage);

            if (enemyHealth[enemyAttacked] <= 0)
            {
                Debug.Log("Enemy Dead");

                yield return(StartCoroutine(EnemyDeath(enemyAttacked, e)));

                yield return(new WaitUntil(() => CombatController.instance._inBattle[enemyAttacked] == null));
            }
            else
            {
                yield return(StartCoroutine(AudioManager.instance.WaitUntilNextBeat(Math.Round(AudioManager.instance.songPositionInBeats, MidpointRounding.AwayFromZero))));

                yield return(new WaitUntil(() => AudioManager.instance.nextBeat));

                AudioManager.instance.nextBeat = false;
                e.Idle();

                if (e.gameObject.tag == "Susan" && e.nextPhase)
                {
                    yield break;
                }
                else if (e.gameObject.tag == "Susan" && e._currentHealth <= 0)
                {
                    StartCoroutine(e.gameObject.GetComponent <Susan>().SusanDeath());
                    yield break;
                }
            }

            if (CombatController.instance.isMultiple)
            {
                Debug.Log("Hit Enemy Multi");

                if (CombatController.instance._inBattle[CombatController.instance.enemy2] != null)
                {
                    e2.EnemyHit();
                    enemyHealth[CombatController.instance.enemy2] -= damage;
                    e2.UpdateHealth(damage);

                    if (enemyHealth[CombatController.instance.enemy2] <= 0)
                    {
                        Debug.Log("Enemy Dead");

                        yield return(StartCoroutine(EnemyDeath(CombatController.instance.enemy2, e2)));
                    }
                    else
                    {
                        yield return(StartCoroutine(AudioManager.instance.WaitUntilNextBeat(Math.Round(AudioManager.instance.songPositionInBeats, MidpointRounding.AwayFromZero))));

                        yield return(new WaitUntil(() => AudioManager.instance.nextBeat));

                        AudioManager.instance.nextBeat = false;
                        e2.Idle();

                        if (e2.gameObject.tag == "Susan" && e2.nextPhase)
                        {
                            yield break;
                        }
                    }
                }

                if (CombatController.instance._inBattle[CombatController.instance.enemy3] != null)
                {
                    e3.EnemyHit();
                    enemyHealth[CombatController.instance.enemy3] -= damage;
                    e3.UpdateHealth(damage);

                    if (enemyHealth[CombatController.instance.enemy3] <= 0)
                    {
                        Debug.Log("Enemy Dead");

                        yield return(StartCoroutine(EnemyDeath(CombatController.instance.enemy3, e3)));
                    }
                    else
                    {
                        yield return(StartCoroutine(AudioManager.instance.WaitUntilNextBeat(Math.Round(AudioManager.instance.songPositionInBeats, MidpointRounding.AwayFromZero))));

                        yield return(new WaitUntil(() => AudioManager.instance.nextBeat));

                        AudioManager.instance.nextBeat = false;
                        e3.Idle();

                        if (e3.gameObject.tag == "Susan" && e3.nextPhase)
                        {
                            yield break;
                        }
                    }
                }
            }
        }



        //If there are no more enemies, return to overworld
        if (_enemiesLeft <= 0)
        {
            Debug.Log("battle Won eqwbij");

            yield return(StartCoroutine(GameManager.instance.BattleWon()));

            yield break;
        }

        yield return(new WaitForEndOfFrame());

        SwitchToEnemyTurn();

        yield return(new WaitForEndOfFrame());

        StartCoroutine(CombatController.instance.EnemyPhase());
    }