diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index a8c0fc5775..075c4c06a7 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4715,23 +4715,23 @@ namespace CalamityMod.CalPlayer if (Player.whoAmI == Main.myPlayer && !endoCooper && randAmt > 0 && Main.rand.NextBool(randAmt) && chaseable) { 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/CalamityPlayerHitHurt.cs b/CalPlayer/CalamityPlayerHitHurt.cs index b84a070442..8f86221423 100644 --- a/CalPlayer/CalamityPlayerHitHurt.cs +++ b/CalPlayer/CalamityPlayerHitHurt.cs @@ -2307,11 +2307,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 b99288c74d..c1be6e8b04 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -858,12 +858,12 @@ 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]); } foreach (NPC target in Main.ActiveNPCs) @@ -1131,10 +1131,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; } @@ -3347,11 +3346,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; } } @@ -3383,12 +3382,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; } } @@ -3406,12 +3405,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; } } 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/Graphics/Primitives/PrimitivePixelationSystem.cs b/Graphics/Primitives/PrimitivePixelationSystem.cs index ad2a82fc40..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 { diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 01a4f20dc6..620eefd8f0 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -724,12 +724,9 @@ 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); } diff --git a/Items/Accessories/NebulousCore.cs b/Items/Accessories/NebulousCore.cs index bc9c165501..b5fc4b712e 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/WulfrumAcrobaticsPack.cs b/Items/Accessories/WulfrumAcrobaticsPack.cs index c25f090ead..a03fba6af5 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/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index d1bf4f9242..151fc33d72 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -531,11 +531,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) @@ -674,9 +674,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; @@ -684,22 +684,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; } } } @@ -707,13 +707,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; } } @@ -724,18 +724,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/Tools/WulfrumDiggingTurtle.cs b/Items/Tools/WulfrumDiggingTurtle.cs index 95718e8b63..7018324832 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 dede135af4..2e8d1edb0a 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 931e3562c0..5c78b117de 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/Exoblade.cs b/Items/Weapons/Melee/Exoblade.cs index 0576af4659..743d745de3 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 d87044c85b..bd9e55241f 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/Hydra.cs b/Items/Weapons/Ranged/Hydra.cs index e3605d5f86..24683fe27e 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/Rogue/Nychthemeron.cs b/Items/Weapons/Rogue/Nychthemeron.cs index c2ea5bae27..55c9228905 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 87a880fec0..922f06a10f 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/Summon/AresExoskeleton.cs b/Items/Weapons/Summon/AresExoskeleton.cs index cbf43d0fc4..2734afd15e 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 662054a9d7..01a536adff 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;