diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index f2ef54de69..dd9088655a 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -162,6 +162,9 @@ namespace CalamityMod // Tile Entities // + case CalamityModMessageType.UnlockAbyssChests: + Abyss.UnlockAllAbyssChests(); + break; case CalamityModMessageType.PowerCellFactory: TEPowerCellFactory.ReadSyncPacket(mod, reader); break; @@ -359,6 +362,7 @@ namespace CalamityMod UpdateCodebreakerConstituents, UpdateCodebreakerContainedStuff, UpdateCodebreakerDecryptCountdown, + UnlockAbyssChests, // Draedon Summoner CodebreakerSummonStuff, diff --git a/NPCs/CalamityGlobalNPCLoot.cs b/NPCs/CalamityGlobalNPCLoot.cs index d6792e3c1c..50451023f8 100644 --- a/NPCs/CalamityGlobalNPCLoot.cs +++ b/NPCs/CalamityGlobalNPCLoot.cs @@ -1783,15 +1783,10 @@ namespace CalamityMod.NPCs // First kill: Notify of Abyss chests being unlocked. if (!NPC.downedBoss3) { - // Abyss chest auto unlock has been shelved, the bug has still not fucking died despite several attempts to fix it. - // Commented it out just in case someone is willing to fix it in the future - Shade - /* - if (Main.netMode != NetmodeID.MultiplayerClient) //Only the server should do this to prevent already unlocked chests from attempting to be unlocked + if (Main.netMode != NetmodeID.MultiplayerClient) { - World.Abyss.AbleToUnlockChests = true; World.Abyss.UnlockAllAbyssChests(); } - */ string keysk = "Mods.CalamityMod.Status.Progression.SkeletronAbyssChestNotification"; CalamityUtils.DisplayLocalizedText(keysk, new Color(76, 181, 76)); } diff --git a/Tiles/Abyss/AbyssTreasureChest.cs b/Tiles/Abyss/AbyssTreasureChest.cs index 5a3891b147..eed55a4907 100644 --- a/Tiles/Abyss/AbyssTreasureChest.cs +++ b/Tiles/Abyss/AbyssTreasureChest.cs @@ -27,11 +27,9 @@ namespace CalamityMod.Tiles.Abyss public override bool IsLockedChest(int i, int j) => Main.tile[i, j].TileFrameX / 36 == 1; public override bool UnlockChest(int i, int j, ref short frameXAdjustment, ref int dustType, ref bool manual) { - //Only unlock if Skeletron is dead - if (NPC.downedBoss3) - return true; - else - return false; + //Skeletron must be dead, NPC.downedBoss3 is added as failsave in case chests fail to open in the Abyss' method. AbleToUnlockChests should be false unless + //the Abyss' unlock method is being run to prevent chests spawning already unlocked. + return World.Abyss.UnlockChests || NPC.downedBoss3; } public override bool RightClick(int i, int j) diff --git a/World/Abyss.cs b/World/Abyss.cs index ba517912e5..a93fc44c13 100644 --- a/World/Abyss.cs +++ b/World/Abyss.cs @@ -36,7 +36,11 @@ namespace CalamityMod.World public static bool AtLeftSideOfWorld = false; public static int AbyssChasmBottom = 0; - //public static bool AbleToUnlockChests = false; //used for unlocking chests during skeletron's death and so that they cannot be opened beforehand + /// + /// Forces abyss chests to unlock even if is false. Used in as it is ran during Skeletron's death, not after. + /// + public static bool UnlockChests { get; set; } + public static void PlaceAbyss() { int x = Main.maxTilesX; @@ -1155,34 +1159,38 @@ namespace CalamityMod.World WorldGen.PlaceObject(i, j - 2, (ushort)ModContent.TileType()); } - // Commented out the method in case we ever use it again in the future, or some guy in the public github fixes it, - // but for now this is a buggy mess that is too disruptive especially in multiplayer despite several attempts at fixing it - Shade - /* + + /// + /// Unlocks all abyss chests, automatically synced across the server. + /// Only run initally on the server. + /// public static void UnlockAllAbyssChests() { - int genLimit = Main.maxTilesX / 2; - int abyssChasmX = AtLeftSideOfWorld ? genLimit - (genLimit - 135) + 35 : genLimit + (genLimit - 135) - 35; - int abyssMinX = AtLeftSideOfWorld ? 0 : abyssChasmX - 150; - int abyssMaxX = AtLeftSideOfWorld ? abyssChasmX + 150 : Main.maxTilesX; + UnlockChests = true; - //loop to unlock all abyss treasure chests - for (int x = abyssMinX; x < abyssMaxX; x++) + if (Main.netMode == NetmodeID.Server) { - for (int y = Main.remixWorld ? SulphurousSea.YStart - (int)((Main.maxTilesY - 200) * 0.4f) : (int)Main.worldSurface; y < Main.maxTilesY - 300; y++) + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.UnlockAbyssChests); + netMessage.Send(); + } + + for (int c = 0; c < Main.maxChests; c++) + { + var chest = Main.chest[c]; + if (chest == null) { - //make SURE to check for the entire chest at once, otherwise it will break when unlocking - if (Main.tile[x, y].TileType == ModContent.TileType() && //top left - Main.tile[x + 1, y].TileType == ModContent.TileType() && //top right - Main.tile[x, y + 1].TileType == ModContent.TileType() && //bottom left - Main.tile[x + 1, y + 1].TileType == ModContent.TileType()) //bottom right - { - Chest.Unlock(x, y); - NetMessage.SendData(MessageID.LockAndUnlock, -1, -1, null, Main.LocalPlayer.whoAmI, 1f, x, y); - } + continue; + } + + var chestTile = Framing.GetTileSafely(chest.x, chest.y); + if (chestTile.HasTile && chestTile.TileType == ModContent.TileType() && Chest.IsLocked(chest.x, chest.y)) + { + Chest.Unlock(chest.x, chest.y); } } - AbleToUnlockChests = false; //reseting the variable in case players generate multiple worlds to prevent already unlocked chests from spawning + + UnlockChests = false; } - */ } }