diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index eda47898f4..443433a04f 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -4846,10 +4846,9 @@ namespace CalamityMod.NPCs if (Main.netMode != NetmodeID.MultiplayerClient) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[j]; - if (nPC.active && !nPC.buffImmune[BuffType()] && npc.Distance(nPC.Center) < 100f && !nPC.dontTakeDamage && nPC.lifeMax > 5 && !nPC.friendly && !nPC.townNPC) + if (!nPC.buffImmune[BuffType()] && npc.Distance(nPC.Center) < 100f && !nPC.dontTakeDamage && nPC.lifeMax > 5 && !nPC.friendly && !nPC.townNPC) nPC.AddBuff(BuffType(), 300); } } diff --git a/NPCs/StormWeaver/StormWeaverHead.cs b/NPCs/StormWeaver/StormWeaverHead.cs index 14a4949b6a..5b16e9aea5 100644 --- a/NPCs/StormWeaver/StormWeaverHead.cs +++ b/NPCs/StormWeaver/StormWeaverHead.cs @@ -292,13 +292,13 @@ namespace CalamityMod.NPCs.StormWeaver if ((double)NPC.position.Y < Main.topWorld + 16f) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].active && (Main.npc[j].type == ModContent.NPCType() - || Main.npc[j].type == ModContent.NPCType() - || Main.npc[j].type == ModContent.NPCType())) + if ((n.type == ModContent.NPCType() + || n.type == ModContent.NPCType() + || n.type == ModContent.NPCType())) { - Main.npc[j].active = false; + n.active = false; } } } @@ -306,13 +306,13 @@ namespace CalamityMod.NPCs.StormWeaver if (Vector2.Distance(Main.player[NPC.target].Center, NPC.Center) > 10000f && NPC.life > 0) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].type == ModContent.NPCType() - || Main.npc[j].type == ModContent.NPCType() - || Main.npc[j].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType() + || n.type == ModContent.NPCType() + || n.type == ModContent.NPCType()) { - Main.npc[j].active = false; + n.active = false; } } } diff --git a/NPCs/VanillaNPCOverrides/Bosses/CultistAI.cs b/NPCs/VanillaNPCOverrides/Bosses/CultistAI.cs index 582442d7ef..49f4d90ce7 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/CultistAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/CultistAI.cs @@ -164,13 +164,13 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if (Main.netMode != NetmodeID.MultiplayerClient) NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, npc.whoAmI, -1f, 0f, 0f, 0, 0, 0); - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].active && Main.npc[j].type == NPCID.CultistBossClone && Main.npc[j].ai[3] == npc.whoAmI) + if (n.type == NPCID.CultistBossClone && n.ai[3] == npc.whoAmI) { - Main.npc[j].life = 0; - Main.npc[j].HitEffect(0, 10.0); - Main.npc[j].active = false; + n.life = 0; + n.HitEffect(0, 10.0); + n.active = false; if (Main.netMode != NetmodeID.MultiplayerClient) NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, npc.whoAmI, -1f, 0f, 0f, 0, 0, 0); @@ -568,10 +568,10 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses if ((npc.ai[1] == 20f & isCultist) && Main.netMode != NetmodeID.MultiplayerClient) { List list5 = new List(); - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].active && Main.npc[j].type == NPCID.CultistBossClone && Main.npc[j].ai[3] == npc.whoAmI) - list5.Add(j); + if (n.type == NPCID.CultistBossClone && n.ai[3] == npc.whoAmI) + list5.Add(n.whoAmI); } foreach (int current5 in list5) @@ -825,7 +825,7 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses foreach (NPC n in Main.ActiveNPCs) { if (n.type == NPCID.CultistBossClone && n.ai[3] == npc.whoAmI) - list7.Add(i); + list7.Add(n.whoAmI); } foreach (int current6 in list7) diff --git a/NPCs/VanillaNPCOverrides/Bosses/MoonLordAI.cs b/NPCs/VanillaNPCOverrides/Bosses/MoonLordAI.cs index 3bf3234916..04cdd9132e 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/MoonLordAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/MoonLordAI.cs @@ -1726,24 +1726,21 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses // Fly towards Moon Lord Head and stay away from other True Eyes float freeEyeAccel = 0.5f; - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].active) + if (n.whoAmI != npc.whoAmI && n.type == npc.type) { - if (j != npc.whoAmI && Main.npc[j].type == npc.type) + if (Vector2.Distance(npc.Center, n.Center) < 150f) { - if (Vector2.Distance(npc.Center, Main.npc[j].Center) < 150f) - { - if (npc.position.X < Main.npc[j].position.X) - npc.velocity.X = npc.velocity.X - freeEyeAccel; - else - npc.velocity.X = npc.velocity.X + freeEyeAccel; - - if (npc.position.Y < Main.npc[j].position.Y) - npc.velocity.Y = npc.velocity.Y - freeEyeAccel; - else - npc.velocity.Y = npc.velocity.Y + freeEyeAccel; - } + if (npc.position.X < n.position.X) + npc.velocity.X = npc.velocity.X - freeEyeAccel; + else + npc.velocity.X = npc.velocity.X + freeEyeAccel; + + if (npc.position.Y < n.position.Y) + npc.velocity.Y = npc.velocity.Y - freeEyeAccel; + else + npc.velocity.Y = npc.velocity.Y + freeEyeAccel; } } } diff --git a/NPCs/VanillaNPCOverrides/Bosses/WallOfFleshAI.cs b/NPCs/VanillaNPCOverrides/Bosses/WallOfFleshAI.cs index a904b3cf91..6cc4b85821 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/WallOfFleshAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/WallOfFleshAI.cs @@ -402,11 +402,11 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { int hungryAmt = 0; float[] array = new float[10]; - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (hungryAmt < 10 && Main.npc[j].active && Main.npc[j].type == NPCID.TheHungry) + if (hungryAmt < 10 && n.type == NPCID.TheHungry) { - array[hungryAmt] = Main.npc[j].ai[0]; + array[hungryAmt] = n.ai[0]; hungryAmt++; } } diff --git a/Projectiles/Melee/AmidiasWhirlpool.cs b/Projectiles/Melee/AmidiasWhirlpool.cs index 1d14113510..2fd27aa019 100644 --- a/Projectiles/Melee/AmidiasWhirlpool.cs +++ b/Projectiles/Melee/AmidiasWhirlpool.cs @@ -68,7 +68,6 @@ namespace CalamityMod.Projectiles.Melee } else if (homeTracker == 1) { - int inc; Projectile.rotation -= 0.104719758f; Vector2 projCenter = Projectile.Center; float homingRange = 150f; @@ -76,21 +75,20 @@ namespace CalamityMod.Projectiles.Melee int npcTracker = 0; if (Projectile.ai[1] == 0f) { - for (int j = 0; j < Main.maxNPCs; j = inc + 1) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - Vector2 npcCenter = Main.npc[j].Center; - if (Projectile.Distance(npcCenter) < homingRange && Collision.CanHit(new Vector2(Projectile.position.X + (float)(Projectile.width / 2), Projectile.position.Y + (float)(Projectile.height / 2)), 1, 1, Main.npc[j].position, Main.npc[j].width, Main.npc[j].height)) + Vector2 npcCenter = n.Center; + if (Projectile.Distance(npcCenter) < homingRange && Collision.CanHit(new Vector2(Projectile.position.X + (float)(Projectile.width / 2), Projectile.position.Y + (float)(Projectile.height / 2)), 1, 1, n.position, n.width, n.height)) { homingRange = Projectile.Distance(npcCenter); projCenter = npcCenter; isHoming = true; - npcTracker = j; + npcTracker = n.whoAmI; break; } } - inc = j; } if (isHoming) { diff --git a/Projectiles/Melee/MourningSkull.cs b/Projectiles/Melee/MourningSkull.cs index 6f056934c1..308824f444 100644 --- a/Projectiles/Melee/MourningSkull.cs +++ b/Projectiles/Melee/MourningSkull.cs @@ -74,21 +74,19 @@ namespace CalamityMod.Projectiles.Melee else { float homingRange = 1000f; - int inc; - for (int j = 0; j < Main.maxNPCs; j = inc + 1) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float targetX = Main.npc[j].position.X + (float)(Main.npc[j].width / 2); - float targetY = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2); + float targetX = n.position.X + (float)(n.width / 2); + float targetY = n.position.Y + (float)(n.height / 2); float targetDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - targetX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - targetY); - if (targetDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[j].position, Main.npc[j].width, Main.npc[j].height)) + if (targetDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height)) { homingRange = targetDist; - Projectile.ai[0] = (float)j; + Projectile.ai[0] = (float)n.whoAmI; } } - inc = j; } } diff --git a/Projectiles/Pets/LadShark.cs b/Projectiles/Pets/LadShark.cs index 0c086d5ec6..5549bba071 100644 --- a/Projectiles/Pets/LadShark.cs +++ b/Projectiles/Pets/LadShark.cs @@ -69,10 +69,9 @@ namespace CalamityMod.Projectiles.Pets SoundEngine.PlaySound(SoundID.Zombie15, Projectile.position); //mouse squeak sound float radius = 240f; // 15 blocks - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[j]; - if (npc.active && !npc.dontTakeDamage && Vector2.Distance(Projectile.Center, npc.Center) <= radius) + if (!npc.dontTakeDamage && Vector2.Distance(Projectile.Center, npc.Center) <= radius) { if (npc.Calamity().ladHearts <= 0) npc.Calamity().ladHearts = CalamityUtils.SecondsToFrames(9f); diff --git a/Projectiles/Rogue/RadiantExplosion.cs b/Projectiles/Rogue/RadiantExplosion.cs index eb5a206d36..90dd1a23ba 100644 --- a/Projectiles/Rogue/RadiantExplosion.cs +++ b/Projectiles/Rogue/RadiantExplosion.cs @@ -60,30 +60,30 @@ namespace CalamityMod.Projectiles.Rogue { float projX = Projectile.Center.X; float projY = Projectile.Center.Y; - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[j].Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses) + if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses) { - float npcCenterX = Main.npc[j].position.X + (float)(Main.npc[j].width / 2); - float npcCenterY = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2); + float npcCenterX = n.position.X + (float)(n.width / 2); + float npcCenterY = n.position.Y + (float)(n.height / 2); float targetDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcCenterX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcCenterY); if (targetDist < 600f) { - if (Main.npc[j].position.X < projX) + if (n.position.X < projX) { - Main.npc[j].velocity.X += 0.25f; + n.velocity.X += 0.25f; } else { - Main.npc[j].velocity.X -= 0.25f; + n.velocity.X -= 0.25f; } - if (Main.npc[j].position.Y < projY) + if (n.position.Y < projY) { - Main.npc[j].velocity.Y += 0.25f; + n.velocity.Y += 0.25f; } else { - Main.npc[j].velocity.Y -= 0.25f; + n.velocity.Y -= 0.25f; } } } diff --git a/Projectiles/Rogue/ShatteredSunScorchedBlade.cs b/Projectiles/Rogue/ShatteredSunScorchedBlade.cs index 3f7f5fd760..3755f8669a 100644 --- a/Projectiles/Rogue/ShatteredSunScorchedBlade.cs +++ b/Projectiles/Rogue/ShatteredSunScorchedBlade.cs @@ -76,9 +76,8 @@ namespace CalamityMod.Projectiles.Rogue float targetDistStore; Vector2 homingPos = Projectile.position; bool isHoming = false; - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[j]; if (nPC2.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Projectiles/Summon/CosmicEnergySpiral.cs b/Projectiles/Summon/CosmicEnergySpiral.cs index 1de027a696..e1ba5e3f27 100644 --- a/Projectiles/Summon/CosmicEnergySpiral.cs +++ b/Projectiles/Summon/CosmicEnergySpiral.cs @@ -179,12 +179,12 @@ namespace CalamityMod.Projectiles.Summon float projY = Projectile.position.Y; float homeDistance = 1200f; bool isInRange = false; - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float npcX = Main.npc[j].position.X + (float)(Main.npc[j].width / 2); - float npcY = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2); + float npcX = n.position.X + (float)(n.width / 2); + float npcY = n.position.Y + (float)(n.height / 2); float npcDistance = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcY); if (npcDistance < homeDistance) { diff --git a/Projectiles/Summon/DaedalusCrystal.cs b/Projectiles/Summon/DaedalusCrystal.cs index 7e43adef7d..aac2c3f685 100644 --- a/Projectiles/Summon/DaedalusCrystal.cs +++ b/Projectiles/Summon/DaedalusCrystal.cs @@ -111,14 +111,14 @@ namespace CalamityMod.Projectiles.Summon } if (!isInRange) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float otherNPCX = Main.npc[j].position.X + (float)(Main.npc[j].width / 2); - float otherNPCY = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2); + float otherNPCX = n.position.X + (float)(n.width / 2); + float otherNPCY = n.position.Y + (float)(n.height / 2); float otherNPCDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - otherNPCX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - otherNPCY); - if (otherNPCDist < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[j].position, Main.npc[j].width, Main.npc[j].height)) + if (otherNPCDist < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height)) { attackRange = otherNPCDist; projX = otherNPCX; diff --git a/Projectiles/Summon/DankCreeperMinion.cs b/Projectiles/Summon/DankCreeperMinion.cs index 07c506c085..7029149f40 100644 --- a/Projectiles/Summon/DankCreeperMinion.cs +++ b/Projectiles/Summon/DankCreeperMinion.cs @@ -103,14 +103,14 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float otherNPCX = Main.npc[j].position.X + (float)(Main.npc[j].width / 2); - float otherNPCY = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2); + float otherNPCX = n.position.X + (float)(n.width / 2); + float otherNPCY = n.position.Y + (float)(n.height / 2); float otherNPCDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - otherNPCX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - otherNPCY); - if (otherNPCDist < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[j].position, Main.npc[j].width, Main.npc[j].height)) + if (otherNPCDist < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height)) { attackRange = otherNPCDist; projX = otherNPCX; diff --git a/Projectiles/Summon/ForbiddenCircletEater.cs b/Projectiles/Summon/ForbiddenCircletEater.cs index 6263c0dca4..16dc09a5c1 100644 --- a/Projectiles/Summon/ForbiddenCircletEater.cs +++ b/Projectiles/Summon/ForbiddenCircletEater.cs @@ -89,9 +89,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[j]; if (npc.CanBeChasedBy(Projectile, false)) { float npcX = npc.position.X + (float)(npc.width / 2); diff --git a/Projectiles/Summon/HermitCrabMinion.cs b/Projectiles/Summon/HermitCrabMinion.cs index dff0a079d2..f454140c76 100644 --- a/Projectiles/Summon/HermitCrabMinion.cs +++ b/Projectiles/Summon/HermitCrabMinion.cs @@ -117,9 +117,8 @@ namespace CalamityMod.Projectiles.Summon } if (!chaseNPC) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC npcTarget in Main.ActiveNPCs) { - NPC npcTarget = Main.npc[j]; if (npcTarget.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(npcTarget.Center, Projectile.Center); diff --git a/Projectiles/Summon/Hive.cs b/Projectiles/Summon/Hive.cs index 609038c0ef..1dc594d2ef 100644 --- a/Projectiles/Summon/Hive.cs +++ b/Projectiles/Summon/Hive.cs @@ -69,9 +69,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[j]; if (nPC2.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); @@ -80,7 +79,7 @@ namespace CalamityMod.Projectiles.Summon attackDist = targetDist; projPos = nPC2.Center; canAttack = true; - target = j; + target = nPC2.whoAmI; } } } diff --git a/Projectiles/Summon/PhantomGuy.cs b/Projectiles/Summon/PhantomGuy.cs index bedbe64fb8..54c83ddaf7 100644 --- a/Projectiles/Summon/PhantomGuy.cs +++ b/Projectiles/Summon/PhantomGuy.cs @@ -90,9 +90,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[j]; if (nPC2.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Projectiles/Summon/PinkButterfly.cs b/Projectiles/Summon/PinkButterfly.cs index 4fcfccd7bd..d948314f43 100644 --- a/Projectiles/Summon/PinkButterfly.cs +++ b/Projectiles/Summon/PinkButterfly.cs @@ -106,10 +106,9 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[j]; - if ((nPC2.CanBeChasedBy(Projectile, false) || nPC2.type == NPCID.DukeFishron) && nPC2.active) + if (nPC2.CanBeChasedBy(Projectile, false) || nPC2.type == NPCID.DukeFishron) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); if (!canAttack && targetDist < attackRange) @@ -117,7 +116,7 @@ namespace CalamityMod.Projectiles.Summon attackRange = targetDist; projPos = nPC2.Center; canAttack = true; - targetIndex = j; + targetIndex = nPC2.whoAmI; } } } diff --git a/Projectiles/Summon/ProfanedEnergy.cs b/Projectiles/Summon/ProfanedEnergy.cs index 723a7e324f..2b7628cd89 100644 --- a/Projectiles/Summon/ProfanedEnergy.cs +++ b/Projectiles/Summon/ProfanedEnergy.cs @@ -102,20 +102,20 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[j].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float npcX = Main.npc[j].position.X + (float)(Main.npc[j].width / 2); - float npcY = Main.npc[j].position.Y + (float)(Main.npc[j].height / 2); + float npcX = n.position.X + (float)(n.width / 2); + float npcY = n.position.Y + (float)(n.height / 2); float npcDist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcY); - if (npcDist < attackDistance && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[j].position, Main.npc[j].width, Main.npc[j].height)) + if (npcDist < attackDistance && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height)) { attackDistance = npcDist; projX = npcX; projY = npcY; canAttack = true; - target = j; + target = n.whoAmI; } } } diff --git a/Projectiles/Summon/SandElementalMinion.cs b/Projectiles/Summon/SandElementalMinion.cs index d8a45cdf7c..6880bae54f 100644 --- a/Projectiles/Summon/SandElementalMinion.cs +++ b/Projectiles/Summon/SandElementalMinion.cs @@ -106,9 +106,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack && !passive) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[j]; if (nPC2.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Projectiles/Summon/VileFeederProjectile.cs b/Projectiles/Summon/VileFeederProjectile.cs index bc93e881e2..d92563efc7 100644 --- a/Projectiles/Summon/VileFeederProjectile.cs +++ b/Projectiles/Summon/VileFeederProjectile.cs @@ -90,9 +90,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[j]; if (npc.CanBeChasedBy(Projectile, false)) { float npcX = npc.position.X + (float)(npc.width / 2); diff --git a/Projectiles/Typeless/DemonshadeRedDevil.cs b/Projectiles/Typeless/DemonshadeRedDevil.cs index 8d2b584ef3..5056300ba8 100644 --- a/Projectiles/Typeless/DemonshadeRedDevil.cs +++ b/Projectiles/Typeless/DemonshadeRedDevil.cs @@ -132,9 +132,8 @@ namespace CalamityMod.Projectiles.Typeless } else { - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[j]; if (nPC2.CanBeChasedBy(Projectile, false)) { float npcDist = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Scenes/MusicScenes/BaseMusicSceneEffect.cs b/Scenes/MusicScenes/BaseMusicSceneEffect.cs index 03b7271f85..921411b0ae 100644 --- a/Scenes/MusicScenes/BaseMusicSceneEffect.cs +++ b/Scenes/MusicScenes/BaseMusicSceneEffect.cs @@ -71,12 +71,8 @@ namespace CalamityMod.Systems Rectangle screenRect = new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight); int musicDistance = MusicDistance * 2; - for (int j = 0; j < Main.maxNPCs; j++) - { - NPC npc = Main.npc[j]; - if (!npc.active) - continue; - + foreach (NPC npc in Main.ActiveNPCs) + { bool inList = false; if (npc.type == NPCType) {