From e3f0e2ce7ada9d47058cbb3e9ce13556804f613d Mon Sep 17 00:00:00 2001 From: Dominic Date: Fri, 9 Oct 2020 23:35:35 -0500 Subject: [PATCH] Added a phase 2 DoG NPC cap check --- World/CalamityWorld.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index 0f1f16f4d2..f2eba650af 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -31,6 +31,7 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Terraria; using Terraria.GameContent.Events; using Terraria.GameContent.Generation; @@ -1495,13 +1496,6 @@ namespace CalamityMod.World if (DoGSecondStageCountdown > 0) { DoGSecondStageCountdown--; - if (Main.netMode == NetmodeID.Server) - { - var netMessage = mod.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.DoGCountdownSync); - netMessage.Write(DoGSecondStageCountdown); - netMessage.Send(); - } if (Main.netMode != NetmodeID.MultiplayerClient) { if (DoGSecondStageCountdown == 21540) @@ -1518,7 +1512,16 @@ namespace CalamityMod.World } if (DoGSecondStageCountdown <= 60) { - if (!NPC.AnyNPCs(ModContent.NPCType())) + int freeNPCSlots = Main.maxNPCs - Main.npc.Take(Main.maxNPCs).Where(npc => npc.active).Count(); + + // If there are too many slots occupied, make a note in the logs, + // and don't attempt to spawn the Devourer of Gods. + if (freeNPCSlots < 102) + { + CalamityMod.Instance.Logger.Warn("You have too many occupied NPC slots for DoG to spawn. Remove dummies or kill excessive town NPCs."); + DoGSecondStageCountdown = 0; + } + else if (!NPC.AnyNPCs(ModContent.NPCType())) { NPC.SpawnOnPlayer(closestPlayer, ModContent.NPCType()); string key = "Mods.CalamityMod.EdgyBossText10"; @@ -1534,6 +1537,13 @@ namespace CalamityMod.World } } } + if (Main.netMode == NetmodeID.Server) + { + var netMessage = mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.DoGCountdownSync); + netMessage.Write(DoGSecondStageCountdown); + netMessage.Send(); + } } if (player.ZoneDungeon && !NPC.downedBoss3 && !player.dead)