Example #1
0
    public IEnumerator StartAITurn()
    {
        yield return(new WaitForSeconds(1));

        // Execute start turn field effects
        yield return(StartCoroutine(Battleground.Instance.UpdateNewTurnHazards(false)));

        // Apply all effects/dots on each enemy
        foreach (BaseUnit unit in _enemies)
        {
            unit.ExecuteStartTurnStatuses();
        }

        // Check if they are all dead
        if (_enemies.Count < 1)
        {
            _turnManager.BattleWon();
            yield break;
        }

        // cycle AI units
        List <BaseUnit> units = _partyManager.GetUnits();

        for (int i = 0; i < _enemies.Count; i++)
        {
            EnemyUnit enemy = _enemies[i] as EnemyUnit;
            // Check if stunned and pass if so
            BaseStatus stun = enemy.SearchStatusLike(typeof(StunStatus));
            if (stun != null)
            {
                Debug.Log(enemy.UnitName + " is skipping turn for stun");
                continue;
            }

            // Pick a target for the card

            // TODO random for now, change later
            // BaseUnit[] target = { units[Random.Range(0, units.Count)] };

            // Check if taunted, if not
            // Pick a target based on thread
            BaseStatus taunt = enemy.SearchStatusLike(typeof(TauntStatus));
            BaseUnit[] target;
            if (taunt != null)
            {
                target = new BaseUnit[] { taunt.Owner }
            }
            ;
            else
            {
                target = new BaseUnit[] { _partyManager.PickUnitWithThreat() }
            };

            // play the card
            enemy.GetNextCard().Play(target);

            yield return(new WaitForSeconds(1));

            // TODO check animations and all effects for appropriate delay or add an event

            // Update the player units left
            units = _partyManager.GetUnits();
            if (units.Count < 1)
            {
                _turnManager.BattleLost();
            }
        }

        foreach (BaseUnit unit in _enemies)
        {
            unit.ExecuteEndTurnStatuses();
        }

        // Execute end turn globals
        yield return(new WaitForSeconds(1));

        GlobalsManager.Instance.ApplyEndTurn(false);
        yield return(new WaitForSeconds(1));

        // End turn
        _turnManager.StartPlayerTurn();
    }