2using System.Collections.Generic;
3using Terraria.GameContent.Events;
14 internal static List<SpawnCondition> conditions =
new List<SpawnCondition>();
16 internal static void Reset() {
25 cond.Check(info, ref weight);
26 if (Math.Abs(weight) < 5E-6) {
39 internal Func<float> WeightFunc;
52 this.children =
new List<SpawnCondition>();
59 this.children =
new List<SpawnCondition>();
64 internal void Reset() {
72 internal void Check(NPCSpawnInfo info, ref
float remainingWeight) {
73 if (WeightFunc !=
null) {
79 float childWeight =
chance;
81 child.Check(info, ref childWeight);
82 if (Math.Abs(childWeight) < 5E-6) {
197 && !NPC.AnyNPCs(NPCID.BartenderUnconscious) && !info.water, 1f / 80f);
200 || WallID.Sets.Conversion.Sandstone[
GetTile(info).wall] || info.desertCave)
201 && WorldGen.checkUnderground(info.spawnTileX, info.spawnTileY));
204 Ocean =
new SpawnCondition((info) => info.water && (info.spawnTileX < 250 || info.spawnTileX > Main.maxTilesX - 250)
205 && Main.tileSand[info.spawnTileType] && info.spawnTileY < Main.rockLayer);
210 && (info.spawnTileX < 340 || info.spawnTileX > Main.maxTilesX - 340) && Main.tileSand[info.spawnTileType]
211 && info.spawnTileY < Main.worldSurface);
218 && info.spawnTileY > 50 && Main.dayTime, 2f / 3f);
223 && info.spawnTileY < Main.maxTilesY - 210, 1f / 20f);
227 && info.spawnTileY > 50 && Main.dayTime, 2f / 3f);
232 || info.spawnTileType == TileID.IceBlock);
235 || info.spawnTileType == TileID.HallowedGrass || info.spawnTileY > Main.worldSurface);
241 FrostMoon =
new SpawnCondition((info) => info.spawnTileY <= Main.worldSurface && !Main.dayTime && Main.snowMoon);
243 && !Main.dayTime && Main.pumpkinMoon);
248 && info.spawnTileY <= Main.worldSurface, 2f / 3f);
250 && Main.hardMode && info.spawnTileY >= Main.worldSurface, 2f / 3f);
255 && !Main.dayTime, 0.05f);
256 Wraith.WeightFunc = () => {
257 float inverseChance = 0.95f;
258 if (Main.moonPhase == 4) {
259 inverseChance *= 0.8f;
261 return 1f - inverseChance;
264 && info.spawnTileY <= Main.worldSurface && !Main.dayTime, 0.1f);
267 && info.spawnTileY > Main.worldSurface, 1f / 60f);
269 && info.spawnTileY < Main.maxTilesY - 210 && !info.player.ZoneSnow && !info.player.ZoneCrimson
270 && !info.player.ZoneCorrupt && !info.player.ZoneJungle && !info.player.ZoneHoly, 1f / 8f);
272 && info.spawnTileY < Main.maxTilesY - 210 && !info.player.ZoneSnow && !info.player.ZoneCrimson
273 && !info.player.ZoneCorrupt && !info.player.ZoneJungle && !info.player.ZoneHoly, 1f / 13f);
275 && info.spawnTileY < (Main.rockLayer + Main.maxTilesY) / 2 && !info.player.ZoneSnow
276 && !info.player.ZoneCrimson && !info.player.ZoneCorrupt && !info.player.ZoneHoly, 1f / 13f);
281 && info.spawnTileY > (Main.worldSurface + Main.rockLayer) / 2);
284 && TileID.Sets.Conversion.Sand[info.spawnTileType]
285 && NPC.Spawning_SandstoneCheck(info.spawnTileX, info.spawnTileY));
286 Mummy =
new SpawnCondition((info) => Main.hardMode && info.spawnTileType == TileID.Sand, 1f / 3f);
288 || info.spawnTileType == TileID.Crimsand), 0.5f);
291 && (info.spawnTileType == TileID.Pearlsand || info.spawnTileType == TileID.Pearlstone
292 || info.spawnTileType == TileID.HallowedGrass || info.spawnTileType == TileID.HallowedIce));
294 && info.spawnTileY >= Main.rockLayer && (info.spawnTileType == TileID.Pearlsand
295 || info.spawnTileType == TileID.Pearlstone || info.spawnTileType == TileID.HallowedGrass
296 || info.spawnTileType == TileID.HallowedIce), 0.02f);
297 Crimson =
new SpawnCondition((info) => (info.spawnTileType == TileID.Crimtane && info.player.ZoneCrimson)
298 || info.spawnTileType == TileID.FleshGrass || info.spawnTileType == TileID.FleshIce
299 || info.spawnTileType == TileID.Crimstone || info.spawnTileType == TileID.Crimsand);
301 || info.spawnTileType == TileID.CorruptGrass || info.spawnTileType == TileID.Ebonstone
302 || info.spawnTileType == TileID.Ebonsand || info.spawnTileType == TileID.CorruptIce);
305 && Main.cloudAlpha > 0f && !NPC.AnyNPCs(NPCID.IceGolem), 0.05f);
307 && Main.cloudAlpha > 0f && !NPC.AnyNPCs(NPCID.RainbowSlime), 0.05f);
309 && Main.cloudAlpha > 0f && NPC.CountNPCS(NPCID.AngryNimbus) < 2, 0.1f);
311 && NPC.downedGolemBoss && !NPC.AnyNPCs(NPCID.MartianProbe), 1f / 400f);
312 MartianProbe.WeightFunc = () => {
313 float inverseChance = 399f / 400f;
314 if (!NPC.downedMartians) {
315 inverseChance *= 0.99f;
317 return 1f - inverseChance;
321 && (
GetTile(info).type == TileID.SnowBlock ||
GetTile(info).type == TileID.IceBlock), 1f / 15f);
323 && (
GetTile(info).type == TileID.Grass ||
GetTile(info).type == TileID.HallowedGrass), 1f / 15f);
325 &&
GetTile(info).type == TileID.Sand, 1f / 15f);
327 && (
GetTile(info).type == TileID.Grass ||
GetTile(info).type == TileID.HallowedGrass), 0.25f);
329 && (
GetTile(info).type == TileID.Grass ||
GetTile(info).type == TileID.HallowedGrass
330 ||
GetTile(info).type == TileID.SnowBlock), 1f / 15f);
332 && !NPC.AnyNPCs(NPCID.KingSlime), 1f / 300f);
334 && !info.water, 0.2f);
336 GoblinScout.WeightFunc = () => {
337 float inverseChance = 14f / 15f;
338 if (!NPC.downedGoblins && WorldGen.shadowOrbSmashed) {
339 return inverseChance *= (6f / 7f);
341 return 1f - inverseChance;
347 ||
GetTile(info).type == TileID.HallowedGrass, 0.1f);
348 OverworldFirefly.WeightFunc = () => 1f / (
float)NPC.fireFlyChance;
365 && !WorldGen.SolidTile(info.
spawnTileX, k + 1) && !WorldGen.SolidTile(info.
spawnTileX, k + 2)) {
373 return (
float)Math.Abs(info.
spawnTileX - Main.maxTilesX / 2) / (float)(Main.maxTilesX / 2) > 0.33f
378 return Math.Abs(info.
spawnTileX - Main.spawnTileX) < Main.maxTilesX / 3;
382 return Math.Abs(info.
spawnTileX - Main.spawnTileX) > Main.maxTilesX / 3;
This server as a central class to help modders spawn their npcs. It's basically the vanilla spawn cod...
static readonly SpawnCondition CorruptWorm
static readonly SpawnCondition Wraith
static readonly SpawnCondition HardmodeJungle
static readonly SpawnCondition FrogCritter
static readonly SpawnCondition LightMummy
static readonly SpawnCondition SolarTower
static readonly SpawnCondition SpiderCave
static readonly SpawnCondition OverworldMimic
static readonly SpawnCondition DungeonNormal
static readonly SpawnCondition UndergroundMimic
static readonly SpawnCondition OverworldUnderwaterCritter
static readonly SpawnCondition OverworldDayRain
List< SpawnCondition > children
static readonly SpawnCondition StardustTower
static readonly SpawnCondition OverworldDayGrassCritter
static readonly SpawnCondition HardmodeJungleWater
static bool InnerThird(NPCSpawnInfo info)
static readonly SpawnCondition UndergroundJungle
static readonly SpawnCondition OverworldWaterCritter
static readonly SpawnCondition Bartender
static readonly SpawnCondition DungeonGuardian
static readonly SpawnCondition OverworldNightMonster
static readonly SpawnCondition SolarEclipse
static readonly SpawnCondition HardmodeMushroomWater
static readonly SpawnCondition DesertCave
static readonly SpawnCondition OverworldDayBirdCritter
static readonly SpawnCondition TownSnowCritter
static readonly SpawnCondition SurfaceJungle
static readonly SpawnCondition Dungeon
static readonly SpawnCondition CorruptWaterCritter
static readonly SpawnCondition VortexTower
static readonly SpawnCondition PumpkinMoon
static readonly SpawnCondition CaveJellyfish
static readonly SpawnCondition OverworldDaySandCritter
static readonly SpawnCondition Underground
static readonly SpawnCondition OceanAngler
static readonly SpawnCondition OverworldMushroom
static readonly SpawnCondition MouseCritter
static readonly SpawnCondition OverworldHallow
static readonly SpawnCondition MartianMadness
static readonly SpawnCondition DoctorBones
static readonly SpawnCondition Underworld
static readonly SpawnCondition Meteor
static readonly SpawnCondition JungleTemple
static readonly SpawnCondition TownJungleCritter
static readonly SpawnCondition TownCritter
static readonly SpawnCondition GoblinArmy
static readonly SpawnCondition WaterCritter
static readonly SpawnCondition Cavern
static readonly SpawnCondition EnchantedSword
static readonly SpawnCondition OverworldDaySnowCritter
static Tile GetTile(NPCSpawnInfo info)
static bool OuterThird(NPCSpawnInfo info)
static readonly SpawnCondition TownDefaultWaterCritter
static readonly SpawnCondition SandstormEvent
static readonly SpawnCondition HoppinJack
static readonly SpawnCondition IceGolem
static readonly SpawnCondition OverworldMorningBirdCritter
static readonly SpawnCondition RainbowSlime
static readonly SpawnCondition GoblinScout
static readonly SpawnCondition OverworldDaySlime
static readonly SpawnCondition FrostMoon
static readonly SpawnCondition HardmodeCrimsonWater
static readonly SpawnCondition Corruption
static readonly SpawnCondition MartianProbe
static readonly SpawnCondition Overworld
static readonly SpawnCondition OverworldWaterSurfaceCritter
static readonly SpawnCondition TownOverworldWaterSurfaceCritter
static readonly SpawnCondition OceanMonster
static readonly SpawnCondition SnailCritter
static readonly SpawnCondition KingSlime
static readonly SpawnCondition OverworldDay
Func< NPCSpawnInfo, bool > condition
static readonly SpawnCondition Sky
static readonly SpawnCondition UndergroundMushroom
static readonly SpawnCondition TownWaterCritter
static readonly SpawnCondition OverworldNight
static readonly SpawnCondition Mummy
static readonly SpawnCondition DefaultWaterCritter
static readonly SpawnCondition DarkMummy
static readonly SpawnCondition NebulaTower
static readonly SpawnCondition TownGeneralCritter
static readonly SpawnCondition OverworldFirefly
static bool WaterSurface(NPCSpawnInfo info)
static readonly SpawnCondition WormCritter
static readonly SpawnCondition OldOnesArmy
static readonly SpawnCondition FrostLegion
static readonly SpawnCondition OverworldDayDesert
static readonly SpawnCondition BeachAngler
static readonly SpawnCondition CavePiranha
static readonly SpawnCondition Ocean
static readonly SpawnCondition TownOverworldWaterCritter
static readonly SpawnCondition BoundCaveNPC
static readonly SpawnCondition LacBeetle
static readonly SpawnCondition Pirates
static readonly SpawnCondition Invasion
static bool MartianProbeHelper(NPCSpawnInfo info)
static readonly SpawnCondition JungleWater
static readonly SpawnCondition Crimson
static readonly SpawnCondition AngryNimbus
static readonly SpawnCondition TownOverworldUnderwaterCritter
A struct that stores information regarding where an NPC is naturally spawning and the player it is sp...
bool safeRangeX
Whether or not the NPC is horizontally within the range near the player in which NPCs cannot spawn....
int spawnTileY
The y-coordinate of the tile the NPC will spawn above.
int spawnTileX
The x-coordinate of the tile the NPC will spawn above.