diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index a096508ead..bc0e838ea4 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -5681,17 +5681,20 @@ namespace CalamityMod.CalPlayer if (Player.whoAmI == Main.myPlayer) { // Summon a portal if needed. - if (Player.Calamity().persecutedEnchant && NPC.CountNPCS(ModContent.NPCType()) < 2) + if (Player.Calamity().persecutedEnchant) { - int tries = 0; - Vector2 spawnPosition; - do + if (NPC.CountNPCS(ModContent.NPCType()) < 2) { - spawnPosition = Player.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(270f, 420f); - tries++; + int tries = 0; + Vector2 spawnPosition; + do + { + spawnPosition = Player.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(270f, 420f); + tries++; + } + while (Collision.SolidCollision(spawnPosition - Vector2.One * 24f, 48, 24) && tries < 100); + CalamityNetcode.NewNPC_ClientSide(spawnPosition, ModContent.NPCType(), Player); } - while (Collision.SolidCollision(spawnPosition - Vector2.One * 24f, 48, 24) && tries < 100); - CalamityNetcode.NewNPC_ClientSide(spawnPosition, ModContent.NPCType(), Player); } if (daedalusAbsorb && Main.rand.NextBool(10)) diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 22ebb0643c..a3ec4fe84e 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -1259,17 +1259,20 @@ namespace CalamityMod.CalPlayer else { persecutedEnchantSummonTimer = 0; - if (Main.myPlayer == Player.whoAmI && persecutedEnchant && NPC.CountNPCS(ModContent.NPCType()) < 2) + if (Main.myPlayer == Player.whoAmI && persecutedEnchant) { - int tries = 0; - Vector2 spawnPosition; - do + if (NPC.CountNPCS(ModContent.NPCType()) < 2) { - spawnPosition = Player.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(270f, 420f); - tries++; + int tries = 0; + Vector2 spawnPosition; + do + { + spawnPosition = Player.Center + Main.rand.NextVector2Unit() * Main.rand.NextFloat(270f, 420f); + tries++; + } + while (Collision.SolidCollision(spawnPosition - Vector2.One * 24f, 48, 24) && tries < 100); + CalamityNetcode.NewNPC_ClientSide(spawnPosition, ModContent.NPCType(), Player); } - while (Collision.SolidCollision(spawnPosition - Vector2.One * 24f, 48, 24) && tries < 100); - CalamityNetcode.NewNPC_ClientSide(spawnPosition, ModContent.NPCType(), Player); } } if (Player.miscCounter % 20 == 0) diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index fead8e1325..8b86e9e46a 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -240,10 +240,13 @@ namespace CalamityMod.Items public override bool Shoot(Item item, Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockBack) { CalamityPlayer modPlayer = player.Calamity(); - if (Main.myPlayer == player.whoAmI && player.Calamity().cursedSummonsEnchant && NPC.CountNPCS(ModContent.NPCType()) < 2) + if (Main.myPlayer == player.whoAmI && player.Calamity().cursedSummonsEnchant) { - CalamityNetcode.NewNPC_ClientSide(Main.MouseWorld, ModContent.NPCType(), player); - SoundEngine.PlaySound(SoundID.DD2_DarkMageSummonSkeleton, Main.MouseWorld); + if (NPC.CountNPCS(ModContent.NPCType()) < 2) + { + CalamityNetcode.NewNPC_ClientSide(Main.MouseWorld, ModContent.NPCType(), player); + SoundEngine.PlaySound(SoundID.DD2_DarkMageSummonSkeleton, Main.MouseWorld); + } } // Traitorous enchantment implementation diff --git a/NPCs/Abyss/Bloatfish.cs b/NPCs/Abyss/Bloatfish.cs index f05e826e48..943294f0dd 100644 --- a/NPCs/Abyss/Bloatfish.cs +++ b/NPCs/Abyss/Bloatfish.cs @@ -183,9 +183,8 @@ namespace CalamityMod.NPCs.Abyss public override float SpawnChance(NPCSpawnInfo spawnInfo) { if (spawnInfo.Player.Calamity().ZoneAbyssLayer4 && spawnInfo.Water && NPC.CountNPCS(ModContent.NPCType()) < 3) - { return Main.remixWorld ? 4.5f : SpawnCondition.CaveJellyfish.Chance * 0.5f; - } + return 0f; } diff --git a/NPCs/Astral/HiveEnemy.cs b/NPCs/Astral/HiveEnemy.cs index edb234c175..708edd5708 100644 --- a/NPCs/Astral/HiveEnemy.cs +++ b/NPCs/Astral/HiveEnemy.cs @@ -70,14 +70,17 @@ namespace CalamityMod.NPCs.Astral NPC.ai[0]++; if (NPC.ai[0] > (CalamityWorld.death ? 60f : CalamityWorld.revenge ? 120f : 180f)) { - if (Main.rand.NextBool(100) && NPC.CountNPCS(ModContent.NPCType()) < 10) + if (Main.rand.NextBool(100)) { - NPC.ai[0] = 0; + if (NPC.CountNPCS(ModContent.NPCType()) < 10) + { + NPC.ai[0] = 0; - //spawn hiveling, it's ai[0] is the hive npc index. - int n = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType(), 0, NPC.whoAmI); - Main.npc[n].velocity.X = Main.rand.NextFloat(-0.4f, 0.4f); - Main.npc[n].velocity.Y = Main.rand.NextFloat(-0.5f, -0.05f); + // Spawn hiveling, it's ai[0] is the hive npc index. + int n = NPC.NewNPC(NPC.GetSource_FromAI(), (int)NPC.Center.X, (int)NPC.Center.Y, ModContent.NPCType(), 0, NPC.whoAmI); + Main.npc[n].velocity.X = Main.rand.NextFloat(-0.4f, 0.4f); + Main.npc[n].velocity.Y = Main.rand.NextFloat(-0.5f, -0.05f); + } } } } @@ -98,7 +101,7 @@ namespace CalamityMod.NPCs.Astral public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { - //draw glowmask + // Draw glowmask. spriteBatch.Draw(glowmask, NPC.Center - screenPos, NPC.frame, Color.White * 0.6f, NPC.rotation, new Vector2(19, 30), 1f, NPC.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); } diff --git a/NPCs/SulphurousSea/AquaticUrchin.cs b/NPCs/SulphurousSea/AquaticUrchin.cs index 5bc86e4812..a90d2d0b56 100644 --- a/NPCs/SulphurousSea/AquaticUrchin.cs +++ b/NPCs/SulphurousSea/AquaticUrchin.cs @@ -136,14 +136,11 @@ namespace CalamityMod.NPCs.SulphurousSea public override float SpawnChance(NPCSpawnInfo spawnInfo) { if (spawnInfo.PlayerSafe) - { return 0f; - } - if ((spawnInfo.Player.Calamity().ZoneSulphur || spawnInfo.Player.Calamity().ZoneAbyssLayer1) && - spawnInfo.Water && NPC.CountNPCS(ModContent.NPCType()) < 12) - { + + if ((spawnInfo.Player.Calamity().ZoneSulphur || spawnInfo.Player.Calamity().ZoneAbyssLayer1) && spawnInfo.Water && NPC.CountNPCS(ModContent.NPCType()) < 12) return 2.2f; - } + return 0f; } diff --git a/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs b/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs index b92fa6248c..57197a5fd7 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs @@ -55,6 +55,7 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses float totalSegments = GetEaterOfWorldsSegmentsCountRevDeath(); // Count segments remaining + // TODO - This runs for every EoW segment, this is bad because there are three separate loops here running every frame. float segmentCount = NPC.CountNPCS(NPCID.EaterofWorldsHead) + NPC.CountNPCS(NPCID.EaterofWorldsBody) + NPC.CountNPCS(NPCID.EaterofWorldsTail); // Percent segments remaining, add two to total for head and tail