Exemplo n.º 1
0
        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}");
            }
        }