/// <summary> /// Updating the last line index. /// </summary> private void updateLastLine() { bool allDead = true; for (int i = 0; i < m_enemies.GetLength(0); i++) { allDead &= m_enemies[i, m_lastEnemiesLine].IsDead; if (!allDead) { break; } } if (allDead) { m_lastEnemiesLine--; if (m_lastEnemiesLine < 0) { if (AllEnemiesDead != null) { AllEnemiesDead.Invoke(); } } else { updateLastLine(); } } }
void OnEnemyDeath() { enemiesDead++; if (enemiesDead == enemiesWithin.Count) { AllEnemiesDead.Invoke(); } }
/// <summary> /// Updating the first and last columns indices. /// </summary> private void updateColumnsBounderies() { bool allDeadFirst = true; bool allDeadLast = true; for (int i = 0; i < m_enemies.GetLength(1); i++) { allDeadFirst &= m_enemies[m_firstEnemiesColumn, i].IsDead; allDeadLast &= m_enemies[m_lastEnemiesColumn, i].IsDead; if (!allDeadFirst && !allDeadLast) { break; } } if (allDeadFirst || allDeadLast) { if (allDeadFirst) { m_firstEnemiesColumn++; } if (allDeadLast) { m_lastEnemiesColumn--; } if (m_firstEnemiesColumn > m_lastEnemiesColumn) { if (AllEnemiesDead != null) { AllEnemiesDead.Invoke(); } } else { updateColumnsBounderies(); } } }
/// <summary> /// Spawns the next wave of enemies, both locally on host and on all clients through messages. /// </summary> public void SpawnEnemies() { // Get data from spawner list var data = _enemyInfoPool.GetEnemySpawnInfos(); // Check if data.Count is greater than zero if (data.Count > 0) { // Spawn enemies locally and through network // Generate an unique id for each enemy data.ForEach(enemy => enemy.SpawnParameters.Id = _aiSpawner.GenerateNextID()); using (var message = _networkedAISpawner.GenerateSpawnMessage(data)) { _synchronizedMessageSender.SendMessageWithResponse(message); } data.ForEach(enemy => enemy.SpawnParameters.IsLocal = true); LocalSpawn(data); } else { // All waves completed AllEnemiesDead?.Invoke(); } }