diff --git a/Backgrounds/AstralDesertSurfaceBGStyle.cs b/Backgrounds/AstralDesertSurfaceBGStyle.cs index 51d1c01ef7..181f0d7222 100644 --- a/Backgrounds/AstralDesertSurfaceBGStyle.cs +++ b/Backgrounds/AstralDesertSurfaceBGStyle.cs @@ -1,22 +1,23 @@ -using Terraria.ModLoader; +using Microsoft.Xna.Framework.Graphics; +using System.Reflection; +using System; +using Terraria.Graphics.Effects; +using Terraria; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; namespace CalamityMod.Backgrounds { public class AstralDesertSurfaceBGStyle : ModSurfaceBackgroundStyle { - public override int ChooseFarTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseMiddleTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseCloseTexture(ref float scale, ref double parallax, ref float a, ref float b) - { - b -= 75f; - return BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - } + internal static readonly FieldInfo screenOffField = typeof(Main).GetField("screenOff", BindingFlags.Instance | BindingFlags.NonPublic); + internal static readonly FieldInfo scAdjField = typeof(Main).GetField("scAdj", BindingFlags.Instance | BindingFlags.NonPublic); + internal static readonly FieldInfo COSBMAplhaField = typeof(Main).GetField("ColorOfSurfaceBackgroundsModified", BindingFlags.Static | BindingFlags.NonPublic); + readonly int CloseBGYOffset = 475; + readonly int MiddleBGYOffset = 475; public override void ModifyFarFades(float[] fades, float transitionSpeed) { - // This just fades in the background and fades out other backgrounds. for (int i = 0; i < fades.Length; i++) { if (i == Slot) @@ -33,5 +34,90 @@ namespace CalamityMod.Backgrounds } } } + + public override int ChooseFarTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralSurfaceHorizon"); + + public override int ChooseMiddleTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralDesertSurfaceFar"); + + public override int ChooseCloseTexture(ref float scale, ref double parallax, ref float a, ref float b) => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Skies/AstralDesertSurfaceMiddle"); + + public override bool PreDrawCloseBackground(SpriteBatch spriteBatch) + { + //Please see AstralSurfaceBGStyle for comments, code is pretty much identical here + float screenOff = (float)screenOffField.GetValue(Main.instance); + float scAdj = (float)scAdjField.GetValue(Main.instance); + Color COSBMAplha = (Color)COSBMAplhaField.GetValue(null); + Color ColorOfSurfaceBackgroundsModified = new Color(63, 51, 90, COSBMAplha.A); + bool canBGDraw = false; + if ((!Main.remixWorld || (Main.gameMenu && !WorldGen.remixWorldGen)) && (!WorldGen.remixWorldGen || !WorldGen.drunkWorldGen)) + canBGDraw = true; + if (Main.mapFullscreen) + canBGDraw = false; + int offset = 30; + if (Main.gameMenu) + offset = 0; + if (WorldGen.drunkWorldGen) + offset = -180; + float surfacePosition = (float)Main.worldSurface; + if (surfacePosition == 0f) + surfacePosition = 1f; + float screenPosition = Main.screenPosition.Y + (float)(Main.screenHeight / 2) - 600f; + double backgroundTopMagicNumber = (0f - screenPosition + screenOff / 2f) / (surfacePosition * 16f); + float bgGlobalScaleMultiplier = 2f; + int pushBGTopHack; + int offset2 = -180; + int menuOffset = 0; + if (Main.gameMenu) + { + menuOffset -= offset2; + } + pushBGTopHack = menuOffset; + pushBGTopHack += offset; + pushBGTopHack += offset2; + if (canBGDraw) + { + var bgScale = 1.25f; + var bgParallax = 0.4; + var bgTopY = (int)(backgroundTopMagicNumber * 1800.0 + 1500.0) + (int)scAdj + pushBGTopHack; + bgScale *= bgGlobalScaleMultiplier; + var bgWidthScaled = (int)((float)CalamityMod.AstralDesertSurfaceMiddle.Width * bgScale); + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1.2f / (float)bgParallax); + var bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); + if (Main.gameMenu) + bgTopY = 320 + pushBGTopHack; + + var bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + Main.spriteBatch.Draw(CalamityMod.AstralDesertSurfaceMiddle, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralDesertSurfaceMiddle.Width, CalamityMod.AstralDesertSurfaceMiddle.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + + bgScale = 1.31f; + bgParallax = 0.43; + bgTopY = (int)(backgroundTopMagicNumber * 1950.0 + 1750.0) + (int)scAdj + pushBGTopHack; + bgScale *= bgGlobalScaleMultiplier; + bgWidthScaled = (int)((float)CalamityMod.AstralDesertSurfaceClose.Width * bgScale); + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); + bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); + if (Main.gameMenu) + { + bgTopY = 400 + pushBGTopHack; + bgStartX -= 80; + } + + bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + Main.spriteBatch.Draw(CalamityMod.AstralDesertSurfaceClose, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralDesertSurfaceClose.Width, CalamityMod.AstralDesertSurfaceClose.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + } + return false; + } } } diff --git a/Backgrounds/AstralDesertSurfaceFar.png b/Backgrounds/AstralDesertSurfaceFar.png index a2337a7d8f..e8b7a01e29 100644 Binary files a/Backgrounds/AstralDesertSurfaceFar.png and b/Backgrounds/AstralDesertSurfaceFar.png differ diff --git a/Backgrounds/AstralSnowSurfaceBGStyle.cs b/Backgrounds/AstralSnowSurfaceBGStyle.cs index 993decd710..239fc427b3 100644 --- a/Backgrounds/AstralSnowSurfaceBGStyle.cs +++ b/Backgrounds/AstralSnowSurfaceBGStyle.cs @@ -1,18 +1,25 @@ -using Terraria.ModLoader; +using Microsoft.Xna.Framework.Graphics; +using System.Reflection; +using System; +using Terraria.Graphics.Effects; +using Terraria; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using Terraria.GameContent.UI.States; namespace CalamityMod.Backgrounds { public class AstralSnowSurfaceBGStyle : ModSurfaceBackgroundStyle { - public override int ChooseFarTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseMiddleTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseCloseTexture(ref float scale, ref double parallax, ref float a, ref float b) => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); + internal static readonly FieldInfo screenOffField = typeof(Main).GetField("screenOff", BindingFlags.Instance | BindingFlags.NonPublic); + internal static readonly FieldInfo scAdjField = typeof(Main).GetField("scAdj", BindingFlags.Instance | BindingFlags.NonPublic); + internal static readonly FieldInfo COSBMAplhaField = typeof(Main).GetField("ColorOfSurfaceBackgroundsModified", BindingFlags.Static | BindingFlags.NonPublic); + readonly int FrontBGYOffset = 275; + readonly int CloseBGYOffset = 175; + readonly int MiddleBGYOffset = 475; public override void ModifyFarFades(float[] fades, float transitionSpeed) { - // This just fades in the background and fades out other backgrounds. for (int i = 0; i < fades.Length; i++) { if (i == Slot) @@ -29,5 +36,113 @@ namespace CalamityMod.Backgrounds } } } + + public override int ChooseFarTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralSurfaceHorizon"); + + public override int ChooseMiddleTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralSurfaceFar"); + + public override int ChooseCloseTexture(ref float scale, ref double parallax, ref float a, ref float b) => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Skies/AstralSnowSurfaceMiddle"); + + public override bool PreDrawCloseBackground(SpriteBatch spriteBatch) + { + //Please see AstralSurfaceBGStyle for comments, code is pretty much identical here + float screenOff = (float)screenOffField.GetValue(Main.instance); + float scAdj = (float)scAdjField.GetValue(Main.instance); + Color COSBMAplha = (Color)COSBMAplhaField.GetValue(null); + Color ColorOfSurfaceBackgroundsModified = new Color(63, 51, 90, COSBMAplha.A); + bool canBGDraw = false; + if ((!Main.remixWorld || (Main.gameMenu && !WorldGen.remixWorldGen)) && (!WorldGen.remixWorldGen || !WorldGen.drunkWorldGen)) + canBGDraw = true; + if (Main.mapFullscreen) + canBGDraw = false; + int offset = 30; + if (Main.gameMenu) + offset = 0; + if (WorldGen.drunkWorldGen) + offset = -180; + float surfacePosition = (float)Main.worldSurface; + if (surfacePosition == 0f) + surfacePosition = 1f; + float screenPosition = Main.screenPosition.Y + (float)(Main.screenHeight / 2) - 600f; + double backgroundTopMagicNumber = (0f - screenPosition + screenOff / 2f) / (surfacePosition * 16f); + float bgGlobalScaleMultiplier = 2f; + int pushBGTopHack; + int offset2 = -180; + int menuOffset = 0; + if (Main.gameMenu) + { + menuOffset -= offset2; + } + pushBGTopHack = menuOffset; + pushBGTopHack += offset; + pushBGTopHack += offset2; + if (canBGDraw) + { + var bgScale = 1.25f; + var bgParallax = 0.4; + var bgTopY = (int)(backgroundTopMagicNumber * 1800.0 + 1500.0) + (int)scAdj + pushBGTopHack; + bgScale *= bgGlobalScaleMultiplier; + var bgWidthScaled = (int)((float)CalamityMod.AstralSnowSurfaceMiddle.Width * bgScale); + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1.2f / (float)bgParallax); + var bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); + if (Main.gameMenu) + bgTopY = 320 + pushBGTopHack; + + var bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + Main.spriteBatch.Draw(CalamityMod.AstralSnowSurfaceMiddle, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSnowSurfaceMiddle.Width, CalamityMod.AstralSnowSurfaceMiddle.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + + bgScale = 1.31f; + bgParallax = 0.43; + bgTopY = (int)(backgroundTopMagicNumber * 1950.0 + 1750.0) + (int)scAdj + pushBGTopHack; + bgScale *= bgGlobalScaleMultiplier; + bgWidthScaled = (int)((float)CalamityMod.AstralSurfaceClose.Width * bgScale); + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); + bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); + if (Main.gameMenu) + { + bgTopY = 400 + pushBGTopHack; + bgStartX -= 80; + } + + bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceClose, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceClose.Width, CalamityMod.AstralSurfaceClose.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceCloseGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceCloseGlow.Width, CalamityMod.AstralSurfaceCloseGlow.Height), new Color(Color.White.R * 0.7f, Color.White.G * 0.7f, Color.White.B * 0.7f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + bgScale = 1.34f; + bgParallax = 0.49; + bgTopY = (int)(backgroundTopMagicNumber * 2100.0 + 2000.0) + (int)scAdj + pushBGTopHack; + bgScale *= bgGlobalScaleMultiplier; + bgWidthScaled = (int)(CalamityMod.AstralSurfaceFront.Width * bgScale); + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); + bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); + if (Main.gameMenu) + { + bgTopY = 480 + pushBGTopHack; + bgStartX -= 120; + } + + bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFront, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFront.Width, CalamityMod.AstralSurfaceFront.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFrontGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFrontGlow.Width, CalamityMod.AstralSurfaceFrontGlow.Height), new Color(Color.White.R * 0.9f, Color.White.G * 0.9f, Color.White.B * 0.9f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + } + return false; + } } } diff --git a/Backgrounds/AstralSnowSurfaceFar.png b/Backgrounds/AstralSnowSurfaceFar.png deleted file mode 100644 index e1b3614aa8..0000000000 Binary files a/Backgrounds/AstralSnowSurfaceFar.png and /dev/null differ diff --git a/Backgrounds/AstralSnowSurfaceMiddle.png b/Backgrounds/AstralSnowSurfaceMiddle.png index fc7c678756..ff4e5fc236 100644 Binary files a/Backgrounds/AstralSnowSurfaceMiddle.png and b/Backgrounds/AstralSnowSurfaceMiddle.png differ diff --git a/Backgrounds/AstralSurfaceBGStyle.cs b/Backgrounds/AstralSurfaceBGStyle.cs index 8c8a7ee21c..c89092d701 100644 --- a/Backgrounds/AstralSurfaceBGStyle.cs +++ b/Backgrounds/AstralSurfaceBGStyle.cs @@ -1,22 +1,24 @@ -using Terraria.ModLoader; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using System.Reflection; +using System; +using Terraria.Graphics.Effects; +using Terraria; +using Terraria.ModLoader; namespace CalamityMod.Backgrounds { public class AstralSurfaceBGStyle : ModSurfaceBackgroundStyle { - public override int ChooseFarTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseMiddleTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseCloseTexture(ref float scale, ref double parallax, ref float a, ref float b) - { - scale *= 0.75f; - return BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - } + internal static readonly FieldInfo screenOffField = typeof(Main).GetField("screenOff", BindingFlags.Instance | BindingFlags.NonPublic); + internal static readonly FieldInfo scAdjField = typeof(Main).GetField("scAdj", BindingFlags.Instance | BindingFlags.NonPublic); + internal static readonly FieldInfo COSBMAplhaField = typeof(Main).GetField("ColorOfSurfaceBackgroundsModified", BindingFlags.Static | BindingFlags.NonPublic); + readonly int FrontBGYOffset = 275; //Offsets for the height positioning. Make these 0 for backgrounds that want to be the same as treeline backgrounds (backgrounds that have the front 3 layers as trees) + readonly int CloseBGYOffset = 175; + readonly int MiddleBGYOffset = 475; public override void ModifyFarFades(float[] fades, float transitionSpeed) { - // This just fades in the background and fades out other backgrounds. for (int i = 0; i < fades.Length; i++) { if (i == Slot) @@ -33,5 +35,120 @@ namespace CalamityMod.Backgrounds } } } + + public override int ChooseFarTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralSurfaceHorizon"); //5th layer (Horizon) + + public override int ChooseMiddleTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralSurfaceFar"); //4th layer (Far) + + public override int ChooseCloseTexture(ref float scale, ref double parallax, ref float a, ref float b) => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Skies/AstralSurfaceMiddle"); //Fallback texture, not nessesarily needed since predraw returns false + + public override bool PreDrawCloseBackground(SpriteBatch spriteBatch) //Taken from vanilla to draw the front 3 layers, edited to fit tmod and astral background needs + { + float screenOff = (float)screenOffField.GetValue(Main.instance); + float scAdj = (float)scAdjField.GetValue(Main.instance); + Color COSBMAplha = (Color)COSBMAplhaField.GetValue(null); + Color ColorOfSurfaceBackgroundsModified = new Color(63, 51, 90, COSBMAplha.A); //Astral Biome Coloration with the alpha as the background fade + bool canBGDraw = false; + if ((!Main.remixWorld || (Main.gameMenu && !WorldGen.remixWorldGen)) && (!WorldGen.remixWorldGen || !WorldGen.drunkWorldGen)) + canBGDraw = true; + if (Main.mapFullscreen) + canBGDraw = false; + int offset = 30; + if (Main.gameMenu) + offset = 0; + if (WorldGen.drunkWorldGen) + offset = -180; + float surfacePosition = (float)Main.worldSurface; + if (surfacePosition == 0f) + surfacePosition = 1f; + float screenPosition = Main.screenPosition.Y + (float)(Main.screenHeight / 2) - 600f; + double backgroundTopMagicNumber = (0f - screenPosition + screenOff / 2f) / (surfacePosition * 16f); + float bgGlobalScaleMultiplier = 2f; + int pushBGTopHack; + int offset2 = -180; + int menuOffset = 0; + if (Main.gameMenu) + { + menuOffset -= offset2; + } + pushBGTopHack = menuOffset; + pushBGTopHack += offset; + pushBGTopHack += offset2; //Offsets to the background placement + if (canBGDraw) //If the background can draw (player is not in a remix world or is not in a map). This can probably be removed since backgrounds already go through these checks + { + //3rd layer (Middle) + var bgScale = 1.25f; //Scale of the furthest of the closest background layers (3rd layer) + var bgParallax = 0.4; //The parallax of the background layer + var bgTopY = (int)(backgroundTopMagicNumber * 1800.0 + 1500.0) + (int)scAdj + pushBGTopHack; //the Y position of the background + bgScale *= bgGlobalScaleMultiplier; //Scale of the background + var bgWidthScaled = (int)((float)CalamityMod.AstralSurfaceMiddle.Width * bgScale); //The Width of the bg texture scaled to the correct size + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1.2f / (float)bgParallax); + var bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); //The starting position of the background layer + if (Main.gameMenu) + bgTopY = 320 + pushBGTopHack; //increases the height in the main menu + + var bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + //Draw the texture and its glowmask to each loop of the texture + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceMiddle, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceMiddle.Width, CalamityMod.AstralSurfaceMiddle.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceMiddleGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceMiddleGlow.Width, CalamityMod.AstralSurfaceMiddleGlow.Height), new Color(Color.White.R * 0.5f, Color.White.G * 0.5f, Color.White.B * 0.5f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + + //2nd layer (Close) + //Repeat of above with slight changes to variables + bgScale = 1.31f; + bgParallax = 0.43; + bgTopY = (int)(backgroundTopMagicNumber * 1950.0 + 1750.0) + (int)scAdj + pushBGTopHack; + bgScale *= bgGlobalScaleMultiplier; + bgWidthScaled = (int)((float)CalamityMod.AstralSurfaceClose.Width * bgScale); + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); + bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); + if (Main.gameMenu) + { + bgTopY = 400 + pushBGTopHack; + bgStartX -= 80; //the initial postion of where the background starts in the main menu is pushed back to not be directly ontop, mostly for tree bgs that use the same treeline texture but faded + } + + bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceClose, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceClose.Width, CalamityMod.AstralSurfaceClose.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceCloseGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceCloseGlow.Width, CalamityMod.AstralSurfaceCloseGlow.Height), new Color(Color.White.R * 0.7f, Color.White.G * 0.7f, Color.White.B * 0.7f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + + //1st layer (Front) + //Repeat of above with slight changes to variables + bgScale = 1.34f; + bgParallax = 0.49; + bgTopY = (int)(backgroundTopMagicNumber * 2100.0 + 2000.0) + (int)scAdj + pushBGTopHack; + bgScale *= bgGlobalScaleMultiplier; + bgWidthScaled = (int)(CalamityMod.AstralSurfaceFront.Width * bgScale); + SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); + bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); + if (Main.gameMenu) + { + bgTopY = 480 + pushBGTopHack; + bgStartX -= 120; + } + + bgLoops = Main.screenWidth / bgWidthScaled + 2; + if ((double)Main.screenPosition.Y < Main.worldSurface * 16.0 + 16.0) + { + for (int i = 0; i < bgLoops; i++) + { + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFront, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFront.Width, CalamityMod.AstralSurfaceFront.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFrontGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFrontGlow.Width, CalamityMod.AstralSurfaceFrontGlow.Height), new Color(Color.White.R * 0.9f, Color.White.G * 0.9f, Color.White.B * 0.9f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + } + } + } + return false; //Stop the drawing of the base close background texture (note: does NOT stop the drawing of the Middle and Far textures because tmodloader is slight stupid :blushing:) + } } } diff --git a/Backgrounds/AstralSurfaceClose.png b/Backgrounds/AstralSurfaceClose.png index 6701b9a71c..166e8bc48d 100644 Binary files a/Backgrounds/AstralSurfaceClose.png and b/Backgrounds/AstralSurfaceClose.png differ diff --git a/Skies/AstralSurfaceCloseGlow.png b/Backgrounds/AstralSurfaceCloseGlow.png similarity index 100% rename from Skies/AstralSurfaceCloseGlow.png rename to Backgrounds/AstralSurfaceCloseGlow.png diff --git a/Backgrounds/AstralSurfaceFar.png b/Backgrounds/AstralSurfaceFar.png index 9285cefdae..6e90155b16 100644 Binary files a/Backgrounds/AstralSurfaceFar.png and b/Backgrounds/AstralSurfaceFar.png differ diff --git a/Backgrounds/AstralSurfaceFogBGStyle.cs b/Backgrounds/AstralSurfaceFogBGStyle.cs deleted file mode 100644 index aab1ea3fba..0000000000 --- a/Backgrounds/AstralSurfaceFogBGStyle.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Backgrounds -{ - public class AstralSurfaceFogBGStyle : ModSurfaceBackgroundStyle - { - public override int ChooseFarTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseMiddleTexture() => BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - - public override int ChooseCloseTexture(ref float scale, ref double parallax, ref float a, ref float b) - { - scale *= 0.75f; - return BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - } - - public override void ModifyFarFades(float[] fades, float transitionSpeed) - { - // This just fades in the background and fades out other backgrounds. - for (int i = 0; i < fades.Length; i++) - { - if (i == Slot) - { - fades[i] += transitionSpeed; - if (fades[i] > 1f) - fades[i] = 1f; - } - else - { - fades[i] -= transitionSpeed; - if (fades[i] < 0f) - fades[i] = 0f; - } - } - } - } -} diff --git a/Backgrounds/AstralSurfaceFront.png b/Backgrounds/AstralSurfaceFront.png new file mode 100644 index 0000000000..5d603a737b Binary files /dev/null and b/Backgrounds/AstralSurfaceFront.png differ diff --git a/Skies/AstralSurfaceFrontGlow.png b/Backgrounds/AstralSurfaceFrontGlow.png similarity index 100% rename from Skies/AstralSurfaceFrontGlow.png rename to Backgrounds/AstralSurfaceFrontGlow.png diff --git a/Backgrounds/AstralSurfaceHorizon.png b/Backgrounds/AstralSurfaceHorizon.png new file mode 100644 index 0000000000..fa58141a90 Binary files /dev/null and b/Backgrounds/AstralSurfaceHorizon.png differ diff --git a/Backgrounds/AstralSurfaceMiddle.png b/Backgrounds/AstralSurfaceMiddle.png index 89b568c3be..d3f984c001 100644 Binary files a/Backgrounds/AstralSurfaceMiddle.png and b/Backgrounds/AstralSurfaceMiddle.png differ diff --git a/Skies/AstralSurfaceMiddleGlow.png b/Backgrounds/AstralSurfaceMiddleGlow.png similarity index 100% rename from Skies/AstralSurfaceMiddleGlow.png rename to Backgrounds/AstralSurfaceMiddleGlow.png diff --git a/Backgrounds/AstralUG4_0.png b/Backgrounds/AstralUG4_0.png new file mode 100644 index 0000000000..73f3bad550 Binary files /dev/null and b/Backgrounds/AstralUG4_0.png differ diff --git a/Backgrounds/AstralUG4_1.png b/Backgrounds/AstralUG4_1.png new file mode 100644 index 0000000000..bf9978ceeb Binary files /dev/null and b/Backgrounds/AstralUG4_1.png differ diff --git a/Backgrounds/AstralUG4_2.png b/Backgrounds/AstralUG4_2.png new file mode 100644 index 0000000000..b36e95b213 Binary files /dev/null and b/Backgrounds/AstralUG4_2.png differ diff --git a/Backgrounds/AstralUndergroundBGStyle.cs b/Backgrounds/AstralUndergroundBGStyle.cs index 71f1ec2c50..f3c9455798 100644 --- a/Backgrounds/AstralUndergroundBGStyle.cs +++ b/Backgrounds/AstralUndergroundBGStyle.cs @@ -1,4 +1,5 @@ -using Terraria.ModLoader; +using Terraria; +using Terraria.ModLoader; namespace CalamityMod.Backgrounds { @@ -6,8 +7,8 @@ namespace CalamityMod.Backgrounds { public override void FillTextureArray(int[] textureSlots) { - for (int i = 0; i <= 3; i++) - textureSlots[i] = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG" + i.ToString()); + for (int i = 0; i <= 4; i++) + textureSlots[i] = BackgroundTextureLoader.GetBackgroundSlot(i == 4 ? "CalamityMod/Backgrounds/AstralUG" + i.ToString() + "_" + Main.hellBackStyle : "CalamityMod/Backgrounds/AstralUG" + i.ToString()); } } } diff --git a/BiomeManagers/AbovegroundAstralBiome.cs b/BiomeManagers/AbovegroundAstralBiome.cs deleted file mode 100644 index aea59f5567..0000000000 --- a/BiomeManagers/AbovegroundAstralBiome.cs +++ /dev/null @@ -1,34 +0,0 @@ -using CalamityMod.Items.Placeables.Furniture; -using CalamityMod.Systems; -using Terraria; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.BiomeManagers -{ - public class AbovegroundAstralBiome : ModBiome - { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/AstralWater"); - public override ModSurfaceBackgroundStyle SurfaceBackgroundStyle => ModContent.Find("CalamityMod/AstralSurfaceFogBGStyle"); - public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle => ModContent.Find("CalamityMod/AstralUndergroundBGStyle"); - public override int BiomeTorchItemType => ModContent.ItemType(); - public override SceneEffectPriority Priority => SceneEffectPriority.BiomeHigh; - public override string BestiaryIcon => "CalamityMod/BiomeManagers/AbovegroundAstralBiomeIcon"; - public override string BackgroundPath => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - - public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("AstralInfection") ?? MusicID.Space; - - public override bool IsBiomeActive(Player player) - { - return !player.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950; - } - - public override void SpecialVisuals(Player player, bool isActive) - { - player.ManageSpecialBiomeVisuals("CalamityMod:Astral", isActive); - - } - } -} diff --git a/BiomeManagers/AbovegroundAstralBiomeSurface.cs b/BiomeManagers/AbovegroundAstralBiomeSurface.cs deleted file mode 100644 index d68e9ed700..0000000000 --- a/BiomeManagers/AbovegroundAstralBiomeSurface.cs +++ /dev/null @@ -1,41 +0,0 @@ -using CalamityMod.Items.Placeables.Furniture; -using CalamityMod.Systems; -using Terraria; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.BiomeManagers -{ - public class AbovegroundAstralBiomeSurface : ModBiome - { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/AstralWater"); - public override ModSurfaceBackgroundStyle SurfaceBackgroundStyle => ModContent.Find("CalamityMod/AstralSurfaceBGStyle"); - public override int BiomeTorchItemType => ModContent.ItemType(); - public override SceneEffectPriority Priority => SceneEffectPriority.BiomeHigh; - public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - - public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("AstralInfection") ?? MusicID.Space; - - public override bool IsBiomeActive(Player player) - { - return !player.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950 && !player.ZoneSnow && !player.ZoneDesert; - } - - public override void SpecialVisuals(Player player, bool isActive) - { - if (SkyManager.Instance["CalamityMod:AstralSurface"] != null && isActive != SkyManager.Instance["CalamityMod:AstralSurface"].IsActive()) - { - if (isActive) - { - SkyManager.Instance.Activate("CalamityMod:AstralSurface"); - } - else - { - SkyManager.Instance.Deactivate("CalamityMod:AstralSurface"); - } - } - } - - } -} diff --git a/BiomeManagers/AbovegroundAstralDesertBiome.cs b/BiomeManagers/AbovegroundAstralDesertBiome.cs deleted file mode 100644 index 37058fdce9..0000000000 --- a/BiomeManagers/AbovegroundAstralDesertBiome.cs +++ /dev/null @@ -1,43 +0,0 @@ -using CalamityMod.Items.Placeables.Furniture; -using CalamityMod.Systems; -using Terraria; -using Terraria.GameContent.Events; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.BiomeManagers -{ - public class AbovegroundAstralDesertBiome : ModBiome - { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/AstralWater"); - public override ModSurfaceBackgroundStyle SurfaceBackgroundStyle => ModContent.Find("CalamityMod/AstralDesertSurfaceBGStyle"); - public override int BiomeTorchItemType => ModContent.ItemType(); - public override SceneEffectPriority Priority => Sandstorm.Happening && !(Main.slimeRain || Main.eclipse) ? SceneEffectPriority.Environment : SceneEffectPriority.BiomeHigh; - public override string BestiaryIcon => "CalamityMod/BiomeManagers/AstralDesertIcon"; - // Could use its own unique background - public override string BackgroundPath => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("AstralInfection") ?? MusicID.Space; - - public override bool IsBiomeActive(Player player) - { - return !player.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950 && player.ZoneDesert && !player.ZoneSnow; - } - - public override void SpecialVisuals(Player player, bool isActive) - { - if (SkyManager.Instance["CalamityMod:AstralDesert"] != null && isActive != SkyManager.Instance["CalamityMod:AstralDesert"].IsActive()) - { - if (isActive) - { - SkyManager.Instance.Activate("CalamityMod:AstralDesert"); - } - else - { - SkyManager.Instance.Deactivate("CalamityMod:AstralDesert"); - } - } - } - } -} diff --git a/BiomeManagers/AbovegroundAstralSnowBiome.cs b/BiomeManagers/AbovegroundAstralSnowBiome.cs deleted file mode 100644 index 029513ce91..0000000000 --- a/BiomeManagers/AbovegroundAstralSnowBiome.cs +++ /dev/null @@ -1,41 +0,0 @@ -using CalamityMod.Items.Placeables.Furniture; -using CalamityMod.Systems; -using Terraria; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.BiomeManagers -{ - public class AbovegroundAstralSnowBiome : ModBiome - { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/AstralWater"); - public override ModSurfaceBackgroundStyle SurfaceBackgroundStyle => ModContent.Find("CalamityMod/AstralSnowSurfaceBGStyle"); - public override int BiomeTorchItemType => ModContent.ItemType(); - public override SceneEffectPriority Priority => SceneEffectPriority.BiomeHigh; - public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - - public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("AstralInfection") ?? MusicID.Space; - - public override bool IsBiomeActive(Player player) - { - return !player.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950 && player.ZoneSnow; - } - - public override void SpecialVisuals(Player player, bool isActive) - { - if (SkyManager.Instance["CalamityMod:AstralSnow"] != null && isActive != SkyManager.Instance["CalamityMod:AstralSnow"].IsActive()) - { - if (isActive) - { - SkyManager.Instance.Activate("CalamityMod:AstralSnow"); - } - else - { - SkyManager.Instance.Deactivate("CalamityMod:AstralSnow"); - } - } - } - - } -} diff --git a/BiomeManagers/AstralInfectionBiome.cs b/BiomeManagers/AstralInfectionBiome.cs new file mode 100644 index 0000000000..980d34e0da --- /dev/null +++ b/BiomeManagers/AstralInfectionBiome.cs @@ -0,0 +1,112 @@ +using CalamityMod.Items.Placeables.Furniture; +using CalamityMod.Systems; +using Terraria; +using Terraria.GameContent.Events; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.BiomeManagers +{ + public class AstralInfectionBiome : ModBiome + { + public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/AstralWater"); + + public override ModSurfaceBackgroundStyle SurfaceBackgroundStyle + { + get + { + if (Main.LocalPlayer.ZoneSnow) //Snow + { + return ModContent.Find("CalamityMod/AstralSnowSurfaceBGStyle"); + } + else if (Main.LocalPlayer.ZoneDesert && !Main.LocalPlayer.ZoneSnow) //Desert + { + return ModContent.Find("CalamityMod/AstralDesertSurfaceBGStyle"); + } + else //surface + { + return ModContent.Find("CalamityMod/AstralSurfaceBGStyle"); + } + } + } + + public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle + { + get + { + if (Main.LocalPlayer.ZoneSnow) + { + return ModContent.Find("CalamityMod/AstralUndergroundBGStyle"); // Could use its own unique background + } + return ModContent.Find("CalamityMod/AstralUndergroundBGStyle"); + } + } + + public override int BiomeTorchItemType => ModContent.ItemType(); + + public override SceneEffectPriority Priority + { + get + { + if (Main.LocalPlayer.ZoneDesert && Sandstorm.Happening && !(Main.LocalPlayer.ZoneSnow || Main.slimeRain || Main.eclipse)) + { + return SceneEffectPriority.Environment; + } + else + { + return SceneEffectPriority.BiomeHigh; + } + } + } + + public override string BestiaryIcon => "CalamityMod/BiomeManagers/AbovegroundAstralBiomeIcon"; + + public override string BackgroundPath + { + get + { + if (Main.LocalPlayer.ZoneDesert && !Main.LocalPlayer.ZoneSnow) + { + //desert + return "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; // Could use its own unique background + } + else if (Main.LocalPlayer.ZoneDirtLayerHeight || Main.LocalPlayer.ZoneRockLayerHeight || Main.LocalPlayer.ZoneUnderworldHeight) + { + //underground + return "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; // Could use its own unique background + } + else + { + return "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; + } + } + } + public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; + + public override int Music + { + get + { + if (Main.LocalPlayer.ZoneDirtLayerHeight || Main.LocalPlayer.ZoneRockLayerHeight || Main.LocalPlayer.ZoneUnderworldHeight) + { + return CalamityMod.Instance.GetMusicFromMusicMod("AstralInfectionUnderground") ?? MusicID.Space; + } + return CalamityMod.Instance.GetMusicFromMusicMod("AstralInfection") ?? MusicID.Space; + } + } + + public override bool IsBiomeActive(Player player) + { + return !player.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950; + } + + public override void SpecialVisuals(Player player, bool isActive) + { + player.ManageSpecialBiomeVisuals("CalamityMod:Astral", isActive); + if (Main.LocalPlayer.ZoneDirtLayerHeight || Main.LocalPlayer.ZoneRockLayerHeight || Main.LocalPlayer.ZoneUnderworldHeight) + { + player.ManageSpecialBiomeVisuals("CalamityMod:Astral", isActive); //underground + } + } + } +} diff --git a/BiomeManagers/AcidRainBiome.cs b/BiomeManagers/BestiaryCategories/AcidRainBiome.cs similarity index 100% rename from BiomeManagers/AcidRainBiome.cs rename to BiomeManagers/BestiaryCategories/AcidRainBiome.cs diff --git a/BiomeManagers/BestiaryCategories/AstralCaveDesert.cs b/BiomeManagers/BestiaryCategories/AstralCaveDesert.cs new file mode 100644 index 0000000000..8f7d2a9a30 --- /dev/null +++ b/BiomeManagers/BestiaryCategories/AstralCaveDesert.cs @@ -0,0 +1,11 @@ +using Terraria.ModLoader; + +namespace CalamityMod.BiomeManagers.BestiaryCategories +{ + public class AstralCaveDesert : ModBiome //Unused, currently + { + public override string BestiaryIcon => "CalamityMod/BiomeManagers/AstralCaveDesertIcon"; + + public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; + } +} diff --git a/BiomeManagers/BestiaryCategories/AstralDesert.cs b/BiomeManagers/BestiaryCategories/AstralDesert.cs new file mode 100644 index 0000000000..29b0a3f907 --- /dev/null +++ b/BiomeManagers/BestiaryCategories/AstralDesert.cs @@ -0,0 +1,11 @@ +using Terraria.ModLoader; + +namespace CalamityMod.BiomeManagers.BestiaryCategories +{ + public class AstralDesert : ModBiome + { + public override string BestiaryIcon => "CalamityMod/BiomeManagers/AstralDesertIcon"; + + public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; + } +} diff --git a/BiomeManagers/BestiaryCategories/AstralIce.cs b/BiomeManagers/BestiaryCategories/AstralIce.cs new file mode 100644 index 0000000000..f478ae1ee9 --- /dev/null +++ b/BiomeManagers/BestiaryCategories/AstralIce.cs @@ -0,0 +1,11 @@ +using Terraria.ModLoader; + +namespace CalamityMod.BiomeManagers.BestiaryCategories +{ + public class AstralIce : ModBiome //Unused, currently + { + public override string BestiaryIcon => "CalamityMod/BiomeManagers/AstralIceIcon"; + + public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; + } +} diff --git a/BiomeManagers/BestiaryCategories/AstralUnderground.cs b/BiomeManagers/BestiaryCategories/AstralUnderground.cs new file mode 100644 index 0000000000..42d924fd5b --- /dev/null +++ b/BiomeManagers/BestiaryCategories/AstralUnderground.cs @@ -0,0 +1,11 @@ +using Terraria.ModLoader; + +namespace CalamityMod.BiomeManagers.BestiaryCategories +{ + public class AstralUnderground : ModBiome + { + public override string BestiaryIcon => "CalamityMod/BiomeManagers/UndergroundAstralIcon"; + + public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; + } +} diff --git a/BiomeManagers/UndergroundAstralBiome.cs b/BiomeManagers/UndergroundAstralBiome.cs deleted file mode 100644 index f83a02d83f..0000000000 --- a/BiomeManagers/UndergroundAstralBiome.cs +++ /dev/null @@ -1,33 +0,0 @@ -using CalamityMod.Systems; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.BiomeManagers -{ - public class UndergroundAstralBiome : ModBiome - { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/AstralWater"); - public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle => ModContent.Find("CalamityMod/AstralUndergroundBGStyle"); - public override SceneEffectPriority Priority => SceneEffectPriority.BiomeHigh; - public override string BestiaryIcon => "CalamityMod/BiomeManagers/UndergroundAstralIcon"; - // Could use its own unique background - public override string BackgroundPath => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - public override string MapBackground => "CalamityMod/Backgrounds/MapBackgrounds/AstralBG"; - - public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("AstralInfectionUnderground") ?? MusicID.Space; - - public override bool IsBiomeActive(Player player) - { - return !player.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950 && (player.ZoneDirtLayerHeight || player.ZoneRockLayerHeight || player.ZoneUnderworldHeight); - } - - public override void SpecialVisuals(Player player, bool isActive) - { - player.ManageSpecialBiomeVisuals("CalamityMod:Astral", isActive); - } - - // Just slightly above the above-ground astral biomes. - public override float GetWeight(Player player) => 0.51f; - } -} diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 6bc8f2c496..af326372ec 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -1089,10 +1089,7 @@ namespace CalamityMod.CalPlayer #region Biome public bool ZoneCalamity => Player.InModBiome(ModContent.GetInstance()); - public bool ZoneAstral => (Player.InModBiome(ModContent.GetInstance()) || - Player.InModBiome(ModContent.GetInstance()) || - Player.InModBiome(ModContent.GetInstance()) || - Player.InModBiome(ModContent.GetInstance())) && !ZoneAbyss; + public bool ZoneAstral => Player.InModBiome(ModContent.GetInstance()) && !ZoneAbyss; public bool ZoneSunkenSea => Player.InModBiome(ModContent.GetInstance()); public bool ZoneSulphur => Player.InModBiome(ModContent.GetInstance()); public bool ZoneAbyss => ZoneAbyssLayer1 || ZoneAbyssLayer2 || ZoneAbyssLayer3 || ZoneAbyssLayer4; @@ -2978,10 +2975,9 @@ namespace CalamityMod.CalPlayer } if (Main.netMode != NetmodeID.MultiplayerClient) { - for (int l = 0; l < Main.maxNPCs; l++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[l]; - if (npc.active && !npc.friendly && !npc.dontTakeDamage && Vector2.Distance(Player.Center, npc.Center) <= 3000f) + if (!npc.friendly && !npc.dontTakeDamage && Vector2.Distance(Player.Center, npc.Center) <= 3000f) npc.AddBuff(ModContent.BuffType(), 600, false); } } @@ -4768,22 +4764,22 @@ namespace CalamityMod.CalPlayer { int spearsFired = 0; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { if (spearsFired == 2) break; - if (Main.projectile[i].owner == Player.whoAmI && Main.projectile[i].friendly) + if (p.owner == Player.whoAmI && p.friendly) { - bool attack = Main.projectile[i].owner == Player.whoAmI && Main.projectile[i].type == ModContent.ProjectileType(); + bool attack = p.type == ModContent.ProjectileType(); if (attack) { int numSpears = profanedCrystalBuffs ? 12 : 6; - int dam = (int)(Main.projectile[i].originalDamage * (profanedCrystalBuffs ? 1f : 0.25f)); + int dam = (int)(p.originalDamage * (profanedCrystalBuffs ? 1f : 0.25f)); for (int x = 0; x < numSpears; x++) { float angle = MathHelper.TwoPi / numSpears * x; - int proj = Projectile.NewProjectile(source, Main.projectile[i].Center, angle.ToRotationVector2().RotatedBy(Math.Atan(-45f)) * 8f, ModContent.ProjectileType(), dam, 0f, Player.whoAmI, pscState, 0f); + int proj = Projectile.NewProjectile(source, p.Center, angle.ToRotationVector2().RotatedBy(Math.Atan(-45f)) * 8f, ModContent.ProjectileType(), dam, 0f, Player.whoAmI, pscState, 0f); Main.projectile[proj].originalDamage = dam; } spearsFired++; diff --git a/CalPlayer/CalamityPlayerDashEffects.cs b/CalPlayer/CalamityPlayerDashEffects.cs index 302f69fc37..279dff0a6d 100644 --- a/CalPlayer/CalamityPlayerDashEffects.cs +++ b/CalPlayer/CalamityPlayerDashEffects.cs @@ -72,15 +72,13 @@ namespace CalamityMod.CalPlayer if (HasCustomDash && Player.dashDelay < 0) { Rectangle hitArea = new Rectangle((int)(Player.position.X + Player.velocity.X * 0.5 - 4f), (int)(Player.position.Y + Player.velocity.Y * 0.5 - 4), Player.width + 8, Player.height + 8); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - NPC n = Main.npc[i]; - // Ignore critters with the Guide to Critter Companionship if (Player.dontHurtCritters && NPCID.Sets.CountsAsCritter[n.type]) continue; - if (n.active && !n.dontTakeDamage && !n.friendly && n.Calamity().dashImmunityTime[Player.whoAmI] <= 0) + if (!n.dontTakeDamage && !n.friendly && n.Calamity().dashImmunityTime[Player.whoAmI] <= 0) { if (hitArea.Intersects(n.getRect()) && (n.noTileCollide || Player.CanHit(n))) { @@ -543,15 +541,13 @@ namespace CalamityMod.CalPlayer public int DoMountDashDamage(Rectangle myRect, float Damage, float Knockback, int NPCImmuneTime, int PlayerImmuneTime) { int totalHurtNPCs = 0; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - NPC n = Main.npc[i]; - // Ignore critters with the Guide to Critter Companionship if (Player.dontHurtCritters && NPCID.Sets.CountsAsCritter[n.type]) continue; - if (n.active && !n.dontTakeDamage && !n.friendly && n.Calamity().dashImmunityTime[Player.whoAmI] <= 0) + if (!n.dontTakeDamage && !n.friendly && n.Calamity().dashImmunityTime[Player.whoAmI] <= 0) { Rectangle npcHitbox = n.getRect(); if (myRect.Intersects(npcHitbox) && (n.noTileCollide || Collision.CanHit(Player.position, Player.width, Player.height, n.position, n.width, n.height))) diff --git a/CalPlayer/CalamityPlayerHitHurt.cs b/CalPlayer/CalamityPlayerHitHurt.cs index 9a80787960..9e208c0ca5 100644 --- a/CalPlayer/CalamityPlayerHitHurt.cs +++ b/CalPlayer/CalamityPlayerHitHurt.cs @@ -250,10 +250,10 @@ namespace CalamityMod.CalPlayer if (hInferno) { - for (int x = 0; x < Main.maxNPCs; x++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[x].active && Main.npc[x].type == ModContent.NPCType()) - Main.npc[x].active = false; + if (n.type == ModContent.NPCType()) + n.active = false; } } @@ -1473,15 +1473,13 @@ namespace CalamityMod.CalPlayer // This also strikes the NPCs as a side effect if (gSabatonFalling) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - NPC n = Main.npc[i]; - // Ignore critters with the Guide to Critter Companionship if (Player.dontHurtCritters && NPCID.Sets.CountsAsCritter[n.type]) continue; - if (n.active && !n.dontTakeDamage && !n.friendly && n.Calamity().dashImmunityTime[Player.whoAmI] <= 0) + if (!n.dontTakeDamage && !n.friendly && n.Calamity().dashImmunityTime[Player.whoAmI] <= 0) { Rectangle npcHitbox = n.getRect(); if ((Player.getRect()).Intersects(npcHitbox) && (n.noTileCollide || Collision.CanHit(Player.position, Player.width, Player.height, n.position, n.width, n.height))) @@ -2269,10 +2267,9 @@ namespace CalamityMod.CalPlayer if (fBarrier || (aquaticHeart && NPC.downedBoss3)) { SoundEngine.PlaySound(SoundID.Item27, Player.Center); - for (int m = 0; m < Main.maxNPCs; m++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[m]; - if (!npc.active || npc.friendly || npc.dontTakeDamage) + if (npc.friendly || npc.dontTakeDamage) continue; float npcDist = (npc.Center - Player.Center).Length(); @@ -2296,10 +2293,9 @@ namespace CalamityMod.CalPlayer // and also doesn't have random chance (why does Brain of Confusion not guarantee confusion on hit) if (aBrain || amalgam) { - for (int m = 0; m < Main.maxNPCs; m++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[m]; - if (!npc.active || npc.friendly || npc.dontTakeDamage) + if (npc.friendly || npc.dontTakeDamage) continue; float npcDist = (npc.Center - Player.Center).Length(); @@ -2334,11 +2330,11 @@ namespace CalamityMod.CalPlayer if (Player.ownedProjectileCounts[ModContent.ProjectileType()] != 0) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach(Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && Main.projectile[i].owner == Player.whoAmI) + if (p.type == ModContent.ProjectileType() && p.owner == Player.whoAmI) { - Main.projectile[i].Kill(); + p.Kill(); break; } } diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 0dd1e07164..e7486c2ef0 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -452,10 +452,9 @@ namespace CalamityMod.CalPlayer float enemyDistance = maxProxRageDistance + 1f; float bossDistance = maxProxRageDistance + 1f; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc is null || npc.type == NPCID.None || !npc.IsAnEnemy() || !npc.Calamity().ProvidesProximityRage) + if (npc.type == NPCID.None || !npc.IsAnEnemy() || !npc.Calamity().ProvidesProximityRage) continue; // Take the longer of the two directions for the NPC's hitbox to be generous. @@ -719,10 +718,9 @@ namespace CalamityMod.CalPlayer sigilDamage = Player.ApplyArmorAccDamageBonusesTo(sigilDamage); bool brightenedSigil = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC target in Main.ActiveNPCs) { - NPC target = Main.npc[i]; - if (!target.active || !target.Hitbox.Intersects(sigilHitbox) || target.immortal || target.dontTakeDamage || target.townNPC || NPCID.Sets.ActsLikeTownNPC[target.type] || NPCID.Sets.CountsAsCritter[target.type]) + if (!target.Hitbox.Intersects(sigilHitbox) || target.immortal || target.dontTakeDamage || target.townNPC || NPCID.Sets.ActsLikeTownNPC[target.type] || NPCID.Sets.CountsAsCritter[target.type]) continue; // Brighten the sigil because it is dealing damage. This can only happen once per hit event. @@ -734,7 +732,7 @@ namespace CalamityMod.CalPlayer // Create a direct strike to hit this specific NPC. var source = Player.GetSource_Accessory(FindAccessory(ModContent.ItemType())); - Projectile sigilStrike = Projectile.NewProjectileDirect(source, target.Center, Vector2.Zero, ModContent.ProjectileType(), sigilDamage, 0f, Player.whoAmI, i); + Projectile sigilStrike = Projectile.NewProjectileDirect(source, target.Center, Vector2.Zero, ModContent.ProjectileType(), sigilDamage, 0f, Player.whoAmI, target.whoAmI); // Enable crits by setting the sigil's damage class to be whatever the player's strongest damage class is. sigilStrike.DamageType = Player.GetBestClass(); @@ -863,24 +861,23 @@ namespace CalamityMod.CalPlayer { int bullseyeType = ModContent.ProjectileType(); List alreadyTargetedNPCs = new List(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != bullseyeType || !Main.projectile[i].active || Main.projectile[i].owner != Player.whoAmI) + if (p.type != bullseyeType || p.owner != Player.whoAmI) continue; - alreadyTargetedNPCs.Add((int)Main.projectile[i].ai[0]); + alreadyTargetedNPCs.Add((int)p.ai[0]); } - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC target in Main.ActiveNPCs) { - NPC target = Main.npc[i]; - if (!target.active || target.friendly || target.lifeMax < 5 || alreadyTargetedNPCs.Contains(i) || target.realLife >= 0 || + if (target.friendly || target.lifeMax < 5 || alreadyTargetedNPCs.Contains(target.whoAmI) || target.realLife >= 0 || target.dontTakeDamage || target.immortal || target.townNPC || NPCID.Sets.ActsLikeTownNPC[target.type] || NPCID.Sets.CountsAsCritter[target.type]) continue; var source = Player.GetSource_Accessory(FindAccessory(ModContent.ItemType())); - if (Main.myPlayer == Player.whoAmI && Main.npc[i].WithinRange(Player.Center, 2000f)) - Projectile.NewProjectile(source, Main.npc[i].Center, Vector2.Zero, bullseyeType, 0, 0f, Player.whoAmI, i); + if (Main.myPlayer == Player.whoAmI && target.WithinRange(Player.Center, 2000f)) + Projectile.NewProjectile(source, target.Center, Vector2.Zero, bullseyeType, 0, 0f, Player.whoAmI, target.whoAmI); if (spiritOriginBullseyeShootCountdown <= 0) spiritOriginBullseyeShootCountdown = 45; } @@ -1142,10 +1139,9 @@ namespace CalamityMod.CalPlayer if (Player.ownedProjectileCounts[ModContent.ProjectileType()] < 6 && Main.myPlayer == Player.whoAmI) { bool[] tentaclesPresent = new bool[6]; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - Projectile projectile = Main.projectile[i]; - if (projectile.active && projectile.type == ModContent.ProjectileType() && projectile.owner == Main.myPlayer && projectile.ai[1] >= 0f && projectile.ai[1] < 6f) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Main.myPlayer && projectile.ai[1] >= 0f && projectile.ai[1] < 6f) tentaclesPresent[(int)projectile.ai[1]] = true; } @@ -1250,14 +1246,13 @@ namespace CalamityMod.CalPlayer { float maxDistance = 300f; int target = -1; - for (int npcIndex = 0; npcIndex < Main.maxNPCs; npcIndex++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[npcIndex]; float targetDist = Vector2.Distance(npc.Center, Player.Center); if (targetDist < maxDistance && npc.Calamity().arcZapCooldown == 0 && npc.CanBeChasedBy()) { maxDistance = targetDist; - target = npcIndex; + target = npc.whoAmI; } } @@ -1853,10 +1848,9 @@ namespace CalamityMod.CalPlayer { if (Main.rand.NextBool(5)) { - for (int l = 0; l < Main.maxNPCs; l++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[l]; - if (!npc.active || npc.friendly || npc.damage <= 0 || npc.dontTakeDamage) + if (npc.friendly || npc.damage <= 0 || npc.dontTakeDamage) continue; if (!npc.buffImmune[buffType] && Vector2.Distance(Player.Center, npc.Center) <= freezeDist) @@ -1902,10 +1896,9 @@ namespace CalamityMod.CalPlayer // Ceaseless Hunger Potion buff if (ceaselessHunger) { - for (int j = 0; j < Main.maxItems; j++) + foreach (Item item in Main.ActiveItems) { - Item item = Main.item[j]; - if (item.active && item.noGrabDelay == 0 && item.playerIndexTheItemIsReservedFor == Player.whoAmI) + if (item.noGrabDelay == 0 && item.playerIndexTheItemIsReservedFor == Player.whoAmI) { item.beingGrabbed = true; if (Player.Center.X > item.Center.X) @@ -2783,10 +2776,9 @@ namespace CalamityMod.CalPlayer { if (Main.netMode != NetmodeID.MultiplayerClient && !areThereAnyDamnBosses) { - for (int m = 0; m < Main.maxNPCs; m++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[m]; - if (!npc.active || npc.friendly || npc.dontTakeDamage) + if (npc.friendly || npc.dontTakeDamage) continue; float distance = (npc.Center - Player.Center).Length(); if (distance < 120f) @@ -3140,14 +3132,13 @@ namespace CalamityMod.CalPlayer var source = Player.GetSource_FromThis(TarragonHeadSummon.LifeAuraEntitySourceContext); float range = 300f; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.dontTakeDamage) + if (npc.friendly || npc.dontTakeDamage) continue; if (Vector2.Distance(Player.Center, npc.Center) <= range) - Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Player.whoAmI, i); + Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Player.whoAmI, npc.whoAmI); } } } @@ -3168,14 +3159,13 @@ namespace CalamityMod.CalPlayer var source = Player.GetSource_ItemUse(Player.ActiveItem()); float range = 200f; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.damage <= 0 || npc.dontTakeDamage) + if (npc.friendly || npc.damage <= 0 || npc.dontTakeDamage) continue; if (Vector2.Distance(Player.Center, npc.Center) <= range) - Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Player.whoAmI, i); + Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Player.whoAmI, npc.whoAmI); // Occasionally spawn cute sparks so it looks like an electrical aura if (Main.rand.NextBool(10)) @@ -3211,17 +3201,16 @@ namespace CalamityMod.CalPlayer var source = Player.GetSource_FromThis(HydrothermicArmor.InfernoPotionEntitySourceContext); float range = 300f; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.damage <= 0 || npc.dontTakeDamage) + if (npc.friendly || npc.damage <= 0 || npc.dontTakeDamage) continue; if (Vector2.Distance(Player.Center, npc.Center) <= range) { npc.AddBuff(ModContent.BuffType(), 120); if (brimLoreInfernoTimer == 0) - Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Player.whoAmI, i); + Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Player.whoAmI, npc.whoAmI); } } } @@ -3381,11 +3370,11 @@ namespace CalamityMod.CalPlayer { if (Player.whoAmI == Main.myPlayer) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && Main.projectile[i].owner == Player.whoAmI) + if (p.type == ModContent.ProjectileType() && p.owner == Player.whoAmI) { - Main.projectile[i].Kill(); + p.Kill(); break; } } @@ -3438,12 +3427,12 @@ namespace CalamityMod.CalPlayer if (Player.whoAmI == Main.myPlayer) { int auraType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != auraType || !Main.projectile[i].active || Main.projectile[i].owner != Player.whoAmI) + if (p.type != auraType || p.owner != Player.whoAmI) continue; - Main.projectile[i].Kill(); + p.Kill(); break; } } @@ -3461,12 +3450,12 @@ namespace CalamityMod.CalPlayer else if (Player.whoAmI == Main.myPlayer) { int shieldType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != shieldType || !Main.projectile[i].active || Main.projectile[i].owner != Player.whoAmI) + if (p.type != shieldType || p.owner != Player.whoAmI) continue; - Main.projectile[i].Kill(); + p.Kill(); break; } } @@ -4217,10 +4206,9 @@ namespace CalamityMod.CalPlayer if (Main.myPlayer != Player.whoAmI) return; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc is null || !npc.active || npc.type != ModContent.NPCType()) + if (npc.type != ModContent.NPCType()) continue; bool holdingsol = ((Player.HeldItem.type >= ItemID.GreenSolution && Player.HeldItem.type <= ItemID.RedSolution) || (Player.HeldItem.type >= ItemID.SandSolution && Player.HeldItem.type <= ItemID.DirtSolution) || Player.HeldItem.type == ModContent.ItemType()); @@ -4316,7 +4304,7 @@ namespace CalamityMod.CalPlayer } } if (Main.netMode == NetmodeID.Server) - NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, i); + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, npc.whoAmI); } } } diff --git a/CalPlayer/CalamityPlayerOnHit.cs b/CalPlayer/CalamityPlayerOnHit.cs index a2d6e81a56..1272e6e3f9 100644 --- a/CalPlayer/CalamityPlayerOnHit.cs +++ b/CalPlayer/CalamityPlayerOnHit.cs @@ -1455,10 +1455,9 @@ namespace CalamityMod.CalPlayer float lowestHealthCheck = 0f; int healTarget = Player.whoAmI; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player otherPlayer in Main.ActivePlayers) { - Player otherPlayer = Main.player[i]; - if (otherPlayer.active && !otherPlayer.dead && ((!Player.hostile && !otherPlayer.hostile) || Player.team == otherPlayer.team)) + if (!otherPlayer.dead && ((!Player.hostile && !otherPlayer.hostile) || Player.team == otherPlayer.team)) { float playerDist = Vector2.Distance(target.Center, otherPlayer.Center); if (playerDist < BalancingConstants.LifeStealRange && (otherPlayer.statLifeMax2 - otherPlayer.statLife) > lowestHealthCheck) @@ -1506,7 +1505,7 @@ namespace CalamityMod.CalPlayer if (playerDist < BalancingConstants.LifeStealRange && (otherPlayer.statLifeMax2 - otherPlayer.statLife) > lowestHealthCheck) { lowestHealthCheck = otherPlayer.statLifeMax2 - otherPlayer.statLife; - healTarget = i; + healTarget = otherPlayer.whoAmI; } } } diff --git a/CalPlayer/DrawLayers/AndromedaMechLayer.cs b/CalPlayer/DrawLayers/AndromedaMechLayer.cs index 49ec26064a..e15b7c80df 100644 --- a/CalPlayer/DrawLayers/AndromedaMechLayer.cs +++ b/CalPlayer/DrawLayers/AndromedaMechLayer.cs @@ -34,9 +34,9 @@ namespace CalamityMod.CalPlayer.DrawLayers int robot = -1; int andromedaMechID = ModContent.ProjectileType(); - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == andromedaMechID && Main.projectile[i].owner == drawPlayer.whoAmI) + if (p.type == andromedaMechID && p.owner == drawPlayer.whoAmI) { robot = i; break; diff --git a/CalamityConditions.cs b/CalamityConditions.cs new file mode 100644 index 0000000000..8cce78968e --- /dev/null +++ b/CalamityConditions.cs @@ -0,0 +1,105 @@ +using System; +using CalamityMod.World; +using Terraria; +using Terraria.Localization; + +namespace CalamityMod +{ + public static class CalamityConditions + { + private static Condition Create(string key, Func predicate) + { + return new Condition( + Language.GetText($"Mods.CalamityMod.Condition.{key}"), + predicate + ); + } + + // + // Config based conditions + // + + public static readonly Condition PotionSellingConfig = Create("PotionConfig", () => CalamityConfig.Instance.PotionSelling); + + // + // Player conditions + // + + public static readonly Condition PlayerHasRogueArmor = Create("HasRogueArmor", () => Main.LocalPlayer.Calamity().rogueStealthMax > 0f && Main.LocalPlayer.Calamity().wearingRogueArmor); + public static readonly Condition PlayerHasWings = Create("HasWings", () => Main.LocalPlayer.wingTimeMax > 0); + public static readonly Condition PlayerAlcoholPoisoned = Create("AlcoholPoison", () => Main.LocalPlayer.Calamity().alcoholPoisoning); + + // + // NPC conditions + // + + /// Don't use this. It's always `true`. + public static readonly Condition TrasherTextCondition = Create("Drops.TrasherKill", () => true); + + // + // Calamity Event Flag conditions + // + + public static readonly Condition DownedAcidRainT1 = Create("Drops.DownedT1AR", () => DownedBossSystem.downedEoCAcidRain); + public static readonly Condition DownedAcidRainT2 = Create("Drops.DownedT2AR", () => DownedBossSystem.downedAquaticScourgeAcidRain); + + // + // Calamity Boss Flag conditions + // + + public static readonly Condition DownedDesertScourge = Create("Drops.DownedDS", () => DownedBossSystem.downedDesertScourge); + public static readonly Condition DownedCrabulon = Create("Drops.DownedCrabulon", () => DownedBossSystem.downedDesertScourge); + public static readonly Condition DownedHiveMind = Create("Drops.DownedHM", () => DownedBossSystem.downedHiveMind); + public static readonly Condition DownedPerforator = Create("Drops.DownedPerfs", () => DownedBossSystem.downedPerforator); + public static readonly Condition DownedSlimeGod = Create("Drops.DownedSG", () => DownedBossSystem.downedSlimeGod); + public static readonly Condition DownedCryogen = Create("Drops.DownedCryo", () => DownedBossSystem.downedCryogen); + public static readonly Condition DownedAquaticScourge = Create("Drops.DownedAS", () => DownedBossSystem.downedAquaticScourge); + public static readonly Condition DownedBrimstoneElemental = Create("Drops.DownedBrim", () => DownedBossSystem.downedBrimstoneElemental); + public static readonly Condition DownedCalamitasClone = Create("Drops.DownedCal", () => DownedBossSystem.downedCalamitasClone); + public static readonly Condition DownedLeviathan = Create("Drops.DownedLebi", () => DownedBossSystem.downedLeviathan); + public static readonly Condition DownedAstrumAureus = Create("Drops.DownedAureus", () => DownedBossSystem.downedAstrumAureus); + public static readonly Condition DownedPlaguebringer = Create("Drops.DownedPBG", () => DownedBossSystem.downedPlaguebringer); + public static readonly Condition DownedRavager = Create("Drops.DownedRav", () => DownedBossSystem.downedRavager); + public static readonly Condition DownedAstrumDeus = Create("Drops.DownedAD", () => DownedBossSystem.downedAstrumDeus); + public static readonly Condition DownedGuardians = Create("Drops.DownedGuard", () => DownedBossSystem.downedGuardians); + public static readonly Condition DownedBumblebird = Create("Drops.DownedBirb", () => DownedBossSystem.downedDragonfolly); + public static readonly Condition DownedProvidence = Create("Drops.DownedProv", () => DownedBossSystem.downedProvidence); + public static readonly Condition DownedSignus = Create("Drops.DownedSig", () => DownedBossSystem.downedSignus); + public static readonly Condition DownedStormWeaver = Create("Drops.DownedSW", () => DownedBossSystem.downedStormWeaver); + public static readonly Condition DownedCeaselessVoid = Create("Drops.DownedCV", () => DownedBossSystem.downedCeaselessVoid); + public static readonly Condition DownedPolterghast = Create("Drops.DownedPolter", () => DownedBossSystem.downedPolterghast); + public static readonly Condition DownedOldDuke = Create("Drops.DownedOD", () => DownedBossSystem.downedBoomerDuke); + public static readonly Condition DownedDevourerOfGods = Create("Drops.DownedDoG", () => DownedBossSystem.downedDoG); + public static readonly Condition DownedYharon = Create("Drops.DownedYharon", () => DownedBossSystem.downedYharon); + public static readonly Condition DownedExoMechs = Create("Drops.DownedExos", () => DownedBossSystem.downedExoMechs); + public static readonly Condition DownedSupremeCalamitas = Create("Drops.DownedSCal", () => DownedBossSystem.downedCalamitas); + public static readonly Condition DownedPrimordialWyrm = Create("Drops.DownedAEW", () => DownedBossSystem.downedPrimordialWyrm); + public static readonly Condition DownedClam = Create("Drops.DownedClam", () => DownedBossSystem.downedCLAM); + public static readonly Condition DownedBuffedClam = Create("Drops.DownedClamHM", () => DownedBossSystem.downedCLAMHardMode); + public static readonly Condition DownedGreatSandShark = Create("Drops.DownedGSS", () => DownedBossSystem.downedGSS); + + // Mixed + public static readonly Condition DownedHiveMindOrPerforator = Create("Drops.DownedHMOrPerfs",() => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator); + public static readonly Condition DownedCalamitasCloneOrPlantera = Create("Drops.DownedCalPlant", () => DownedBossSystem.downedCalamitasClone || Condition.DownedPlantera.IsMet()); + + // Vanilla + public static readonly Condition DownedBetsy = Create("Drops.DownedBetsy", () => DownedBossSystem.downedBetsy); + + // + // Calamity Biome conditions + // + + public static readonly Condition InAstral = Create("InAstral", () => Main.LocalPlayer.Calamity().ZoneAstral); + public static readonly Condition InCrag = Create("InCrag", () => Main.LocalPlayer.Calamity().ZoneCalamity); + public static readonly Condition InSulph = Create("InSulph", () => Main.LocalPlayer.Calamity().ZoneSulphur); + public static readonly Condition InSunken = Create("InSunken", () => Main.LocalPlayer.Calamity().ZoneSunkenSea); + + // + // World based conditions + // + + public static readonly Condition InRevengeanceMode = Create("InRev", () => CalamityWorld.revenge); + public static readonly Condition InRevengeanceModeNotMasterMode = Create("InRev", () => !Main.masterMode && CalamityWorld.revenge); + public static readonly Condition InRevengeanceModeOrMasterMode = Create("InRevOrMM", () => Main.masterMode || CalamityWorld.revenge); + } +} diff --git a/CalamityMod.cs b/CalamityMod.cs index db4492d4f8..62b15634c1 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -92,13 +92,10 @@ namespace CalamityMod public static Texture2D AstralSurfaceCloseGlow; public static Texture2D AstralSurfaceMiddle; public static Texture2D AstralSurfaceMiddleGlow; - public static Texture2D AstralSurfaceFar; - public static Texture2D AstralSurfaceHorizon; // Astral Desert Sky/BG public static Texture2D AstralDesertSurfaceClose; public static Texture2D AstralDesertSurfaceMiddle; - public static Texture2D AstralDesertSurfaceFar; // Astral Snow Sky/BG public static Texture2D AstralSnowSurfaceMiddle; @@ -278,22 +275,19 @@ namespace CalamityMod { // Astral Sky/BG AstralSky = ModContent.Request("CalamityMod/Skies/AstralSky", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceFront = ModContent.Request("CalamityMod/Skies/AstralSurfaceFront", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceFrontGlow = ModContent.Request("CalamityMod/Skies/AstralSurfaceFrontGlow", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceClose = ModContent.Request("CalamityMod/Skies/AstralSurfaceClose", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceCloseGlow = ModContent.Request("CalamityMod/Skies/AstralSurfaceCloseGlow", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceMiddle = ModContent.Request("CalamityMod/Skies/AstralSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceMiddleGlow = ModContent.Request("CalamityMod/Skies/AstralSurfaceMiddleGlow", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceFar = ModContent.Request("CalamityMod/Skies/AstralSurfaceFar", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceHorizon = ModContent.Request("CalamityMod/Skies/AstralSurfaceHorizon", AssetRequestMode.ImmediateLoad).Value; + AstralSurfaceFront = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceFront", AssetRequestMode.ImmediateLoad).Value; + AstralSurfaceFrontGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceFrontGlow", AssetRequestMode.ImmediateLoad).Value; + AstralSurfaceClose = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceClose", AssetRequestMode.ImmediateLoad).Value; + AstralSurfaceCloseGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceCloseGlow", AssetRequestMode.ImmediateLoad).Value; + AstralSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; + AstralSurfaceMiddleGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceMiddleGlow", AssetRequestMode.ImmediateLoad).Value; - // Astral Desert Sky/BG - AstralDesertSurfaceClose = ModContent.Request("CalamityMod/Skies/AstralDesertSurfaceClose", AssetRequestMode.ImmediateLoad).Value; - AstralDesertSurfaceMiddle = ModContent.Request("CalamityMod/Skies/AstralDesertSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; - AstralDesertSurfaceFar = ModContent.Request("CalamityMod/Skies/AstralDesertSurfaceFar", AssetRequestMode.ImmediateLoad).Value; + //Astral Desert Sky/BG + AstralDesertSurfaceClose = ModContent.Request("CalamityMod/Backgrounds/AstralDesertSurfaceClose", AssetRequestMode.ImmediateLoad).Value; + AstralDesertSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralDesertSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; - // Astral Snow Sky/BG - AstralSnowSurfaceMiddle = ModContent.Request("CalamityMod/Skies/AstralSnowSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; + //Astral Snow Sky/BG + AstralSnowSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralSnowSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; // Sulpher Sea Sky/BG SulphurSeaSky = ModContent.Request("CalamityMod/Skies/SulphurSeaSky", AssetRequestMode.ImmediateLoad).Value; @@ -352,10 +346,6 @@ namespace CalamityMod SkyManager.Instance["CalamityMod:BrimstoneCrag"] = new BrimstoneCragSky(); SkyManager.Instance["CalamityMod:Astral"] = new AstralSky(); - SkyManager.Instance["CalamityMod:AstralSurface"] = new AstralSkySurface(); - SkyManager.Instance["CalamityMod:AstralDesert"] = new AstralSkyDesert(); - SkyManager.Instance["CalamityMod:AstralSnow"] = new AstralSkySnow(); - SkyManager.Instance["CalamityMod:MonolithAstral"] = new AstralMonolithSky(); SkyManager.Instance["CalamityMod:SulphurSea"] = new SulphurSeaSky(); SkyManager.Instance["CalamityMod:Cryogen"] = new CryogenSky(); SkyManager.Instance["CalamityMod:StormWeaverFlash"] = new StormWeaverFlashSky(); diff --git a/Events/AcidRainEvent.cs b/Events/AcidRainEvent.cs index 0536f96f59..a56fbe8ce2 100644 --- a/Events/AcidRainEvent.cs +++ b/Events/AcidRainEvent.cs @@ -65,10 +65,10 @@ namespace CalamityMod.Events { get { - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - if (Main.npc[i].active && (PossibleMinibossesAS.Select(miniboss => miniboss.Key).Contains(Main.npc[i].type) || - PossibleMinibossesPolter.Select(miniboss => miniboss.Key).Contains(Main.npc[i].type))) + if ((PossibleMinibossesAS.Select(miniboss => miniboss.Key).Contains(npc.type) || + PossibleMinibossesPolter.Select(miniboss => miniboss.Key).Contains(npc.type))) { return true; } @@ -107,14 +107,8 @@ namespace CalamityMod.Events { get { - int playerCount = 0; - for (int i = 0; i < Main.player.Length; i++) - { - if (Main.player[i].active) - { - playerCount++; - } - } + int playerCount = Main.CurrentFrameFlags.ActivePlayersCount; + if (DownedBossSystem.downedPolterghast) return (int)(Math.Log(playerCount + Math.E - 1) * 170f); else if (DownedBossSystem.downedAquaticScourge) @@ -189,12 +183,7 @@ namespace CalamityMod.Events if (AcidRainEventIsOngoing || (!NPC.downedBoss1 && !Main.hardMode && !DownedBossSystem.downedAquaticScourge) || BossRushEvent.BossRushActive) return; - int playerCount = 0; - for (int i = 0; i < Main.player.Length; i++) - { - if (Main.player[i].active) - playerCount++; - } + int playerCount = Main.CurrentFrameFlags.ActivePlayersCount; if (playerCount > 0) { @@ -243,12 +232,8 @@ namespace CalamityMod.Events if (!HasStartedAcidicDownpour) { int sulphSeaWidth = SulphurousSea.BiomeWidth; - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[playerIndex]; - if (!player.active) - continue; - // An artificial biome can be made, and therefore, the event could be started by an artificial biome. // While fighting the event in an artificial biome is not bad, having it be started by a patch of Sulphurous Sand // would definitely be strange. @@ -387,11 +372,9 @@ namespace CalamityMod.Events if ((int)Main.time == (int)(Main.nightLength - 1f) && !Main.dayTime && Main.rand.NextBool(increasedEventChance ? 3 : 300)) { bool shouldNotStartEvent = false; - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + foreach (Player player in Main.ActivePlayers) { - if (!Main.player[playerIndex].active) - continue; - if (Main.player[playerIndex].Calamity().noStupidNaturalARSpawns) + if (player.Calamity().noStupidNaturalARSpawns) { shouldNotStartEvent = true; break; @@ -407,9 +390,9 @@ namespace CalamityMod.Events // Attempt to force an Acid Rain immediately after the EoC is dead when someone wanders to the sea. if (NPC.downedBoss1 && !DownedBossSystem.downedEoCAcidRain && !HasBeenForceStartedByEoCDefeat) { - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + foreach (Player player in Main.ActivePlayers) { - if (Main.player[playerIndex].active && Main.player[playerIndex].Calamity().ZoneSulphur) + if (player.Calamity().ZoneSulphur) { HasBeenForceStartedByEoCDefeat = true; TryStartEvent(); diff --git a/Events/BossRushEvent.cs b/Events/BossRushEvent.cs index 628a809bcf..6da1815a4d 100644 --- a/Events/BossRushEvent.cs +++ b/Events/BossRushEvent.cs @@ -320,14 +320,10 @@ namespace CalamityMod.Events new Boss(ModContent.NPCType(), spawnContext: type => { - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[playerIndex]; - if (p is not null && p.active) - { - if (p.FindBuffIndex(ModContent.BuffType()) > -1) - p.ClearBuff(ModContent.BuffType()); - } + if (p.FindBuffIndex(ModContent.BuffType()) > -1) + p.ClearBuff(ModContent.BuffType()); } Player player = Main.player[ClosestPlayerToWorldCenter]; @@ -415,19 +411,15 @@ namespace CalamityMod.Events BossRushDialogueSystem.StartDialogue(BossRushDialoguePhase.TierOneComplete); // Teleport players to where they came from - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[playerIndex]; - if (p is not null && p.active) + if (p.Calamity().BossRushReturnPosition.HasValue) { - if (p.Calamity().BossRushReturnPosition.HasValue) - { - CalamityPlayer.ModTeleport(p, p.Calamity().BossRushReturnPosition.Value, false, TeleportationStyleID.TeleportationPotion); - p.Calamity().BossRushReturnPosition = null; - } + CalamityPlayer.ModTeleport(p, p.Calamity().BossRushReturnPosition.Value, false, TeleportationStyleID.TeleportationPotion); p.Calamity().BossRushReturnPosition = null; - SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center); } + p.Calamity().BossRushReturnPosition = null; + SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center); } }, // Plantera: End of Tier 2 @@ -628,13 +620,9 @@ namespace CalamityMod.Events public static void End() { // Reset BossRushReturnPosition - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[playerIndex]; - if (p is not null && p.active) - { - p.Calamity().BossRushReturnPosition = null; - } + p.Calamity().BossRushReturnPosition = null; } if (Main.netMode == NetmodeID.SinglePlayer) @@ -735,18 +723,14 @@ namespace CalamityMod.Events CalamityUtils.KillAllHostileProjectiles(); HostileProjectileKillCounter = 3; - for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[playerIndex]; - if (p is not null && p.active) - { - p.Calamity().BossRushReturnPosition = p.Center; - Vector2? underworld = CalamityPlayer.GetUnderworldPosition(p); - if (!underworld.HasValue) - break; - CalamityPlayer.ModTeleport(p, underworld.Value, false, TeleportationStyleID.TeleportationPotion); - SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center); - } + p.Calamity().BossRushReturnPosition = p.Center; + Vector2? underworld = CalamityPlayer.GetUnderworldPosition(p); + if (!underworld.HasValue) + break; + CalamityPlayer.ModTeleport(p, underworld.Value, false, TeleportationStyleID.TeleportationPotion); + SoundEngine.PlaySound(TeleportSound with { Volume = 1.6f }, p.Center); } } @@ -794,12 +778,12 @@ namespace CalamityMod.Events { if (Main.netMode != NetmodeID.MultiplayerClient) { - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player p in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (p.dead) continue; - int animation = Projectile.NewProjectile(new EntitySource_WorldEvent(), Main.player[i].Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, i); + int animation = Projectile.NewProjectile(new EntitySource_WorldEvent(), p.Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, p.whoAmI); if (Main.projectile.IndexInRange(animation)) Main.projectile[animation].ai[0] = tier; } diff --git a/Graphics/Primitives/PrimitivePixelationSystem.cs b/Graphics/Primitives/PrimitivePixelationSystem.cs index 27a40a1efd..19d5fb1b5c 100644 --- a/Graphics/Primitives/PrimitivePixelationSystem.cs +++ b/Graphics/Primitives/PrimitivePixelationSystem.cs @@ -65,12 +65,10 @@ namespace CalamityMod.Graphics.Primitives var afterProjectiles = new List(); // Check every active projectile. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - // If the projectile is active, a mod projectile, and uses the interface, add it to the list of primitives to draw this frame. - if (projectile.active && projectile.ModProjectile != null && projectile.ModProjectile is IPixelatedPrimitiveRenderer pixelPrimitiveProjectile) + if (projectile.ModProjectile != null && projectile.ModProjectile is IPixelatedPrimitiveRenderer pixelPrimitiveProjectile) { var listToUse = pixelPrimitiveProjectile.LayerToRenderTo switch { @@ -84,12 +82,10 @@ namespace CalamityMod.Graphics.Primitives } // Check every active NPC. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - var npc = Main.npc[i]; - // If the NPC is active, a mod NPC, and uses the interface, add it to the list of primitives to draw this frame. - if (npc.active && npc.ModNPC != null && npc.ModNPC is IPixelatedPrimitiveRenderer pixelPrimitiveNPC) + if (npc.ModNPC != null && npc.ModNPC is IPixelatedPrimitiveRenderer pixelPrimitiveNPC) { var listToUse = pixelPrimitiveNPC.LayerToRenderTo switch { diff --git a/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs b/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs index 2f6ee9af3f..9fdab1f84a 100644 --- a/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs +++ b/Graphics/Renderers/CalamityRenderers/MiracleBlightRenderer.cs @@ -89,14 +89,12 @@ namespace CalamityMod.Graphics.Renderers.CalamityRenderers ActuallyDoPreDraw = true; // Draw every npc to a single target that should have the miracle blight visual. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { // Extra check to ensure that index errors will not occur. If not in range, something has gone wrong and the loop should terminate. - if (!Main.npc.IndexInRange(i)) + if (!Main.npc.IndexInRange(npc.whoAmI)) break; - NPC npc = Main.npc[i]; - if (ValidToDraw(npc)) Main.instance.DrawNPC(npc.whoAmI, npc.behindTiles); } diff --git a/ILEditing/ILHelperMethods.cs b/ILEditing/ILHelperMethods.cs index bd8175fb1f..01f2379f0e 100644 --- a/ILEditing/ILHelperMethods.cs +++ b/ILEditing/ILHelperMethods.cs @@ -64,7 +64,7 @@ namespace CalamityMod.ILEditing SoundEngine.PlaySound(SoundID.DoorClosed, new Vector2(doorX * 16, doorY * 16)); return true; } - + private static Texture2D SelectLavaTexture(Texture2D initialTexture, LiquidTileType type) { // Use the initial texture if it isn't lava. diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 37bdeebdbd..fb4fe1510e 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -736,22 +736,16 @@ namespace CalamityMod.ILEditing Main.spriteBatch.SetBlendState(BlendState.Additive); // Draw Projectiles. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (!Main.projectile[i].active) - continue; - - if (Main.projectile[i].ModProjectile is IAdditiveDrawer d) + if (p.ModProjectile is IAdditiveDrawer d) d.AdditiveDraw(Main.spriteBatch); } // Draw NPCs. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!Main.npc[i].active) - continue; - - if (Main.npc[i].ModNPC is IAdditiveDrawer d) + if (n.ModNPC is IAdditiveDrawer d) d.AdditiveDraw(Main.spriteBatch); } diff --git a/ILEditing/VanillaStupidityFixingILChanges.cs b/ILEditing/VanillaStupidityFixingILChanges.cs index 11e06f825f..9a430ec383 100644 --- a/ILEditing/VanillaStupidityFixingILChanges.cs +++ b/ILEditing/VanillaStupidityFixingILChanges.cs @@ -271,7 +271,7 @@ namespace CalamityMod.ILEditing // Sync the color changes. if (colorWasChanged) - NetMessage.SendData(MessageID.ItemTweaker, -1, -1, null, itemID, 1f); + NetMessage.SendData(MessageID.ItemTweaker, -1, -1, null, itemIndex, 1f); } #endregion Color Blighted Gel diff --git a/Items/Accessories/NebulousCore.cs b/Items/Accessories/NebulousCore.cs index fcbb9e69d8..a9ead56f4f 100644 --- a/Items/Accessories/NebulousCore.cs +++ b/Items/Accessories/NebulousCore.cs @@ -39,9 +39,9 @@ namespace CalamityMod.Items.Accessories if (Main.rand.NextBool(15)) { int numProj = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].type == ModContent.ProjectileType()) + if (p.owner == player.whoAmI && p.type == ModContent.ProjectileType()) { numProj++; } diff --git a/Items/Accessories/ProfanedSoulArtifact.cs b/Items/Accessories/ProfanedSoulArtifact.cs index 1823d0a29b..21905aa701 100644 --- a/Items/Accessories/ProfanedSoulArtifact.cs +++ b/Items/Accessories/ProfanedSoulArtifact.cs @@ -38,10 +38,9 @@ namespace CalamityMod.Items.Accessories get { bool result = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); @@ -118,10 +117,9 @@ namespace CalamityMod.Items.Accessories // Visibility is not net synced, for example. bool alreadyDrawnShieldForPlayer = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); @@ -135,6 +133,7 @@ namespace CalamityMod.Items.Accessories // Scale the shield is drawn at. // The "i" parameter is to make different player's shields not be perfectly synced. + int i = player.whoAmI; float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + i * 0.2f)); if (!alreadyDrawnShieldForPlayer) diff --git a/Items/Accessories/ProfanedSoulCrystal.cs b/Items/Accessories/ProfanedSoulCrystal.cs index e04ec73a75..926771a180 100644 --- a/Items/Accessories/ProfanedSoulCrystal.cs +++ b/Items/Accessories/ProfanedSoulCrystal.cs @@ -42,10 +42,9 @@ namespace CalamityMod.Items.Accessories get { bool result = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); diff --git a/Items/Accessories/RoverDrive.cs b/Items/Accessories/RoverDrive.cs index 92b08066ed..f2669eef54 100644 --- a/Items/Accessories/RoverDrive.cs +++ b/Items/Accessories/RoverDrive.cs @@ -38,11 +38,10 @@ namespace CalamityMod.Items.Accessories get { bool result = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) - continue; + if (player.outOfRange || player.dead) + continue; CalamityPlayer modPlayer = player.Calamity(); @@ -112,10 +111,9 @@ namespace CalamityMod.Items.Accessories // Visibility is not net synced, for example. bool alreadyDrawnShieldForPlayer = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); @@ -127,7 +125,7 @@ namespace CalamityMod.Items.Accessories continue; // The shield very gently grows and shrinks - float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + i * 0.2f)); + float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + player.whoAmI * 0.2f)); if (!alreadyDrawnShieldForPlayer) { diff --git a/Items/Accessories/TheCamper.cs b/Items/Accessories/TheCamper.cs index 430535724a..1d77244faf 100644 --- a/Items/Accessories/TheCamper.cs +++ b/Items/Accessories/TheCamper.cs @@ -58,13 +58,12 @@ namespace CalamityMod.Items.Accessories if (auraCounter == 9) { auraCounter = 0; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.IsAnEnemy() && !npc.dontTakeDamage && Vector2.Distance(player.Center, npc.Center) <= range) { int campingFireDamage = (int)player.GetBestClassDamage().ApplyTo(Main.rand.Next(20, 41)); - Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), campingFireDamage, 0f, player.whoAmI, i); + Projectile.NewProjectileDirect(source, npc.Center, Vector2.Zero, ModContent.ProjectileType(), campingFireDamage, 0f, player.whoAmI, npc.whoAmI); } } } diff --git a/Items/Accessories/TheSponge.cs b/Items/Accessories/TheSponge.cs index 16fe75addd..a58d372c0b 100644 --- a/Items/Accessories/TheSponge.cs +++ b/Items/Accessories/TheSponge.cs @@ -47,10 +47,9 @@ namespace CalamityMod.Items.Accessories get { bool result = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); @@ -178,10 +177,9 @@ namespace CalamityMod.Items.Accessories // Visibility is not net synced, for example. bool alreadyDrawnShieldForPlayer = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); @@ -194,6 +192,7 @@ namespace CalamityMod.Items.Accessories // Scale the shield is drawn at. The Sponge shield gently grows and shrinks; it should be largely imperceptible. // The "i" parameter is to make different player's shields not be perfectly synced. + int i = player.whoAmI; float baseScale = 0.155f; float maxExtraScale = 0.025f; float extraScalePulseInterpolant = MathF.Pow(4f, MathF.Sin(Main.GlobalTimeWrappedHourly * 0.791f + i) - 1); diff --git a/Items/Accessories/ToxicHeart.cs b/Items/Accessories/ToxicHeart.cs index b5cbd57c43..ee4b89c267 100644 --- a/Items/Accessories/ToxicHeart.cs +++ b/Items/Accessories/ToxicHeart.cs @@ -40,9 +40,8 @@ namespace CalamityMod.Items.Accessories { if (random == 0) { - for (int l = 0; l < Main.maxNPCs; l++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[l]; if (nPC.IsAnEnemy() && !nPC.dontTakeDamage && !nPC.buffImmune[plagueDebuff] && Vector2.Distance(player.Center, nPC.Center) <= 300f) { if (nPC.FindBuffIndex(plagueDebuff) == -1) @@ -53,7 +52,7 @@ namespace CalamityMod.Items.Accessories { if (player.whoAmI == Main.myPlayer) { - Projectile.NewProjectileDirect(source, nPC.Center, Vector2.Zero, ModContent.ProjectileType(), auraDamage, 0f, player.whoAmI, l); + Projectile.NewProjectileDirect(source, nPC.Center, Vector2.Zero, ModContent.ProjectileType(), auraDamage, 0f, player.whoAmI, nPC.whoAmI); } } } diff --git a/Items/Accessories/WarbanneroftheSun.cs b/Items/Accessories/WarbanneroftheSun.cs index 3b16c87ca2..ff2003d17f 100644 --- a/Items/Accessories/WarbanneroftheSun.cs +++ b/Items/Accessories/WarbanneroftheSun.cs @@ -49,26 +49,24 @@ namespace CalamityMod.Items.Accessories float bonus = 0f; int closestNPC = -1; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[i]; if (nPC.IsAnEnemy() && !nPC.dontTakeDamage) { - closestNPC = i; + closestNPC = nPC.whoAmI; break; } } float distance = -1f; - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[j]; if (nPC.IsAnEnemy() && !nPC.dontTakeDamage) { float distance2 = Math.Abs(nPC.position.X + (float)(nPC.width / 2) - (player.position.X + (float)(player.width / 2))) + Math.Abs(nPC.position.Y + (float)(nPC.height / 2) - (player.position.Y + (float)(player.height / 2))); if (distance == -1f || distance2 < distance) { distance = distance2; - closestNPC = j; + closestNPC = nPC.whoAmI; } } } diff --git a/Items/Accessories/WulfrumAcrobaticsPack.cs b/Items/Accessories/WulfrumAcrobaticsPack.cs index 0558fdda00..78fc5d2339 100644 --- a/Items/Accessories/WulfrumAcrobaticsPack.cs +++ b/Items/Accessories/WulfrumAcrobaticsPack.cs @@ -361,10 +361,9 @@ namespace CalamityMod.Items.Accessories if (bestGrapplePos != Point.Zero) { //Clear any hooks that might have been flying before then. - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (!p.active || p.owner != Player.whoAmI || p.type != ProjectileType()) + if (p.owner != Player.whoAmI || p.type != ProjectileType()) continue; if (p.ModProjectile is WulfrumHook) @@ -412,10 +411,9 @@ namespace CalamityMod.Items.Accessories if (triggersSet.Grapple && Player.releaseHook) { //Clear any previous non-wulfrum hooks / Any hooks that just got shot (should already be handled by the global proj - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (!p.active || p.owner != Player.whoAmI || p.aiStyle != 7 || p.type == ProjectileType()) + if (p.owner != Player.whoAmI || p.aiStyle != 7 || p.type == ProjectileType()) continue; p.Kill(); @@ -443,10 +441,9 @@ namespace CalamityMod.Items.Accessories //Jumping out of the hook if (triggersSet.Jump && Player.releaseJump) { - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (!p.active || p.owner != Player.whoAmI || p.type != ProjectileType()) + if (p.owner != Player.whoAmI || p.type != ProjectileType()) continue; //Only clear hooks that are attached to stuff diff --git a/Items/AlicornonaStick.cs b/Items/AlicornonaStick.cs index 9c3ce74d19..4f30a42f0b 100644 --- a/Items/AlicornonaStick.cs +++ b/Items/AlicornonaStick.cs @@ -26,9 +26,9 @@ namespace CalamityMod.Items { int offset = player.direction == 1 ? 5 : -Item.width - 5; Rectangle itemRect = new Rectangle((int)player.Center.X + offset, (int)player.position.Y - 10, Item.width, Item.height); - foreach (NPC npc in Main.npc) + foreach (NPC npc in Main.ActiveNPCs) { - if (npc.active && npc != null && !npc.dontTakeDamage && npc.type != ModContent.NPCType()) + if (!npc.dontTakeDamage && npc.type != ModContent.NPCType()) { if (itemRect.Intersects(npc.getRect())) { diff --git a/Items/Armor/LunicCorps/LunicCorpsHelmet.cs b/Items/Armor/LunicCorps/LunicCorpsHelmet.cs index f8c38f6f04..9333121be6 100644 --- a/Items/Armor/LunicCorps/LunicCorpsHelmet.cs +++ b/Items/Armor/LunicCorps/LunicCorpsHelmet.cs @@ -42,10 +42,9 @@ namespace CalamityMod.Items.Armor.LunicCorps get { bool result = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); @@ -116,10 +115,9 @@ namespace CalamityMod.Items.Armor.LunicCorps // Visibility is not net synced, for example. bool alreadyDrawnShieldForPlayer = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active || player.outOfRange || player.dead) + if (player.outOfRange || player.dead) continue; CalamityPlayer modPlayer = player.Calamity(); @@ -130,6 +128,7 @@ namespace CalamityMod.Items.Armor.LunicCorps // Scale the shield is drawn at. The Lunic Corps shield sticks very close to the body to mimic Halo and occasionally pulses. // The "i" parameter is to make different player's shields not be perfectly synced. + int i = player.whoAmI; float baseScale = 0.11f; float maxExtraScale = 0.013f; float extraScalePulseInterpolant = MathF.Pow(12f, MathF.Sin(Main.GlobalTimeWrappedHourly * 1.6f + i) - 1); diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index 3aa3cafddf..8c6efe6774 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -513,11 +513,11 @@ namespace CalamityMod.Items } if (item.type == ItemID.PearlwoodBow) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && (Main.projectile[i].type == ModContent.ProjectileType() || Main.projectile[i].type == ModContent.ProjectileType()) && Main.projectile[i].owner == player.whoAmI) + if ((p.type == ModContent.ProjectileType() || p.type == ModContent.ProjectileType()) && p.owner == player.whoAmI) { - Main.projectile[i].Kill(); + p.Kill(); } } for (int i = -8; i <= 8; i += 8) @@ -678,9 +678,9 @@ namespace CalamityMod.Items if (player.ActiveItem().type == ModContent.ItemType()) { bool hasBlades = false; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].localAI[1] == 0f) + if (p.type == ModContent.ProjectileType() && p.owner == player.whoAmI && p.localAI[1] == 0f) { hasBlades = true; break; @@ -688,22 +688,22 @@ namespace CalamityMod.Items } if (hasBlades) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].ModProjectile is IgneousBlade) + if (p.ModProjectile is IgneousBlade) { - if (Main.projectile[i].ModProjectile().Firing) + if (p.ModProjectile().Firing) continue; } - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].localAI[1] == 0f) + if (p.type == ModContent.ProjectileType() && p.owner == player.whoAmI && p.localAI[1] == 0f) { - Main.projectile[i].rotation = MathHelper.PiOver2 + MathHelper.PiOver4; - Main.projectile[i].velocity = Main.projectile[i].SafeDirectionTo(Main.MouseWorld, Vector2.UnitY) * 22f; - Main.projectile[i].rotation += Main.projectile[i].velocity.ToRotation(); - Main.projectile[i].ai[0] = 180f; - Main.projectile[i].ModProjectile().Firing = true; - Main.projectile[i].tileCollide = true; - Main.projectile[i].netUpdate = true; + p.rotation = MathHelper.PiOver2 + MathHelper.PiOver4; + p.velocity = p.SafeDirectionTo(Main.MouseWorld, Vector2.UnitY) * 22f; + p.rotation += p.velocity.ToRotation(); + p.ai[0] = 180f; + p.ModProjectile().Firing = true; + p.tileCollide = true; + p.netUpdate = true; } } } @@ -711,13 +711,13 @@ namespace CalamityMod.Items } if (player.ActiveItem().type == ModContent.ItemType() && player.ownedProjectileCounts[ModContent.ProjectileType()] == 0) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].ModProjectile is VoidConcentrationAura) + if (p.ModProjectile is VoidConcentrationAura) { - if (Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + if (p.owner == player.whoAmI) { - Main.projectile[i].ModProjectile().HandleRightClick(); + p.ModProjectile().HandleRightClick(); break; } } @@ -728,18 +728,18 @@ namespace CalamityMod.Items { bool canContinue = true; int count = 0; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && Main.projectile[i].owner == player.whoAmI) + if (p.type == ModContent.ProjectileType() && p.owner == player.whoAmI) { - if (Main.projectile[i].ai[1] > 1f) + if (p.ai[1] > 1f) { canContinue = false; break; } - else if (Main.projectile[i].ai[1] == 0f) + else if (p.ai[1] == 0f) { - if (((GlacialEmbracePointyThing)Main.projectile[i].ModProjectile).circlingPlayer) + if (((GlacialEmbracePointyThing)p.ModProjectile).circlingPlayer) count++; } } diff --git a/Items/CalamityGlobalItemTweaks.cs b/Items/CalamityGlobalItemTweaks.cs index 877fc5ffeb..4b73cceaba 100644 --- a/Items/CalamityGlobalItemTweaks.cs +++ b/Items/CalamityGlobalItemTweaks.cs @@ -601,6 +601,7 @@ namespace CalamityMod.Items { ItemID.SpicyPepper, Do(Value(Item.sellPrice(copper: 40))) }, { ItemID.Starfruit, Do(Value(Item.sellPrice(copper: 40))) }, { ItemID.PortableStool, Do(Value(Item.sellPrice(copper: 20))) }, // Step Stool + { ItemID.UncumberingStone, Do(Worthless) }, { ItemID.ViciousMushroom, Do(Worthless) }, { ItemID.VileMushroom, Do(Worthless) }, #endregion diff --git a/Items/Materials/WulfrumMetalScrap.cs b/Items/Materials/WulfrumMetalScrap.cs index bd5a55c188..7df22c2da1 100644 --- a/Items/Materials/WulfrumMetalScrap.cs +++ b/Items/Materials/WulfrumMetalScrap.cs @@ -44,9 +44,9 @@ namespace CalamityMod.Items.Materials bool closePlayer = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - if ((Main.player[i].Center - Item.Center).Length() < 1200 && Main.player[i].GetModPlayer().battery) + if ((player.Center - Item.Center).Length() < 1200 && player.GetModPlayer().battery) { closePlayer = true; break; diff --git a/Items/Mounts/AlicornMount.cs b/Items/Mounts/AlicornMount.cs index 7db85ed596..d1f8acca61 100644 --- a/Items/Mounts/AlicornMount.cs +++ b/Items/Mounts/AlicornMount.cs @@ -71,12 +71,12 @@ namespace CalamityMod.Items.Mounts public override void SetMount(Player player, ref bool skipDust) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - if (Main.npc[i].type == ModContent.NPCType()) + if (npc.type == ModContent.NPCType()) { - Main.npc[i].active = false; - Main.npc[i].netUpdate = true; + npc.active = false; + npc.netUpdate = true; break; } } @@ -85,12 +85,8 @@ namespace CalamityMod.Items.Mounts public override void Dismount(Player player, ref bool skipDust) { bool anyPlayerOnFabMount = false; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player2 in Main.ActivePlayers) { - Player player2 = Main.player[i]; - if (!player2.active) - continue; - // The player that is dismounting is technically not on the mount anymore. if (player2.Calamity().fab && player2.whoAmI != player.whoAmI) { diff --git a/Items/SummonItems/BloodyWormFood.cs b/Items/SummonItems/BloodyWormFood.cs index 67c13f0eea..c5847c9316 100644 --- a/Items/SummonItems/BloodyWormFood.cs +++ b/Items/SummonItems/BloodyWormFood.cs @@ -50,14 +50,13 @@ namespace CalamityMod.Items.SummonItems public override void AddRecipes() { - Condition downedPerfs = new(CalamityUtils.GetText("Condition.DownedPerfs"), () => DownedBossSystem.downedPerforator); - CreateRecipe(). - AddIngredient(ItemID.CrimtaneBar, 3). - AddIngredient(7). - AddIngredient(ItemID.Vertebrae, 13). - AddTile(TileID.DemonAltar). - AddDecraftCondition(downedPerfs). - Register(); + CreateRecipe() + .AddIngredient(ItemID.CrimtaneBar, 3) + .AddIngredient(7) + .AddIngredient(ItemID.Vertebrae, 13) + .AddTile(TileID.DemonAltar) + .AddDecraftCondition(CalamityConditions.DownedPerforator) + .Register(); } } } diff --git a/Items/SummonItems/Teratoma.cs b/Items/SummonItems/Teratoma.cs index 0266af0838..7f3fee2cbf 100644 --- a/Items/SummonItems/Teratoma.cs +++ b/Items/SummonItems/Teratoma.cs @@ -50,13 +50,12 @@ namespace CalamityMod.Items.SummonItems public override void AddRecipes() { - Condition downedHM = new(CalamityUtils.GetText("Condition.DownedHM"), () => DownedBossSystem.downedHiveMind); CreateRecipe(). AddIngredient(ItemID.DemoniteBar, 3). AddIngredient(7). AddIngredient(ItemID.RottenChunk, 13). AddTile(TileID.DemonAltar). - AddDecraftCondition(downedHM). + AddDecraftCondition(CalamityConditions.DownedHiveMind). Register(); } } diff --git a/Items/SuperDummy.cs b/Items/SuperDummy.cs index ed1859f390..2791c4a11f 100644 --- a/Items/SuperDummy.cs +++ b/Items/SuperDummy.cs @@ -30,16 +30,15 @@ namespace CalamityMod.Items public static void DeleteDummies() { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc.type == ModContent.NPCType() && npc.active) + if (npc.type == ModContent.NPCType()) { npc.life = 0; npc.active = false; if (Main.netMode == NetmodeID.Server) - NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, i); + NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, npc.whoAmI); } } } diff --git a/Items/Tools/WulfrumDiggingTurtle.cs b/Items/Tools/WulfrumDiggingTurtle.cs index 2150a3403e..f398ed1c3a 100644 --- a/Items/Tools/WulfrumDiggingTurtle.cs +++ b/Items/Tools/WulfrumDiggingTurtle.cs @@ -53,10 +53,9 @@ namespace CalamityMod.Items.Tools { bool explodedAny = false; - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (!p.active || p.owner != player.whoAmI || p.type != Item.shoot) + if (p.owner != player.whoAmI || p.type != Item.shoot) continue; p.ai[1] = 1f; diff --git a/Items/Weapons/DraedonsArsenal/PoleWarper.cs b/Items/Weapons/DraedonsArsenal/PoleWarper.cs index 83a8625855..857a3d038e 100644 --- a/Items/Weapons/DraedonsArsenal/PoleWarper.cs +++ b/Items/Weapons/DraedonsArsenal/PoleWarper.cs @@ -56,9 +56,9 @@ namespace CalamityMod.Items.Weapons.DraedonsArsenal float magnetCount = 0f; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == type && Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + if (p.type == type && p.owner == player.whoAmI) { magnetCount++; } @@ -67,12 +67,12 @@ namespace CalamityMod.Items.Weapons.DraedonsArsenal // Adjust the offset of all existing magnets such that they form a psuedo-circle. // This offset is used when determining where a magnet should move to relative to its true destination (such as the player or an enemy). int magnetIndex = 0; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == type && Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + if (p.type == type && p.owner == player.whoAmI) { - ((PoleWarperSummon)Main.projectile[i].ModProjectile).Time = 0f; - ((PoleWarperSummon)Main.projectile[i].ModProjectile).AngularOffset = MathHelper.TwoPi * magnetIndex / magnetCount; + ((PoleWarperSummon)p.ModProjectile).Time = 0f; + ((PoleWarperSummon)p.ModProjectile).AngularOffset = MathHelper.TwoPi * magnetIndex / magnetCount; magnetIndex++; } } diff --git a/Items/Weapons/Melee/BladecrestOathsword.cs b/Items/Weapons/Melee/BladecrestOathsword.cs index 066a995169..84639e8046 100644 --- a/Items/Weapons/Melee/BladecrestOathsword.cs +++ b/Items/Weapons/Melee/BladecrestOathsword.cs @@ -35,12 +35,12 @@ namespace CalamityMod.Items.Weapons.Melee public override bool CanUseItem(Player player) { int bladeProjID = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != bladeProjID || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + if (p.type != bladeProjID || p.owner != player.whoAmI) continue; - return Main.projectile[i].ModProjectile().PostSwingRepositionDelay <= 0f; + return p.ModProjectile().PostSwingRepositionDelay <= 0f; } return base.CanUseItem(player); diff --git a/Items/Weapons/Melee/CosmicShiv.cs b/Items/Weapons/Melee/CosmicShiv.cs index eb19732c3d..b7e5f75b48 100644 --- a/Items/Weapons/Melee/CosmicShiv.cs +++ b/Items/Weapons/Melee/CosmicShiv.cs @@ -43,4 +43,4 @@ namespace CalamityMod.Items.Weapons.Melee Register(); } } -} +} \ No newline at end of file diff --git a/Items/Weapons/Melee/Exoblade.cs b/Items/Weapons/Melee/Exoblade.cs index e4e2851a5e..3b47ca0784 100644 --- a/Items/Weapons/Melee/Exoblade.cs +++ b/Items/Weapons/Melee/Exoblade.cs @@ -100,15 +100,24 @@ namespace CalamityMod.Items.Weapons.Melee float state = 0; //If there are any exoblades in "stasis" after a bonk, the attack should be an empowered slash instead - if (Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ProjectileType() && n.ai[0] == 1 && n.ai[1] == 1 && n.timeLeft > LungeCooldown)) + bool empoweredSlash = false; + foreach (Projectile p in Main.ActiveProjectiles) + { + if (p.owner == player.whoAmI && p.type == Item.shoot && p.ai[0] == 1 && p.ai[1] == 1 && p.timeLeft > LungeCooldown) + { + empoweredSlash = true; + break; + } + } + + if (empoweredSlash) { state = 2; //Put all the "post bonk" stasised exoblades into regular cooldown for the right click ljunge - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (!p.active || p.owner != player.whoAmI || p.type != Item.shoot || p.ai[0] != 1 || p.ai[1] != 1) + if (p.owner != player.whoAmI || p.type != Item.shoot || p.ai[0] != 1 || p.ai[1] != 1) continue; p.timeLeft = LungeCooldown; diff --git a/Items/Weapons/Ranged/ChickenCannon.cs b/Items/Weapons/Ranged/ChickenCannon.cs index 889f57a40e..5d4b85312a 100644 --- a/Items/Weapons/Ranged/ChickenCannon.cs +++ b/Items/Weapons/Ranged/ChickenCannon.cs @@ -66,10 +66,9 @@ namespace CalamityMod.Items.Weapons.Ranged private void DetonateRockets(Player player) { - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (!p.active || p.owner != player.whoAmI || p.type != Item.shoot) + if (p.owner != player.whoAmI || p.type != Item.shoot) continue; // All rockets will instantly explode on the next frame and send packets to indicate as such. diff --git a/Items/Weapons/Ranged/ConferenceCall.cs b/Items/Weapons/Ranged/ConferenceCall.cs index 9c9fa464e9..a673f01eb8 100644 --- a/Items/Weapons/Ranged/ConferenceCall.cs +++ b/Items/Weapons/Ranged/ConferenceCall.cs @@ -58,16 +58,15 @@ namespace CalamityMod.Items.Weapons.Ranged int[] targets = new int[maxTargets]; int targetArrayIndex = 0; Rectangle rectangle = new Rectangle((int)player.Center.X - 960, (int)player.Center.Y - 540, 1920, 1080); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc.active && npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly && !npc.immortal) + if (npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly && !npc.immortal) { if (npc.Hitbox.Intersects(rectangle)) { if (targetArrayIndex < maxTargets) { - targets[targetArrayIndex] = i; + targets[targetArrayIndex] = npc.whoAmI; targetArrayIndex++; } else diff --git a/Items/Weapons/Ranged/Disseminator.cs b/Items/Weapons/Ranged/Disseminator.cs index 2583ef4355..a777199c5a 100644 --- a/Items/Weapons/Ranged/Disseminator.cs +++ b/Items/Weapons/Ranged/Disseminator.cs @@ -58,16 +58,15 @@ namespace CalamityMod.Items.Weapons.Ranged int[] targets = new int[maxTargets]; int targetArrayIndex = 0; Rectangle rectangle = new Rectangle((int)player.Center.X - 960, (int)player.Center.Y - 540, 1920, 1080); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc.active && npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly && !npc.immortal) + if (npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly && !npc.immortal) { if (npc.Hitbox.Intersects(rectangle)) { if (targetArrayIndex < maxTargets) { - targets[targetArrayIndex] = i; + targets[targetArrayIndex] = npc.whoAmI; targetArrayIndex++; } else diff --git a/Items/Weapons/Ranged/Hydra.cs b/Items/Weapons/Ranged/Hydra.cs index bdc1828846..d4a5d9ffa6 100644 --- a/Items/Weapons/Ranged/Hydra.cs +++ b/Items/Weapons/Ranged/Hydra.cs @@ -68,11 +68,11 @@ namespace CalamityMod.Items.Weapons.Ranged } else if (player.ActiveItem().type != Item.type || player.dead || !player.active) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { //Destroy all heads - if (Main.projectile[i].type == HeadID && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].active) - Main.projectile[i].Kill(); + if (p.type == HeadID && p.owner == player.whoAmI) + p.Kill(); } HeadSpawnTimer = 0; } @@ -111,11 +111,11 @@ namespace CalamityMod.Items.Weapons.Ranged Projectile.NewProjectile(source, newPos, spreadVelocity * spreadDirection, Item.shoot, damage, knockback, player.whoAmI); } - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { //Force all heads to shoot - if (Main.projectile[i].type == HeadID && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].active) - Main.projectile[i].ai[1] = 1f; + if (p.type == HeadID && p.owner == player.whoAmI) + p.ai[1] = 1f; } return false; } diff --git a/Items/Weapons/Ranged/NitroExpressRifle.cs b/Items/Weapons/Ranged/NitroExpressRifle.cs index fcaa47df0d..8964b33364 100644 --- a/Items/Weapons/Ranged/NitroExpressRifle.cs +++ b/Items/Weapons/Ranged/NitroExpressRifle.cs @@ -29,13 +29,13 @@ namespace CalamityMod.Items.Weapons.Ranged Item.useStyle = ItemUseStyleID.Shoot; Item.noMelee = true; Item.knockBack = 7.5f; - Item.value = CalamityGlobalItem.RarityPureGreenBuyPrice; + Item.value = CalamityGlobalItem.RarityLightRedBuyPrice; Item.UseSound = FireSound; Item.autoReuse = true; Item.shoot = ModContent.ProjectileType(); Item.shootSpeed = 12f; Item.useAmmo = AmmoID.Bullet; - Item.rare = ModContent.RarityType(); + Item.rare = ItemRarityID.LightRed; Item.Calamity().canFirePointBlankShots = true; } diff --git a/Items/Weapons/Rogue/Mycoroot.cs b/Items/Weapons/Rogue/Mycoroot.cs index dd6856efe8..72bfad6516 100644 --- a/Items/Weapons/Rogue/Mycoroot.cs +++ b/Items/Weapons/Rogue/Mycoroot.cs @@ -43,12 +43,11 @@ namespace CalamityMod.Items.Weapons.Rogue if (spore.WithinBounds(Main.maxProjectiles)) Main.projectile[spore].ai[1] = 1f; } - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player other in Main.ActivePlayers) { - Player other = Main.player[i]; - if (other is null || !other.active || other.dead) + if (other.dead) continue; - if ((other.team == player.team && player.team != 0) || player.whoAmI == i) + if ((other.team == player.team && player.team != 0) || player.whoAmI == other.whoAmI) { if (player.Distance(other.Center) <= 800f) other.AddBuff(ModContent.BuffType(), 900); diff --git a/Items/Weapons/Rogue/Nychthemeron.cs b/Items/Weapons/Rogue/Nychthemeron.cs index 8cf3c076fb..7a4119a894 100644 --- a/Items/Weapons/Rogue/Nychthemeron.cs +++ b/Items/Weapons/Rogue/Nychthemeron.cs @@ -32,10 +32,9 @@ namespace CalamityMod.Items.Weapons.Rogue public override bool AltFunctionUse(Player player) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.type == ModContent.ProjectileType() && p.owner == player.whoAmI) + if (p.type == Item.shoot && p.owner == player.whoAmI) { p.ai[0] = 1f; } @@ -93,12 +92,11 @@ namespace CalamityMod.Items.Weapons.Rogue // Ideally new projectiles will fill in the most recently vacated spots in the pattern int[] activeSlots = new int[10] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj.type == ModContent.ProjectileType() && proj.owner == player.whoAmI && proj.active && proj.localAI[0] == 0f && activeSlots[(int)proj.localAI[1]] == -1) + if (proj.type == ModContent.ProjectileType() && proj.owner == player.whoAmI && proj.localAI[0] == 0f && activeSlots[(int)proj.localAI[1]] == -1) { - activeSlots[(int)proj.localAI[1]] = i; + activeSlots[(int)proj.localAI[1]] = proj.whoAmI; } } diff --git a/Items/Weapons/Rogue/Sacrifice.cs b/Items/Weapons/Rogue/Sacrifice.cs index 09e611d9d1..d13814e54e 100644 --- a/Items/Weapons/Rogue/Sacrifice.cs +++ b/Items/Weapons/Rogue/Sacrifice.cs @@ -39,18 +39,18 @@ namespace CalamityMod.Items.Weapons.Rogue { if (player.altFunctionUse == 2) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != type || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + if (p.type != type || p.owner != player.whoAmI) continue; - if (Main.projectile[i].ai[0] != 1f) + if (p.ai[0] != 1f) continue; - NPC attachedNPC = Main.npc[(int)Main.projectile[i].ai[1]]; - Main.projectile[i].ai[0] = 2f; - Main.projectile[i].ModProjectile().AbleToHealOwner = attachedNPC.type != NPCID.TargetDummy && attachedNPC.type != ModContent.NPCType(); - Main.projectile[i].netUpdate = true; + NPC attachedNPC = Main.npc[(int)p.ai[1]]; + p.ai[0] = 2f; + p.ModProjectile().AbleToHealOwner = attachedNPC.type != NPCID.TargetDummy && attachedNPC.type != ModContent.NPCType(); + p.netUpdate = true; } //TODO: Add something here to avoid stealth being consumed return false; diff --git a/Items/Weapons/Rogue/SlickCane.cs b/Items/Weapons/Rogue/SlickCane.cs index 09d437d088..22ee59fe16 100644 --- a/Items/Weapons/Rogue/SlickCane.cs +++ b/Items/Weapons/Rogue/SlickCane.cs @@ -19,14 +19,14 @@ namespace CalamityMod.Items.Weapons.Rogue Item.channel = true; Item.useAnimation = 26; Item.useTime = 26; - Item.useStyle = ItemUseStyleID.Swing; - Item.knockBack = 5f; + Item.useStyle = ItemUseStyleID.Shoot; + Item.knockBack = 6f; Item.UseSound = SoundID.DD2_GhastlyGlaivePierce; Item.autoReuse = true; - Item.value = CalamityGlobalItem.RarityLightRedBuyPrice; - Item.rare = ItemRarityID.LightRed; + Item.value = CalamityGlobalItem.RarityOrangeBuyPrice; + Item.rare = ItemRarityID.Orange; Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 22f; + Item.shootSpeed = 16f; Item.DamageType = RogueDamageClass.Instance; } @@ -34,8 +34,8 @@ namespace CalamityMod.Items.Weapons.Rogue public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - float ai0 = Main.rand.NextFloat() * Item.shootSpeed * 0.75f * (float)player.direction; - int projectileIndex = Projectile.NewProjectile(source, position.X, position.Y, velocity.X, velocity.Y, type, damage, knockback, player.whoAmI, ai0, 0f); + float ai0 = Main.rand.NextFloat() * Item.shootSpeed * 1.5f * (float)player.direction; + int projectileIndex = Projectile.NewProjectile(source, position.X, position.Y+100, velocity.X*2f, velocity.Y*2f, type, damage, knockback, player.whoAmI, ai0, 0f); if (projectileIndex.WithinBounds(Main.maxProjectiles)) Main.projectile[projectileIndex].Calamity().stealthStrike = player.Calamity().StealthStrikeAvailable(); return false; diff --git a/Items/Weapons/Summon/AbandonedSlimeStaff.cs b/Items/Weapons/Summon/AbandonedSlimeStaff.cs index baf024b006..5240e09f86 100644 --- a/Items/Weapons/Summon/AbandonedSlimeStaff.cs +++ b/Items/Weapons/Summon/AbandonedSlimeStaff.cs @@ -38,10 +38,9 @@ namespace CalamityMod.Items.Weapons.Summon player.jumpSpeedBoost += 0.5f; double minionCount = 0; - for (int j = 0; j < Main.projectile.Length; j++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - Projectile projectile = Main.projectile[j]; - if (projectile.active && projectile.owner == player.whoAmI && projectile.minion && projectile.type != ModContent.ProjectileType()) + if (projectile.owner == player.whoAmI && projectile.minion && projectile.type != ModContent.ProjectileType()) { minionCount += projectile.minionSlots; } diff --git a/Items/Weapons/Summon/AresExoskeleton.cs b/Items/Weapons/Summon/AresExoskeleton.cs index 8d81e099cd..25c8513ee5 100644 --- a/Items/Weapons/Summon/AresExoskeleton.cs +++ b/Items/Weapons/Summon/AresExoskeleton.cs @@ -113,13 +113,13 @@ namespace CalamityMod.Items.Weapons.Summon // If the player owns a panel, make it fade away. if (player.ownedProjectileCounts[panelID] >= 1) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != panelID || Main.projectile[i].owner != player.whoAmI || !Main.projectile[i].active) + if (p.type != panelID || p.owner != player.whoAmI) continue; - Main.projectile[i].ai[0] = 1f; - Main.projectile[i].netUpdate = true; + p.ai[0] = 1f; + p.netUpdate = true; } } diff --git a/Items/Weapons/Summon/BrittleStarStaff.cs b/Items/Weapons/Summon/BrittleStarStaff.cs index 927726bba0..8a2b3ed5f5 100644 --- a/Items/Weapons/Summon/BrittleStarStaff.cs +++ b/Items/Weapons/Summon/BrittleStarStaff.cs @@ -53,13 +53,13 @@ namespace CalamityMod.Items.Weapons.Summon Item.noUseGraphic = true; } int bladeIndex = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == type && Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + if (p.type == type && p.owner == player.whoAmI) { - Main.projectile[i].ModProjectile().StarIndex = bladeIndex++; - Main.projectile[i].ModProjectile().AITimer = 0f; - Main.projectile[i].netUpdate = true; + p.ModProjectile().StarIndex = bladeIndex++; + p.ModProjectile().AITimer = 0f; + p.netUpdate = true; } } return false; diff --git a/Items/Weapons/Summon/Cosmilamp.cs b/Items/Weapons/Summon/Cosmilamp.cs index 231bd38e69..13dc9b4d22 100644 --- a/Items/Weapons/Summon/Cosmilamp.cs +++ b/Items/Weapons/Summon/Cosmilamp.cs @@ -45,12 +45,12 @@ namespace CalamityMod.Items.Weapons.Summon if (player.altFunctionUse != 2) { // Reset the timer for all lamps, to re-align the formation. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].active) + if (pro.type == type && pro.owner == player.whoAmI) { - Main.projectile[i].ModProjectile().Timer = 0f; - Main.projectile[i].netUpdate = true; + pro.ModProjectile().Timer = 0f; + pro.netUpdate = true; } } diff --git a/Items/Weapons/Summon/DazzlingStabberStaff.cs b/Items/Weapons/Summon/DazzlingStabberStaff.cs index bab08f23e9..3759fa322b 100644 --- a/Items/Weapons/Summon/DazzlingStabberStaff.cs +++ b/Items/Weapons/Summon/DazzlingStabberStaff.cs @@ -48,12 +48,12 @@ namespace CalamityMod.Items.Weapons.Summon angleMax += MathHelper.ToRadians((player.ownedProjectileCounts[Item.shoot] - 8) * 2.5f); } angleMax = angleMax > MathHelper.ToRadians(105f) ? MathHelper.ToRadians(105f) : angleMax; // More intuative than using a min function - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) + if (p.type == type && p.owner == player.whoAmI) { - Main.projectile[i].ai[1] = (index / CalamityUtils.CountProjectiles(type)) * angleMax - angleMax / 2f; - Main.projectile[i].netUpdate = true; + p.ai[1] = (index / CalamityUtils.CountProjectiles(type)) * angleMax - angleMax / 2f; + p.netUpdate = true; index++; } } diff --git a/Items/Weapons/Summon/DormantBrimseeker.cs b/Items/Weapons/Summon/DormantBrimseeker.cs index ae2b2695e9..33371abda8 100644 --- a/Items/Weapons/Summon/DormantBrimseeker.cs +++ b/Items/Weapons/Summon/DormantBrimseeker.cs @@ -32,11 +32,11 @@ namespace CalamityMod.Items.Weapons.Summon public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { float totalSlots = 0f; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].minion && Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + if (p.minion && p.owner == player.whoAmI) { - totalSlots += Main.projectile[i].minionSlots; + totalSlots += p.minionSlots; } } if (totalSlots < player.maxMinions) diff --git a/Items/Weapons/Summon/EndoHydraStaff.cs b/Items/Weapons/Summon/EndoHydraStaff.cs index 163f44253a..6e96ca55f3 100644 --- a/Items/Weapons/Summon/EndoHydraStaff.cs +++ b/Items/Weapons/Summon/EndoHydraStaff.cs @@ -39,11 +39,11 @@ namespace CalamityMod.Items.Weapons.Summon { bool bodyExists = false; int bodyIndex = -1; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) + if (p.type == type && p.owner == player.whoAmI) { - bodyIndex = i; + bodyIndex = p.whoAmI; bodyExists = true; break; } diff --git a/Items/Weapons/Summon/FlamsteedRing.cs b/Items/Weapons/Summon/FlamsteedRing.cs index 438bf16a36..697ee14482 100644 --- a/Items/Weapons/Summon/FlamsteedRing.cs +++ b/Items/Weapons/Summon/FlamsteedRing.cs @@ -122,13 +122,12 @@ namespace CalamityMod.Items.Weapons.Summon // If the player has any robots, kill them all. if (player.ownedProjectileCounts[Item.shoot] > 0) { - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && - Main.projectile[i].type == Item.shoot && - Main.projectile[i].owner == player.whoAmI) + if (p.type == Item.shoot && + p.owner == player.whoAmI) { - Main.projectile[i].Kill(); + p.Kill(); } } if (CalamityPlayer.areThereAnyDamnBosses) @@ -151,13 +150,12 @@ namespace CalamityMod.Items.Weapons.Summon int robotIndex = -1; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && - Main.projectile[i].type == ModContent.ProjectileType() && - Main.projectile[i].owner == player.whoAmI) + if (p.type == ModContent.ProjectileType() && + p.owner == player.whoAmI) { - robotIndex = i; + robotIndex = p.whoAmI; break; } } diff --git a/Items/Weapons/Summon/GlacialEmbrace.cs b/Items/Weapons/Summon/GlacialEmbrace.cs index bce8284a37..466e2ceb5e 100644 --- a/Items/Weapons/Summon/GlacialEmbrace.cs +++ b/Items/Weapons/Summon/GlacialEmbrace.cs @@ -35,11 +35,11 @@ namespace CalamityMod.Items.Weapons.Summon public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { float totalMinionSlots = 0f; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].minion && Main.projectile[i].owner == player.whoAmI) + if (pro.minion && pro.owner == player.whoAmI) { - totalMinionSlots += Main.projectile[i].minionSlots; + totalMinionSlots += pro.minionSlots; } } if (player.altFunctionUse != 2 && totalMinionSlots < player.maxMinions) @@ -50,29 +50,29 @@ namespace CalamityMod.Items.Weapons.Summon if (Main.projectile.IndexInRange(p)) Main.projectile[p].originalDamage = Item.damage; int pointyThingCount = 0; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) + if (pro.type == type && pro.owner == player.whoAmI) { - if (!(Main.projectile[i].ModProjectile as GlacialEmbracePointyThing).circlingPlayer) + if (!(pro.ModProjectile as GlacialEmbracePointyThing).circlingPlayer) continue; pointyThingCount++; } } float angleVariance = MathHelper.TwoPi / pointyThingCount; float angle = 0f; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].ai[1] == 0f) + if (pro.type == type && pro.owner == player.whoAmI && pro.ai[1] == 0f) { - if (!(Main.projectile[i].ModProjectile as GlacialEmbracePointyThing).circlingPlayer) + if (!(pro.ModProjectile as GlacialEmbracePointyThing).circlingPlayer) continue; - Main.projectile[i].ai[0] = angle; - Main.projectile[i].netUpdate = true; + pro.ai[0] = angle; + pro.netUpdate = true; angle += angleVariance; for (int j = 0; j < 22; j++) { - Dust dust = Dust.NewDustDirect(Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height, DustID.Ice); + Dust dust = Dust.NewDustDirect(pro.position, pro.width, pro.height, DustID.Ice); dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool().ToDirectionInt(); dust.noGravity = true; } diff --git a/Items/Weapons/Summon/IgneousExaltation.cs b/Items/Weapons/Summon/IgneousExaltation.cs index f0ae80e6cc..b00537081a 100644 --- a/Items/Weapons/Summon/IgneousExaltation.cs +++ b/Items/Weapons/Summon/IgneousExaltation.cs @@ -37,11 +37,11 @@ namespace CalamityMod.Items.Weapons.Summon public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { float totalMinionSlots = 0f; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].minion && Main.projectile[i].owner == player.whoAmI) + if (pro.minion && pro.owner == player.whoAmI) { - totalMinionSlots += Main.projectile[i].minionSlots; + totalMinionSlots += pro.minionSlots; } } if (player.altFunctionUse != 2 && totalMinionSlots < player.maxMinions) @@ -51,16 +51,16 @@ namespace CalamityMod.Items.Weapons.Summon if (Main.projectile.IndexInRange(p)) Main.projectile[p].originalDamage = Item.damage; int swordCount = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) + if (pro.type == type && pro.owner == player.whoAmI) { - if ((Main.projectile[i].ModProjectile as IgneousBlade).Firing) + if ((pro.ModProjectile as IgneousBlade).Firing) continue; swordCount++; for (int j = 0; j < 22; j++) { - Dust dust = Dust.NewDustDirect(Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height, DustID.Torch); + Dust dust = Dust.NewDustDirect(pro.position, pro.width, pro.height, DustID.Torch); dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool().ToDirectionInt(); dust.noGravity = true; } @@ -68,17 +68,17 @@ namespace CalamityMod.Items.Weapons.Summon } float angleVariance = MathHelper.TwoPi / swordCount; float angle = 0f; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI && Main.projectile[i].localAI[1] == 0f) + if (pro.type == type && pro.owner == player.whoAmI && pro.localAI[1] == 0f) { - if ((Main.projectile[i].ModProjectile as IgneousBlade).Firing) + if ((pro.ModProjectile as IgneousBlade).Firing) continue; - Main.projectile[i].ai[0] = angle; + pro.ai[0] = angle; angle += angleVariance; for (int j = 0; j < 22; j++) { - Dust dust = Dust.NewDustDirect(Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height, DustID.Torch); + Dust dust = Dust.NewDustDirect(pro.position, pro.width, pro.height, DustID.Torch); dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool().ToDirectionInt(); dust.noGravity = true; } diff --git a/Items/Weapons/Summon/StaffoftheMechworm.cs b/Items/Weapons/Summon/StaffoftheMechworm.cs index c3555dbd4b..5a9a3a858f 100644 --- a/Items/Weapons/Summon/StaffoftheMechworm.cs +++ b/Items/Weapons/Summon/StaffoftheMechworm.cs @@ -35,10 +35,9 @@ namespace CalamityMod.Items.Weapons.Summon { float neededSlots = 1; float foundSlotsCount = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.active && p.minion && p.owner == player.whoAmI) + if (p.minion && p.owner == player.whoAmI) { foundSlotsCount += p.minionSlots; if (foundSlotsCount + neededSlots > player.maxMinions) @@ -100,17 +99,17 @@ namespace CalamityMod.Items.Weapons.Summon { int head = -1; int tail = -1; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer) + if (p.owner == Main.myPlayer) { - if (head == -1 && Main.projectile[i].type == ModContent.ProjectileType()) + if (head == -1 && p.type == ModContent.ProjectileType()) { - head = i; + head = p.whoAmI; } - if (tail == -1 && Main.projectile[i].type == ModContent.ProjectileType()) + if (tail == -1 && p.type == ModContent.ProjectileType()) { - tail = i; + tail = p.whoAmI; } if (head != -1 && tail != -1) { diff --git a/Items/Weapons/Summon/StarspawnHelixStaff.cs b/Items/Weapons/Summon/StarspawnHelixStaff.cs index 867e824854..ac6e306dcd 100644 --- a/Items/Weapons/Summon/StarspawnHelixStaff.cs +++ b/Items/Weapons/Summon/StarspawnHelixStaff.cs @@ -42,13 +42,13 @@ namespace CalamityMod.Items.Weapons.Summon } int bladeIndex = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].type == type && Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + if (pro.type == type && pro.owner == player.whoAmI) { - Main.projectile[i].ModProjectile().ProbeIndex = bladeIndex++; - Main.projectile[i].ModProjectile().AITimer = 0f; - Main.projectile[i].netUpdate = true; + pro.ModProjectile().ProbeIndex = bladeIndex++; + pro.ModProjectile().AITimer = 0f; + pro.netUpdate = true; } } } diff --git a/Items/Weapons/Summon/ViralSprout.cs b/Items/Weapons/Summon/ViralSprout.cs index b8562622b7..a15b2b4211 100644 --- a/Items/Weapons/Summon/ViralSprout.cs +++ b/Items/Weapons/Summon/ViralSprout.cs @@ -39,13 +39,13 @@ namespace CalamityMod.Items.Weapons.Summon Main.projectile[p].originalDamage = Item.damage; int minionCount = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].type != type || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + if (pro.type != type || pro.owner != player.whoAmI) continue; - Main.projectile[i].localAI[0] = minionCount; - Main.projectile[i].netUpdate = true; + pro.localAI[0] = minionCount; + pro.netUpdate = true; minionCount++; } } diff --git a/Items/Weapons/Summon/ViridVanguard.cs b/Items/Weapons/Summon/ViridVanguard.cs index 99585eaccc..2e30e7403b 100644 --- a/Items/Weapons/Summon/ViridVanguard.cs +++ b/Items/Weapons/Summon/ViridVanguard.cs @@ -63,13 +63,13 @@ namespace CalamityMod.Items.Weapons.Summon } int bladeIndex = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].type == type && Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) + if (pro.type == type && pro.owner == player.whoAmI) { - Main.projectile[i].ModProjectile().BladeIndex = bladeIndex++; - Main.projectile[i].ModProjectile().AITimer = 0f; - Main.projectile[i].netUpdate = true; + pro.ModProjectile().BladeIndex = bladeIndex++; + pro.ModProjectile().AITimer = 0f; + pro.netUpdate = true; } } } diff --git a/Items/Weapons/Typeless/RelicOfResilience.cs b/Items/Weapons/Typeless/RelicOfResilience.cs index a86f3f278e..a2b5adafcb 100644 --- a/Items/Weapons/Typeless/RelicOfResilience.cs +++ b/Items/Weapons/Typeless/RelicOfResilience.cs @@ -56,12 +56,12 @@ namespace CalamityMod.Items.Weapons.Typeless }; if (player.ownedProjectileCounts[Item.shoot] > 0) { - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == Item.shoot) + if (p.type == Item.shoot) { - Main.projectile[i].Center = Main.MouseWorld; - Main.projectile[i].netUpdate = true; + p.Center = Main.MouseWorld; + p.netUpdate = true; } } } diff --git a/Localization/en-US/Mods.CalamityMod.Biomes.hjson b/Localization/en-US/Mods.CalamityMod.Biomes.hjson index 7751dea39b..f6834ea4a1 100644 --- a/Localization/en-US/Mods.CalamityMod.Biomes.hjson +++ b/Localization/en-US/Mods.CalamityMod.Biomes.hjson @@ -1,29 +1,28 @@ // For general uses Abyss: Abyss AstralInfection: Astral Infection -AstralDesert: Astral Desert AstralSnow: Astral Snow BrimstoneCrags: Brimstone Crags SulphurousSea: Sulphurous Sea SunkenSea: Sunken Sea -AbovegroundAstralBiome: { - DisplayName: Astral Infection - TownNPCDialogueName: Astral Infection -} - -AbovegroundAstralBiomeSurface: { - DisplayName: Astral Surface - TownNPCDialogueName: Astral Infection -} - -AbovegroundAstralDesertBiome: { +AstralDesert: { DisplayName: Astral Desert Surface TownNPCDialogueName: Astral Desert } -AbovegroundAstralSnowBiome: { - DisplayName: Astral Snow Surface +AstralBiome: { + DisplayName: Astral Infection + TownNPCDialogueName: Astral Infection +} + +AstralInfectionBiome: { + DisplayName: Astral Infection + TownNPCDialogueName: Astral Infection +} + +AstralIce: { + DisplayName: Astral Ice TownNPCDialogueName: Astral Snow } @@ -72,7 +71,12 @@ SunkenSeaBiome: { TownNPCDialogueName: Sunken Sea } -UndergroundAstralBiome: { +AstralUnderground: { DisplayName: Astral Underground TownNPCDialogueName: Underground Astral Infection } + +AstralCaveDesert: { + DisplayName: Astral Cave Desert + TownNPCDialogueName: the Astral Cave Desert +} diff --git a/Localization/en-US/Mods.CalamityMod.Condition.hjson b/Localization/en-US/Mods.CalamityMod.Condition.hjson index bf60551d64..6dbe1feb52 100644 --- a/Localization/en-US/Mods.CalamityMod.Condition.hjson +++ b/Localization/en-US/Mods.CalamityMod.Condition.hjson @@ -1,64 +1,43 @@ // Drop conditions Drops: { - Cynosure: Drops once you have defeated both Draedon and Calamitas - DownedKS: Drops after defeating King Slime - DownedDS: Drops after defeating the Desert Scourge - DownedEoC: Drops after defeating the Eye of Cthulhu - DownedCrab: Drops after defeating Crabulon - DownedEoW: Drops after defeating the Eater of Worlds - DownedBoC: Drops after defeating the Brain of Cthulhu - DownedHM: Drops after defeating the Hive Mind - DownedPerfs: Drops after defeating the Perforators - DownedQB: Drops after defeating the Queen Bee - DownedDeer: Drops after defeating Deerclops - DownedSkele: Drops after defeating Skeletron - DownedSG: Drops after defeating the Slime God - Hardmode: Drops in Hardmode - DownedQS: Drops after defeating Queen Slime - DownedCryo: Drops after defeating Cryogen - DownedAS: Drops after defeating the Aquatic Scourge - DownedBrim: Drops after defeating the Brimstone Elemental - DownedDest: Drops after defeating the Destroyer - DownedTwins: Drops after defeating the Twins - DownedSP: Drops after defeating Skeletron Prime - Downed1Mech: Drops after defeating a Mechanical Boss - Downed3Mechs: Drops after defeating all three Mechanical Bosses - DownedCal: Drops after defeating Calamitas Clone - DownedPlant: Drops after defeating Plantera - DownedCalPlant: Drops after defeating Calamitas or Plantera - DownedLevi: Drops after defeating the Leviathan and Anahita - DownedAureus: Drops after defeating Astrum Aureus - DownedGolem: Drops after defeating Golem - DownedPBG: Drops after defeating the Plaguebringer Goliath - DownedEoL: Drops after defeating the Empress of Light - DownedFish: Drops after defeating Duke Fishron - DownedRav: Drops after defeating the Ravager - DownedLC: Drops after defeating the Lunatic Cultist - DownedAD: Drops after defeating Astrum Deus - DownedML: Drops after defeating the Moon Lord - DownedGuard: Drops after defeating the Profaned Guardians - DownedBirb: Drops after defeating the Dragonfolly - DownedProv: Drops after defeating Providence - DownedSig: Drops after defeating Signus - DownedSW: Drops after defeating the Storm Weaver - DownedCV: Drops after defeating the Ceaseless Void - DownedPolter: Drops after defeating the Polterghast - DownedOD: Drops after defeating the Old Duke - DownedDoG: Drops after defeating the Devourer of Gods - DownedYharon: Drops after defeating Yharon - DownedExos: Drops after defeating the Exo Mechs - DownedSCal: Drops after defeating Calamitas - DownedAEW: Drops after defeating the Primordial Wyrm - DownedClam: Drops after defeating the Giant Clam - DownedClamHM: Drops after defeating the Giant Clam in Hardmode - DownedGSS: Drops after defeating the Great Sand Shark - DownedBetsy: Drops after defeating Betsy - DownedT1AR: Drops after defeating the first tier of Acid Rain - DownedT2AR: Drops after defeating the second tier of Acid Rain + Cynosure: After defeating both Draedon and Calamitas + DownedDS: After defeating the Desert Scourge + DownedCrab: After defeating Crabulon + DownedHM: After defeating the Hive Mind + DownedPerfs: After defeating the Perforators + DownedHMOrPerfs: After defeating the Hive Mind or the Perforators + DownedSG: After defeating the Slime God + DownedCryo: After defeating Cryogen + DownedAS: After defeating the Aquatic Scourge + DownedBrim: After defeating the Brimstone Elemental + DownedDest: After defeating the Destroyer + DownedCal: After defeating Calamitas Clone + DownedCalPlant: After defeating Calamitas or Plantera + DownedLevi: After defeating the Leviathan and Anahita + DownedAureus: After defeating Astrum Aureus + DownedPBG: After defeating the Plaguebringer Goliath + DownedRav: After defeating the Ravager + DownedAD: After defeating Astrum Deus + DownedGuard: After defeating the Profaned Guardians + DownedBirb: After defeating the Dragonfolly + DownedProv: After defeating Providence + DownedSig: After defeating Signus + DownedSW: After defeating the Storm Weaver + DownedCV: After defeating the Ceaseless Void + DownedPolter: After defeating the Polterghast + DownedOD: After defeating the Old Duke + DownedDoG: After defeating the Devourer of Gods + DownedYharon: After defeating Yharon + DownedExos: After defeating the Exo Mechs + DownedSCal: After defeating Calamitas + DownedAEW: After defeating the Primordial Wyrm + DownedClam: After defeating the Giant Clam + DownedClamHM: After defeating the Giant Clam in Hardmode + DownedGSS: After defeating the Great Sand Shark + DownedBetsy: After defeating Betsy + DownedT1AR: After defeating the first tier of Acid Rain + DownedT2AR: After defeating the second tier of Acid Rain FirstKill: Drops only on the first kill - IsGFB: This is an Everything Seed drop rate - IsRev: This is a Revengeance Mode drop rate - IsDeath: This is a Death Mode drop rate MechBoss: Drops on the first kill of the final Mechanical Boss ProvidenceHallow: ''' @@ -84,18 +63,16 @@ PotionConfig: While the Town NPC Potion Selling configuration option is enabled HasFlareGun: While holding a Flare Gun upgrade HasRogueArmor: While wearing rogue armor HasWings: While wearing wings -InAstral: While in the Astral Infection -InCrag: While in the Brimstone Crags -InSulph: While in the Sulphurous Sea -InSunken: While in the Sunken Sea +InAstral: In the Astral Infection +InCrag: In the Brimstone Crags +InSulph: In the Sulphurous Sea +InSunken: In the Sunken Sea InRev: In Revengeance Mode +IsRevOrMM: In Revengeance Mode or in Master Mode AlcoholPoison: While inflicted with Alcohol Poisoning -DownedHM: After the Hive Mind has been defeated -DownedPerfs: After the Perforator Hive has been defeated -DownedEvil2Boss: After the Hive Mind or the Perforators have been defeated -PostCal: After Calamitas Clone has been defeated -PostAureus: After Astrum Aureus has been defeated -PostPolter: After Polterghast has been defeated -PostOD: After the Old Duke has been defeated -PostDoG: After the Devourer of Gods has been defeated -PostYharon: After Yharon has been defeated +PostCal: After defeating Calamitas Clone +PostAureus: After defeating Astrum Aureus +PostPolter: After defeating Polterghast +PostOD: After defeating the Old Duke +PostDoG: After defeating the Devourer of Gods +PostYharon: After defeating Yharon diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson index d92ae3dc73..abd9755e31 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson @@ -1084,7 +1084,8 @@ SlickCane: { Tooltip: ''' Swipes a cane that steals money from enemies - Stealth strikes gives a 1 in 15 chance for enemies to drop 1-3 gold coins when hit + Stealth strikes gives a 1 in 20 chance for enemies to drop 1-3 gold coins when hit + Stealth strikes' damage increases in proportion to money in the inventory (up to 2 platinum) 'Economy at its finest' ''' } diff --git a/ModSupport/WeakReferenceSupport.cs b/ModSupport/WeakReferenceSupport.cs index 32f4280027..086ae693e4 100644 --- a/ModSupport/WeakReferenceSupport.cs +++ b/ModSupport/WeakReferenceSupport.cs @@ -21,6 +21,7 @@ using CalamityMod.Items.Weapons.Magic; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.Items.Weapons.Rogue; using CalamityMod.NPCs.AcidRain; using CalamityMod.NPCs.AquaticScourge; using CalamityMod.NPCs.Astral; diff --git a/NPCs/Abyss/BabyCannonballJellyfish.cs b/NPCs/Abyss/BabyCannonballJellyfish.cs index 95b7a901fb..b9dad300de 100644 --- a/NPCs/Abyss/BabyCannonballJellyfish.cs +++ b/NPCs/Abyss/BabyCannonballJellyfish.cs @@ -162,8 +162,13 @@ namespace CalamityMod.NPCs.Abyss NPC.height = (int)(NPC.height * 3f); NPC.position -= NPC.Size * 0.5f; //hitbox expansion + adjustments SoundEngine.PlaySound(SoundID.Item14, NPC.Center); //bomb sound - foreach (Player player in Main.player.Where(player => player.active && !player.dead && NPC.Hitbox.Intersects(player.Hitbox))) + foreach (Player player in Main.ActivePlayers) + { + if (player.dead || !NPC.Hitbox.Intersects(player.Hitbox)) + continue; + player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), explosionDamage, NPC.direction); + } for (int k = 0; k < 8; k++) { int dust = Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.MoonBoulder, 0f, -1f, 0, default, 1f); diff --git a/NPCs/Abyss/CannonballJellyfish.cs b/NPCs/Abyss/CannonballJellyfish.cs index 3985c19fbe..772500e4be 100644 --- a/NPCs/Abyss/CannonballJellyfish.cs +++ b/NPCs/Abyss/CannonballJellyfish.cs @@ -272,8 +272,14 @@ namespace CalamityMod.NPCs.Abyss NPC.width = NPC.height; NPC.position -= NPC.Size * 0.5f; //hitbox expansion + adjustments SoundEngine.PlaySound(SoundID.Item14, NPC.Center); //bomb sound - foreach (Player player in Main.player.Where(player => player.active && !player.dead && NPC.Hitbox.Intersects(player.Hitbox))) - player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage * 3, NPC.direction); //Due to how slow the jelly is, this might catch you unaware, but then you'll never get hit by it again + foreach (Player player in Main.ActivePlayers) + { + if (player.dead || !NPC.Hitbox.Intersects(player.Hitbox)) + continue; + + //Due to how slow the jelly is, this might catch you unaware, but then you'll never get hit by it again + player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage * 3, NPC.direction); + } for (int k = 0; k < 25; k++) { int dust = Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.MoonBoulder, 0f, -1f, 0, default, 2f); diff --git a/NPCs/Abyss/ColossalSquid.cs b/NPCs/Abyss/ColossalSquid.cs index 7770841c3a..3081a1a826 100644 --- a/NPCs/Abyss/ColossalSquid.cs +++ b/NPCs/Abyss/ColossalSquid.cs @@ -540,24 +540,21 @@ namespace CalamityMod.NPCs.Abyss } float pushVelocity = 0.05f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC otherNPC in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (otherNPC.whoAmI != NPC.whoAmI && otherNPC.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, otherNPC.Center) < 160f) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 160f) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= pushVelocity; - else - NPC.velocity.X += pushVelocity; + if (NPC.position.X < otherNPC.position.X) + NPC.velocity.X -= pushVelocity; + else + NPC.velocity.X += pushVelocity; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= pushVelocity; - else - NPC.velocity.Y += pushVelocity; - } + if (NPC.position.Y < otherNPC.position.Y) + NPC.velocity.Y -= pushVelocity; + else + NPC.velocity.Y += pushVelocity; } } } diff --git a/NPCs/Abyss/EidolonWyrmBody.cs b/NPCs/Abyss/EidolonWyrmBody.cs index de8d0bb5d9..5e0b418ef0 100644 --- a/NPCs/Abyss/EidolonWyrmBody.cs +++ b/NPCs/Abyss/EidolonWyrmBody.cs @@ -62,9 +62,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/EidolonWyrmBodyAlt.cs b/NPCs/Abyss/EidolonWyrmBodyAlt.cs index c0a31646c9..9e31e16946 100644 --- a/NPCs/Abyss/EidolonWyrmBodyAlt.cs +++ b/NPCs/Abyss/EidolonWyrmBodyAlt.cs @@ -62,9 +62,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/EidolonWyrmTail.cs b/NPCs/Abyss/EidolonWyrmTail.cs index 45ff9eb1da..78045ad275 100644 --- a/NPCs/Abyss/EidolonWyrmTail.cs +++ b/NPCs/Abyss/EidolonWyrmTail.cs @@ -62,9 +62,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/GulperEelBody.cs b/NPCs/Abyss/GulperEelBody.cs index e043327a62..819cae17cd 100644 --- a/NPCs/Abyss/GulperEelBody.cs +++ b/NPCs/Abyss/GulperEelBody.cs @@ -70,9 +70,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/GulperEelBodyAlt.cs b/NPCs/Abyss/GulperEelBodyAlt.cs index ce6ac572b1..73d68d7b0f 100644 --- a/NPCs/Abyss/GulperEelBodyAlt.cs +++ b/NPCs/Abyss/GulperEelBodyAlt.cs @@ -70,9 +70,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/GulperEelTail.cs b/NPCs/Abyss/GulperEelTail.cs index 48748c15c8..8c0444d4c1 100644 --- a/NPCs/Abyss/GulperEelTail.cs +++ b/NPCs/Abyss/GulperEelTail.cs @@ -70,9 +70,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/MorayEel.cs b/NPCs/Abyss/MorayEel.cs index 35c2d095df..7da581930d 100644 --- a/NPCs/Abyss/MorayEel.cs +++ b/NPCs/Abyss/MorayEel.cs @@ -118,7 +118,6 @@ namespace CalamityMod.NPCs.Abyss public override void ModifyNPCLoot(NPCLoot npcLoot) { npcLoot.Add(ItemID.Flipper, 20); - npcLoot.Add(ItemDropRule.NormalvsExpert(ModContent.ItemType(), 15, 10)); } public override void HitEffect(NPC.HitInfo hit) diff --git a/NPCs/Abyss/OarfishBody.cs b/NPCs/Abyss/OarfishBody.cs index ac1f56f8e3..2849ab2efa 100644 --- a/NPCs/Abyss/OarfishBody.cs +++ b/NPCs/Abyss/OarfishBody.cs @@ -61,9 +61,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/OarfishTail.cs b/NPCs/Abyss/OarfishTail.cs index f91af05d87..eb0ce07f93 100644 --- a/NPCs/Abyss/OarfishTail.cs +++ b/NPCs/Abyss/OarfishTail.cs @@ -61,9 +61,9 @@ namespace CalamityMod.NPCs.Abyss // Check if other segments are still alive, if not, die bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { shouldDespawn = false; break; diff --git a/NPCs/Abyss/Viperfish.cs b/NPCs/Abyss/Viperfish.cs index f774286a91..c81ad502c2 100644 --- a/NPCs/Abyss/Viperfish.cs +++ b/NPCs/Abyss/Viperfish.cs @@ -3,6 +3,7 @@ using CalamityMod.BiomeManagers; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables.Banners; +using CalamityMod.Items.Weapons.Melee; using CalamityMod.NPCs.CalamityAIs.CalamityRegularEnemyAIs; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -10,6 +11,7 @@ using ReLogic.Content; using Terraria; using Terraria.GameContent; using Terraria.GameContent.Bestiary; +using Terraria.GameContent.ItemDropRules; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Utilities; @@ -158,6 +160,7 @@ namespace CalamityMod.NPCs.Abyss var postLevi = npcLoot.DefineConditionalDropSet(DropHelper.PostLevi()); postLevi.Add(DropHelper.NormalVsExpertQuantity(ModContent.ItemType(), 2, 1, 2, 2, 3)); postLevi.Add(ModContent.ItemType(), 4); + npcLoot.Add(ItemDropRule.NormalvsExpert(ModContent.ItemType(), 10, 6)); } public override void HitEffect(NPC.HitInfo hit) diff --git a/NPCs/AcidRain/BloodwormNormal.cs b/NPCs/AcidRain/BloodwormNormal.cs index 18c8b4e8c9..b95a54e1eb 100644 --- a/NPCs/AcidRain/BloodwormNormal.cs +++ b/NPCs/AcidRain/BloodwormNormal.cs @@ -56,10 +56,9 @@ namespace CalamityMod.NPCs.AcidRain NPC.velocity.X = xSpeed * NPC.ai[0]; NPC.spriteDirection = (int)NPC.ai[0]; bool flee = false; - for (int i = 0; i < Main.player.Length; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player.active && !player.dead && Vector2.Distance(player.Center, NPC.Center) <= 220f) + if (!player.dead && Vector2.Distance(player.Center, NPC.Center) <= 220f) { flee = true; break; diff --git a/NPCs/AcidRain/SulphurousSkater.cs b/NPCs/AcidRain/SulphurousSkater.cs index a984472c18..17b047ceb0 100644 --- a/NPCs/AcidRain/SulphurousSkater.cs +++ b/NPCs/AcidRain/SulphurousSkater.cs @@ -189,20 +189,20 @@ namespace CalamityMod.NPCs.AcidRain float minimumDistance = 2400f; Projectile closestBubble = null; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != bubbleType || !Main.projectile[i].active) + if (p.type != bubbleType) continue; - if (Math.Abs(NPC.Center.X - Main.projectile[i].Center.X) >= minimumDistance || - Main.projectile[i].Center.Y <= NPC.Bottom.Y || - !Collision.CanHit(NPC.position, NPC.width, NPC.height, Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height)) + if (Math.Abs(NPC.Center.X - p.Center.X) >= minimumDistance || + p.Center.Y <= NPC.Bottom.Y || + !Collision.CanHit(NPC.position, NPC.width, NPC.height, p.position, p.width, p.height)) { continue; } - minimumDistance = NPC.Distance(Main.projectile[i].Center); - closestBubble = Main.projectile[i]; + minimumDistance = NPC.Distance(p.Center); + closestBubble = p; } distanceToBubble = minimumDistance; diff --git a/NPCs/Astral/Aries.cs b/NPCs/Astral/Aries.cs index 76984fe721..1ea110d392 100644 --- a/NPCs/Astral/Aries.cs +++ b/NPCs/Astral/Aries.cs @@ -50,7 +50,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/AstralProbe.cs b/NPCs/Astral/AstralProbe.cs index 337b44f461..b57bd3c99d 100644 --- a/NPCs/Astral/AstralProbe.cs +++ b/NPCs/Astral/AstralProbe.cs @@ -56,7 +56,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/AstralSlime.cs b/NPCs/Astral/AstralSlime.cs index bd9d700934..9959c22d91 100644 --- a/NPCs/Astral/AstralSlime.cs +++ b/NPCs/Astral/AstralSlime.cs @@ -44,7 +44,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/AstralachneaWall.cs b/NPCs/Astral/AstralachneaWall.cs index 988cf850db..ab3c5fc0d1 100644 --- a/NPCs/Astral/AstralachneaWall.cs +++ b/NPCs/Astral/AstralachneaWall.cs @@ -7,6 +7,7 @@ using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Sounds; using CalamityMod.World; +using CalamityMod.BiomeManagers.BestiaryCategories; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; @@ -58,7 +59,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/Atlas.cs b/NPCs/Astral/Atlas.cs index 5089169c16..d3fc6d6641 100644 --- a/NPCs/Astral/Atlas.cs +++ b/NPCs/Astral/Atlas.cs @@ -153,7 +153,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); @@ -270,13 +270,13 @@ namespace CalamityMod.NPCs.Astral centerY - height / 2, width, height); - for (int i = 0; i < Main.player.Length; i++) + foreach (Player player in Main.ActivePlayers) { - if (Main.player[i].active && !Main.player[i].dead && Main.player[i].getRect().Intersects(hitbox)) + if (!player.dead && player.getRect().Intersects(hitbox)) { - Vector2 before = Main.player[i].velocity; - Main.player[i].Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.defDamage, NPC.direction); - Vector2 after = Main.player[i].velocity; + Vector2 before = player.velocity; + player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.defDamage, NPC.direction); + Vector2 after = player.velocity; Vector2 difference = after - before; float horMult = 3.5f; @@ -291,7 +291,7 @@ namespace CalamityMod.NPCs.Astral swingYeet = true; } - if (Main.player[i].noKnockback) + if (player.noKnockback) { horMult *= 0.5f; verMult *= 0.5f; @@ -299,7 +299,7 @@ namespace CalamityMod.NPCs.Astral difference *= new Vector2(horMult, verMult); - Main.player[i].velocity = before + difference; + player.velocity = before + difference; } } } diff --git a/NPCs/Astral/FusionFeeder.cs b/NPCs/Astral/FusionFeeder.cs index 49a6b73e71..9df2efe204 100644 --- a/NPCs/Astral/FusionFeeder.cs +++ b/NPCs/Astral/FusionFeeder.cs @@ -4,6 +4,7 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables.Banners; +using CalamityMod.BiomeManagers.BestiaryCategories; using CalamityMod.Projectiles.Enemy; using CalamityMod.Sounds; using Microsoft.Xna.Framework; @@ -75,7 +76,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/Hadarian.cs b/NPCs/Astral/Hadarian.cs index f71ed2a2df..8882cf68c8 100644 --- a/NPCs/Astral/Hadarian.cs +++ b/NPCs/Astral/Hadarian.cs @@ -8,6 +8,7 @@ using CalamityMod.Items.Placeables.Banners; using CalamityMod.Sounds; using CalamityMod.Tiles.AstralDesert; using CalamityMod.World; +using CalamityMod.BiomeManagers.BestiaryCategories; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; @@ -58,7 +59,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/HiveEnemy.cs b/NPCs/Astral/HiveEnemy.cs index 75d9527c5d..ab56f1f246 100644 --- a/NPCs/Astral/HiveEnemy.cs +++ b/NPCs/Astral/HiveEnemy.cs @@ -7,6 +7,7 @@ using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Weapons.Summon; using CalamityMod.Sounds; using CalamityMod.World; +using CalamityMod.BiomeManagers.BestiaryCategories; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; @@ -50,7 +51,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; if (Main.zenithWorld) { NPC.scale = 3f; @@ -126,6 +127,8 @@ namespace CalamityMod.NPCs.Astral if (NPC.life <= 0) { int type = ModContent.NPCType(); + + // TODO: Should this use `Main.ActiveNPCs` iterator? for (int i = 0; i < Main.maxNPCs; i++) { if (Main.npc[i].type == type) diff --git a/NPCs/Astral/Hiveling.cs b/NPCs/Astral/Hiveling.cs index 8d57509795..1815cf10a8 100644 --- a/NPCs/Astral/Hiveling.cs +++ b/NPCs/Astral/Hiveling.cs @@ -4,6 +4,7 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using CalamityMod.Sounds; using CalamityMod.World; +using CalamityMod.BiomeManagers.BestiaryCategories; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; @@ -50,7 +51,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/Mantis.cs b/NPCs/Astral/Mantis.cs index f2abb227c0..f4416a41f4 100644 --- a/NPCs/Astral/Mantis.cs +++ b/NPCs/Astral/Mantis.cs @@ -60,7 +60,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/Nova.cs b/NPCs/Astral/Nova.cs index 3eec7f005b..19ad010c55 100644 --- a/NPCs/Astral/Nova.cs +++ b/NPCs/Astral/Nova.cs @@ -81,7 +81,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); @@ -228,12 +228,12 @@ namespace CalamityMod.NPCs.Astral if (Main.netMode != NetmodeID.MultiplayerClient) { - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - if (Main.player[i].getRect().Intersects(myRect)) + if (player.getRect().Intersects(myRect)) { - int direction = NPC.Center.X - Main.player[i].Center.X < 0 ? -1 : 1; - Main.player[i].Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage, direction); + int direction = NPC.Center.X - player.Center.X < 0 ? -1 : 1; + player.Hurt(PlayerDeathReason.ByNPC(NPC.whoAmI), NPC.damage, direction); } } } diff --git a/NPCs/Astral/SightseerCollider.cs b/NPCs/Astral/SightseerCollider.cs index 9e8dc3fec8..5b0a72f09c 100644 --- a/NPCs/Astral/SightseerCollider.cs +++ b/NPCs/Astral/SightseerCollider.cs @@ -59,7 +59,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/SightseerSpitter.cs b/NPCs/Astral/SightseerSpitter.cs index 018a3f7efe..18a292029b 100644 --- a/NPCs/Astral/SightseerSpitter.cs +++ b/NPCs/Astral/SightseerSpitter.cs @@ -61,7 +61,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/StellarCulex.cs b/NPCs/Astral/StellarCulex.cs index 7cdb6f1050..979055f748 100644 --- a/NPCs/Astral/StellarCulex.cs +++ b/NPCs/Astral/StellarCulex.cs @@ -5,6 +5,7 @@ using CalamityMod.Dusts; using CalamityMod.Items.Accessories; using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables.Banners; +using CalamityMod.BiomeManagers.BestiaryCategories; using CalamityMod.Sounds; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -59,7 +60,7 @@ namespace CalamityMod.NPCs.Astral } NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); diff --git a/NPCs/Astral/Twinkler.cs b/NPCs/Astral/Twinkler.cs index d0b5d1794e..236659fd72 100644 --- a/NPCs/Astral/Twinkler.cs +++ b/NPCs/Astral/Twinkler.cs @@ -26,7 +26,7 @@ namespace CalamityMod.NPCs.Astral AIType = NPCID.LightningBug; AnimationType = NPCID.LightningBug; NPC.catchItem = (short)ModContent.ItemType(); - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; } public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) diff --git a/NPCs/AstrumAureus/AstrumAureus.cs b/NPCs/AstrumAureus/AstrumAureus.cs index a99da6194b..c2222cc170 100644 --- a/NPCs/AstrumAureus/AstrumAureus.cs +++ b/NPCs/AstrumAureus/AstrumAureus.cs @@ -106,7 +106,7 @@ namespace CalamityMod.NPCs.AstrumAureus NPC.lifeMax += (int)(NPC.lifeMax * HPBoost); NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; if (Main.getGoodWorld) NPC.scale *= 0.8f; @@ -439,7 +439,7 @@ namespace CalamityMod.NPCs.AstrumAureus } // Drop an Astral Meteor if applicable - ThreadPool.QueueUserWorkItem(_ => AstralBiome.PlaceAstralMeteor()); + ThreadPool.QueueUserWorkItem(_ => World.AstralBiome.PlaceAstralMeteor()); // Mark Astrum Aureus as dead DownedBossSystem.downedAstrumAureus = true; diff --git a/NPCs/AstrumAureus/AureusSpawn.cs b/NPCs/AstrumAureus/AureusSpawn.cs index 5c44436054..379d8a9e6d 100644 --- a/NPCs/AstrumAureus/AureusSpawn.cs +++ b/NPCs/AstrumAureus/AureusSpawn.cs @@ -115,24 +115,21 @@ namespace CalamityMod.NPCs.AstrumAureus // Push away from each other float pushVelocity = 0.5f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < (160f + 30f * (NPC.scale - 1f))) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < (160f + 30f * (NPC.scale - 1f))) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X = NPC.velocity.X - pushVelocity; - else - NPC.velocity.X = NPC.velocity.X + pushVelocity; + if (NPC.position.X < n.position.X) + NPC.velocity.X = NPC.velocity.X - pushVelocity; + else + NPC.velocity.X = NPC.velocity.X + pushVelocity; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y = NPC.velocity.Y - pushVelocity; - else - NPC.velocity.Y = NPC.velocity.Y + pushVelocity; - } + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y = NPC.velocity.Y - pushVelocity; + else + NPC.velocity.Y = NPC.velocity.Y + pushVelocity; } } } diff --git a/NPCs/AstrumDeus/AstrumDeusHead.cs b/NPCs/AstrumDeus/AstrumDeusHead.cs index ed43b0fe56..f814c85120 100644 --- a/NPCs/AstrumDeus/AstrumDeusHead.cs +++ b/NPCs/AstrumDeus/AstrumDeusHead.cs @@ -108,7 +108,7 @@ namespace CalamityMod.NPCs.AstrumDeus NPC.netAlways = true; NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToSickness = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; if (Main.zenithWorld) { @@ -253,10 +253,9 @@ namespace CalamityMod.NPCs.AstrumDeus return; // Killing ANY split Deus makes all other Deus heads die immediately. - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC otherWormHead in Main.ActiveNPCs) { - NPC otherWormHead = Main.npc[i]; - if (otherWormHead.active && otherWormHead.type == NPC.type) + if (otherWormHead.type == NPC.type) { // Kill the other worm head after setting it to not drop loot. otherWormHead.Calamity().newAI[0] = 0f; diff --git a/NPCs/BrimstoneElemental/Brimling.cs b/NPCs/BrimstoneElemental/Brimling.cs index b538a4df94..f4fc581261 100644 --- a/NPCs/BrimstoneElemental/Brimling.cs +++ b/NPCs/BrimstoneElemental/Brimling.cs @@ -195,24 +195,21 @@ namespace CalamityMod.NPCs.BrimstoneElemental // Push away from other Brimlings float pushVelocity = 0.5f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < 40f * NPC.scale) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 40f * NPC.scale) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= pushVelocity; - else - NPC.velocity.X += pushVelocity; + if (NPC.position.X < n.position.X) + NPC.velocity.X -= pushVelocity; + else + NPC.velocity.X += pushVelocity; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= pushVelocity; - else - NPC.velocity.Y += pushVelocity; - } + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y -= pushVelocity; + else + NPC.velocity.Y += pushVelocity; } } } diff --git a/NPCs/CalClone/CalScreenShaderData.cs b/NPCs/CalClone/CalScreenShaderData.cs index 11ee4782e0..af7b7ada08 100644 --- a/NPCs/CalClone/CalScreenShaderData.cs +++ b/NPCs/CalClone/CalScreenShaderData.cs @@ -24,11 +24,11 @@ namespace CalamityMod.NPCs.CalClone return; } CalIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == CalType) + if (n.type == CalType) { - CalIndex = i; + CalIndex = n.whoAmI; break; } } diff --git a/NPCs/CalClone/CalSky.cs b/NPCs/CalClone/CalSky.cs index e7d242d4d0..21beea7407 100644 --- a/NPCs/CalClone/CalSky.cs +++ b/NPCs/CalClone/CalSky.cs @@ -52,11 +52,11 @@ namespace CalamityMod.NPCs.CalClone return true; } CalIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == CalType) + if (n.type == CalType) { - CalIndex = i; + CalIndex = n.whoAmI; break; } } diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index 7a85115865..1378deb1cd 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -628,11 +628,10 @@ namespace CalamityMod.NPCs npc.lifeRegen = 0; int projectileCount = 0; - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[j].active && - (Main.projectile[j].type == ProjectileType() || Main.projectile[j].type == ProjectileType() || Main.projectile[j].type == ProjectileType()) && - Main.projectile[j].ai[0] == 1f && Main.projectile[j].ai[1] == npc.whoAmI) + if ((p.type == ProjectileType() || p.type == ProjectileType() || p.type == ProjectileType()) && + p.ai[0] == 1f && p.ai[1] == npc.whoAmI) { projectileCount++; } @@ -653,10 +652,10 @@ namespace CalamityMod.NPCs npc.lifeRegen = 0; int projectileCount = 0; - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[j].active && Main.projectile[j].type == ProjectileType() && - Main.projectile[j].ai[0] == 1f && Main.projectile[j].ai[1] == npc.whoAmI) + if (p.type == ProjectileType() && + p.ai[0] == 1f && p.ai[1] == npc.whoAmI) { projectileCount++; } @@ -675,12 +674,12 @@ namespace CalamityMod.NPCs { int projectileCount = 0; int owner = 255; - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[j].active && Main.projectile[j].type == ProjectileType() && - Main.projectile[j].ai[0] == 1f && Main.projectile[j].ai[1] == npc.whoAmI) + if (p.type == ProjectileType() && + p.ai[0] == 1f && p.ai[1] == npc.whoAmI) { - owner = Main.projectile[j].owner; + owner = p.owner; projectileCount++; if (projectileCount >= 5) { @@ -717,13 +716,13 @@ namespace CalamityMod.NPCs if (clamDebuff > 0) { int projectileCount = 0; - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[j].active && Main.projectile[j].ai[0] == 1f && Main.projectile[j].ai[1] == npc.whoAmI) + if (p.ai[0] == 1f && p.ai[1] == npc.whoAmI) { - if (Main.projectile[j].type == ProjectileType()) + if (p.type == ProjectileType()) projectileCount += 2; - if (Main.projectile[j].type == ProjectileType()) + if (p.type == ProjectileType()) projectileCount++; } } @@ -734,10 +733,10 @@ namespace CalamityMod.NPCs if (irradiated > 0) { int projectileCount = 0; - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[j].active && Main.projectile[j].type == ProjectileType() && - Main.projectile[j].ai[0] == 1f && Main.projectile[j].ai[1] == npc.whoAmI) + if (p.type == ProjectileType() && + p.ai[0] == 1f && p.ai[1] == npc.whoAmI) { projectileCount++; } @@ -5473,15 +5472,15 @@ namespace CalamityMod.NPCs { int bullseyeType = ProjectileType(); Projectile bullseye = null; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != bullseyeType || !Main.projectile[i].active || Main.projectile[i].owner != player.whoAmI) + if (p.type != bullseyeType || p.owner != player.whoAmI) continue; // Only choose a bullseye if it is attached to the NPC that is being hit. - if (npc.whoAmI == (int)Main.projectile[i].ai[0]) + if (npc.whoAmI == (int)p.ai[0]) { - bullseye = Main.projectile[i]; + bullseye = p; break; } } @@ -5823,10 +5822,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); } } @@ -7810,9 +7808,9 @@ namespace CalamityMod.NPCs #region Player Counts public static bool AnyLivingPlayers() { - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - if (Main.player[i] != null && Main.player[i].active && !Main.player[i].dead && !Main.player[i].ghost) + if (!player.dead && !player.ghost) { return true; } @@ -7827,15 +7825,7 @@ namespace CalamityMod.NPCs return 1; } - int players = 0; - for (int i = 0; i < Main.maxPlayers; i++) - { - if (Main.player[i] != null && Main.player[i].active) - { - players++; - } - } - return players; + return Main.CurrentFrameFlags.ActivePlayersCount; } #endregion @@ -7901,12 +7891,11 @@ namespace CalamityMod.NPCs return; Projectile proj = null; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - proj = Main.projectile[i]; - if (Main.projectile[i].active && Main.projectile[i].bobber && Main.projectile[i].owner == player.whoAmI) + proj = p; + if (p.bobber && p.owner == player.whoAmI) { - proj = Main.projectile[i]; break; } } diff --git a/NPCs/CalamityGlobalNPCLoot.cs b/NPCs/CalamityGlobalNPCLoot.cs index 85dd2cb643..6b875b8cad 100644 --- a/NPCs/CalamityGlobalNPCLoot.cs +++ b/NPCs/CalamityGlobalNPCLoot.cs @@ -2031,11 +2031,11 @@ DukeEditFailed: internal static void SplittingWormBroadcastInteraction(NPC npc, int player, int head, int body, int tail) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != npc.whoAmI && Main.npc[i].active && (Main.npc[i].type == head || Main.npc[i].type == body || Main.npc[i].type == tail)) + if (n.whoAmI != npc.whoAmI && (n.type == head || n.type == body || n.type == tail)) { - Main.npc[i].ApplyInteraction(player); + n.ApplyInteraction(player); } } } @@ -2105,9 +2105,9 @@ DukeEditFailed: bool CheckSegments(int head, int body, int tail) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != npc.whoAmI && Main.npc[i].active && (Main.npc[i].type == head || Main.npc[i].type == body || Main.npc[i].type == tail)) + if (n.whoAmI != npc.whoAmI && (n.type == head || n.type == body || n.type == tail)) { return false; } diff --git a/NPCs/CalamityGlobalTownNPC.cs b/NPCs/CalamityGlobalTownNPC.cs index 7800b4b05b..ae24263c1f 100644 --- a/NPCs/CalamityGlobalTownNPC.cs +++ b/NPCs/CalamityGlobalTownNPC.cs @@ -17,6 +17,7 @@ using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.NPCs.TownNPCs; +using CalamityMod.Projectiles.Rogue; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -1064,6 +1065,14 @@ namespace CalamityMod.NPCs defense += 20; } } + + public override bool? CanBeHitByProjectile(NPC npc, Projectile projectile) + { + //Not an axe but close enough + if (npc.type == NPCID.TaxCollector && projectile.type == ModContent.ProjectileType()) + return true; + return base.CanBeHitByProjectile(npc, projectile); + } #endregion #region Shop Stuff @@ -1074,14 +1083,14 @@ namespace CalamityMod.NPCs bool happy = Main.LocalPlayer.currentShoppingSettings.PriceAdjustment <= 0.9; - Condition potionSells = new(CalamityUtils.GetText("Condition.PotionConfig"), () => CalamityConfig.Instance.PotionSelling); + Condition potionSells = CalamityConditions.PotionSellingConfig; Condition hasFlareGunUpgrade = new(CalamityUtils.GetText("Condition.HasFlareGun"), () => (Main.LocalPlayer.HasItem(ItemType()) || Main.LocalPlayer.HasItem(ItemType())) && !Main.LocalPlayer.HasItem(ItemID.FlareGun)); - Condition roguePlayer = new(CalamityUtils.GetText("Condition.HasRogueArmor"), () => Main.LocalPlayer.Calamity().rogueStealthMax > 0f && Main.LocalPlayer.Calamity().wearingRogueArmor); - Condition wingedPlayer = new(CalamityUtils.GetText("Condition.HasWings"), () => Main.LocalPlayer.wingTimeMax > 0); - Condition revengeance = new(CalamityUtils.GetText("Condition.InRev"), () => CalamityWorld.revenge); - Condition drunk = new(CalamityUtils.GetText("Condition.AlcoholPoison"), () => Main.LocalPlayer.Calamity().alcoholPoisoning); - Condition downedPolterghast = new(CalamityUtils.GetText("Condition.PostPolter"), () => DownedBossSystem.downedPolterghast); - Condition downedDoG = new(CalamityUtils.GetText("Condition.PostDoG"), () => DownedBossSystem.downedDoG); + Condition roguePlayer = CalamityConditions.PlayerHasRogueArmor; + Condition wingedPlayer = CalamityConditions.PlayerHasWings; + Condition revengeance = CalamityConditions.InRevengeanceMode; + Condition drunk = CalamityConditions.PlayerAlcoholPoisoned; + Condition downedPolterghast = CalamityConditions.DownedPolterghast; + Condition downedDoG = CalamityConditions.DownedDevourerOfGods; if (type == NPCID.Merchant) { diff --git a/NPCs/Crabulon/CrabShroom.cs b/NPCs/Crabulon/CrabShroom.cs index fe2ecc6d04..c3dda3d521 100644 --- a/NPCs/Crabulon/CrabShroom.cs +++ b/NPCs/Crabulon/CrabShroom.cs @@ -106,24 +106,21 @@ namespace CalamityMod.NPCs.Crabulon if (CalamityWorld.LegendaryMode && CalamityWorld.revenge) { float pushVelocity = 0.5f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < 30f * NPC.scale) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 30f * NPC.scale) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= pushVelocity; - else - NPC.velocity.X += pushVelocity; + if (NPC.position.X < n.position.X) + NPC.velocity.X -= pushVelocity; + else + NPC.velocity.X += pushVelocity; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= pushVelocity; - else - NPC.velocity.Y += pushVelocity; - } + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y -= pushVelocity; + else + NPC.velocity.Y += pushVelocity; } } } diff --git a/NPCs/DesertScourge/DesertNuisanceBody.cs b/NPCs/DesertScourge/DesertNuisanceBody.cs index a37c59a5c8..e666fc7b04 100644 --- a/NPCs/DesertScourge/DesertNuisanceBody.cs +++ b/NPCs/DesertScourge/DesertNuisanceBody.cs @@ -164,15 +164,7 @@ namespace CalamityMod.NPCs.DesertScourge if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/DesertScourge/DesertNuisanceHead.cs b/NPCs/DesertScourge/DesertNuisanceHead.cs index b6cdd5e965..564cf646cc 100644 --- a/NPCs/DesertScourge/DesertNuisanceHead.cs +++ b/NPCs/DesertScourge/DesertNuisanceHead.cs @@ -249,19 +249,15 @@ namespace CalamityMod.NPCs.DesertScourge bool shouldDirectlyChase = true; if (NPC.position.Y > Main.player[NPC.target].position.Y) { - for (int m = 0; m < Main.maxPlayers; m++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[m].active) + Rectangle rectangle2 = new Rectangle((int)plr.position.X - directChaseDistance, (int)plr.position.Y - directChaseDistance, directChaseDistance * 2, directChaseDistance * 2); + if (rectangle.Intersects(rectangle2)) { - Rectangle rectangle2 = new Rectangle((int)Main.player[m].position.X - directChaseDistance, (int)Main.player[m].position.Y - directChaseDistance, directChaseDistance * 2, directChaseDistance * 2); - if (rectangle.Intersects(rectangle2)) - { - shouldDirectlyChase = false; - break; - } + shouldDirectlyChase = false; + break; } } - if (shouldDirectlyChase) shouldFly = true; } diff --git a/NPCs/DesertScourge/DesertNuisanceTail.cs b/NPCs/DesertScourge/DesertNuisanceTail.cs index 285b6f2806..860e56f7b0 100644 --- a/NPCs/DesertScourge/DesertNuisanceTail.cs +++ b/NPCs/DesertScourge/DesertNuisanceTail.cs @@ -69,15 +69,7 @@ namespace CalamityMod.NPCs.DesertScourge if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/DesertScourge/DesertScourgeBody.cs b/NPCs/DesertScourge/DesertScourgeBody.cs index 628434af56..daa0b54eae 100644 --- a/NPCs/DesertScourge/DesertScourgeBody.cs +++ b/NPCs/DesertScourge/DesertScourgeBody.cs @@ -182,15 +182,7 @@ namespace CalamityMod.NPCs.DesertScourge if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/DesertScourge/DesertScourgeHead.cs b/NPCs/DesertScourge/DesertScourgeHead.cs index c0aa4509c0..ef2068422d 100644 --- a/NPCs/DesertScourge/DesertScourgeHead.cs +++ b/NPCs/DesertScourge/DesertScourgeHead.cs @@ -528,21 +528,17 @@ namespace CalamityMod.NPCs.DesertScourge { int rectWidth = directChaseDistance * 2; int rectHeight = directChaseDistance * 2; - for (int m = 0; m < Main.maxPlayers; m++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[m].active) + int rectX = (int)plr.position.X - directChaseDistance; + int rectY = (int)plr.position.Y - directChaseDistance; + Rectangle directChaseRect = new Rectangle(rectX, rectY, rectWidth, rectHeight); + if (rectangle.Intersects(directChaseRect)) { - int rectX = (int)Main.player[m].position.X - directChaseDistance; - int rectY = (int)Main.player[m].position.Y - directChaseDistance; - Rectangle directChaseRect = new Rectangle(rectX, rectY, rectWidth, rectHeight); - if (rectangle.Intersects(directChaseRect)) - { - shouldDirectlyChase = false; - break; - } + shouldDirectlyChase = false; + break; } } - if (shouldDirectlyChase) shouldFly = true; } diff --git a/NPCs/DesertScourge/DesertScourgeTail.cs b/NPCs/DesertScourge/DesertScourgeTail.cs index abf6aca169..749dd0791a 100644 --- a/NPCs/DesertScourge/DesertScourgeTail.cs +++ b/NPCs/DesertScourge/DesertScourgeTail.cs @@ -91,15 +91,7 @@ namespace CalamityMod.NPCs.DesertScourge if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/DevourerofGods/CosmicGuardianBody.cs b/NPCs/DevourerofGods/CosmicGuardianBody.cs index 184958c7f5..6c0600c59f 100644 --- a/NPCs/DevourerofGods/CosmicGuardianBody.cs +++ b/NPCs/DevourerofGods/CosmicGuardianBody.cs @@ -93,15 +93,7 @@ namespace CalamityMod.NPCs.DevourerofGods NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/DevourerofGods/CosmicGuardianHead.cs b/NPCs/DevourerofGods/CosmicGuardianHead.cs index 72df92eb3b..eb7ef94bad 100644 --- a/NPCs/DevourerofGods/CosmicGuardianHead.cs +++ b/NPCs/DevourerofGods/CosmicGuardianHead.cs @@ -199,11 +199,11 @@ namespace CalamityMod.NPCs.DevourerofGods else if (increaseSpeed) velocityMult *= 2f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && (Main.npc[i].type == NPC.type || Main.npc[i].type == ModContent.NPCType()) && i != NPC.whoAmI) + if ((n.type == NPC.type || n.type == ModContent.NPCType()) && n.whoAmI != NPC.whoAmI) { - Vector2 distFromHead = Main.npc[i].Center - NPC.Center; + Vector2 distFromHead = n.Center - NPC.Center; if (distFromHead.Length() < maxDistanceFromDoGHead) { distFromHead.Normalize(); diff --git a/NPCs/DevourerofGods/CosmicGuardianTail.cs b/NPCs/DevourerofGods/CosmicGuardianTail.cs index 5d2c622fa4..d44bab21c7 100644 --- a/NPCs/DevourerofGods/CosmicGuardianTail.cs +++ b/NPCs/DevourerofGods/CosmicGuardianTail.cs @@ -90,15 +90,7 @@ namespace CalamityMod.NPCs.DevourerofGods NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/DevourerofGods/DevourerofGodsBody.cs b/NPCs/DevourerofGods/DevourerofGodsBody.cs index b77ecc0466..aff92981bc 100644 --- a/NPCs/DevourerofGods/DevourerofGodsBody.cs +++ b/NPCs/DevourerofGods/DevourerofGodsBody.cs @@ -206,15 +206,7 @@ namespace CalamityMod.NPCs.DevourerofGods Player player = Main.player[NPC.target]; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) @@ -376,9 +368,9 @@ namespace CalamityMod.NPCs.DevourerofGods private bool AnyTeleportRifts() { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == ModContent.ProjectileType()) + if (p.type == ModContent.ProjectileType()) return true; } return false; diff --git a/NPCs/DevourerofGods/DevourerofGodsHead.cs b/NPCs/DevourerofGods/DevourerofGodsHead.cs index bfe4a051f5..705f248c4c 100644 --- a/NPCs/DevourerofGods/DevourerofGodsHead.cs +++ b/NPCs/DevourerofGods/DevourerofGodsHead.cs @@ -2454,20 +2454,20 @@ namespace CalamityMod.NPCs.DevourerofGods if (NPC.netSpam >= 10) NPC.netSpam = 9; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && (Main.npc[i].type == ModContent.NPCType() || Main.npc[i].type == ModContent.NPCType())) + if (n.type == ModContent.NPCType() || n.type == ModContent.NPCType()) { - Main.npc[i].position = newPosition; + n.position = newPosition; - if (Main.npc[i].type == ModContent.NPCType()) - ((DevourerofGodsTail)Main.npc[i].ModNPC).setInvulTime(720); + if (n.type == ModContent.NPCType()) + ((DevourerofGodsTail)n.ModNPC).setInvulTime(720); - Main.npc[i].netUpdate = true; + n.netUpdate = true; // Prevent netUpdate from being blocked by the spam counter. - if (Main.npc[i].netSpam >= 10) - Main.npc[i].netSpam = 9; + if (n.netSpam >= 10) + n.netSpam = 9; } } @@ -2498,28 +2498,28 @@ namespace CalamityMod.NPCs.DevourerofGods ModContent.NPCType(), ModContent.NPCType() }; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (segments.Contains(Main.npc[i].type) && Main.npc[i].active && - (Main.npc[i].type == segments[1] || Main.npc[i].ModNPC().SegmentIndex == index)) + if (segments.Contains(n.type) && n.active && + (n.type == segments[1] || n.ModNPC().SegmentIndex == index)) { for (int j = 0; j < 20; j++) { - Dust cosmicBurst = Dust.NewDustPerfect(Main.npc[i].Center + Main.rand.NextVector2Circular(25f, 25f), 234); + Dust cosmicBurst = Dust.NewDustPerfect(n.Center + Main.rand.NextVector2Circular(25f, 25f), 234); cosmicBurst.scale = 1.7f; cosmicBurst.velocity = Main.rand.NextVector2Circular(9f, 9f); cosmicBurst.noGravity = true; } - Main.npc[i].life = 0; - Main.npc[i].HitEffect(); - Main.npc[i].active = false; + n.life = 0; + n.HitEffect(); + n.active = false; - Main.npc[i].netUpdate = true; + n.netUpdate = true; // Prevent netUpdate from being blocked by the spam counter. - if (Main.npc[i].netSpam >= 10) - Main.npc[i].netSpam = 9; + if (n.netSpam >= 10) + n.netSpam = 9; destroyedSegments++; break; @@ -2588,9 +2588,8 @@ namespace CalamityMod.NPCs.DevourerofGods private Vector2 GetRiftLocation(bool spawnDust) { Vector2 realSpot = default; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; if (proj.type == ModContent.ProjectileType()) { if (!spawnDust) diff --git a/NPCs/DevourerofGods/DevourerofGodsTail.cs b/NPCs/DevourerofGods/DevourerofGodsTail.cs index ffcf9c3123..36b7a39663 100644 --- a/NPCs/DevourerofGods/DevourerofGodsTail.cs +++ b/NPCs/DevourerofGods/DevourerofGodsTail.cs @@ -217,15 +217,7 @@ namespace CalamityMod.NPCs.DevourerofGods NPC.takenDamageMultiplier = 1.25f; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/DevourerofGods/DoGScreenShaderData.cs b/NPCs/DevourerofGods/DoGScreenShaderData.cs index 74963b76e8..78a58b4511 100644 --- a/NPCs/DevourerofGods/DoGScreenShaderData.cs +++ b/NPCs/DevourerofGods/DoGScreenShaderData.cs @@ -23,11 +23,11 @@ namespace CalamityMod.NPCs.DevourerofGods return; } DoGIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == DoGType) + if (n.type == DoGType) { - DoGIndex = i; + DoGIndex = n.whoAmI; break; } } diff --git a/NPCs/DevourerofGods/DoGSky.cs b/NPCs/DevourerofGods/DoGSky.cs index 76a41b16b9..ded6e6fd46 100644 --- a/NPCs/DevourerofGods/DoGSky.cs +++ b/NPCs/DevourerofGods/DoGSky.cs @@ -62,11 +62,11 @@ namespace CalamityMod.NPCs.DevourerofGods return true; } DoGIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == DoGType) + if (n.type == DoGType) { - DoGIndex = i; + DoGIndex = n.whoAmI; break; } } diff --git a/NPCs/DraedonLabThings/Androomba.cs b/NPCs/DraedonLabThings/Androomba.cs index d867d59bc8..012e36788c 100644 --- a/NPCs/DraedonLabThings/Androomba.cs +++ b/NPCs/DraedonLabThings/Androomba.cs @@ -87,9 +87,8 @@ namespace CalamityMod.NPCs.DraedonLabThings NPC.ai[2] *= -1; } // If she sees someone, start running - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; if (Collision.CanHit(NPC.position, NPC.width, NPC.height, player.position, player.width, player.height)) { ChangeAI(1); @@ -152,12 +151,8 @@ namespace CalamityMod.NPCs.DraedonLabThings break; } - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active) - continue; - if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) { Main.BestiaryTracker.Kills.RegisterKill(NPC); diff --git a/NPCs/DraedonLabThings/NanodroidDysfunctional.cs b/NPCs/DraedonLabThings/NanodroidDysfunctional.cs index fba1017618..c2ffabf81f 100644 --- a/NPCs/DraedonLabThings/NanodroidDysfunctional.cs +++ b/NPCs/DraedonLabThings/NanodroidDysfunctional.cs @@ -42,12 +42,8 @@ namespace CalamityMod.NPCs.DraedonLabThings { Lighting.AddLight(NPC.Center, 0.25f, 0.1f, 0f); } - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active) - continue; - if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) { NPC nPC = new NPC(); diff --git a/NPCs/DraedonLabThings/NanodroidPlagueGreen.cs b/NPCs/DraedonLabThings/NanodroidPlagueGreen.cs index 9b7f651e01..babe18e052 100644 --- a/NPCs/DraedonLabThings/NanodroidPlagueGreen.cs +++ b/NPCs/DraedonLabThings/NanodroidPlagueGreen.cs @@ -42,12 +42,8 @@ namespace CalamityMod.NPCs.DraedonLabThings { Lighting.AddLight(NPC.Center, 0.03f, 0.3f, 0.05f); } - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active) - continue; - if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) { NPC nPC = new NPC(); diff --git a/NPCs/DraedonLabThings/NanodroidPlagueRed.cs b/NPCs/DraedonLabThings/NanodroidPlagueRed.cs index 7473e4dd55..ca28f3ce7f 100644 --- a/NPCs/DraedonLabThings/NanodroidPlagueRed.cs +++ b/NPCs/DraedonLabThings/NanodroidPlagueRed.cs @@ -42,12 +42,8 @@ namespace CalamityMod.NPCs.DraedonLabThings { Lighting.AddLight(NPC.Center, 0.3f, 0.03f, 0f); } - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active) - continue; - if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) { NPC nPC = new NPC(); diff --git a/NPCs/DraedonLabThings/RepairUnitCritter.cs b/NPCs/DraedonLabThings/RepairUnitCritter.cs index b6a844db97..0edf8ef94a 100644 --- a/NPCs/DraedonLabThings/RepairUnitCritter.cs +++ b/NPCs/DraedonLabThings/RepairUnitCritter.cs @@ -138,12 +138,8 @@ namespace CalamityMod.NPCs.DraedonLabThings } Time++; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active) - continue; - if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) { Main.BestiaryTracker.Kills.RegisterKill(NPC); diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs index eba4711d38..37f8031eee 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -1766,10 +1766,9 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo public override bool CheckDead() { // Kill Artemis if he's still alive when Apollo dies - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[i]; - if (nPC.active && nPC.type == ModContent.NPCType() && nPC.life > 0) + if (nPC.type == ModContent.NPCType() && nPC.life > 0) { nPC.life = 0; nPC.HitEffect(); diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs index 705b0c02f0..f53b9eead4 100644 --- a/NPCs/ExoMechs/Artemis/Artemis.cs +++ b/NPCs/ExoMechs/Artemis/Artemis.cs @@ -1142,11 +1142,11 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis { calamityGlobalNPC.newAI[3] = 0f; AIState = (float)Phase.Deathray; - for (int i = 0; i < Main.maxProjectiles; i ++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == ModContent.ProjectileType()) + if (p.type == ModContent.ProjectileType()) { - Main.projectile[i].active = false; + p.active = false; continue; } } @@ -1602,10 +1602,9 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis public override bool CheckDead() { // Kill Apollo if he's still alive when Artemis dies - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[i]; - if (nPC.active && nPC.type == ModContent.NPCType() && nPC.life > 0) + if (nPC.type == ModContent.NPCType() && nPC.life > 0) { nPC.life = 0; nPC.HitEffect(); diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs index d14f1fbf62..4dc825f12a 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs @@ -147,15 +147,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos bool expertMode = Main.expertMode || bossRush; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) @@ -290,16 +282,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { - whoAmIArray[numProjectiles] = i; + whoAmIArray[numProjectiles] = plr.whoAmI; targetCenterArray[numProjectiles] = playerCenter; int projectileLimit = numProjectiles + 1; numProjectiles = projectileLimit; @@ -354,16 +346,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { - whoAmIArray[numProjectiles] = i; + whoAmIArray[numProjectiles] = plr.whoAmI; targetCenterArray[numProjectiles] = playerCenter; int projectileLimit = numProjectiles + 1; numProjectiles = projectileLimit; diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs index 9b3cdbe77f..087418c40c 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs @@ -146,15 +146,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos bool expertMode = Main.expertMode || bossRush; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) @@ -289,12 +281,12 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { @@ -353,16 +345,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { - whoAmIArray[numProjectiles] = i; + whoAmIArray[numProjectiles] = plr.whoAmI; targetCenterArray[numProjectiles] = playerCenter; int projectileLimit = numProjectiles + 1; numProjectiles = projectileLimit; diff --git a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs index 7b5ea2721a..23622c7c61 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs @@ -146,15 +146,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos bool expertMode = Main.expertMode || bossRush; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) @@ -289,16 +281,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { - whoAmIArray[numProjectiles] = i; + whoAmIArray[numProjectiles] = plr.whoAmI; targetCenterArray[numProjectiles] = playerCenter; int projectileLimit = numProjectiles + 1; numProjectiles = projectileLimit; @@ -353,16 +345,16 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { - whoAmIArray[numProjectiles] = i; + whoAmIArray[numProjectiles] = plr.whoAmI; targetCenterArray[numProjectiles] = playerCenter; int projectileLimit = numProjectiles + 1; numProjectiles = projectileLimit; diff --git a/NPCs/Leviathan/Anahita.cs b/NPCs/Leviathan/Anahita.cs index 84462774fc..270966cff3 100644 --- a/NPCs/Leviathan/Anahita.cs +++ b/NPCs/Leviathan/Anahita.cs @@ -511,13 +511,7 @@ namespace CalamityMod.NPCs.Leviathan float restingPlayerDistance = (float)Math.Sqrt(restingPlayerXDist * restingPlayerXDist + restingPlayerYDist * restingPlayerYDist); NPC.ai[1] += 1f; - int activePlayerAmt = 0; - for (int i = 0; i < 255; i++) - { - if (Main.player[i].active && !Main.player[i].dead && (NPC.Center - Main.player[i].Center).Length() < 1000f) - activePlayerAmt++; - } - NPC.ai[1] += activePlayerAmt / 2; + NPC.ai[1] += Main.CurrentFrameFlags.ActivePlayersCount / 2; bool spawnedBubble = false; float bubbleDelay = 20f; diff --git a/NPCs/Leviathan/AquaticAberration.cs b/NPCs/Leviathan/AquaticAberration.cs index 55d330b8b9..e98ae031d8 100644 --- a/NPCs/Leviathan/AquaticAberration.cs +++ b/NPCs/Leviathan/AquaticAberration.cs @@ -237,24 +237,21 @@ namespace CalamityMod.NPCs.Leviathan if (death) { float pushVelocity = 0.5f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < 80f * NPC.scale) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 80f * NPC.scale) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= pushVelocity; - else - NPC.velocity.X += pushVelocity; + if (NPC.position.X < n.position.X) + NPC.velocity.X -= pushVelocity; + else + NPC.velocity.X += pushVelocity; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= pushVelocity; - else - NPC.velocity.Y += pushVelocity; - } + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y -= pushVelocity; + else + NPC.velocity.Y += pushVelocity; } } } diff --git a/NPCs/Leviathan/LevScreenShaderData.cs b/NPCs/Leviathan/LevScreenShaderData.cs index 3552560be3..8dc3343de2 100644 --- a/NPCs/Leviathan/LevScreenShaderData.cs +++ b/NPCs/Leviathan/LevScreenShaderData.cs @@ -24,11 +24,11 @@ namespace CalamityMod.NPCs.Leviathan return; } LevIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == LevType) + if (n.type == LevType) { - LevIndex = i; + LevIndex = n.whoAmI; break; } } diff --git a/NPCs/Leviathan/LevSky.cs b/NPCs/Leviathan/LevSky.cs index 17c53ba72b..fbe87825de 100644 --- a/NPCs/Leviathan/LevSky.cs +++ b/NPCs/Leviathan/LevSky.cs @@ -67,11 +67,11 @@ namespace CalamityMod.NPCs.Leviathan return true; } LevIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == LevType) + if (n.type == LevType) { - LevIndex = i; + LevIndex = n.whoAmI; break; } } diff --git a/NPCs/NormalNPCs/ArmoredDiggerBody.cs b/NPCs/NormalNPCs/ArmoredDiggerBody.cs index 8a6ecf8271..26296ef13d 100644 --- a/NPCs/NormalNPCs/ArmoredDiggerBody.cs +++ b/NPCs/NormalNPCs/ArmoredDiggerBody.cs @@ -81,10 +81,9 @@ namespace CalamityMod.NPCs.NormalNPCs else { // find a new npc to attatch to in gfb, it's not a bug, it's a feature:tm: - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC host in Main.ActiveNPCs) { - NPC host = Main.npc[i]; - if (host.active && !host.friendly && !host.dontTakeDamage && host.type != ModContent.NPCType() && host.type != ModContent.NPCType() && host.type != ModContent.NPCType()) + if (!host.friendly && !host.dontTakeDamage && host.type != ModContent.NPCType() && host.type != ModContent.NPCType() && host.type != ModContent.NPCType()) { NPC.ai[1] = host.whoAmI; NPC.ai[3] = host.whoAmI; diff --git a/NPCs/NormalNPCs/ArmoredDiggerHead.cs b/NPCs/NormalNPCs/ArmoredDiggerHead.cs index 448082010e..1fc942cfb8 100644 --- a/NPCs/NormalNPCs/ArmoredDiggerHead.cs +++ b/NPCs/NormalNPCs/ArmoredDiggerHead.cs @@ -169,16 +169,13 @@ namespace CalamityMod.NPCs.NormalNPCs bool outsideNoFlyZone = true; if (NPC.position.Y > Main.player[NPC.target].position.Y) { - for (int m = 0; m < 255; m++) + foreach (Player player in Main.ActivePlayers) { - if (Main.player[m].active) + Rectangle noFlyArea = new Rectangle((int)player.position.X - noFlyZone, (int)player.position.Y - noFlyZone, noFlyZone * 2, noFlyZone * 2); + if (rectangle.Intersects(noFlyArea)) { - Rectangle noFlyArea = new Rectangle((int)Main.player[m].position.X - noFlyZone, (int)Main.player[m].position.Y - noFlyZone, noFlyZone * 2, noFlyZone * 2); - if (rectangle.Intersects(noFlyArea)) - { - outsideNoFlyZone = false; - break; - } + outsideNoFlyZone = false; + break; } } if (outsideNoFlyZone) diff --git a/NPCs/NormalNPCs/PlanterasFreeTentacle.cs b/NPCs/NormalNPCs/PlanterasFreeTentacle.cs index 0cbf988952..f3912e4d09 100644 --- a/NPCs/NormalNPCs/PlanterasFreeTentacle.cs +++ b/NPCs/NormalNPCs/PlanterasFreeTentacle.cs @@ -171,24 +171,21 @@ namespace CalamityMod.NPCs.NormalNPCs } float pushVelocity = 0.5f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < 40f * NPC.scale) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 40f * NPC.scale) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= pushVelocity; - else - NPC.velocity.X += pushVelocity; + if (NPC.position.X < n.position.X) + NPC.velocity.X -= pushVelocity; + else + NPC.velocity.X += pushVelocity; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= pushVelocity; - else - NPC.velocity.Y += pushVelocity; - } + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y -= pushVelocity; + else + NPC.velocity.Y += pushVelocity; } } } diff --git a/NPCs/NormalNPCs/WulfrumAmplifier.cs b/NPCs/NormalNPCs/WulfrumAmplifier.cs index 5519d7528c..d6c1823226 100644 --- a/NPCs/NormalNPCs/WulfrumAmplifier.cs +++ b/NPCs/NormalNPCs/WulfrumAmplifier.cs @@ -165,12 +165,8 @@ namespace CalamityMod.NPCs.NormalNPCs } } - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var npcAtIndex in Main.ActiveNPCs) { - NPC npcAtIndex = Main.npc[i]; - if (!npcAtIndex.active) - continue; - // For some strange reason, the Wulfrum enemies are not counted when SuperchargableEnemies is a static list declared up front. // What I assume is going on is that it hasn't been loaded yet since it's later alphabetically (Amplifier is before the other enemies). if (!SuperchargableEnemies.Contains(npcAtIndex.type) && npcAtIndex.type != ModContent.NPCType()) diff --git a/NPCs/OldDuke/OldDukeToothBall.cs b/NPCs/OldDuke/OldDukeToothBall.cs index bf297747ac..f880849a6e 100644 --- a/NPCs/OldDuke/OldDukeToothBall.cs +++ b/NPCs/OldDuke/OldDukeToothBall.cs @@ -147,24 +147,21 @@ namespace CalamityMod.NPCs.OldDuke NPC.velocity.Y = (NPC.velocity.Y * inertia + targetYDist) / (inertia + 1f); float toothBallAccel = bossRush ? 0.65f : 0.5f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < 48f) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 48f) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= toothBallAccel; - else - NPC.velocity.X += toothBallAccel; + if (NPC.position.X < n.position.X) + NPC.velocity.X -= toothBallAccel; + else + NPC.velocity.X += toothBallAccel; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= toothBallAccel; - else - NPC.velocity.Y += toothBallAccel; - } + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y -= toothBallAccel; + else + NPC.velocity.Y += toothBallAccel; } } } diff --git a/NPCs/OldDuke/SulphurousSharkron.cs b/NPCs/OldDuke/SulphurousSharkron.cs index e0d2298c82..f1480f9f0a 100644 --- a/NPCs/OldDuke/SulphurousSharkron.cs +++ b/NPCs/OldDuke/SulphurousSharkron.cs @@ -188,24 +188,21 @@ namespace CalamityMod.NPCs.OldDuke } float pushVelocity = 0.5f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < 160f) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 160f) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= pushVelocity; - else - NPC.velocity.X += pushVelocity; + if (NPC.position.X < n.position.X) + NPC.velocity.X -= pushVelocity; + else + NPC.velocity.X += pushVelocity; - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= pushVelocity; - else - NPC.velocity.Y += pushVelocity; - } + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y -= pushVelocity; + else + NPC.velocity.Y += pushVelocity; } } } diff --git a/NPCs/Other/DemonPortal.cs b/NPCs/Other/DemonPortal.cs index 99a6c00f2c..630cd48ca1 100644 --- a/NPCs/Other/DemonPortal.cs +++ b/NPCs/Other/DemonPortal.cs @@ -47,14 +47,14 @@ namespace CalamityMod.NPCs.Other NPC.dontTakeDamage = true; NPC.netUpdate = true; int demonType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != demonType || !Main.projectile[i].active || Main.projectile[i].hostile) + if (p.type != demonType || p.hostile) continue; - Main.projectile[i].hostile = true; - Main.projectile[i].friendly = false; - Main.projectile[i].netUpdate = true; + p.hostile = true; + p.friendly = false; + p.netUpdate = true; } } diff --git a/NPCs/Other/THELORDE.cs b/NPCs/Other/THELORDE.cs index bc6876021a..dc4b4ad615 100644 --- a/NPCs/Other/THELORDE.cs +++ b/NPCs/Other/THELORDE.cs @@ -320,9 +320,8 @@ namespace CalamityMod.NPCs.Other NPC.ai[3] = 0f; NPC.aiStyle = (urAMemeNow ? -1 : aiChoice); NPC.netUpdate = true; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; if (proj.type == ModContent.ProjectileType() || proj.type == ModContent.ProjectileType()) { proj.Kill(); diff --git a/NPCs/Perforator/PerforatorBodyLarge.cs b/NPCs/Perforator/PerforatorBodyLarge.cs index 01fb9ffb94..c25aae7727 100644 --- a/NPCs/Perforator/PerforatorBodyLarge.cs +++ b/NPCs/Perforator/PerforatorBodyLarge.cs @@ -91,15 +91,7 @@ namespace CalamityMod.NPCs.Perforator if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(true); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/Perforator/PerforatorBodySmall.cs b/NPCs/Perforator/PerforatorBodySmall.cs index edbe9583e2..08627fc303 100644 --- a/NPCs/Perforator/PerforatorBodySmall.cs +++ b/NPCs/Perforator/PerforatorBodySmall.cs @@ -86,15 +86,7 @@ namespace CalamityMod.NPCs.Perforator if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(true); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/Perforator/PerforatorHeadLarge.cs b/NPCs/Perforator/PerforatorHeadLarge.cs index 95dd7fde47..ae4e888120 100644 --- a/NPCs/Perforator/PerforatorHeadLarge.cs +++ b/NPCs/Perforator/PerforatorHeadLarge.cs @@ -246,19 +246,15 @@ namespace CalamityMod.NPCs.Perforator bool outsideFlyingRadius = true; if (NPC.position.Y > player.position.Y) { - for (int m = 0; m < Main.maxPlayers; m++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[m].active) + Rectangle rectangle2 = new Rectangle((int)plr.position.X - stopFlyingRadius, (int)plr.position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2); + if (rectangle.Intersects(rectangle2)) { - Rectangle rectangle2 = new Rectangle((int)Main.player[m].position.X - stopFlyingRadius, (int)Main.player[m].position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2); - if (rectangle.Intersects(rectangle2)) - { - outsideFlyingRadius = false; - break; - } + outsideFlyingRadius = false; + break; } } - if (outsideFlyingRadius) shouldFly = true; } diff --git a/NPCs/Perforator/PerforatorHeadMedium.cs b/NPCs/Perforator/PerforatorHeadMedium.cs index 4170cfdc34..acdb3c712b 100644 --- a/NPCs/Perforator/PerforatorHeadMedium.cs +++ b/NPCs/Perforator/PerforatorHeadMedium.cs @@ -527,11 +527,12 @@ namespace CalamityMod.NPCs.Perforator } } - for (int i = 0; i < Main.maxNPCs; i++) + // ???? + /*for (int i = 0; i < Main.maxNPCs; i++) { if (i != NPC.whoAmI && Main.npc[i].active && (Main.npc[i].type == NPC.type || Main.npc[i].type == ModContent.NPCType() || Main.npc[i].type == ModContent.NPCType())) return; - } + }*/ } public override void BossLoot(ref string name, ref int potionType) diff --git a/NPCs/Perforator/PerforatorHeadSmall.cs b/NPCs/Perforator/PerforatorHeadSmall.cs index 8d341da595..40a2a555dc 100644 --- a/NPCs/Perforator/PerforatorHeadSmall.cs +++ b/NPCs/Perforator/PerforatorHeadSmall.cs @@ -238,19 +238,15 @@ namespace CalamityMod.NPCs.Perforator bool outsideFlyRadius = true; if (NPC.position.Y > player.position.Y) { - for (int m = 0; m < Main.maxPlayers; m++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[m].active) + Rectangle rectangle2 = new Rectangle((int)plr.position.X - stopFlyingRadius, (int)plr.position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2); + if (rectangle.Intersects(rectangle2)) { - Rectangle rectangle2 = new Rectangle((int)Main.player[m].position.X - stopFlyingRadius, (int)Main.player[m].position.Y - stopFlyingRadius, stopFlyingRadius * 2, stopFlyingRadius * 2); - if (rectangle.Intersects(rectangle2)) - { - outsideFlyRadius = false; - break; - } + outsideFlyRadius = false; + break; } } - if (outsideFlyRadius) shouldFly = true; } diff --git a/NPCs/Perforator/PerforatorTailLarge.cs b/NPCs/Perforator/PerforatorTailLarge.cs index df4536e71a..5095d20a37 100644 --- a/NPCs/Perforator/PerforatorTailLarge.cs +++ b/NPCs/Perforator/PerforatorTailLarge.cs @@ -86,15 +86,7 @@ namespace CalamityMod.NPCs.Perforator if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(true); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/Perforator/PerforatorTailSmall.cs b/NPCs/Perforator/PerforatorTailSmall.cs index 7f5d26a183..30ad5f8738 100644 --- a/NPCs/Perforator/PerforatorTailSmall.cs +++ b/NPCs/Perforator/PerforatorTailSmall.cs @@ -86,15 +86,7 @@ namespace CalamityMod.NPCs.Perforator if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(true); - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/PlagueEnemies/PlaguebringerMiniboss.cs b/NPCs/PlagueEnemies/PlaguebringerMiniboss.cs index d403dd897b..97213f3c1d 100644 --- a/NPCs/PlagueEnemies/PlaguebringerMiniboss.cs +++ b/NPCs/PlagueEnemies/PlaguebringerMiniboss.cs @@ -92,15 +92,10 @@ namespace CalamityMod.NPCs.PlagueEnemies { if (NPC.timeLeft < 750) NPC.timeLeft = 750; + } } - int playerAmt = 0; - for (int i = 0; i < Main.maxPlayers; i++) - { - if (Main.player[i].active && !Main.player[i].dead && (NPC.Center - Main.player[i].Center).Length() < 1000f) - playerAmt++; - } - + int playerAmt = Main.CurrentFrameFlags.ActivePlayersCount; if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) NPC.TargetClosest(); diff --git a/NPCs/PlaguebringerGoliath/PbGScreenShaderData.cs b/NPCs/PlaguebringerGoliath/PbGScreenShaderData.cs index 717e8c0cc0..d31f5b22e0 100644 --- a/NPCs/PlaguebringerGoliath/PbGScreenShaderData.cs +++ b/NPCs/PlaguebringerGoliath/PbGScreenShaderData.cs @@ -22,15 +22,7 @@ namespace CalamityMod.NPCs.PlaguebringerGoliath { return; } - PbGIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == PbGType) - { - PbGIndex = i; - break; - } - } + PbGIndex = NPC.FindFirstNPC(PbGType); } public override void Update(GameTime gameTime) diff --git a/NPCs/PlaguebringerGoliath/PbGSky.cs b/NPCs/PlaguebringerGoliath/PbGSky.cs index ada84bda25..39e5888f4a 100644 --- a/NPCs/PlaguebringerGoliath/PbGSky.cs +++ b/NPCs/PlaguebringerGoliath/PbGSky.cs @@ -51,15 +51,7 @@ namespace CalamityMod.NPCs.PlaguebringerGoliath { return true; } - PbGIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == PbGType) - { - PbGIndex = i; - break; - } - } + PbGIndex = NPC.FindFirstNPC(PbGType); //this.DoGIndex = DoGIndex; return PbGIndex != -1; } diff --git a/NPCs/PlaguebringerGoliath/PlagueHomingMissile.cs b/NPCs/PlaguebringerGoliath/PlagueHomingMissile.cs index dd170d4dfa..a01811e7b6 100644 --- a/NPCs/PlaguebringerGoliath/PlagueHomingMissile.cs +++ b/NPCs/PlaguebringerGoliath/PlagueHomingMissile.cs @@ -149,10 +149,9 @@ namespace CalamityMod.NPCs.PlaguebringerGoliath } float distanceBeforeExploding = 42f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player.active && !player.dead && Vector2.Distance(player.Center, NPC.Center) <= distanceBeforeExploding) + if (!player.dead && Vector2.Distance(player.Center, NPC.Center) <= distanceBeforeExploding) { CheckDead(); NPC.life = 0; diff --git a/NPCs/PlaguebringerGoliath/PlaguebringerGoliath.cs b/NPCs/PlaguebringerGoliath/PlaguebringerGoliath.cs index 2b78a69901..e1983374f1 100644 --- a/NPCs/PlaguebringerGoliath/PlaguebringerGoliath.cs +++ b/NPCs/PlaguebringerGoliath/PlaguebringerGoliath.cs @@ -211,12 +211,7 @@ namespace CalamityMod.NPCs.PlaguebringerGoliath MissileCountdown--; // Count nearby players - int activePlayers = 0; - for (int i = 0; i < Main.maxPlayers; i++) - { - if (Main.player[i].active && !Main.player[i].dead && (NPC.Center - Main.player[i].Center).Length() < 1000f) - activePlayers++; - } + int activePlayers = Main.CurrentFrameFlags.ActivePlayersCount; // Get a target if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) diff --git a/NPCs/Polterghast/PolterPhantom.cs b/NPCs/Polterghast/PolterPhantom.cs index 6593c96a5a..6724039449 100644 --- a/NPCs/Polterghast/PolterPhantom.cs +++ b/NPCs/Polterghast/PolterPhantom.cs @@ -207,12 +207,12 @@ namespace CalamityMod.NPCs.Polterghast float movementLimitX = 0f; float movementLimitY = 0f; int numHooks = 4; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { - movementLimitX += Main.npc[i].Center.X; - movementLimitY += Main.npc[i].Center.Y; + movementLimitX += n.Center.X; + movementLimitY += n.Center.Y; } } movementLimitX /= numHooks; diff --git a/NPCs/Polterghast/Polterghast.cs b/NPCs/Polterghast/Polterghast.cs index d7f339cba4..1c8833c123 100644 --- a/NPCs/Polterghast/Polterghast.cs +++ b/NPCs/Polterghast/Polterghast.cs @@ -450,12 +450,12 @@ namespace CalamityMod.NPCs.Polterghast float movementLimitX = 0f; float movementLimitY = 0f; int numHooks = 4; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) { - movementLimitX += Main.npc[i].Center.X; - movementLimitY += Main.npc[i].Center.Y; + movementLimitX += n.Center.X; + movementLimitY += n.Center.Y; } } movementLimitX /= numHooks; diff --git a/NPCs/Polterghast/PolterghastHook.cs b/NPCs/Polterghast/PolterghastHook.cs index e6b04762ad..50c6039a49 100644 --- a/NPCs/Polterghast/PolterghastHook.cs +++ b/NPCs/Polterghast/PolterghastHook.cs @@ -229,9 +229,9 @@ namespace CalamityMod.NPCs.Polterghast if (!despawnBoost && NPC.localAI[0] <= 0f && NPC.ai[0] != 0f) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (i != NPC.whoAmI && Main.npc[i].active && Main.npc[i].type == NPC.type && (Main.npc[i].velocity.X != 0f || Main.npc[i].velocity.Y != 0f)) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type && (n.velocity.X != 0f || n.velocity.Y != 0f)) NPC.localAI[0] = 180f; } } diff --git a/NPCs/PrimordialWyrm/PrimordialWyrmBody.cs b/NPCs/PrimordialWyrm/PrimordialWyrmBody.cs index 8a8fb1aa1d..edd0b1f728 100644 --- a/NPCs/PrimordialWyrm/PrimordialWyrmBody.cs +++ b/NPCs/PrimordialWyrm/PrimordialWyrmBody.cs @@ -76,16 +76,8 @@ namespace CalamityMod.NPCs.PrimordialWyrm NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive. If not, die. - bool shouldDespawn = true; int wyrmHeadID = ModContent.NPCType(); - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == wyrmHeadID) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(wyrmHeadID); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/PrimordialWyrm/PrimordialWyrmBodyAlt.cs b/NPCs/PrimordialWyrm/PrimordialWyrmBodyAlt.cs index fa061524e4..823636e046 100644 --- a/NPCs/PrimordialWyrm/PrimordialWyrmBodyAlt.cs +++ b/NPCs/PrimordialWyrm/PrimordialWyrmBodyAlt.cs @@ -75,16 +75,8 @@ namespace CalamityMod.NPCs.PrimordialWyrm NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive. If not, die. - bool shouldDespawn = true; int wyrmHeadID = ModContent.NPCType(); - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == wyrmHeadID) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(wyrmHeadID); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs b/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs index 974863ec59..49391cd55c 100644 --- a/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs +++ b/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs @@ -609,16 +609,16 @@ namespace CalamityMod.NPCs.PrimordialWyrm int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { - whoAmIArray[numProjectiles] = i; + whoAmIArray[numProjectiles] = plr.whoAmI; targetCenterArray[numProjectiles] = playerCenter; int projectileLimit = numProjectiles + 1; numProjectiles = projectileLimit; @@ -904,16 +904,16 @@ namespace CalamityMod.NPCs.PrimordialWyrm int numProjectiles = 0; float maxDistance = 2400f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (plr.dead) continue; - Vector2 playerCenter = Main.player[i].Center; + Vector2 playerCenter = plr.Center; float distance = Vector2.Distance(playerCenter, NPC.Center); if (distance < maxDistance) { - whoAmIArray[numProjectiles] = i; + whoAmIArray[numProjectiles] = plr.whoAmI; targetCenterArray[numProjectiles] = playerCenter; int projectileLimit = numProjectiles + 1; numProjectiles = projectileLimit; diff --git a/NPCs/PrimordialWyrm/PrimordialWyrmTail.cs b/NPCs/PrimordialWyrm/PrimordialWyrmTail.cs index e192350bad..7b9aae19b0 100644 --- a/NPCs/PrimordialWyrm/PrimordialWyrmTail.cs +++ b/NPCs/PrimordialWyrm/PrimordialWyrmTail.cs @@ -64,16 +64,8 @@ namespace CalamityMod.NPCs.PrimordialWyrm NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive. If not, die. - bool shouldDespawn = true; int wyrmHeadID = ModContent.NPCType(); - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == wyrmHeadID) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(wyrmHeadID); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/ProfanedGuardians/ProfanedRocks.cs b/NPCs/ProfanedGuardians/ProfanedRocks.cs index 9ef42786b6..6e8de8df02 100644 --- a/NPCs/ProfanedGuardians/ProfanedRocks.cs +++ b/NPCs/ProfanedGuardians/ProfanedRocks.cs @@ -231,29 +231,25 @@ namespace CalamityMod.NPCs.ProfanedGuardians if (death) { float pushVelocity = bossRush ? 0.2f : 0.15f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != NPC.whoAmI && n.type == NPC.type) { - if (i != NPC.whoAmI && Main.npc[i].type == NPC.type) + if (Vector2.Distance(NPC.Center, n.Center) < 160f) { - if (Vector2.Distance(NPC.Center, Main.npc[i].Center) < 160f) - { - if (NPC.position.X < Main.npc[i].position.X) - NPC.velocity.X -= pushVelocity; - else - NPC.velocity.X += pushVelocity; - - if (NPC.position.Y < Main.npc[i].position.Y) - NPC.velocity.Y -= pushVelocity; - else - NPC.velocity.Y += pushVelocity; - } - - // Slow down so they don't push away from each other too far + if (NPC.position.X < n.position.X) + NPC.velocity.X -= pushVelocity; else - NPC.velocity *= 0.95f; + NPC.velocity.X += pushVelocity; + + if (NPC.position.Y < n.position.Y) + NPC.velocity.Y -= pushVelocity; + else + NPC.velocity.Y += pushVelocity; } + // Slow down so they don't push away from each other too far + else + NPC.velocity *= 0.95f; } } } diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 79471eeab9..7f0bbfabc3 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -1353,10 +1353,10 @@ namespace CalamityMod.NPCs.Providence if (NPC.ai[3] % 60f == 0f && expertMode) { List targets = new List(); - for (int p = 0; p < Main.maxPlayers; p++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[p].active && !Main.player[p].dead) - targets.Add(p); + if (!plr.dead) + targets.Add(plr.whoAmI); if (targets.Count > 4) break; @@ -1834,11 +1834,11 @@ namespace CalamityMod.NPCs.Providence DespawnSpecificProjectiles(); int laserType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (!Main.projectile[i].active || Main.projectile[i].type != laserType) + if (p.type != laserType) continue; - Main.projectile[i].Kill(); + p.Kill(); } } diff --git a/NPCs/Ravager/RavagerBody.cs b/NPCs/Ravager/RavagerBody.cs index ffee658261..09b76c70fb 100644 --- a/NPCs/Ravager/RavagerBody.cs +++ b/NPCs/Ravager/RavagerBody.cs @@ -201,19 +201,19 @@ namespace CalamityMod.NPCs.Ravager bool leftClawActive = false; bool freeHeadActive = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) headActive = true; - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) rightClawActive = true; - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) leftClawActive = true; - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) rightLegActive = true; - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) leftLegActive = true; - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) + if (n.type == ModContent.NPCType()) freeHeadActive = true; } @@ -619,13 +619,13 @@ namespace CalamityMod.NPCs.Ravager if (expertMode) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].type == ModContent.NPCType() && Main.npc[i].ai[0] == 0f) + if (n.type == ModContent.NPCType() && n.ai[0] == 0f) { - Main.npc[i].ai[1] = -1f; - Main.npc[i].direction = NPC.direction; - Main.npc[i].netUpdate = true; + n.ai[1] = -1f; + n.direction = NPC.direction; + n.netUpdate = true; } } diff --git a/NPCs/Signus/SignusScreenShaderData.cs b/NPCs/Signus/SignusScreenShaderData.cs index 902c4f9389..a2fa44c859 100644 --- a/NPCs/Signus/SignusScreenShaderData.cs +++ b/NPCs/Signus/SignusScreenShaderData.cs @@ -20,15 +20,7 @@ namespace CalamityMod.NPCs.Signus { return; } - SignusIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == SignusType) - { - SignusIndex = i; - break; - } - } + SignusIndex = NPC.FindFirstNPC(SignusType); } public override void Apply() diff --git a/NPCs/Signus/SignusSky.cs b/NPCs/Signus/SignusSky.cs index fe449714bb..a128b08f8c 100644 --- a/NPCs/Signus/SignusSky.cs +++ b/NPCs/Signus/SignusSky.cs @@ -60,15 +60,7 @@ namespace CalamityMod.NPCs.Signus { return true; } - SignusIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == SignusType) - { - SignusIndex = i; - break; - } - } + SignusIndex = NPC.FindFirstNPC(SignusType); return SignusIndex != -1; } diff --git a/NPCs/SlimeGod/CrimulanPaladin.cs b/NPCs/SlimeGod/CrimulanPaladin.cs index 0881cbf004..2efc4de6b7 100644 --- a/NPCs/SlimeGod/CrimulanPaladin.cs +++ b/NPCs/SlimeGod/CrimulanPaladin.cs @@ -462,10 +462,10 @@ namespace CalamityMod.NPCs.SlimeGod if (enraged && expertMode) { List targets = new List(); - for (int p = 0; p < Main.maxPlayers; p++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[p].active && !Main.player[p].dead) - targets.Add(p); + if (!plr.dead) + targets.Add(plr.whoAmI); if (targets.Count > 1) break; diff --git a/NPCs/SlimeGod/EbonianPaladin.cs b/NPCs/SlimeGod/EbonianPaladin.cs index 6fb4067319..f8c225f0cb 100644 --- a/NPCs/SlimeGod/EbonianPaladin.cs +++ b/NPCs/SlimeGod/EbonianPaladin.cs @@ -506,10 +506,10 @@ namespace CalamityMod.NPCs.SlimeGod if (enraged && expertMode) { List targets = new List(); - for (int p = 0; p < Main.maxPlayers; p++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[p].active && !Main.player[p].dead) - targets.Add(p); + if (!plr.dead) + targets.Add(plr.whoAmI); if (targets.Count > 1) break; diff --git a/NPCs/SlimeGod/SlimeGodCore.cs b/NPCs/SlimeGod/SlimeGodCore.cs index d208410b88..c0bdd4c2f6 100644 --- a/NPCs/SlimeGod/SlimeGodCore.cs +++ b/NPCs/SlimeGod/SlimeGodCore.cs @@ -500,19 +500,16 @@ namespace CalamityMod.NPCs.SlimeGod float ignoreAllSlimesDistanceThreshold = 3200f; // Find all slimes within a generous area. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - int npcType = Main.npc[i].type; + int npcType = n.type; if (npcType != largeCrimulanPaladin && npcType != splitCrimulanPaladin && npcType != largeEbonianPaladin && npcType != splitEbonianPaladin) continue; - if (!Main.npc[i].active) + if (!NPC.WithinRange(n.Center, ignoreAllSlimesDistanceThreshold)) continue; - if (!NPC.WithinRange(Main.npc[i].Center, ignoreAllSlimesDistanceThreshold)) - continue; - - largeSlimes.Add(Main.npc[i]); + largeSlimes.Add(n); } // If no slimes were found, don't bother doing any more calculations. Just use the player's center. diff --git a/NPCs/SlimeGod/SplitCrimulanPaladin.cs b/NPCs/SlimeGod/SplitCrimulanPaladin.cs index 40504fa27a..d00c921ae9 100644 --- a/NPCs/SlimeGod/SplitCrimulanPaladin.cs +++ b/NPCs/SlimeGod/SplitCrimulanPaladin.cs @@ -446,10 +446,10 @@ namespace CalamityMod.NPCs.SlimeGod if (enraged && expertMode) { List targets = new List(); - for (int p = 0; p < Main.maxPlayers; p++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[p].active && !Main.player[p].dead) - targets.Add(p); + if (!plr.dead) + targets.Add(plr.whoAmI); if (targets.Count > 1) break; diff --git a/NPCs/SlimeGod/SplitEbonianPaladin.cs b/NPCs/SlimeGod/SplitEbonianPaladin.cs index 439b06b21e..91036c6d16 100644 --- a/NPCs/SlimeGod/SplitEbonianPaladin.cs +++ b/NPCs/SlimeGod/SplitEbonianPaladin.cs @@ -493,10 +493,10 @@ namespace CalamityMod.NPCs.SlimeGod if (enraged && expertMode) { List targets = new List(); - for (int p = 0; p < Main.maxPlayers; p++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[p].active && !Main.player[p].dead) - targets.Add(p); + if (!plr.dead) + targets.Add(plr.whoAmI); if (targets.Count > 1) break; diff --git a/NPCs/StormWeaver/StormWeaverBody.cs b/NPCs/StormWeaver/StormWeaverBody.cs index cbddaba0a0..d921c85011 100644 --- a/NPCs/StormWeaver/StormWeaverBody.cs +++ b/NPCs/StormWeaver/StormWeaverBody.cs @@ -163,15 +163,7 @@ namespace CalamityMod.NPCs.StormWeaver } // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/StormWeaver/StormWeaverHead.cs b/NPCs/StormWeaver/StormWeaverHead.cs index 3239bbd167..75e8814fe4 100644 --- a/NPCs/StormWeaver/StormWeaverHead.cs +++ b/NPCs/StormWeaver/StormWeaverHead.cs @@ -300,13 +300,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; } } } @@ -314,13 +314,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/StormWeaver/StormWeaverTail.cs b/NPCs/StormWeaver/StormWeaverTail.cs index 668878f4ed..62afff7228 100644 --- a/NPCs/StormWeaver/StormWeaverTail.cs +++ b/NPCs/StormWeaver/StormWeaverTail.cs @@ -159,15 +159,7 @@ namespace CalamityMod.NPCs.StormWeaver } // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/SunkenSea/SeaSerpent2.cs b/NPCs/SunkenSea/SeaSerpent2.cs index d64d5cc51c..4334908959 100644 --- a/NPCs/SunkenSea/SeaSerpent2.cs +++ b/NPCs/SunkenSea/SeaSerpent2.cs @@ -63,15 +63,7 @@ namespace CalamityMod.NPCs.SunkenSea NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/SunkenSea/SeaSerpent3.cs b/NPCs/SunkenSea/SeaSerpent3.cs index 3274777561..3258776809 100644 --- a/NPCs/SunkenSea/SeaSerpent3.cs +++ b/NPCs/SunkenSea/SeaSerpent3.cs @@ -61,15 +61,7 @@ namespace CalamityMod.NPCs.SunkenSea NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/SunkenSea/SeaSerpent4.cs b/NPCs/SunkenSea/SeaSerpent4.cs index 4d869b2c09..336e640558 100644 --- a/NPCs/SunkenSea/SeaSerpent4.cs +++ b/NPCs/SunkenSea/SeaSerpent4.cs @@ -61,15 +61,7 @@ namespace CalamityMod.NPCs.SunkenSea NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/SunkenSea/SeaSerpent5.cs b/NPCs/SunkenSea/SeaSerpent5.cs index 671e3ea62f..419b90c22f 100644 --- a/NPCs/SunkenSea/SeaSerpent5.cs +++ b/NPCs/SunkenSea/SeaSerpent5.cs @@ -61,15 +61,7 @@ namespace CalamityMod.NPCs.SunkenSea NPC.realLife = (int)NPC.ai[2]; // Check if other segments are still alive, if not, die - bool shouldDespawn = true; - for (int i = 0; i < Main.maxNPCs; i++) - { - if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType()) - { - shouldDespawn = false; - break; - } - } + bool shouldDespawn = !NPC.AnyNPCs(ModContent.NPCType()); if (!shouldDespawn) { if (NPC.ai[1] <= 0f) diff --git a/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs b/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs index b2ffcd398e..299f2d5144 100644 --- a/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs +++ b/NPCs/SupremeCalamitas/SoulSeekerSupreme.cs @@ -145,9 +145,8 @@ namespace CalamityMod.NPCs.SupremeCalamitas int shootRate = BossRushEvent.BossRushActive ? 120 : 180; if (timer > shootRate) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC seeker in Main.ActiveNPCs) { - NPC seeker = Main.npc[i]; if (seeker.type == NPC.type) { if (seeker == NPC) diff --git a/NPCs/TownNPCs/AndroombaFriendly.cs b/NPCs/TownNPCs/AndroombaFriendly.cs index b78f297891..a1c3038966 100644 --- a/NPCs/TownNPCs/AndroombaFriendly.cs +++ b/NPCs/TownNPCs/AndroombaFriendly.cs @@ -113,12 +113,8 @@ namespace CalamityMod.NPCs.TownNPCs break; } - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - if (player is null || !player.active) - continue; - if (NPC.Hitbox.Intersects(player.HitboxForBestiaryNearbyCheck)) { Main.BestiaryTracker.Chats.RegisterChatStartWith(NPC); @@ -147,13 +143,13 @@ namespace CalamityMod.NPCs.TownNPCs type = ConvertType.Crimson; break; } - AstralBiome.ConvertFromAstral(x - 2, x + 2, y - 2, y + 2, type); + World.AstralBiome.ConvertFromAstral(x - 2, x + 2, y - 2, y + 2, type); WorldGen.Convert(x, y, conversionType, 2); } // Calamity solution(s) else if (conversionType == 8) { - AstralBiome.ConvertToAstral(x - 2, x + 2, y - 2, y + 2); + World.AstralBiome.ConvertToAstral(x - 2, x + 2, y - 2, y + 2); } // Solutions registered by other mods else diff --git a/NPCs/TownNPCs/DILF.cs b/NPCs/TownNPCs/DILF.cs index 93a834e7cb..9b2de8371c 100644 --- a/NPCs/TownNPCs/DILF.cs +++ b/NPCs/TownNPCs/DILF.cs @@ -140,7 +140,7 @@ namespace CalamityMod.NPCs.TownNPCs public override void AddShops() { - Condition potionSells = new(CalamityUtils.GetText("Condition.PotionConfig"), () => CalamityConfig.Instance.PotionSelling); + Condition potionSells = CalamityConditions.PotionSellingConfig; NPCShop shop = new(Type); shop.Add(ModContent.ItemType()) .Add(ModContent.ItemType()) diff --git a/NPCs/TownNPCs/FAP.cs b/NPCs/TownNPCs/FAP.cs index 43bc9b2541..24b57edf9b 100644 --- a/NPCs/TownNPCs/FAP.cs +++ b/NPCs/TownNPCs/FAP.cs @@ -669,11 +669,10 @@ namespace CalamityMod.NPCs.TownNPCs if (CalamityWorld.spawnedCirrus) return true; - for (int k = 0; k < Main.maxPlayers; k++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[k]; bool hasVodka = player.InventoryHas(ModContent.ItemType()) || player.PortableStorageHas(ModContent.ItemType()); - if (player.active && hasVodka) + if (hasVodka) return Main.hardMode; } return false; @@ -883,8 +882,8 @@ namespace CalamityMod.NPCs.TownNPCs public override void AddShops() { - Condition potionSells = new(CalamityUtils.GetText("Condition.PotionConfig"), () => CalamityConfig.Instance.PotionSelling); - Condition downedAureus = new(CalamityUtils.GetText("Condition.PostAureus"), () => DownedBossSystem.downedAstrumAureus); + Condition potionSells = CalamityConditions.PotionSellingConfig; + Condition downedAureus = CalamityConditions.DownedAstrumAureus; NPCShop shop = new(Type); shop.AddWithCustomValue(ItemID.LovePotion, Item.buyPrice(silver: 25), potionSells, Condition.HappyEnough) diff --git a/NPCs/TownNPCs/SEAHOE.cs b/NPCs/TownNPCs/SEAHOE.cs index ff8be76ae6..b455f13eb2 100644 --- a/NPCs/TownNPCs/SEAHOE.cs +++ b/NPCs/TownNPCs/SEAHOE.cs @@ -198,7 +198,7 @@ namespace CalamityMod.NPCs.TownNPCs } public override void AddShops() { - Condition downedOldDuke = new(CalamityUtils.GetText("Condition.PostOD"), () => DownedBossSystem.downedBoomerDuke); + Condition downedOldDuke = CalamityConditions.DownedOldDuke; NPCShop shop = new(Type); shop.Add(ModContent.ItemType()) diff --git a/NPCs/TownNPCs/THIEF.cs b/NPCs/TownNPCs/THIEF.cs index ca0b761bf9..c9ea97d8d4 100644 --- a/NPCs/TownNPCs/THIEF.cs +++ b/NPCs/TownNPCs/THIEF.cs @@ -91,11 +91,10 @@ namespace CalamityMod.NPCs.TownNPCs if (CalamityWorld.spawnedBandit) return true; - for (int k = 0; k < Main.maxPlayers; k++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[k]; bool rich = player.InventoryHas(ItemID.PlatinumCoin) || player.PortableStorageHas(ItemID.PlatinumCoin); - if (player.active && rich) + if (rich) return NPC.downedBoss3; } return false; @@ -269,10 +268,10 @@ namespace CalamityMod.NPCs.TownNPCs } public override void AddShops() { - Condition potionSells = new(CalamityUtils.GetText("Condition.PotionConfig"), () => CalamityConfig.Instance.PotionSelling); - Condition downedCalclone = new(CalamityUtils.GetText("Condition.PostCal"), () => DownedBossSystem.downedCalamitasClone); - Condition downedDoG = new(CalamityUtils.GetText("Condition.PostDoG"), () => DownedBossSystem.downedDoG); - Condition downedYharon = new(CalamityUtils.GetText("Condition.PostYharon"), () => DownedBossSystem.downedYharon); + Condition potionSells = CalamityConditions.PotionSellingConfig; + Condition downedCalclone = CalamityConditions.DownedCalamitasClone; + Condition downedDoG = CalamityConditions.DownedDevourerOfGods; + Condition downedYharon = CalamityConditions.DownedYharon; NPCShop shop = new(Type); shop.AddWithCustomValue(ModContent.ItemType(), Item.buyPrice(gold: 9)) @@ -282,7 +281,7 @@ namespace CalamityMod.NPCs.TownNPCs .Add(ItemID.TigerClimbingGear) .AddWithCustomValue(ItemID.InvisibilityPotion, Item.buyPrice(silver: 25), potionSells, Condition.HappyEnough) .AddWithCustomValue(ItemID.NightOwlPotion, Item.buyPrice(silver: 25), potionSells, Condition.HappyEnough) - .AddWithCustomValue(ModContent.ItemType(), Item.buyPrice(gold: 25), Condition.Hardmode) + .AddWithCustomValue(ModContent.ItemType(), Item.buyPrice(gold: 25)) .Add(ModContent.ItemType(), Condition.DownedPirates) .AddWithCustomValue(ModContent.ItemType(), Item.buyPrice(gold: 60), Condition.DownedMechBossAll) .Add(ModContent.ItemType(), downedCalclone) diff --git a/NPCs/VanillaNPCAIOverrides/Bosses/DeerclopsAI.cs b/NPCs/VanillaNPCAIOverrides/Bosses/DeerclopsAI.cs index 3eb437dcd6..90aeb04f5c 100644 --- a/NPCs/VanillaNPCAIOverrides/Bosses/DeerclopsAI.cs +++ b/NPCs/VanillaNPCAIOverrides/Bosses/DeerclopsAI.cs @@ -554,22 +554,22 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses if (shadowHandTimer / shadowHandSpawnRate >= 3) npc.localAI[2] = 0f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - if (npc.Boss_CanShootExtraAt(i, rotation % 3, 3, 1200f, alwaysSkipMainTarget: false)) + if (npc.Boss_CanShootExtraAt(player.whoAmI, rotation % 3, 3, 1200f, alwaysSkipMainTarget: false)) { // Normal shadow hand spawn behavior // Modified to make the shadow hand spawns fair - RandomizeInsanityShadowFor(Main.player[i], death, isHostile: true, out var spawnPosition, out var spawnVelocity, out var ai, out var ai2); + RandomizeInsanityShadowFor(player, death, isHostile: true, out var spawnPosition, out var spawnVelocity, out var ai, out var ai2); // Spawn hands to cut the player off and force them back towards Deerclops // This only happens if the player is triggering Deerclops' increased DR float minShadowHandSpawnDistanceFromPlayer = 450f; - float playerDistanceFromDeerclops = Vector2.Distance(npc.Center, Main.player[i].Center); + float playerDistanceFromDeerclops = Vector2.Distance(npc.Center, player.Center); if (playerDistanceFromDeerclops >= 450f) { - spawnPosition = (Main.player[i].Center - npc.Center).SafeNormalize(Vector2.UnitY) * (playerDistanceFromDeerclops + minShadowHandSpawnDistanceFromPlayer); - spawnVelocity = (Main.player[i].Center - spawnPosition).SafeNormalize(Vector2.UnitY) * spawnVelocity.Length(); + spawnPosition = (player.Center - npc.Center).SafeNormalize(Vector2.UnitY) * (playerDistanceFromDeerclops + minShadowHandSpawnDistanceFromPlayer); + spawnVelocity = (player.Center - spawnPosition).SafeNormalize(Vector2.UnitY) * spawnVelocity.Length(); } Projectile.NewProjectile(npc.GetSource_FromAI(), spawnPosition, spawnVelocity, shadowHand, shadowHandDamage, 0f, Main.myPlayer, ai, ai2); diff --git a/NPCs/VanillaNPCAIOverrides/Bosses/MoonLordAI.cs b/NPCs/VanillaNPCAIOverrides/Bosses/MoonLordAI.cs index 52a67431e5..a00ffc39e3 100644 --- a/NPCs/VanillaNPCAIOverrides/Bosses/MoonLordAI.cs +++ b/NPCs/VanillaNPCAIOverrides/Bosses/MoonLordAI.cs @@ -317,19 +317,17 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses if (npc.ai[1] == 60f) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - Projectile projectile = Main.projectile[i]; - if (projectile.active && (projectile.type == ProjectileID.MoonLeech || projectile.type == ProjectileID.PhantasmalBolt || + if ((projectile.type == ProjectileID.MoonLeech || projectile.type == ProjectileID.PhantasmalBolt || projectile.type == ProjectileID.PhantasmalDeathray || projectile.type == ProjectileID.PhantasmalEye || projectile.type == ProjectileID.PhantasmalSphere)) projectile.Kill(); } - for (int j = 0; j < Main.maxNPCs; j++) + foreach (NPC nPC3 in Main.ActiveNPCs) { - NPC nPC3 = Main.npc[j]; - if (nPC3.active && nPC3.type == NPCID.MoonLordFreeEye) + if (nPC3.type == NPCID.MoonLordFreeEye) { nPC3.HitEffect(0, 9999.0); nPC3.active = false; @@ -445,10 +443,9 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses npc.HitEffect(0, 1337.0); npc.checkDead(); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC5 in Main.ActiveNPCs) { - NPC nPC5 = Main.npc[i]; - if (nPC5.active && (nPC5.type == NPCID.MoonLordHand || nPC5.type == NPCID.MoonLordHead)) + if (nPC5.type == NPCID.MoonLordHand || nPC5.type == NPCID.MoonLordHead) { nPC5.active = false; if (Main.netMode != NetmodeID.MultiplayerClient) @@ -477,16 +474,15 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses if (npc.ai[1] == 40f) { - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile projectile2 in Main.ActiveProjectiles) { - Projectile projectile2 = Main.projectile[j]; - if (projectile2.active && (projectile2.type == ProjectileID.MoonLeech || projectile2.type == ProjectileID.PhantasmalBolt || + if ((projectile2.type == ProjectileID.MoonLeech || projectile2.type == ProjectileID.PhantasmalBolt || projectile2.type == ProjectileID.PhantasmalDeathray || projectile2.type == ProjectileID.PhantasmalEye || projectile2.type == ProjectileID.PhantasmalSphere)) { projectile2.active = false; if (Main.netMode != NetmodeID.MultiplayerClient) - NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, j, 0f, 0f, 0f, 0, 0, 0); + NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, projectile2.whoAmI, 0f, 0f, 0f, 0, 0, 0); } } @@ -511,10 +507,9 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses if (npc.ai[1] >= 60f) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC5 in Main.ActiveNPCs) { - NPC nPC5 = Main.npc[i]; - if (nPC5.active && (nPC5.type == NPCID.MoonLordFreeEye || nPC5.type == NPCID.MoonLordHand || nPC5.type == NPCID.MoonLordHead)) + if (nPC5.type == NPCID.MoonLordFreeEye || nPC5.type == NPCID.MoonLordHand || nPC5.type == NPCID.MoonLordHead) { nPC5.active = false; if (Main.netMode != NetmodeID.MultiplayerClient) @@ -586,13 +581,11 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses Main.npc[(int)npc.localAI[2]].netUpdate = true; } - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC7 in Main.ActiveNPCs) { - NPC nPC7 = Main.npc[i]; if (nPC7.active && nPC7.type == NPCID.MoonLordFreeEye) { - NPC nPC6 = nPC7; - nPC6.position += value8; + nPC7.position += value8; nPC7.netUpdate = true; } } @@ -844,32 +837,30 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses if (attackTimer == 0f && Main.netMode != NetmodeID.MultiplayerClient) { Vector2 leechNPCCenter = npc.Center + leechCenterOffset; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player6 in Main.ActivePlayers) { - Player player6 = Main.player[i]; - if (player6.active && !player6.dead && Vector2.Distance(player6.Center, leechNPCCenter) <= 3000f) + if (!player6.dead && Vector2.Distance(player6.Center, leechNPCCenter) <= 3000f) { Vector2 targetLeechDist = Main.player[npc.target].Center - leechNPCCenter; if (targetLeechDist != Vector2.Zero) targetLeechDist.Normalize(); - Projectile.NewProjectile(npc.GetSource_FromAI(), leechNPCCenter.X, leechNPCCenter.Y, targetLeechDist.X, targetLeechDist.Y, ProjectileID.MoonLeech, 0, 0f, Main.myPlayer, npc.whoAmI + 1, i); + Projectile.NewProjectile(npc.GetSource_FromAI(), leechNPCCenter.X, leechNPCCenter.Y, targetLeechDist.X, targetLeechDist.Y, ProjectileID.MoonLeech, 0, 0f, Main.myPlayer, npc.whoAmI + 1, player6.whoAmI); } } } if ((attackTimer == 120f || attackTimer == 150f || attackTimer == 180f || attackTimer == 210f || attackTimer == 240f) && Main.netMode != NetmodeID.MultiplayerClient) { - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile projectile6 in Main.ActiveProjectiles) { - Projectile projectile6 = Main.projectile[j]; - if (projectile6.active && projectile6.type == ProjectileID.MoonLeech && Main.player[(int)projectile6.ai[1]].FindBuffIndex(BuffID.MoonLeech) != -1) + if (projectile6.type == ProjectileID.MoonLeech && Main.player[(int)projectile6.ai[1]].FindBuffIndex(BuffID.MoonLeech) != -1) { Vector2 targetCenter = Main.player[npc.target].Center; int moonLeech = NPC.NewNPC(npc.GetSource_FromAI(), (int)targetCenter.X, (int)targetCenter.Y, NPCID.MoonLordLeechBlob); Main.npc[moonLeech].netUpdate = true; Main.npc[moonLeech].ai[0] = npc.whoAmI + 1; - Main.npc[moonLeech].ai[1] = j; + Main.npc[moonLeech].ai[1] = projectile6.whoAmI; } } } @@ -1391,10 +1382,9 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses } sphereVelocity *= velocity; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile currentProjectile in Main.ActiveProjectiles) { - Projectile currentProjectile = Main.projectile[i]; - if (currentProjectile.active && currentProjectile.type == ProjectileID.PhantasmalSphere && currentProjectile.ai[1] == npc.whoAmI && currentProjectile.ai[0] != -1f) + if (currentProjectile.type == ProjectileID.PhantasmalSphere && currentProjectile.ai[1] == npc.whoAmI && currentProjectile.ai[0] != -1f) { currentProjectile.ai[0] = -1f; currentProjectile.velocity = sphereVelocity; @@ -1597,26 +1587,23 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses if (eyeCount > 1) { int eyesSynced = 1; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active) + if (n.whoAmI != npc.whoAmI && n.type == npc.type) { - if (i != npc.whoAmI && Main.npc[i].type == npc.type) - { - Main.npc[i].ai[0] = 0f; - Main.npc[i].ai[1] = 0f; - Main.npc[i].ai[2] = 0f; - Main.npc[i].localAI[0] = 0f; - Main.npc[i].localAI[1] = 0f; - Main.npc[i].localAI[2] = 0f; - calamityGlobalNPC.newAI[0] = 1f; - calamityGlobalNPC.newAI[1] = 0f; - npc.netUpdate = true; + n.ai[0] = 0f; + n.ai[1] = 0f; + n.ai[2] = 0f; + n.localAI[0] = 0f; + n.localAI[1] = 0f; + n.localAI[2] = 0f; + calamityGlobalNPC.newAI[0] = 1f; + calamityGlobalNPC.newAI[1] = 0f; + npc.netUpdate = true; - eyesSynced++; - if (eyesSynced >= eyeCount) - break; - } + eyesSynced++; + if (eyesSynced >= eyeCount) + break; } } } @@ -1739,24 +1726,21 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.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; } } } @@ -1905,13 +1889,11 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses npc.velocity = Vector2.UnitY * -7f; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile trueEyeSpheres in Main.ActiveProjectiles) { - Projectile trueEyeSpheres = Main.projectile[i]; - if (trueEyeSpheres.active && trueEyeSpheres.type == type && trueEyeSpheres.ai[1] == npc.whoAmI && trueEyeSpheres.ai[0] != -1f) + if (trueEyeSpheres.type == type && trueEyeSpheres.ai[1] == npc.whoAmI && trueEyeSpheres.ai[0] != -1f) { - Projectile trueEyeSphereVel = trueEyeSpheres; - trueEyeSphereVel.velocity += npc.velocity; + trueEyeSpheres.velocity += npc.velocity; trueEyeSpheres.netUpdate = true; } } @@ -1937,10 +1919,9 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses Vector2 trueEyeSphereVelocity = (npc.ai[2] - MathHelper.PiOver2).ToRotationVector2() * velocity; npc.velocity = trueEyeSphereVelocity * 2f; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile trueEyeSphereProj in Main.ActiveProjectiles) { - Projectile trueEyeSphereProj = Main.projectile[i]; - if (trueEyeSphereProj.active && trueEyeSphereProj.type == type && trueEyeSphereProj.ai[1] == npc.whoAmI && trueEyeSphereProj.ai[0] != -1f) + if (trueEyeSphereProj.type == type && trueEyeSphereProj.ai[1] == npc.whoAmI && trueEyeSphereProj.ai[0] != -1f) { trueEyeSphereProj.ai[0] = -1f; trueEyeSphereProj.damage = damage; @@ -2154,14 +2135,14 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses int rightHandHeal = -1; int headHeal = headNPCType; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].ai[3] == k) + if (n.ai[3] == k) { - if (leftHandHeal == -1 && Main.npc[i].type == NPCID.MoonLordHand && Main.npc[i].ai[2] == 0f) - leftHandHeal = i; - if (rightHandHeal == -1 && Main.npc[i].type == NPCID.MoonLordHand && Main.npc[i].ai[2] == 1f) - rightHandHeal = i; + if (leftHandHeal == -1 && n.type == NPCID.MoonLordHand && n.ai[2] == 0f) + leftHandHeal = n.whoAmI; + if (rightHandHeal == -1 && n.type == NPCID.MoonLordHand && n.ai[2] == 1f) + rightHandHeal = n.whoAmI; if (leftHandHeal != -1 && rightHandHeal != -1 && headHeal != -1) break; } diff --git a/NPCs/VanillaNPCAIOverrides/Bosses/PlanteraAI.cs b/NPCs/VanillaNPCAIOverrides/Bosses/PlanteraAI.cs index 8ea83cb22e..a7c993715b 100644 --- a/NPCs/VanillaNPCAIOverrides/Bosses/PlanteraAI.cs +++ b/NPCs/VanillaNPCAIOverrides/Bosses/PlanteraAI.cs @@ -107,13 +107,13 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses float hookPositionX = 0f; float hookPositionY = 0f; int numHooksSpawned = 0; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].aiStyle == NPCAIStyleID.PlanteraHook) + if (n.aiStyle == NPCAIStyleID.PlanteraHook) { - hookPositionX += Main.npc[i].Center.X; - hookPositionY += Main.npc[i].Center.Y; - hookArray[numHooksSpawned] = i; + hookPositionX += n.Center.X; + hookPositionY += n.Center.Y; + hookArray[numHooksSpawned] = n.whoAmI; numHooksSpawned++; if (numHooksSpawned >= maxHooks) @@ -680,14 +680,14 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses if (Main.getGoodWorld) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].aiStyle == NPCAIStyleID.PlanteraHook) + if (n.aiStyle == NPCAIStyleID.PlanteraHook) { for (int j = 0; j < totalTentacles / 2 - 1; j++) { int hookIndex = NPC.NewNPC(npc.GetSource_FromAI(), (int)npc.Center.X, (int)npc.Center.Y, NPCID.PlanterasTentacle, npc.whoAmI); - Main.npc[hookIndex].ai[3] = i + 1; + Main.npc[hookIndex].ai[3] = n.whoAmI + 1; } } } @@ -948,9 +948,9 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses // Set timer to new amount if a different hook is currently moving if (!despawn && npc.localAI[0] <= 0f && npc.ai[0] != 0f) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != npc.whoAmI && Main.npc[i].active && Main.npc[i].type == npc.type && (Main.npc[i].velocity.X != 0f || Main.npc[i].velocity.Y != 0f)) + if (n.whoAmI != npc.whoAmI && n.type == npc.type && (n.velocity.X != 0f || n.velocity.Y != 0f)) npc.localAI[0] = Main.rand.Next(60, 301); } } diff --git a/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs b/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs index afeb4c188e..218a4643c2 100644 --- a/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs +++ b/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs @@ -1169,11 +1169,11 @@ PrepareToShoot: int nailCount = Main.rand.Next(3, 6); int[] players = new int[nailCount]; int i = 0; - for (int j = 0; j < Main.player.Length; j++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[j].active && !Main.player[j].dead && Collision.CanHitLine(npc.position, npc.width, npc.height, Main.player[j].position, Main.player[j].width, Main.player[j].height)) + if (!plr.dead && Collision.CanHitLine(npc.position, npc.width, npc.height, plr.position, plr.width, plr.height)) { - players[i] = j; + players[i] = plr.whoAmI; i++; if (i == nailCount) { @@ -1975,9 +1975,9 @@ PrepareToShoot: { npc.hide = false; // I'd assume the Drakomire is drawn by the rider if it's present - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].type == NPCID.SolarDrakomireRider && Main.npc[i].ai[0] == (float)npc.whoAmI) + if (n.type == NPCID.SolarDrakomireRider && n.ai[0] == (float)npc.whoAmI) { npc.hide = true; break; @@ -2077,11 +2077,11 @@ PrepareToShoot: dust.customData = npc; } // Adjust velocity based on the other storm drivers who want to pump your face full of bullets - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != npc.whoAmI && Main.npc[i].active && Main.npc[i].type == npcType && Math.Abs(npc.position.X - Main.npc[i].position.X) + Math.Abs(npc.position.Y - Main.npc[i].position.Y) < (float)npc.width) + if (n.whoAmI != npc.whoAmI && n.type == npcType && Math.Abs(npc.position.X - n.position.X) + Math.Abs(npc.position.Y - n.position.Y) < (float)npc.width) { - if (npc.position.X < Main.npc[i].position.X) + if (npc.position.X < n.position.X) { npc.velocity.X -= 0.05f; } @@ -2089,7 +2089,7 @@ PrepareToShoot: { npc.velocity.X += 0.05f; } - if (npc.position.Y < Main.npc[i].position.Y) + if (npc.position.Y < n.position.Y) { npc.velocity.Y -= 0.05f; } @@ -2184,11 +2184,11 @@ PrepareToShoot: npc.velocity.Y += 0.25f; } } - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != npc.whoAmI && Main.npc[i].active && Main.npc[i].type == npcType && Math.Abs(npc.position.X - Main.npc[i].position.X) + Math.Abs(npc.position.Y - Main.npc[i].position.Y) < (float)npc.width) + if (i != npc.whoAmI && n.type == npcType && Math.Abs(npc.position.X - n.position.X) + Math.Abs(npc.position.Y - n.position.Y) < (float)npc.width) { - if (npc.position.X < Main.npc[i].position.X) + if (npc.position.X < n.position.X) { npc.velocity.X -= 0.05f; } @@ -2196,7 +2196,7 @@ PrepareToShoot: { npc.velocity.X += 0.05f; } - if (npc.position.Y < Main.npc[i].position.Y) + if (npc.position.Y < n.position.Y) { npc.velocity.Y -= 0.05f; } @@ -2260,11 +2260,11 @@ PrepareToShoot: { npc.velocity.Y = -8f; } - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != npc.whoAmI && Main.npc[i].active && Main.npc[i].type == npcType && Math.Abs(npc.position.X - Main.npc[i].position.X) + Math.Abs(npc.position.Y - Main.npc[i].position.Y) < (float)npc.width) + if (i != npc.whoAmI && n.type == npcType && Math.Abs(npc.position.X - n.position.X) + Math.Abs(npc.position.Y - n.position.Y) < (float)npc.width) { - if (npc.position.X < Main.npc[i].position.X) + if (npc.position.X < n.position.X) { npc.velocity.X -= 0.1f; } @@ -2272,7 +2272,7 @@ PrepareToShoot: { npc.velocity.X += 0.1f; } - if (npc.position.Y < Main.npc[i].position.Y) + if (npc.position.Y < n.position.Y) { npc.velocity.Y -= 0.1f; } @@ -7592,11 +7592,11 @@ PrepareToShoot: { turnAroundDelayMult = 3; bool noYVelocity = npc.velocity.Y == 0f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != npc.whoAmI && Main.npc[i].active && Main.npc[i].type == npc.type && Math.Abs(npc.position.X - Main.npc[i].position.X) + Math.Abs(npc.position.Y - Main.npc[i].position.Y) < (float)npc.width) + if (n.whoAmI != npc.whoAmI && n.type == npc.type && Math.Abs(npc.position.X - n.position.X) + Math.Abs(npc.position.Y - n.position.Y) < (float)npc.width) { - if (npc.position.X < Main.npc[i].position.X) + if (npc.position.X < n.position.X) { npc.velocity.X -= 0.05f; } @@ -7604,7 +7604,7 @@ PrepareToShoot: { npc.velocity.X += 0.05f; } - if (npc.position.Y < Main.npc[i].position.Y) + if (npc.position.Y < n.position.Y) { npc.velocity.Y -= 0.05f; } @@ -7661,9 +7661,9 @@ PrepareToShoot: bool spawnTwinkle = npc.ai[1] >= (CalamityWorld.death ? 60f : 120f); if (!spawnTwinkle && npc.velocity.Y == 0f) { - for (int j = 0; j < Main.maxPlayers; j++) + foreach (Player plr in Main.ActivePlayers) { - if (Main.player[j].active && !Main.player[j].dead && Main.player[j].Distance(npc.Center) < 800f && Main.player[j].Center.Y < npc.Center.Y && Math.Abs(Main.player[j].Center.X - npc.Center.X) < 20f) + if (!plr.dead && plr.Distance(npc.Center) < 800f && plr.Center.Y < npc.Center.Y && Math.Abs(plr.Center.X - npc.Center.X) < 20f) { spawnTwinkle = true; break; @@ -10704,12 +10704,12 @@ PrepareToShoot: npc.noTileCollide = true; npc.knockBackResist = 0f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i == npc.whoAmI || !Main.npc[i].active || Main.npc[i].type != npc.type) + if (i == npc.whoAmI || n.type != npc.type) continue; - Vector2 targetDirection = Main.npc[i].Center - npc.Center; + Vector2 targetDirection = n.Center - npc.Center; if (!(targetDirection.Length() < 50f)) continue; @@ -10724,8 +10724,7 @@ PrepareToShoot: targetDirection *= 0.4f; npc.velocity -= targetDirection; - NPC nPC = Main.npc[i]; - nPC.velocity += targetDirection; + n.velocity += targetDirection; } if (npc.type == NPCID.ShadowFlameApparition) diff --git a/NPCs/Yharon/YScreenShader.cs b/NPCs/Yharon/YScreenShader.cs index af5d55aaed..f7f3cf9e44 100644 --- a/NPCs/Yharon/YScreenShader.cs +++ b/NPCs/Yharon/YScreenShader.cs @@ -23,15 +23,7 @@ namespace CalamityMod.NPCs.Yharon { return; } - YIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == YType) - { - YIndex = i; - break; - } - } + YIndex = NPC.FindFirstNPC(YType); } public override void Update(GameTime gameTime) diff --git a/NPCs/Yharon/YSky.cs b/NPCs/Yharon/YSky.cs index bb673e8253..c033a023ce 100644 --- a/NPCs/Yharon/YSky.cs +++ b/NPCs/Yharon/YSky.cs @@ -60,15 +60,7 @@ namespace CalamityMod.NPCs.Yharon { return true; } - YIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == YType) - { - YIndex = i; - break; - } - } + YIndex = NPC.FindFirstNPC(YType); //this.DoGIndex = DoGIndex; return YIndex != -1; } diff --git a/Particles/BloodParticle.cs b/Particles/BloodParticle.cs index 9bb8333486..bfe3e02e8f 100644 --- a/Particles/BloodParticle.cs +++ b/Particles/BloodParticle.cs @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent; using Terraria.ModLoader; namespace CalamityMod.Particles @@ -31,6 +32,11 @@ namespace CalamityMod.Particles Velocity.Y = MathHelper.Clamp(Velocity.Y + 0.9f, -22f, 22f); Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 3D)); Rotation = Velocity.ToRotation() + MathHelper.PiOver2; + // Cycle through disco colors if blood and gore is off + if (!ChildSafety.Disabled) + { + Color = Main.DiscoColor; + } } public override void CustomDraw(SpriteBatch spriteBatch) diff --git a/Particles/BloodParticle2.cs b/Particles/BloodParticle2.cs index ee8b9bf707..53320c9c1b 100644 --- a/Particles/BloodParticle2.cs +++ b/Particles/BloodParticle2.cs @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent; using Terraria.ModLoader; namespace CalamityMod.Particles @@ -29,6 +30,11 @@ namespace CalamityMod.Particles Velocity *= 0.98f; Color = Color.Lerp(InitialColor, Color.Transparent, (float)Math.Pow(LifetimeCompletion, 4D)); Rotation = Velocity.ToRotation(); + // Cycle through disco colors if blood and gore is off + if (!ChildSafety.Disabled) + { + Color = Main.DiscoColor; + } } public override void CustomDraw(SpriteBatch spriteBatch) diff --git a/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs b/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs index fa73780b80..34d117b2e6 100644 --- a/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs +++ b/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs @@ -51,9 +51,9 @@ namespace CalamityMod.Projectiles.BaseProjectiles bool bladeIsPresent = false; int holdoutType = ItemProjectileRelationship[itemID]; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != holdoutType || Main.projectile[i].owner != player.whoAmI || !Main.projectile[i].active) + if (p.type != holdoutType || p.owner != player.whoAmI) continue; bladeIsPresent = true; diff --git a/Projectiles/Boss/AresTeslaOrb.cs b/Projectiles/Boss/AresTeslaOrb.cs index cec82cf781..3ccee65e4c 100644 --- a/Projectiles/Boss/AresTeslaOrb.cs +++ b/Projectiles/Boss/AresTeslaOrb.cs @@ -155,15 +155,15 @@ namespace CalamityMod.Projectiles.Boss bool expertMode = Main.expertMode || bossRush; float detachDistance = bossRush ? 1600f : death ? 1360f : revenge ? 1280f : expertMode ? 1200f : 960f; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != Projectile.type || Main.projectile[i].ai[0] != Identity + 1f || !Main.projectile[i].active || Main.npc[CalamityGlobalNPC.draedonExoMechPrime].Calamity().newAI[0] == (float)AresBody.Phase.Deathrays) + if (p.type != Projectile.type || p.ai[0] != Identity + 1f || Main.npc[CalamityGlobalNPC.draedonExoMechPrime].Calamity().newAI[0] == (float)AresBody.Phase.Deathrays) continue; - if (Vector2.Distance(Projectile.Center, Main.projectile[i].Center) > detachDistance) + if (Vector2.Distance(Projectile.Center, p.Center) > detachDistance) continue; - return Main.projectile[i]; + return p; } return null; diff --git a/Projectiles/Boss/FlareBomb.cs b/Projectiles/Boss/FlareBomb.cs index 9039baeaf1..a77545e689 100644 --- a/Projectiles/Boss/FlareBomb.cs +++ b/Projectiles/Boss/FlareBomb.cs @@ -80,24 +80,21 @@ namespace CalamityMod.Projectiles.Boss return; float acceleration = 0.5f; - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[j].active) + if (p.whoAmI != Projectile.whoAmI && p.type == Projectile.type) { - if (j != Projectile.whoAmI && Main.projectile[j].type == Projectile.type) + if (Vector2.Distance(Projectile.Center, p.Center) < 24f) { - if (Vector2.Distance(Projectile.Center, Main.projectile[j].Center) < 24f) - { - if (Projectile.position.X < Main.projectile[j].position.X) - Projectile.velocity.X -= acceleration; - else - Projectile.velocity.X += acceleration; - - if (Projectile.position.Y < Main.projectile[j].position.Y) - Projectile.velocity.Y -= acceleration; - else - Projectile.velocity.Y += acceleration; - } + if (Projectile.position.X < p.position.X) + Projectile.velocity.X -= acceleration; + else + Projectile.velocity.X += acceleration; + + if (Projectile.position.Y < p.position.Y) + Projectile.velocity.Y -= acceleration; + else + Projectile.velocity.Y += acceleration; } } } diff --git a/Projectiles/Boss/OldDukeVortex.cs b/Projectiles/Boss/OldDukeVortex.cs index 02f6b1d5a7..f2c1fd5171 100644 --- a/Projectiles/Boss/OldDukeVortex.cs +++ b/Projectiles/Boss/OldDukeVortex.cs @@ -124,10 +124,8 @@ namespace CalamityMod.Projectiles.Boss float distanceRequired = 800f * Projectile.scale; float succPower = Main.zenithWorld ? 1f : 0.5f; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { - Player player = Main.player[i]; - float distance = Vector2.Distance(player.Center, Projectile.Center); if (distance < distanceRequired && player.grappling[0] == -1) { diff --git a/Projectiles/Boss/OverlyDramaticDukeSummoner.cs b/Projectiles/Boss/OverlyDramaticDukeSummoner.cs index d9f506ba87..53510f205b 100644 --- a/Projectiles/Boss/OverlyDramaticDukeSummoner.cs +++ b/Projectiles/Boss/OverlyDramaticDukeSummoner.cs @@ -107,9 +107,9 @@ namespace CalamityMod.Projectiles.Boss Projectile.alpha = (int)MathHelper.Lerp(0f, 255f, (Projectile.ai[0] - 600f) / 120f); bool canSpawnBoomer = false; - for (int i = 0; i < Main.player.Length; i++) + foreach (Player player in Main.ActivePlayers) { - if (!Main.player[i].dead && Projectile.Distance(Main.player[i].Center) < 12000f) + if (!player.dead && Projectile.Distance(player.Center) < 12000f) { canSpawnBoomer = true; break; diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 702bd1e219..f48741ddd9 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -3587,17 +3587,17 @@ namespace CalamityMod.Projectiles float maxDistance = 460f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(projectile, false)) + if (n.CanBeChasedBy(projectile, false)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (Main.npc[i].height / 2); + float extraDistance = (float)(n.width / 2) + (n.height / 2); - bool canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[i].Center, 1, 1); + bool canHit = Collision.CanHit(projectile.Center, 1, 1, n.Center, 1, 1); - if (Vector2.Distance(Main.npc[i].Center, projectile.Center) < (maxDistance + extraDistance) && canHit) + if (Vector2.Distance(n.Center, projectile.Center) < (maxDistance + extraDistance) && canHit) { - center = Main.npc[i].Center; + center = n.Center; homeIn = true; break; } @@ -4890,10 +4890,9 @@ namespace CalamityMod.Projectiles float lowestHealthCheck = 0f; int healTarget = projectile.owner; - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player otherPlayer in Main.ActivePlayers) { - Player otherPlayer = Main.player[i]; - if (otherPlayer.active && !otherPlayer.dead && ((!player.hostile && !otherPlayer.hostile) || player.team == otherPlayer.team)) + if (!otherPlayer.dead && ((!player.hostile && !otherPlayer.hostile) || player.team == otherPlayer.team)) { float playerDist = Vector2.Distance(projectile.Center, otherPlayer.Center); if (playerDist < distanceRequired && (otherPlayer.statLifeMax2 - otherPlayer.statLife) > lowestHealthCheck) diff --git a/Projectiles/CalamityGlobalProjectileTweaks.cs b/Projectiles/CalamityGlobalProjectileTweaks.cs index 658c5faae7..916a1412a8 100644 --- a/Projectiles/CalamityGlobalProjectileTweaks.cs +++ b/Projectiles/CalamityGlobalProjectileTweaks.cs @@ -133,9 +133,9 @@ namespace CalamityMod.Projectiles { ProjectileID.CrystalVileShardShaft, Do(LocalIFrames(23)) }, { ProjectileID.CursedBullet, standardBulletTweaks }, { ProjectileID.ClusterRocketI, Do(LocalIFrames(15)) }, - { ProjectileID.ClusterFragmentsI, Do(LocalIFrames(15)) }, + { ProjectileID.ClusterFragmentsI, Do(IDStaticIFrames(15)) }, { ProjectileID.ClusterRocketII, Do(LocalIFrames(15)) }, - { ProjectileID.ClusterFragmentsII, Do(LocalIFrames(15)) }, + { ProjectileID.ClusterFragmentsII, Do(IDStaticIFrames(15)) }, { ProjectileID.ClusterSnowmanRocketI, Do(LocalIFrames(15)) }, { ProjectileID.ClusterSnowmanRocketII, Do(LocalIFrames(15)) }, { ProjectileID.DD2SquireSonicBoom, Do(PiercingExact(3)) }, // Flying Dragon diff --git a/Projectiles/Damageable/DamageableProjectile.cs b/Projectiles/Damageable/DamageableProjectile.cs index 74b0bfe440..91d14e4f9d 100644 --- a/Projectiles/Damageable/DamageableProjectile.cs +++ b/Projectiles/Damageable/DamageableProjectile.cs @@ -169,14 +169,14 @@ namespace CalamityMod.Projectiles.Damageable public virtual bool NPCCollisionCheck() { Player player = Main.player[Projectile.owner]; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].IsAnEnemy() && DamageSources.HasFlag(DamageSourceType.HostileNPCs)) + if (n.IsAnEnemy() && DamageSources.HasFlag(DamageSourceType.HostileNPCs)) { - if (Main.npc[i].Hitbox.Intersects(Projectile.Hitbox) && !NPCsToIgnore.Contains(Main.npc[i].type)) + if (n.Hitbox.Intersects(Projectile.Hitbox) && !NPCsToIgnore.Contains(n.type)) { - int damage = Main.DamageVar(Main.npc[i].damage); - int bannerBuffId = Item.NPCtoBanner(Main.npc[i].BannerID()); + int damage = Main.DamageVar(n.damage); + int bannerBuffId = Item.NPCtoBanner(n.BannerID()); if (bannerBuffId > 0 && player.HasNPCBannerBuff(bannerBuffId)) { if (Main.expertMode) @@ -190,7 +190,7 @@ namespace CalamityMod.Projectiles.Damageable } CombatText.NewText(new Rectangle((int)Projectile.position.X, (int)Projectile.position.Y, Projectile.width, Projectile.height), CombatText.DamagedFriendly, damage); Life -= damage; - HitEffectNPC(damage, Main.npc[i]); + HitEffectNPC(damage, n); DamageImmunityFrames = MaxDamageImmunityFrames; NetUpdate(true); return true; @@ -201,20 +201,20 @@ namespace CalamityMod.Projectiles.Damageable } public virtual bool ProjectileCollisionCheck() { - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - bool canBeHit = (Main.projectile[i].friendly && DamageSources.HasFlag(DamageSourceType.FriendlyProjectiles) || - Main.projectile[i].hostile && DamageSources.HasFlag(DamageSourceType.HostileProjectiles)) && - i != Projectile.whoAmI; - if (Main.projectile[i].active && canBeHit && Main.projectile[i].damage > 0) + bool canBeHit = (p.friendly && DamageSources.HasFlag(DamageSourceType.FriendlyProjectiles) || + p.hostile && DamageSources.HasFlag(DamageSourceType.HostileProjectiles)) && + p.whoAmI != Projectile.whoAmI; + if (canBeHit && p.damage > 0) { - if (Main.projectile[i].Colliding(Main.projectile[i].Hitbox, Projectile.Hitbox)) + if (p.Colliding(p.Hitbox, Projectile.Hitbox)) { - int damage = Main.DamageVar(Main.projectile[i].damage) * 2; + int damage = Main.DamageVar(p.damage) * 2; damage = Main.expertMode ? (int)(damage * Main.RegisteredGameModes[GameModeID.Expert].EnemyDamageMultiplier) : damage; CombatText.NewText(new Rectangle((int)Projectile.position.X, (int)Projectile.position.Y, Projectile.width, Projectile.height), CombatText.DamagedFriendly, damage); Life -= damage; - HitEffectProjectile(damage, Main.projectile[i]); + HitEffectProjectile(damage, p); DamageImmunityFrames = MaxDamageImmunityFrames; if (Projectile.usesIDStaticNPCImmunity) DamageImmunityFrames = Projectile.idStaticNPCHitCooldown; diff --git a/Projectiles/DraedonsArsenal/HydraulicVoltCrasherProjectile.cs b/Projectiles/DraedonsArsenal/HydraulicVoltCrasherProjectile.cs index 5c1b0f93f2..9a99cf55b4 100644 --- a/Projectiles/DraedonsArsenal/HydraulicVoltCrasherProjectile.cs +++ b/Projectiles/DraedonsArsenal/HydraulicVoltCrasherProjectile.cs @@ -129,19 +129,19 @@ namespace CalamityMod.Projectiles.DraedonsArsenal chargeCooldown = 60; TryToSuperchargeNPC(target); int extraZaps = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i != target.whoAmI && - Main.npc[i].CanBeChasedBy(Projectile, false) && - Main.npc[i].Distance(target.Center) < 240f && + if (n.whoAmI != target.whoAmI && + n.CanBeChasedBy(Projectile, false) && + n.Distance(target.Center) < 240f && extraZaps < 3) { - - if (TryToSuperchargeNPC(Main.npc[i])) + + if (TryToSuperchargeNPC(n)) { for (float increment = 0f; increment <= 1f; increment += 0.05f) { - Vector2 spawnPosition = Vector2.Lerp(target.Center, Main.npc[i].Center, increment); + Vector2 spawnPosition = Vector2.Lerp(target.Center, n.Center, increment); Dust dust = Dust.NewDustPerfect(spawnPosition, 226); dust.velocity = Vector2.Zero; dust.scale = 1.6f; @@ -162,11 +162,10 @@ namespace CalamityMod.Projectiles.DraedonsArsenal return false; // Prevent supercharging an enemy twice. - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && - Main.projectile[i].type == attackType && - Main.projectile[i].ai[1] == i) + if (p.type == attackType && + p.ai[1] == p.whoAmI) { return false; } diff --git a/Projectiles/DraedonsArsenal/PoleWarperSummon.cs b/Projectiles/DraedonsArsenal/PoleWarperSummon.cs index 4458db75aa..61308df0d2 100644 --- a/Projectiles/DraedonsArsenal/PoleWarperSummon.cs +++ b/Projectiles/DraedonsArsenal/PoleWarperSummon.cs @@ -116,13 +116,12 @@ namespace CalamityMod.Projectiles.DraedonsArsenal public void NPCMovement(NPC npc) { - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == Projectile.type && - Main.projectile[i].active && + if (p.type == Projectile.type && Projectile.owner == Projectile.owner) { - PoleWarperSummon otherPole = (PoleWarperSummon)Main.projectile[i].ModProjectile; + PoleWarperSummon otherPole = (PoleWarperSummon)p.ModProjectile; if (otherPole.Time != Time && otherPole.Time != Time + 1) { otherPole.Time = Time; @@ -152,22 +151,21 @@ namespace CalamityMod.Projectiles.DraedonsArsenal public void RepelMovement() { // This does not incorporate attraction on purpose. Doing so causes the minions to very easily become distracted. - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == Projectile.type && - Main.projectile[i].active && - Projectile.Distance(Main.projectile[i].Center) < 40f) + if (p.type == Projectile.type && + Projectile.Distance(p.Center) < 40f) { - PoleWarperSummon otherPole = (PoleWarperSummon)Main.projectile[i].ModProjectile; + PoleWarperSummon otherPole = (PoleWarperSummon)p.ModProjectile; if (otherPole.North != North) { - float distanceFromOtherPole = Projectile.Distance(Main.projectile[i].Center) + 1f; + float distanceFromOtherPole = Projectile.Distance(p.Center) + 1f; if (float.IsNaN(distanceFromOtherPole) || distanceFromOtherPole < 1f) { distanceFromOtherPole = 1f; } float repulsionSpeed = MaximumRepulsionSpeed * (float)Math.Pow(3f, -distanceFromOtherPole / 27f); - Projectile.velocity -= (Main.projectile[i].Center - Projectile.Center).SafeNormalize(Vector2.UnitY) * repulsionSpeed; + Projectile.velocity -= (p.Center - Projectile.Center).SafeNormalize(Vector2.UnitY) * repulsionSpeed; } } } diff --git a/Projectiles/DraedonsArsenal/PulsePistolShot.cs b/Projectiles/DraedonsArsenal/PulsePistolShot.cs index abd03aceaf..86a4fa01e8 100644 --- a/Projectiles/DraedonsArsenal/PulsePistolShot.cs +++ b/Projectiles/DraedonsArsenal/PulsePistolShot.cs @@ -90,15 +90,15 @@ namespace CalamityMod.Projectiles.DraedonsArsenal float minDistance = 600f; List potentialTargets = new List(); - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - bool legalTarget = Main.npc[i] != target && Main.npc[i].active && Main.npc[i].CanBeChasedBy(null); - float distanceToTarget = Projectile.Distance(Main.npc[i].Center); - if (legalTarget && distanceToTarget < minDistance && !NPCsAlreadyHit.Contains(Main.npc[i])) + bool legalTarget = n != target && n.CanBeChasedBy(null); + float distanceToTarget = Projectile.Distance(n.Center); + if (legalTarget && distanceToTarget < minDistance && !NPCsAlreadyHit.Contains(n)) { minDistance = distanceToTarget; // The NPCs at the bottom will always be at the bottom of the list because it works via a minimum distance. - potentialTargets.Add(Main.npc[i]); + potentialTargets.Add(n); } } diff --git a/Projectiles/DraedonsArsenal/SnakeEyesSummon.cs b/Projectiles/DraedonsArsenal/SnakeEyesSummon.cs index 62127086be..18ad44c4b2 100644 --- a/Projectiles/DraedonsArsenal/SnakeEyesSummon.cs +++ b/Projectiles/DraedonsArsenal/SnakeEyesSummon.cs @@ -139,10 +139,9 @@ namespace CalamityMod.Projectiles.DraedonsArsenal // so it looks like the minion deflected his own projectile. if (HasShot) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj is not null && proj.active && proj.type == ModContent.ProjectileType() && proj.owner == Owner.whoAmI && proj.ModProjectile().MinionID == Projectile.whoAmI && proj.ModProjectile().HasRedirected) + if (proj.type == ModContent.ProjectileType() && proj.owner == Owner.whoAmI && proj.ModProjectile().MinionID == Projectile.whoAmI && proj.ModProjectile().HasRedirected) { Projectile.Center = proj.Center; SwitchAIState(AIState.Redirecting); diff --git a/Projectiles/DraedonsArsenal/TeslaCannonShot.cs b/Projectiles/DraedonsArsenal/TeslaCannonShot.cs index 6a6464955a..d0a4e1bc1f 100644 --- a/Projectiles/DraedonsArsenal/TeslaCannonShot.cs +++ b/Projectiles/DraedonsArsenal/TeslaCannonShot.cs @@ -96,14 +96,14 @@ namespace CalamityMod.Projectiles.DraedonsArsenal { if (arcs < 10) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!Main.npc[i].CanBeChasedBy(Projectile, false) || !Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1)) + if (!n.CanBeChasedBy(Projectile, false) || !Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1)) continue; - if (Projectile.Center.ManhattanDistance(Main.npc[i].Center) < 600f) + if (Projectile.Center.ManhattanDistance(n.Center) < 600f) { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.SafeDirectionTo(Main.npc[i].Center) * 2f, Projectile.type, (int)(Projectile.damage * 0.6), Projectile.knockBack * 0.6f, Projectile.owner, 0f, -1f); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.SafeDirectionTo(n.Center) * 2f, Projectile.type, (int)(Projectile.damage * 0.6), Projectile.knockBack * 0.6f, Projectile.owner, 0f, -1f); Projectile.ai[1] = 60f; diff --git a/Projectiles/Enemy/FlakAcid.cs b/Projectiles/Enemy/FlakAcid.cs index f51e4bc8d5..3edadc017d 100644 --- a/Projectiles/Enemy/FlakAcid.cs +++ b/Projectiles/Enemy/FlakAcid.cs @@ -35,9 +35,9 @@ namespace CalamityMod.Projectiles.Enemy Projectile.velocity.Y += 0.15f; Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; - for (int i = 0; i < Main.player.Length; i++) + foreach (Player player in Main.ActivePlayers) { - if (Main.player[i].Distance(Projectile.Center) < 60f) + if (player.Distance(Projectile.Center) < 60f) { Projectile.Kill(); } diff --git a/Projectiles/Magic/ArtAttackStar.cs b/Projectiles/Magic/ArtAttackStar.cs index ecbbfc032d..aea6eae32c 100644 --- a/Projectiles/Magic/ArtAttackStar.cs +++ b/Projectiles/Magic/ArtAttackStar.cs @@ -134,9 +134,9 @@ namespace CalamityMod.Projectiles.Magic { float damageFactor = MathHelper.Lerp(1f, ArtAttack.MaxDamageBoostFactor, Utils.GetLerpValue(0f, ArtAttack.MaxDamageBoostTime, Time, true)); int damage = (int)(Projectile.damage * damageFactor); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (!Main.npc[i].CanBeChasedBy()) + if (!n.CanBeChasedBy()) continue; bool enemyIsInShape = false; @@ -159,9 +159,9 @@ namespace CalamityMod.Projectiles.Magic Rectangle shapeRectangle = Utils.CenteredRectangle(center, area); for (int j = 0; j < cleanOldPositions.Count; j++) { - Vector2 left = Main.npc[i].Center - Vector2.UnitX * 2000f; - Vector2 right = Main.npc[i].Center + Vector2.UnitX * 2000f; - bool inRangeOfStars = shapeRectangle.Intersects(Main.npc[i].Hitbox); + Vector2 left = n.Center - Vector2.UnitX * 2000f; + Vector2 right = n.Center + Vector2.UnitX * 2000f; + bool inRangeOfStars = shapeRectangle.Intersects(n.Hitbox); bool lineCheck = Collision.CheckLinevLine(left, right, cleanOldPositions[j], cleanOldPositions[(j + 1) % cleanOldPositions.Count]).Length > 0; if (lineCheck && inRangeOfStars) { @@ -173,12 +173,12 @@ namespace CalamityMod.Projectiles.Magic // Strike an enemy if it's in the shape. if (enemyIsInShape) { - SoundEngine.PlaySound(SoundID.DD2_LightningBugZap, Main.npc[i].Center); - CreateDustExplosionEffect(Main.npc[i].Center); + SoundEngine.PlaySound(SoundID.DD2_LightningBugZap, n.Center); + CreateDustExplosionEffect(n.Center); if (Main.myPlayer == Projectile.owner) { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Main.npc[i].Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Projectile.owner, i); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), n.Center, Vector2.Zero, ModContent.ProjectileType(), damage, 0f, Projectile.owner, n.whoAmI); } } } diff --git a/Projectiles/Magic/BlackAnurianPlankton.cs b/Projectiles/Magic/BlackAnurianPlankton.cs index 4269f14e51..ca29350bbc 100644 --- a/Projectiles/Magic/BlackAnurianPlankton.cs +++ b/Projectiles/Magic/BlackAnurianPlankton.cs @@ -57,14 +57,14 @@ namespace CalamityMod.Projectiles.Magic if (Projectile.ai[0] > 30f) { Projectile.ai[0] = 30f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && !Main.npc[i].wet) + if (n.CanBeChasedBy(Projectile, false) && !n.wet) { - float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2); - float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].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 < 800f && npcDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) + if (npcDist < 800f && npcDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height)) { homingRange = npcDist; projX = npcX; diff --git a/Projectiles/Magic/BlindingLight.cs b/Projectiles/Magic/BlindingLight.cs index 8b4252e738..b4b206a6da 100644 --- a/Projectiles/Magic/BlindingLight.cs +++ b/Projectiles/Magic/BlindingLight.cs @@ -61,10 +61,9 @@ namespace CalamityMod.Projectiles.Magic { int lightBlade = ModContent.ProjectileType(); int extraDamage = 0; - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile otherProj in Main.ActiveProjectiles) { - Projectile otherProj = Main.projectile[i]; - if (otherProj is null || !otherProj.active || otherProj.owner != Projectile.owner || otherProj.type != lightBlade) + if (otherProj.owner != Projectile.owner || otherProj.type != lightBlade) continue; // Can only consume blades within the flash radius (which should be most if not all of them anyway) @@ -79,10 +78,9 @@ namespace CalamityMod.Projectiles.Magic private void DivideDamageAmongstTargets() { int numTargets = 0; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (var npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc is null || !npc.active || npc.friendly || npc.dontTakeDamage || npc.immortal) + if (npc.friendly || npc.dontTakeDamage || npc.immortal) continue; if (Projectile.Colliding(default, npc.Hitbox)) ++numTargets; diff --git a/Projectiles/Magic/EternityHex.cs b/Projectiles/Magic/EternityHex.cs index b7d62c4130..8443eb4ffb 100644 --- a/Projectiles/Magic/EternityHex.cs +++ b/Projectiles/Magic/EternityHex.cs @@ -177,11 +177,8 @@ namespace CalamityMod.Projectiles.Magic TargetNPCIndex = newTarget.whoAmI; // Adjust the target index for the other components of the projectile. - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (!proj.active) - continue; if (proj.owner != Projectile.owner) continue; if (proj.type != ModContent.ProjectileType() && proj.type != ModContent.ProjectileType()) diff --git a/Projectiles/Magic/EventHorizonStar.cs b/Projectiles/Magic/EventHorizonStar.cs index 3b7ec095cf..daf819b4d6 100644 --- a/Projectiles/Magic/EventHorizonStar.cs +++ b/Projectiles/Magic/EventHorizonStar.cs @@ -93,15 +93,15 @@ namespace CalamityMod.Projectiles.Magic float inertia = 25f; float homingSpeed = 23f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); + float extraDistance = (float)(n.width / 2) + (float)(n.height / 2); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (homingRange + extraDistance)) + if (Vector2.Distance(n.Center, Projectile.Center) < (homingRange + extraDistance)) { - center = Main.npc[i].Center; + center = n.Center; homeIn = true; break; } diff --git a/Projectiles/Magic/ExoVortex.cs b/Projectiles/Magic/ExoVortex.cs index fed7e9cdfc..aba7ceed69 100644 --- a/Projectiles/Magic/ExoVortex.cs +++ b/Projectiles/Magic/ExoVortex.cs @@ -8,6 +8,7 @@ using Terraria; using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.Graphics.Primitives; namespace CalamityMod.Projectiles.Magic { diff --git a/Projectiles/Magic/ExoVortex2.cs b/Projectiles/Magic/ExoVortex2.cs index d9351189ea..594aac4474 100644 --- a/Projectiles/Magic/ExoVortex2.cs +++ b/Projectiles/Magic/ExoVortex2.cs @@ -8,6 +8,7 @@ using Terraria; using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.Graphics.Primitives; namespace CalamityMod.Projectiles.Magic { diff --git a/Projectiles/Magic/GranitePulse.cs b/Projectiles/Magic/GranitePulse.cs index 2a75dd05e4..1cee67b0f7 100644 --- a/Projectiles/Magic/GranitePulse.cs +++ b/Projectiles/Magic/GranitePulse.cs @@ -67,15 +67,14 @@ namespace CalamityMod.Projectiles.Magic int index = 0; float findOldest = 0f; int projType = Projectile.type; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj.active && proj.owner == Projectile.owner && proj.type == projType && proj.ai[1] < 3600f) + if (proj.owner == Projectile.owner && proj.type == projType && proj.ai[1] < 3600f) { projCount++; if (proj.ai[1] > findOldest) { - index = i; + index = proj.whoAmI; findOldest = proj.ai[1]; } } diff --git a/Projectiles/Magic/HadalUrnJellyfish.cs b/Projectiles/Magic/HadalUrnJellyfish.cs index ed56c37ba2..dc57cb8008 100644 --- a/Projectiles/Magic/HadalUrnJellyfish.cs +++ b/Projectiles/Magic/HadalUrnJellyfish.cs @@ -75,17 +75,17 @@ namespace CalamityMod.Projectiles.Magic //Detect if any enemies are very close int maxDistance = 10; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2); + float extraDistance = (n.width / 2) + (n.height / 2); bool canHit = true; if (extraDistance < maxDistance) - canHit = Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1); + canHit = Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1); - if (Projectile.WithinRange(Main.npc[i].Center, maxDistance + extraDistance) && canHit) + if (Projectile.WithinRange(n.Center, maxDistance + extraDistance) && canHit) { neartarget = true; } diff --git a/Projectiles/Magic/IceBlock.cs b/Projectiles/Magic/IceBlock.cs index da684fba9f..228677e7de 100644 --- a/Projectiles/Magic/IceBlock.cs +++ b/Projectiles/Magic/IceBlock.cs @@ -35,9 +35,8 @@ namespace CalamityMod.Projectiles.Magic { Projectile.alpha = 20; } - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; if (proj.type == ModContent.ProjectileType() && proj.owner == Main.myPlayer) { Vector2 pos1 = new Vector2(proj.Center.X, proj.Center.Y - (proj.height * 0.5f) - 44f); diff --git a/Projectiles/Magic/NebulaCloudCore.cs b/Projectiles/Magic/NebulaCloudCore.cs index 155380efe0..4543a55adc 100644 --- a/Projectiles/Magic/NebulaCloudCore.cs +++ b/Projectiles/Magic/NebulaCloudCore.cs @@ -169,17 +169,17 @@ namespace CalamityMod.Projectiles.Magic int npcTrack = 0; if (Projectile.ai[1] == 0f) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(this)) + if (n.CanBeChasedBy(this)) { - Vector2 npcCenter = Main.npc[i].Center; - if (Projectile.Distance(npcCenter) < homingRange && Collision.CanHit(new Vector2(Projectile.position.X + Projectile.width / 2, Projectile.position.Y + Projectile.height / 2), 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) + Vector2 npcCenter = n.Center; + if (Projectile.Distance(npcCenter) < homingRange && Collision.CanHit(new Vector2(Projectile.position.X + Projectile.width / 2, Projectile.position.Y + Projectile.height / 2), 1, 1, n.position, n.width, n.height)) { homingRange = Projectile.Distance(npcCenter); projCenter = npcCenter; isHoming = true; - npcTrack = i; + npcTrack = n.whoAmI; } } } diff --git a/Projectiles/Magic/RancorLaserbeam.cs b/Projectiles/Magic/RancorLaserbeam.cs index df0f3ecfc8..b2d907be0d 100644 --- a/Projectiles/Magic/RancorLaserbeam.cs +++ b/Projectiles/Magic/RancorLaserbeam.cs @@ -21,12 +21,12 @@ namespace CalamityMod.Projectiles.Magic { get { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].identity != Projectile.ai[0] || !Main.projectile[i].active || Main.projectile[i].owner != Projectile.owner) + if (p.identity != Projectile.ai[0] || p.owner != Projectile.owner) continue; - return Main.projectile[i]; + return p; } return null; } diff --git a/Projectiles/Magic/SHPB.cs b/Projectiles/Magic/SHPB.cs index 5b7c11d916..edbdac9ab9 100644 --- a/Projectiles/Magic/SHPB.cs +++ b/Projectiles/Magic/SHPB.cs @@ -68,12 +68,12 @@ namespace CalamityMod.Projectiles.Magic float projY = Projectile.Center.Y; float explodeRange = 250f; bool canExplode = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1)) + if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1)) { - float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2); - float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].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 < explodeRange) { diff --git a/Projectiles/Magic/SmallSpirit.cs b/Projectiles/Magic/SmallSpirit.cs index fb98eb148e..ef1d961c19 100644 --- a/Projectiles/Magic/SmallSpirit.cs +++ b/Projectiles/Magic/SmallSpirit.cs @@ -15,15 +15,15 @@ namespace CalamityMod.Projectiles.Magic get { int spiritType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != spiritType || Main.projectile[i].identity != Projectile.ai[0] || - Main.projectile[i].owner != Projectile.owner) + if (p.type != spiritType || p.identity != Projectile.ai[0] || + p.owner != Projectile.owner) { continue; } - return Main.projectile[i]; + return p; } return null; } diff --git a/Projectiles/Magic/WulfrumBolt.cs b/Projectiles/Magic/WulfrumBolt.cs index fcc64df360..3565948b51 100644 --- a/Projectiles/Magic/WulfrumBolt.cs +++ b/Projectiles/Magic/WulfrumBolt.cs @@ -67,10 +67,8 @@ namespace CalamityMod.Projectiles.Magic float bestScore = 0; NPC bestTarget = null; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC potentialTarget in Main.ActiveNPCs) { - NPC potentialTarget = Main.npc[i]; - if (!potentialTarget.CanBeChasedBy(null, false)) continue; diff --git a/Projectiles/Magic/WulfrumManaDrain.cs b/Projectiles/Magic/WulfrumManaDrain.cs index 258f09e141..04ede744a2 100644 --- a/Projectiles/Magic/WulfrumManaDrain.cs +++ b/Projectiles/Magic/WulfrumManaDrain.cs @@ -94,11 +94,9 @@ namespace CalamityMod.Projectiles.Magic { float collisionPoint = 0f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC struckNPC in Main.ActiveNPCs) { - NPC struckNPC = Main.npc[i]; - - if (!struckNPC.active || struckNPC.townNPC || struckNPC.friendly) + if (struckNPC.townNPC || struckNPC.friendly) continue; float distance = struckNPC.Distance(Projectile.Center); diff --git a/Projectiles/Melee/AmidiasWhirlpool.cs b/Projectiles/Melee/AmidiasWhirlpool.cs index b0277b9fcd..bcaf24ed46 100644 --- a/Projectiles/Melee/AmidiasWhirlpool.cs +++ b/Projectiles/Melee/AmidiasWhirlpool.cs @@ -76,21 +76,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/BalefulHarvesterProjectile.cs b/Projectiles/Melee/BalefulHarvesterProjectile.cs index d5371d6a92..8855fed60a 100644 --- a/Projectiles/Melee/BalefulHarvesterProjectile.cs +++ b/Projectiles/Melee/BalefulHarvesterProjectile.cs @@ -73,21 +73,19 @@ namespace CalamityMod.Projectiles.Melee else { float homingRange = 1000f; - int inc; - for (int i = 0; i < Main.maxNPCs; i = inc + 1) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2); - float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].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 < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) + if (npcDist < homingRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height)) { homingRange = npcDist; - Projectile.ai[0] = (float)i; + Projectile.ai[0] = (float)n.whoAmI; } } - inc = i; } } diff --git a/Projectiles/Melee/CosmicShivAura.cs b/Projectiles/Melee/CosmicShivAura.cs index 5abefa744d..43e42687bb 100644 --- a/Projectiles/Melee/CosmicShivAura.cs +++ b/Projectiles/Melee/CosmicShivAura.cs @@ -1,4 +1,12 @@ -using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Buffs.DamageOverTime; +using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; using Terraria.ModLoader; @@ -28,7 +36,7 @@ namespace CalamityMod.Projectiles.Melee public override void OnSpawn(IEntitySource source) { if (Main.npc[(int)Projectile.ai[0]] is not null || Main.npc[(int)Projectile.ai[0]].active) - target = Main.npc[(int)Projectile.ai[0]]; // Convert target.whoAmI to object + target = Main.npc[(int)Projectile.ai[0]]; // Convert target.whoAmI to object } // ai[0] for ID of target to follow until the end of projectile's lifespan or the target cannot be found @@ -41,7 +49,8 @@ namespace CalamityMod.Projectiles.Melee Projectile.Kill(); } - Projectile.Center = Main.npc[(int)Projectile.ai[0]].Center; // Stay with target + // Stay with target + Projectile.Center = Main.npc[(int)Projectile.ai[0]].Center; if (Projectile.ai[1] == CurrentSwordTimer) { @@ -49,10 +58,16 @@ namespace CalamityMod.Projectiles.Melee randomDirection.Normalize(); int randomDistance = Main.rand.Next(200, 426); Vector2 spawnPos = Projectile.Center + (randomDirection * randomDistance); - Vector2 velocity = Vector2.Normalize(Projectile.Center - spawnPos) * Utils.GetLerpValue(-100, 426, randomDistance, clamped: true) * 20f; // Sword moves a bit slower if spawned closer, moves faster if spawned further + + // Sword moves a bit slower if spawned closer, moves faster if spawned further + Vector2 velocity = Vector2.Normalize(Projectile.Center - spawnPos) * Utils.GetLerpValue(-100, 426, randomDistance, clamped: true) * 20f; Projectile.NewProjectile(Projectile.GetSource_FromThis(), spawnPos.X, spawnPos.Y, velocity.X, velocity.Y, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack * 0.8f, Projectile.owner, randomDistance); - Projectile.ai[1] = 0; // Reset timer - CurrentSwordTimer = Main.rand.Next(SwordsAverageDelay - SwordsRandomOffset, SwordsAverageDelay + SwordsRandomOffset); // Determine when next sword will spawn + + // Reset timer + Projectile.ai[1] = 0; + + // Determine when next sword will spawn + CurrentSwordTimer = Main.rand.Next(SwordsAverageDelay - SwordsRandomOffset, SwordsAverageDelay + SwordsRandomOffset); } Projectile.ai[1]++; diff --git a/Projectiles/Melee/CosmicShivBlade.cs b/Projectiles/Melee/CosmicShivBlade.cs index 10b158513a..5ae1c83de6 100644 --- a/Projectiles/Melee/CosmicShivBlade.cs +++ b/Projectiles/Melee/CosmicShivBlade.cs @@ -66,13 +66,18 @@ namespace CalamityMod.Projectiles.Melee float rotation = Projectile.rotation; Color randomColor = Projectile.GetAlpha(lightColor); + // Afterimages to make the blade look longer float scaleMult = 1.2f; - for (int i = 0; i < Projectile.oldPos.Length; i++) // Afterimages to make the blade look longer + for (int i = 0; i < Projectile.oldPos.Length; i++) { Vector2 drawPos = Projectile.oldPos[i] + (Projectile.Size / 2f) - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); Color color = randomColor * ((float)(Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); - Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color, rotation, origin, Projectile.scale * scaleMult, SpriteEffects.None, 0f); // Smaller, more visible layer - Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color * 0.5f, rotation, origin, Projectile.scale * 1.6f * scaleMult, SpriteEffects.None, 0f); // Bigger, less visible layer + + // Smaller, more visible layer + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color, rotation, origin, Projectile.scale * scaleMult, SpriteEffects.None, 0f); + + // Bigger, less visible layer + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color * 0.5f, rotation, origin, Projectile.scale * 1.6f * scaleMult, SpriteEffects.None, 0f); scaleMult *= 0.95f; } @@ -88,12 +93,14 @@ namespace CalamityMod.Projectiles.Melee } } - public override Color? GetAlpha(Color lightColor) // Probably not the right way to use this function, but it works (hopefully) + // Probably not the right way to use this function, but it works (hopefully) + public override Color? GetAlpha(Color lightColor) { + // Take random color from a list and make it more white Color color = CosmicShivTrail.DustColors[ColorIndex] * Projectile.Opacity; color = Color.Lerp(color, Color.White, 0.6f); color.A = 0; - return color; // Take random color from a list and make it more white + return color; } } } diff --git a/Projectiles/Melee/CosmicShivTrail.cs b/Projectiles/Melee/CosmicShivTrail.cs index 8c7d14eb67..df703c0e46 100644 --- a/Projectiles/Melee/CosmicShivTrail.cs +++ b/Projectiles/Melee/CosmicShivTrail.cs @@ -7,6 +7,14 @@ using Terraria; using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.Buffs.DamageOverTime; +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; +using System.Reflection.Metadata; +using Microsoft.Xna.Framework.Graphics; +using System.Diagnostics.Contracts; +using Terraria.GameContent; +using Terraria.Audio; namespace CalamityMod.Projectiles.Melee { @@ -104,6 +112,39 @@ namespace CalamityMod.Projectiles.Melee target.AddBuff(ModContent.BuffType(), 60); } + // pretty much entirely from the Oracle circular damage code + private void CircularDamage(float radius) + { + if (Projectile.owner != Main.myPlayer) + return; + Player owner = Main.player[Projectile.owner]; + + foreach (NPC target in Main.ActiveNPCs) + { + if (target.dontTakeDamage || target.friendly) + continue; + + // Shock any valid target within range. Check all four corners of their hitbox. + float d1 = Vector2.Distance(Projectile.Center, target.Hitbox.TopLeft()); + float d2 = Vector2.Distance(Projectile.Center, target.Hitbox.TopRight()); + float d3 = Vector2.Distance(Projectile.Center, target.Hitbox.BottomLeft()); + float d4 = Vector2.Distance(Projectile.Center, target.Hitbox.BottomRight()); + float dist = MathHelper.Min(d1, d2); + dist = MathHelper.Min(dist, d3); + dist = MathHelper.Min(dist, d4); + + if (dist <= radius) + { + int damage = (int)(Projectile.damage * ExplosionDamageMultiplier); + bool crit = Main.rand.Next(100) <= owner.GetCritChance() + 4; + target.StrikeNPC(target.CalculateHitInfo(damage, 0, crit, 0)); + + if (Main.netMode != NetmodeID.SinglePlayer) + NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, target.whoAmI, damage, 0f, 0f, crit ? 1 : 0, 0, 0); + } + } + } + // Very similar to CosmicShivBlade PreDraw public override bool PreDraw(ref Color lightColor) { @@ -187,6 +228,8 @@ namespace CalamityMod.Projectiles.Melee dust.fadeIn = -1f; } } + + CircularDamage(80f); } public override Color? GetAlpha(Color lightColor) diff --git a/Projectiles/Melee/Cyclone.cs b/Projectiles/Melee/Cyclone.cs index ffd4d3fa0e..e079ace083 100644 --- a/Projectiles/Melee/Cyclone.cs +++ b/Projectiles/Melee/Cyclone.cs @@ -65,9 +65,8 @@ namespace CalamityMod.Projectiles.Melee } float projX = Projectile.Center.X; float projY = Projectile.Center.Y; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses) { float npcCenterX = npc.position.X + (float)(npc.width / 2); diff --git a/Projectiles/Melee/DivineHatchetBoomerang.cs b/Projectiles/Melee/DivineHatchetBoomerang.cs index a37d582fb4..7399a76afb 100644 --- a/Projectiles/Melee/DivineHatchetBoomerang.cs +++ b/Projectiles/Melee/DivineHatchetBoomerang.cs @@ -165,21 +165,20 @@ namespace CalamityMod.Projectiles.Melee //find a nearby NPC to track float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { bool hasHitNPC = false; for (int j = 0; j < previousNPCs.Count; j++) { - if (previousNPCs[j] == i) + if (previousNPCs[j] == npc.whoAmI) { hasHitNPC = true; } } - NPC npc = Main.npc[i]; if (npc == target) { - previousNPCs.Add(i); + previousNPCs.Add(npc.whoAmI); } if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC) { @@ -187,7 +186,7 @@ namespace CalamityMod.Projectiles.Melee if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Melee/DraconicSpark.cs b/Projectiles/Melee/DraconicSpark.cs index 3ae085492e..2bd1719ad8 100644 --- a/Projectiles/Melee/DraconicSpark.cs +++ b/Projectiles/Melee/DraconicSpark.cs @@ -46,12 +46,12 @@ namespace CalamityMod.Projectiles.Melee float targetY = Projectile.Center.Y; bool foundTarget = false; float maxRange = MaxHomingRange; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1)) + if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1)) { - float iterCenterX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2); - float iterCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2); + float iterCenterX = n.position.X + (float)(n.width / 2); + float iterCenterY = n.position.Y + (float)(n.height / 2); float dist = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - iterCenterX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - iterCenterY); if (dist < maxRange) { diff --git a/Projectiles/Melee/DragonRageStaff.cs b/Projectiles/Melee/DragonRageStaff.cs index c02a0bbd26..79c116440d 100644 --- a/Projectiles/Melee/DragonRageStaff.cs +++ b/Projectiles/Melee/DragonRageStaff.cs @@ -191,13 +191,12 @@ namespace CalamityMod.Projectiles.Melee Rectangle myRect = Projectile.Hitbox; if (Projectile.owner == Main.myPlayer) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; bool voodooDolls = Projectile.owner < Main.maxPlayers && (npc.type == NPCID.Guide && player.killGuide || npc.type == NPCID.Clothier && player.killClothier); bool friendlyProjs = Projectile.friendly && (!npc.friendly || voodooDolls); bool hostileProjs = Projectile.hostile && npc.friendly && !npc.dontTakeDamageFromHostiles; - if (npc.active && !npc.dontTakeDamage && (friendlyProjs || hostileProjs) && (Projectile.owner < 0 || npc.immune[Projectile.owner] == 0 || Projectile.maxPenetrate == 1)) + if (!npc.dontTakeDamage && (friendlyProjs || hostileProjs) && (Projectile.owner < 0 || npc.immune[Projectile.owner] == 0 || Projectile.maxPenetrate == 1)) { if (npc.noTileCollide || !Projectile.ownerHitCheck || (ProjectileLoader.CanHitNPC(Projectile, npc) ?? false)) { diff --git a/Projectiles/Melee/EonBolt.cs b/Projectiles/Melee/EonBolt.cs index d6aaba4fd7..ff20bd185c 100644 --- a/Projectiles/Melee/EonBolt.cs +++ b/Projectiles/Melee/EonBolt.cs @@ -8,6 +8,7 @@ using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; using static Terraria.ModLoader.ModContent; +using CalamityMod.Graphics.Primitives; namespace CalamityMod.Projectiles.Melee { diff --git a/Projectiles/Melee/Galaxia_AriesWrath.cs b/Projectiles/Melee/Galaxia_AriesWrath.cs index c948b565c9..fbfac04194 100644 --- a/Projectiles/Melee/Galaxia_AriesWrath.cs +++ b/Projectiles/Melee/Galaxia_AriesWrath.cs @@ -87,9 +87,8 @@ namespace CalamityMod.Projectiles.Melee { float longestReach = MaxProjReach; NPC target = null; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC) { float distance = Vector2.Distance(hitFrom, npc.Center); diff --git a/Projectiles/Melee/GalaxyBlast.cs b/Projectiles/Melee/GalaxyBlast.cs index f5065f0ba0..632f541652 100644 --- a/Projectiles/Melee/GalaxyBlast.cs +++ b/Projectiles/Melee/GalaxyBlast.cs @@ -79,16 +79,15 @@ namespace CalamityMod.Projectiles.Melee { int npcTracker = -1; float homingRange = 60f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[i]; if (nPC.CanBeChasedBy(Projectile, false)) { float npcDistance = Projectile.Distance(nPC.Center); if (npcDistance < homingRange && Collision.CanHitLine(Projectile.Center, 0, 0, nPC.Center, 0, 0)) { homingRange = npcDistance; - npcTracker = i; + npcTracker = nPC.whoAmI; } } } diff --git a/Projectiles/Melee/GalaxyBlastType2.cs b/Projectiles/Melee/GalaxyBlastType2.cs index c511cee1ba..69c316a3d8 100644 --- a/Projectiles/Melee/GalaxyBlastType2.cs +++ b/Projectiles/Melee/GalaxyBlastType2.cs @@ -80,16 +80,15 @@ namespace CalamityMod.Projectiles.Melee { int npcTracker = -1; float homingRange = 60f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[i]; if (nPC.CanBeChasedBy(Projectile, false)) { float npcDistance = Projectile.Distance(nPC.Center); if (npcDistance < homingRange && Collision.CanHitLine(Projectile.Center, 0, 0, nPC.Center, 0, 0)) { homingRange = npcDistance; - npcTracker = i; + npcTracker = nPC.whoAmI; } } } diff --git a/Projectiles/Melee/GalaxyBlastType3.cs b/Projectiles/Melee/GalaxyBlastType3.cs index 707c0e8973..6ee3f57b3a 100644 --- a/Projectiles/Melee/GalaxyBlastType3.cs +++ b/Projectiles/Melee/GalaxyBlastType3.cs @@ -79,16 +79,15 @@ namespace CalamityMod.Projectiles.Melee { int npcTracker = -1; float homingRange = 60f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[i]; if (nPC.CanBeChasedBy(Projectile, false)) { float npcDistance = Projectile.Distance(nPC.Center); if (npcDistance < homingRange && Collision.CanHitLine(Projectile.Center, 0, 0, nPC.Center, 0, 0)) { homingRange = npcDistance; - npcTracker = i; + npcTracker = nPC.whoAmI; } } } diff --git a/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs b/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs index 6a70c0a862..c689dd82ff 100644 --- a/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs +++ b/Projectiles/Melee/MendedBiomeBlade_TrueGrovetendersTouch.cs @@ -132,9 +132,8 @@ namespace CalamityMod.Projectiles.Melee { float longestReach = MaxTangleReach; NPC target = null; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC) { float distance = Vector2.Distance(hitFrom, npc.Center); diff --git a/Projectiles/Melee/MicrowaveAura.cs b/Projectiles/Melee/MicrowaveAura.cs index 3a35f35f65..06c548340b 100644 --- a/Projectiles/Melee/MicrowaveAura.cs +++ b/Projectiles/Melee/MicrowaveAura.cs @@ -66,10 +66,9 @@ namespace CalamityMod.Projectiles.Melee private Projectile FindParent() { Projectile parent = null; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.identity == Projectile.ai[0] && p.active && p.type == ModContent.ProjectileType() && p.owner == Projectile.owner) + if (p.identity == Projectile.ai[0] && p.type == ModContent.ProjectileType() && p.owner == Projectile.owner) { parent = p; break; diff --git a/Projectiles/Melee/MourningSkull.cs b/Projectiles/Melee/MourningSkull.cs index d3c6622512..b709078298 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/Melee/OrderbringerAura.cs b/Projectiles/Melee/OrderbringerAura.cs index ebf5317dae..bdc5e8c106 100644 --- a/Projectiles/Melee/OrderbringerAura.cs +++ b/Projectiles/Melee/OrderbringerAura.cs @@ -52,15 +52,15 @@ namespace CalamityMod.Projectiles.Melee int incTracker = 0; float aiTracker = 0f; int theProjectile = Projectile.type; - for (int i = 0; i < 1000; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Projectile.owner && Main.projectile[i].type == theProjectile && Main.projectile[i].ai[1] < 3600f) + if (p.owner == Projectile.owner && p.type == theProjectile && p.ai[1] < 3600f) { projTimer++; - if (Main.projectile[i].ai[1] > aiTracker) + if (p.ai[1] > aiTracker) { - incTracker = i; - aiTracker = Main.projectile[i].ai[1]; + incTracker = p.whoAmI; + aiTracker = p.ai[1]; } } } diff --git a/Projectiles/Melee/Shortswords/CosmicShivProj.cs b/Projectiles/Melee/Shortswords/CosmicShivProj.cs index ce21686f54..15a8518531 100644 --- a/Projectiles/Melee/Shortswords/CosmicShivProj.cs +++ b/Projectiles/Melee/Shortswords/CosmicShivProj.cs @@ -1,9 +1,14 @@ -using System; +using System; using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent; +using Terraria.Graphics; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; @@ -57,7 +62,8 @@ namespace CalamityMod.Projectiles.Melee.Shortswords OnHitEffect(); if (NumHits < 3) - { // Just to avoid insanity from stacking so many super dummies or hitting many worm segments at once + { + // Just to avoid insanity from stacking so many super dummies or hitting many worm segments at once // 2x bonus for true melee hits (spawns an additional aura plus the one aura from the cosmic shiv ball) Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.position, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, target.whoAmI); NumHits++; diff --git a/Projectiles/Melee/StygianShieldAttack.cs b/Projectiles/Melee/StygianShieldAttack.cs index 775bbf5d0c..2293e3eb0e 100644 --- a/Projectiles/Melee/StygianShieldAttack.cs +++ b/Projectiles/Melee/StygianShieldAttack.cs @@ -66,10 +66,9 @@ namespace CalamityMod.Projectiles.Melee // Detach the owner from any mounts/hooks if (Owner.mount != null) Owner.mount.Dismount(Owner); - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (!proj.active || proj.owner != Owner.whoAmI || proj.aiStyle != ProjAIStyleID.Hook) + if (proj.owner != Owner.whoAmI || proj.aiStyle != ProjAIStyleID.Hook) continue; if (proj.aiStyle == ProjAIStyleID.Hook) proj.Kill(); diff --git a/Projectiles/Melee/StygianShieldThrown.cs b/Projectiles/Melee/StygianShieldThrown.cs index 48aa964265..3ee45d065b 100644 --- a/Projectiles/Melee/StygianShieldThrown.cs +++ b/Projectiles/Melee/StygianShieldThrown.cs @@ -120,17 +120,16 @@ namespace CalamityMod.Projectiles.Melee // Find the closest NPC targetable float range = MaxHomingRange; int targetNPC = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC target in Main.ActiveNPCs) { - NPC target = Main.npc[i]; - if (!target.CanBeChasedBy(Projectile) || PreviousNPCs.Contains(i)) + if (!target.CanBeChasedBy(Projectile) || PreviousNPCs.Contains(target.whoAmI)) continue; float distance = Vector2.Distance(target.Center, Projectile.Center); if (distance < range && Collision.CanHit(Projectile, target)) { range = distance; - targetNPC = i; + targetNPC = target.whoAmI; } } diff --git a/Projectiles/Melee/TenebreusTidesWaterSpear.cs b/Projectiles/Melee/TenebreusTidesWaterSpear.cs index 22fb1371eb..da2fbddebb 100644 --- a/Projectiles/Melee/TenebreusTidesWaterSpear.cs +++ b/Projectiles/Melee/TenebreusTidesWaterSpear.cs @@ -123,9 +123,8 @@ namespace CalamityMod.Projectiles.Melee int whoAmI = -1; Vector2 targetSpot = Projectile.Center; float detectRange = 700f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(npc.Center, Projectile.Center); @@ -133,7 +132,7 @@ namespace CalamityMod.Projectiles.Melee { detectRange = targetDist; targetSpot = npc.Center; - whoAmI = i; + whoAmI = npc.whoAmI; } } } diff --git a/Projectiles/Melee/TenebreusTidesWaterSword.cs b/Projectiles/Melee/TenebreusTidesWaterSword.cs index bcec9f85c8..8eeca5bc8d 100644 --- a/Projectiles/Melee/TenebreusTidesWaterSword.cs +++ b/Projectiles/Melee/TenebreusTidesWaterSword.cs @@ -105,9 +105,8 @@ namespace CalamityMod.Projectiles.Melee int whoAmI = -1; Vector2 targetSpot = Projectile.Center; float detectRange = 700f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(npc.Center, Projectile.Center); @@ -115,7 +114,7 @@ namespace CalamityMod.Projectiles.Melee { detectRange = targetDist; targetSpot = npc.Center; - whoAmI = i; + whoAmI = npc.whoAmI; } } } diff --git a/Projectiles/Melee/Tornado.cs b/Projectiles/Melee/Tornado.cs index 035dbd64cf..e1c3021502 100644 --- a/Projectiles/Melee/Tornado.cs +++ b/Projectiles/Melee/Tornado.cs @@ -82,9 +82,8 @@ namespace CalamityMod.Projectiles.Melee } float projX = Projectile.Center.X; float projY = Projectile.Center.Y; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1) && !CalamityPlayer.areThereAnyDamnBosses) { float npcCenterX = npc.position.X + (float)(npc.width / 2); diff --git a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs index e01060d597..38a4346f7e 100644 --- a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs +++ b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.cs @@ -138,9 +138,8 @@ namespace CalamityMod.Projectiles.Melee { float longestReach = MaxTangleReach; NPC target = null; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC) { float distance = Vector2.Distance(hitFrom, npc.Center); diff --git a/Projectiles/Melee/UrchinSpikeFugu.cs b/Projectiles/Melee/UrchinSpikeFugu.cs index aa1e315677..8d22f3cf4a 100644 --- a/Projectiles/Melee/UrchinSpikeFugu.cs +++ b/Projectiles/Melee/UrchinSpikeFugu.cs @@ -29,15 +29,14 @@ namespace CalamityMod.Projectiles.Melee { float maxRange = Projectile.ai[1] == 1f ? 256f : 100f; // Increased homing range for Lionfish int npcIndex = -1; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height)) { float targetDist = (npc.Center - Projectile.Center).Length(); if (targetDist < maxRange) { - npcIndex = i; + npcIndex = npc.whoAmI; maxRange = targetDist; } } diff --git a/Projectiles/Melee/VoidEssence.cs b/Projectiles/Melee/VoidEssence.cs index f04b58b948..692aea191f 100644 --- a/Projectiles/Melee/VoidEssence.cs +++ b/Projectiles/Melee/VoidEssence.cs @@ -88,19 +88,15 @@ namespace CalamityMod.Projectiles.Melee int targetIdx = -1; float maxHomingRange = 400f; bool hasHomingTarget = false; - for (int i = 0; i < Main.npc.Length; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc == null || !npc.active) - continue; - // Won't home in through walls and won't chase invulnerable targets. if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < maxHomingRange) { - targetIdx = i; + targetIdx = npc.whoAmI; maxHomingRange = dist; hasHomingTarget = true; } diff --git a/Projectiles/Melee/WhiteBoltAura.cs b/Projectiles/Melee/WhiteBoltAura.cs index 042342de1d..d361a79873 100644 --- a/Projectiles/Melee/WhiteBoltAura.cs +++ b/Projectiles/Melee/WhiteBoltAura.cs @@ -51,15 +51,15 @@ namespace CalamityMod.Projectiles.Melee int incTracker = 0; float aiTracker = 0f; int theProjectile = Projectile.type; - for (int j = 0; j < 1000; j++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[j].active && Main.projectile[j].owner == Projectile.owner && Main.projectile[j].type == theProjectile && Main.projectile[j].ai[1] < 3600f) + if (p.owner == Projectile.owner && p.type == theProjectile && p.ai[1] < 3600f) { projTimer++; - if (Main.projectile[j].ai[1] > aiTracker) + if (p.ai[1] > aiTracker) { - incTracker = j; - aiTracker = Main.projectile[j].ai[1]; + incTracker = p.whoAmI; + aiTracker = p.ai[1]; } } } diff --git a/Projectiles/Melee/WulfrumScrewdriverProj.cs b/Projectiles/Melee/WulfrumScrewdriverProj.cs index a87015759d..e5b86eea6a 100644 --- a/Projectiles/Melee/WulfrumScrewdriverProj.cs +++ b/Projectiles/Melee/WulfrumScrewdriverProj.cs @@ -88,9 +88,8 @@ namespace CalamityMod.Projectiles.Melee //Check for launchable screws. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; if (proj.ModProjectile != null && proj.owner == Projectile.owner && proj.ModProjectile is WulfrumScrew screw && screw.BazingaTime == 0) { float collisionPoint = 0f; @@ -132,10 +131,8 @@ namespace CalamityMod.Projectiles.Melee float bestScore = 0; NPC bestTarget = null; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC potentialTarget in Main.ActiveNPCs) { - NPC potentialTarget = Main.npc[i]; - if (!potentialTarget.CanBeChasedBy(null, false)) continue; diff --git a/Projectiles/Melee/Yoyos/ObliteratorYoyo.cs b/Projectiles/Melee/Yoyos/ObliteratorYoyo.cs index e95a5817f1..4676977462 100644 --- a/Projectiles/Melee/Yoyos/ObliteratorYoyo.cs +++ b/Projectiles/Melee/Yoyos/ObliteratorYoyo.cs @@ -95,19 +95,15 @@ namespace CalamityMod.Projectiles.Melee.Yoyos { List targets = new List(); float laserRange = 300f; - for (int i = 0; i < Main.npc.Length; ++i) + foreach (NPC n in Main.ActiveNPCs) { - ref NPC n = ref Main.npc[i]; - if (n is null || !n.active) - continue; - if (n.CanBeChasedBy(Projectile, false) && (n.Center - Projectile.Center).Length() <= laserRange && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1)) { - targets.Add(i); + targets.Add(n.whoAmI); // Bosses are added 5 times instead of 1 so that they are preferentially but not exclusively targeted. if (n.boss) for (int j = 0; j < 4; ++j) - targets.Add(i); + targets.Add(n.whoAmI); } } if (targets.Count == 0) diff --git a/Projectiles/Melee/Yoyos/OracleYoyo.cs b/Projectiles/Melee/Yoyos/OracleYoyo.cs index 39ec79b67f..4ed630902c 100644 --- a/Projectiles/Melee/Yoyos/OracleYoyo.cs +++ b/Projectiles/Melee/Yoyos/OracleYoyo.cs @@ -236,10 +236,9 @@ namespace CalamityMod.Projectiles.Melee.Yoyos return; Player owner = Main.player[Projectile.owner]; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC target in Main.ActiveNPCs) { - NPC target = Main.npc[i]; - if (!target.active || target.dontTakeDamage || target.friendly) + if (target.dontTakeDamage || target.friendly) continue; // Shock any valid target within range. Check all four corners of their hitbox. @@ -256,7 +255,7 @@ namespace CalamityMod.Projectiles.Melee.Yoyos int finalDamage = (int)owner.GetTotalDamage().ApplyTo(baseDamage); if (Projectile.owner == Main.myPlayer) { - Projectile p = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), target.Center, Vector2.Zero, ModContent.ProjectileType(), finalDamage, 0f, Projectile.owner, i); + Projectile p = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), target.Center, Vector2.Zero, ModContent.ProjectileType(), finalDamage, 0f, Projectile.owner, target.whoAmI); if (p.whoAmI.WithinBounds(Main.maxProjectiles)) p.DamageType = DamageClass.MeleeNoSpeed; } diff --git a/Projectiles/Melee/Yoyos/SulphurousGrabberYoyo.cs b/Projectiles/Melee/Yoyos/SulphurousGrabberYoyo.cs index 851525836a..238cd1a404 100644 --- a/Projectiles/Melee/Yoyos/SulphurousGrabberYoyo.cs +++ b/Projectiles/Melee/Yoyos/SulphurousGrabberYoyo.cs @@ -59,10 +59,9 @@ namespace CalamityMod.Projectiles.Melee.Yoyos if (bubbleStronkCounter >= 180) bubbleStronk = false; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj.active && proj.type == ModContent.ProjectileType() && proj.ai[0] >= 40f && proj.owner == Projectile.owner) + if (proj.type == ModContent.ProjectileType() && proj.ai[0] >= 40f && proj.owner == Projectile.owner) { if (Projectile.Hitbox.Intersects(proj.Hitbox)) { diff --git a/Projectiles/Pets/LadShark.cs b/Projectiles/Pets/LadShark.cs index dceeda70ad..ca68ec4c9c 100644 --- a/Projectiles/Pets/LadShark.cs +++ b/Projectiles/Pets/LadShark.cs @@ -72,18 +72,16 @@ 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); } } - for (int k = 0; k < Main.maxPlayers; k++) + foreach (Player players in Main.ActivePlayers) { - Player players = Main.player[k]; if (!players.dead && Vector2.Distance(Projectile.Center, players.Center) <= radius) { if (players.Calamity().ladHearts <= 0) diff --git a/Projectiles/Ranged/DrataliornusFlame.cs b/Projectiles/Ranged/DrataliornusFlame.cs index dd09b0470e..eb614b0583 100644 --- a/Projectiles/Ranged/DrataliornusFlame.cs +++ b/Projectiles/Ranged/DrataliornusFlame.cs @@ -73,11 +73,9 @@ namespace CalamityMod.Projectiles.Ranged int possibleTarget = -1; float closestDistance = 700f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - - if (npc.active && npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly && + if (npc.chaseable && npc.lifeMax > 5 && !npc.dontTakeDamage && !npc.friendly && !npc.immortal && Collision.CanHit(Projectile.Center, 0, 0, npc.Center, 0, 0)) { float distance = Vector2.Distance(Projectile.Center, npc.Center); @@ -85,7 +83,7 @@ namespace CalamityMod.Projectiles.Ranged if (closestDistance > distance) { closestDistance = distance; - possibleTarget = i; + possibleTarget = npc.whoAmI; } } } diff --git a/Projectiles/Ranged/ExoLight.cs b/Projectiles/Ranged/ExoLight.cs index d905834c7f..d9b146600d 100644 --- a/Projectiles/Ranged/ExoLight.cs +++ b/Projectiles/Ranged/ExoLight.cs @@ -71,10 +71,10 @@ namespace CalamityMod.Projectiles.Ranged Projectile.scale = MathHelper.Lerp(0.001f, 1f, Utils.GetLerpValue(0f, 25f, Time, true)); if (Projectile.localAI[0] == 0f) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile.GetSource_FromThis(), false)) - NPCDestination = Main.npc[i].Center + Main.npc[i].velocity * 5f; + if (n.CanBeChasedBy(Projectile.GetSource_FromThis(), false)) + NPCDestination = n.Center + n.velocity * 5f; } InitialCenter = Projectile.Center; Projectile.localAI[0] = 1f; diff --git a/Projectiles/Ranged/MagnomalyAura.cs b/Projectiles/Ranged/MagnomalyAura.cs index 0d3807eddf..44c91fe234 100644 --- a/Projectiles/Ranged/MagnomalyAura.cs +++ b/Projectiles/Ranged/MagnomalyAura.cs @@ -30,9 +30,8 @@ namespace CalamityMod.Projectiles.Ranged { Projectile parent = Main.projectile[0]; bool active = false; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; if (p.identity == Projectile.ai[0] && p.active && p.type == ModContent.ProjectileType()) { parent = p; diff --git a/Projectiles/Ranged/PrismMine.cs b/Projectiles/Ranged/PrismMine.cs index 363878009d..d677b63c99 100644 --- a/Projectiles/Ranged/PrismMine.cs +++ b/Projectiles/Ranged/PrismMine.cs @@ -68,10 +68,9 @@ namespace CalamityMod.Projectiles.Ranged public List LocateOtherMines() { List mines = new List(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj.type != Projectile.type || !proj.active || proj.timeLeft <= 12 || i == Projectile.whoAmI) + if (proj.type != Projectile.type || proj.timeLeft <= 12 || proj.whoAmI == Projectile.whoAmI) continue; if (!Projectile.WithinRange(proj.Center, MineConnectDistanceMax)) continue; diff --git a/Projectiles/Ranged/ThePackMissile.cs b/Projectiles/Ranged/ThePackMissile.cs index 3ae4347197..9a369c0616 100644 --- a/Projectiles/Ranged/ThePackMissile.cs +++ b/Projectiles/Ranged/ThePackMissile.cs @@ -36,11 +36,11 @@ namespace CalamityMod.Projectiles.Ranged Vector2 targetCenter = Projectile.Center; float minTargetDistance = 2500f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1)) + if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1)) { - float distanceFromTarget = Projectile.Center.ManhattanDistance(Main.npc[i].Center); + float distanceFromTarget = Projectile.Center.ManhattanDistance(n.Center); if (distanceFromTarget < 200f) { if (Projectile.owner == Main.myPlayer) @@ -58,7 +58,7 @@ namespace CalamityMod.Projectiles.Ranged else if (distanceFromTarget < minTargetDistance) { minTargetDistance = distanceFromTarget; - targetCenter = Main.npc[i].Center; + targetCenter = n.Center; homeIn = true; } } diff --git a/Projectiles/Ranged/UniversalGenesisStarcaller.cs b/Projectiles/Ranged/UniversalGenesisStarcaller.cs index 0f32060983..2c95e6bdeb 100644 --- a/Projectiles/Ranged/UniversalGenesisStarcaller.cs +++ b/Projectiles/Ranged/UniversalGenesisStarcaller.cs @@ -87,9 +87,8 @@ namespace CalamityMod.Projectiles.Ranged bool bossFound = false; int life = 0; Vector2 targetVec = Projectile.Center; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (bossFound && !npc.IsABoss()) continue; if (npc.CanBeChasedBy(Projectile, false)) diff --git a/Projectiles/Rogue/AlphaSeeker.cs b/Projectiles/Rogue/AlphaSeeker.cs index 40721f2fb7..e15fc1e560 100644 --- a/Projectiles/Rogue/AlphaSeeker.cs +++ b/Projectiles/Rogue/AlphaSeeker.cs @@ -50,10 +50,9 @@ namespace CalamityMod.Projectiles.Rogue Projectile parent = Main.projectile[0]; bool active = false; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.identity == Projectile.ai[1] && p.active) + if (p.identity == Projectile.ai[1]) { parent = p; active = true; @@ -141,10 +140,9 @@ namespace CalamityMod.Projectiles.Rogue { int target = -1; float minDist = HomingStartRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (var npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.type == NPCID.TargetDummy) + if (npc.type == NPCID.TargetDummy) continue; if (npc.CanBeChasedBy(Projectile, false)) @@ -155,7 +153,7 @@ namespace CalamityMod.Projectiles.Rogue if (distToNPC < minDist) { minDist = distToNPC; - target = i; + target = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/AuroradicalStar.cs b/Projectiles/Rogue/AuroradicalStar.cs index e577cdd132..2b0acbde3b 100644 --- a/Projectiles/Rogue/AuroradicalStar.cs +++ b/Projectiles/Rogue/AuroradicalStar.cs @@ -72,16 +72,15 @@ namespace CalamityMod.Projectiles.Rogue //Home in float maxDistance = 800f; int targetIndex = -1; - int i; - for (i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2); + float extraDistance = (n.width / 2) + (n.height / 2); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance)) + if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance)) { - targetIndex = i; + targetIndex = n.whoAmI; break; } } diff --git a/Projectiles/Rogue/BlunderBoosterLightning.cs b/Projectiles/Rogue/BlunderBoosterLightning.cs index dd935e3195..322fa2d5f9 100644 --- a/Projectiles/Rogue/BlunderBoosterLightning.cs +++ b/Projectiles/Rogue/BlunderBoosterLightning.cs @@ -57,16 +57,15 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = -1; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/BouncyBol.cs b/Projectiles/Rogue/BouncyBol.cs index 5c62b6b6ef..32dfaba20c 100644 --- a/Projectiles/Rogue/BouncyBol.cs +++ b/Projectiles/Rogue/BouncyBol.cs @@ -47,21 +47,20 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { bool hasHitNPC = false; for (int j = 0; j < previousNPCs.Count; j++) { - if (previousNPCs[j] == i) + if (previousNPCs[j] == npc.whoAmI) { hasHitNPC = true; } } - NPC npc = Main.npc[i]; if (npc == target) { - previousNPCs.Add(i); + previousNPCs.Add(npc.whoAmI); } if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC) { @@ -69,7 +68,7 @@ namespace CalamityMod.Projectiles.Rogue if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/CobaltEnergy.cs b/Projectiles/Rogue/CobaltEnergy.cs index 0d43432bde..d6ead0de25 100644 --- a/Projectiles/Rogue/CobaltEnergy.cs +++ b/Projectiles/Rogue/CobaltEnergy.cs @@ -59,21 +59,20 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { bool hasHitNPC = false; for (int j = 0; j < previousNPCs.Count; j++) { - if (previousNPCs[j] == i) + if (previousNPCs[j] == npc.whoAmI) { hasHitNPC = true; } } - NPC npc = Main.npc[i]; if (npc == target) { - previousNPCs.Add(i); + previousNPCs.Add(npc.whoAmI); } if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC) { @@ -81,7 +80,7 @@ namespace CalamityMod.Projectiles.Rogue if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/DestructionBolt.cs b/Projectiles/Rogue/DestructionBolt.cs index 71daf97bbe..7ab9e7cc56 100644 --- a/Projectiles/Rogue/DestructionBolt.cs +++ b/Projectiles/Rogue/DestructionBolt.cs @@ -55,16 +55,16 @@ namespace CalamityMod.Projectiles.Rogue { int index = -1; float otherConstant = 300f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - Vector2 npcCenter = Main.npc[i].Center; + Vector2 npcCenter = n.Center; float targetDist = Vector2.Distance(npcCenter, Projectile.Center); if (targetDist < otherConstant && index == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, npcCenter, 1, 1)) { otherConstant = targetDist; - index = i; + index = n.whoAmI; } } } diff --git a/Projectiles/Rogue/DynamicPursuerProjectile.cs b/Projectiles/Rogue/DynamicPursuerProjectile.cs index f0b630c69a..d12823defd 100644 --- a/Projectiles/Rogue/DynamicPursuerProjectile.cs +++ b/Projectiles/Rogue/DynamicPursuerProjectile.cs @@ -241,18 +241,18 @@ namespace CalamityMod.Projectiles.Rogue float targettingDistance = MaxTargetSearchDistance * 2f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var n in Main.ActiveNPCs) { - if (i == target.whoAmI) + if (n.whoAmI == target.whoAmI) continue; - if (Main.npc[i].CanBeChasedBy(Projectile)) + if (n.CanBeChasedBy(Projectile)) { - float potentialNewDistance = (Projectile.Center - Main.npc[i].Center).Length(); + float potentialNewDistance = (Projectile.Center - n.Center).Length(); if (potentialNewDistance < targettingDistance && potentialNewDistance < closestNPCDistance) { closestNPCDistance = potentialNewDistance; - newTarget = Main.npc[i]; + newTarget = n; nextTarget = newTarget; if (Projectile.timeLeft < 300) Projectile.timeLeft = 300; diff --git a/Projectiles/Rogue/ElementalDiskProj.cs b/Projectiles/Rogue/ElementalDiskProj.cs index a262f8d9b0..0d32eba95d 100644 --- a/Projectiles/Rogue/ElementalDiskProj.cs +++ b/Projectiles/Rogue/ElementalDiskProj.cs @@ -116,9 +116,8 @@ namespace CalamityMod.Projectiles.Rogue float maxDistance = 300f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float extraDistance = npc.width / 2 + npc.height / 2; diff --git a/Projectiles/Rogue/EnchantedAxeProj.cs b/Projectiles/Rogue/EnchantedAxeProj.cs index ab8ce605d0..3ef7ccf355 100644 --- a/Projectiles/Rogue/EnchantedAxeProj.cs +++ b/Projectiles/Rogue/EnchantedAxeProj.cs @@ -73,16 +73,15 @@ namespace CalamityMod.Projectiles.Rogue float minDist = 999f; int index = 0; // Get the closest enemy to the axe - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/EquanimityDarkShard.cs b/Projectiles/Rogue/EquanimityDarkShard.cs index 42da8f6630..aa65007872 100644 --- a/Projectiles/Rogue/EquanimityDarkShard.cs +++ b/Projectiles/Rogue/EquanimityDarkShard.cs @@ -30,16 +30,15 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/FinalDawnThrow2.cs b/Projectiles/Rogue/FinalDawnThrow2.cs index 9109382a0a..71e5979a8f 100644 --- a/Projectiles/Rogue/FinalDawnThrow2.cs +++ b/Projectiles/Rogue/FinalDawnThrow2.cs @@ -77,11 +77,9 @@ namespace CalamityMod.Projectiles.Rogue } // Kill any hooks from the projectile owner. - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - - if (!proj.active || proj.owner != player.whoAmI || proj.aiStyle != ProjAIStyleID.Hook) + if (proj.owner != player.whoAmI || proj.aiStyle != ProjAIStyleID.Hook) continue; if (proj.aiStyle == ProjAIStyleID.Hook) diff --git a/Projectiles/Rogue/FishboneBoomerangProjectile.cs b/Projectiles/Rogue/FishboneBoomerangProjectile.cs index 905b5409b5..f15ed5da4d 100644 --- a/Projectiles/Rogue/FishboneBoomerangProjectile.cs +++ b/Projectiles/Rogue/FishboneBoomerangProjectile.cs @@ -168,18 +168,18 @@ namespace CalamityMod.Projectiles.Rogue float closestNPCDistance = 10000f; float targettingDistance = 400f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (i == target.whoAmI) + if (n.whoAmI == target.whoAmI) continue; - if (Main.npc[i].CanBeChasedBy(Projectile)) + if (n.CanBeChasedBy(Projectile)) { - float potentialNewDistance = (Projectile.Center - Main.npc[i].Center).Length(); + float potentialNewDistance = (Projectile.Center - n.Center).Length(); if (potentialNewDistance < targettingDistance && potentialNewDistance < closestNPCDistance) { closestNPCDistance = potentialNewDistance; - newTarget = Main.npc[i]; + newTarget = n; } } } diff --git a/Projectiles/Rogue/FrostyFlareProj.cs b/Projectiles/Rogue/FrostyFlareProj.cs index 8b8ea4711f..f101b2cb23 100644 --- a/Projectiles/Rogue/FrostyFlareProj.cs +++ b/Projectiles/Rogue/FrostyFlareProj.cs @@ -96,15 +96,15 @@ namespace CalamityMod.Projectiles.Rogue int flaresFound = 0; int oldestFlare = -1; int oldestFlareTimeLeft = 300; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == Projectile.type && i != Projectile.whoAmI && Main.projectile[i].ai[1] == target.whoAmI) + if (p.owner == Main.myPlayer && p.type == Projectile.type && p.whoAmI != Projectile.whoAmI && p.ai[1] == target.whoAmI) { flaresFound++; - if (Main.projectile[i].timeLeft < oldestFlareTimeLeft) + if (p.timeLeft < oldestFlareTimeLeft) { - oldestFlareTimeLeft = Main.projectile[i].timeLeft; - oldestFlare = Main.projectile[i].whoAmI; + oldestFlareTimeLeft = p.timeLeft; + oldestFlare = p.whoAmI; } if (flaresFound >= maxFlares) break; diff --git a/Projectiles/Rogue/FrostyFlareStealth.cs b/Projectiles/Rogue/FrostyFlareStealth.cs index 3bda873ea7..e485108463 100644 --- a/Projectiles/Rogue/FrostyFlareStealth.cs +++ b/Projectiles/Rogue/FrostyFlareStealth.cs @@ -105,15 +105,15 @@ namespace CalamityMod.Projectiles.Rogue int flaresFound = 0; int oldestFlare = -1; int oldestFlareTimeLeft = 300; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == Projectile.type && i != Projectile.whoAmI && Main.projectile[i].ai[1] == target.whoAmI) + if (p.owner == Main.myPlayer && p.type == Projectile.type && p.whoAmI != Projectile.whoAmI && p.ai[1] == target.whoAmI) { flaresFound++; - if (Main.projectile[i].timeLeft < oldestFlareTimeLeft) + if (p.timeLeft < oldestFlareTimeLeft) { - oldestFlareTimeLeft = Main.projectile[i].timeLeft; - oldestFlare = Main.projectile[i].whoAmI; + oldestFlareTimeLeft = p.timeLeft; + oldestFlare = p.whoAmI; } if (flaresFound >= maxFlares) break; diff --git a/Projectiles/Rogue/GildedDaggerProj.cs b/Projectiles/Rogue/GildedDaggerProj.cs index 19b51fd850..5d1d4d48f2 100644 --- a/Projectiles/Rogue/GildedDaggerProj.cs +++ b/Projectiles/Rogue/GildedDaggerProj.cs @@ -70,21 +70,20 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { bool hasHitNPC = false; for (int j = 0; j < previousNPCs.Count; j++) { - if (previousNPCs[j] == i) + if (previousNPCs[j] == npc.whoAmI) { hasHitNPC = true; } } - NPC npc = Main.npc[i]; if (npc == target) { - previousNPCs.Add(i); + previousNPCs.Add(npc.whoAmI); } if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC) { @@ -92,7 +91,7 @@ namespace CalamityMod.Projectiles.Rogue if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/GleamingDaggerProj.cs b/Projectiles/Rogue/GleamingDaggerProj.cs index 14913d4f07..99c742ee71 100644 --- a/Projectiles/Rogue/GleamingDaggerProj.cs +++ b/Projectiles/Rogue/GleamingDaggerProj.cs @@ -70,21 +70,20 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { bool hasHitNPC = false; for (int j = 0; j < previousNPCs.Count; j++) { - if (previousNPCs[j] == i) + if (previousNPCs[j] == npc.whoAmI) { hasHitNPC = true; } } - NPC npc = Main.npc[i]; if (npc == target) { - previousNPCs.Add(i); + previousNPCs.Add(npc.whoAmI); } if (npc.CanBeChasedBy(Projectile, false) && npc != target && !hasHitNPC) { @@ -92,7 +91,7 @@ namespace CalamityMod.Projectiles.Rogue if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/IcebreakerHammer.cs b/Projectiles/Rogue/IcebreakerHammer.cs index ff7f603d8d..4ae1e85156 100644 --- a/Projectiles/Rogue/IcebreakerHammer.cs +++ b/Projectiles/Rogue/IcebreakerHammer.cs @@ -64,10 +64,9 @@ namespace CalamityMod.Projectiles.Rogue int buffType = ModContent.BuffType(); float radius = 112f; // 7 blocks - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC in Main.ActiveNPCs) { - NPC nPC = Main.npc[i]; - if (nPC.active && !nPC.dontTakeDamage && !nPC.buffImmune[buffType] && Vector2.Distance(Projectile.Center, nPC.Center) <= radius) + if (!nPC.dontTakeDamage && !nPC.buffImmune[buffType] && Vector2.Distance(Projectile.Center, nPC.Center) <= radius) { if (nPC.FindBuffIndex(buffType) == -1) nPC.AddBuff(buffType, 60, false); @@ -93,10 +92,9 @@ namespace CalamityMod.Projectiles.Rogue int buffType = ModContent.BuffType(); float radius = 112f; // 7 blocks - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player player in Main.ActivePlayers) { Player owner = Main.player[Projectile.owner]; - Player player = Main.player[i]; if ((owner.team != player.team || player.team == 0) && player.hostile && owner.hostile && !player.dead && !player.buffImmune[buffType] && Vector2.Distance(Projectile.Center, player.Center) <= radius) { if (player.FindBuffIndex(buffType) == -1) diff --git a/Projectiles/Rogue/MalachiteStealth.cs b/Projectiles/Rogue/MalachiteStealth.cs index 2f6451498f..77206f17f0 100644 --- a/Projectiles/Rogue/MalachiteStealth.cs +++ b/Projectiles/Rogue/MalachiteStealth.cs @@ -127,15 +127,15 @@ namespace CalamityMod.Projectiles.Rogue int kunaiFound = 0; int oldestKunai = -1; int oldestKunaiTimeLeft = lifeSpan; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == Projectile.type && i != Projectile.whoAmI && Main.projectile[i].ai[1] == target.whoAmI) + if (p.owner == Main.myPlayer && p.type == Projectile.type && p.whoAmI != Projectile.whoAmI && p.ai[1] == target.whoAmI) { kunaiFound++; - if (Main.projectile[i].timeLeft < oldestKunaiTimeLeft) + if (p.timeLeft < oldestKunaiTimeLeft) { - oldestKunaiTimeLeft = Main.projectile[i].timeLeft; - oldestKunai = Main.projectile[i].whoAmI; + oldestKunaiTimeLeft = p.timeLeft; + oldestKunai = p.whoAmI; } if (kunaiFound >= maxKunai) break; diff --git a/Projectiles/Rogue/MeteorFistStealth.cs b/Projectiles/Rogue/MeteorFistStealth.cs index d7e386cc7f..d08caeb9a1 100644 --- a/Projectiles/Rogue/MeteorFistStealth.cs +++ b/Projectiles/Rogue/MeteorFistStealth.cs @@ -157,16 +157,15 @@ namespace CalamityMod.Projectiles.Rogue // Get the closest enemy to the fist if (Projectile.penetrate != -1) { - for (int i = 0; i < Main.npc.Length; i++) + foreach (var npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false) && npc != target) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/NanoblackSplit.cs b/Projectiles/Rogue/NanoblackSplit.cs index 03d77819c7..6fb8f943a6 100644 --- a/Projectiles/Rogue/NanoblackSplit.cs +++ b/Projectiles/Rogue/NanoblackSplit.cs @@ -128,10 +128,9 @@ namespace CalamityMod.Projectiles.Rogue bool bossFound = false; int target = -1; float minDist = HomingStartRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.type == NPCID.TargetDummy) + if (npc.type == NPCID.TargetDummy) continue; // If we've found a valid boss target, ignore ALL targets which aren't bosses. @@ -149,7 +148,7 @@ namespace CalamityMod.Projectiles.Rogue if (npc.boss) bossFound = true; minDist = distToNPC; - target = i; + target = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/NanoblackStealthSplit.cs b/Projectiles/Rogue/NanoblackStealthSplit.cs index a9dc579fb6..b91da360f6 100644 --- a/Projectiles/Rogue/NanoblackStealthSplit.cs +++ b/Projectiles/Rogue/NanoblackStealthSplit.cs @@ -137,10 +137,9 @@ namespace CalamityMod.Projectiles.Rogue bool bossFound = false; int target = -1; float minDist = HomingStartRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.type == NPCID.TargetDummy) + if (npc.type == NPCID.TargetDummy) continue; // If we've found a valid boss target, ignore ALL targets which aren't bosses. @@ -158,7 +157,7 @@ namespace CalamityMod.Projectiles.Rogue if (npc.boss) bossFound = true; minDist = distToNPC; - target = i; + target = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/NightsGazeStar.cs b/Projectiles/Rogue/NightsGazeStar.cs index bcf4b231a2..fad89f3222 100644 --- a/Projectiles/Rogue/NightsGazeStar.cs +++ b/Projectiles/Rogue/NightsGazeStar.cs @@ -65,16 +65,15 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/NychthemeronOrb.cs b/Projectiles/Rogue/NychthemeronOrb.cs index 9a16edbac9..2c2a439121 100644 --- a/Projectiles/Rogue/NychthemeronOrb.cs +++ b/Projectiles/Rogue/NychthemeronOrb.cs @@ -30,10 +30,9 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { bool isActive = false; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.identity == Projectile.ai[1] && p.active) + if (p.identity == Projectile.ai[1]) { isActive = true; } @@ -64,16 +63,15 @@ namespace CalamityMod.Projectiles.Rogue // Follow Enemy float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/RadiantExplosion.cs b/Projectiles/Rogue/RadiantExplosion.cs index ed8f447e7d..9c6a87fafe 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/RadiantStar2.cs b/Projectiles/Rogue/RadiantStar2.cs index 44e60111e5..2fc8e04e0a 100644 --- a/Projectiles/Rogue/RadiantStar2.cs +++ b/Projectiles/Rogue/RadiantStar2.cs @@ -41,30 +41,30 @@ namespace CalamityMod.Projectiles.Rogue float projY = Projectile.Center.Y; float homeRange = Projectile.Calamity().stealthStrike ? 1800f : 600f; float homingSpeed = 0.25f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].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[i].position.X + (float)(Main.npc[i].width / 2); - float npcCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].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 < homeRange) { - if (Main.npc[i].position.X < projX) + if (n.position.X < projX) { - Main.npc[i].velocity.X += homingSpeed; + n.velocity.X += homingSpeed; } else { - Main.npc[i].velocity.X -= homingSpeed; + n.velocity.X -= homingSpeed; } - if (Main.npc[i].position.Y < projY) + if (n.position.Y < projY) { - Main.npc[i].velocity.Y += homingSpeed; + n.velocity.Y += homingSpeed; } else { - Main.npc[i].velocity.Y -= homingSpeed; + n.velocity.Y -= homingSpeed; } } } diff --git a/Projectiles/Rogue/RadiantStarKnife.cs b/Projectiles/Rogue/RadiantStarKnife.cs index 1c9a51d6d7..fa3d6ca7ff 100644 --- a/Projectiles/Rogue/RadiantStarKnife.cs +++ b/Projectiles/Rogue/RadiantStarKnife.cs @@ -41,9 +41,8 @@ namespace CalamityMod.Projectiles.Rogue float projY = Projectile.Center.Y; float homeRange = Projectile.Calamity().stealthStrike ? 1800f : 600f; float homingSpeed = 0.25f; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1) && !npc.boss) { float npcX = npc.position.X + (float)(npc.width / 2); diff --git a/Projectiles/Rogue/RealityRuptureMini.cs b/Projectiles/Rogue/RealityRuptureMini.cs index 9a5a53d134..aa16a31513 100644 --- a/Projectiles/Rogue/RealityRuptureMini.cs +++ b/Projectiles/Rogue/RealityRuptureMini.cs @@ -53,16 +53,16 @@ namespace CalamityMod.Projectiles.Rogue float maxDistance = 350f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); - bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1); + float extraDistance = (float)(n.width / 2) + (float)(n.height / 2); + bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && canHit) + if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && canHit) { - center = Main.npc[i].Center; + center = n.Center; homeIn = true; break; } diff --git a/Projectiles/Rogue/ReaperProjectile.cs b/Projectiles/Rogue/ReaperProjectile.cs index fd8bfe5e4e..b1f15611b0 100644 --- a/Projectiles/Rogue/ReaperProjectile.cs +++ b/Projectiles/Rogue/ReaperProjectile.cs @@ -87,10 +87,9 @@ namespace CalamityMod.Projectiles.Rogue Vector2 homingTarget = Projectile.Center; bool foundTarget = false; Vector2 targetVelocity = new Vector2(0f); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC potentialTarget in Main.ActiveNPCs) { - NPC potentialTarget = Main.npc[i]; - if (potentialTarget.CanBeChasedBy(Projectile, false) && Projectile.WithinRange(Main.npc[i].Center, homingRange)) + if (potentialTarget.CanBeChasedBy(Projectile, false) && Projectile.WithinRange(potentialTarget.Center, homingRange)) { if (!foundTarget) { diff --git a/Projectiles/Rogue/RegulusEnergy.cs b/Projectiles/Rogue/RegulusEnergy.cs index e7a56a394b..cac9b64289 100644 --- a/Projectiles/Rogue/RegulusEnergy.cs +++ b/Projectiles/Rogue/RegulusEnergy.cs @@ -54,15 +54,15 @@ namespace CalamityMod.Projectiles.Rogue float maxDistance = 500f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); + float extraDistance = (float)(n.width / 2) + (float)(n.height / 2); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1)) + if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1)) { - center = Main.npc[i].Center; + center = n.Center; homeIn = true; break; } diff --git a/Projectiles/Rogue/SamsaraSlicerProjectile.cs b/Projectiles/Rogue/SamsaraSlicerProjectile.cs index e0bfbd6a17..e0c48554f8 100644 --- a/Projectiles/Rogue/SamsaraSlicerProjectile.cs +++ b/Projectiles/Rogue/SamsaraSlicerProjectile.cs @@ -143,9 +143,8 @@ namespace CalamityMod.Projectiles.Rogue const float maxDistance = 300f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float extraDistance = npc.width / 2 + npc.height / 2; diff --git a/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs b/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs index 220b381b0d..9d0c40de2b 100644 --- a/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs +++ b/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs @@ -47,10 +47,9 @@ namespace CalamityMod.Projectiles.Rogue Projectile parent = Main.projectile[0]; bool active = false; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.identity == Projectile.ai[0] && p.active && p.type == ModContent.ProjectileType()) + if (p.identity == Projectile.ai[0] && p.type == ModContent.ProjectileType()) { parent = p; active = true; diff --git a/Projectiles/Rogue/ScourgeoftheDesertProj.cs b/Projectiles/Rogue/ScourgeoftheDesertProj.cs index 186ae20d14..1a6297b614 100644 --- a/Projectiles/Rogue/ScourgeoftheDesertProj.cs +++ b/Projectiles/Rogue/ScourgeoftheDesertProj.cs @@ -101,10 +101,10 @@ namespace CalamityMod.Projectiles.Rogue } if (InsideTiles) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile.GetSource_FromThis(), false)) - NPCDestination = Main.npc[i].Center + Main.npc[i].velocity * 5f; + if (n.CanBeChasedBy(Projectile.GetSource_FromThis(), false)) + NPCDestination = n.Center + n.velocity * 5f; } TimeUnderground++; diff --git a/Projectiles/Rogue/SearedPanProjectile.cs b/Projectiles/Rogue/SearedPanProjectile.cs index 174bc44bc7..a7022fce06 100644 --- a/Projectiles/Rogue/SearedPanProjectile.cs +++ b/Projectiles/Rogue/SearedPanProjectile.cs @@ -129,18 +129,18 @@ namespace CalamityMod.Projectiles.Rogue { if (Projectile.owner == Main.myPlayer) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (!Main.projectile[i].active || Main.projectile[i].owner != Projectile.owner) + if (p.owner != Projectile.owner) continue; - if (Main.projectile[i].ModProjectile is NiceCock) + if (p.ModProjectile is NiceCock) { if (!activate) - Main.projectile[i].Kill(); + p.Kill(); else { - Main.projectile[i].ModProjectile().homing = true; - Main.projectile[i].extraUpdates += 2; + p.ModProjectile().homing = true; + p.extraUpdates += 2; } } } @@ -151,14 +151,14 @@ namespace CalamityMod.Projectiles.Rogue { int fireballCount = 0; // Count how many fireballs exist already around the given target - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { // Keep the loop as short as possible - if (!Main.projectile[i].active || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].CountsAsClass() || targetIndex != (int)Main.projectile[i].ai[1]) + if (p.owner != Projectile.owner || !p.CountsAsClass() || targetIndex != (int)p.ai[1]) continue; - if (Main.projectile[i].ModProjectile is NiceCock) + if (p.ModProjectile is NiceCock) { - if (Main.projectile[i].ModProjectile().homing) + if (p.ModProjectile().homing) continue; fireballCount++; } @@ -166,16 +166,16 @@ namespace CalamityMod.Projectiles.Rogue // Adjust the angle of the existing fireballs around a target float angleVariance = MathHelper.TwoPi / fireballCount; float angle = 0f; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (!Main.projectile[i].active || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].CountsAsClass() || targetIndex != (int)Main.projectile[i].ai[1]) + if (p.owner != Projectile.owner || !p.CountsAsClass() || targetIndex != (int)p.ai[1]) continue; - if (Main.projectile[i].ModProjectile is NiceCock) + if (p.ModProjectile is NiceCock) { - if (Main.projectile[i].ModProjectile().homing) + if (p.ModProjectile().homing) continue; - Main.projectile[i].ai[0] = angle; - Main.projectile[i].netUpdate = true; + p.ai[0] = angle; + p.netUpdate = true; angle += angleVariance; } } diff --git a/Projectiles/Rogue/ShatteredSunKnife.cs b/Projectiles/Rogue/ShatteredSunKnife.cs index 1c6ecfe6de..9a6017b8d5 100644 --- a/Projectiles/Rogue/ShatteredSunKnife.cs +++ b/Projectiles/Rogue/ShatteredSunKnife.cs @@ -90,30 +90,30 @@ namespace CalamityMod.Projectiles.Rogue { float projX = Projectile.Center.X; float projY = Projectile.Center.Y; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].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[i].position.X + (float)(Main.npc[i].width / 2); - float npcCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].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[i].position.X < projX) + if (n.position.X < projX) { - Main.npc[i].velocity.X += 0.25f; + n.velocity.X += 0.25f; } else { - Main.npc[i].velocity.X -= 0.25f; + n.velocity.X -= 0.25f; } - if (Main.npc[i].position.Y < projY) + if (n.position.Y < projY) { - Main.npc[i].velocity.Y += 0.25f; + n.velocity.Y += 0.25f; } else { - Main.npc[i].velocity.Y -= 0.25f; + n.velocity.Y -= 0.25f; } } } diff --git a/Projectiles/Rogue/ShatteredSunScorchedBlade.cs b/Projectiles/Rogue/ShatteredSunScorchedBlade.cs index de1bbed1c3..ce556d1071 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); @@ -112,30 +111,30 @@ namespace CalamityMod.Projectiles.Rogue { float projX = Projectile.Center.X; float projY = Projectile.Center.Y; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].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[i].position.X + (float)(Main.npc[i].width / 2); - float npcCenterY = Main.npc[i].position.Y + (float)(Main.npc[i].height / 2); + float npcCenterX = n.position.X + (float)(n.width / 2); + float npcCenterY = n.position.Y + (float)(n.height / 2); float targetDistance = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - npcCenterX) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - npcCenterY); if (targetDistance < 600f) { - if (Main.npc[i].position.X < projX) + if (n.position.X < projX) { - Main.npc[i].velocity.X += 0.25f; + n.velocity.X += 0.25f; } else { - Main.npc[i].velocity.X -= 0.25f; + n.velocity.X -= 0.25f; } - if (Main.npc[i].position.Y < projY) + if (n.position.Y < projY) { - Main.npc[i].velocity.Y += 0.25f; + n.velocity.Y += 0.25f; } else { - Main.npc[i].velocity.Y -= 0.25f; + n.velocity.Y -= 0.25f; } } } diff --git a/Projectiles/Rogue/ShockGrenadeBolt.cs b/Projectiles/Rogue/ShockGrenadeBolt.cs index e9b685a881..3d647376a3 100644 --- a/Projectiles/Rogue/ShockGrenadeBolt.cs +++ b/Projectiles/Rogue/ShockGrenadeBolt.cs @@ -56,16 +56,15 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Rogue/SlickCaneProjectile.cs b/Projectiles/Rogue/SlickCaneProjectile.cs index 4c1acff6de..5e325c56e6 100644 --- a/Projectiles/Rogue/SlickCaneProjectile.cs +++ b/Projectiles/Rogue/SlickCaneProjectile.cs @@ -1,9 +1,13 @@ using System; +using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.Audio; +using Terraria.GameContent; +using Terraria.GameContent.ItemDropRules; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; @@ -21,7 +25,7 @@ namespace CalamityMod.Projectiles.Rogue Projectile.width = 42; Projectile.height = 36; Projectile.DamageType = RogueDamageClass.Instance; - Projectile.timeLeft = 90; + Projectile.timeLeft = 120; Projectile.friendly = true; Projectile.hostile = false; Projectile.tileCollide = false; @@ -32,6 +36,7 @@ namespace CalamityMod.Projectiles.Rogue Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 2; Projectile.alpha = 180; + Projectile.scale = 1.25f; } public override SpearType SpearAiType => SpearType.GhastlyGlaiveSpear; public override float TravelSpeed => 8f; @@ -80,11 +85,13 @@ namespace CalamityMod.Projectiles.Rogue float moneyValueToDrop = target.value / Main.rand.NextFloat(15f, 35f); // Maximum of 50 silver, not counting steath strikes moneyValueToDrop = (int)MathHelper.Clamp(moneyValueToDrop, 0, 5000f); - if (Projectile.Calamity().stealthStrike && Main.rand.NextBool(15)) + if (Projectile.Calamity().stealthStrike && Main.rand.NextBool(20)) { moneyValueToDrop += Item.buyPrice(0, Main.rand.Next(1, 4), Main.rand.Next(0, 100), Main.rand.Next(0, 100)); + SoundEngine.PlaySound(TheSevensStriker.TriplesSound, Projectile.Center); } - + else if (moneyValueToDrop > 0f) + SoundEngine.PlaySound(TheSevensStriker.DoublesSound, Projectile.Center); while (moneyValueToDrop > 10000f) { int modifiedMoneyValue = (int)(moneyValueToDrop / 10000f); @@ -133,5 +140,29 @@ namespace CalamityMod.Projectiles.Rogue } } } + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + // Boost dmg in proportion to money, caps at 2 plat + if (Projectile.Calamity().stealthStrike) + { + Player player = Main.player[Projectile.owner]; + double money = Utils.CoinsCount(out bool overflow, player.inventory); + if (money >= 2000000) + money = 2000000; + if (money != 0) + { + modifiers.SourceDamage *= (float)(money / 500000 + 1); + SoundEngine.PlaySound(TheSevensStriker.JackpotSound, Projectile.Center); + for (int j = 0; j < 8; j++) + { + int dust2 = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.GoldCoin, 0f, 0f, 100, default, 3f); + Main.dust[dust2].noGravity = true; + Main.dust[dust2].velocity *= 5f; + dust2 = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.GoldCoin, 0f, 0f, 100, default, 2f); + Main.dust[dust2].velocity *= 2f; + } + } + } + } } } diff --git a/Projectiles/Rogue/SpearofDestinyProjectile.cs b/Projectiles/Rogue/SpearofDestinyProjectile.cs index 27f75dbf83..cbec922070 100644 --- a/Projectiles/Rogue/SpearofDestinyProjectile.cs +++ b/Projectiles/Rogue/SpearofDestinyProjectile.cs @@ -63,16 +63,16 @@ namespace CalamityMod.Projectiles.Rogue float maxDistance = 200f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); - bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1); + float extraDistance = (float)(n.width / 2) + (float)(n.height / 2); + bool canHit = Projectile.Calamity().stealthStrike || Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && canHit) + if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && canHit) { - center = Main.npc[i].Center; + center = n.Center; homeIn = true; break; } diff --git a/Projectiles/Rogue/StellarKnifeProj.cs b/Projectiles/Rogue/StellarKnifeProj.cs index 62c1b8abf3..1b90218b98 100644 --- a/Projectiles/Rogue/StellarKnifeProj.cs +++ b/Projectiles/Rogue/StellarKnifeProj.cs @@ -69,15 +69,15 @@ namespace CalamityMod.Projectiles.Rogue float maxDistance = 600f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1)) + if (n.CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, n.Center, 1, 1)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); + float extraDistance = (float)(n.width / 2) + (float)(n.height / 2); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance)) + if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance)) { - center = Main.npc[i].Center; + center = n.Center; homeIn = true; break; } diff --git a/Projectiles/Rogue/TimeBoltKnife.cs b/Projectiles/Rogue/TimeBoltKnife.cs index e60f1d8767..0372da7e39 100644 --- a/Projectiles/Rogue/TimeBoltKnife.cs +++ b/Projectiles/Rogue/TimeBoltKnife.cs @@ -132,9 +132,8 @@ namespace CalamityMod.Projectiles.Rogue int whoAmI = -1; Vector2 targetSpot = Projectile.Center; float detectRange = 1000f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(npc.Center, Projectile.Center); @@ -142,7 +141,7 @@ namespace CalamityMod.Projectiles.Rogue { detectRange = targetDist; targetSpot = npc.Center; - whoAmI = i; + whoAmI = npc.whoAmI; } } } @@ -304,10 +303,9 @@ namespace CalamityMod.Projectiles.Rogue int buffType = ModContent.BuffType(); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc.active && !npc.dontTakeDamage && !npc.buffImmune[buffType] && Vector2.Distance(Projectile.Center, npc.Center) <= radius) + if (!npc.dontTakeDamage && !npc.buffImmune[buffType] && Vector2.Distance(Projectile.Center, npc.Center) <= radius) { if (npc.FindBuffIndex(buffType) == -1) npc.AddBuff(buffType, 60, false); diff --git a/Projectiles/Rogue/VeneratedKnife.cs b/Projectiles/Rogue/VeneratedKnife.cs index 93830c3b28..960c4eb363 100644 --- a/Projectiles/Rogue/VeneratedKnife.cs +++ b/Projectiles/Rogue/VeneratedKnife.cs @@ -37,16 +37,15 @@ namespace CalamityMod.Projectiles.Rogue { float minDist = 999f; int index = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < minDist) { minDist = dist; - index = i; + index = npc.whoAmI; } } } diff --git a/Projectiles/Summon/ApexShark.cs b/Projectiles/Summon/ApexShark.cs index 7bba64724b..58ba156d6c 100644 --- a/Projectiles/Summon/ApexShark.cs +++ b/Projectiles/Summon/ApexShark.cs @@ -126,9 +126,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[i]; if (nPC2.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Projectiles/Summon/AquasScepterCloud.cs b/Projectiles/Summon/AquasScepterCloud.cs index 1d8af26757..37e01d580f 100644 --- a/Projectiles/Summon/AquasScepterCloud.cs +++ b/Projectiles/Summon/AquasScepterCloud.cs @@ -57,10 +57,8 @@ namespace CalamityMod.Projectiles.Summon } - for (int i = 0; i < Main.maxNPCs; i++) + foreach (var npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc.CanBeChasedBy()) { float between = Vector2.Distance(npc.Center, Projectile.Center); diff --git a/Projectiles/Summon/AstrageldonSummon.cs b/Projectiles/Summon/AstrageldonSummon.cs index 675c375416..4d1f353634 100644 --- a/Projectiles/Summon/AstrageldonSummon.cs +++ b/Projectiles/Summon/AstrageldonSummon.cs @@ -123,9 +123,8 @@ namespace CalamityMod.Projectiles.Summon } else { - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { bool lineOfSight = Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height); diff --git a/Projectiles/Summon/AtlasMunitionsAutocannon.cs b/Projectiles/Summon/AtlasMunitionsAutocannon.cs index d01046351f..5161f2b0b5 100644 --- a/Projectiles/Summon/AtlasMunitionsAutocannon.cs +++ b/Projectiles/Summon/AtlasMunitionsAutocannon.cs @@ -200,20 +200,20 @@ namespace CalamityMod.Projectiles.Summon if (!CannonIsMounted) { int detachedCannonID = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != detachedCannonID || !Main.projectile[i].active || Main.projectile[i].owner != Projectile.owner) + if (p.type != detachedCannonID || p.owner != Projectile.owner) continue; - if (!Main.projectile[i].Hitbox.Intersects(Projectile.Hitbox)) + if (!p.Hitbox.Intersects(Projectile.Hitbox)) continue; - if (Main.projectile[i].ModProjectile().BeingHeld) + if (p.ModProjectile().BeingHeld) continue; - Main.projectile[i].Kill(); + p.Kill(); CannonIsMounted = true; - HeatInterpolant = Main.projectile[i].ModProjectile().HeatInterpolant; + HeatInterpolant = p.ModProjectile().HeatInterpolant; Projectile.netUpdate = true; break; } @@ -222,11 +222,13 @@ namespace CalamityMod.Projectiles.Summon // If a cannon is not mounted, die if the owner goes very, very far away. else if (!Projectile.WithinRange(Owner.Center, 7200f)) { - for (int i = 0; i < Main.maxProjectiles; i++) + int podID = ModContent.ProjectileType(); + int podUpperID = ModContent.ProjectileType(); + foreach (Projectile p in Main.ActiveProjectiles) { - bool validID = Main.projectile[i].type == ModContent.ProjectileType(); - if (Main.projectile[i].active && validID && Main.projectile[i].owner == Projectile.owner) - Main.projectile[i].Kill(); + bool validID = p.type == podID || p.type == podUpperID; + if (validID && p.owner == Projectile.owner) + p.Kill(); } Projectile.Kill(); diff --git a/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs b/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs index 64a475442a..be7518fde5 100644 --- a/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs +++ b/Projectiles/Summon/AtlasMunitionsAutocannonHeld.cs @@ -171,11 +171,11 @@ namespace CalamityMod.Projectiles.Summon int podID = ModContent.ProjectileType(); int podUpperID = ModContent.ProjectileType(); int cannonID = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - bool validID = Main.projectile[i].type == podID || Main.projectile[i].type == podUpperID || Main.projectile[i].type == cannonID; - if (Main.projectile[i].active && validID && Main.projectile[i].owner == Projectile.owner) - Main.projectile[i].Kill(); + bool validID = p.type == podID || p.type == podUpperID || p.type == cannonID; + if (validID && p.owner == Projectile.owner) + p.Kill(); } Projectile.Kill(); diff --git a/Projectiles/Summon/BabyBloodCrawler.cs b/Projectiles/Summon/BabyBloodCrawler.cs index 9ea82a99b5..3bd8c32128 100644 --- a/Projectiles/Summon/BabyBloodCrawler.cs +++ b/Projectiles/Summon/BabyBloodCrawler.cs @@ -53,11 +53,10 @@ namespace CalamityMod.Projectiles.Summon Player player = Main.player[Projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); - for (int j = 0; j < Main.maxProjectiles; j++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[j]; // Short circuits to make the loop as fast as possible - if (!proj.active || proj.owner != Projectile.owner || !proj.minion || proj.Calamity().lineColor != 1) + if (proj.owner != Projectile.owner || !proj.minion || proj.Calamity().lineColor != 1) continue; if (proj.type == Projectile.type) { diff --git a/Projectiles/Summon/BabyPlaguebringer.cs b/Projectiles/Summon/BabyPlaguebringer.cs index 62cd29c934..862928f071 100644 --- a/Projectiles/Summon/BabyPlaguebringer.cs +++ b/Projectiles/Summon/BabyPlaguebringer.cs @@ -100,9 +100,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[i]; if (nPC2.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Projectiles/Summon/BlackDragonBody.cs b/Projectiles/Summon/BlackDragonBody.cs index 9b945dff76..27168209bd 100644 --- a/Projectiles/Summon/BlackDragonBody.cs +++ b/Projectiles/Summon/BlackDragonBody.cs @@ -63,10 +63,9 @@ namespace CalamityMod.Projectiles.Summon var live = false; Projectile nextSegment = new Projectile(); BlackDragonHead head = new BlackDragonHead(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == Type && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == Type && projectile.owner == Projectile.owner) { if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) { @@ -74,7 +73,7 @@ namespace CalamityMod.Projectiles.Summon nextSegment = projectile; } } - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { if (segmentIndex == 1) { @@ -108,10 +107,9 @@ namespace CalamityMod.Projectiles.Summon { if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { projectile.Kill(); } diff --git a/Projectiles/Summon/BlackDragonTail.cs b/Projectiles/Summon/BlackDragonTail.cs index 9cdd238f9f..0b9be2eff1 100644 --- a/Projectiles/Summon/BlackDragonTail.cs +++ b/Projectiles/Summon/BlackDragonTail.cs @@ -50,10 +50,9 @@ namespace CalamityMod.Projectiles.Summon Projectile nextSegment = new Projectile(); BlackDragonHead head = new BlackDragonHead(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) { @@ -61,7 +60,7 @@ namespace CalamityMod.Projectiles.Summon nextSegment = projectile; } } - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { if (segmentIndex == 1) { @@ -96,10 +95,9 @@ namespace CalamityMod.Projectiles.Summon { if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { projectile.Kill(); } diff --git a/Projectiles/Summon/BrimstoneElementalMinion.cs b/Projectiles/Summon/BrimstoneElementalMinion.cs index 7d4a7de5dc..7abda0562d 100644 --- a/Projectiles/Summon/BrimstoneElementalMinion.cs +++ b/Projectiles/Summon/BrimstoneElementalMinion.cs @@ -117,9 +117,8 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack && !passive) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[i]; if (nPC2.CanBeChasedBy(Projectile, false)) { float targetDist = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Projectiles/Summon/CnidarianJellyfishOnTheString.cs b/Projectiles/Summon/CnidarianJellyfishOnTheString.cs index 04d14b3cc5..45e342e5a3 100644 --- a/Projectiles/Summon/CnidarianJellyfishOnTheString.cs +++ b/Projectiles/Summon/CnidarianJellyfishOnTheString.cs @@ -13,6 +13,7 @@ using Terraria.ID; using Terraria.ModLoader; using static CalamityMod.CalamityUtils; using static Terraria.ModLoader.ModContent; +using CalamityMod.Graphics.Primitives; namespace CalamityMod.Projectiles.Summon { @@ -143,16 +144,16 @@ namespace CalamityMod.Projectiles.Summon int[] targetArray = new int[maxTargets]; int targetsAquired = 0; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { if (targetsAquired == maxTargets) break; - if (Main.npc[i].CanBeChasedBy(Projectile)) + if (n.CanBeChasedBy(Projectile)) { - if ((CnidarianPos - Main.npc[i].Center).Length() < targettingDistance) + if ((CnidarianPos - n.Center).Length() < targettingDistance) { - targetArray[targetsAquired] = i; + targetArray[targetsAquired] = n.whoAmI; targetsAquired++; } } diff --git a/Projectiles/Summon/CosmicEnergySpiral.cs b/Projectiles/Summon/CosmicEnergySpiral.cs index d7e0585150..a57cf8ad25 100644 --- a/Projectiles/Summon/CosmicEnergySpiral.cs +++ b/Projectiles/Summon/CosmicEnergySpiral.cs @@ -76,9 +76,8 @@ namespace CalamityMod.Projectiles.Summon } else { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[i]; if (nPC2.CanBeChasedBy(Projectile, false)) { float maxTargetDist = Vector2.Distance(nPC2.Center, Projectile.Center); @@ -87,7 +86,7 @@ namespace CalamityMod.Projectiles.Summon targetDist = maxTargetDist; projPos = nPC2.Center; canAttack = true; - target = i; + target = nPC2.whoAmI; } } } @@ -180,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/CosmicViperHomingRocket.cs b/Projectiles/Summon/CosmicViperHomingRocket.cs index 9f0cb319ed..c5efb9e256 100644 --- a/Projectiles/Summon/CosmicViperHomingRocket.cs +++ b/Projectiles/Summon/CosmicViperHomingRocket.cs @@ -86,15 +86,15 @@ namespace CalamityMod.Projectiles.Summon } if (!homeIn) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); + float extraDistance = (float)(n.width / 2) + (float)(n.height / 2); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance)) + if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance)) { - center = Main.npc[i].Center; + center = n.Center; homeIn = true; break; } diff --git a/Projectiles/Summon/DaedalusCrystal.cs b/Projectiles/Summon/DaedalusCrystal.cs index 68aeab7cef..590cf7215a 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 2eca566982..d18311e5fc 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/DormantBrimseekerAura.cs b/Projectiles/Summon/DormantBrimseekerAura.cs index 95d4cff152..e92f6098c6 100644 --- a/Projectiles/Summon/DormantBrimseekerAura.cs +++ b/Projectiles/Summon/DormantBrimseekerAura.cs @@ -71,20 +71,20 @@ namespace CalamityMod.Projectiles.Summon if (Main.rand.NextBool(360)) dust.scale = 1.5f; } - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && - Main.projectile[i].owner == Projectile.owner && Main.projectile[i].localAI[1] == 0f) + if (p.type == ModContent.ProjectileType() && + p.owner == Projectile.owner && p.localAI[1] == 0f) { - if (Main.projectile[i].Distance(Projectile.Center) < Projectile.localAI[1]) + if (p.Distance(Projectile.Center) < Projectile.localAI[1]) { for (int j = 0; j < 30; j++) { - Dust dust = Dust.NewDustPerfect(Main.projectile[i].Center, (int)CalamityDusts.Brimstone); + Dust dust = Dust.NewDustPerfect(p.Center, (int)CalamityDusts.Brimstone); dust.velocity = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * 7f; } - Main.projectile[i].localAI[1] = 1f; - SoundEngine.PlaySound(SoundID.Item45, Main.projectile[i].Center); + p.localAI[1] = 1f; + SoundEngine.PlaySound(SoundID.Item45, p.Center); } } } @@ -99,18 +99,18 @@ namespace CalamityMod.Projectiles.Summon } public override void OnKill(int timeLeft) { - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && - Main.projectile[i].owner == Projectile.owner && Main.projectile[i].localAI[1] == 1f) + if (p.type == ModContent.ProjectileType() && + p.owner == Projectile.owner && p.localAI[1] == 1f) { for (int j = 0; j < 30; j++) { Dust dust = Dust.NewDustPerfect(Projectile.Center, (int)CalamityDusts.Brimstone); dust.velocity = Vector2.One.RotatedByRandom(MathHelper.TwoPi) * 7f; } - SoundEngine.PlaySound(SoundID.Item29, Main.projectile[i].Center); - Main.projectile[i].localAI[1] = 0f; + SoundEngine.PlaySound(SoundID.Item29, p.Center); + p.localAI[1] = 0f; } } } diff --git a/Projectiles/Summon/Dreadmine.cs b/Projectiles/Summon/Dreadmine.cs index 3230ecfc43..d352755434 100644 --- a/Projectiles/Summon/Dreadmine.cs +++ b/Projectiles/Summon/Dreadmine.cs @@ -140,17 +140,17 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float npcX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2); - float npcY = Main.npc[i].position.Y + (float)(Main.npc[i].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) { attackDistance = npcDist; - center12 = Main.npc[i].Center; + center12 = n.Center; canAttack = true; } } diff --git a/Projectiles/Summon/DreadmineTurret.cs b/Projectiles/Summon/DreadmineTurret.cs index ea90f19aa5..ee71f068e6 100644 --- a/Projectiles/Summon/DreadmineTurret.cs +++ b/Projectiles/Summon/DreadmineTurret.cs @@ -50,9 +50,9 @@ namespace CalamityMod.Projectiles.Summon if (Main.rand.NextBool(15)) { int mineAmt = 0; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == ModContent.ProjectileType()) + if (p.owner == Main.myPlayer && p.type == ModContent.ProjectileType()) { mineAmt++; } diff --git a/Projectiles/Summon/EndoCooperBody.cs b/Projectiles/Summon/EndoCooperBody.cs index 33109677d6..4013aebaef 100644 --- a/Projectiles/Summon/EndoCooperBody.cs +++ b/Projectiles/Summon/EndoCooperBody.cs @@ -177,9 +177,8 @@ namespace CalamityMod.Projectiles.Summon } if (!gotoenemy) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC nPC2 in Main.ActiveNPCs) { - NPC nPC2 = Main.npc[i]; if (nPC2.CanBeChasedBy(Projectile, false)) { float disttoobjective = Vector2.Distance(nPC2.Center, Projectile.Center); diff --git a/Projectiles/Summon/EndoIceShard.cs b/Projectiles/Summon/EndoIceShard.cs index 90acd42f3a..117e8183ef 100644 --- a/Projectiles/Summon/EndoIceShard.cs +++ b/Projectiles/Summon/EndoIceShard.cs @@ -80,12 +80,8 @@ namespace CalamityMod.Projectiles.Summon } if (!hasHomingTarget) { - for (int i = 0; i < Main.npc.Length; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc == null || !npc.active) - continue; - if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); diff --git a/Projectiles/Summon/ForbiddenCircletEater.cs b/Projectiles/Summon/ForbiddenCircletEater.cs index c7789a909f..23a01694bd 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/GiantIbanRobotOfDoom.cs b/Projectiles/Summon/GiantIbanRobotOfDoom.cs index ddb1374ee2..c79c442c8f 100644 --- a/Projectiles/Summon/GiantIbanRobotOfDoom.cs +++ b/Projectiles/Summon/GiantIbanRobotOfDoom.cs @@ -156,13 +156,12 @@ namespace CalamityMod.Projectiles.Summon // If the player has any existing UIs, kill them all. if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) { - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && - Main.projectile[i].type == ModContent.ProjectileType() && - Main.projectile[i].owner == player.whoAmI) + if (p.type == ModContent.ProjectileType() && + p.owner == player.whoAmI) { - Main.projectile[i].Kill(); + p.Kill(); } } } @@ -289,13 +288,12 @@ namespace CalamityMod.Projectiles.Summon } int slashIndex = -1; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && - Main.projectile[i].type == ModContent.ProjectileType() && - Main.projectile[i].owner == Projectile.owner) + if (p.type == ModContent.ProjectileType() && + p.owner == Projectile.owner) { - slashIndex = i; + slashIndex = p.whoAmI; break; } } @@ -310,13 +308,12 @@ namespace CalamityMod.Projectiles.Summon int laserBeamIndex = -1; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && - Main.projectile[i].type == ModContent.ProjectileType() && - Main.projectile[i].owner == Projectile.owner) + if (p.type == ModContent.ProjectileType() && + p.owner == Projectile.owner) { - laserBeamIndex = i; + laserBeamIndex = p.whoAmI; break; } } diff --git a/Projectiles/Summon/GlacialEmbracePointyThing.cs b/Projectiles/Summon/GlacialEmbracePointyThing.cs index 287b3c2479..a06cefa7f5 100644 --- a/Projectiles/Summon/GlacialEmbracePointyThing.cs +++ b/Projectiles/Summon/GlacialEmbracePointyThing.cs @@ -240,12 +240,12 @@ namespace CalamityMod.Projectiles.Summon { target.AddBuff(BuffID.Frostburn2, 300); int circlers = 0; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Projectile.owner && Main.projectile[i].type == Projectile.type) + if (p.owner == Projectile.owner && p.type == Projectile.type) { - GlacialEmbracePointyThing pointy = (GlacialEmbracePointyThing)Main.projectile[i].ModProjectile; - if (Main.projectile[i].ai[1] > 2f) + GlacialEmbracePointyThing pointy = (GlacialEmbracePointyThing)p.ModProjectile; + if (p.ai[1] > 2f) circlers += Main.rand.Next(1, 4); } } diff --git a/Projectiles/Summon/HermitCrabMinion.cs b/Projectiles/Summon/HermitCrabMinion.cs index 176c6e52b6..924e296129 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 500cdee637..3f2f6adc50 100644 --- a/Projectiles/Summon/Hive.cs +++ b/Projectiles/Summon/Hive.cs @@ -67,9 +67,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); @@ -78,7 +77,7 @@ namespace CalamityMod.Projectiles.Summon attackDist = targetDist; projPos = nPC2.Center; canAttack = true; - target = j; + target = nPC2.whoAmI; } } } diff --git a/Projectiles/Summon/HowlsHeartFireball.cs b/Projectiles/Summon/HowlsHeartFireball.cs index 1d4932627f..d343308b61 100644 --- a/Projectiles/Summon/HowlsHeartFireball.cs +++ b/Projectiles/Summon/HowlsHeartFireball.cs @@ -82,9 +82,8 @@ namespace CalamityMod.Projectiles.Summon } if (!homeIn) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float extraDistance = (npc.width / 2) + (npc.height / 2); diff --git a/Projectiles/Summon/IceSentry.cs b/Projectiles/Summon/IceSentry.cs index 170aa4b52c..e6532ff2ba 100644 --- a/Projectiles/Summon/IceSentry.cs +++ b/Projectiles/Summon/IceSentry.cs @@ -117,16 +117,15 @@ namespace CalamityMod.Projectiles.Summon float maxDistance = 1000f; int possibleTarget = -1; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile)) { float npcDistance = Projectile.Distance(npc.Center); if (npcDistance < maxDistance) { maxDistance = npcDistance; - possibleTarget = i; + possibleTarget = npc.whoAmI; } } } diff --git a/Projectiles/Summon/LanternSoul.cs b/Projectiles/Summon/LanternSoul.cs index f0f4202a2a..98817c5858 100644 --- a/Projectiles/Summon/LanternSoul.cs +++ b/Projectiles/Summon/LanternSoul.cs @@ -53,9 +53,9 @@ namespace CalamityMod.Projectiles.Summon } int flameCount = 0; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Main.myPlayer && Main.projectile[i].type == ModContent.ProjectileType()) + if (p.owner == Main.myPlayer && p.type == ModContent.ProjectileType()) { flameCount++; } diff --git a/Projectiles/Summon/MK2FlaskSummon.cs b/Projectiles/Summon/MK2FlaskSummon.cs index 23f918e7e3..13769a795a 100644 --- a/Projectiles/Summon/MK2FlaskSummon.cs +++ b/Projectiles/Summon/MK2FlaskSummon.cs @@ -51,11 +51,11 @@ namespace CalamityMod.Projectiles.Summon Main.projectile[p].originalDamage = Projectile.originalDamage; int beeArrayIndex = 0; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile pro in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Projectile.owner && Main.projectile[i].type == ModContent.ProjectileType()) + if (pro.owner == Projectile.owner && pro.type == ModContent.ProjectileType()) { - Main.projectile[i].ai[1] = beeArrayIndex; + pro.ai[1] = beeArrayIndex; beeArrayIndex++; } } diff --git a/Projectiles/Summon/MechwormBody.cs b/Projectiles/Summon/MechwormBody.cs index 70e74c2a7e..071383cb99 100644 --- a/Projectiles/Summon/MechwormBody.cs +++ b/Projectiles/Summon/MechwormBody.cs @@ -174,11 +174,11 @@ namespace CalamityMod.Projectiles.Summon public static Projectile LocateHead(Projectile projectile) { int headType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != headType || !Main.projectile[i].active || Main.projectile[i].owner != projectile.owner) + if (p.type != headType || p.owner != projectile.owner) continue; - return Main.projectile[i]; + return p; } return null; } diff --git a/Projectiles/Summon/MechwormHead.cs b/Projectiles/Summon/MechwormHead.cs index 4e7ba8024c..d84c7adc57 100644 --- a/Projectiles/Summon/MechwormHead.cs +++ b/Projectiles/Summon/MechwormHead.cs @@ -338,10 +338,9 @@ namespace CalamityMod.Projectiles.Summon Projectile.Center = TeleportStartingPoint; // Reset the alpha and position across the entire worm for the next charge. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile otherProj in Main.ActiveProjectiles) { - Projectile otherProj = Main.projectile[i]; - if (!otherProj.active || otherProj.owner != Projectile.owner || i == Projectile.whoAmI) + if (otherProj.owner != Projectile.owner || otherProj.whoAmI == Projectile.whoAmI) continue; if (otherProj.type == ModContent.ProjectileType() || otherProj.type == ModContent.ProjectileType()) @@ -377,10 +376,9 @@ namespace CalamityMod.Projectiles.Summon private void CleanUpMechwormPortals() { int portalType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj.type != portalType || !proj.active || proj.owner != Projectile.owner) + if (proj.type != portalType || proj.owner != Projectile.owner) continue; proj.Kill(); diff --git a/Projectiles/Summon/MutatedTruffleMinion.cs b/Projectiles/Summon/MutatedTruffleMinion.cs index 6a4e05edb0..20ca2992a1 100644 --- a/Projectiles/Summon/MutatedTruffleMinion.cs +++ b/Projectiles/Summon/MutatedTruffleMinion.cs @@ -194,10 +194,9 @@ namespace CalamityMod.Projectiles.Summon if (Target is not null) { // Find the vortex that it shot. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj is null || !proj.active || proj.type != ModContent.ProjectileType() || proj.owner != Owner.whoAmI || proj.timeLeft < MutatedTruffle.VortexTimeUntilNextState) + if (proj.type != ModContent.ProjectileType() || proj.owner != Owner.whoAmI || proj.timeLeft < MutatedTruffle.VortexTimeUntilNextState) continue; // Spin around the vortex. diff --git a/Projectiles/Summon/OldDukeSharkVomit.cs b/Projectiles/Summon/OldDukeSharkVomit.cs index 5a3afae25e..be484f33a8 100644 --- a/Projectiles/Summon/OldDukeSharkVomit.cs +++ b/Projectiles/Summon/OldDukeSharkVomit.cs @@ -73,18 +73,14 @@ namespace CalamityMod.Projectiles.Summon } if (!hasHomingTarget) { - for (int i = 0; i < Main.npc.Length; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc is null || !npc.active) - continue; - if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < maxHomingRange && Collision.CanHit(Projectile.Center, Projectile.width, Projectile.height, npc.Center, npc.width, npc.height)) { - targetIdx = i; + targetIdx = npc.whoAmI; maxHomingRange = dist; hasHomingTarget = true; } diff --git a/Projectiles/Summon/PhantomGuy.cs b/Projectiles/Summon/PhantomGuy.cs index 472e64dc8a..fbaf86c064 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 bdb465766b..ffdfa52520 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/PlantationStaffTentacle.cs b/Projectiles/Summon/PlantationStaffTentacle.cs index ee8898e20b..a713ee71f3 100644 --- a/Projectiles/Summon/PlantationStaffTentacle.cs +++ b/Projectiles/Summon/PlantationStaffTentacle.cs @@ -101,11 +101,9 @@ namespace CalamityMod.Projectiles.Summon Projectile.Center = Vector2.Lerp(Projectile.Center, MainMinion.Center + DesiredLocation, interpolant); Projectile.rotation = (Projectile.Center - MainMinion.Center).ToRotation(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - - if (proj is null || !proj.active || proj.owner != Owner.whoAmI || proj.type != ModContent.ProjectileType() || proj.ModProjectile().State == PlantationStaffSummon.AIState.Ramming) + if (proj.owner != Owner.whoAmI || proj.type != ModContent.ProjectileType() || proj.ModProjectile().State == PlantationStaffSummon.AIState.Ramming) continue; State = AIState.Seeking; diff --git a/Projectiles/Summon/ProfanedEnergy.cs b/Projectiles/Summon/ProfanedEnergy.cs index 9dbe380c6a..66da00abc3 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/SakuraBullet.cs b/Projectiles/Summon/SakuraBullet.cs index 485334b7dd..b1d43958f6 100644 --- a/Projectiles/Summon/SakuraBullet.cs +++ b/Projectiles/Summon/SakuraBullet.cs @@ -65,9 +65,8 @@ namespace CalamityMod.Projectiles.Summon } if (!homeIn) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if ((npc.CanBeChasedBy(Projectile, false) || (npc.type == NPCID.DukeFishron && (!npc.dontTakeDamage || npc.ai[0] > 9f))) && npc.active) { float extraDistance = (npc.width / 2) + (npc.height / 2); diff --git a/Projectiles/Summon/SandElementalMinion.cs b/Projectiles/Summon/SandElementalMinion.cs index 073149b87b..c748e8c0da 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/SeekerSummonProj.cs b/Projectiles/Summon/SeekerSummonProj.cs index bb5f4a1e55..99a0bc8d05 100644 --- a/Projectiles/Summon/SeekerSummonProj.cs +++ b/Projectiles/Summon/SeekerSummonProj.cs @@ -100,10 +100,9 @@ namespace CalamityMod.Projectiles.Summon { // Make an imp laugh sound every so often if you're the first seeker in the projectile array. if (Main.rand.NextBool(1600)) - { - for (int i = 0; i < Main.maxProjectiles; i++) + { + foreach (Projectile seeker in Main.ActiveProjectiles) { - Projectile seeker = Main.projectile[i]; if (seeker.type == Projectile.type) { if (seeker == Projectile) diff --git a/Projectiles/Summon/SepulcherMinion.cs b/Projectiles/Summon/SepulcherMinion.cs index 38197aa588..93860c3ce5 100644 --- a/Projectiles/Summon/SepulcherMinion.cs +++ b/Projectiles/Summon/SepulcherMinion.cs @@ -503,16 +503,16 @@ namespace CalamityMod.Projectiles.Summon } float distance = searchDistance * searchDistance; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy() && Main.npc[i].type != heartType) + if (n.CanBeChasedBy() && n.type != heartType) { - float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2); + float extraDistance = (n.width / 2) + (n.height / 2); - if (Main.npc[i].WithinRange(Projectile.Center, distance + extraDistance)) + if (n.WithinRange(Projectile.Center, distance + extraDistance)) { - distance = Main.npc[i].DistanceSQ(Projectile.Center); - closestTarget = Main.npc[i]; + distance = n.DistanceSQ(Projectile.Center); + closestTarget = n; } } } diff --git a/Projectiles/Summon/SilvaCrystal.cs b/Projectiles/Summon/SilvaCrystal.cs index 134940397a..34b378dcc7 100644 --- a/Projectiles/Summon/SilvaCrystal.cs +++ b/Projectiles/Summon/SilvaCrystal.cs @@ -114,20 +114,17 @@ namespace CalamityMod.Projectiles.Summon } if (targetID < 0) { - int targetIDCopy; - for (int i = 0; i < Main.maxNPCs; i = targetIDCopy + 1) + foreach (NPC target in Main.ActiveNPCs) { - NPC target = Main.npc[i]; if (target.CanBeChasedBy(Projectile, false)) { float targetDistance = Projectile.Distance(target.Center); if (targetDistance < attackRange && Collision.CanHitLine(Projectile.Center, 0, 0, target.Center, 0, 0)) { attackRange = targetDistance; - targetID = i; + targetID = target.whoAmI; } } - targetIDCopy = i; } } if (targetID != -1) diff --git a/Projectiles/Summon/SkeletalDragonMother.cs b/Projectiles/Summon/SkeletalDragonMother.cs index 6a33794efb..b8864fe285 100644 --- a/Projectiles/Summon/SkeletalDragonMother.cs +++ b/Projectiles/Summon/SkeletalDragonMother.cs @@ -112,13 +112,13 @@ namespace CalamityMod.Projectiles.Summon if (Projectile.Distance(player.Center) > 3250f) { Projectile.Center = player.Center; - for (int i = 0; i < Main.projectile.Length; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].active && Main.projectile[i].owner == Projectile.owner && - Main.projectile[i].type == ModContent.ProjectileType()) + if (p.owner == Projectile.owner && + p.type == ModContent.ProjectileType()) { - Main.projectile[i].Center = player.Center; - Main.projectile[i].netUpdate = true; + p.Center = player.Center; + p.netUpdate = true; } } Projectile.netUpdate = true; diff --git a/Projectiles/Summon/SmallAresArms/ExoskeletonPanel.cs b/Projectiles/Summon/SmallAresArms/ExoskeletonPanel.cs index 5fc5c0e894..bb7dfcce40 100644 --- a/Projectiles/Summon/SmallAresArms/ExoskeletonPanel.cs +++ b/Projectiles/Summon/SmallAresArms/ExoskeletonPanel.cs @@ -160,22 +160,22 @@ namespace CalamityMod.Projectiles.Summon.SmallAresArms // Dynamically update panel icons. for (int i = 0; i < 4; i++) PanelIcons[i].CurrentState = IconType.Inactive; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (!arms.Contains(Main.projectile[i].type) || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].active) + if (!arms.Contains(p.type) || p.owner != Projectile.owner) continue; IconType stateFromID = IconType.Inactive; - if (Main.projectile[i].type == plasmaCannonID) + if (p.type == plasmaCannonID) stateFromID = IconType.Plasma; - if (Main.projectile[i].type == teslaCannonID) + if (p.type == teslaCannonID) stateFromID = IconType.Tesla; - if (Main.projectile[i].type == laserCannonID) + if (p.type == laserCannonID) stateFromID = IconType.Laser; - if (Main.projectile[i].type == gaussNukeID) + if (p.type == gaussNukeID) stateFromID = IconType.Gauss; - PanelIcons[(int)Main.projectile[i].ai[0]].CurrentState = stateFromID; + PanelIcons[(int)p.ai[0]].CurrentState = stateFromID; } // Handle fade effects. @@ -195,9 +195,9 @@ namespace CalamityMod.Projectiles.Summon.SmallAresArms if (ArmIDToSpawn >= 0) { bool armAlreadyExists = false; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (!arms.Contains(Main.projectile[i].type) || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].active || Main.projectile[i].ai[0] != ArmIndex) + if (!arms.Contains(p.type) || p.owner != Projectile.owner || p.ai[0] != ArmIndex) continue; armAlreadyExists = true; @@ -215,12 +215,12 @@ namespace CalamityMod.Projectiles.Summon.SmallAresArms if (ShouldDeleteArmIndex) { SoundEngine.PlaySound(SoundID.Item74, Projectile.Center); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (!arms.Contains(Main.projectile[i].type) || Main.projectile[i].owner != Projectile.owner || !Main.projectile[i].active || Main.projectile[i].ai[0] != ArmIndex) + if (!arms.Contains(p.type) || p.owner != Projectile.owner || p.ai[0] != ArmIndex) continue; - - Main.projectile[i].Kill(); + + p.Kill(); } } diff --git a/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs b/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs index bbcee7b814..7e24206cd7 100644 --- a/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs +++ b/Projectiles/Summon/SmallAresArms/MinionTeslaOrb.cs @@ -74,15 +74,15 @@ namespace CalamityMod.Projectiles.Summon.SmallAresArms public Projectile GetOrbToAttachTo() { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != Projectile.type || Main.projectile[i].ai[0] != Identity + 1f || !Main.projectile[i].active) + if (p.type != Projectile.type || p.ai[0] != Identity + 1f) continue; - if (!Main.projectile[i].WithinRange(Projectile.Center, AresExoskeleton.TeslaOrbDetatchDistance)) + if (!p.WithinRange(Projectile.Center, AresExoskeleton.TeslaOrbDetatchDistance)) continue; - return Main.projectile[i]; + return p; } return null; diff --git a/Projectiles/Summon/SolarGod.cs b/Projectiles/Summon/SolarGod.cs index 9ca80b96e9..5f9ee985f2 100644 --- a/Projectiles/Summon/SolarGod.cs +++ b/Projectiles/Summon/SolarGod.cs @@ -100,9 +100,8 @@ namespace CalamityMod.Projectiles.Summon } if (!foundTarget) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float npcDist = Vector2.Distance(Projectile.Center, npc.Center); diff --git a/Projectiles/Summon/SolarPixie.cs b/Projectiles/Summon/SolarPixie.cs index cd909e789c..fd06939b02 100644 --- a/Projectiles/Summon/SolarPixie.cs +++ b/Projectiles/Summon/SolarPixie.cs @@ -100,9 +100,8 @@ namespace CalamityMod.Projectiles.Summon } if (!foundTarget) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float npcDist = Vector2.Distance(Projectile.Center, npc.Center); diff --git a/Projectiles/Summon/Spikecrag.cs b/Projectiles/Summon/Spikecrag.cs index 4700e18d10..219ca81408 100644 --- a/Projectiles/Summon/Spikecrag.cs +++ b/Projectiles/Summon/Spikecrag.cs @@ -56,13 +56,13 @@ namespace CalamityMod.Projectiles.Summon float maxDistance = 1000f; bool homeIn = false; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float extraDistance = (float)(Main.npc[i].width / 2) + (Main.npc[i].height / 2); + float extraDistance = (float)(n.width / 2) + (n.height / 2); - if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, Projectile.width, Projectile.height, Main.npc[i].Center, Main.npc[i].width, Main.npc[i].height)) + if (Vector2.Distance(n.Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, Projectile.width, Projectile.height, n.Center, n.width, n.height)) { homeIn = true; break; diff --git a/Projectiles/Summon/StormjawBaby.cs b/Projectiles/Summon/StormjawBaby.cs index 28a737829d..1b27ab23b2 100644 --- a/Projectiles/Summon/StormjawBaby.cs +++ b/Projectiles/Summon/StormjawBaby.cs @@ -111,15 +111,14 @@ namespace CalamityMod.Projectiles.Summon } if (targetIndex < 0) { - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { float num1 = (npc.Center - Projectile.Center).Length(); if (num1 < maxDistance) { - targetIndex = i; + targetIndex = npc.whoAmI; maxDistance = num1; } } @@ -299,9 +298,8 @@ namespace CalamityMod.Projectiles.Summon else { Rectangle rectangle = new Rectangle((int)(Projectile.position.X + Projectile.velocity.X * 0.5f - 4f), (int)(Projectile.position.Y + Projectile.velocity.Y * 0.5f - 4f), Projectile.width + 8, Projectile.height + 8); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false) && npc.immune[Projectile.owner] <= 0) { Rectangle rect = npc.getRect(); diff --git a/Projectiles/Summon/Umbrella/MagicBird.cs b/Projectiles/Summon/Umbrella/MagicBird.cs index efe57b47a0..2672893275 100644 --- a/Projectiles/Summon/Umbrella/MagicBird.cs +++ b/Projectiles/Summon/Umbrella/MagicBird.cs @@ -88,18 +88,14 @@ namespace CalamityMod.Projectiles.Summon.Umbrella } if (!hasHomingTarget) { - for (int i = 0; i < Main.npc.Length; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc is null || !npc.active) - continue; - if (npc.CanBeChasedBy(Projectile, false)) { float dist = (Projectile.Center - npc.Center).Length(); if (dist < maxHomingRange) { - targetIdx = i; + targetIdx = npc.whoAmI; maxHomingRange = dist; hasHomingTarget = true; } diff --git a/Projectiles/Summon/Umbrella/MagicUmbrella.cs b/Projectiles/Summon/Umbrella/MagicUmbrella.cs index 5dd12a0966..952850a152 100644 --- a/Projectiles/Summon/Umbrella/MagicUmbrella.cs +++ b/Projectiles/Summon/Umbrella/MagicUmbrella.cs @@ -255,19 +255,18 @@ namespace CalamityMod.Projectiles.Summon.Umbrella return selectedTarget.whoAmI; } - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (npc.CanBeChasedBy(this) && (npc.boss || !blackListedTargets.Contains(i))) - { - float npcDist = npc.Distance(center); - if (npcDist <= MagicHat.Range && (npcDist <= closestDist || closestDist == -1f)) - { - closestDist = npcDist; - target = i; - } - } - } + if (npc.CanBeChasedBy(this) && (npc.boss || !blackListedTargets.Contains(npc.whoAmI))) + { + float npcDist = npc.Distance(center); + if (npcDist <= MagicHat.Range && (npcDist <= closestDist || closestDist == -1f)) + { + closestDist = npcDist; + target = npc.whoAmI; + } + } + } return target; } diff --git a/Projectiles/Summon/VictideSeaSnail.cs b/Projectiles/Summon/VictideSeaSnail.cs index 2d90f53ec7..52e1cc5bf2 100644 --- a/Projectiles/Summon/VictideSeaSnail.cs +++ b/Projectiles/Summon/VictideSeaSnail.cs @@ -154,9 +154,8 @@ namespace CalamityMod.Projectiles.Summon bool foundTarget = false; float maxDist = 300f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile, false)) { if (Vector2.Distance(Projectile.Center, npc.Center) < maxDist && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height)) diff --git a/Projectiles/Summon/VileFeederProjectile.cs b/Projectiles/Summon/VileFeederProjectile.cs index 83e73f76d5..8e0b672027 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/Summon/VoidConcentrationBlackhole.cs b/Projectiles/Summon/VoidConcentrationBlackhole.cs index 6e0fc0f7d6..b92eae0d7f 100644 --- a/Projectiles/Summon/VoidConcentrationBlackhole.cs +++ b/Projectiles/Summon/VoidConcentrationBlackhole.cs @@ -166,12 +166,12 @@ namespace CalamityMod.Projectiles.Summon } Projectile.frameCounter++; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && !Main.npc[i].friendly && CalamityGlobalNPC.ShouldAffectNPC(Main.npc[i])) + if (!n.friendly && CalamityGlobalNPC.ShouldAffectNPC(n)) { - if (Vector2.Distance(Projectile.Center, Main.npc[i].Center) <= radius) - ApplySucc(Main.npc[i]); + if (Vector2.Distance(Projectile.Center, n.Center) <= radius) + ApplySucc(n); } } diff --git a/Projectiles/Summon/WaterElementalMinion.cs b/Projectiles/Summon/WaterElementalMinion.cs index 5acfa868b6..86e7a1de94 100644 --- a/Projectiles/Summon/WaterElementalMinion.cs +++ b/Projectiles/Summon/WaterElementalMinion.cs @@ -125,14 +125,14 @@ namespace CalamityMod.Projectiles.Summon } if (!canAttack) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - float targetX = Main.npc[i].position.X + (float)(Main.npc[i].width / 2); - float targetY = Main.npc[i].position.Y + (float)(Main.npc[i].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 < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) + if (targetDist < attackRange && Collision.CanHit(Projectile.position, Projectile.width, Projectile.height, n.position, n.width, n.height)) { attackRange = targetDist; projX = targetX; diff --git a/Projectiles/Summon/WhiteDragonBody.cs b/Projectiles/Summon/WhiteDragonBody.cs index 954983e8b7..918211fc27 100644 --- a/Projectiles/Summon/WhiteDragonBody.cs +++ b/Projectiles/Summon/WhiteDragonBody.cs @@ -62,10 +62,9 @@ namespace CalamityMod.Projectiles.Summon var live = false; Projectile nextSegment = new Projectile(); WhiteDragonHead head = new WhiteDragonHead(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == Type && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == Type && projectile.owner == Projectile.owner) { if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) { @@ -73,7 +72,7 @@ namespace CalamityMod.Projectiles.Summon nextSegment = projectile; } } - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { if (segmentIndex == 1) { @@ -106,10 +105,9 @@ namespace CalamityMod.Projectiles.Summon { if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { projectile.Kill(); } diff --git a/Projectiles/Summon/WhiteDragonTail.cs b/Projectiles/Summon/WhiteDragonTail.cs index 0dbbdb3352..8a14b34937 100644 --- a/Projectiles/Summon/WhiteDragonTail.cs +++ b/Projectiles/Summon/WhiteDragonTail.cs @@ -51,10 +51,9 @@ namespace CalamityMod.Projectiles.Summon Projectile nextSegment = new Projectile(); WhiteDragonHead head = new WhiteDragonHead(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { if (projectile.ModProjectile().segmentIndex == segmentIndex - 1) { @@ -62,7 +61,7 @@ namespace CalamityMod.Projectiles.Summon nextSegment = projectile; } } - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { if (segmentIndex == 1) { @@ -97,10 +96,9 @@ namespace CalamityMod.Projectiles.Summon { if (Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] > 0) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile projectile in Main.ActiveProjectiles) { - var projectile = Main.projectile[i]; - if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner && projectile.active) + if (projectile.type == ModContent.ProjectileType() && projectile.owner == Projectile.owner) { projectile.Kill(); } diff --git a/Projectiles/Summon/WulfrumDroid.cs b/Projectiles/Summon/WulfrumDroid.cs index 74fa359aa1..1a5083b4db 100644 --- a/Projectiles/Summon/WulfrumDroid.cs +++ b/Projectiles/Summon/WulfrumDroid.cs @@ -32,10 +32,9 @@ namespace CalamityMod.Projectiles.Summon get { int minionCount = 1; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj.active && proj.owner == Owner.whoAmI && proj.type == Type && proj.whoAmI != Projectile.whoAmI) + if (proj.owner == Owner.whoAmI && proj.type == Type && proj.whoAmI != Projectile.whoAmI) { minionCount++; } @@ -315,14 +314,14 @@ namespace CalamityMod.Projectiles.Summon if (Main.netMode == NetmodeID.MultiplayerClient && mouseDistanceToOwner > 120f) { - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player p in Main.ActivePlayers) { - if (Main.player[i].active && !Main.player[i].dead && (Main.player[i].team == Owner.team || Main.player[i].team == 0)) + if (!p.dead && (p.team == Owner.team || p.team == 0)) { - float mouseDistanceToPotentialTarget = (Main.player[i].MountedCenter - Owner.Calamity().mouseWorld).Length(); + float mouseDistanceToPotentialTarget = (p.MountedCenter - Owner.Calamity().mouseWorld).Length(); if (mouseDistanceToPotentialTarget < 120f && mouseDistanceToOwner > mouseDistanceToPotentialTarget) { - playerToBuff = Main.player[i]; + playerToBuff = p; mouseDistanceToOwner = mouseDistanceToPotentialTarget; } } diff --git a/Projectiles/Summon/WulfrumEnergyBurst.cs b/Projectiles/Summon/WulfrumEnergyBurst.cs index 687a48141d..836cfab051 100644 --- a/Projectiles/Summon/WulfrumEnergyBurst.cs +++ b/Projectiles/Summon/WulfrumEnergyBurst.cs @@ -65,10 +65,8 @@ namespace CalamityMod.Projectiles.Summon float bestScore = 0; NPC bestTarget = null; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC potentialTarget in Main.ActiveNPCs) { - NPC potentialTarget = Main.npc[i]; - if (!potentialTarget.CanBeChasedBy(null, false)) continue; diff --git a/Projectiles/Summon/WulfrumFusionBolt.cs b/Projectiles/Summon/WulfrumFusionBolt.cs index a32b4ef95a..2007486933 100644 --- a/Projectiles/Summon/WulfrumFusionBolt.cs +++ b/Projectiles/Summon/WulfrumFusionBolt.cs @@ -68,10 +68,8 @@ namespace CalamityMod.Projectiles.Summon float bestScore = 0; NPC bestTarget = null; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC potentialTarget in Main.ActiveNPCs) { - NPC potentialTarget = Main.npc[i]; - if (!potentialTarget.CanBeChasedBy(null, false)) continue; diff --git a/Projectiles/Typeless/ArtifactOfResilienceShards.cs b/Projectiles/Typeless/ArtifactOfResilienceShards.cs index 7b769f1616..782c9d73ab 100644 --- a/Projectiles/Typeless/ArtifactOfResilienceShards.cs +++ b/Projectiles/Typeless/ArtifactOfResilienceShards.cs @@ -88,17 +88,16 @@ namespace CalamityMod.Projectiles.Typeless } if (projectile.ModProjectile is ArtifactOfResilienceShard1) { - for (int i = 0; i < Main.npc.Length; i++) + foreach (var n in Main.ActiveNPCs) { - if (Main.npc[i].active && - Main.npc[i].Distance(StartingPosition) < projectile.ai[1] && - Main.npc[i].damage > 0) + if (n.Distance(StartingPosition) < projectile.ai[1] && + n.damage > 0) { - if (Main.npc[i].Calamity().relicOfResilienceCooldown <= 0) + if (n.Calamity().relicOfResilienceCooldown <= 0) { - Main.npc[i].Calamity().relicOfResilienceCooldown = 600; - Main.npc[i].Calamity().relicOfResilienceWeakness = 180; - Main.npc[i].AddBuff(ModContent.BuffType(), Main.npc[i].Calamity().relicOfResilienceWeakness); + n.Calamity().relicOfResilienceCooldown = 600; + n.Calamity().relicOfResilienceWeakness = 180; + n.AddBuff(ModContent.BuffType(), n.Calamity().relicOfResilienceWeakness); } } } diff --git a/Projectiles/Typeless/BossRushEndEffectThing.cs b/Projectiles/Typeless/BossRushEndEffectThing.cs index b45a3230c2..879c088d75 100644 --- a/Projectiles/Typeless/BossRushEndEffectThing.cs +++ b/Projectiles/Typeless/BossRushEndEffectThing.cs @@ -52,16 +52,13 @@ namespace CalamityMod.Projectiles.Typeless public override void OnKill(int timeLeft) { BossRushEvent.End(); - for (int i = Main.maxPlayers - 1; i >= 0; i--) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (p is null || !p.active) - continue; int rock = Item.NewItem(p.GetSource_Misc("CalamityMod_BossRushRock"), (int)p.position.X, (int)p.position.Y, p.width, p.height, ModContent.ItemType()); if (Main.netMode == NetmodeID.Server) { Main.timeItemSlotCannotBeReusedFor[rock] = 54000; - NetMessage.SendData(MessageID.InstancedItem, i, -1, null, rock); + NetMessage.SendData(MessageID.InstancedItem, p.whoAmI, -1, null, rock); } } } diff --git a/Projectiles/Typeless/CursorProj.cs b/Projectiles/Typeless/CursorProj.cs index c27d89b830..af813ea592 100644 --- a/Projectiles/Typeless/CursorProj.cs +++ b/Projectiles/Typeless/CursorProj.cs @@ -57,16 +57,16 @@ namespace CalamityMod.Projectiles.Typeless { int targetID = -1; float hitDistance = 300f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - Vector2 targetCenter = Main.npc[i].Center; + Vector2 targetCenter = n.Center; float targetDist = Vector2.Distance(targetCenter, Projectile.Center); if (targetDist < hitDistance && targetID == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, targetCenter, 1, 1)) { hitDistance = targetDist; - targetID = i; + targetID = n.whoAmI; } } } diff --git a/Projectiles/Typeless/CursorProjSplit.cs b/Projectiles/Typeless/CursorProjSplit.cs index 3271984fc2..1031a67052 100644 --- a/Projectiles/Typeless/CursorProjSplit.cs +++ b/Projectiles/Typeless/CursorProjSplit.cs @@ -58,16 +58,16 @@ namespace CalamityMod.Projectiles.Typeless { int targetID = -1; float hitDistance = 300f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - Vector2 targetCenter = Main.npc[i].Center; + Vector2 targetCenter = n.Center; float targetDist = Vector2.Distance(targetCenter, Projectile.Center); if (targetDist < hitDistance && targetID == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, targetCenter, 1, 1)) { hitDistance = targetDist; - targetID = i; + targetID = n.whoAmI; } } } diff --git a/Projectiles/Typeless/DemonshadeRedDevil.cs b/Projectiles/Typeless/DemonshadeRedDevil.cs index 5a1b926bbd..df25b38ec2 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/Projectiles/Typeless/LunicBeam.cs b/Projectiles/Typeless/LunicBeam.cs index ffdce3a0c2..99360f627e 100644 --- a/Projectiles/Typeless/LunicBeam.cs +++ b/Projectiles/Typeless/LunicBeam.cs @@ -46,16 +46,16 @@ namespace CalamityMod.Projectiles.Typeless { int targetID = -1; float hitDistance = 150f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - Vector2 targetCenter = Main.npc[i].Center; + Vector2 targetCenter = n.Center; float targetDist = Vector2.Distance(targetCenter, Projectile.Center); if (targetDist < hitDistance && targetID == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, targetCenter, 1, 1)) { hitDistance = targetDist; - targetID = i; + targetID = n.whoAmI; } } } diff --git a/Projectiles/Typeless/MagnusBeam.cs b/Projectiles/Typeless/MagnusBeam.cs index 0b17ba7cc9..c5ca9718f5 100644 --- a/Projectiles/Typeless/MagnusBeam.cs +++ b/Projectiles/Typeless/MagnusBeam.cs @@ -39,16 +39,16 @@ namespace CalamityMod.Projectiles.Typeless { int targetIdx = -1; float npcRange = 150f; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].active && Main.npc[i].CanBeChasedBy(Projectile, false)) + if (n.CanBeChasedBy(Projectile, false)) { - Vector2 npcPos = Main.npc[i].Center; + Vector2 npcPos = n.Center; float npcDist = Vector2.Distance(npcPos, Projectile.Center); if (npcDist < npcRange && targetIdx == -1 && Collision.CanHitLine(Projectile.Center, 1, 1, npcPos, 1, 1)) { npcRange = npcDist; - targetIdx = i; + targetIdx = n.whoAmI; } } } diff --git a/Projectiles/Typeless/OmegaBlueTentacle.cs b/Projectiles/Typeless/OmegaBlueTentacle.cs index 80e2c60add..b908dd04a6 100644 --- a/Projectiles/Typeless/OmegaBlueTentacle.cs +++ b/Projectiles/Typeless/OmegaBlueTentacle.cs @@ -96,16 +96,15 @@ namespace CalamityMod.Projectiles.Typeless Projectile.ai[0] = 10 + Main.rand.Next(10); float maxDistance = hentai ? 900f : 600f; int target = -1; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(Projectile)) { float npcDistance = Projectile.Distance(npc.Center); if (npcDistance < maxDistance) { maxDistance = npcDistance; - target = i; + target = npc.whoAmI; } } } diff --git a/Projectiles/Typeless/WulfrumLureSignal.cs b/Projectiles/Typeless/WulfrumLureSignal.cs index 2c78db94ac..4b103fbb0f 100644 --- a/Projectiles/Typeless/WulfrumLureSignal.cs +++ b/Projectiles/Typeless/WulfrumLureSignal.cs @@ -43,13 +43,13 @@ namespace CalamityMod.Projectiles.Typeless if (Main.netMode == NetmodeID.MultiplayerClient) { float closestPlayerDistance = (Main.LocalPlayer.Center - Projectile.Center).Length(); - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player plr in Main.ActivePlayers) { - float newDistance = (Main.player[i].Center - Projectile.Center).Length(); + float newDistance = (plr.Center - Projectile.Center).Length(); if (newDistance < closestPlayerDistance) { closestPlayerDistance = newDistance; - player = Main.player[i]; + player = plr; } } } diff --git a/Scenes/MusicScenes/BaseMusicSceneEffect.cs b/Scenes/MusicScenes/BaseMusicSceneEffect.cs index 79b5f1802c..03a575e50f 100644 --- a/Scenes/MusicScenes/BaseMusicSceneEffect.cs +++ b/Scenes/MusicScenes/BaseMusicSceneEffect.cs @@ -38,12 +38,12 @@ namespace CalamityMod.Systems // You can't even edit music if the game has Otherworld toggle on lol. Have fun with Boss 1 /* - FieldInfo swapMusicField = typeof(Main).GetField("swapMusic", BindingFlags.Static | BindingFlags.NonPublic); - bool musicSwapped = (bool)swapMusicField.GetValue(null); - bool playingOtherworld = (!Main.drunkWorld && musicSwapped) || (Main.drunkWorld && !musicSwapped); - // Main.swapMusic is private. Todo: bug tmod devs to avoid reflection - return playingOtherworld ? OtherworldMusic : VanillaMusic; - */ + FieldInfo swapMusicField = typeof(Main).GetField("swapMusic", BindingFlags.Static | BindingFlags.NonPublic); + bool musicSwapped = (bool)swapMusicField.GetValue(null); + bool playingOtherworld = (!Main.drunkWorld && musicSwapped) || (Main.drunkWorld && !musicSwapped); + // Main.swapMusic is private. Todo: bug tmod devs to avoid reflection + return playingOtherworld ? OtherworldMusic : VanillaMusic; + */ } public virtual bool SetSceneEffect(Player player) @@ -55,28 +55,24 @@ namespace CalamityMod.Systems return false; /* - // You can't even edit music if the game has Otherworld toggle on lol. - // Theoretically, reflection would only occur if the music mod is disabled - if (MusicModMusic is null) - { - FieldInfo swapMusicField = typeof(Main).GetField("swapMusic", BindingFlags.Static | BindingFlags.NonPublic); - bool musicSwapped = (bool)swapMusicField.GetValue(null); - bool playingOtherworld = (!Main.drunkWorld && musicSwapped) || (Main.drunkWorld && !musicSwapped); - if (VanillaMusic == -1 && !playingOtherworld) - return false; - if (OtherworldMusic == -1 && playingOtherworld) - return false; - } - */ + // You can't even edit music if the game has Otherworld toggle on lol. + // Theoretically, reflection would only occur if the music mod is disabled + if (MusicModMusic is null) + { + FieldInfo swapMusicField = typeof(Main).GetField("swapMusic", BindingFlags.Static | BindingFlags.NonPublic); + bool musicSwapped = (bool)swapMusicField.GetValue(null); + bool playingOtherworld = (!Main.drunkWorld && musicSwapped) || (Main.drunkWorld && !musicSwapped); + if (VanillaMusic == -1 && !playingOtherworld) + return false; + if (OtherworldMusic == -1 && playingOtherworld) + return false; + } + */ 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++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[j]; - if (!npc.active) - continue; - bool inList = false; if (npc.type == NPCType) { diff --git a/Skies/AstralDesertSurfaceClose.png b/Skies/AstralDesertSurfaceClose.png deleted file mode 100644 index c96ebe2cfd..0000000000 Binary files a/Skies/AstralDesertSurfaceClose.png and /dev/null differ diff --git a/Skies/AstralDesertSurfaceFar.png b/Skies/AstralDesertSurfaceFar.png deleted file mode 100644 index a2337a7d8f..0000000000 Binary files a/Skies/AstralDesertSurfaceFar.png and /dev/null differ diff --git a/Skies/AstralDesertSurfaceMiddle.png b/Skies/AstralDesertSurfaceMiddle.png deleted file mode 100644 index 6b5c33dee8..0000000000 Binary files a/Skies/AstralDesertSurfaceMiddle.png and /dev/null differ diff --git a/Skies/AstralSky.cs b/Skies/AstralSky.cs index c919a6f549..7290303387 100644 --- a/Skies/AstralSky.cs +++ b/Skies/AstralSky.cs @@ -6,6 +6,7 @@ using Terraria.GameContent; using Terraria.Graphics.Effects; using Terraria.ID; using Terraria.ModLoader; +using System.Reflection; namespace CalamityMod.Skies { diff --git a/Skies/AstralSkyDesert.cs b/Skies/AstralSkyDesert.cs deleted file mode 100644 index f786d156da..0000000000 --- a/Skies/AstralSkyDesert.cs +++ /dev/null @@ -1,137 +0,0 @@ -using CalamityMod.Systems; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.GameContent; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Skies -{ - public class AstralSkyDesert : CustomSky - { - private bool skyActive; - private float opacity; - - private const float Scale = 2f; - - public override void Deactivate(params object[] args) - { - skyActive = Main.LocalPlayer.Calamity().ZoneAstral && !Main.LocalPlayer.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950 && Main.LocalPlayer.ZoneDesert && !Main.LocalPlayer.ZoneSnow; - } - - public override void Reset() - { - skyActive = false; - } - - public override bool IsActive() - { - return skyActive || opacity > 0f; - } - - public override void Activate(Vector2 position, params object[] args) - { - skyActive = true; - } - public override Color OnTileColor(Color inColor) - { - return Color.Lerp(inColor, new Color(63, 51, 90, inColor.A), opacity); - } - - public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) - { - // Small worlds, default draw height. - int AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 2; - - // Medium worlds. - if (Main.maxTilesX >= 6400 && Main.maxTilesX < 8400) - AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 4; - - // Large worlds (and anything bigger). - if (Main.maxTilesX >= 8400) - AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 140; - - // Background from here starting from the back layer to the front layer. - float width = Main.screenWidth / 2f; - float height = Main.screenHeight / 2f; - Color color = new Color(63, 51, 90, 255) * opacity; - if (maxDepth >= 9f && minDepth < 9f) - { - float screenParralaxMultiplier = 0.16f; - Texture2D texture = CalamityMod.AstralSurfaceHorizon; - int x = (int)(Main.screenPosition.X * screenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * screenParralaxMultiplier); - y -= 1380; // 1000 - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - texture.Size() / 2f * Scale, null, color, 0f, new Vector2(0f, (float)AstralBiomeHeight), Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 8f && minDepth < 8f) - { - float screenParralaxMultiplier = 0.4f; - Texture2D texture = CalamityMod.AstralDesertSurfaceFar; - int x = (int)(Main.screenPosition.X * 0.5f * screenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.45f * screenParralaxMultiplier); - y -= 1520; // 1000 - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - texture.Size() / 2f * Scale, null, color, 0f, new Vector2(0f, (float)AstralBiomeHeight), Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 7f && minDepth < 7f) - { - float screenParralaxMultiplier = 0.4f; - Texture2D texture = CalamityMod.AstralDesertSurfaceMiddle; - int x = (int)(Main.screenPosition.X * 0.8f * screenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.5f * screenParralaxMultiplier); - y -= 1900; // 1000 - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - texture.Size() / 2f * Scale, null, color, 0f, new Vector2(0f, (float)AstralBiomeHeight), Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 6f && minDepth < 6f) - { - float screenParralaxMultiplier = 0.4f; - Texture2D texture = CalamityMod.AstralDesertSurfaceClose; - int x = (int)(Main.screenPosition.X * 1f * screenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.55f * screenParralaxMultiplier); - y -= 2050; // 1000 - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - texture.Size() / 2f * Scale, null, color, 0f, new Vector2(0f, (float)AstralBiomeHeight), Scale, SpriteEffects.None, 0f); - } - } - } - - public override void Update(GameTime gameTime) - { - if (!Main.LocalPlayer.Calamity().ZoneAstral || Main.gameMenu) - skyActive = false; - - if (skyActive && opacity < 1f) - opacity += 0.02f; - else if (!skyActive && opacity > 0f) - opacity -= 0.02f; - } - - public override float GetCloudAlpha() - { - return (1f - opacity) * 0.97f + 0.03f; - } - } -} diff --git a/Skies/AstralSkySnow.cs b/Skies/AstralSkySnow.cs deleted file mode 100644 index 277b92f4fd..0000000000 --- a/Skies/AstralSkySnow.cs +++ /dev/null @@ -1,171 +0,0 @@ -using CalamityMod.Systems; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.GameContent; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Skies -{ - public class AstralSkySnow : CustomSky - { - private bool skyActive; - private float opacity; - - private const float Scale = 2.0f; - private const float ScreenParralaxMultiplier = 0.4f; - - public override void Deactivate(params object[] args) - { - skyActive = Main.LocalPlayer.Calamity().ZoneAstral && !Main.LocalPlayer.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950 && Main.LocalPlayer.ZoneSnow && !Main.LocalPlayer.ZoneDesert; - } - - public override void Reset() - { - skyActive = false; - } - - public override bool IsActive() - { - return skyActive || opacity > 0f; - } - - public override void Activate(Vector2 position, params object[] args) - { - skyActive = true; - } - - public override Color OnTileColor(Color inColor) - { - return Color.Lerp(inColor, new Color(63, 51, 90, inColor.A), opacity); - } - - public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) - { - // Small worlds, default draw height. - int AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 2; - - // Medium worlds. - if (Main.maxTilesX >= 6400 && Main.maxTilesX < 8400) - AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 4; - - // Large worlds (and anything bigger). - if (Main.maxTilesX >= 8400) - AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 140; - - // Background from here starting from the back layer to the front layer. - float width = Main.screenWidth / 2f; - float height = Main.screenHeight / 2f; - Color textureColor = new Color(116, 96, 164, 255) * opacity; - Vector2 origin = new Vector2(0f, AstralBiomeHeight); - if (maxDepth >= 9f && minDepth < 9f) - { - Texture2D texture = CalamityMod.AstralSurfaceHorizon; - int x = (int)(Main.screenPosition.X * 0.4f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.4f * ScreenParralaxMultiplier); - y -= 1380; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 8f && minDepth < 8f) - { - Texture2D texture = CalamityMod.AstralSurfaceFar; - int x = (int)(Main.screenPosition.X * 0.5f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.45f * ScreenParralaxMultiplier); - y -= 1520; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 7f && minDepth < 7f) - { - Texture2D texture = CalamityMod.AstralSnowSurfaceMiddle; - int x = (int)(Main.screenPosition.X * 0.8f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.5f * ScreenParralaxMultiplier); - y -= 1900; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 6f && minDepth < 6f) - { - Texture2D texture = CalamityMod.AstralSurfaceClose; - int x = (int)(Main.screenPosition.X * 0.9f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.55f * ScreenParralaxMultiplier); - y -= 1880; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - - Texture2D textureglow = CalamityMod.AstralSurfaceCloseGlow; - Color textureGlowColor = Color.White * 0.7f * opacity; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(textureglow, pos - position, null, textureGlowColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 5f && minDepth < 5f) - { - Texture2D texture = CalamityMod.AstralSurfaceFront; - int x = (int)(Main.screenPosition.X * 1.1f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.6f * ScreenParralaxMultiplier); - y -= 2100; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - - Texture2D textureglow = CalamityMod.AstralSurfaceFrontGlow; - Color textureGlowColor = Color.White * 0.9f * opacity; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(textureglow, pos - position, null, textureGlowColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - } - - public override void Update(GameTime gameTime) - { - if (!Main.LocalPlayer.Calamity().ZoneAstral || Main.gameMenu) - skyActive = false; - - if (skyActive && opacity < 1f) - opacity += 0.02f; - else if (!skyActive && opacity > 0f) - opacity -= 0.02f; - } - - public override float GetCloudAlpha() - { - return (1f - opacity) * 0.97f + 0.03f; - } - } -} diff --git a/Skies/AstralSkySurface.cs b/Skies/AstralSkySurface.cs deleted file mode 100644 index b4eead4ca8..0000000000 --- a/Skies/AstralSkySurface.cs +++ /dev/null @@ -1,179 +0,0 @@ -using CalamityMod.Systems; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.GameContent; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Skies -{ - public class AstralSkySurface : CustomSky - { - private bool skyActive; - private float opacity; - - private const float Scale = 2f; - private const float ScreenParralaxMultiplier = 0.4f; - - public override void Deactivate(params object[] args) - { - skyActive = Main.LocalPlayer.Calamity().ZoneAstral && !Main.LocalPlayer.ZoneDungeon && BiomeTileCounterSystem.AstralTiles > 950 && !Main.LocalPlayer.ZoneDesert && !Main.LocalPlayer.ZoneSnow; - } - - public override void Reset() - { - skyActive = false; - } - - public override bool IsActive() - { - return skyActive || opacity > 0f; - } - - public override void Activate(Vector2 position, params object[] args) - { - skyActive = true; - } - - public override Color OnTileColor(Color inColor) - { - return Color.Lerp(inColor, new Color(63, 51, 90, inColor.A), opacity); - } - - public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) - { - // Small worlds, default draw height. - int AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 2; - - // Medium worlds. - if (Main.maxTilesX >= 6400 && Main.maxTilesX < 8400) - AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 4; - - // Large worlds (and anything bigger). - if (Main.maxTilesX >= 8400) - AstralBiomeHeight = (World.AstralBiome.YStart + (int)Main.worldSurface) / 140; - - // Background from here starting from the back layer to the front layer. - float width = Main.screenWidth / 2f; - float height = Main.screenHeight / 2f; - Color textureColor = new Color(63, 51, 90, 255) * opacity; - Vector2 origin = new Vector2(0f, AstralBiomeHeight); - if (maxDepth >= 9f && minDepth < 9f) - { - Texture2D texture = CalamityMod.AstralSurfaceHorizon; - int x = (int)(Main.screenPosition.X * 0.4f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.4f * ScreenParralaxMultiplier); - y -= 1380; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 8f && minDepth < 8f) - { - Texture2D texture = CalamityMod.AstralSurfaceFar; - int x = (int)(Main.screenPosition.X * 0.5f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.45f * ScreenParralaxMultiplier); - y -= 1520; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 7f && minDepth < 7f) - { - Texture2D texture = CalamityMod.AstralSurfaceMiddle; - int x = (int)(Main.screenPosition.X * 0.8f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.5f * ScreenParralaxMultiplier); - y -= 1900; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - - Texture2D textureglow = CalamityMod.AstralSurfaceMiddleGlow; - Color textureGlowColor = Color.White * 0.5f * opacity; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(textureglow, pos - position, null, textureGlowColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 6f && minDepth < 6f) - { - Texture2D texture = CalamityMod.AstralSurfaceClose; - int x = (int)(Main.screenPosition.X * 0.9f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.55f * ScreenParralaxMultiplier); - y -= 1880; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - - Texture2D textureglow = CalamityMod.AstralSurfaceCloseGlow; - Color textureGlowColor = Color.White * 0.7f * opacity; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(textureglow, pos - position, null, textureGlowColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - - if (maxDepth >= 5f && minDepth < 5f) - { - Texture2D texture = CalamityMod.AstralSurfaceFront; - int x = (int)(Main.screenPosition.X * 1.1f * ScreenParralaxMultiplier); - x %= (int)(texture.Width * Scale); - int y = (int)(Main.screenPosition.Y * 0.6f * ScreenParralaxMultiplier); - y -= 2100; // 1000 - Vector2 position = texture.Size() / 2f * Scale; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(texture, pos - position, null, textureColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - - Texture2D textureglow = CalamityMod.AstralSurfaceFrontGlow; - Color textureGlowColor = Color.White * 0.9f * opacity; - for (int k = -1; k <= 1; k++) - { - var pos = new Vector2(width - x + texture.Width * k * Scale, height - y); - spriteBatch.Draw(textureglow, pos - position, null, textureGlowColor, 0f, origin, Scale, SpriteEffects.None, 0f); - } - } - } - - public override void Update(GameTime gameTime) - { - if (!Main.LocalPlayer.Calamity().ZoneAstral || Main.gameMenu) - skyActive = false; - - if (skyActive && opacity < 1f) - opacity += 0.02f; - else if (!skyActive && opacity > 0f) - opacity -= 0.02f; - } - - public override float GetCloudAlpha() - { - return (1f - opacity) * 0.97f + 0.03f; - } - } -} diff --git a/Skies/AstralSnowSurfaceMiddle.png b/Skies/AstralSnowSurfaceMiddle.png deleted file mode 100644 index ff4e5fc236..0000000000 Binary files a/Skies/AstralSnowSurfaceMiddle.png and /dev/null differ diff --git a/Skies/AstralSurfaceClose.png b/Skies/AstralSurfaceClose.png deleted file mode 100644 index 166e8bc48d..0000000000 Binary files a/Skies/AstralSurfaceClose.png and /dev/null differ diff --git a/Skies/AstralSurfaceFar.png b/Skies/AstralSurfaceFar.png deleted file mode 100644 index de6901e9e4..0000000000 Binary files a/Skies/AstralSurfaceFar.png and /dev/null differ diff --git a/Skies/AstralSurfaceFront.png b/Skies/AstralSurfaceFront.png deleted file mode 100644 index d9db0020e9..0000000000 Binary files a/Skies/AstralSurfaceFront.png and /dev/null differ diff --git a/Skies/AstralSurfaceHorizon.png b/Skies/AstralSurfaceHorizon.png deleted file mode 100644 index 8f448fb3b4..0000000000 Binary files a/Skies/AstralSurfaceHorizon.png and /dev/null differ diff --git a/Skies/AstralSurfaceMiddle.png b/Skies/AstralSurfaceMiddle.png deleted file mode 100644 index d3f984c001..0000000000 Binary files a/Skies/AstralSurfaceMiddle.png and /dev/null differ diff --git a/Skies/CryogenSky.cs b/Skies/CryogenSky.cs index e8d05d6677..02b5b528f5 100644 --- a/Skies/CryogenSky.cs +++ b/Skies/CryogenSky.cs @@ -108,15 +108,7 @@ namespace CalamityMod.Skies if (CryogenIndex >= 0 && Main.npc[CryogenIndex].active && Main.npc[CryogenIndex].type == cryogenType) return true; - CryogenIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == cryogenType) - { - CryogenIndex = i; - break; - } - } + CryogenIndex = NPC.FindFirstNPC(cryogenType); return CryogenIndex != -1; } diff --git a/Skies/DrunkCrabScreenShaderData.cs b/Skies/DrunkCrabScreenShaderData.cs index 6eee00117e..2d67cb7706 100644 --- a/Skies/DrunkCrabScreenShaderData.cs +++ b/Skies/DrunkCrabScreenShaderData.cs @@ -47,14 +47,7 @@ namespace CalamityMod.Skies if (!shouldForceDeactivateCirrusShader) { - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == CirrusType) - { - CirrusIndex = i; - break; - } - } + CirrusIndex = NPC.FindFirstNPC(CirrusType); } } else @@ -62,16 +55,7 @@ namespace CalamityMod.Skies if (CrabIndex >= 0 && Main.npc[CrabIndex].active && Main.npc[CrabIndex].type == CrabType) return; - CrabIndex = -1; - - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == CrabType) - { - CrabIndex = i; - break; - } - } + CrabIndex = NPC.FindFirstNPC(CrabType); } } diff --git a/Skies/SCalScreenShaderData.cs b/Skies/SCalScreenShaderData.cs index 92f0b5ca3a..1e562f1683 100644 --- a/Skies/SCalScreenShaderData.cs +++ b/Skies/SCalScreenShaderData.cs @@ -24,15 +24,7 @@ namespace CalamityMod.Skies { return; } - SCalIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == SCalType) - { - SCalIndex = i; - break; - } - } + SCalIndex = NPC.FindFirstNPC(SCalType); } public override void Update(GameTime gameTime) diff --git a/Skies/SCalSky.cs b/Skies/SCalSky.cs index bb3af0b383..739d66cdee 100644 --- a/Skies/SCalSky.cs +++ b/Skies/SCalSky.cs @@ -232,15 +232,7 @@ namespace CalamityMod.Skies if (SCalIndex >= 0 && Main.npc[SCalIndex].active && Main.npc[SCalIndex].type == SCalType) return true; - SCalIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == SCalType) - { - SCalIndex = i; - break; - } - } + SCalIndex = NPC.FindFirstNPC(SCalType); return SCalIndex != -1; } diff --git a/Skies/StormWeaverFlashSky.cs b/Skies/StormWeaverFlashSky.cs index 42471c402e..82de86c339 100644 --- a/Skies/StormWeaverFlashSky.cs +++ b/Skies/StormWeaverFlashSky.cs @@ -18,15 +18,7 @@ namespace CalamityMod.Skies if (StormWeaverHeadIndex >= 0 && Main.npc[StormWeaverHeadIndex].active && Main.npc[StormWeaverHeadIndex].type == weaverType) return; - StormWeaverHeadIndex = -1; - for (int i = 0; i < Main.npc.Length; i++) - { - if (Main.npc[i].active && Main.npc[i].type == weaverType) - { - StormWeaverHeadIndex = i; - break; - } - } + StormWeaverHeadIndex = NPC.FindFirstNPC(weaverType); } public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) diff --git a/Systems/WorldMiscUpdateSystem.cs b/Systems/WorldMiscUpdateSystem.cs index 05c4a3c2d5..074ff42332 100644 --- a/Systems/WorldMiscUpdateSystem.cs +++ b/Systems/WorldMiscUpdateSystem.cs @@ -104,12 +104,12 @@ namespace CalamityMod.Systems // Attempt to summon lab critters manually since they refuse to exist when using vanilla's spawn methods. // This needs to check all players since the method only runs server-side. - for (int i = 0; i < Main.maxPlayers; i++) + foreach (Player p in Main.ActivePlayers) { - if (!Main.player[i].active || Main.player[i].dead) + if (p.dead) continue; - CalamityGlobalNPC.AttemptToSpawnLabCritters(Main.player[i]); + CalamityGlobalNPC.AttemptToSpawnLabCritters(p); } // Make the cultist countdown happen much more quickly. diff --git a/TileEntities/TEChargingStation.cs b/TileEntities/TEChargingStation.cs index caa483d473..33ec54628d 100644 --- a/TileEntities/TEChargingStation.cs +++ b/TileEntities/TEChargingStation.cs @@ -140,10 +140,9 @@ namespace CalamityMod.TileEntities // If this charging station breaks, anyone's who's viewing it is no longer viewing it. public override void OnKill() { - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active) + if (p.dead) continue; // Use reflection to stop TML from spitting an error here. diff --git a/TileEntities/TEHostileFireTurret.cs b/TileEntities/TEHostileFireTurret.cs index 65171977ee..5f79addd68 100644 --- a/TileEntities/TEHostileFireTurret.cs +++ b/TileEntities/TEHostileFireTurret.cs @@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active || p.dead) + if (p.dead) continue; float distSQ = p.DistanceSQ(targetingCenter); @@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = p.Center; - indexToSet = i; + indexToSet = p.whoAmI; } } diff --git a/TileEntities/TEHostileIceTurret.cs b/TileEntities/TEHostileIceTurret.cs index 7e6ff9c24d..17d4fec62d 100644 --- a/TileEntities/TEHostileIceTurret.cs +++ b/TileEntities/TEHostileIceTurret.cs @@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active || p.dead) + if (p.dead) continue; float distSQ = p.DistanceSQ(targetingCenter); @@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = p.Center; - indexToSet = i; + indexToSet = p.whoAmI; } } diff --git a/TileEntities/TEHostileLabTurret.cs b/TileEntities/TEHostileLabTurret.cs index 22eed5f8b8..e56a00222a 100644 --- a/TileEntities/TEHostileLabTurret.cs +++ b/TileEntities/TEHostileLabTurret.cs @@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active || p.dead) + if (p.dead) continue; float distSQ = p.DistanceSQ(targetingCenter); @@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = p.Center; - indexToSet = i; + indexToSet = p.whoAmI; } } diff --git a/TileEntities/TEHostileLaserTurret.cs b/TileEntities/TEHostileLaserTurret.cs index 694a184e10..f6957f917a 100644 --- a/TileEntities/TEHostileLaserTurret.cs +++ b/TileEntities/TEHostileLaserTurret.cs @@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active || p.dead) + if (p.dead) continue; float distSQ = p.DistanceSQ(targetingCenter); @@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = p.Center; - indexToSet = i; + indexToSet = p.whoAmI; } } diff --git a/TileEntities/TEHostileOnyxTurret.cs b/TileEntities/TEHostileOnyxTurret.cs index 6c800d2ec8..6443c09f49 100644 --- a/TileEntities/TEHostileOnyxTurret.cs +++ b/TileEntities/TEHostileOnyxTurret.cs @@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active || p.dead) + if (p.dead) continue; float distSQ = p.DistanceSQ(targetingCenter); @@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = p.Center; - indexToSet = i; + indexToSet = p.whoAmI; } } diff --git a/TileEntities/TEHostilePlagueTurret.cs b/TileEntities/TEHostilePlagueTurret.cs index 1969210cd5..b06e3301c5 100644 --- a/TileEntities/TEHostilePlagueTurret.cs +++ b/TileEntities/TEHostilePlagueTurret.cs @@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active || p.dead) + if (p.dead) continue; float distSQ = p.DistanceSQ(targetingCenter); @@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = p.Center; - indexToSet = i; + indexToSet = p.whoAmI; } } diff --git a/TileEntities/TEHostileWaterTurret.cs b/TileEntities/TEHostileWaterTurret.cs index edaf987128..d89dc7c8a0 100644 --- a/TileEntities/TEHostileWaterTurret.cs +++ b/TileEntities/TEHostileWaterTurret.cs @@ -85,10 +85,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active || p.dead) + if (p.dead) continue; float distSQ = p.DistanceSQ(targetingCenter); @@ -96,7 +95,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = p.Center; - indexToSet = i; + indexToSet = p.whoAmI; } } diff --git a/TileEntities/TELabHologramProjector.cs b/TileEntities/TELabHologramProjector.cs index ea28ff6fbc..791cd49489 100644 --- a/TileEntities/TELabHologramProjector.cs +++ b/TileEntities/TELabHologramProjector.cs @@ -35,11 +35,10 @@ namespace CalamityMod.TileEntities // If one is, pop up. Vector2 projectorCenterPos = Center; float distSQ = PopupDistance * PopupDistance; - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active) // The lack of a dead check is intentional. Dead players keep hologram boxes on for amusement. - continue; + // The lack of a dead check is intentional. Dead players keep hologram boxes on for amusement. + if (p.DistanceSQ(projectorCenterPos) < distSQ) { PoppingUp = true; @@ -72,12 +71,8 @@ namespace CalamityMod.TileEntities // If this projector breaks, anyone who's viewing it is no longer viewing it. public override void OnKill() { - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active) - continue; - // Use reflection to stop TML from spitting an error here. // Try-catching will not stop this error, TML will print it to console anyway. The error is harmless. ModPlayer[] mpStorageArray = (ModPlayer[])typeof(Player).GetField("modPlayers", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(p); diff --git a/TileEntities/TEPlayerFireTurret.cs b/TileEntities/TEPlayerFireTurret.cs index de0a344fee..ce3485376e 100644 --- a/TileEntities/TEPlayerFireTurret.cs +++ b/TileEntities/TEPlayerFireTurret.cs @@ -88,10 +88,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.CountsAsACritter) + if (npc.friendly || npc.CountsAsACritter) continue; float distSQ = npc.DistanceSQ(targetingCenter); @@ -99,7 +98,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = npc.Center; - indexToSet = i; + indexToSet = npc.whoAmI; } } diff --git a/TileEntities/TEPlayerIceTurret.cs b/TileEntities/TEPlayerIceTurret.cs index 3972e8c0c9..b391d06346 100644 --- a/TileEntities/TEPlayerIceTurret.cs +++ b/TileEntities/TEPlayerIceTurret.cs @@ -88,10 +88,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.CountsAsACritter) + if (npc.friendly || npc.CountsAsACritter) continue; float distSQ = npc.DistanceSQ(targetingCenter); @@ -99,7 +98,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = npc.Center; - indexToSet = i; + indexToSet = npc.whoAmI; } } diff --git a/TileEntities/TEPlayerLabTurret.cs b/TileEntities/TEPlayerLabTurret.cs index 53fff521c4..df9517428b 100644 --- a/TileEntities/TEPlayerLabTurret.cs +++ b/TileEntities/TEPlayerLabTurret.cs @@ -88,10 +88,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.CountsAsACritter) + if (npc.friendly || npc.CountsAsACritter) continue; float distSQ = npc.DistanceSQ(targetingCenter); @@ -99,7 +98,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = npc.Center; - indexToSet = i; + indexToSet = npc.whoAmI; } } diff --git a/TileEntities/TEPlayerLaserTurret .cs b/TileEntities/TEPlayerLaserTurret .cs index 543d48156d..0360e32168 100644 --- a/TileEntities/TEPlayerLaserTurret .cs +++ b/TileEntities/TEPlayerLaserTurret .cs @@ -88,10 +88,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.CountsAsACritter) + if (npc.friendly || npc.CountsAsACritter) continue; float distSQ = npc.DistanceSQ(targetingCenter); @@ -99,7 +98,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = npc.Center; - indexToSet = i; + indexToSet = npc.whoAmI; } } diff --git a/TileEntities/TEPlayerOnyxTurret.cs b/TileEntities/TEPlayerOnyxTurret.cs index 249773f018..997b04959c 100644 --- a/TileEntities/TEPlayerOnyxTurret.cs +++ b/TileEntities/TEPlayerOnyxTurret.cs @@ -88,10 +88,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.CountsAsACritter) + if (npc.friendly || npc.CountsAsACritter) continue; float distSQ = npc.DistanceSQ(targetingCenter); @@ -99,7 +98,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = npc.Center; - indexToSet = i; + indexToSet = npc.whoAmI; } } diff --git a/TileEntities/TEPlayerPlagueTurret.cs b/TileEntities/TEPlayerPlagueTurret.cs index eac6772413..764f0c8ed8 100644 --- a/TileEntities/TEPlayerPlagueTurret.cs +++ b/TileEntities/TEPlayerPlagueTurret.cs @@ -69,10 +69,9 @@ namespace CalamityMod.TileEntities //This turret can switch targets at any time - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.CountsAsACritter) + if (npc.friendly || npc.CountsAsACritter) continue; float distSQ = npc.DistanceSQ(targetingCenter); @@ -80,7 +79,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = npc.Center; - indexToSet = i; + indexToSet = npc.whoAmI; } } diff --git a/TileEntities/TEPlayerWaterTurret.cs b/TileEntities/TEPlayerWaterTurret.cs index 50da41de03..924f72e22c 100644 --- a/TileEntities/TEPlayerWaterTurret.cs +++ b/TileEntities/TEPlayerWaterTurret.cs @@ -88,10 +88,9 @@ namespace CalamityMod.TileEntities Vector2 ret = InvalidTarget; float distSQToBeat = MaxRange * MaxRange; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; - if (!npc.active || npc.friendly || npc.CountsAsACritter) + if (npc.friendly || npc.CountsAsACritter) continue; float distSQ = npc.DistanceSQ(targetingCenter); @@ -99,7 +98,7 @@ namespace CalamityMod.TileEntities { distSQToBeat = distSQ; ret = npc.Center; - indexToSet = i; + indexToSet = npc.whoAmI; } } diff --git a/TileEntities/TEPowerCellFactory.cs b/TileEntities/TEPowerCellFactory.cs index 7b1482be3a..93bdce0481 100644 --- a/TileEntities/TEPowerCellFactory.cs +++ b/TileEntities/TEPowerCellFactory.cs @@ -103,12 +103,8 @@ namespace CalamityMod.TileEntities // If this factory breaks, anyone who's viewing it is no longer viewing it. public override void OnKill() { - for (int i = 0; i < Main.maxPlayers; ++i) + foreach (Player p in Main.ActivePlayers) { - Player p = Main.player[i]; - if (!p.active) - continue; - // Use reflection to stop TML from spitting an error here. // Try-catching will not stop this error, TML will print it to console anyway. The error is harmless. ModPlayer[] mpStorageArray = (ModPlayer[])typeof(Player).GetField("modPlayers", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(p); diff --git a/Tiles/Pylons/AstralPylonTile.cs b/Tiles/Pylons/AstralPylonTile.cs index 9a95f6053f..1aeac063ef 100644 --- a/Tiles/Pylons/AstralPylonTile.cs +++ b/Tiles/Pylons/AstralPylonTile.cs @@ -18,8 +18,7 @@ namespace CalamityMod.Tiles.Pylons public override NPCShop.Entry GetNPCShopEntry() { - Condition biomeCondition = new Condition(CalamityUtils.GetText("Condition.InAstral"), () => Main.LocalPlayer.Calamity().ZoneAstral); - return new NPCShop.Entry(AssociatedItem, Condition.AnotherTownNPCNearby, biomeCondition); + return new NPCShop.Entry(AssociatedItem, Condition.AnotherTownNPCNearby, CalamityConditions.InAstral); } diff --git a/Tiles/Pylons/CragsPylonTile.cs b/Tiles/Pylons/CragsPylonTile.cs index fa711e50a6..a4987d44d6 100644 --- a/Tiles/Pylons/CragsPylonTile.cs +++ b/Tiles/Pylons/CragsPylonTile.cs @@ -19,8 +19,7 @@ namespace CalamityMod.Tiles.Pylons public override NPCShop.Entry GetNPCShopEntry() { - Condition biomeCondition = new Condition(CalamityUtils.GetText("Condition.InCrag"), () => Main.LocalPlayer.Calamity().ZoneCalamity); - return new NPCShop.Entry(AssociatedItem, biomeCondition); + return new NPCShop.Entry(AssociatedItem, CalamityConditions.InCrag); } //Doesnt require npcs to function diff --git a/Tiles/Pylons/SulphurPylonTile.cs b/Tiles/Pylons/SulphurPylonTile.cs index 825e594738..39f2718703 100644 --- a/Tiles/Pylons/SulphurPylonTile.cs +++ b/Tiles/Pylons/SulphurPylonTile.cs @@ -18,8 +18,7 @@ namespace CalamityMod.Tiles.Pylons public override NPCShop.Entry GetNPCShopEntry() { - Condition biomeCondition = new Condition(CalamityUtils.GetText("Condition.InSulph"), () => Main.LocalPlayer.Calamity().ZoneSulphur); - return new NPCShop.Entry(AssociatedItem, Condition.AnotherTownNPCNearby, biomeCondition); + return new NPCShop.Entry(AssociatedItem, Condition.AnotherTownNPCNearby, CalamityConditions.InSulph); } public override bool ValidTeleportCheck_BiomeRequirements(TeleportPylonInfo pylonInfo, SceneMetrics sceneData) => BiomeTileCounterSystem.SulphurTiles >= 100; diff --git a/Tiles/Pylons/SunkenPylonTile.cs b/Tiles/Pylons/SunkenPylonTile.cs index 74dc1115c1..8f48db51bf 100644 --- a/Tiles/Pylons/SunkenPylonTile.cs +++ b/Tiles/Pylons/SunkenPylonTile.cs @@ -18,8 +18,7 @@ namespace CalamityMod.Tiles.Pylons public override NPCShop.Entry GetNPCShopEntry() { - Condition biomeCondition = new Condition(CalamityUtils.GetText("Condition.InSunken"), () => Main.LocalPlayer.Calamity().ZoneSunkenSea); - return new NPCShop.Entry(AssociatedItem, Condition.AnotherTownNPCNearby, biomeCondition); + return new NPCShop.Entry(AssociatedItem, Condition.AnotherTownNPCNearby, CalamityConditions.InSunken); } public override bool ValidTeleportCheck_BiomeRequirements(TeleportPylonInfo pylonInfo, SceneMetrics sceneData) => BiomeTileCounterSystem.SunkenSeaTiles >= 100; diff --git a/UI/BossHealthBarManager.cs b/UI/BossHealthBarManager.cs index 66a703bbc1..a7a0ad791c 100644 --- a/UI/BossHealthBarManager.cs +++ b/UI/BossHealthBarManager.cs @@ -330,17 +330,17 @@ namespace CalamityMod.UI if (npc.ai[0] == 2f) life = 0L; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - bool isMoonLordPiece = Main.npc[i].type == NPCID.MoonLordHand || Main.npc[i].type == NPCID.MoonLordHead; - if (!Main.npc[i].active || !isMoonLordPiece || Main.npc[i].ai[3] != npc.whoAmI) + bool isMoonLordPiece = n.type == NPCID.MoonLordHand || n.type == NPCID.MoonLordHead; + if (!isMoonLordPiece || n.ai[3] != npc.whoAmI) continue; // Don't count HP towards the total if the NPC is in its dead state. - if (Main.npc[i].Calamity().newAI[0] == 1f) + if (n.Calamity().newAI[0] == 1f) continue; - life += checkingForMaxLife ? Main.npc[i].lifeMax : Main.npc[i].life; + life += checkingForMaxLife ? n.lifeMax : n.life; } return life; @@ -364,15 +364,15 @@ namespace CalamityMod.UI public override void Update(IBigProgressBar currentBar, ref BigProgressBarInfo info) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - // Ignore inactive NPCs and NPCs that should not be given a bar, even if it meets other criteria. - if (!Main.npc[i].active || BossExclusionList.Contains(Main.npc[i].type)) + // Ignore NPCs that should not be given a bar, even if it meets other criteria. + if (BossExclusionList.Contains(n.type)) continue; - bool isEoWSegment = Main.npc[i].type == NPCID.EaterofWorldsBody || Main.npc[i].type == NPCID.EaterofWorldsTail; - if ((Main.npc[i].IsABoss() && !isEoWSegment) || MinibossHPBarList.Contains(Main.npc[i].type) || Main.npc[i].Calamity().CanHaveBossHealthBar) - AttemptToAddBar(i); + bool isEoWSegment = n.type == NPCID.EaterofWorldsBody || n.type == NPCID.EaterofWorldsTail; + if ((n.IsABoss() && !isEoWSegment) || MinibossHPBarList.Contains(n.type) || n.Calamity().CanHaveBossHealthBar) + AttemptToAddBar(n.whoAmI); } for (int i = 0; i < Bars.Count; i++) @@ -466,12 +466,12 @@ namespace CalamityMod.UI return life; // Otherwise, check if any of said relationship NPCs are enraged. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!Main.npc[i].active || Main.npc[i].life <= 0 || !OneToMany[NPCType].Contains(Main.npc[i].type)) + if (n.life <= 0 || !OneToMany[NPCType].Contains(n.type)) continue; - life += Main.npc[i].life; + life += n.life; } return life; @@ -498,12 +498,12 @@ namespace CalamityMod.UI return maxLife; // Otherwise, check if any of said relationship NPCs are enraged. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!Main.npc[i].active || Main.npc[i].life <= 0 || !OneToMany[NPCType].Contains(Main.npc[i].type)) + if (n.life <= 0 || !OneToMany[NPCType].Contains(n.type)) continue; - maxLife += Main.npc[i].lifeMax; + maxLife += n.lifeMax; } return maxLife; @@ -524,12 +524,12 @@ namespace CalamityMod.UI return false; // Otherwise, check if any of said relationship NPCs are enraged. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!Main.npc[i].active || Main.npc[i].life <= 0 || !OneToMany[NPCType].Contains(Main.npc[i].type)) + if (n.life <= 0 || !OneToMany[NPCType].Contains(n.type)) continue; - if (Main.npc[i].Calamity().CurrentlyEnraged) + if (n.Calamity().CurrentlyEnraged) return true; } return false; @@ -550,12 +550,12 @@ namespace CalamityMod.UI return false; // Otherwise, check if any of said relationship NPCs are increasing their defense or DR. - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!Main.npc[i].active || Main.npc[i].life <= 0 || !OneToMany[NPCType].Contains(Main.npc[i].type)) + if (n.life <= 0 || !OneToMany[NPCType].Contains(n.type)) continue; - if (Main.npc[i].Calamity().CurrentlyIncreasingDefenseOrDR) + if (n.Calamity().CurrentlyIncreasingDefenseOrDR) return true; } return false; diff --git a/UI/BossRushUI.cs b/UI/BossRushUI.cs index 8b3ae93b96..b431ca9ff2 100644 --- a/UI/BossRushUI.cs +++ b/UI/BossRushUI.cs @@ -39,14 +39,12 @@ namespace CalamityMod.UI { int totalLife = 0; int totalLifeMax = 0; - for (int i = 0; i < Main.npc.Length; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!Main.npc[i].active) - continue; - if (types.Contains(Main.npc[i].type)) + if (types.Contains(n.type)) { - totalLife += Main.npc[i].life; - totalLifeMax += Main.npc[i].lifeMax; + totalLife += n.life; + totalLifeMax += n.lifeMax; } } diff --git a/UI/CalamitasEnchantments/EnchantmentManager.cs b/UI/CalamitasEnchantments/EnchantmentManager.cs index 8b66952b06..afbb994bc5 100644 --- a/UI/CalamitasEnchantments/EnchantmentManager.cs +++ b/UI/CalamitasEnchantments/EnchantmentManager.cs @@ -222,9 +222,9 @@ namespace CalamityMod.UI.CalamitasEnchants player.Calamity().bladeArmEnchant = true; bool armsArePresent = false; int armType = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type != armType || Main.projectile[i].owner != player.whoAmI || !Main.projectile[i].active) + if (p.type != armType || p.owner != player.whoAmI) continue; armsArePresent = true; @@ -282,9 +282,9 @@ namespace CalamityMod.UI.CalamitasEnchants bool orbIsPresent = false; int orbType = ModContent.NPCType(); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].type != orbType || Main.npc[i].target != player.whoAmI || !Main.npc[i].active) + if (n.type != orbType || n.target != player.whoAmI) continue; orbIsPresent = true; diff --git a/UI/DraedonSummoning/CodebreakerUI.Communication.cs b/UI/DraedonSummoning/CodebreakerUI.Communication.cs index 5224045c0d..bfaa365107 100644 --- a/UI/DraedonSummoning/CodebreakerUI.Communication.cs +++ b/UI/DraedonSummoning/CodebreakerUI.Communication.cs @@ -111,6 +111,7 @@ namespace CalamityMod.UI.DraedonSummoning get; set; } + public static float DialogOffYCache = 0; /// diff --git a/UI/MiscTextures/StealthMeterBar.png b/UI/MiscTextures/StealthMeterBar.png index 36d0552574..64a040088c 100644 Binary files a/UI/MiscTextures/StealthMeterBar.png and b/UI/MiscTextures/StealthMeterBar.png differ diff --git a/UI/MiscTextures/StealthMeterBarFull.png b/UI/MiscTextures/StealthMeterBarFull.png index 86048fd097..92f0fe7dc6 100644 Binary files a/UI/MiscTextures/StealthMeterBarFull.png and b/UI/MiscTextures/StealthMeterBarFull.png differ diff --git a/UI/VanillaBossBars/AstrumDeusBossBar.cs b/UI/VanillaBossBars/AstrumDeusBossBar.cs index 24e3b77c0a..3513f1cbc7 100644 --- a/UI/VanillaBossBars/AstrumDeusBossBar.cs +++ b/UI/VanillaBossBars/AstrumDeusBossBar.cs @@ -29,10 +29,9 @@ namespace CalamityMod.UI.VanillaBossBars lifeMax = 0f; // Determine the real health by finding more of itself - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC worm in Main.ActiveNPCs) { - NPC worm = Main.npc[i]; - if (worm.active && worm.type == target.type) + if (worm.type == target.type) { // In Death Mode, every worm must be killed if (CalamityWorld.death) @@ -57,16 +56,8 @@ namespace CalamityMod.UI.VanillaBossBars public bool FindMoreWorms(ref BigProgressBarInfo info) { - for (int i = 0; i < Main.maxNPCs; i++) - { - NPC target = Main.npc[i]; - if (target.active && target.type == NPCType()) - { - info.npcIndexToAimAt = i; - return true; - } - } - return false; + info.npcIndexToAimAt = NPC.FindFirstNPC(ModContent.NPCType()); + return info.npcIndexToAimAt != -1; } } } diff --git a/UI/VanillaBossBars/CeaselessVoidBossBar.cs b/UI/VanillaBossBars/CeaselessVoidBossBar.cs index d472836584..29fb7c446c 100644 --- a/UI/VanillaBossBars/CeaselessVoidBossBar.cs +++ b/UI/VanillaBossBars/CeaselessVoidBossBar.cs @@ -51,10 +51,9 @@ namespace CalamityMod.UI.VanillaBossBars shieldMax = (int)(FalseNPCSegment.lifeMax * ExpectedBallsCounter * (1 - RatioToCombust)); shield -= (int)(FalseNPCSegment.lifeMax * ExpectedBallsCounter * RatioToCombust); - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC part in Main.ActiveNPCs) { - NPC part = Main.npc[i]; - if (part.active && part.type == NPCType()) + if (part.type == NPCType()) shield += part.life; } } diff --git a/UI/VanillaBossBars/CryogenBossBar.cs b/UI/VanillaBossBars/CryogenBossBar.cs index 5202e40a2b..7342cd1913 100644 --- a/UI/VanillaBossBars/CryogenBossBar.cs +++ b/UI/VanillaBossBars/CryogenBossBar.cs @@ -39,10 +39,9 @@ namespace CalamityMod.UI.VanillaBossBars shieldMax = 0f; // Determine the shield health - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC part in Main.ActiveNPCs) { - NPC part = Main.npc[i]; - if (part.active && part.type == NPCType()) + if (part.type == NPCType()) { shield += part.life; shieldMax += part.lifeMax; diff --git a/UI/VanillaBossBars/ExoMechsBossBar.cs b/UI/VanillaBossBars/ExoMechsBossBar.cs index f808cc93fa..2c3a0d0986 100644 --- a/UI/VanillaBossBars/ExoMechsBossBar.cs +++ b/UI/VanillaBossBars/ExoMechsBossBar.cs @@ -79,16 +79,15 @@ namespace CalamityMod.UI.VanillaBossBars lifeMax += FalseNPCSegment.lifeMax; // Find the others - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC ecco in Main.ActiveNPCs) { - NPC ecco = Main.npc[i]; - if (ecco.active && ecco.type == NPCType() && target.type != NPCType()) + if (ecco.type == NPCType() && target.type != NPCType()) life += ecco.life; - if (ecco.active && ecco.type == NPCType() && target.type != NPCType()) + if (ecco.type == NPCType() && target.type != NPCType()) life += ecco.life; - if (ecco.active && ecco.type == NPCType() && target.type != NPCType()) + if (ecco.type == NPCType() && target.type != NPCType()) life += ecco.life; } } @@ -97,9 +96,8 @@ namespace CalamityMod.UI.VanillaBossBars public void ValidateAllMechs(ref BigProgressBarInfo info) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC target in Main.ActiveNPCs) { - NPC target = Main.npc[i]; // Find out first whether or not each of the mechs are in hiding if (target.type == NPCType()) HideAres = target.Opacity < 0.5f; diff --git a/UI/VanillaBossBars/LeviathanAnahitaBossBar.cs b/UI/VanillaBossBars/LeviathanAnahitaBossBar.cs index f0dc0a389c..070058dcf8 100644 --- a/UI/VanillaBossBars/LeviathanAnahitaBossBar.cs +++ b/UI/VanillaBossBars/LeviathanAnahitaBossBar.cs @@ -36,11 +36,10 @@ namespace CalamityMod.UI.VanillaBossBars lifeMax = target.lifeMax; // Find the partner in question - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC wife in Main.ActiveNPCs) { - NPC wife = Main.npc[i]; int targetCouple = target.type == NPCType() ? NPCType() : NPCType(); - if (wife.active && wife.type == targetCouple) + if (wife.type == targetCouple) { life += wife.life; lifeMax += wife.lifeMax; @@ -54,10 +53,9 @@ namespace CalamityMod.UI.VanillaBossBars // Determine Anahita's shield health only if she's solo (she can't just block Leviathan out of existence) if (target.type == NPCType() && !NPC.AnyNPCs(NPCType())) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC part in Main.ActiveNPCs) { - NPC part = Main.npc[i]; - if (part.active && part.type == NPCType()) + if (part.type == NPCType()) { shield += part.life; shieldMax += part.lifeMax; @@ -69,17 +67,16 @@ namespace CalamityMod.UI.VanillaBossBars public bool FindTheRightFish(ref BigProgressBarInfo info) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC target in Main.ActiveNPCs) { - NPC target = Main.npc[i]; if (target.active && target.type == NPCType()) { - info.npcIndexToAimAt = i; + info.npcIndexToAimAt = target.whoAmI; return true; } else if (target.active && target.type == NPCType()) { - info.npcIndexToAimAt = i; + info.npcIndexToAimAt = target.whoAmI; return true; } } diff --git a/UI/VanillaBossBars/RavagerBossBar.cs b/UI/VanillaBossBars/RavagerBossBar.cs index 39028612e5..eabbef027c 100644 --- a/UI/VanillaBossBars/RavagerBossBar.cs +++ b/UI/VanillaBossBars/RavagerBossBar.cs @@ -46,10 +46,9 @@ namespace CalamityMod.UI.VanillaBossBars } // Determine the current health of the parts - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC part in Main.ActiveNPCs) { - NPC part = Main.npc[i]; - if (part.active && RavagerParts.Contains(part.type)) + if (RavagerParts.Contains(part.type)) { life += part.life; } @@ -59,16 +58,8 @@ namespace CalamityMod.UI.VanillaBossBars public bool FindRavagerBody(ref BigProgressBarInfo info) { - for (int i = 0; i < Main.maxNPCs; i++) - { - NPC target = Main.npc[i]; - if (target.active && target.type == NPCType()) - { - info.npcIndexToAimAt = i; - return true; - } - } - return false; + info.npcIndexToAimAt = NPC.FindFirstNPC(ModContent.NPCType()); + return info.npcIndexToAimAt != -1; } } } diff --git a/UI/VanillaBossBars/SlimeGodBossBar.cs b/UI/VanillaBossBars/SlimeGodBossBar.cs index 33f8670457..fb329da1ff 100644 --- a/UI/VanillaBossBars/SlimeGodBossBar.cs +++ b/UI/VanillaBossBars/SlimeGodBossBar.cs @@ -44,10 +44,9 @@ namespace CalamityMod.UI.VanillaBossBars lifeMax += FalseNPCSegment.lifeMax; // Determine the current health of each slime - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC part in Main.ActiveNPCs) { - NPC part = Main.npc[i]; - if (part.active && SlimeGodSlimes.Contains(part.type)) + if (SlimeGodSlimes.Contains(part.type)) { life += part.life; } diff --git a/Utilities/DropHelper.cs b/Utilities/DropHelper.cs index 5cbc22d183..88a518df31 100644 --- a/Utilities/DropHelper.cs +++ b/Utilities/DropHelper.cs @@ -212,16 +212,15 @@ namespace CalamityMod int r = wormHead.whoAmI; float minDist = 1E+06f; - for (int i = 0; i < Main.npc.Length; ++i) + foreach (NPC n in Main.ActiveNPCs) { - NPC n = Main.npc[i]; - if (n != null && n.active && idsToCheck.Contains(n.type)) + if (idsToCheck.Contains(n.type)) { float dist = (n.Center - playerPos).Length(); if (dist < minDist) { minDist = dist; - r = i; + r = n.whoAmI; } } } @@ -545,10 +544,9 @@ namespace CalamityMod public static IItemDropRuleCondition AnglerFedToTrasherCondition = If((info) => { bool trasherNearby = false; - for (int i = 0; i < Main.maxNPCs; ++i) + foreach (NPC nearby in Main.ActiveNPCs) { - NPC nearby = Main.npc[i]; - if (nearby is null || !nearby.active || nearby.type != ModContent.NPCType()) + if (nearby.type != ModContent.NPCType()) continue; if (info.npc.Distance(nearby.Center) < TrasherEatDistance) { @@ -559,71 +557,69 @@ namespace CalamityMod return trasherNearby; }); // The text is a separate rule so it doesn't show up on the non-Trasher Fishing Rod drop which only occurs if the Angler is not fed to a Trasher - public static IItemDropRuleCondition TrasherText = If((info) => true, true, CalamityUtils.GetTextValue("Condition.Drops.TrasherKill")); + public static IItemDropRuleCondition TrasherText => CalamityConditions.TrasherTextCondition.ToDropCondition(ShowItemDropInUI.Always); // Get Fixed Boi seed drop rule - public static IItemDropRuleCondition GFB = If((info) => Main.zenithWorld, () => Main.zenithWorld, CalamityUtils.GetTextValue("Condition.Drops.IsGFB")); + public static IItemDropRuleCondition GFB => Condition.ZenithWorld.ToDropCondition(ShowItemDropInUI.WhenConditionSatisfied); - public static IItemDropRuleCondition RevNoMaster = If((info) => !Main.masterMode && CalamityWorld.revenge, () => !Main.masterMode && CalamityWorld.revenge, CalamityUtils.GetTextValue("Condition.Drops.IsRev")); - public static IItemDropRuleCondition RevAndMaster = If((info) => Main.masterMode || CalamityWorld.revenge, () => Main.masterMode || CalamityWorld.revenge, () => - { - return Main.masterMode ? Language.GetTextValue("Bestiary_ItemDropConditions.IsMasterMode") : CalamityUtils.GetTextValue("Condition.Drops.IsRev"); - }); + public static IItemDropRuleCondition RevNoMaster => CalamityConditions.InRevengeanceModeNotMasterMode.ToDropCondition(ShowItemDropInUI.WhenConditionSatisfied); + public static IItemDropRuleCondition RevAndMaster => CalamityConditions.InRevengeanceModeOrMasterMode.ToDropCondition(ShowItemDropInUI.WhenConditionSatisfied); #region Boss Defeat Conditionals - public static IItemDropRuleCondition PostKS(bool ui = true) => If(() => NPC.downedSlimeKing, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedKS")); - public static IItemDropRuleCondition PostDS(bool ui = true) => If(() => DownedBossSystem.downedDesertScourge, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedDS")); - public static IItemDropRuleCondition PostEoC(bool ui = true) => If(() => NPC.downedBoss1, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedEoC")); - public static IItemDropRuleCondition PostCrab(bool ui = true) => If(() => DownedBossSystem.downedCrabulon, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedCrab")); - public static IItemDropRuleCondition PostEvil1(bool ui = true) => If(() => NPC.downedBoss2, ui, CalamityUtils.GetTextValue("Condition.Drops.Downed" + (WorldGen.crimson ? "BoC" : "EoW"))); - public static IItemDropRuleCondition PostHM(bool ui = true) => If(() => DownedBossSystem.downedHiveMind, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedHM")); - public static IItemDropRuleCondition PostPerfs(bool ui = true) => If(() => DownedBossSystem.downedPerforator, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedPerfs")); - public static IItemDropRuleCondition PostEvil2(bool ui = true) => If(() => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator, ui, CalamityUtils.GetTextValue("Condition.Drops.Downed" + (WorldGen.crimson ? "Perfs" : "HM"))); - public static IItemDropRuleCondition PostQB(bool ui = true) => If(() => NPC.downedQueenBee, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedQB")); - public static IItemDropRuleCondition PostDeer(bool ui = true) => If(() => NPC.downedDeerclops, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedDeer")); - public static IItemDropRuleCondition PostSkele(bool ui = true) => If(() => NPC.downedBoss3, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedSkele")); - public static IItemDropRuleCondition PostSG(bool ui = true) => If(() => DownedBossSystem.downedSlimeGod, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedSG")); - public static IItemDropRuleCondition Hardmode(bool ui = true) => If(() => Main.hardMode, ui, CalamityUtils.GetTextValue("Condition.Drops.Hardmode")); - public static IItemDropRuleCondition PostQS(bool ui = true) => If(() => NPC.downedQueenSlime, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedQS")); - public static IItemDropRuleCondition PostCryo(bool ui = true) => If(() => DownedBossSystem.downedCryogen, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedCryo")); - public static IItemDropRuleCondition PostAS(bool ui = true) => If(() => DownedBossSystem.downedAquaticScourge, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedAS")); - public static IItemDropRuleCondition PostBrim(bool ui = true) => If(() => DownedBossSystem.downedBrimstoneElemental, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedBrim")); - public static IItemDropRuleCondition PostDest(bool ui = true) => If(() => NPC.downedMechBoss1, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedDest")); - public static IItemDropRuleCondition PostTwins(bool ui = true) => If(() => NPC.downedMechBoss2, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedTwins")); - public static IItemDropRuleCondition PostSP(bool ui = true) => If(() => NPC.downedMechBoss3, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedSP")); - public static IItemDropRuleCondition Post1Mech(bool ui = true) => If(() => NPC.downedMechBossAny, ui, CalamityUtils.GetTextValue("Condition.Drops.Downed1Mech")); - public static IItemDropRuleCondition Post3Mechs(bool ui = true) => If(() => NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3, ui, CalamityUtils.GetTextValue("Condition.Drops.Downed3Mechs")); - public static IItemDropRuleCondition PostCal(bool ui = true) => If(() => DownedBossSystem.downedCalamitasClone, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedCal")); - public static IItemDropRuleCondition PostPlant(bool ui = true) => If(() => NPC.downedPlantBoss, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedPlant")); - public static IItemDropRuleCondition PostLevi(bool ui = true) => If(() => DownedBossSystem.downedLeviathan, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedLebi")); - public static IItemDropRuleCondition PostAureus(bool ui = true) => If(() => DownedBossSystem.downedAstrumAureus, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedAureus")); - public static IItemDropRuleCondition PostGolem(bool ui = true) => If(() => NPC.downedGolemBoss, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedGolem")); - public static IItemDropRuleCondition PostPBG(bool ui = true) => If(() => DownedBossSystem.downedPlaguebringer, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedPBG")); - public static IItemDropRuleCondition PostEoL(bool ui = true) => If(() => NPC.downedEmpressOfLight, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedEoL")); - public static IItemDropRuleCondition PostFish(bool ui = true) => If(() => NPC.downedFishron, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedFish")); - public static IItemDropRuleCondition PostRav(bool ui = true) => If(() => DownedBossSystem.downedRavager, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedRav")); - public static IItemDropRuleCondition PostLC(bool ui = true) => If(() => NPC.downedAncientCultist, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedLC")); - public static IItemDropRuleCondition PostAD(bool ui = true) => If(() => DownedBossSystem.downedAstrumDeus, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedAD")); - public static IItemDropRuleCondition PostML(bool ui = true) => If(() => NPC.downedMoonlord, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedML")); - public static IItemDropRuleCondition PostGuard(bool ui = true) => If(() => DownedBossSystem.downedGuardians, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedGuard")); - public static IItemDropRuleCondition PostBirb(bool ui = true) => If(() => DownedBossSystem.downedDragonfolly, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedBirb")); - public static IItemDropRuleCondition PostProv(bool ui = true) => If(() => DownedBossSystem.downedProvidence, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedProv")); - public static IItemDropRuleCondition PostSig(bool ui = true) => If(() => DownedBossSystem.downedSignus, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedSig")); - public static IItemDropRuleCondition PostSW(bool ui = true) => If(() => DownedBossSystem.downedStormWeaver, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedSW")); - public static IItemDropRuleCondition PostCV(bool ui = true) => If(() => DownedBossSystem.downedCeaselessVoid, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedCV")); - public static IItemDropRuleCondition PostPolter(bool ui = true) => If(() => DownedBossSystem.downedPolterghast, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedPolter")); - public static IItemDropRuleCondition PostOD(bool ui = true) => If(() => DownedBossSystem.downedBoomerDuke, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedOD")); - public static IItemDropRuleCondition PostDoG(bool ui = true) => If(() => DownedBossSystem.downedDoG, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedDoG")); - public static IItemDropRuleCondition PostYharon(bool ui = true) => If(() => DownedBossSystem.downedYharon, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedYharon")); - public static IItemDropRuleCondition PostExos(bool ui = true) => If(() => DownedBossSystem.downedExoMechs, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedExos")); - public static IItemDropRuleCondition PostSCal(bool ui = true) => If(() => DownedBossSystem.downedCalamitas, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedSCal")); - public static IItemDropRuleCondition PostAEW(bool ui = true) => If(() => DownedBossSystem.downedPrimordialWyrm, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedAEW")); - public static IItemDropRuleCondition PostClam(bool ui = true) => If(() => DownedBossSystem.downedCLAM, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedClam")); - public static IItemDropRuleCondition PostClamHM(bool ui = true) => If(() => DownedBossSystem.downedCLAMHardMode, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedClamHM")); - public static IItemDropRuleCondition PostGSS(bool ui = true) => If(() => DownedBossSystem.downedGSS, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedGSS")); - public static IItemDropRuleCondition PostBetsy(bool ui = true) => If(() => DownedBossSystem.downedBetsy, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedBetsy")); - public static IItemDropRuleCondition PostT1AR(bool ui = true) => If(() => DownedBossSystem.downedEoCAcidRain, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedT1AR")); - public static IItemDropRuleCondition PostT2AR(bool ui = true) => If(() => DownedBossSystem.downedAquaticScourgeAcidRain, ui, CalamityUtils.GetTextValue("Condition.Drops.DownedT2AR")); + public static IItemDropRuleCondition PostKS(bool ui = true) => Condition.DownedKingSlime.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostDS(bool ui = true) => CalamityConditions.DownedDesertScourge.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostEoC(bool ui = true) => Condition.DownedEyeOfCthulhu.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostCrab(bool ui = true) => CalamityConditions.DownedCrabulon.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostEvil1(bool ui = true) => Condition.DownedEowOrBoc.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostHM(bool ui = true) => CalamityConditions.DownedHiveMind.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostPerfs(bool ui = true) => CalamityConditions.DownedPerforator.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostEvil2(bool ui = true) => CalamityConditions.DownedHiveMindOrPerforator.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostQB(bool ui = true) => Condition.DownedQueenBee.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostDeer(bool ui = true) => Condition.DownedDeerclops.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostSkele(bool ui = true) => Condition.DownedSkeletron.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostSG(bool ui = true) => CalamityConditions.DownedSlimeGod.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition Hardmode(bool ui = true) => Condition.Hardmode.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostQS(bool ui = true) => Condition.DownedQueenSlime.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostCryo(bool ui = true) => CalamityConditions.DownedCryogen.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostAS(bool ui = true) => CalamityConditions.DownedAquaticScourge.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostBrim(bool ui = true) => CalamityConditions.DownedBrimstoneElemental.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostDest(bool ui = true) => Condition.DownedDestroyer.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostTwins(bool ui = true) => Condition.DownedTwins.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostSP(bool ui = true) => Condition.DownedSkeletronPrime.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition Post1Mech(bool ui = true) => Condition.DownedMechBossAny.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition Post3Mechs(bool ui = true) => Condition.DownedMechBossAll.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostCal(bool ui = true) => CalamityConditions.DownedCalamitasClone.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostPlant(bool ui = true) => Condition.DownedPlantera.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostCalPlant(bool ui = true) => CalamityConditions.DownedCalamitasCloneOrPlantera.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostLevi(bool ui = true) => CalamityConditions.DownedLeviathan.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostAureus(bool ui = true) => CalamityConditions.DownedAstrumAureus.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostGolem(bool ui = true) => Condition.DownedGolem.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostPBG(bool ui = true) => CalamityConditions.DownedPlaguebringer.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostEoL(bool ui = true) => Condition.DownedEmpressOfLight.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostFish(bool ui = true) => Condition.DownedDukeFishron.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostRav(bool ui = true) => CalamityConditions.DownedRavager.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostLC(bool ui = true) => Condition.DownedCultist.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostAD(bool ui = true) => CalamityConditions.DownedAstrumDeus.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostML(bool ui = true) => Condition.DownedMoonLord.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostGuard(bool ui = true) => CalamityConditions.DownedGuardians.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostBirb(bool ui = true) => CalamityConditions.DownedBumblebird.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostProv(bool ui = true) => CalamityConditions.DownedProvidence.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostSig(bool ui = true) => CalamityConditions.DownedSignus.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostSW(bool ui = true) => CalamityConditions.DownedStormWeaver.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostCV(bool ui = true) => CalamityConditions.DownedCeaselessVoid.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostPolter(bool ui = true) => CalamityConditions.DownedPolterghast.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostOD(bool ui = true) => CalamityConditions.DownedOldDuke.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostDoG(bool ui = true) => CalamityConditions.DownedDevourerOfGods.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostYharon(bool ui = true) => CalamityConditions.DownedYharon.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostExos(bool ui = true) => CalamityConditions.DownedExoMechs.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostSCal(bool ui = true) => CalamityConditions.DownedSupremeCalamitas.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostAEW(bool ui = true) => CalamityConditions.DownedPrimordialWyrm.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostClam(bool ui = true) => CalamityConditions.DownedClam.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostClamHM(bool ui = true) => CalamityConditions.DownedBuffedClam.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostGSS(bool ui = true) => CalamityConditions.DownedGreatSandShark.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostBetsy(bool ui = true) => CalamityConditions.DownedBetsy.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostT1AR(bool ui = true) => CalamityConditions.DownedAcidRainT1.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); + public static IItemDropRuleCondition PostT2AR(bool ui = true) => CalamityConditions.DownedAcidRainT2.ToDropCondition(ui ? ShowItemDropInUI.Always : ShowItemDropInUI.Never); #endregion #endregion @@ -1163,9 +1159,8 @@ namespace CalamityMod NPC npc = info.npc; int idx = Item.NewItem(npc.GetSource_Loot(), npc.Center, itemId, stack, true, -1); Main.timeItemSlotCannotBeReusedFor[idx] = protectionTime; - for (int i = 0; i < Main.maxPlayers; ++i) - if (Main.player[i].active) - NetMessage.SendData(MessageID.InstancedItem, i, -1, null, idx); + foreach (Player player in Main.ActivePlayers) + NetMessage.SendData(MessageID.InstancedItem, player.whoAmI, -1, null, idx); Main.item[idx].active = false; } diff --git a/Utilities/NPCUtils.cs b/Utilities/NPCUtils.cs index 84aa4a19d2..b7bc443738 100644 --- a/Utilities/NPCUtils.cs +++ b/Utilities/NPCUtils.cs @@ -38,9 +38,9 @@ namespace CalamityMod return 0; int count = 0; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (!typesToCheck.Contains(Main.npc[i].type) || !Main.npc[i].active) + if (!typesToCheck.Contains(n.type)) continue; count++; @@ -174,18 +174,14 @@ namespace CalamityMod public static bool AnyBossNPCS(bool checkForMechs = false) { - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - if (Main.npc[i] != null) + if (npc.IsABoss()) { - NPC npc = Main.npc[i]; - if (npc.IsABoss()) - { - // Added due to the new mech boss ore progression, return true if any mech is alive and checkForMechs is true, reduces mech boss projectile damage if true. - if (checkForMechs) - return npc.type == NPCID.TheDestroyer || npc.type == NPCID.SkeletronPrime || npc.type == NPCID.Spazmatism || npc.type == NPCID.Retinazer; - return true; - } + // Added due to the new mech boss ore progression, return true if any mech is alive and checkForMechs is true, reduces mech boss projectile damage if true. + if (checkForMechs) + return npc.type == NPCID.TheDestroyer || npc.type == NPCID.SkeletronPrime || npc.type == NPCID.Spazmatism || npc.type == NPCID.Retinazer; + return true; } } return FindFirstProjectile(ProjectileType()) != -1; @@ -495,12 +491,11 @@ namespace CalamityMod return; Projectile projectile = null; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - projectile = Main.projectile[i]; - if (Main.projectile[i].active && Main.projectile[i].bobber && Main.projectile[i].owner == playerIndex) + if (p.bobber && p.owner == playerIndex) { - projectile = Main.projectile[i]; + projectile = p; break; } } diff --git a/Utilities/ProjectileUtils.cs b/Utilities/ProjectileUtils.cs index 0a34629ef5..ff127a3de6 100644 --- a/Utilities/ProjectileUtils.cs +++ b/Utilities/ProjectileUtils.cs @@ -22,10 +22,9 @@ namespace CalamityMod { // Efficiently loop through all projectiles, using a specially designed continue continue that attempts to minimize the amount of OR // checks per iteration. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.type != projectileID || !p.active) + if (p.type != projectileID) continue; return true; @@ -37,10 +36,9 @@ namespace CalamityMod public static IEnumerable AllProjectilesByID(int projectileID) { // This uses the same efficient loop idea as AnyProjectiles. - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p.type != projectileID || !p.active) + if (p.type != projectileID) continue; yield return p; @@ -71,12 +69,12 @@ namespace CalamityMod if (Main.netMode == NetmodeID.SinglePlayer) return Main.projectile[identity]; - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].identity != identity || Main.projectile[i].owner != ownerIndex || !Main.projectile[i].active) + if (p.identity != identity || p.owner != ownerIndex) continue; - return Main.projectile[i]; + return p; } return null; } @@ -111,8 +109,8 @@ namespace CalamityMod int index = -1; for (int i = 0; i < Main.maxNPCs; i++) { - float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2); - if (!Main.npc[i].CanBeChasedBy(projectile, false) || !projectile.WithinRange(Main.npc[i].Center, maxDistance + extraDistance)) + float extraDistance = (n.width / 2) + (n.height / 2); + if (!n.CanBeChasedBy(projectile, false) || !projectile.WithinRange(n.Center, maxDistance + extraDistance)) continue; float currentNPCDist = Vector2.Distance(Main.npc[i].Center, projectile.Center); @@ -276,9 +274,8 @@ namespace CalamityMod int[] array = new int[Main.maxNPCs]; int targetArrayA = 0; int targetArrayB = 0; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC npc in Main.ActiveNPCs) { - NPC npc = Main.npc[i]; if (npc.CanBeChasedBy(projectile, false)) { float enemyDist = Vector2.Distance(projectile.Center, npc.Center); @@ -286,12 +283,12 @@ namespace CalamityMod { if (Collision.CanHit(projectile.position, 1, 1, npc.position, npc.width, npc.height) && enemyDist > 50f) { - array[targetArrayB] = i; + array[targetArrayB] = npc.whoAmI; targetArrayB++; } else if (targetArrayB == 0) { - array[targetArrayA] = i; + array[targetArrayA] = npc.whoAmI; targetArrayA++; } } @@ -322,21 +319,21 @@ namespace CalamityMod int[] targetArray = new int[maxTargets]; int targetArrayIndex = 0; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { - if (Main.npc[i].CanBeChasedBy(projectile, false)) + if (n.CanBeChasedBy(projectile, false)) { - float extraDistance = (Main.npc[i].width / 2) + (Main.npc[i].height / 2); + float extraDistance = (n.width / 2) + (n.height / 2); bool canHit = true; if (extraDistance < maxDistance) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[i].Center, 1, 1); + canHit = Collision.CanHit(projectile.Center, 1, 1, n.Center, 1, 1); - if (projectile.WithinRange(Main.npc[i].Center, maxDistance + extraDistance) && canHit) + if (projectile.WithinRange(n.Center, maxDistance + extraDistance) && canHit) { if (targetArrayIndex < maxTargets) { - targetArray[targetArrayIndex] = i; + targetArray[targetArrayIndex] = n.whoAmI; targetArrayIndex++; homeIn = true; } @@ -575,13 +572,12 @@ namespace CalamityMod int existingTurrets = player.ownedProjectileCounts[Type]; if (existingTurrets > 0) { - for (int i = 0; i < Main.maxProjectiles; i++) + foreach (Projectile p in Main.ActiveProjectiles) { - if (Main.projectile[i].type == Type && - Main.projectile[i].owner == player.whoAmI && - Main.projectile[i].active) + if (p.type == Type && + p.owner == player.whoAmI) { - Main.projectile[i].Kill(); + p.Kill(); existingTurrets--; if (existingTurrets <= 0) break; diff --git a/Utilities/RicoshotUtils.cs b/Utilities/RicoshotUtils.cs index f79a060cc9..697fba3fc1 100644 --- a/Utilities/RicoshotUtils.cs +++ b/Utilities/RicoshotUtils.cs @@ -32,10 +32,9 @@ namespace CalamityMod int count = 0; int id = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile p in Main.ActiveProjectiles) { - Projectile p = Main.projectile[i]; - if (p is null || !p.active || p.owner != player.whoAmI) + if (p.owner != player.whoAmI) continue; if (p.type == id) ++count; @@ -98,10 +97,9 @@ namespace CalamityMod // Search for all nearby coins. // Coins do not necessarily have to be owned by the same player as the searching projectile! int coinID = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (!proj.active || proj.ModProjectile is null || proj.type != coinID) + if (proj.ModProjectile is null || proj.type != coinID) continue; // Coins that have already been struck are ignored. @@ -173,10 +171,9 @@ namespace CalamityMod bool foundAnyBullseye = false; float closestBullseyeDistance = DaawnlightSpiritOrigin.RicoshotSearchDistance; int bullseyeID = ModContent.ProjectileType(); - for (int i = 0; i < Main.maxProjectiles; ++i) + foreach (Projectile proj in Main.ActiveProjectiles) { - Projectile proj = Main.projectile[i]; - if (proj is null || !proj.active || proj.ModProjectile is null || proj.type != bullseyeID || proj.owner != theShot.owner) + if (proj.ModProjectile is null || proj.type != bullseyeID || proj.owner != theShot.owner) continue; // Do a distance check. diff --git a/World/AstralBiome.cs b/World/AstralBiome.cs index dd83cb6b9d..bc1389ee03 100644 --- a/World/AstralBiome.cs +++ b/World/AstralBiome.cs @@ -83,13 +83,10 @@ namespace CalamityMod.World // Clients in multiplayer don't drop meteors. if (Main.netMode == NetmodeID.MultiplayerClient) return; - for (int i = 0; i < 255; i++) + foreach (Player _ in Main.ActivePlayers) { - if (Main.player[i].active) - { - meteorDropped = false; - break; - } + meteorDropped = false; + break; } // Check whether there is already too much ore. @@ -277,11 +274,11 @@ namespace CalamityMod.World } int avoidRectangleSize = 35; Rectangle rectangle = new Rectangle((i - avoidRectangleSize) * 16, (j - avoidRectangleSize) * 16, avoidRectangleSize * 2 * 16, avoidRectangleSize * 2 * 16); - for (int k = 0; k < Main.maxPlayers; k++) + foreach (Player player in Main.ActivePlayers) { - if (Main.player[k].active) + if (player.active) { - Rectangle value = new Rectangle((int)(Main.player[k].position.X + (float)(Main.player[k].width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.player[k].position.Y + (float)(Main.player[k].height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); + Rectangle value = new Rectangle((int)(player.position.X + (float)(player.width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(player.position.Y + (float)(player.height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2); if (rectangle.Intersects(value)) { return false;