diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index 88e29c1b2a..f0776c139e 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -150,6 +150,9 @@ namespace CalamityMod case CalamityModMessageType.LabHologramProjector: TELabHologramProjector.ReadSyncPacket(mod, reader); break; + case CalamityModMessageType.UpdateCodebreakerConstituents: + TECodebreaker.ReadConstituentsUpdateSync(mod, reader); + break; // // Boss Rush @@ -284,6 +287,7 @@ namespace CalamityMod ChargingStationItemChange, Turret, LabHologramProjector, + UpdateCodebreakerConstituents, // Boss Rush BossRushStage, diff --git a/Items/DraedonMisc/AdvancedDisplay.cs b/Items/DraedonMisc/AdvancedDisplay.cs new file mode 100644 index 0000000000..7dcefc9c72 --- /dev/null +++ b/Items/DraedonMisc/AdvancedDisplay.cs @@ -0,0 +1,64 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.DraedonSummoner; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using CalamityMod.TileEntities; + +namespace CalamityMod.Items.DraedonMisc +{ + public class AdvancedDisplay : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Advanced Display"); + Tooltip.SetDefault("Can be placed in the Codebreaker"); + } + + public override void SetDefaults() + { + item.width = 52; + item.height = 52; + item.maxStack = 999; + item.consumable = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.rare = ItemRarityID.Pink; + item.useTime = item.useAnimation = 15; + } + + public override bool UseItem(Player player) => true; + + public override bool ConsumeItem(Player player) + { + Point placeTileCoords = Main.MouseWorld.ToTileCoordinates(); + Tile tile = CalamityUtils.ParanoidTileRetrieval(placeTileCoords.X, placeTileCoords.Y); + float checkDistance = ((Player.tileRangeX + Player.tileRangeY) / 2f + player.blockRange) * 16f; + + if (Main.myPlayer == player.whoAmI && player.WithinRange(Main.MouseWorld, checkDistance) && tile.active() && tile.type == ModContent.TileType()) + { + TECodebreaker codebreakerTileEntity = CalamityUtils.FindTileEntity(placeTileCoords.X, placeTileCoords.Y, CodebreakerTile.Width, CodebreakerTile.Height, CodebreakerTile.SheetSquare); + if (codebreakerTileEntity is null || codebreakerTileEntity.ContainsAdvancedDisplay) + return false; + + codebreakerTileEntity.ContainsAdvancedDisplay = true; + codebreakerTileEntity.SyncConstituents(); + return true; + } + + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddIngredient(ItemID.Glass, 20); + recipe.AddTile(TileID.MythrilAnvil); + recipe.SetResult(this, 1); + recipe.AddRecipe(); + } + } +} diff --git a/Items/DraedonMisc/AdvancedDisplay.png b/Items/DraedonMisc/AdvancedDisplay.png new file mode 100644 index 0000000000..c0a76b9fac Binary files /dev/null and b/Items/DraedonMisc/AdvancedDisplay.png differ diff --git a/Items/DraedonMisc/AuricQuantumCoolingCell.cs b/Items/DraedonMisc/AuricQuantumCoolingCell.cs new file mode 100644 index 0000000000..bbef3dc013 --- /dev/null +++ b/Items/DraedonMisc/AuricQuantumCoolingCell.cs @@ -0,0 +1,69 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.DraedonSummoner; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using CalamityMod.TileEntities; + +namespace CalamityMod.Items.DraedonMisc +{ + public class AuricQuantumCoolingCell : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Auric Quantum Cooling Cell"); + Tooltip.SetDefault("Can be placed in the Codebreaker"); + } + + public override void SetDefaults() + { + item.width = 26; + item.height = 44; + item.maxStack = 999; + item.consumable = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.rare = ItemRarityID.Red; + item.useTime = item.useAnimation = 15; + item.Calamity().customRarity = CalamityRarity.Violet; + } + + public override void Update(ref float gravity, ref float maxFallSpeed) + { + float brightness = Main.essScale * Main.rand.NextFloat(0.9f, 1.1f); + Lighting.AddLight(item.Center, 1.2f * brightness, 0.4f * brightness, 0.8f); + } + + public override bool UseItem(Player player) => true; + + public override bool ConsumeItem(Player player) + { + Point placeTileCoords = Main.MouseWorld.ToTileCoordinates(); + Tile tile = CalamityUtils.ParanoidTileRetrieval(placeTileCoords.X, placeTileCoords.Y); + float checkDistance = ((Player.tileRangeX + Player.tileRangeY) / 2f + player.blockRange) * 16f; + + if (Main.myPlayer == player.whoAmI && player.WithinRange(Main.MouseWorld, checkDistance) && tile.active() && tile.type == ModContent.TileType()) + { + TECodebreaker codebreakerTileEntity = CalamityUtils.FindTileEntity(placeTileCoords.X, placeTileCoords.Y, CodebreakerTile.Width, CodebreakerTile.Height, CodebreakerTile.SheetSquare); + if (codebreakerTileEntity is null || codebreakerTileEntity.ContainsCoolingCell) + return false; + + codebreakerTileEntity.ContainsCoolingCell = true; + codebreakerTileEntity.SyncConstituents(); + return true; + } + + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/DraedonMisc/AuricQuantumCoolingCell.png b/Items/DraedonMisc/AuricQuantumCoolingCell.png new file mode 100644 index 0000000000..ed57707d71 Binary files /dev/null and b/Items/DraedonMisc/AuricQuantumCoolingCell.png differ diff --git a/Items/DraedonMisc/CodebreakerBase.cs b/Items/DraedonMisc/CodebreakerBase.cs new file mode 100644 index 0000000000..a6d5d5f160 --- /dev/null +++ b/Items/DraedonMisc/CodebreakerBase.cs @@ -0,0 +1,39 @@ +using Terraria.ModLoader; +using Terraria.ID; +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.DraedonSummoner; +using CalamityMod.Items.Placeables.DraedonStructures; + +namespace CalamityMod.Items.DraedonMisc +{ + public class CodebreakerBase : ModItem + { + public override void SetStaticDefaults() => DisplayName.SetDefault("Codebreaker Base"); + + public override void SetDefaults() + { + item.useStyle = ItemUseStyleID.SwingThrow; + item.useTurn = true; + item.useAnimation = 15; + item.useTime = 10; + item.autoReuse = true; + item.consumable = true; + item.width = 42; + item.height = 32; + item.maxStack = 999; + item.rare = ItemRarityID.Orange; + item.createTile = ModContent.TileType(); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddIngredient(ModContent.ItemType(), 20); + recipe.AddIngredient(ModContent.ItemType(), 35); + recipe.AddTile(TileID.Anvils); + recipe.SetResult(this, 1); + recipe.AddRecipe(); + } + } +} diff --git a/Items/DraedonMisc/CodebreakerBase.png b/Items/DraedonMisc/CodebreakerBase.png new file mode 100644 index 0000000000..eacc52b6c4 Binary files /dev/null and b/Items/DraedonMisc/CodebreakerBase.png differ diff --git a/Items/DraedonMisc/DecryptionComputer.cs b/Items/DraedonMisc/DecryptionComputer.cs new file mode 100644 index 0000000000..6ccf6c2da9 --- /dev/null +++ b/Items/DraedonMisc/DecryptionComputer.cs @@ -0,0 +1,63 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.DraedonSummoner; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using CalamityMod.TileEntities; + +namespace CalamityMod.Items.DraedonMisc +{ + public class DecryptionComputer : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Decryption Computer"); + Tooltip.SetDefault("Can be placed in the Codebreaker"); + } + + public override void SetDefaults() + { + item.width = 42; + item.height = 40; + item.maxStack = 999; + item.consumable = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.rare = ItemRarityID.Orange; + item.useTime = item.useAnimation = 15; + } + + public override bool UseItem(Player player) => true; + + public override bool ConsumeItem(Player player) + { + Point placeTileCoords = Main.MouseWorld.ToTileCoordinates(); + Tile tile = CalamityUtils.ParanoidTileRetrieval(placeTileCoords.X, placeTileCoords.Y); + float checkDistance = ((Player.tileRangeX + Player.tileRangeY) / 2f + player.blockRange) * 16f; + + if (Main.myPlayer == player.whoAmI && player.WithinRange(Main.MouseWorld, checkDistance) && tile.active() && tile.type == ModContent.TileType()) + { + TECodebreaker codebreakerTileEntity = CalamityUtils.FindTileEntity(placeTileCoords.X, placeTileCoords.Y, CodebreakerTile.Width, CodebreakerTile.Height, CodebreakerTile.SheetSquare); + if (codebreakerTileEntity is null || codebreakerTileEntity.ContainsDecryptionComputer) + return false; + + codebreakerTileEntity.ContainsDecryptionComputer = true; + codebreakerTileEntity.SyncConstituents(); + return true; + } + + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 18); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ItemID.Glass, 5); + recipe.AddTile(TileID.Anvils); + recipe.SetResult(this, 1); + recipe.AddRecipe(); + } + } +} diff --git a/Items/DraedonMisc/DecryptionComputer.png b/Items/DraedonMisc/DecryptionComputer.png new file mode 100644 index 0000000000..bfe9dcbb2b Binary files /dev/null and b/Items/DraedonMisc/DecryptionComputer.png differ diff --git a/Items/DraedonMisc/LongRangedSensorArray.cs b/Items/DraedonMisc/LongRangedSensorArray.cs new file mode 100644 index 0000000000..dc07195d59 --- /dev/null +++ b/Items/DraedonMisc/LongRangedSensorArray.cs @@ -0,0 +1,64 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.DraedonSummoner; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using CalamityMod.TileEntities; + +namespace CalamityMod.Items.DraedonMisc +{ + public class LongRangedSensorArray : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Long Ranged Sensor Array"); + Tooltip.SetDefault("Can be placed in the Codebreaker"); + } + + public override void SetDefaults() + { + item.width = 52; + item.height = 52; + item.maxStack = 999; + item.consumable = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.rare = ItemRarityID.Pink; + item.useTime = item.useAnimation = 15; + } + + public override bool UseItem(Player player) => true; + + public override bool ConsumeItem(Player player) + { + Point placeTileCoords = Main.MouseWorld.ToTileCoordinates(); + Tile tile = CalamityUtils.ParanoidTileRetrieval(placeTileCoords.X, placeTileCoords.Y); + float checkDistance = ((Player.tileRangeX + Player.tileRangeY) / 2f + player.blockRange) * 16f; + + if (Main.myPlayer == player.whoAmI && player.WithinRange(Main.MouseWorld, checkDistance) && tile.active() && tile.type == ModContent.TileType()) + { + TECodebreaker codebreakerTileEntity = CalamityUtils.FindTileEntity(placeTileCoords.X, placeTileCoords.Y, CodebreakerTile.Width, CodebreakerTile.Height, CodebreakerTile.SheetSquare); + if (codebreakerTileEntity is null || codebreakerTileEntity.ContainsSensorArray) + return false; + + codebreakerTileEntity.ContainsSensorArray = true; + codebreakerTileEntity.SyncConstituents(); + return true; + } + + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ItemID.HallowedBar, 10); + recipe.AddIngredient(ItemID.Wire, 50); + recipe.AddTile(TileID.MythrilAnvil); + recipe.SetResult(this, 1); + recipe.AddRecipe(); + } + } +} diff --git a/Items/DraedonMisc/LongRangedSensorArray.png b/Items/DraedonMisc/LongRangedSensorArray.png new file mode 100644 index 0000000000..3b9a2bb067 Binary files /dev/null and b/Items/DraedonMisc/LongRangedSensorArray.png differ diff --git a/Items/DraedonMisc/VoltageRegulationSystem.cs b/Items/DraedonMisc/VoltageRegulationSystem.cs new file mode 100644 index 0000000000..860866a26c --- /dev/null +++ b/Items/DraedonMisc/VoltageRegulationSystem.cs @@ -0,0 +1,65 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.DraedonSummoner; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using CalamityMod.TileEntities; + +namespace CalamityMod.Items.DraedonMisc +{ + public class VoltageRegulationSystem : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Voltage Regulation System"); + Tooltip.SetDefault("Can be placed in the Codebreaker"); + } + + public override void SetDefaults() + { + item.width = 52; + item.height = 52; + item.maxStack = 999; + item.consumable = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Turquoise; + item.useTime = item.useAnimation = 15; + } + + public override bool UseItem(Player player) => true; + + public override bool ConsumeItem(Player player) + { + Point placeTileCoords = Main.MouseWorld.ToTileCoordinates(); + Tile tile = CalamityUtils.ParanoidTileRetrieval(placeTileCoords.X, placeTileCoords.Y); + float checkDistance = ((Player.tileRangeX + Player.tileRangeY) / 2f + player.blockRange) * 16f; + + if (Main.myPlayer == player.whoAmI && player.WithinRange(Main.MouseWorld, checkDistance) && tile.active() && tile.type == ModContent.TileType()) + { + TECodebreaker codebreakerTileEntity = CalamityUtils.FindTileEntity(placeTileCoords.X, placeTileCoords.Y, CodebreakerTile.Width, CodebreakerTile.Height, CodebreakerTile.SheetSquare); + if (codebreakerTileEntity is null || codebreakerTileEntity.ContainsVoltageRegulationSystem) + return false; + + codebreakerTileEntity.ContainsVoltageRegulationSystem = true; + codebreakerTileEntity.SyncConstituents(); + return true; + } + + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ItemID.LunarBar, 5); + recipe.AddTile(TileID.MythrilAnvil); + recipe.SetResult(this, 1); + recipe.AddRecipe(); + } + } +} diff --git a/Items/DraedonMisc/VoltageRegulationSystem.png b/Items/DraedonMisc/VoltageRegulationSystem.png new file mode 100644 index 0000000000..4336750cba Binary files /dev/null and b/Items/DraedonMisc/VoltageRegulationSystem.png differ diff --git a/TileEntities/TECodebreaker.cs b/TileEntities/TECodebreaker.cs new file mode 100644 index 0000000000..6e12016794 --- /dev/null +++ b/TileEntities/TECodebreaker.cs @@ -0,0 +1,149 @@ +using CalamityMod.Items.DraedonMisc; +using CalamityMod.Tiles.DraedonStructures; +using CalamityMod.Tiles.DraedonSummoner; +using Microsoft.Xna.Framework; +using System.IO; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; + +namespace CalamityMod.TileEntities +{ + public class TECodebreaker : ModTileEntity + { + public bool ContainsDecryptionComputer; + public bool ContainsSensorArray; + public bool ContainsAdvancedDisplay; + public bool ContainsVoltageRegulationSystem; + public bool ContainsCoolingCell; + public Vector2 Center => Position.ToWorldCoordinates(8f * CodebreakerTile.Width, 8f * CodebreakerTile.Height); + + // This guarantees that this tile entity will not persist if not placed directly on the top left corner of a Charging Station tile. + public override bool ValidTile(int i, int j) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(i, j); + return tile.active() && tile.type == ModContent.TileType() && tile.frameX == 0 && tile.frameY == 0; + } + + // This code is called as a hook when the player places the Charging Station tile so that the tile entity may be placed. + public override int Hook_AfterPlacement(int i, int j, int type, int style, int direction) + { + // If in multiplayer, tell the server to place the tile entity and DO NOT place it yourself. That would mismatch IDs. + // Also tell the server that you placed the 3x2 tiles that make up the Charging Station. + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendTileRange(Main.myPlayer, i, j, CodebreakerTile.Width, CodebreakerTile.Height); + NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, null, i, j, Type); + return -1; + } + + // If in single player, just place the tile entity, no problems. + return Place(i, j); + } + + // This code is called on dedicated servers only. It is the server-side response to MessageID.TileEntityPlacement. + // When the server receives such a message from a client, it sends a MessageID.TileEntitySharing to all clients. + // This will cause them to Place the tile entity locally at that position, all with exactly the same ID. + public override void OnNetPlace() => NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID, Position.X, Position.Y); + + public void DropConstituents(int x, int y) + { + if (ContainsDecryptionComputer) + Item.NewItem(x * 16, y * 16, 32, 32, ModContent.ItemType()); + if (ContainsSensorArray) + Item.NewItem(x * 16, y * 16, 32, 32, ModContent.ItemType()); + if (ContainsAdvancedDisplay) + Item.NewItem(x * 16, y * 16, 32, 32, ModContent.ItemType()); + if (ContainsVoltageRegulationSystem) + Item.NewItem(x * 16, y * 16, 32, 32, ModContent.ItemType()); + if (ContainsCoolingCell) + Item.NewItem(x * 16, y * 16, 32, 32, ModContent.ItemType()); + } + + public void SyncConstituents() + { + // Don't bother sending packets in singleplayer. + if (Main.netMode == NetmodeID.SinglePlayer) + return; + + ModPacket packet = mod.GetPacket(); + packet.Write((byte)CalamityModMessageType.UpdateCodebreakerConstituents); + packet.Write(ID); + packet.Write(ContainsDecryptionComputer); + packet.Write(ContainsSensorArray); + packet.Write(ContainsAdvancedDisplay); + packet.Write(ContainsVoltageRegulationSystem); + packet.Write(ContainsCoolingCell); + } + + public static void ReadConstituentsUpdateSync(Mod mod, BinaryReader reader) + { + int id = reader.ReadInt32(); + bool exists = ByID.TryGetValue(id, out TileEntity tileEntity); + + // Continue reading to the end even if a tile entity with the given ID does not exist. + // Not doing this will cause errors/bugs. + bool containsDecryptionComputer = reader.ReadBoolean(); + bool containsSensorArray = reader.ReadBoolean(); + bool containsAdvancedDisplay = reader.ReadBoolean(); + bool containsVoltageRegulationSystem = reader.ReadBoolean(); + bool containsCoolingCell = reader.ReadBoolean(); + + // After doing reading, check again to see if the tile entity is actually there. + // If it isn't don't bother doing anything else. + if (!exists) + return; + + // Furthermore, verify to ensure that the tile entity is a valid one. + if (!(tileEntity is TECodebreaker codebreakerTileEntity)) + return; + + codebreakerTileEntity.ContainsDecryptionComputer = containsDecryptionComputer; + codebreakerTileEntity.ContainsSensorArray = containsSensorArray; + codebreakerTileEntity.ContainsAdvancedDisplay = containsAdvancedDisplay; + codebreakerTileEntity.ContainsVoltageRegulationSystem = containsVoltageRegulationSystem; + codebreakerTileEntity.ContainsCoolingCell = containsCoolingCell; + } + + public override TagCompound Save() + { + return new TagCompound + { + ["ContainsDecryptionComputer"] = ContainsDecryptionComputer, + ["ContainsSensorArray"] = ContainsSensorArray, + ["ContainsAdvancedDisplay"] = ContainsAdvancedDisplay, + ["ContainsVoltageRegulationSystem"] = ContainsVoltageRegulationSystem, + ["ContainsCoolingCell"] = ContainsCoolingCell + }; + } + + public override void Load(TagCompound tag) + { + ContainsDecryptionComputer = tag.GetBool("ContainsDecryptionComputer"); + ContainsSensorArray = tag.GetBool("ContainsSensorArray"); + ContainsAdvancedDisplay = tag.GetBool("ContainsAdvancedDisplay"); + ContainsVoltageRegulationSystem = tag.GetBool("ContainsVoltageRegulationSystem"); + ContainsCoolingCell = tag.GetBool("ContainsCoolingCell"); + } + + public override void NetSend(BinaryWriter writer, bool lightSend) + { + writer.Write(ContainsDecryptionComputer); + writer.Write(ContainsSensorArray); + writer.Write(ContainsAdvancedDisplay); + writer.Write(ContainsVoltageRegulationSystem); + writer.Write(ContainsCoolingCell); + } + + public override void NetReceive(BinaryReader reader, bool lightReceive) + { + ContainsDecryptionComputer = reader.ReadBoolean(); + ContainsSensorArray = reader.ReadBoolean(); + ContainsAdvancedDisplay = reader.ReadBoolean(); + ContainsVoltageRegulationSystem = reader.ReadBoolean(); + ContainsCoolingCell = reader.ReadBoolean(); + } + } +} diff --git a/Tiles/DraedonSummoner/CodebreakerAdvancedDisplay.png b/Tiles/DraedonSummoner/CodebreakerAdvancedDisplay.png new file mode 100644 index 0000000000..8853083806 Binary files /dev/null and b/Tiles/DraedonSummoner/CodebreakerAdvancedDisplay.png differ diff --git a/Tiles/DraedonSummoner/CodebreakerAuricQuantumCoolingCell.png b/Tiles/DraedonSummoner/CodebreakerAuricQuantumCoolingCell.png new file mode 100644 index 0000000000..e098482c31 Binary files /dev/null and b/Tiles/DraedonSummoner/CodebreakerAuricQuantumCoolingCell.png differ diff --git a/Tiles/DraedonSummoner/CodebreakerDecryptionComputer.png b/Tiles/DraedonSummoner/CodebreakerDecryptionComputer.png new file mode 100644 index 0000000000..a5a0642811 Binary files /dev/null and b/Tiles/DraedonSummoner/CodebreakerDecryptionComputer.png differ diff --git a/Tiles/DraedonSummoner/CodebreakerLongRangedSensorArray.png b/Tiles/DraedonSummoner/CodebreakerLongRangedSensorArray.png new file mode 100644 index 0000000000..07d8351f6d Binary files /dev/null and b/Tiles/DraedonSummoner/CodebreakerLongRangedSensorArray.png differ diff --git a/Tiles/DraedonSummoner/CodebreakerTile.cs b/Tiles/DraedonSummoner/CodebreakerTile.cs new file mode 100644 index 0000000000..f35288d432 --- /dev/null +++ b/Tiles/DraedonSummoner/CodebreakerTile.cs @@ -0,0 +1,127 @@ +using CalamityMod.Items.DraedonMisc; +using CalamityMod.TileEntities; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.Enums; +using Terraria.ModLoader; +using Terraria.ObjectData; + +namespace CalamityMod.Tiles.DraedonSummoner +{ + public class CodebreakerTile : ModTile + { + public const int Width = 5; + public const int Height = 8; + public const int OriginOffsetX = 2; + public const int OriginOffsetY = 7; + public const int SheetSquare = 18; + + public override void SetDefaults() + { + Main.tileLighted[Type] = true; + Main.tileFrameImportant[Type] = true; + Main.tileNoAttach[Type] = true; + Main.tileLavaDeath[Type] = false; + Main.tileWaterDeath[Type] = false; + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2); + TileObjectData.newTile.Width = Width; + TileObjectData.newTile.Height = Height; + TileObjectData.newTile.Origin = new Point16(OriginOffsetX, OriginOffsetY); + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); + TileObjectData.newTile.CoordinateHeights = new int[Height]; + + // Initialize the coordinate heights of each frame based on the sheet area. The padding is shaved off. + for (int i = 0; i < Height; i++) + TileObjectData.newTile.CoordinateHeights[i] = SheetSquare - 2; + + TileObjectData.newTile.LavaDeath = false; + + TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(ModContent.GetInstance().Hook_AfterPlacement, -1, 0, true); + + TileObjectData.addTile(Type); + ModTranslation name = CreateMapEntryName(); + name.SetDefault("The Codebreaker"); + AddMapEntry(new Color(92, 107, 112), name); + animationFrameHeight = 144; + } + + public override bool CanExplode(int i, int j) => false; + + public override bool CreateDust(int i, int j, ref int type) + { + Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, 182); + return false; + } + + public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; + + public override void KillMultiTile(int i, int j, int frameX, int frameY) + { + // Drop the base of the codebreaker. + Item.NewItem(i * 16, j * 16, 32, 32, ModContent.ItemType()); + + Tile t = Main.tile[i, j]; + int left = i - t.frameX % (Width * SheetSquare) / SheetSquare; + int top = j - t.frameY % (Height * SheetSquare) / SheetSquare; + + TECodebreaker codebreakerTileEntity = CalamityUtils.FindTileEntity(i, j, Width, Height, SheetSquare); + + // Drop any any attached components. + codebreakerTileEntity?.DropConstituents(i, j); + + // And destroy the tile entity, if it exists. + codebreakerTileEntity?.Kill(left, top); + } + + // All tile drawcode is done manually because the tile's animation is controlled by a tile entity. + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) + { + // These offsets start as the tile offsets, i.e. which sub-tile of the FrameImportant structure this specific location is. + Tile t = Main.tile[i, j]; + int frameXPos = t.frameX; + int frameYPos = t.frameY; + + // Grab the tile entity because it stores the information regarding what is actually attached. + TECodebreaker codebreakerTileEntity = CalamityUtils.FindTileEntity(i, j, Width, Height, SheetSquare); + + Texture2D tex = ModContent.GetTexture("CalamityMod/Tiles/DraedonSummoner/CodebreakerTile"); + Texture2D computerTexture = ModContent.GetTexture("CalamityMod/Tiles/DraedonSummoner/CodebreakerDecryptionComputer"); + Texture2D sensorTexture = ModContent.GetTexture("CalamityMod/Tiles/DraedonSummoner/CodebreakerLongRangedSensorArray"); + Texture2D voltageRegulatorTexture = ModContent.GetTexture("CalamityMod/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem"); + Texture2D voltageRegulatorTexture2 = ModContent.GetTexture("CalamityMod/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem2"); + Texture2D coolingCellTexture = ModContent.GetTexture("CalamityMod/Tiles/DraedonSummoner/CodebreakerAuricQuantumCoolingCell"); + Vector2 offset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); + if (t.halfBrick()) + offset.Y += 8f; + Vector2 drawPosition = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + offset; + Color drawColor = Lighting.GetColor(i, j); + Rectangle frame = new Rectangle(frameXPos, frameYPos, 16, 16); + + if ((!t.halfBrick() && t.slope() == 0) || t.halfBrick()) + { + spriteBatch.Draw(tex, drawPosition, frame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + + // Place secondary parts. + if (codebreakerTileEntity != null) + { + if (codebreakerTileEntity.ContainsDecryptionComputer) + spriteBatch.Draw(computerTexture, drawPosition, frame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + if (codebreakerTileEntity.ContainsSensorArray) + spriteBatch.Draw(sensorTexture, drawPosition, frame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + if (codebreakerTileEntity.ContainsAdvancedDisplay) + spriteBatch.Draw(coolingCellTexture, drawPosition, frame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + if (codebreakerTileEntity.ContainsVoltageRegulationSystem) + { + spriteBatch.Draw(voltageRegulatorTexture, drawPosition, frame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + spriteBatch.Draw(voltageRegulatorTexture2, drawPosition, frame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + if (codebreakerTileEntity.ContainsCoolingCell) + spriteBatch.Draw(coolingCellTexture, drawPosition, frame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + } + } + return false; + } + } +} diff --git a/Tiles/DraedonSummoner/CodebreakerTile.png b/Tiles/DraedonSummoner/CodebreakerTile.png new file mode 100644 index 0000000000..5b78410bec Binary files /dev/null and b/Tiles/DraedonSummoner/CodebreakerTile.png differ diff --git a/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem.png b/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem.png new file mode 100644 index 0000000000..86cffb899a Binary files /dev/null and b/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem.png differ diff --git a/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem2.png b/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem2.png new file mode 100644 index 0000000000..22bab29496 Binary files /dev/null and b/Tiles/DraedonSummoner/CodebreakerVoltageRegulationSystem2.png differ