diff --git a/Assets/Design/Levels/Level1.asset b/Assets/Design/Levels/Level1.asset index 23e574f..56169bb 100644 --- a/Assets/Design/Levels/Level1.asset +++ b/Assets/Design/Levels/Level1.asset @@ -248,7 +248,7 @@ MonoBehaviour: _renderLayer: Default _position: {x: 0, y: 0} _scale: {x: 1, y: 1} - _waveConfig: {fileID: 11400000, guid: d8140ae36f1b7fd4fb1a57ab3dc69de4, type: 2} + _waveConfig: {fileID: 11400000, guid: 61b21509b3e4be0438ea87b4e7a73e17, type: 2} _startPopulation: 10 _startFood: 40 _startWood: 0 diff --git a/Assets/Design/Levels/WaveConfig_Test.asset b/Assets/Design/Levels/WaveConfig_Test.asset new file mode 100644 index 0000000..2e4eca2 --- /dev/null +++ b/Assets/Design/Levels/WaveConfig_Test.asset @@ -0,0 +1,27 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: eb0795e326609f0499365f5b65c2b5cd, type: 3} + m_Name: WaveConfig_Test + m_EditorClassIdentifier: + _constantSpawn: + - _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3} + _count: 4 + - _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} + _count: 4 + - _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3} + _count: 6 + _nestedGroupSpawn: + - groupSpawn: + - _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3} + _count: 2 + triggerTime: 2 + _gameDuration: 1 diff --git a/Assets/Design/Levels/WaveConfig_Test.asset.meta b/Assets/Design/Levels/WaveConfig_Test.asset.meta new file mode 100644 index 0000000..0c8bb1d --- /dev/null +++ b/Assets/Design/Levels/WaveConfig_Test.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 61b21509b3e4be0438ea87b4e7a73e17 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Drag&Drop/DeleteShovel.cs b/Assets/Scripts/Drag&Drop/DeleteShovel.cs index 9288b40..f9fb5f0 100644 --- a/Assets/Scripts/Drag&Drop/DeleteShovel.cs +++ b/Assets/Scripts/Drag&Drop/DeleteShovel.cs @@ -1,4 +1,3 @@ -using Codice.CM.Client.Differences; using System.Collections; using System.Collections.Generic; using UnityEngine; diff --git a/Assets/Scripts/LevelConfig/WaveConfig.cs b/Assets/Scripts/LevelConfig/WaveConfig.cs index 3671260..41b9b6a 100644 --- a/Assets/Scripts/LevelConfig/WaveConfig.cs +++ b/Assets/Scripts/LevelConfig/WaveConfig.cs @@ -16,6 +16,7 @@ public class WaveConfig : ScriptableObject private List _nestedGroupSpawn = new List(); [SerializeField] private float _gameDuration = 1; + private List _constraintList = new List(); //List of depleted enemies private float _enemySpawndOnStart = 0; private int _enemySum = 0; public List ConstantSpawn @@ -56,14 +57,34 @@ public class WaveConfig : ScriptableObject /** * Returns a random enemy among the constantSpawn list + * Called when assigning a new enemy to a spawner + * When given, ensures that assigned enemy hasn't depleted */ - public EnemyType GetRandomSpawn() + public EnemyType GetRandomSpawn(GameObject constraint = null) { if (_constantSpawn.Count == 1) { return _constantSpawn[0]; + } else if (constraint != null) + { + if (!_constraintList.Contains(constraint)) + { + _constraintList.Add(constraint); + } + if (_constraintList.Count < _constantSpawn.Count) + { + EnemyType randomEnemy; + do + { + randomEnemy = _constantSpawn[Random.Range(0, _constantSpawn.Count)]; + } while (_constraintList.Contains(randomEnemy.GetEnemyObject())); + return randomEnemy; + } else + { + return null; + } } - return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)]; + return _constantSpawn[Random.Range(0, _constantSpawn.Count)]; } /** diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index 2ab3d1c..4d6e660 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -5,17 +5,18 @@ using UnityEngine; public class WaveObserver : Singleton { + private const int MAXTOUGHNESS = 10; + private List _subjects = new List(); private List _aliveEnemyCount = new List(); - private List _copyConstantSpawn; - private List> _copyGroupSpawn; //Contains count of enemies per group private List _groupSpawnTimers; - private WaveConfig _levelConfig; - private const int MAXTOUGHNESS = 10; - private int _spawnerTiming = 0; + private List _copyConstantSpawn; private List _intervalTiming = new List(); - private bool _once = true; + private List> _copyGroupSpawn; //Contains count of enemies per group + private WaveConfig _levelConfig; + private int _spawnerTiming = 0; private int _currentGroupIndex = 0; + private bool _once = true; public void Init(WaveConfig config) { @@ -79,26 +80,35 @@ public class WaveObserver : Singleton { GameObject paramPrefab = spawnerSubject.Prefab; spawnerSubject.ChangeSpawnSpeed(_levelConfig.Interval * _spawnerTiming); - if (paramPrefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) + for (int spawnIndex = 0; spawnIndex < _copyConstantSpawn.Count; spawnIndex++) { - int currentCount = 0; - for (int i = 0; i < _copyConstantSpawn.Count; i++) + if (_copyConstantSpawn[spawnIndex] == 0) //Doesn't compare this iteration because it's already empty { - if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) - { - currentCount = --_copyConstantSpawn[i]; - break; - } + continue; } - if (currentCount <= 0) + if (paramPrefab.Equals(_levelConfig.ConstantSpawn[spawnIndex].GetEnemyObject())) { - foreach (SpawnerTile spawner in _subjects) + _copyConstantSpawn[spawnIndex]--; + + if (_copyConstantSpawn[spawnIndex] == 0) { - if (spawner.Prefab.Equals(paramPrefab)) + foreach (SpawnerTile spawner in _subjects) { - spawner.StopSpawn(); + if (spawner.Prefab.Equals(paramPrefab)) + { + EnemyType randomEnemy = _levelConfig.GetRandomSpawn(paramPrefab); + if (randomEnemy?.GetEnemyObject() == spawner.Prefab || randomEnemy == null) + { + spawner.StopSpawn(); + } + else + { + spawner.Prefab = randomEnemy.GetEnemyObject(); + } + } } } + break; } } } @@ -122,12 +132,34 @@ public class WaveObserver : Singleton * Called when an enemy dies * Reactivates spawning on that row if disabled before */ - public void NotifyDies(int position, float toughness) + public void NotifyDies(int position, float toughness, GameObject paramPrefab) { _aliveEnemyCount[position] -= toughness; if (_aliveEnemyCount[position] < MAXTOUGHNESS) { - _subjects[position].StartSpawn(); + for (int i = 0; i < _copyConstantSpawn.Count; i++) + { + if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) + { + // Checks if there are more of the same type to create + if (_copyConstantSpawn[i] > 0) + { + _subjects[position].StartSpawn(); + break; + } + for (int j = i; j < _copyConstantSpawn.Count; j++) + { + // Checks if there are other types to create + if (_copyConstantSpawn[_copyConstantSpawn.Count - j] > 0) + { + _subjects[position].Prefab = _levelConfig.ConstantSpawn[j].GetEnemyObject(); + _subjects[position].StartSpawn(); + break; + } + } + break; + } + } } } @@ -187,7 +219,7 @@ public class WaveObserver : Singleton if (_copyGroupSpawn[_currentGroupIndex][groupIndex] != 0) { CycleRows(usedRows, currentGroup, groupIndex); - /*If group is done OR max rows reached while group is not done*/ + // If group is done OR max rows reached while group is not done if (_copyGroupSpawn[_currentGroupIndex][groupIndex] > 0 || (usedRows.Count == _subjects.Count && _copyGroupSpawn[_currentGroupIndex][groupIndex] > 0)) { return false; diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index a8ca40f..f5ba5db 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -63,7 +63,7 @@ public class Opponent : Entity public override void Death() { - _observer.NotifyDies(_observerIndex, _toughness); + _observer.NotifyDies(_observerIndex, _toughness, gameObject); base.Death(); } diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index ac47b5a..e668a4b 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -61,7 +61,6 @@ public class SpawnerTile : LevelTile } } if (_spawnCounter < _spawnSpeed) return; - _spawnCounter = 0; if (!_cooldownEnded) {