Pull request #62: InvestigationSpawnConstant

Merge in CGD/gather-and-defend from feature/InvestigationSpawnConstant to main

* commit '8e8c32ca68d7c740289bb40a64dbf8895c4a377c':
  Fix misplaced variable
  Comments + variable structure
  Fixed spawning decrementation and changing spawner objectives dynamically
  Fix ConstantSpawn to change constant spawn group when one group dies Keeps doing constant spawn after 2nd group dies
  Temp reset
  Fixed enemy death resuming spawner timers unexpectedly. Now checks if the constant spawn is done to decide if spawning should end.
This commit is contained in:
Ader Alisma 01 2024-03-17 16:18:28 +00:00
commit 6dd08eb51c
8 changed files with 113 additions and 27 deletions

View File

@ -248,7 +248,7 @@ MonoBehaviour:
_renderLayer: Default _renderLayer: Default
_position: {x: 0, y: 0} _position: {x: 0, y: 0}
_scale: {x: 1, y: 1} _scale: {x: 1, y: 1}
_waveConfig: {fileID: 11400000, guid: d8140ae36f1b7fd4fb1a57ab3dc69de4, type: 2} _waveConfig: {fileID: 11400000, guid: 61b21509b3e4be0438ea87b4e7a73e17, type: 2}
_startPopulation: 10 _startPopulation: 10
_startFood: 40 _startFood: 40
_startWood: 0 _startWood: 0

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 61b21509b3e4be0438ea87b4e7a73e17
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,4 +1,3 @@
using Codice.CM.Client.Differences;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;

View File

