Beispiel #1
0
    private IEnumerator HeroAttack()
    {
        // definir inimigo
        var index = SelectedEnemyIndex;
        var enemy = _enemies[index];

        // executar regra pré ataque
        ExecuteRule(RuleType.BeforeHeroAttack);

        // definir quem ataca
        var heroes = _heroes.FindAll(h => h.IsPresent);
        var hero   = heroes[_currentHeroIndex];

        // atacar
        var previousHp = enemy.currentHp;

        BattleService.Attack(hero, enemy);

        var currentHp = enemy.currentHp;

        // verificar se causou dano
        var enemyDisplay = EnemyDisplay.Get(_enemies.Count - 1);
        var tagName      = enemyDisplay.ContainerNames[index] + "_" + _enemies.Count;

        var attackValue = previousHp - currentHp;

        if (_strongestAttack < attackValue)
        {
            _strongestAttack = attackValue;
            HeroWhoGaveTheStrongestAttack = hero;
        }

        if (previousHp != currentHp)
        {
            for (var i = 0; i < 5; i++)
            {
                yield return(new WaitForSeconds(0.1f));

                SetColorToGameObject(Color.red, tagName);

                yield return(new WaitForSeconds(0.1f));

                SetColorToGameObject(Color.white, tagName);
            }
        }

        // alterar status da vida
        if (currentHp <= 0)
        {
            enemy.isPresent = false;

            SetColorToGameObject(Color.black, tagName);
        }

        // verificar se existem inimigos vivos
        var thereAreEnemiesAlive = _enemies.Any(e => e.isPresent);

        if (!thereAreEnemiesAlive)
        {
            //TODO: Verificar se toda a equipe ganha xp, mesmo se tiver morrido.
            HeroBattleCalculator.CalculateTheExperienceGained(heroes, _enemies);


            SkillsViewerService.GetInstance().Heroes = _heroes.ConvertAll(h => h.Name).ToArray();
            SceneManager.LoadScene(_currentBattle.whereToGoWhenTheBattleIsOver);
        }

        // executar regra pos ataque
        ExecuteRule(RuleType.AfterHeroAttack);

        var count = heroes.FindAll(h => h.IsPresent).Count;

        // se Existir aliados continuar ataque
        if (_currentHeroIndex + 1 < count)
        {
            _currentHeroIndex++;
            DrawAttackMenu();
            yield break;
        }

        // ir para a próxima fase da batalha
        _currentHeroIndex = 0;
        DrawDefenseMenu();
    }
Beispiel #2
0
 public void Attack(HeroBattle hero, Enemy enemy)
 {
     HeroBattleCalculator.Attack(hero, enemy);
 }