The Gift barebones implementation

I will defer the sprite and visual effects to Triangle and Xyk
This commit is contained in:
CongratsIsTrash committed 2026-03-15 12:53:48 -04:00
1 parent f0b867dcd7
commit e47f4c684a
3 files changed
+99

No files matched your search

+83
View File
@@ -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<CalamityGlobalTownNPC>().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<CalamityGlobalTownNPC>().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<CalamityGlobalTownNPC>().TheGiftStatus;
if (gift.HasValue)
{
if (gift.Value)
self._currentPriceAdjustment = 0.5f;
else
self._currentPriceAdjustment = 1.75f;
}
}
}
}
@@ -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:
+6
View File
@@ -70,6 +70,11 @@ namespace CalamityMod.NPCs
public int shopAlertAnimTimer = 0;
/// <summary> <inheritdoc cref="shopAlertAnimTimer"/> </summary>
public int shopAlertAnimFrame = 0;
/// <summary>
/// Controls how this Town NPC is being affected by The Gift.<br/>
/// 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.
/// </summary>
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;
}