Ader Alisma 01 6345febb35 Start reworking constant spawn
Made interval between spawns adapt to enemies spawned at the Start

Removed the random factor of interval to respect the game duration

Made max spawn per row dependent of enemy toughness on that row
2023-09-10 15:39:19 -04:00

50 lines
1.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Gather And Defend/Levels/WaveConfig")]
public class WaveConfig : ScriptableObject
{
[SerializeField]
private List<EnemyType> _constantSpawn = new List<EnemyType>();
[SerializeField]
private float _gameDuration = 0;
private float _enemySpawndOnStart = 0;
private int _enemySum = 0;
public List<EnemyType> ConstantSpawn
{
get
{
return _constantSpawn;
}
}
public float GetInterval()
{
float interval = _gameDuration * 60.0f / (_enemySum > 0 ? _enemySum.ToFloat() : SumCount()) ;
return interval;
}
public float GetUpdatedInterval()
{
_enemySpawndOnStart++;
float interval = Mathf.Max(_gameDuration * 60.0f / (_enemySum - _enemySpawndOnStart).ToFloat(), 0);
return interval;
}
public EnemyType GetRandomSpawn()
{
if (_constantSpawn.Count == 1)
{
return _constantSpawn[0];
}
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)];
}
private float SumCount()
{
foreach (EnemyType enemy in _constantSpawn)
{
_enemySum += enemy.Count;
}
return _enemySum.ToFloat();
}
}