From 28008d116aaccec32be39d2b0595d911b8fd3c08 Mon Sep 17 00:00:00 2001 From: termigator1359 <45545085+termigator1359@users.noreply.github.com> Date: Sat, 22 Aug 2020 13:55:47 -0400 Subject: [PATCH] 1. NPCs straight up can't open lab doors anymore 2. Lab doors can now be wired --- CalamityMod.cs | 34 +++++++++++++++++-- .../AgedLaboratoryDoorClosed.cs | 5 +++ .../AgedLaboratoryDoorOpen.cs | 5 +++ .../DraedonStructures/LaboratoryDoorClosed.cs | 5 +++ Tiles/DraedonStructures/LaboratoryDoorOpen.cs | 5 +++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CalamityMod.cs b/CalamityMod.cs index 727c8611cd..5c4fb0d4e4 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -265,8 +265,38 @@ namespace CalamityMod CalamityLocalization.AddLocalizations(); On.Terraria.Player.TileInteractionsUse += Player_TileInteractionsUse; + On.Terraria.WorldGen.OpenDoor += LabDoorsOpen; + On.Terraria.WorldGen.CloseDoor += LabDoorsClose; } + private static bool LabDoorsOpen(On.Terraria.WorldGen.orig_OpenDoor orig, int i, int j, int direction) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || + tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) + { + return false; + } + else + { + return orig(i, j, direction); + } + } + + private static bool LabDoorsClose(On.Terraria.WorldGen.orig_CloseDoor orig, int i, int j, bool forced) + { + Tile tile = Main.tile[i, j]; + if (tile.type == ModContent.TileType() || tile.type == ModContent.TileType() || + tile.type == ModContent.TileType() || tile.type == ModContent.TileType()) + { + return false; + } + else + { + return orig(i, j, forced); + } + } + private static void Player_TileInteractionsUse(On.Terraria.Player.orig_TileInteractionsUse orig, Player player, int i, int j) { Tile tile = Main.tile[i, j]; @@ -292,9 +322,9 @@ namespace CalamityMod } } - private static void DoorSwap(int type1, int type2, int i, int j) + public static void DoorSwap(int type1, int type2, int i, int j, bool forced = false) { - if (PlayerInput.Triggers.JustPressed.MouseRight) + if (PlayerInput.Triggers.JustPressed.MouseRight || forced) { ushort type = (ushort)type1; short frameY = 0; diff --git a/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs b/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs index 88c6d4d7fe..d84713a383 100644 --- a/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs +++ b/Tiles/DraedonStructures/AgedLaboratoryDoorClosed.cs @@ -55,6 +55,11 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } + public override void HitWire(int i, int j) + { + CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); + } + public override void KillMultiTile(int i, int j, int frameX, int frameY) { Item.NewItem(i * 16, j * 16, 16, 48, ModContent.ItemType()); diff --git a/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs b/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs index ed8985c7e6..1e07787d23 100644 --- a/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs +++ b/Tiles/DraedonStructures/AgedLaboratoryDoorOpen.cs @@ -55,6 +55,11 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } + public override void HitWire(int i, int j) + { + CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); + } + public override void KillMultiTile(int i, int j, int frameX, int frameY) { Item.NewItem(i * 16, j * 16, 16, 48, ModContent.ItemType()); diff --git a/Tiles/DraedonStructures/LaboratoryDoorClosed.cs b/Tiles/DraedonStructures/LaboratoryDoorClosed.cs index 170cac3fe9..f7e5a431f3 100644 --- a/Tiles/DraedonStructures/LaboratoryDoorClosed.cs +++ b/Tiles/DraedonStructures/LaboratoryDoorClosed.cs @@ -55,6 +55,11 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } + public override void HitWire(int i, int j) + { + CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); + } + public override void KillMultiTile(int i, int j, int frameX, int frameY) { Item.NewItem(i * 16, j * 16, 16, 48, ModContent.ItemType()); diff --git a/Tiles/DraedonStructures/LaboratoryDoorOpen.cs b/Tiles/DraedonStructures/LaboratoryDoorOpen.cs index cffc7aa927..87c11cf966 100644 --- a/Tiles/DraedonStructures/LaboratoryDoorOpen.cs +++ b/Tiles/DraedonStructures/LaboratoryDoorOpen.cs @@ -55,6 +55,11 @@ namespace CalamityMod.Tiles.DraedonStructures num = fail ? 1 : 3; } + public override void HitWire(int i, int j) + { + CalamityMod.DoorSwap(ModContent.TileType(), ModContent.TileType(), i, j, true); + } + public override void KillMultiTile(int i, int j, int frameX, int frameY) { Item.NewItem(i * 16, j * 16, 16, 48, ModContent.ItemType());