コード例 #1
0
ファイル: CombatStats.cs プロジェクト: cmrnprry/Rat-House
    //Handles what happens when an enemy dies
    public IEnumerator EnemyDeath(int enemyAttacked, EnemyCombatBehaviour enemy)
    {
        //decrease the number o f enemies left
        _enemiesLeft -= 1;

        //Death Sound
        AudioManager.instance.SFX.clip = AudioManager.instance.enemySFX[AudioManager.instance.enemySFX.Count - 1];
        AudioManager.instance.SFX.Play();

        //turin off health bar
        CombatController.instance.enemyHealthBars[enemyAttacked].gameObject.SetActive(false);

        enemy.EnemyDeath();
        yield return(new WaitForSecondsRealtime(1f));

        Debug.Log("Enemy Dead");

        //Destroy Enemy
        Destroy(CombatController.instance._inBattle[enemyAttacked].gameObject);

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

        //remove enemy from list(s)
        CombatController.instance._inBattle[enemyAttacked] = null;
    }
コード例 #2
0
ファイル: TutorialScript.cs プロジェクト: cmrnprry/Rat-House
    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();
        }
    }
コード例 #3
0
    /****************************   HANDLES ENEMY TURN  **********************************************/


    public IEnumerator EnemyPhase(int enemy = 0)
    {
        yield return(new WaitForSecondsRealtime(0.5f));

        Debug.Log("Enemy Phase Start");
        Image[] splashScreen = null;

        //for each non-defeated enemy, do their attacks
        if (enemy < _inBattle.Count)
        {
            if (_inBattle[enemy] != null)
            {
                float                damage      = 0;
                GameObject           enemyObj    = _inBattle[enemy];
                EnemyCombatBehaviour enemyScript = enemyObj.GetComponent <EnemyCombatBehaviour>();


                StartCoroutine(enemyScript.AttackPlayer());

                yield return(new WaitUntil(() => enemyScript.IsTurnOver()));

                splashScreen = (CombatStats.amountHit >= (CombatStats.totalHits / 2) && CombatStats.amountHit != 0) ? CombatController.instance.splashScreensGood : CombatController.instance.splashScreensBad;
                // _stats.UpdatePlayerHealth(-1 * enemyScript.GetBaseAttack());
                damage = enemyScript.GetBaseAttack();

                enemyScript.SetIsTurnOver(false);

                _stats.enemyHealth[enemy] = enemyScript._currentHealth;

                if (enemyScript.tag == "Susan" && (enemyScript._currentHealth <= 0 || enemyScript.nextPhase))
                {
                    yield break;
                }
                else if (enemyScript._currentHealth <= 0)
                {
                    StartCoroutine(_stats.EnemyDeath(enemy, enemyScript));
                }

                Debug.Log("Turn Over");

                //turn on splashscreens and play animation
                splashScreen[splashScreen.Length - 1].gameObject.SetActive(true);

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

                //Update Player health
                _stats.UpdatePlayerHealth(-1 * damage);
                yield return(new WaitForSecondsRealtime(2f));

                splashScreen[splashScreen.Length - 1].gameObject.SetActive(false);

                if (!_stats.hasEffect)
                {
                    PlayerStatusEffect(enemyList[enemy]);
                }

                //if the player is dead, break
                if (_stats.playerHealth <= 0)
                {
                    yield break;
                }

                yield return(new WaitForSecondsRealtime(0.75f));
            }

            yield return(new WaitForEndOfFrame());

            StartCoroutine(EnemyPhase(enemy + 1));
            yield break;
        }

        enemyTurnOver = true;

        //If there are no enemies left
        if (_stats._enemiesLeft <= 0)
        {
            StartCoroutine(GameManager.instance.BattleWon());
            yield break;
        }

        yield return(new WaitForEndOfFrame());

        //Find the first non-defeated enemy to have selected
        for (int i = 0; i < _inBattle.Count; i++)
        {
            if (_inBattle[i] != null)
            {
                _selectedEnemy = i;
                _battleStart   = i;
                break;
            }
        }

        FindEnd(_inBattle.Count - 1);

        //Play player turn SFX
        AudioManager.instance.SFX.clip = AudioManager.instance.UISFX[3];
        AudioManager.instance.SFX.Play();

        if (_stats.hasEffect)
        {
            _stats.UpdateEffect();
        }

        ShowActionMenu();
        GameManager.instance.battleAnimator.SetBool("IsOpen", true);

        yield return(new WaitForEndOfFrame());

        enemyTurnOver = false;
        yield break;
    }
コード例 #4
0
ファイル: CombatStats.cs プロジェクト: cmrnprry/Rat-House
    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());
    }