2 using System.Collections.Generic;
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;
44 internal IEnumerable<SpawnCondition> Children => children;
45 internal float BlockWeight => blockWeight;
47 public float Chance => chance;
48 public bool Active => active;
50 internal SpawnCondition(Func<NPCSpawnInfo, bool> condition,
float blockWeight = 1f) {
51 this.condition = condition;
52 this.children =
new List<SpawnCondition>();
53 this.blockWeight = blockWeight;
58 this.condition = condition;
59 this.children =
new List<SpawnCondition>();
60 this.blockWeight = blockWeight;
64 internal void Reset() {
72 internal void Check(
NPCSpawnInfo info, ref
float remainingWeight) {
73 if (WeightFunc != null) {
74 blockWeight = WeightFunc();
77 if (condition(info)) {
78 chance = remainingWeight * blockWeight;
79 float childWeight = chance;
81 child.Check(info, ref childWeight);
82 if (Math.Abs(childWeight) < 5E-6) {
86 remainingWeight -= chance;
192 GoblinArmy =
new SpawnCondition(Invasion, (info) => Main.invasionType == 1);
193 FrostLegion =
new SpawnCondition(Invasion, (info) => Main.invasionType == 2);
194 Pirates =
new SpawnCondition(Invasion, (info) => Main.invasionType == 3);
195 MartianMadness =
new SpawnCondition(Invasion, (info) => Main.invasionType == 4);
196 Bartender =
new SpawnCondition((info) => !NPC.savedBartender && DD2Event.ReadyToFindBartender
197 && !NPC.AnyNPCs(NPCID.BartenderUnconscious) && !info.
water, 1f / 80f);
199 DesertCave =
new SpawnCondition((info) => (WallID.Sets.Conversion.HardenedSand[GetTile(info).wall]
200 || WallID.Sets.Conversion.Sandstone[GetTile(info).wall] || info.
desertCave)
206 OceanAngler =
new SpawnCondition(Ocean, (info) => !NPC.savedAngler && !NPC.AnyNPCs(NPCID.SleepingAngler)
207 && WaterSurface(info));
209 BeachAngler =
new SpawnCondition((info) => !info.
water && !NPC.savedAngler && !NPC.AnyNPCs(NPCID.SleepingAngler)
218 && info.
spawnTileY > 50 && Main.dayTime, 2f / 3f);
219 OverworldWaterSurfaceCritter =
new SpawnCondition(OverworldWaterCritter, WaterSurface);
220 OverworldUnderwaterCritter =
new SpawnCondition(OverworldWaterCritter, (info) =>
true);
221 DefaultWaterCritter =
new SpawnCondition(WaterCritter, (info) =>
true);
223 && info.
spawnTileY < Main.maxTilesY - 210, 1f / 20f);
227 && info.
spawnTileY > 50 && Main.dayTime, 2f / 3f);
228 TownOverworldWaterSurfaceCritter =
new SpawnCondition(TownOverworldWaterCritter, WaterSurface);
229 TownOverworldUnderwaterCritter =
new SpawnCondition(TownOverworldWaterCritter, (info) =>
true);
230 TownDefaultWaterCritter =
new SpawnCondition(TownWaterCritter, (info) =>
true);
237 DungeonGuardian =
new SpawnCondition(Dungeon, (info) => !NPC.downedBoss3);
243 && !Main.dayTime && Main.pumpkinMoon);
248 && info.
spawnTileY <= Main.worldSurface, 2f / 3f);
250 && Main.hardMode && info.
spawnTileY >= Main.worldSurface, 2f / 3f);
253 OverworldMimic =
new SpawnCondition((info) => Main.hardMode && GetTile(info).wall == WallID.DirtUnsafe, 0.05f);
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;
263 HoppinJack =
new SpawnCondition((info) => Main.hardMode && Main.halloween
264 && info.
spawnTileY <= Main.worldSurface && !Main.dayTime, 0.1f);
267 && info.
spawnTileY > Main.worldSurface, 1f / 60f);
270 && !info.
player.ZoneCorrupt && !info.
player.ZoneJungle && !info.
player.ZoneHoly, 1f / 8f);
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);
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);
310 MartianProbe =
new SpawnCondition(Overworld, (info) => MartianProbeHelper(info) && Main.hardMode
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;
319 OverworldDay =
new SpawnCondition(Overworld, (info) => Main.dayTime);
320 OverworldDaySnowCritter =
new SpawnCondition(OverworldDay, (info) => InnerThird(info)
321 && (GetTile(info).type == TileID.SnowBlock || GetTile(info).type == TileID.IceBlock), 1f / 15f);
322 OverworldDayGrassCritter =
new SpawnCondition(OverworldDay, (info) => InnerThird(info)
323 && (GetTile(info).type == TileID.Grass || GetTile(info).type == TileID.HallowedGrass), 1f / 15f);
324 OverworldDaySandCritter =
new SpawnCondition(OverworldDay, (info) => InnerThird(info)
325 && GetTile(info).type == TileID.Sand, 1f / 15f);
326 OverworldMorningBirdCritter =
new SpawnCondition(OverworldDay, (info) => InnerThird(info) && Main.time < 18000.0
327 && (GetTile(info).type == TileID.Grass || GetTile(info).type == TileID.HallowedGrass), 0.25f);
328 OverworldDayBirdCritter =
new SpawnCondition(OverworldDay, (info) => InnerThird(info)
329 && (GetTile(info).type == TileID.Grass || GetTile(info).type == TileID.HallowedGrass
330 || GetTile(info).type == TileID.SnowBlock), 1f / 15f);
331 KingSlime =
new SpawnCondition(OverworldDay, (info) => OuterThird(info) && GetTile(info).type == TileID.Grass
332 && !NPC.AnyNPCs(NPCID.KingSlime), 1f / 300f);
333 OverworldDayDesert =
new SpawnCondition(OverworldDay, (info) => GetTile(info).type == TileID.Sand
334 && !info.
water, 0.2f);
335 GoblinScout =
new SpawnCondition(OverworldDay, (info) => OuterThird(info), 1f / 15f);
336 GoblinScout.WeightFunc = () => {
337 float inverseChance = 14f / 15f;
338 if (!NPC.downedGoblins && WorldGen.shadowOrbSmashed) {
339 return inverseChance *= (6f / 7f);
341 return 1f - inverseChance;
343 OverworldDayRain =
new SpawnCondition(OverworldDay, (info) => Main.raining, 2f / 3f);
344 OverworldDaySlime =
new SpawnCondition(OverworldDay, (info) =>
true);
346 OverworldFirefly =
new SpawnCondition(OverworldNight, (info) => GetTile(info).type == TileID.Grass
347 || GetTile(info).type == TileID.HallowedGrass, 0.1f);
348 OverworldFirefly.WeightFunc = () => 1f / (
float)NPC.fireFlyChance;
349 OverworldNightMonster =
new SpawnCondition(OverworldNight, (info) =>
true);
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;
bool lihzahrd
Whether or not the player is inside the jungle temple, where Lihzahrds spawn.
static readonly SpawnCondition Crimson
static readonly SpawnCondition IceGolem
int spawnTileX
The x-coordinate of the tile the NPC will spawn above.
static readonly SpawnCondition SandstormEvent
static bool MartianProbeHelper(NPCSpawnInfo info)
This server as a central class to help modders spawn their npcs. It's basically the vanilla spawn cod...
bool invasion
Whether or not there is an invasion going on and the player is near it.
static readonly SpawnCondition Overworld
static readonly SpawnCondition Dungeon
static readonly SpawnCondition KingSlime
static readonly SpawnCondition Wraith
static readonly SpawnCondition UndergroundMushroom
static readonly SpawnCondition TownCritter
static bool InnerThird(NPCSpawnInfo info)
int spawnTileY
The y-coordinate of the tile the NPC will spawn above.
static readonly SpawnCondition SurfaceJungle
static readonly SpawnCondition MartianProbe
Func< NPCSpawnInfo, bool > condition
static readonly SpawnCondition DefaultWaterCritter
static readonly SpawnCondition TownWaterCritter
bool spiderCave
Whether or not the player is in a spider cave or the NPC will spawn near one.
static readonly SpawnCondition Sky
static readonly SpawnCondition CaveJellyfish
static readonly SpawnCondition VortexTower
static readonly SpawnCondition OverworldDayRain
static readonly SpawnCondition DoctorBones
static readonly SpawnCondition JungleTemple
static readonly SpawnCondition SolarTower
A struct that stores information regarding where an NPC is naturally spawning and the player it is sp...
static readonly SpawnCondition Pirates
static readonly SpawnCondition MouseCritter
static readonly SpawnCondition LacBeetle
static readonly SpawnCondition OceanAngler
static readonly SpawnCondition Underground
List< SpawnCondition > children
static bool WaterSurface(NPCSpawnInfo info)
static readonly SpawnCondition PumpkinMoon
static readonly SpawnCondition OverworldMushroom
static readonly SpawnCondition GoblinArmy
static readonly SpawnCondition Corruption
static readonly SpawnCondition OverworldDaySlime
static readonly SpawnCondition OverworldNight
static readonly SpawnCondition Cavern
static readonly SpawnCondition TownGeneralCritter
static readonly SpawnCondition TownOverworldUnderwaterCritter
static readonly SpawnCondition UndergroundJungle
static readonly SpawnCondition AngryNimbus
bool water
Whether or not the tile the NPC will spawn in contains water.
static readonly SpawnCondition OverworldMimic
static readonly SpawnCondition OverworldNightMonster
static readonly SpawnCondition OverworldDayGrassCritter
static readonly SpawnCondition EnchantedSword
static Tile GetTile(NPCSpawnInfo info)
static readonly SpawnCondition TownOverworldWaterCritter
static readonly SpawnCondition OverworldWaterSurfaceCritter
static readonly SpawnCondition Ocean
static readonly SpawnCondition BeachAngler
static readonly SpawnCondition TownDefaultWaterCritter
Player player
The player that this NPC is spawning around. For convenience, here are the player zones...
static readonly SpawnCondition Mummy
static readonly SpawnCondition TownSnowCritter
static readonly SpawnCondition OverworldDaySandCritter
static readonly SpawnCondition FrostMoon
static readonly SpawnCondition CavePiranha
static readonly SpawnCondition NebulaTower
static readonly SpawnCondition DungeonGuardian
static readonly SpawnCondition HoppinJack
static readonly SpawnCondition WormCritter
static readonly SpawnCondition OverworldWaterCritter
static readonly SpawnCondition OverworldHallow
static readonly SpawnCondition SnailCritter
bool playerSafe
Whether or not the player is in front of a player-placed wall or in a large town. If this is true...
static readonly SpawnCondition OverworldMorningBirdCritter
static readonly SpawnCondition SolarEclipse
static readonly SpawnCondition BoundCaveNPC
static readonly SpawnCondition DarkMummy
static readonly SpawnCondition Bartender
bool safeRangeX
Whether or not the NPC is horizontally within the range near the player in which NPCs cannot spawn...
static readonly SpawnCondition WaterCritter
static readonly SpawnCondition JungleWater
static readonly SpawnCondition DungeonNormal
static readonly SpawnCondition SpiderCave
static readonly SpawnCondition UndergroundMimic
bool desertCave
Whether or not the player is in front of a desert wall or the NPC will spawn near one...
static readonly SpawnCondition Underworld
static bool OuterThird(NPCSpawnInfo info)
static readonly SpawnCondition OverworldDayDesert
static readonly SpawnCondition DesertCave
static readonly SpawnCondition LightMummy
static readonly SpawnCondition HardmodeMushroomWater
bool sky
Whether or not the player is in the sky biome, where harpies and wyverns spawn.
static readonly SpawnCondition RainbowSlime
static readonly SpawnCondition Meteor
static readonly SpawnCondition MartianMadness
static readonly SpawnCondition FrogCritter
static readonly SpawnCondition OverworldDay
static readonly SpawnCondition HardmodeJungle
static readonly SpawnCondition GoblinScout
static readonly SpawnCondition OverworldFirefly
static readonly SpawnCondition TownJungleCritter
static readonly SpawnCondition FrostLegion
static readonly SpawnCondition OverworldDayBirdCritter
static readonly SpawnCondition CorruptWorm
static readonly SpawnCondition OverworldDaySnowCritter
static readonly SpawnCondition CorruptWaterCritter
static readonly SpawnCondition OldOnesArmy
static readonly SpawnCondition StardustTower
static readonly SpawnCondition OverworldUnderwaterCritter
static readonly SpawnCondition Invasion
static readonly SpawnCondition HardmodeCrimsonWater
static readonly SpawnCondition OceanMonster
static readonly SpawnCondition TownOverworldWaterSurfaceCritter
bool playerInTown
Whether or not the player is in a town. This is used for spawning critters instead of monsters...
static readonly SpawnCondition HardmodeJungleWater