Fix ConstantSpawn to change constant spawn group when one group dies

Keeps doing constant spawn after 2nd group dies

To test: 2 groups die, what about the 3rd one
This commit is contained in:
Ader Alisma 01 2024-02-27 15:21:47 -05:00
parent d0371349db
commit 8921c898ec
5 changed files with 41 additions and 54 deletions

View File

@ -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

View File

@ -14,10 +14,12 @@ MonoBehaviour:
m_EditorClassIdentifier:
_constantSpawn:
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
_count: 20
_count: 4
- _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
_count: 4
_nestedGroupSpawn:
- groupSpawn:
- _enemy: {fileID: 80204295746100150, guid: 5bbf0d85fa5bb3f4599da79f0a84e3a9, type: 3}
_count: 2
triggerTime: 2
_gameDuration: 3
_gameDuration: 1

View File

@ -57,11 +57,19 @@ public class WaveConfig : ScriptableObject
/**
* Returns a random enemy among the constantSpawn list
*/
public EnemyType GetRandomSpawn()
public EnemyType GetRandomSpawn(GameObject constraint = null)
{
if (_constantSpawn.Count == 1)
{
return _constantSpawn[0];
} else if (constraint != null)
{
EnemyType randomEnemy;
do
{
randomEnemy = _constantSpawn[Random.Range(0, _constantSpawn.Count)];
} while (randomEnemy.GetEnemyObject() == constraint);
return randomEnemy;
}
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)];
}

View File

@ -79,64 +79,41 @@ public class WaveObserver : Singleton<WaveObserver>
{
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 (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab)
// {
// currentCount = --_copyConstantSpawn[i];
// break;
// Debug.Log("Amout to spawn is now: " + currentCount);
// if (currentCount <= 0)
// {
// //bool hasNextTarget = false;
// //for (int j = i; j < _copyConstantSpawn.Count; j++)
// //{
// // if (_copyConstantSpawn[_copyConstantSpawn.Count - j] > 0)
// // {
// // spawnerSubject.Prefab = _levelConfig.ConstantSpawn[j].GetEnemyObject();
// // hasNextTarget = true;
// // Debug.Log(spawnerSubject.Prefab.name);
// // }
// //}
// //if (!hasNextTarget)
// //{
// foreach (SpawnerTile spawner in _subjects)
// {
// if (spawner.Prefab.Equals(paramPrefab))
// {
// spawner.StopSpawn();
// Debug.Log("----Spawn Stopped----");
// }
// }
// //}
// }
// }
//}
int currentCount = 0;
for (int i = 0; i < _copyConstantSpawn.Count; i++)
if (_copyConstantSpawn[spawnIndex] == 0)
{
if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab)
{
currentCount = --_copyConstantSpawn[i];
break;
}
Debug.Log("--I'm empty--");
continue;
}
Debug.Log("Amout to spawn is now: " + currentCount);
if (currentCount <= 0)
if (paramPrefab.Equals(_levelConfig.ConstantSpawn[spawnIndex].GetEnemyObject()))
{
foreach (SpawnerTile spawner in _subjects)
_copyConstantSpawn[spawnIndex]--;
Debug.Log("Amout to spawn is now: " + _copyConstantSpawn[spawnIndex]);
if (_copyConstantSpawn[spawnIndex] == 0)
{
if (spawner.Prefab.Equals(paramPrefab))
foreach (SpawnerTile spawner in _subjects)
{
spawner.StopSpawn();
Debug.Log("----Spawn Stopped----");
if (spawner.Prefab.Equals(paramPrefab))
{
GameObject randomEnemy = _levelConfig.GetRandomSpawn(paramPrefab).GetEnemyObject();
if (randomEnemy == spawner.Prefab)
{
spawner.StopSpawn();
Debug.Log("----Spawn Stopped----");
}
else
{
spawner.Prefab = randomEnemy;
Debug.Log("----Spawn Changed!!!----");
}
}
}
}
break;
}
}
}
}
/**

View File

@ -60,7 +60,7 @@ public class SpawnerTile : LevelTile
}
}
}
Debug.Log("Time: " + _spawnCounter);
//Debug.Log("Time: " + _spawnCounter);
if (_spawnCounter < _spawnSpeed) return;
Debug.Log("Stopped but still spawning");
_spawnCounter = 0;