From bb77d53b0ca0f9bb648ccf3954dd7b24e06118bb Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Mon, 13 May 2024 22:11:02 -0400 Subject: [PATCH] Fix numerous compilation errors caused by botched entity iterator merge. --- CalPlayer/CalamityPlayerOnHit.cs | 2 +- CalPlayer/DrawLayers/AndromedaMechLayer.cs | 2 +- Graphics/Metaballs/GruesomeMetaball.cs | 8 ++++++-- Items/Potions/TeslaPotion.cs | 3 +-- .../en-US/Mods.CalamityMod.Condition.hjson | 2 +- NPCs/ExoMechs/Thanatos/ThanatosBody2.cs | 2 +- NPCs/PlagueEnemies/PlaguebringerMiniboss.cs | 1 - .../RegularEnemies/RevengeanceAndDeathAI.cs | 8 ++++---- Projectiles/CalamityGlobalProjectile.cs | 2 +- Projectiles/Summon/EndoIceShard.cs | 2 +- Utilities/ProjectileUtils.cs | 20 ++++--------------- 11 files changed, 21 insertions(+), 31 deletions(-) diff --git a/CalPlayer/CalamityPlayerOnHit.cs b/CalPlayer/CalamityPlayerOnHit.cs index 1272e6e3f9..2b07be737a 100644 --- a/CalPlayer/CalamityPlayerOnHit.cs +++ b/CalPlayer/CalamityPlayerOnHit.cs @@ -1463,7 +1463,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 e15b7c80df..cbf5c7c409 100644 --- a/CalPlayer/DrawLayers/AndromedaMechLayer.cs +++ b/CalPlayer/DrawLayers/AndromedaMechLayer.cs @@ -38,7 +38,7 @@ namespace CalamityMod.CalPlayer.DrawLayers { if (p.type == andromedaMechID && p.owner == drawPlayer.whoAmI) { - robot = i; + robot = p.whoAmI; break; } } diff --git a/Graphics/Metaballs/GruesomeMetaball.cs b/Graphics/Metaballs/GruesomeMetaball.cs index f1d273a344..3a67d24c7c 100644 --- a/Graphics/Metaballs/GruesomeMetaball.cs +++ b/Graphics/Metaballs/GruesomeMetaball.cs @@ -136,8 +136,12 @@ namespace CalamityMod.Graphics.Metaballs } // Draw gruesome eminence ghost heads. - foreach (Projectile eminence in CalamityUtils.AllProjectilesByID(ModContent.ProjectileType())) - eminence.ModProjectile().DrawHeadForMetaball(); + int eminenceType = ModContent.ProjectileType(); + foreach (Projectile p in Main.ActiveProjectiles) + { + if (p.type == eminenceType) + p.ModProjectile().DrawHeadForMetaball(); + } } } } diff --git a/Items/Potions/TeslaPotion.cs b/Items/Potions/TeslaPotion.cs index c2d8e0142b..1fa1a540b3 100644 --- a/Items/Potions/TeslaPotion.cs +++ b/Items/Potions/TeslaPotion.cs @@ -38,7 +38,6 @@ namespace CalamityMod.Items.Potions public override void AddRecipes() { - Condition evil2Dead = new(CalamityUtils.GetText("Condition.DownedEvil2Boss"), () => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator); CreateRecipe(5). AddIngredient(ItemID.BottledWater). AddIngredient(2). @@ -46,7 +45,7 @@ namespace CalamityMod.Items.Potions AddIngredient(). AddIngredient(). AddTile(TileID.Bottles). - AddDecraftCondition(evil2Dead). + AddDecraftCondition(CalamityConditions.DownedHiveMindOrPerforator). Register(); CreateRecipe(). diff --git a/Localization/en-US/Mods.CalamityMod.Condition.hjson b/Localization/en-US/Mods.CalamityMod.Condition.hjson index 6dbe1feb52..844e15ed3e 100644 --- a/Localization/en-US/Mods.CalamityMod.Condition.hjson +++ b/Localization/en-US/Mods.CalamityMod.Condition.hjson @@ -5,7 +5,7 @@ Drops: { DownedCrab: After defeating Crabulon DownedHM: After defeating the Hive Mind DownedPerfs: After defeating the Perforators - DownedHMOrPerfs: After defeating the Hive Mind or 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 diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs index 087418c40c..76c6275344 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs @@ -290,7 +290,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos 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/PlagueEnemies/PlaguebringerMiniboss.cs b/NPCs/PlagueEnemies/PlaguebringerMiniboss.cs index 97213f3c1d..d8abae06ac 100644 --- a/NPCs/PlagueEnemies/PlaguebringerMiniboss.cs +++ b/NPCs/PlagueEnemies/PlaguebringerMiniboss.cs @@ -92,7 +92,6 @@ namespace CalamityMod.NPCs.PlagueEnemies { if (NPC.timeLeft < 750) NPC.timeLeft = 750; - } } int playerAmt = Main.CurrentFrameFlags.ActivePlayersCount; diff --git a/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs b/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs index 218a4643c2..b8d7686a30 100644 --- a/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs +++ b/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs @@ -2186,7 +2186,7 @@ PrepareToShoot: } foreach (NPC n in Main.ActiveNPCs) { - 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 (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 < n.position.X) { @@ -2262,7 +2262,7 @@ PrepareToShoot: } foreach (NPC n in Main.ActiveNPCs) { - 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 (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 < n.position.X) { @@ -10706,7 +10706,7 @@ PrepareToShoot: foreach (NPC n in Main.ActiveNPCs) { - if (i == npc.whoAmI || n.type != npc.type) + if (n.whoAmI == npc.whoAmI || n.type != npc.type) continue; Vector2 targetDirection = n.Center - npc.Center; @@ -10716,7 +10716,7 @@ PrepareToShoot: targetDirection.Normalize(); if (targetDirection.X == 0f && targetDirection.Y == 0f) { - if (i > npc.whoAmI) + if (n.whoAmI > npc.whoAmI) targetDirection.X = 1f; else targetDirection.X = -1f; diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index f48741ddd9..83f8b28779 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -4898,7 +4898,7 @@ namespace CalamityMod.Projectiles if (playerDist < distanceRequired && (otherPlayer.statLifeMax2 - otherPlayer.statLife) > lowestHealthCheck) { lowestHealthCheck = otherPlayer.statLifeMax2 - otherPlayer.statLife; - healTarget = i; + healTarget = otherPlayer.whoAmI; } } } diff --git a/Projectiles/Summon/EndoIceShard.cs b/Projectiles/Summon/EndoIceShard.cs index 117e8183ef..9d87d5f665 100644 --- a/Projectiles/Summon/EndoIceShard.cs +++ b/Projectiles/Summon/EndoIceShard.cs @@ -87,7 +87,7 @@ namespace CalamityMod.Projectiles.Summon float dist = (Projectile.Center - npc.Center).Length(); if (dist < maxHomingRange) { - targetIdx = i; + targetIdx = npc.whoAmI; maxHomingRange = dist; hasHomingTarget = true; } diff --git a/Utilities/ProjectileUtils.cs b/Utilities/ProjectileUtils.cs index ff127a3de6..8d3a596706 100644 --- a/Utilities/ProjectileUtils.cs +++ b/Utilities/ProjectileUtils.cs @@ -33,18 +33,6 @@ namespace CalamityMod return false; } - public static IEnumerable AllProjectilesByID(int projectileID) - { - // This uses the same efficient loop idea as AnyProjectiles. - foreach (Projectile p in Main.ActiveProjectiles) - { - if (p.type != projectileID) - continue; - - yield return p; - } - } - public static int CountProjectiles(int projectileID) => Main.projectile.Count(proj => proj.type == projectileID && proj.active); public static int CountHookProj() => Main.projectile.Count(proj => Main.projHook[proj.type] && proj.ai[0] == 2f && proj.active && proj.owner == Main.myPlayer); @@ -107,17 +95,17 @@ namespace CalamityMod // Find the closest target. float npcDistCompare = 25000f; // Initializing the value to a large number so the first entry is basically guaranteed to replace it. int index = -1; - for (int i = 0; i < Main.maxNPCs; i++) + foreach (NPC n in Main.ActiveNPCs) { 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); - if ((currentNPCDist < npcDistCompare) && (ignoreTiles || Collision.CanHit(projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))) + float currentNPCDist = Vector2.Distance(n.Center, projectile.Center); + if ((currentNPCDist < npcDistCompare) && (ignoreTiles || Collision.CanHit(projectile.Center, 1, 1, n.Center, 1, 1))) { npcDistCompare = currentNPCDist; - index = i; + index = n.whoAmI; } } // If the index was never changed, don't do anything. Otherwise, tell the projectile where to home.