Esempio n. 1
0
    // Token: 0x06000310 RID: 784 RVA: 0x0001A289 File Offset: 0x00018489
    private IEnumerator Spawn()
    {
        int toSpawn = UnityEngine.Random.Range(this.m_minToSpawn, this.m_maxToSpawn);
        int num;

        for (int i = 0; i < toSpawn; i = num)
        {
            Vector3 vector;
            if (this.FindTarget(out vector))
            {
                Vector3 vector2 = this.m_spawnAtTarget ? vector : base.transform.position;
                Vector2 vector3 = UnityEngine.Random.insideUnitCircle * this.m_spawnRadius;
                Vector3 vector4 = vector2 + new Vector3(vector3.x, 0f, vector3.y);
                if (this.m_snapToTerrain)
                {
                    float solidHeight = ZoneSystem.instance.GetSolidHeight(vector4);
                    vector4.y = solidHeight;
                }
                vector4.y += this.m_spawnGroundOffset;
                if (Mathf.Abs(vector4.y - vector2.y) <= 100f)
                {
                    GameObject gameObject = this.m_spawnPrefab[UnityEngine.Random.Range(0, this.m_spawnPrefab.Length)];
                    if (this.m_maxSpawned <= 0 || SpawnSystem.GetNrOfInstances(gameObject) < this.m_maxSpawned)
                    {
                        GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(gameObject, vector4, Quaternion.Euler(0f, UnityEngine.Random.value * 3.1415927f * 2f, 0f));
                        Projectile component   = gameObject2.GetComponent <Projectile>();
                        if (component)
                        {
                            this.SetupProjectile(component, vector);
                        }
                        BaseAI component2 = gameObject2.GetComponent <BaseAI>();
                        if (component2 != null && this.m_alertSpawnedCreature)
                        {
                            component2.Alert();
                        }
                        this.m_spawnEffects.Create(vector4, Quaternion.identity, null, 1f);
                        if (this.m_spawnDelay > 0f)
                        {
                            yield return(new WaitForSeconds(this.m_spawnDelay));
                        }
                    }
                }
            }
            num = i + 1;
        }
        UnityEngine.Object.Destroy(base.gameObject);
        yield break;
    }
        private static void UpdateSpawners(SpawnSystem self, bool eventSpawners)
        {
            if (Instances.TryGetValue(self, out var goodSpawnSystem))
            {
                var activeSpawnersForBiome = goodSpawnSystem.Spawners.List.Where(spawner => spawner.Item.m_enabled && self.m_heightmap.HaveBiome(spawner.Item.m_biome)).ToList();
                var spawner = goodSpawnSystem.Spawners.GetRandomItem(activeSpawnersForBiome);

                if ((!string.IsNullOrEmpty(spawner.m_requiredGlobalKey) && !ZoneSystem.instance.GetGlobalKey(spawner.m_requiredGlobalKey)) ||
                    (spawner.m_requiredEnvironments.Count > 0 && !EnvMan.instance.IsEnvironment(spawner.m_requiredEnvironments)) ||
                    (!spawner.m_spawnAtDay && EnvMan.instance.IsDay()) ||
                    (!spawner.m_spawnAtNight && EnvMan.instance.IsNight()) ||
                    SpawnSystem.GetNrOfInstances(spawner.m_prefab, Vector3.zero, 0f, eventSpawners, false) >= spawner.m_maxSpawned)
                {
                    return;
                }

                if (self.FindBaseSpawnPoint(spawner, self.m_nearPlayers, out var vector, out var player) &&
                    (spawner.m_spawnDistance <= 0f || !SpawnSystem.HaveInstanceInRange(spawner.m_prefab, vector, spawner.m_spawnDistance)))
                {
                    var groupSize   = UnityEngine.Random.Range(spawner.m_groupSizeMin, spawner.m_groupSizeMax + 1);
                    var groupRadius = groupSize > 1 ? spawner.m_groupRadius : 0f;

                    var numberOfSpawnedMonsters = 0;
                    for (var i = 0; i < groupSize * 2; i++)
                    {
                        var insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                        var spawnPoint       = vector + new Vector3(insideUnitCircle.x, 0f, insideUnitCircle.y) * groupRadius;
                        if (self.IsSpawnPointGood(spawner, ref spawnPoint))
                        {
                            self.Spawn(spawner, spawnPoint + Vector3.up * spawner.m_groundOffset, eventSpawners);

                            numberOfSpawnedMonsters++;
                            if (numberOfSpawnedMonsters >= groupSize)
                            {
                                break;
                            }
                        }
                    }

                    Log.LogInfo($"Spawned {numberOfSpawnedMonsters} {spawner.m_prefab.name}");
                }
            }
            else
            {
                Log.LogWarning($"Failed to find a spawner list for : {self.name}");
            }
        }
