From 4ae8f0dcfac6a4d87276d088475603f4ea1d7e0e Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sat, 4 Nov 2023 10:01:40 -0400 Subject: [PATCH] Start delay with for loop and breakTag --- Assets/Design/Levels/WaveConfig01.asset | 6 +-- Assets/Scripts/LevelConfig/WaveObserver.cs | 57 +++++++++++++++++++--- Assets/Scripts/Tiles/SpawnerTile.cs | 13 ++++- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Assets/Design/Levels/WaveConfig01.asset b/Assets/Design/Levels/WaveConfig01.asset index 76aa0cf..db67372 100644 --- a/Assets/Design/Levels/WaveConfig01.asset +++ b/Assets/Design/Levels/WaveConfig01.asset @@ -18,10 +18,10 @@ MonoBehaviour: _nestedGroupSpawn: - groupSpawn: - _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} - _count: 11 + _count: 0 - _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} - _count: 4 - triggerTime: 0.5 + _count: 2 + triggerTime: 0.1 - groupSpawn: - _enemy: {fileID: 313037212318601125, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} _count: 1 diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index 3229353..9b12dd7 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -6,7 +6,7 @@ public class WaveObserver : Singleton private List _subjects = new List(); private List _aliveEnemyCount = new List(); private List _copyConstantSpawn; - private List _copyGroupSpawn; + private List> _copyGroupSpawn; private List _groupSpawnTimers; private WaveConfig _levelConfig; private const int MAXTOUGHNESS = 10; @@ -19,7 +19,7 @@ public class WaveObserver : Singleton { _levelConfig = config; _copyConstantSpawn = new List(); - _copyGroupSpawn = new List(); + _copyGroupSpawn = new List>(); _groupSpawnTimers = new List(); foreach (EnemyType enemy in _levelConfig.ConstantSpawn) { @@ -27,7 +27,11 @@ public class WaveObserver : Singleton } for (int index = 0; index < _levelConfig.NestedGroupSpawn.Count; index++) { - _copyGroupSpawn.Add(_levelConfig.NestedGroupSpawn[index]); + _copyGroupSpawn.Add(new List()); + for (int nestedIndex = 0; nestedIndex < _levelConfig.NestedGroupSpawn[index].groupSpawn.Count; nestedIndex++) + { + _copyGroupSpawn[index].Add(_levelConfig.NestedGroupSpawn[index].groupSpawn[nestedIndex].Count); + } _groupSpawnTimers.Add(_levelConfig.NestedGroupSpawn[index].triggerTime); } } @@ -158,16 +162,55 @@ public class WaveObserver : Singleton * Called when it is time to spawn a group * Assigns a random element of the group to a random spawner */ - public void NotifyGroupSpawn() + public bool NotifyGroupSpawn() { System.Random rand = new System.Random(); - foreach (EnemyType groupEnemy in _copyGroupSpawn[_currentGroupIndex].groupSpawn) + List usedRows = new List(); + List currentGroup = _levelConfig.NestedGroupSpawn[_currentGroupIndex].groupSpawn; + for (int groupIndex = 0; groupIndex < currentGroup.Count; groupIndex++) //Loops through enemy groups { - for (int i = 0; i < groupEnemy.Count; i++) + if (_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0) + if (usedRows.Count < _subjects.Count) //TODO: decreases actual count + goes into negatives { - _subjects[rand.Next(_subjects.Count)].TriggerSpawn(groupEnemy.GetEnemyObject()); + for (int i = 0; i < _subjects.Count; i++) //Loops through spawners + { + bool breakTag = false; + do + { + int currentRow = rand.Next(_subjects.Count); + if (!usedRows.Contains(currentRow)) + { + _subjects[rand.Next(_subjects.Count)].TriggerSpawn(currentGroup[groupIndex].GetEnemyObject()); + _copyGroupSpawn[_currentGroupIndex][groupIndex]--; + Debug.Log(_copyGroupSpawn[_currentGroupIndex][groupIndex]); + usedRows.Add(currentRow); + } + if(_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0) //If current ennemy has reached count of 0 + { + breakTag = true; + break; + } + }while(usedRows.Count==i); + Debug.Log("Row: " + usedRows.Count); + if (breakTag) + { + break; + } + } + if (_copyGroupSpawn[_currentGroupIndex][groupIndex] > 0) //If after doing evry row, there are still some left + { + return false; + } + else + { + break; + } + } else + { + return false; } } _currentGroupIndex++; + return true; } } diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index b37aa4f..56376aa 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -16,6 +16,7 @@ public class SpawnerTile : LevelTile private WaveObserver _observer; private bool _stopped = false; private bool _cooldownEnded = false; + private bool _EnemiesCleared = true; private List _groupSpawnTimers = new List(); public void SetGroupSpawnTimers(List groupSpawnTimers) @@ -49,8 +50,16 @@ public class SpawnerTile : LevelTile { if (_lifetime / 60 > _groupSpawnTimers[0]) { - _groupSpawnTimers.RemoveAt(0); - _observer.NotifyGroupSpawn(); + _EnemiesCleared = _observer.NotifyGroupSpawn(); + if (_EnemiesCleared) + { + _groupSpawnTimers.RemoveAt(0); + Debug.Log("Next..."); + } else + { + _groupSpawnTimers[0] += 0.05f; + Debug.Log("Timer: " + _groupSpawnTimers[0]); + } } } if (_spawnCounter < _spawnSpeed) return;