From b9eeb72260d94a2592b9038bd9eb8b4e725a5244 Mon Sep 17 00:00:00 2001 From: Big E Date: Mon, 13 Apr 2026 16:44:10 -0400 Subject: [PATCH] + Basic Greed Pot Implementation --- Items/Placeables/GreedPot.cs | 18 ++ Items/Placeables/GreedPot.png | Bin 0 -> 457 bytes Tiles/GreedPotTile.cs | 303 ++++++++++++++++++++++++++++++++++ Tiles/GreedPotTile.png | Bin 0 -> 2409 bytes 4 files changed, 321 insertions(+) create mode 100644 Items/Placeables/GreedPot.cs create mode 100644 Items/Placeables/GreedPot.png create mode 100644 Tiles/GreedPotTile.cs create mode 100644 Tiles/GreedPotTile.png diff --git a/Items/Placeables/GreedPot.cs b/Items/Placeables/GreedPot.cs new file mode 100644 index 0000000000..9ae76a3736 --- /dev/null +++ b/Items/Placeables/GreedPot.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Tiles; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables +{ + public class GreedPot : ModItem + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() => Item.DefaultToPlaceableTile(ModContent.TileType()); + + } +} diff --git a/Items/Placeables/GreedPot.png b/Items/Placeables/GreedPot.png new file mode 100644 index 0000000000000000000000000000000000000000..9b89cb64059ea82b168a6706dd7cc02aef4d2f21 GIT binary patch literal 457 zcmeAS@N?(olHy`uVBq!ia0vp^3P7yH!3-ohbF|L_DaPU;cPEB*=VV?2ISBziA+A80 zkB{GmK}JtXPf5YVM$I&nRo2(Q-dH&_m?5~DA*8@NXcdFhM?QEak-(K~l?VBcW_4wvQ* zS6)TEuy^&>uIhw}u6(&kSH4VW-l2*Er$6!79W4@Nbx1LLK1Wb#mCJl)2bVK0Rr`JZ zb2^9#ZjKa-2;Vbzi5P?Nk%!L(1#g4~e_+;RSaNp8L_dS1`_=pJG8kTG2xL*2wK8vZ z*1F$(GX-5t8xD608PCtfONnEQzN0lUW&G0D*R%%I3(@O1TaS?83{1OWAyuj>E+ literal 0 HcmV?d00001 diff --git a/Tiles/GreedPotTile.cs b/Tiles/GreedPotTile.cs new file mode 100644 index 0000000000..a7f59c16a1 --- /dev/null +++ b/Tiles/GreedPotTile.cs @@ -0,0 +1,303 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.DataStructures; +using CalamityMod.Items.Placeables.Ores; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ObjectData; + +namespace CalamityMod.Tiles +{ + public class GreedPotTile : ModTile + { + public override void SetStaticDefaults() + { + Main.tileFrameImportant[Type] = true; + Main.tileNoFail[Type] = true; + Main.tileObsidianKill[Type] = true; + + TileObjectData.newTile.CopyFrom(TileObjectData.Style3x3); + + ModTileEntity te = ModContent.GetInstance(); + TileObjectData.newTile.HookPostPlaceMyPlayer = new PlacementHook(te.Hook_AfterPlacement, -1, 0, true); + + TileObjectData.addTile(Type); + + DustType = DustID.Iron; + + AddMapEntry(new Color(250, 142, 4)); + } + + public override void MouseOver(int i, int j) + { + List availableOres = GreedTransmutation.GreedChain.Where(p => p.Value.Availability.Invoke()).Select(p => p.Key).ToList(); + + Player player = Main.LocalPlayer; + player.noThrow = 2; + player.cursorItemIconEnabled = true; + player.cursorItemIconID = availableOres[(int)((Main.GlobalTimeWrappedHourly * 2) % availableOres.Count)]; + } + + public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) + { + if (TileEntity.TryGet(new(i, j), out var greedPotTE)) + { + frameXOffset = 18 * 3 * greedPotTE.MyFrame; + } + } + } + + public class GreedPotTE : ModTileEntity + { + internal bool Activated = false; + internal ushort TimeSinceActivation = 0; + private ushort FrameTime = 0; + private byte CurrentFrame = 0; + public int MyFrame => (int)CurrentFrame; + + private const byte FullActiveFrame = 4; + private const byte FrameRate = 3; + private const byte FrameTotal = 8; + + public override bool IsTileValidForEntity(int x, int y) + { + Tile tile = Main.tile[x, y]; + + int style = 0, alt = 0; + TileObjectData.GetTileInfo(tile, ref style, ref alt); + TileObjectData data = TileObjectData.GetTileData(tile.TileType, style, alt); + + int sheetSquare = 16 + data.CoordinatePadding; + int FrameX = tile.TileFrameX / sheetSquare % data.Width; + int FrameY = tile.TileFrameY / sheetSquare % data.Height; + + return tile.HasTile && tile.TileType == ModContent.TileType() && FrameX == 0 && FrameY == 0; + } + + public override int Hook_AfterPlacement(int i, int j, int type, int style, int direction, int alternate) + { + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendTileSquare(Main.myPlayer, i, j, 3, 3); + NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, null, i, j, Type); + return -1; + } + return Place(i, j); + } + + public override void OnNetPlace() => NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID, Position.X, Position.Y); + + public override void Update() + { + if(Activated) + { + if(CurrentFrame != 3) + { + FrameTime++; + if(FrameTime % FrameRate == 0) + { + FrameTime = 0; + CurrentFrame = (byte)((CurrentFrame + 1) % FrameTotal); + } + } + + if (TimeSinceActivation >= 150) + { + Activated = false; + TimeSinceActivation = 0; + return; + } + + TimeSinceActivation++; + } + else + { + if (CurrentFrame != 0) + { + FrameTime++; + if (FrameTime % FrameRate == 0) + { + FrameTime = 0; + CurrentFrame = (byte)((CurrentFrame + 1) % FrameTotal); + } + } + } + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write(Activated); + writer.Write(FrameTime); + writer.Write(TimeSinceActivation); + writer.Write(CurrentFrame); + } + public override void NetReceive(BinaryReader reader) + { + Activated = reader.ReadBoolean(); + FrameTime = reader.ReadUInt16(); + TimeSinceActivation = reader.ReadUInt16(); + CurrentFrame = reader.ReadByte(); + } + } + + public class GreedTransmutation : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() + { + static bool twoMechsDowned() => + NPC.downedMechBoss1 && NPC.downedMechBoss2 && !NPC.downedMechBoss3 || + NPC.downedMechBoss2 && NPC.downedMechBoss3 && !NPC.downedMechBoss1 || + NPC.downedMechBoss3 && NPC.downedMechBoss1 && !NPC.downedMechBoss2 || + NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3; + + GreedChain = new() + { + { ItemID.CopperOre, (ItemID.IronOre, () => true) }, + { ItemID.IronOre, (ItemID.SilverOre, () => true) }, + { ItemID.SilverOre, (ItemID.GoldOre, () => true) }, + { ItemID.TinOre, (ItemID.LeadOre, () => true) }, + { ItemID.LeadOre, (ItemID.TungstenOre, () => true) }, + { ItemID.TungstenOre, (ItemID.PlatinumOre, () => true) }, + { ItemID.GoldOre, (ModContent.ItemType(), () => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator) }, + { ItemID.PlatinumOre, (ModContent.ItemType(), () => DownedBossSystem.downedHiveMind || DownedBossSystem.downedPerforator) }, + { ModContent.ItemType(), (ItemID.PalladiumOre, () => Main.hardMode) }, + { ItemID.CobaltOre, (ItemID.MythrilOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBossAny : Main.hardMode) }, + { ItemID.MythrilOre, (ItemID.AdamantiteOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? twoMechsDowned() : Main.hardMode) }, + { ItemID.PalladiumOre, (ItemID.OrichalcumOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBossAny : Main.hardMode) }, + { ItemID.OrichalcumOre, (ItemID.TitaniumOre, () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? twoMechsDowned() : Main.hardMode) }, + { ItemID.AdamantiteOre, (ModContent.ItemType(), () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3 : NPC.downedMechBossAny) }, + { ItemID.TitaniumOre, (ModContent.ItemType(), () => CalamityServerConfig.Instance.EarlyHardmodeProgressionRework ? NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3 : NPC.downedMechBossAny) }, + { ModContent.ItemType(), (ItemID.ChlorophyteOre, () => NPC.downedMechBoss1 && NPC.downedMechBoss2 && NPC.downedMechBoss3) }, + { ItemID.ChlorophyteOre, (ModContent.ItemType(), () => NPC.downedPlantBoss) }, + { ModContent.ItemType(), (ModContent.ItemType(), () => NPC.downedGolemBoss) }, + { ModContent.ItemType(), (ItemID.LunarOre, () => NPC.downedMoonlord) }, + { ItemID.LunarOre, (ModContent.ItemType(), () => NPC.downedMoonlord) }, + { ModContent.ItemType(), (ModContent.ItemType(), () => DownedBossSystem.downedProvidence) }, + { ModContent.ItemType(), (ModContent.ItemType(), () => DownedBossSystem.downedYharon) }, + }; + } + + internal static Dictionary Availability)> GreedChain; + + private int InputItemType => (int)Projectile.ai[0]; + private int SuccessOutputItemType => (int)Projectile.ai[1]; + + private Vector2 PotPosition = Vector2.Zero; + private Vector2 StartPosition = Vector2.Zero; + + BezierCurve path = null; + + public override void SetDefaults() + { + Projectile.width = 24; + Projectile.height = 24; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.penetrate = 1; + Projectile.timeLeft = 120; + } + + public override void OnSpawn(IEntitySource source) + { + StartPosition = Projectile.Center; + PotPosition = Projectile.velocity; + Projectile.velocity = Vector2.Zero; + Projectile.netUpdate = true; + } + + + public override void AI() + { + if(path == null) + { + Vector2 startPoint = StartPosition; + Vector2 endPoint = PotPosition - Vector2.UnitY * 64; + + Vector2 direction = endPoint - startPoint; + float curveIntensity = Main.rand.NextFloat(0.2f, 0.4f); + Vector2 perpindicular = direction.RotatedBy(MathHelper.PiOver2); + if (direction.X > 0) + curveIntensity *= -1; + + Vector2 controlPoint1 = startPoint + (direction * 0.25f) + (perpindicular * curveIntensity); + Vector2 controlPoint2 = startPoint + (direction * 0.75f) + (perpindicular * curveIntensity); + + path = new BezierCurve(startPoint, controlPoint1, controlPoint2, endPoint); + } + + float lerp = 1 - MathHelper.Clamp(((Projectile.timeLeft - 60) / 60f), 0f, 1f); + + Projectile.Center = path.Evaluate(CalamityUtils.CircOutEasing(lerp, 1)); + + if (Projectile.timeLeft == 1) + { + int i = Item.NewItem(Projectile.GetItemSource_DropAsItem(), Projectile.Center, Main.rand.NextBool(3) ? SuccessOutputItemType : ItemID.StoneBlock); + Main.item[i].GetGlobalItem().FromGreedPot = true; + } + } + + public override bool PreDraw(ref Color lightColor) + { + //Anim Plan + //Moving to Pos: 0 -> 60 + //Darken: 70 -> 80 + //Transform: 90 -> 100 + //Undarken: 110 -> 120 + Texture2D tex = TextureAssets.Item[InputItemType].Value; + Main.spriteBatch.Draw(tex, Projectile.Center - Main.screenPosition + (Vector2.UnitY * MathF.Sin(Main.GlobalTimeWrappedHourly + Projectile.ai[2]) * 8), null, lightColor, Projectile.rotation, tex.Size() * 0.5f, 1f, 0, 0); + return false; + } + } + + public class GreedTransmutationGlobalItem : GlobalItem + { + public override bool InstancePerEntity => true; + + internal bool FromGreedPot = false; + + public override bool? UseItem(Item item, Player player) + { + if (Main.LocalPlayer.whoAmI != player.whoAmI) + return null; + + if (!GreedTransmutation.GreedChain.TryGetValue(item.type, out var transmutation)) + return null; + + if (!transmutation.Availability()) + return null; + + Point mouseTile = Main.MouseWorld.ToTileCoordinates(); + + GreedPotTE greedPotTE = CalamityUtils.FindTileEntity(mouseTile.X, mouseTile.Y, 3, 3, 18); + if (greedPotTE == null) + return null; + + if (!player.IsInTileInteractionRange(mouseTile.X, mouseTile.Y, TileReachCheckSettings.Simple)) + return null; + + Projectile.NewProjectile(Projectile.GetSource_NaturalSpawn(), Main.LocalPlayer.Center, greedPotTE.Position.ToWorldCoordinates(24, 24) + Main.rand.NextVector2Circular(12, 32), ModContent.ProjectileType(), 0, 0, Main.LocalPlayer.whoAmI, item.type, transmutation.Result, Main.rand.Next(120)); + greedPotTE.Activated = true; + greedPotTE.TimeSinceActivation = 0; + + return true; + } + + public override bool CanStackInWorld(Item destination, Item source) + { + return !destination.GetGlobalItem().FromGreedPot || !source.GetGlobalItem().FromGreedPot; + } + } +} diff --git a/Tiles/GreedPotTile.png b/Tiles/GreedPotTile.png new file mode 100644 index 0000000000000000000000000000000000000000..1e8745c33afd518362afbac516fbf85d64b733ab GIT binary patch literal 2409 zcmZWrdmz(mAOA5Sp;V4Tsix$0YZ0l0jtJFT!Wz+%%jAB|jK(@i7ok-wghTGMwJ>6a zEwEzI~E0mBE=%4Z+F#5r@D}71iwCJm|aj(8s$c z#ro_tqBLEp2Tw~Sc@30$gcX9wt8=*}!;9aChcn{Lgf0Zr>>ks6mY?N%j z?KP2}`_z8uiI!nO{0oW#rXeFiZ*0zPWXTKwp(mxj@x)s&c?NEZ&Gmha>U2XBK}6db zI1Ge3%1+-6@%5D4>E+O;XmGr5!03|^qOkgITxn;@^$bYedwM9g4jCqoajUZ0)Z8@K zYF2pc^D4VS6V)DQywVOc7d-0s`T3X-T`*Ckcvc>4W1yaX(@kcGGH)3w>f;vLC*Nfe zKVH70421DDLmpH|v3BxrBzI7gLe#D`rN=OW?PVeP(XI464@p9TM>ujZ4rhE&QWDW; zU%8vi@;HPd)%?+1IZp0UA)~RDK@Y(aDbvH-{k;n~eUL<>awplY&Rf;;D+W!5S}%?j z1*KM8B9^O}kHpNhLxCHSU(Ud--uwz(@+&kVW@hfh7F2NM7cKVa>Q?*YCl_z`7%?>z zV9yixzPj3)9;uG$aVH?n2Zug_+C@^O=et;%33;fNVKcqILs z9P@QfNYH$5gc;jkW#DH`93k8FCHnQ1nny~g_O(v*e-}8(?q5T~-*5mY{(eiVqIJZz z_BTvz!#U}&I-wz9IKHvBU4~_V=U-fJ`|K-% zlay)H3uZS!_JFeH#l(dJz$z6-=CY!BiX^q4eBZoUbXST=EIcrPG5=#atf^nD^nMd? z&40%N$?VI_3L}r1t2>t!($A_{XjCzUtZe=p9GU*u%JH^1-JWT2OE29$kt81g)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