Esempio n. 3
0
 // Token: 0x06000252 RID: 594 RVA: 0x00012D64 File Offset: 0x00010F64
 private void Procreate()
 {
     if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())
     {
         return;
     }
     if (!this.m_character.IsTamed())
     {
         return;
     }
     if (this.m_offspringPrefab == null)
     {
         string prefabName = ZNetView.GetPrefabName(this.m_offspring);
         this.m_offspringPrefab = ZNetScene.instance.GetPrefab(prefabName);
         int prefab = this.m_nview.GetZDO().GetPrefab();
         this.m_myPrefab = ZNetScene.instance.GetPrefab(prefab);
     }
     if (this.IsPregnant())
     {
         if (this.IsDue())
         {
             this.ResetPregnancy();
             GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.m_offspringPrefab, base.transform.position - base.transform.forward * this.m_spawnOffset, Quaternion.LookRotation(-base.transform.forward, Vector3.up));
             Character  component  = gameObject.GetComponent <Character>();
             if (component)
             {
                 component.SetTamed(this.m_character.IsTamed());
                 component.SetLevel(Mathf.Max(this.m_minOffspringLevel, this.m_character.GetLevel()));
             }
             this.m_birthEffects.Create(gameObject.transform.position, Quaternion.identity, null, 1f);
             return;
         }
     }
     else
     {
         if (UnityEngine.Random.value <= this.m_pregnancyChance)
         {
             return;
         }
         if (this.m_baseAI.IsAlerted())
         {
             return;
         }
         if (this.m_tameable.IsHungry())
         {
             return;
         }
         int nrOfInstances  = SpawnSystem.GetNrOfInstances(this.m_myPrefab, base.transform.position, this.m_totalCheckRange, false, false);
         int nrOfInstances2 = SpawnSystem.GetNrOfInstances(this.m_offspringPrefab, base.transform.position, this.m_totalCheckRange, false, false);
         if (nrOfInstances + nrOfInstances2 >= this.m_maxCreatures)
         {
             return;
         }
         if (SpawnSystem.GetNrOfInstances(this.m_myPrefab, base.transform.position, this.m_partnerCheckRange, false, true) < 2)
         {
             return;
         }
         this.m_loveEffects.Create(base.transform.position, Quaternion.identity, null, 1f);
         int num = this.m_nview.GetZDO().GetInt("lovePoints", 0);
         num++;
         this.m_nview.GetZDO().Set("lovePoints", num);
         if (num >= this.m_requiredLovePoints)
         {
             this.m_nview.GetZDO().Set("lovePoints", 0);
             this.MakePregnant();
         }
     }
 }
Esempio n. 4
0
    // Token: 0x06000BCF RID: 3023 RVA: 0x0005413C File Offset: 0x0005233C
    private void UpdateSpawnList(List <SpawnSystem.SpawnData> spawners, DateTime currentTime, bool eventSpawners)
    {
        string str = eventSpawners ? "e_" : "b_";
        int    num = 0;

        foreach (SpawnSystem.SpawnData spawnData in spawners)
        {
            num++;
            if (spawnData.m_enabled && this.m_heightmap.HaveBiome(spawnData.m_biome))
            {
                int      stableHashCode = (str + spawnData.m_prefab.name + num.ToString()).GetStableHashCode();
                DateTime d        = new DateTime(this.m_nview.GetZDO().GetLong(stableHashCode, 0L));
                TimeSpan timeSpan = currentTime - d;
                int      num2     = Mathf.Min(spawnData.m_maxSpawned, (int)(timeSpan.TotalSeconds / (double)spawnData.m_spawnInterval));
                if (num2 > 0)
                {
                    this.m_nview.GetZDO().Set(stableHashCode, currentTime.Ticks);
                }
                for (int i = 0; i < num2; i++)
                {
                    if (UnityEngine.Random.Range(0f, 100f) <= spawnData.m_spawnChance)
                    {
                        if ((!string.IsNullOrEmpty(spawnData.m_requiredGlobalKey) && !ZoneSystem.instance.GetGlobalKey(spawnData.m_requiredGlobalKey)) || (spawnData.m_requiredEnvironments.Count > 0 && !EnvMan.instance.IsEnvironment(spawnData.m_requiredEnvironments)) || (!spawnData.m_spawnAtDay && EnvMan.instance.IsDay()) || (!spawnData.m_spawnAtNight && EnvMan.instance.IsNight()) || SpawnSystem.GetNrOfInstances(spawnData.m_prefab, Vector3.zero, 0f, eventSpawners, false) >= spawnData.m_maxSpawned)
                        {
                            break;
                        }
                        Vector3 vector;
                        Player  player;
                        if (this.FindBaseSpawnPoint(spawnData, this.m_nearPlayers, out vector, out player) && (spawnData.m_spawnDistance <= 0f || !SpawnSystem.HaveInstanceInRange(spawnData.m_prefab, vector, spawnData.m_spawnDistance)))
                        {
                            int   num3 = UnityEngine.Random.Range(spawnData.m_groupSizeMin, spawnData.m_groupSizeMax + 1);
                            float d2   = (num3 > 1) ? spawnData.m_groupRadius : 0f;
                            int   num4 = 0;
                            for (int j = 0; j < num3 * 2; j++)
                            {
                                Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                                Vector3 a = vector + new Vector3(insideUnitCircle.x, 0f, insideUnitCircle.y) * d2;
                                if (this.IsSpawnPointGood(spawnData, ref a))
                                {
                                    this.Spawn(spawnData, a + Vector3.up * spawnData.m_groundOffset, eventSpawners);
                                    num4++;
                                    if (num4 >= num3)
                                    {
                                        break;
                                    }
                                }
                            }
                            ZLog.Log(string.Concat(new object[]
                            {
                                "Spawned ",
                                spawnData.m_prefab.name,
                                " x ",
                                num4
                            }));
                        }
                    }
                }
            }
        }
    }
Esempio n. 5
0
 // Token: 0x06000BD9 RID: 3033 RVA: 0x00054A4C File Offset: 0x00052C4C
 public static int GetNrOfInstances(GameObject prefab)
 {
     return(SpawnSystem.GetNrOfInstances(prefab, Vector3.zero, 0f, false, false));
 }