Exemplo n.º 1
0
    private void DrawDefenseMenu()
    {
        ClearDefenseList();

        // var heroes = _heroes.FindAll(hero => hero.IsPresent);
        var count = _heroes.Count;

        Hide("AttackMenu");
        Show("DefenseMenu");

        var heroDefenseDisplay = HeroDefenseDisplay.Get(count - 1);

        Show(heroDefenseDisplay.DisplayContainerName);

        for (var i = 0; i < count; i++)
        {
            var containerName = heroDefenseDisplay.ContainerNames[i] + "_" + count;
            DrawSpriteToGameObject(_heroes[i].Thumbnail, containerName);

            SetColorToGameObject(_heroes[i].IsPresent ? Color.white : Color.black, containerName);
        }

        StartCoroutine(EnemyAttack());
    }
Exemplo n.º 2
0
    private IEnumerator EnemyAttack()
    {
        yield return(new WaitForSeconds(1.0f));

        // definir quem ataca
        var enemy = _enemies[_currentEnemyIndex];

        // Definir o inimigo
        var heroes = _heroes.FindAll(h => h.IsPresent);
        var hero   = EnemyBattleCalculator.GetHero(heroes, enemy);

        // Executar regra pré turno
        ExecuteRule(RuleType.BeforeEnemyAttack);

        // atacar
        var hp = hero.CurrentHp;

        EnemyBattleCalculator.Attack(hero, enemy);

        // verificar se causou dano
        var heroDefenseDisplay = HeroDefenseDisplay.Get(_heroes.Count - 1);
        var index   = _heroes.FindIndex(h => h.Name.Equals(hero.Name));
        var tagName = heroDefenseDisplay.ContainerNames[index] + "_" + _heroes.Count;

        if (hero.CurrentHp < hp)
        {
            for (var i = 0; i < 5; i++)
            {
                yield return(new WaitForSeconds(0.2f));

                SetColorToGameObject(Color.red, tagName);

                yield return(new WaitForSeconds(0.2f));

                SetColorToGameObject(Color.white, tagName);
            }
        }

        // definir personagem como morto caso a vida esteja menor ou igual a zero
        if (hero.CurrentHp <= 0)
        {
            hero.IsPresent = false;

            SetColorToGameObject(Color.black, tagName);

            _currentHeroIndex = 0;
        }

        // Verificar se existem inimigos vivos
        if (GameOverRuleService.GetInstance().Test(_currentBattle.gameOverRule, heroes))
        {
            SceneManager.LoadScene("GameOver");
            yield break;
        }

        // Executar a regra pos ataque
        ExecuteRule(RuleType.AfterEnemyAttack);

        // Se existir outros aliados continua o ataque
        if (_currentEnemyIndex + 1 == _enemies.Count)
        {
            DrawAttackMenu();
            yield break;
        }

        // se não existir outros aliados vai para a outra fase da batalha
        _currentEnemyIndex++;
        yield return(EnemyAttack());
    }