public void RemoveEnemySpawnProbability(WaveEnemy _wep) { float i_difference = _wep.probability; currentEnemies.Remove(_wep); float i_totalProba = 0; foreach (WaveEnemy wep in currentEnemies) { i_totalProba += wep.probability; } //Reduce or improve all the other probabilities (So it keep a maximum of 1) foreach (WaveEnemy wep in currentEnemies) { if (i_totalProba != 0) { float force = wep.probability / i_totalProba; wep.probability += force * i_difference; wep.probability = Mathf.Clamp(wep.probability, 0f, 1f); } else { wep.probability = 1; } } }
public void AddWaveEnemy(WaveEnemy waveEnemyToAdd) { if (!m_WaveEnemies.Contains(waveEnemyToAdd)) { m_WaveEnemies.Add(waveEnemyToAdd); } }
public WaveEnemy GetWaveEnemy() { WaveEnemy enemy = null; if (!spawnRandom) { int maxDiff = -1; // Get enemy with less spawns foreach (WaveEnemy e in enemies) { if (e.Count - e.counter > maxDiff) { maxDiff = e.Count - e.counter; enemy = e; } } } // Get random enemy if (spawnRandom || enemy == null) { int random = UnityEngine.Random.Range(0, 100); if (enemies != null && enemies.Length > 0) { enemy = enemies[random % enemies.Length]; } } if (enemy != null) { enemy.counter++; } return(enemy); }
private void SpawnAIEnemy(WaveEnemy enemy) { bool switched = exchange.arePlacesSwitched; if (switched) { // Player Room GameObject playerRoomEnemy = Instantiate(waveManager.enemy, new Vector3(0, 25, 0), Quaternion.identity); playerRoomEnemy.GetComponent <Enemy>().globals = switched ? AIGlobals.Instance : PlayerGlobals.Instance; playerRoomEnemy.GetComponent <Enemy>().maxHealth = enemy.health; playerRoomEnemy.GetComponent <Enemy>().damage = enemy.damage; playerRoomEnemy.GetComponent <Enemy>().level = enemy.level; PlayerGlobals.Instance.enemies.Add(playerRoomEnemy); waveManager.enemies.Add(playerRoomEnemy); } else { // AI Room GameObject aiRoomEnemy = Instantiate(waveManager.aiEnemy, new Vector3(20, 25, 0), Quaternion.identity); aiRoomEnemy.GetComponent <Enemy>().globals = switched ? PlayerGlobals.Instance : AIGlobals.Instance; aiRoomEnemy.GetComponent <Enemy>().maxHealth = enemy.health; aiRoomEnemy.GetComponent <Enemy>().damage = enemy.damage; aiRoomEnemy.GetComponent <Enemy>().level = enemy.level; AIGlobals.Instance.enemies.Add(aiRoomEnemy); waveManager.enemies.Add(aiRoomEnemy); } }
void CreateWavePool(Wave currentWave) { for (int i = 0; i < currentWave.enemies.Count; i++) { // für jeden Enemy in WaveDB WaveEnemy currentWaveEnemy = currentWave.enemies[i]; if (currentWaveEnemy != null) { Enemy currentEnemy = currentWaveEnemy.Enemy; if (currentEnemy != null) { if (currentWaveEnemy.Amount <= 0) { // überspringen Debug.Log(this.ToString() + " " + currentWaveEnemy.Enemy.Prefab.name + " wave Amount =" + currentWaveEnemy.Amount + ". dont need to create pool."); continue; } List <GameObject> currentEnemyPool = null; int initAmount = 0; if (objectsPool.TryGetValue(currentEnemy.Prefab, out currentEnemyPool)) { // bereits vorhanden, anzahl überprüfen und ggf. neue hinzufügen initAmount = currentWaveEnemy.Amount - currentEnemyPool.Count; } else { // noch nicht in pool db vorhanden initAmount = currentWaveEnemy.Amount; // liste erzeugen currentEnemyPool = new List <GameObject> (); // liste in dictionary eintragen objectsPool.Add(currentEnemy.Prefab, currentEnemyPool); } // erzeuge falls notwendig restliche GameObject instancen von Prefab, deaktivieren und in pool laden if (initAmount > 0) { for (int a = 0; a < initAmount; a++) { GameObject newPooledObject = Instantiate(currentEnemy.Prefab); newPooledObject.SetActive(false); currentEnemyPool.Add(newPooledObject); } } Debug.Log(this.ToString() + " " + initAmount + " " + currentWaveEnemy.Enemy.Prefab.name + " pooled."); } else { Debug.LogError("WaveEnemy " + currentWaveEnemy.ToString() + " has no Enemy set"); } } else { Debug.LogError("error in currentWave " + currentWave.waveName + " @ EnemyField " + i); } } }
public void RemoveWaveEnemy(WaveEnemy waveEnemyToRemove) { if (!m_WaveEnemies.Contains(waveEnemyToRemove)) return; else m_WaveEnemies.Remove(waveEnemyToRemove); if (m_WaveEnemies.Count == 0) SpawnWave(); // Go to next wave }
public void InstantiateEnemy(WaveEnemy _enemy) { if (_enemy.spawnIndexes.Count <= 0) { Debug.LogWarning("Can't spawn enemy: no spawn assigned"); return; } int i_chosenSpawnerIndex = Random.Range(0, _enemy.spawnIndexes.Count); i_chosenSpawnerIndex = _enemy.spawnIndexes[i_chosenSpawnerIndex]; GameObject i_spawner = spawnList[i_chosenSpawnerIndex].transform.gameObject; Spawner i_spawnerScript = i_spawner.GetComponent <Spawner>(); if (i_spawnerScript != null && !i_spawnerScript.IsFree()) { return; } //A custom spawner is assigned, it can be used to spawn enemy if (i_spawnerScript != null) { if (!i_spawnerScript.IsFree()) { return; } EnemyBehaviour spawnedEnemy = i_spawnerScript.SpawnEnemy(EnemyDatas.GetEnemyDatas().GetEnemyByID(_enemy.enemyType.name), true); RegisterEnemy(spawnedEnemy); } //No custom spawner found, it'll spawn the enemy instantly on the assigned position else { GameObject i_newEnemy = Instantiate(_enemy.enemyType.prefab).gameObject; EnemyBehaviour i_enemyBehaviour = i_newEnemy.GetComponent <EnemyBehaviour>(); if (i_enemyBehaviour == null) { Destroy(i_newEnemy); Debug.LogWarning("Wave can't instantiate enemy: invalid prefab"); return; } if (i_enemyBehaviour.GetNavMesh() != null) { i_enemyBehaviour.GetNavMesh().enabled = false; } i_newEnemy.transform.position = spawnList[i_chosenSpawnerIndex].transform.position; i_enemyBehaviour.GetNavMesh().enabled = true; RegisterEnemy(i_enemyBehaviour); } UpdateCurrentPowerLevel(); nextEnemyToSpawn = null; }
public void RemoveWaveEnemy(WaveEnemy waveEnemyToRemove) { if (!m_WaveEnemies.Contains(waveEnemyToRemove)) { return; } else { m_WaveEnemies.Remove(waveEnemyToRemove); } if (m_WaveEnemies.Count == 0) { SpawnWave(); // Go to next wave } }
void PopulateEnemyList(int maxPoints) { int pointsLeft = maxPoints; while (pointsLeft > 0) { WaveEnemy tempEnemy = GetRandomEnemy(pointsLeft); if (tempEnemy != null) { pointsLeft -= tempEnemy.pointCost; enemiesToSpawn.Enqueue(tempEnemy); } else { break; } } }
void SpawnEnemy(WaveEnemy waveEnemy) { Debug.Log("Spawning Enemy " + waveEnemy.enemy.name); Transform spawnTransform = waveEnemy.GetSpawn(CheckSpawnOverlap); if (spawnTransform == null) { Debug.LogWarning("Spawn transform is null. It may overlap with other physical gameobject"); return; //spawnTransform = _transform; } Transform enemy = Instantiate(waveEnemy.enemy, spawnTransform.position, spawnTransform.rotation) as Transform; if (SetEnemyRotationOnSpawn) { SetTargetOrientation(GetTarget(), enemy); } }
void AddEnemy(WaveData _wave, int _index) { if (enemyAvailable[_wave][_index] == null) { return; } WaveEnemy i_newWEP = new WaveEnemy(); i_newWEP.enemyType = enemyAvailable[_wave][_index]; if (_wave.currentEnemies.Count <= 0) { i_newWEP.probability = 1; } else { i_newWEP.probability = 0; } i_newWEP.spawnIndexes = new List <int>(); _wave.currentEnemies.Add(i_newWEP); UpdateAvailableEnemies(_wave); }
private void GenerateWave(int waveNumber) { int minEnemies = waveNumber, maxEnemies = waveNumber + waveNumber / 2; int enemiesCount = (int)Random.Range(minEnemies, maxEnemies); List <WaveEnemy> enemies = new List <WaveEnemy>(); for (int i = 0; i < enemiesCount; i++) { WaveEnemy enemyType = new WaveEnemy { health = 100f + (waveNumber > 10 ? waveNumber * 0.75f : waveNumber * 0.35f), damage = 0.023f + (waveNumber > 5 ? waveNumber * 0.045f : waveNumber * 0.01f), color = new Color(waveNumber * .35f, waveNumber * .75f, waveNumber * .4f), level = Mathf.FloorToInt(waveNumber / 1.5f) }; enemies.Add(enemyType); } wave = gameObject.AddComponent <Wave>(); wave.enemies = enemies.ToArray(); wave.waveManager = this; }
//TODO: Fix enemyScript.SetTarget(tempTarget); void SpawnEnemy(WaveEnemy waveEnemy) { Debug.Log("Spawning Enemy " + waveEnemy.enemy.name); Transform spawnTransform; spawnTransform = waveEnemy.GetRandomSpawn(); if (spawnTransform == null) { spawnTransform = _transform; } Transform enemy = Instantiate(waveEnemy.enemy, spawnTransform.position, spawnTransform.rotation) as Transform; if (SetEnemyRotation) { /// Calculating rotation; GameObject obj = GameManager.Instance.GetPlayer(spawnTransform.position); float targetOrientation = 0; if (obj) { Vector3 direction = obj.transform.position - spawnTransform.position; targetOrientation = Mathf.Atan2(direction.y, direction.x); targetOrientation *= Mathf.Rad2Deg; AI.Agent2D agent = enemy.GetComponent <AI.Agent2D>(); if (agent) { agent.rotation = targetOrientation; } else { enemy.transform.eulerAngles = new Vector3(0, 0, targetOrientation); } } } }
private void Update() { if (arenaFinished) { return; } if (waveStarted) { if (nextEnemyToSpawn == null) { nextEnemyToSpawn = GetRandomEnemy(); } else { if (nextEnemyToSpawn.enemyType.prefab.GetComponent <EnemyBehaviour>().powerLevel + currentPowerLevel <= currentMaxPowerLevel) { InstantiateEnemy(nextEnemyToSpawn); } } } else { if (currentWaveIndex >= 0) { if (currentPowerLevel <= 0) { EndWave(); delayBeforeNextWave -= Time.deltaTime; if (delayBeforeNextWave <= 0) { StartNextWave(); } } } } }