Exemplo n.º 1
0
        /// <summary>
        /// This function spawns spawnables of the spawnertype.
        /// </summary>
        /// <returns>waiting time until this routine starts again</returns>
        public IEnumerator Spawn()
        {
            switch (SpawnerType)
            {
            case Type.MOB:
                while (CurrentUnit < _totalUnits && _activated)
                {
                    while (((Mob)Pool[CurrentUnit]).IsDead() && CurrentUnit + 1 < Pool.Count)
                    {
                        CurrentUnit++;
                    }

                    int remaining = _totalUnits - CurrentUnit;
                    for (int i = 0; i < Math.Min(WaveSize, remaining); i++)
                    {
                        Mob currentMob = (Mob)Pool[CurrentUnit];

                        // Spawn them on a random position around the spawner.
                        currentMob.Spawn(NewPosition());

                        // Give the mob a new ID
                        currentMob.PlayerNo = GameManager.GetInstance().NextMobId++;

                        // Activate it
                        currentMob.gameObject.SetActive(true);

                        CurrentUnit++;

                        // Waiting for next spawning
                    }

                    // original version
                    // yield return new WaitForSeconds(SpawnRate);
                    // -----------------
                    for (Countdown = (int)SpawnRate; Countdown >= 0; Countdown--)
                    {
                        yield return(new WaitForSeconds(1));
                    }
                }

                break;

            case Type.MERC:
                while (CurrentUnit < Pool.Count)
                {
                    yield return(new WaitForSeconds(SpawnRate));

                    Mercenary            currentMerc = (Mercenary)Pool[CurrentUnit];
                    List <MercenaryCage> mercList    = new List <MercenaryCage>();
                    Vector3 spawnPosition            = new Vector3();
                    bool    loopBool = true;
                    while (loopBool)
                    {
                        loopBool = false;
                        mercList.Clear();
                        spawnPosition = NewPosition();
                        Collider[] hitColliders = Physics.OverlapSphere(new Vector3(spawnPosition.x, 0, spawnPosition.z), 7);
                        foreach (Collider hitCollider in hitColliders)
                        {
                            MercenaryCage mercCase = hitCollider.GetComponent <MercenaryCage>();
                            if (mercCase != null)
                            {
                                loopBool = true;
                                Debug.Log("Recalculating");
                            }

                            if (hitCollider.GetComponent <Character>() != null)
                            {
                                loopBool = true;
                                Debug.Log("Recalculating");
                            }
                        }
                    }

                    // Spawn them on a random position around the spawner.
                    currentMerc.Spawn(spawnPosition);

                    // Give it a new ID.
                    currentMerc.PlayerNo = GameManager.GetInstance().NextMercenaryId++;

                    // Activate them.
                    currentMerc.gameObject.SetActive(true);

                    CurrentUnit++;

                    // Waiting for next spawning
                }

                break;

            case Type.ITEM:
                while (_activated && Pool.Count > 0)
                {
                    yield return(new WaitForSeconds(SpawnRate));

                    if (_gameManager.CurrentSection != null)
                    {
                        Item item = (Item)Pool[UnityEngine.Random.Range(0, Pool.Count)].Clone();
                        _gameManager.CurrentSection.AddItem(item);
                        item.Spawn(ItemSpawnPoint());
                    }
                }

                break;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds Mercenary to Mercenary-Spawnpool
 /// </summary>
 /// <param name="merc">The new Mercenary</param>
 public void AddMercenary(Mercenary merc)
 {
     _mercPool.Add(merc);
 }