Split grabRangeMultiplier from CalamityGlobalItem

This commit is contained in:
Flowaria authored and Cameron Ewell committed 2025-12-16 18:02:45 -05:00
1 parent 06ec9677de
commit 6904f51ee4
3 files changed
+42 -9

No files matched your search

+2 -8
View File
@@ -125,11 +125,6 @@ namespace CalamityMod.Items
/// Adds "- Dev Item -" to the bottom of the item's tooltip.
/// </summary>
public bool devItem = false;
/// <summary>
/// If set to a value greater than 1, applies a multiplier to the item's grab range.<br/>
/// Used by coin items spawned from hitting ricoshot coins.
/// </summary>
public float grabRangeMultiplier = 1f;
public static readonly Color ExhumedTooltipColor = new Color(198, 27, 64);
@@ -168,7 +163,6 @@ namespace CalamityMod.Items
myClone.revengeanceItem = revengeanceItem;
myClone.donorItem = donorItem;
myClone.devItem = devItem;
myClone.grabRangeMultiplier = grabRangeMultiplier;
return myClone;
}
@@ -1448,8 +1442,8 @@ namespace CalamityMod.Items
public override void GrabRange(Item item, Player player, ref int grabRange)
{
// First, apply the grab range multiplier.
if (grabRangeMultiplier > 1f)
grabRange = (int)(grabRangeMultiplier * grabRange);
if (item.TryGetGlobalItem<GrabRangeGlobalItem>(out var grabRangeItem) && grabRangeItem.grabRangeMultiplier > 1f)
grabRange = (int)(grabRangeItem.grabRangeMultiplier * grabRange);
// Then, apply flat grab range boosts.
if (player.Calamity().reaverExplore)
+37
View File
@@ -0,0 +1,37 @@
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items;
internal sealed class GrabRangeGlobalItem : GlobalItem
{
/// <summary>
/// If set to a value greater than 1, applies a multiplier to the item's grab range.<br/>
/// Used by coin items spawned from hitting ricoshot coins.
/// </summary>
public float grabRangeMultiplier = 1f;
public override bool InstancePerEntity => true;
public override bool AppliesToEntity(Item entity, bool lateInstantiation)
{
return entity.type switch
{
ItemID.CopperCoin
or ItemID.SilverCoin
or ItemID.GoldCoin
or ItemID.PlatinumCoin => true,
_ => false,
};
}
public override GlobalItem Clone(Item item, Item itemClone)
{
GrabRangeGlobalItem myClone = (GrabRangeGlobalItem)base.Clone(item, itemClone);
myClone.grabRangeMultiplier = grabRangeMultiplier;
return myClone;
}
// GrabRange hook is Placed in CalamityGlobalItem for sake of ordering
}
+3 -1
View File
@@ -1,4 +1,5 @@
using System;
using CalamityMod.Items;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
@@ -243,7 +244,8 @@ namespace CalamityMod.Projectiles.Ranged
_ => ItemID.CopperCoin,
};
int coin = Item.NewItem(Projectile.GetSource_DropAsItem(), Projectile.Center, Vector2.One, itemID, noBroadcast: false);
Main.item[coin].Calamity().grabRangeMultiplier = UsedCoinGrabRangeMultiplier;
if (Main.item[coin].TryGetGlobalItem<GrabRangeGlobalItem>(out var grabRangeItem))
grabRangeItem.grabRangeMultiplier = UsedCoinGrabRangeMultiplier;
// Sync this dropped coin in multiplayer.
if (Main.netMode == NetmodeID.MultiplayerClient)