From c23099c6ab081a748f773a1393d5f197d1064f34 Mon Sep 17 00:00:00 2001 From: Amber Sienna Date: Mon, 20 Jan 2020 14:35:05 +0000 Subject: [PATCH] Destroyer force despawn fix --- Items/DifficultyItems/Armageddon.cs | 3 +-- Items/DifficultyItems/Death.cs | 3 +-- Items/DifficultyItems/DefiledRune.cs | 3 +-- Items/DifficultyItems/IronHeart.cs | 3 +-- Items/DifficultyItems/Revenge.cs | 3 +-- NPCs/CalamityGlobalAI.cs | 23 +++++++++++++++-------- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Items/DifficultyItems/Armageddon.cs b/Items/DifficultyItems/Armageddon.cs index ac7865f068..c42330f06d 100644 --- a/Items/DifficultyItems/Armageddon.cs +++ b/Items/DifficultyItems/Armageddon.cs @@ -45,8 +45,7 @@ namespace CalamityMod.Items.DifficultyItems for (int doom = 0; doom < 200; doom++) { if ((Main.npc[doom].active && (Main.npc[doom].boss || Main.npc[doom].type == NPCID.EaterofWorldsHead || Main.npc[doom].type == NPCID.EaterofWorldsTail || Main.npc[doom].type == ModContent.NPCType() || - Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0 || - Main.npc[doom].type == NPCID.TheDestroyerBody || Main.npc[doom].type == NPCID.TheDestroyerTail) + Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0) { player.KillMe(PlayerDeathReason.ByCustomReason(player.name + " tried to change the rules."), 1000.0, 0, false); Main.npc[doom].active = false; diff --git a/Items/DifficultyItems/Death.cs b/Items/DifficultyItems/Death.cs index 9e234c1008..43393fddfc 100644 --- a/Items/DifficultyItems/Death.cs +++ b/Items/DifficultyItems/Death.cs @@ -52,8 +52,7 @@ namespace CalamityMod.Items.DifficultyItems for (int doom = 0; doom < 200; doom++) { if ((Main.npc[doom].active && (Main.npc[doom].boss || Main.npc[doom].type == NPCID.EaterofWorldsHead || Main.npc[doom].type == NPCID.EaterofWorldsTail || Main.npc[doom].type == ModContent.NPCType() || - Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0 || - Main.npc[doom].type == NPCID.TheDestroyerBody || Main.npc[doom].type == NPCID.TheDestroyerTail) + Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0) { player.KillMe(PlayerDeathReason.ByCustomReason(player.name + " tried to change the rules."), 1000.0, 0, false); Main.npc[doom].active = false; diff --git a/Items/DifficultyItems/DefiledRune.cs b/Items/DifficultyItems/DefiledRune.cs index 288e2f3009..8a633f5557 100644 --- a/Items/DifficultyItems/DefiledRune.cs +++ b/Items/DifficultyItems/DefiledRune.cs @@ -46,8 +46,7 @@ namespace CalamityMod.Items.DifficultyItems for (int doom = 0; doom < 200; doom++) { if ((Main.npc[doom].active && (Main.npc[doom].boss || Main.npc[doom].type == NPCID.EaterofWorldsHead || Main.npc[doom].type == NPCID.EaterofWorldsTail || Main.npc[doom].type == ModContent.NPCType() || - Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0 || - Main.npc[doom].type == NPCID.TheDestroyerBody || Main.npc[doom].type == NPCID.TheDestroyerTail) + Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0) { player.KillMe(PlayerDeathReason.ByCustomReason(player.name + " tried to change the rules."), 1000.0, 0, false); Main.npc[doom].active = false; diff --git a/Items/DifficultyItems/IronHeart.cs b/Items/DifficultyItems/IronHeart.cs index 33946ef2af..58236f96e4 100644 --- a/Items/DifficultyItems/IronHeart.cs +++ b/Items/DifficultyItems/IronHeart.cs @@ -47,8 +47,7 @@ namespace CalamityMod.Items.DifficultyItems for (int doom = 0; doom < 200; doom++) { if ((Main.npc[doom].active && (Main.npc[doom].boss || Main.npc[doom].type == NPCID.EaterofWorldsHead || Main.npc[doom].type == NPCID.EaterofWorldsTail || Main.npc[doom].type == ModContent.NPCType() || - Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0 || - Main.npc[doom].type == NPCID.TheDestroyerBody || Main.npc[doom].type == NPCID.TheDestroyerTail) + Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0) { player.KillMeForGood(); Main.npc[doom].active = false; diff --git a/Items/DifficultyItems/Revenge.cs b/Items/DifficultyItems/Revenge.cs index d11f17398a..5c5b4c2dbb 100644 --- a/Items/DifficultyItems/Revenge.cs +++ b/Items/DifficultyItems/Revenge.cs @@ -60,8 +60,7 @@ namespace CalamityMod.Items.DifficultyItems for (int doom = 0; doom < 200; doom++) { if ((Main.npc[doom].active && (Main.npc[doom].boss || Main.npc[doom].type == NPCID.EaterofWorldsHead || Main.npc[doom].type == NPCID.EaterofWorldsTail || Main.npc[doom].type == ModContent.NPCType() || - Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0 || - Main.npc[doom].type == NPCID.TheDestroyerBody || Main.npc[doom].type == NPCID.TheDestroyerTail) + Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType() || Main.npc[doom].type == ModContent.NPCType())) || CalamityWorld.DoGSecondStageCountdown > 0) { player.KillMe(PlayerDeathReason.ByCustomReason(player.name + " tried to change the rules."), 1000.0, 0, false); Main.npc[doom].active = false; diff --git a/NPCs/CalamityGlobalAI.cs b/NPCs/CalamityGlobalAI.cs index 1baa354605..af0aee68e7 100644 --- a/NPCs/CalamityGlobalAI.cs +++ b/NPCs/CalamityGlobalAI.cs @@ -4258,20 +4258,27 @@ namespace CalamityMod.NPCs // Check if other segments are still alive, if not, die if (npc.type > NPCID.TheDestroyer) { - bool flag = false; - if (npc.ai[1] <= 0f) - flag = true; - else if (Main.npc[(int)npc.ai[1]].life <= 0) - flag = true; - - if (flag) + bool shouldDespawn = true; + for (int i = 0; i < Main.maxNPCs; i++) + { + if (Main.npc[i].active && Main.npc[i].type == NPCID.TheDestroyer) + shouldDespawn = false; + } + if (!shouldDespawn) + { + if (npc.ai[1] > 0f) + shouldDespawn = false; + else if (Main.npc[(int)npc.ai[1]].life > 0) + shouldDespawn = false; + } + if (shouldDespawn) { npc.life = 0; npc.HitEffect(0, 10.0); npc.checkDead(); + npc.active = false; } } - if (npc.type == NPCID.TheDestroyerBody) { // Gain more defense as health lowers with a max of 30, lose defense if probe has been launched