void Start() { this.returnBuffer = new List <Fighter>(); this.fighters = GameObject.FindObjectsOfType <Fighter>(); this.SortFightersBySpeed(); this.MakeTeams(); LogPanel.Write("Battle initiated."); this.combatStatus = CombatStatus.NEXT_TURN; this.fighterIndex = -1; this.isCombatActive = true; StartCoroutine(this.CombatLoop()); }
IEnumerator CombatLoop() { while (this.isCombatActive) { switch (this.combatStatus) { case CombatStatus.WAITING_FOR_FIGHTER: yield return(null); break; case CombatStatus.FIGHTER_ACTION: LogPanel.Write($"{this.fighters[this.fighterIndex].idName} uses {currentFighterSkill.skillName}."); yield return(null); // Executing fighter skill currentFighterSkill.Run(); // Wait for fighter skill animation yield return(new WaitForSeconds(currentFighterSkill.animationDuration)); this.combatStatus = CombatStatus.CHECK_ACTION_MESSAGES; break; case CombatStatus.CHECK_ACTION_MESSAGES: string nextMessage = this.currentFighterSkill.GetNextMessage(); if (nextMessage != null) { LogPanel.Write(nextMessage); yield return(new WaitForSeconds(2f)); } else { this.currentFighterSkill = null; this.combatStatus = CombatStatus.CHECK_FOR_VICTORY; yield return(null); } break; case CombatStatus.CHECK_FOR_VICTORY: bool arePlayersAlive = false; foreach (var figther in this.playerTeam) { arePlayersAlive |= figther.isAlive; } // if (this.playerTeam[0].isAlive OR this.playerTeam[1].isAlive) bool areEnemiesAlive = false; foreach (var figther in this.enemyTeam) { areEnemiesAlive |= figther.isAlive; } bool victory = areEnemiesAlive == false; bool defeat = arePlayersAlive == false; if (victory) { LogPanel.Write("Victoria!"); this.isCombatActive = false; } if (defeat) { LogPanel.Write("Derrota!"); this.isCombatActive = false; } if (this.isCombatActive) { this.combatStatus = CombatStatus.NEXT_TURN; } yield return(null); break; case CombatStatus.NEXT_TURN: yield return(new WaitForSeconds(1f)); Fighter current = null; do { this.fighterIndex = (this.fighterIndex + 1) % this.fighters.Length; current = this.fighters[this.fighterIndex]; } while (current.isAlive == false); this.combatStatus = CombatStatus.CHECK_FIGHTER_STATUS_CONDITION; break; case CombatStatus.CHECK_FIGHTER_STATUS_CONDITION: var currentFighter = this.fighters[this.fighterIndex]; var statusCondition = currentFighter.GetCurrentStatusCondition(); if (statusCondition != null) { statusCondition.Apply(); while (true) { string nextSCMessage = statusCondition.GetNextMessage(); if (nextSCMessage == null) { break; } LogPanel.Write(nextSCMessage); yield return(new WaitForSeconds(2f)); } if (statusCondition.BlocksTurn()) { this.combatStatus = CombatStatus.CHECK_FOR_VICTORY; break; } } LogPanel.Write($"{currentFighter.idName} has the turn."); currentFighter.InitTurn(); this.combatStatus = CombatStatus.WAITING_FOR_FIGHTER; break; } } }