private void DrawEnemy() { var battle = _currentBattle; var enemyDisplay = EnemyDisplay.Get(battle.enemies.Count - 1); Show(enemyDisplay.DisplayContainerName); var count = battle.enemies.Count; for (var i = 0; i < count; i++) { var containerName = enemyDisplay.ContainerNames[i] + "_" + count; DrawSpriteToGameObject(battle.enemies[i].image, containerName); } }
// SELECTORS public void OnSelectEnemy(int index) { if (_enemies[index].currentHp <= 0) { return; } var count = _currentBattle.enemies.Count; var enemyDisplay = EnemyDisplay.Get(count - 1); GetEnemiesPresentIndexes().ForEach(i => { SetColorToGameObject(Color.white, enemyDisplay.ContainerNames[i] + "_" + count); }); SetColorToGameObject(Color.yellow, enemyDisplay.ContainerNames[index] + "_" + count); SelectedEnemyIndex = index; }
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(); }