Monster Core #21

Open
Ader_Alisma wants to merge 7 commits from feature/monsterCore into main
4 changed files with 77 additions and 5 deletions
Showing only changes of commit cfbc84e567 - Show all commits

View File

@ -20,16 +20,20 @@ MonoBehaviour:
- _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
_count: 2
triggerTime: 0.25
dropsMonsterCore: 1
- groupSpawn:
- _enemy: {fileID: 80204295746100150, guid: 2419a879bd4e47d4fa8b30de0fcdde42, type: 3}
_count: 9
triggerTime: 1.5
dropsMonsterCore: 1
- groupSpawn:
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
_count: 7
triggerTime: 2
dropsMonsterCore: 0
- groupSpawn:
- _enemy: {fileID: 80204295746100150, guid: 1be769d6ef642314b8846bed35e7297c, type: 3}
_count: 14
triggerTime: 3
dropsMonsterCore: 0
_gameDuration: 3

View File

@ -249,15 +249,59 @@ public class WaveObserver : Singleton<WaveObserver>
private void CycleRows(List<int> usedRows, List<EnemyType> currentGroup, int groupIndex)
{
System.Random rand = new System.Random();
bool dropsCore = _monsterCoreGroups != null && _monsterCoreGroups.Count > _currentGroupIndex && _monsterCoreGroups[_currentGroupIndex];
int totalToSpawn = _copyGroupSpawn[_currentGroupIndex][groupIndex];
int monsterCoreTarget = -1;
if (dropsCore && totalToSpawn > 0)
{
monsterCoreTarget = rand.Next(0, totalToSpawn);
}
int spawnCount = 0;
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());
GameObject spawnedInstance = _subjects[currentRow].TriggerSpawn(currentGroup[groupIndex].GetEnemyObject());
// Si ce spawn doit être le porteur du MonsterCore, on remplace/ajoute le comportement
if (monsterCoreTarget >= 0 && spawnCount == monsterCoreTarget)
{
if (spawnedInstance != null)
{
// tentative de remplacer le composant Opponent par MonsterCoreDrop
var existingOpponent = spawnedInstance.GetComponent<Opponent>();
if (existingOpponent != null)
{
// we remove the existing Opponent-derived behaviour to avoid duplicate logic
Object.Destroy(existingOpponent);
}
// add MonsterCoreDrop component and configure son prefab (si disponible dans la Database)
MonsterCoreDrop mc = spawnedInstance.AddComponent<MonsterCoreDrop>();
mc.Init();
// essaye de récupérer le prefab "MonsterCore" dans la database (adapter le nom si nécessaire)
//GameObject corePrefab = null;
//try
//{
// corePrefab = Database.Instance.Prefabs["MonsterCore"];
//}
//catch { corePrefab = null; }
//if (corePrefab != null)
//{
// mc.SetCorePrefab(corePrefab);
//}
}
}
_copyGroupSpawn[_currentGroupIndex][groupIndex]--;
usedRows.Add(currentRow);
spawnCount++;
}
if (_copyGroupSpawn[_currentGroupIndex][groupIndex] == 0) //If current ennemy has reached count of 0
{
break;

View File

@ -4,10 +4,34 @@ using UnityEngine;
public class MonsterCoreDrop : Opponent
{
private GameObject mosnterCorePrefab;
private GameObject _monsterCorePrefab;
public void Init()
{
base.Start();
// Si le prefab n'est pas fixé via l'inspector, tenter de le charger depuis Resources/"Food"
if (_monsterCorePrefab == null)
{
_monsterCorePrefab = Resources.Load<GameObject>("yieldFood");
if (_monsterCorePrefab == null)
{
Debug.LogWarning("MonsterCoreDrop: prefab 'yieldFood' introuvable dans le dossier Resources. Assignez-le dans l'inspector ou placez-le dans Resources/yieldFood.");
}
}
}
public void SetCorePrefab(GameObject prefab)
{
_monsterCorePrefab = prefab;
}
public override void Death()
{
Instantiate(mosnterCorePrefab, transform.position, Quaternion.identity);
if (_monsterCorePrefab != null)
{
Instantiate(_monsterCorePrefab, transform.position, Quaternion.identity);
}
base.Death();
}
}

View File

@ -138,9 +138,9 @@ public class SpawnerTile : LevelTile
* Instantly spawns an enemy.
* Used for GroupSpawn
*/
public void TriggerSpawn(GameObject enemy)
public GameObject TriggerSpawn(GameObject enemy)
{
enemy.Create(Position, parent: LevelManager.Instance.LevelTransform);
return enemy.Create(Position, parent: LevelManager.Instance.LevelTransform);
}
#if UNITY_EDITOR