@ -16,6 +16,7 @@ public class WaveConfig : ScriptableObject
private List<GroupList> _nestedGroupSpawn = new List<GroupList>(); private List<GroupList> _nestedGroupSpawn = new List<GroupList>();
[SerializeField] [SerializeField]
private float _gameDuration = 1; private float _gameDuration = 1;
private List<GameObject> _constraintList = new List<GameObject>(); //List of depleted enemies
private float _enemySpawndOnStart = 0; private float _enemySpawndOnStart = 0;
private int _enemySum = 0; private int _enemySum = 0;
public List<EnemyType> ConstantSpawn public List<EnemyType> ConstantSpawn
@ -56,14 +57,34 @@ public class WaveConfig : ScriptableObject
/** /**
* Returns a random enemy among the constantSpawn list * Returns a random enemy among the constantSpawn list
* Called when assigning a new enemy to a spawner
* <param name="constraint"> When given, ensures that assigned enemy hasn't depleted </param>
*/ */
public EnemyType GetRandomSpawn() public EnemyType GetRandomSpawn(GameObject constraint = null)
{ {
if (_constantSpawn.Count == 1) if (_constantSpawn.Count == 1)
{ {
return _constantSpawn[0]; return _constantSpawn[0];
} else if (constraint != null)
{
if (!_constraintList.Contains(constraint))
{
_constraintList.Add(constraint);
} }
return _constantSpawn[Random.Range(0, _constantSpawn.Count - 1)]; 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)];
} }
/** /**

View File

@ -5,17 +5,18 @@ using UnityEngine;
public class WaveObserver : Singleton<WaveObserver> public class WaveObserver : Singleton<WaveObserver>
{ {
private const int MAXTOUGHNESS = 10;
private List<SpawnerTile> _subjects = new List<SpawnerTile>(); private List<SpawnerTile> _subjects = new List<SpawnerTile>();
private List<float> _aliveEnemyCount = new List<float>(); private List<float> _aliveEnemyCount = new List<float>();
private List<int> _copyConstantSpawn;
private List<List<int>> _copyGroupSpawn; //Contains count of enemies per group
private List<float> _groupSpawnTimers; private List<float> _groupSpawnTimers;
private WaveConfig _levelConfig; private List<int> _copyConstantSpawn;
private const int MAXTOUGHNESS = 10;
private int _spawnerTiming = 0;
private List<int> _intervalTiming = new List<int>(); private List<int> _intervalTiming = new List<int>();
private bool _once = true; private List<List<int>> _copyGroupSpawn; //Contains count of enemies per group
private WaveConfig _levelConfig;
private int _spawnerTiming = 0;
private int _currentGroupIndex = 0; private int _currentGroupIndex = 0;
private bool _once = true;
public void Init(WaveConfig config) public void Init(WaveConfig config)
{ {
@ -79,29 +80,38 @@ public class WaveObserver : Singleton<WaveObserver>
{ {
GameObject paramPrefab = spawnerSubject.Prefab; GameObject paramPrefab = spawnerSubject.Prefab;
spawnerSubject.ChangeSpawnSpeed(_levelConfig.Interval * _spawnerTiming); spawnerSubject.ChangeSpawnSpeed(_levelConfig.Interval * _spawnerTiming);
if (paramPrefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) for (int spawnIndex = 0; spawnIndex < _copyConstantSpawn.Count; spawnIndex++)
{ {
int currentCount = 0; if (_copyConstantSpawn[spawnIndex] == 0) //Doesn't compare this iteration because it's already empty
for (int i = 0; i < _copyConstantSpawn.Count; i++)
{ {
if (_levelConfig.ConstantSpawn[i].GetEnemyObject() == paramPrefab) continue;
{
currentCount = --_copyConstantSpawn[i];
break;
} }
} if (paramPrefab.Equals(_levelConfig.ConstantSpawn[spawnIndex].GetEnemyObject()))
if (currentCount <= 0) {
_copyConstantSpawn[spawnIndex]--;
if (_copyConstantSpawn[spawnIndex] == 0)
{ {
foreach (SpawnerTile spawner in _subjects) foreach (SpawnerTile spawner in _subjects)
{ {
if (spawner.Prefab.Equals(paramPrefab)) if (spawner.Prefab.Equals(paramPrefab))
{
EnemyType randomEnemy = _levelConfig.GetRandomSpawn(paramPrefab);
if (randomEnemy?.GetEnemyObject() == spawner.Prefab || randomEnemy == null)
{ {
spawner.StopSpawn(); spawner.StopSpawn();
} }
else
{
spawner.Prefab = randomEnemy.GetEnemyObject();
} }
} }
} }
} }
break;
}
}
}
/** /**
* Called by enemy when they spawn * Called by enemy when they spawn
@ -122,12 +132,34 @@ public class WaveObserver : Singleton<WaveObserver>
* Called when an enemy dies * Called when an enemy dies
* Reactivates spawning on that row if disabled before * 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; _aliveEnemyCount[position] -= toughness;
if (_aliveEnemyCount[position] < MAXTOUGHNESS) if (_aliveEnemyCount[position] < MAXTOUGHNESS)
{
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(); _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<WaveObserver>
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] != 0) if (_copyGroupSpawn[_currentGroupIndex][groupIndex] != 0)
{ {
CycleRows(usedRows, currentGroup, groupIndex); 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)) if (_copyGroupSpawn[_currentGroupIndex][groupIndex] > 0 || (usedRows.Count == _subjects.Count && _copyGroupSpawn[_currentGroupIndex][groupIndex] > 0))
{ {
return false; return false;

View File

@ -63,7 +63,7 @@ public class Opponent : Entity
public override void Death() public override void Death()
{ {
_observer.NotifyDies(_observerIndex, _toughness); _observer.NotifyDies(_observerIndex, _toughness, gameObject);
base.Death(); base.Death();
} }

View File

@ -61,7 +61,6 @@ public class SpawnerTile : LevelTile
} }
} }
if (_spawnCounter < _spawnSpeed) return; if (_spawnCounter < _spawnSpeed) return;
_spawnCounter = 0; _spawnCounter = 0;
if (!_cooldownEnded) if (!_cooldownEnded)
{ {