private void TrySpawnEntity() { if (IsSpawned) { return; } if (!HasSpaceToSpawn()) { nextSpawnTime = Time.time + Random.Range(respawnDelayMin, respawnDelayMax); return; } BaseEntity baseEntity = GameManager.server.CreateEntity(entityPrefab.resourcePath, base.transform.position, base.transform.rotation, false); if (baseEntity != null) { baseEntity.enableSaving = false; PoolableEx.AwakeFromInstantiate(baseEntity.gameObject); baseEntity.Spawn(); SpawnPointInstance spawnPointInstance = baseEntity.gameObject.AddComponent <SpawnPointInstance>(); spawnPointInstance.parentSpawnPointUser = this; spawnPointInstance.Notify(); } else { Debug.LogError("IndividualSpawner failed to spawn entity.", base.gameObject); } }
protected virtual void Spawn(int numToSpawn) { Vector3 vector3; Quaternion quaternion; numToSpawn = Mathf.Min(numToSpawn, this.maxPopulation - this.currentPopulation); for (int i = 0; i < numToSpawn; i++) { BaseSpawnPoint spawnPoint = this.GetSpawnPoint(out vector3, out quaternion); if (spawnPoint) { BaseEntity baseEntity = GameManager.server.CreateEntity(this.GetPrefab(), vector3, quaternion, false); if (baseEntity) { baseEntity.enableSaving = false; baseEntity.gameObject.AwakeFromInstantiate(); baseEntity.Spawn(); this.PostSpawnProcess(baseEntity, spawnPoint); SpawnPointInstance spawnPointInstance = baseEntity.gameObject.AddComponent <SpawnPointInstance>(); spawnPointInstance.parentSpawnGroup = this; spawnPointInstance.parentSpawnPoint = spawnPoint; spawnPointInstance.Notify(); } } } }
protected override void Spawn(int numToSpawn) { AiLocationSpawner.SquadSpawnerLocation location; Vector3 vector3; Quaternion quaternion; if (!ConVar.AI.npc_enable) { this.maxPopulation = 0; this.numToSpawnPerTickMax = 0; this.numToSpawnPerTickMin = 0; return; } if (numToSpawn == 0) { if (!this.IsMainSpawner) { this.maxPopulation = this.defaultMaxPopulation; this.numToSpawnPerTickMax = this.defaultNumToSpawnPerTickMax; this.numToSpawnPerTickMin = this.defaultNumToSpawnPerTickMin; numToSpawn = UnityEngine.Random.Range(this.numToSpawnPerTickMin, this.numToSpawnPerTickMax + 1); } else { location = this.Location; if (location != AiLocationSpawner.SquadSpawnerLocation.MilitaryTunnels) { this.maxPopulation = this.defaultMaxPopulation; this.numToSpawnPerTickMax = this.defaultNumToSpawnPerTickMax; this.numToSpawnPerTickMin = this.defaultNumToSpawnPerTickMin; numToSpawn = UnityEngine.Random.Range(this.numToSpawnPerTickMin, this.numToSpawnPerTickMax + 1); } else { this.maxPopulation = ConVar.AI.npc_max_population_military_tunnels; this.numToSpawnPerTickMax = ConVar.AI.npc_spawn_per_tick_max_military_tunnels; this.numToSpawnPerTickMin = ConVar.AI.npc_spawn_per_tick_min_military_tunnels; numToSpawn = UnityEngine.Random.Range(this.numToSpawnPerTickMin, this.numToSpawnPerTickMax + 1); } } } float npcJunkpileASpawnChance = this.chance; location = this.Location; if (location == AiLocationSpawner.SquadSpawnerLocation.JunkpileA) { npcJunkpileASpawnChance = ConVar.AI.npc_junkpile_a_spawn_chance; } else if (location == AiLocationSpawner.SquadSpawnerLocation.JunkpileG) { npcJunkpileASpawnChance = ConVar.AI.npc_junkpile_g_spawn_chance; } if (numToSpawn == 0 || UnityEngine.Random.@value > npcJunkpileASpawnChance || (this.Location == AiLocationSpawner.SquadSpawnerLocation.JunkpileA || this.Location == AiLocationSpawner.SquadSpawnerLocation.JunkpileG) && NPCPlayerApex.AllJunkpileNPCs.Count >= ConVar.AI.npc_max_junkpile_count) { return; } numToSpawn = Mathf.Min(numToSpawn, this.maxPopulation - base.currentPopulation); for (int i = 0; i < numToSpawn; i++) { BaseSpawnPoint spawnPoint = this.GetSpawnPoint(out vector3, out quaternion); if (spawnPoint) { BaseEntity baseEntity = GameManager.server.CreateEntity(base.GetPrefab(), vector3, quaternion, true); if (baseEntity) { if (this.Manager != null) { NPCPlayerApex manager = baseEntity as NPCPlayerApex; if (manager != null) { manager.AiContext.AiLocationManager = this.Manager; if (this.Junkpile != null) { this.Junkpile.AddNpc(manager); } } } baseEntity.Spawn(); SpawnPointInstance spawnPointInstance = baseEntity.gameObject.AddComponent <SpawnPointInstance>(); spawnPointInstance.parentSpawnGroup = this; spawnPointInstance.parentSpawnPoint = spawnPoint; spawnPointInstance.Notify(); } } } }