TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ ChooseSpawn()

static ? int Terraria.ModLoader.NPCLoader.ChooseSpawn ( NPCSpawnInfo spawnInfo)
inlinestatic

Definition at line 1289 of file NPCLoader.cs.

1290 {
1294 pool[0] = 1f;
1295 foreach (ModNPC npc in npcs)
1296 {
1297 float weight2 = npc.SpawnChance(spawnInfo);
1298 if (weight2 > 0f)
1299 {
1300 pool[npc.NPC.type] = weight2;
1301 }
1302 }
1304 for (int i = 0; i < readOnlySpan.Length; i++)
1305 {
1306 readOnlySpan[i].EditSpawnPool(pool, spawnInfo);
1307 }
1308 float totalWeight = 0f;
1309 foreach (int type2 in pool.Keys)
1310 {
1311 if (pool[type2] < 0f)
1312 {
1313 pool[type2] = 0f;
1314 }
1316 }
1317 float choice = (float)Main.rand.NextDouble() * totalWeight;
1318 foreach (int type in pool.Keys)
1319 {
1320 float weight = pool[type];
1321 if (choice < weight)
1322 {
1323 return type;
1324 }
1325 choice -= weight;
1326 }
1327 return null;
1328 }
static readonly IList< ModNPC > npcs
Definition NPCLoader.cs:101
static GlobalHookList< GlobalNPC > HookEditSpawnPool
Definition NPCLoader.cs:214
static void DoChecks(NPCSpawnInfo info)

References Terraria.ModLoader.Utilities.NPCSpawnHelper.DoChecks(), Terraria.ModLoader.NPCLoader.HookEditSpawnPool, Terraria.ModLoader.ModNPC.NPC, Terraria.ModLoader.NPCLoader.npcs, Terraria.Main.rand, Terraria.ModLoader.Utilities.NPCSpawnHelper.Reset(), Terraria.ModLoader.ModNPC.SpawnChance(), and Terraria.NPC.type.

Referenced by Terraria.NPC.SpawnNPC().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: