End groupSpawn delay

Adds a ~3 seconds delay when a group has more ennemies than available rows·.

Added groupSpawnDelay to GlobalConfigFile
This commit is contained in:
Ader Alisma 01 2023-11-12 16:18:52 -05:00
parent 4ae8f0dcfa
commit 7edbec43b3
3 changed files with 36 additions and 45 deletions

View File

@ -16,6 +16,9 @@ public class GlobalConfigFile : ScriptableObject
public Vector2 enemyRangeMultiplier = Vector2.one;
public float enemyAttackSpeedMultiplier = 1;
[Header("Spawn")]
public float groupSpawnDelay = 0.05f;
[Header("Allies")]
public float allyDamageMultiplier = 1;
public float allyLifeMultiplier = 1;

View File

@ -6,7 +6,7 @@ public class WaveObserver : Singleton<WaveObserver>
private List<SpawnerTile> _subjects = new List<SpawnerTile>();
private List<float> _aliveEnemyCount = new List<float>();
private List<int> _copyConstantSpawn;
private List<List<int>> _copyGroupSpawn;
private List<List<int>> _copyGroupSpawn; //Contains count of enemies per group
private List<float> _groupSpawnTimers;
private WaveConfig _levelConfig;
private const int MAXTOUGHNESS = 10;
@ -17,7 +17,7 @@ public class WaveObserver : Singleton<WaveObserver>
public void SetLevelConfig(WaveConfig config)
{
_levelConfig = config;
_levelConfig = Object.Instantiate(config);
_copyConstantSpawn = new List<int>();
_copyGroupSpawn = new List<List<int>>();
_groupSpawnTimers = new List<float>();
@ -164,53 +164,43 @@ public class WaveObserver : Singleton<WaveObserver>
*/
public bool NotifyGroupSpawn()
{
System.Random rand = new System.Random();
List<int> usedRows = new List<int>();
List<EnemyType> currentGroup = _levelConfig.NestedGroupSpawn[_currentGroupIndex].groupSpawn;
for (int groupIndex = 0; groupIndex < currentGroup.Count; groupIndex++) //Loops through enemy groups
{
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0)
if (usedRows.Count < _subjects.Count) //TODO: decreases actual count + goes into negatives
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] != 0)
{
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
CycleRows(usedRows, currentGroup, groupIndex);
/*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;
}
else
{
break;
}
} else
{
return false;
}
}
_currentGroupIndex++;
return true;
}
/**
* Called to go through every row randomly without duplicate rows
*/
private void CycleRows(List<int> usedRows, List<EnemyType> currentGroup, int groupIndex)
{
System.Random rand = new System.Random();
while (usedRows.Count < _subjects.Count)
{
int currentRow = rand.Next(_subjects.Count);
if (!usedRows.Contains(currentRow)) //If picked row has laready been used
{
_subjects[currentRow].TriggerSpawn(currentGroup[groupIndex].GetEnemyObject());
_copyGroupSpawn[_currentGroupIndex][groupIndex]--;
usedRows.Add(currentRow);
}
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0) //If current ennemy has reached count of 0
{
break;
}
}
}
}

View File

@ -21,7 +21,7 @@ public class SpawnerTile : LevelTile
public void SetGroupSpawnTimers(List<float> groupSpawnTimers)
{
for (int i = 0; i < groupSpawnTimers.Count-1; i++)
for (int i = 0; i < groupSpawnTimers.Count; i++)
{
_groupSpawnTimers.Add(groupSpawnTimers[i]);
}
@ -48,17 +48,15 @@ public class SpawnerTile : LevelTile
}
if (_groupSpawnTimers.Count > 0)
{
if (_lifetime / 60 > _groupSpawnTimers[0])
if (_lifetime / 60.0f > _groupSpawnTimers[0])
{
_EnemiesCleared = _observer.NotifyGroupSpawn();
if (_EnemiesCleared)
if (_EnemiesCleared) //Moves on to next group
{
_groupSpawnTimers.RemoveAt(0);
Debug.Log("Next...");
} else
} else //Adds a delay to finish current group
{
_groupSpawnTimers[0] += 0.05f;
Debug.Log("Timer: " + _groupSpawnTimers[0]);
_groupSpawnTimers[0] += GlobalConfig.Instance.Current.groupSpawnDelay;
}
}
}