Esempio n. 1
0
 /// <summary>
 /// Start the next wave in the list.
 /// </summary>
 private void AdvanceWave()
 {
     _currentWaveIndex++;
     if (_currentWaveIndex < waves.Count)
     {
         _currentWave             = waves[_currentWaveIndex];
         _currentWave.enemyTarget = encounterTarget;
         _currentWave.BeginWave();
     }
     else
     {
         return;
     }
 }
Esempio n. 2
0
    public void StartEncounter()
    {
        _currentWaveIndex = 0;
        OnEncounterStart.Invoke();
        _currentWave = waves[_currentWaveIndex];

        _allWavesComplete = false;

        if (encounterTarget == null)
        {
            Debug.LogWarning($"No Target for encounter {gameObject.name}. Assigning its own transform for now");
            encounterTarget = transform;
        }

        _currentWave.enemyTarget = encounterTarget;
        //yield return new WaitForSeconds(timeFromStartToFirstWave);
        _currentWave.BeginWave();
        ongoing = true;
    }
Esempio n. 3
0
    /// <summary>
    /// Spawn the first object in its queue and if there are more left, keep
    /// itself open too keep spawning
    /// </summary>
    /// <param name="callerWave">The wave commanding the spawns</param>
    /// <param name="minDistanceToNext">The minimum distance a newly spawned
    /// enemy must have to this spawner until it can spawn the next monster in
    /// the queue.</param>
    /// <returns></returns>
    public GameObject StartSpawning(CombatWave callerWave, float minDistanceToNext)
    {
        if (spawnQueue.Count == 0)
        {
            return(null);
        }

        _callerWave        = callerWave;
        _minDistanceToNext = minDistanceToNext;

        _lastSpawned = Instantiate(spawnQueue.Peek(), transform.position, transform.rotation);
        spawnQueue.Dequeue();

        TargetHolder target = _lastSpawned.GetComponent <TargetHolder>();

        if (target != null)
        {
            target.Target = _callerWave.enemyTarget;
        }
        else
        {
            Debug.LogWarning($"Enemy from {_lastSpawned.name} doesn't have a TargetHolder Component");
        }

        if (_lastSpawned.GetComponent <WaypointMovement>())
        {
            GetComponent <Waypoint>().ToggleOccupation();
            _lastSpawned.GetComponent <WaypointMovement>().SetCurrentWaypoint(GetComponent <Waypoint>());
        }

        if (spawnQueue.Count > 0)
        {
            _openForSpawning = true;
        }

        return(_lastSpawned);
    }
    /// <summary>
    /// Tell the spawners of a type to queue in the prefabs to instantiate, and
    /// then spawn them.
    /// </summary>
    /// <param name="enemy">The enemy Holder with the prefab to spawn</param>
    /// <param name="amount">How many enemies?</param>
    /// <param name="delay">Wait some seconds until telling each spawner to
    /// start</param>
    /// <param name="callerWave"> The combat wave that is sending the enemies
    /// </param>
    /// <returns>The objects spawned by all the spawners of this type.</returns>
    public Stack <GameObject> PopulateType(EnemyHolder enemy, int amount, float delay, CombatWave callerWave)
    {
        EnemyTypes         enemyType = enemy.enemyType;
        Stack <GameObject> spawned   = new Stack <GameObject>();

        CombatSpawner[] sp = spawnerGroups[(int)enemyType].ToArray();
        if (sp.Length == 0)
        {
            Debug.Log($"No spawners of type {enemyType}");
            return(null);
        }

        int enqueued = 0;

        // Tell each spawner how many enemies it needs to spawn
        while (enqueued < amount)
        {
            for (int i = 0; i < sp.Length; i++)
            {
                sp[i].spawnQueue.Enqueue(enemy.enemyPrefab);
                enqueued++;
                if (enqueued >= amount)
                {
                    break;
                }
            }
        }

        // Start the spawning process, making each spawner go down their queue.
        foreach (CombatSpawner cs in sp)
        {
            /* float startTime = Time.unscaledTime;
             * float time_delta = 0;
             * do
             * {
             *   time_delta = Time.unscaledTime - startTime;
             *
             * }while(time_delta < delay);*/

            spawned.Push(cs.StartSpawning(callerWave, enemy.distanceToAllowOtherToSpawn));
        }
        return(spawned);
    }