diff --git a/Items/Tools/TheGift.cs b/Items/Tools/TheGift.cs new file mode 100644 index 0000000000..7762a59070 --- /dev/null +++ b/Items/Tools/TheGift.cs @@ -0,0 +1,83 @@ +using CalamityMod.NPCs; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Tools +{ + public class TheGift : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Tools"; + public override string Texture => "Terraria/Images/Item_601"; //Placeholder + + public override void SetDefaults() + { + Item.width = Item.height = 20; + Item.maxStack = Item.CommonMaxStack; + Item.useTime = Item.useAnimation = 10; + Item.useStyle = ItemUseStyleID.Swing; + Item.useTurn = true; + Item.noMelee = true; + Item.UseSound = SoundID.Item1; + Item.autoReuse = true; + Item.value = CalamityGlobalItem.RarityGreenBuyPrice; + Item.rare = ItemRarityID.Green; + } + + public override void Load() + { + On_ShopHelper.ProcessMood += TheGiftHappiness; + } + + public override void Update(ref float gravity, ref float maxFallSpeed) + { + // Controls actually applying the effect to an NPC + // None of this should work in Remix because Remix disables happiness + if (Item.noGrabDelay <= 0 && !Main.remixWorld) + { + foreach (NPC n in Main.ActiveNPCs) + { + // Don't run this code for the Traveling Merchant and Skeleton Merchant because they aren't affected by happiness + // Also don't run this if The Gift has already been used on this NPC; they all will hold grudges against you :) + if (!n.isLikeATownNPC || n.type == NPCID.TravellingMerchant || n.type == NPCID.SkeletonMerchant || + n.GetGlobalNPC().TheGiftStatus.HasValue) + continue; + + if (Item.Hitbox.Intersects(n.Hitbox)) + { + Item.active = false; + Item.type = ItemID.None; + Item.stack = 0; + if (Main.dedServ) + NetMessage.SendData(MessageID.SyncItem, -1, -1, null, Item.whoAmI); + + bool positive = Main.rand.NextBool(); + Color c = positive ? Color.Green : Color.Red; + n.GetGlobalNPC().TheGiftStatus = positive; + + // Placeholder visual effect + HealingPlus s = new(n.Center, 2f, Vector2.Zero, c, c, 40); + GeneralParticleHandler.SpawnParticle(s); + } + } + } + } + + private static void TheGiftHappiness(On_ShopHelper.orig_ProcessMood orig, ShopHelper self, Player player, NPC npc) + { + orig(self, player, npc); + + bool? gift = npc.GetGlobalNPC().TheGiftStatus; + if (gift.HasValue) + { + if (gift.Value) + self._currentPriceAdjustment = 0.5f; + else + self._currentPriceAdjustment = 1.75f; + } + } + } +} diff --git a/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson b/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson index 75bc1378a2..ffab1c0245 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Tools.hjson @@ -358,6 +358,16 @@ TectonicTruncator: { Tooltip: "" } +TheGift: { + DisplayName: The Gift + Tooltip: + ''' + Drop this fine gift on one of your Town NPCs as a token of appreciation + May make them either love you or hate you, you'll never know until they open it! + [c/F54278:'There's no return policy, better be responsible'] + ''' +} + TorrentialTear: { DisplayName: Torrential Tear Tooltip: diff --git a/NPCs/CalamityGlobalTownNPC.cs b/NPCs/CalamityGlobalTownNPC.cs index 0d477e9611..0321e81d36 100644 --- a/NPCs/CalamityGlobalTownNPC.cs +++ b/NPCs/CalamityGlobalTownNPC.cs @@ -70,6 +70,11 @@ namespace CalamityMod.NPCs public int shopAlertAnimTimer = 0; /// public int shopAlertAnimFrame = 0; + /// + /// Controls how this Town NPC is being affected by The Gift.
+ /// If true, happiness is overriden with an extremely high value. If false, happiness is overriden with an extremely low value. If null, uses vanilla happiness. + ///
+ public bool? TheGiftStatus = null; public override bool InstancePerEntity => true; @@ -85,6 +90,7 @@ namespace CalamityMod.NPCs myClone.setNewName = setNewName; myClone.shopAlertAnimTimer = shopAlertAnimTimer; myClone.shopAlertAnimFrame = shopAlertAnimFrame; + myClone.TheGiftStatus = TheGiftStatus; return myClone; }