Merge branch 'main' into origin/feature/berriesInteractions
This commit is contained in:
commit
2ec32f8832
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<GroupList> _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,9 +17,9 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
|
||||
public void SetLevelConfig(WaveConfig config)
|
||||
{
|
||||
_levelConfig = config;
|
||||
_levelConfig = Object.Instantiate(config);
|
||||
_copyConstantSpawn = new List<int>();
|
||||
_copyGroupSpawn = new List<GroupList>();
|
||||
_copyGroupSpawn = new List<List<int>>();
|
||||
_groupSpawnTimers = new List<float>();
|
||||
if (!_levelConfig)
|
||||
{
|
||||
@ -32,7 +32,11 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
}
|
||||
for (int index = 0; index < _levelConfig.NestedGroupSpawn.Count; index++)
|
||||
{
|
||||
_copyGroupSpawn.Add(_levelConfig.NestedGroupSpawn[index]);
|
||||
_copyGroupSpawn.Add(new List<int>());
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -163,16 +167,45 @@ public class WaveObserver : Singleton<WaveObserver>
|
||||
* 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<int> usedRows = new List<int>();
|
||||
List<EnemyType> 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)
|
||||
{
|
||||
_subjects[rand.Next(_subjects.Count)].TriggerSpawn(groupEnemy.GetEnemyObject());
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,11 +16,12 @@ public class SpawnerTile : LevelTile
|
||||
private WaveObserver _observer;
|
||||
private bool _stopped = false;
|
||||
private bool _cooldownEnded = false;
|
||||
private bool _EnemiesCleared = true;
|
||||
private List<float> _groupSpawnTimers = new List<float>();
|
||||
|
||||
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]);
|
||||
}
|
||||
@ -47,10 +48,16 @@ public class SpawnerTile : LevelTile
|
||||
}
|
||||
if (_groupSpawnTimers.Count > 0)
|
||||
{
|
||||
if (_lifetime / 60 > _groupSpawnTimers[0])
|
||||
if (_lifetime / 60.0f > _groupSpawnTimers[0])
|
||||
{
|
||||
_groupSpawnTimers.RemoveAt(0);
|
||||
_observer.NotifyGroupSpawn();
|
||||
_EnemiesCleared = _observer.NotifyGroupSpawn();
|
||||
if (_EnemiesCleared) //Moves on to next group
|
||||
{
|
||||
_groupSpawnTimers.RemoveAt(0);
|
||||
} else //Adds a delay to finish current group
|
||||
{
|
||||
_groupSpawnTimers[0] += GlobalConfig.Instance.Current.groupSpawnDelay;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_spawnCounter < _spawnSpeed) return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user