Beispiel #1
0
    public IEnumerator HandleDeathCoroutine(LivingEntity entity, Action action)
    {
        Debug.Log("CombatLogic.HandleDeathCoroutine() started for " + entity.myName);
        entity.inDeathProcess = true;

        LevelManager.Instance.SetTileAsUnoccupied(entity.tile);
        LivingEntityManager.Instance.allLivingEntities.Remove(entity);
        entity.DisableWorldSpaceCanvas();
        ActivationManager.Instance.activationOrder.Remove(entity);

        entity.PlayDeathAnimation();
        Action destroyWindowAction = entity.myActivationWindow.FadeOutWindow();

        yield return(new WaitUntil(() => destroyWindowAction.ActionResolved() == true));

        yield return(new WaitUntil(() => entity.MyDeathAnimationFinished() == true));


        // Check volatile
        if (entity.myPassiveManager.Volatile)
        {
            // Notification
            VisualEffectManager.Instance.CreateStatusEffect(entity.transform.position, "Volatile");

            // Calculate which characters are hit by the aoe
            List <LivingEntity> targetsInRange = GetAllLivingEntitiesWithinAoeEffect(entity, entity.tile, 1, true, true);

            // Damage all targets hit
            foreach (LivingEntity targetInBlast in targetsInRange)
            {
                if (targetInBlast.inDeathProcess == false)
                {
                    int    finalDamageValue  = GetFinalDamageValueAfterAllCalculations(entity, targetInBlast, null, "Physical", false, entity.myPassiveManager.volatileStacks);
                    Action volatileExplosion = HandleDamage(finalDamageValue, null, targetInBlast, "Physical");
                    yield return(new WaitUntil(() => volatileExplosion.ActionResolved() == true));
                }
            }

            yield return(new WaitForSeconds(1));
        }

        // Check unstable
        if (entity.myPassiveManager.unstable)
        {
            // Notification
            VisualEffectManager.Instance.CreateStatusEffect(entity.transform.position, "Unstable");

            // Calculate which characters are hit by the aoe
            List <LivingEntity> targetsInRange = GetAllLivingEntitiesWithinAoeEffect(entity, entity.tile, 1, true, true);

            // Poison all targets hit
            foreach (LivingEntity targetInBlast in targetsInRange)
            {
                if (targetInBlast.inDeathProcess == false)
                {
                    targetInBlast.myPassiveManager.ModifyPoisoned(entity.myPassiveManager.unstableStacks);
                }
            }

            yield return(new WaitForSeconds(1));
        }

        // Remove entity from relavent lists
        if (entity.defender)
        {
            DefenderManager.Instance.allDefenders.Remove(entity.defender);
        }
        else if (entity.enemy)
        {
            entity.enemy.currentlyActivated = false;
            EnemyManager.Instance.allEnemies.Remove(entity.enemy);
        }


        // Depending on the state of the combat, decide which ending or continuation occurs

        // check if the player has lost all characters and thus the game
        if (DefenderManager.Instance.allDefenders.Count == 0 &&
            EventManager.Instance.currentCombatEndEventTriggered == false)
        {
            Debug.Log("CombatLogic.HandleDeath() detected player has lost all defenders...");
            EventManager.Instance.currentCombatEndEventTriggered = true;
            EventManager.Instance.StartNewGameOverDefeatedEvent();
        }

        // check if this was the last enemy in the encounter
        else if (EnemyManager.Instance.allEnemies.Count == 0 &&
                 DefenderManager.Instance.allDefenders.Count >= 1 &&
                 EventManager.Instance.currentCombatEndEventTriggered == false)
        {
            Debug.Log("CombatLogic.HandleDeath() detected that all enemies have been killed...");

            // Trigger combat victory event depending on current encounter type
            if (EventManager.Instance.currentEncounterType == WorldEncounter.EncounterType.EliteEnemy)
            {
                EventManager.Instance.currentCombatEndEventTriggered = true;
                EventManager.Instance.StartNewEndEliteEncounterEvent();
            }
            else if (EventManager.Instance.currentEncounterType == WorldEncounter.EncounterType.BasicEnemy)
            {
                EventManager.Instance.currentCombatEndEventTriggered = true;
                EventManager.Instance.StartNewEndBasicEncounterEvent();
            }
            else if (EventManager.Instance.currentEncounterType == WorldEncounter.EncounterType.Boss)
            {
                EventManager.Instance.currentCombatEndEventTriggered = true;
                EventManager.Instance.StartNewEndBossEncounterEvent();
            }
        }

        // Destroy character GO
        Debug.Log("Destroying " + entity.myName + " game object");
        Destroy(entity.gameObject);

        // Resolve
        action.actionResolved = true;
    }