From d0167ffe4e4d1eaf935d58a55caffcce2b5ee4c7 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Tue, 9 Dec 2025 08:22:05 +0900 Subject: [PATCH] Separate StealthStrikePrefixBonus from CalamityGlobalItem --- CalPlayer/CalamityPlayer.cs | 6 +++--- Items/CalamityGlobalItem.cs | 19 ------------------- Items/RogueGlobalItem.cs | 33 +++++++++++++++++++++++++++++++++ Prefixes/RogueWeaponPrefix.cs | 5 +++-- 4 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 Items/RogueGlobalItem.cs diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 5521a0b86d..072b2e0681 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -4861,13 +4861,13 @@ namespace CalamityMod.CalPlayer #region Get Weapon Damage And KB public override void ModifyWeaponDamage(Item item, ref StatModifier damage) { - if (item.CountsAsClass()) + if (item.CountsAsClass() && item.TryGetGlobalItem(out var rogueItem)) { // Apply weapon modifier stealth strike damage bonus // 01OCT2023: Ozzatron: This is a multiplicative bonus because it is a prefix. // It should be equivalent to x1.15 (or whatever multiplier) on the base damage of the weapon for stealth only. - if (item.Calamity().StealthStrikePrefixBonus != 0f && StealthStrikeAvailable()) - damage *= item.Calamity().StealthStrikePrefixBonus; // This number centers on 1f, so 1.15f = 1.15x damage. + if (rogueItem.StealthStrikePrefixBonus != 0f && StealthStrikeAvailable()) + damage *= rogueItem.StealthStrikePrefixBonus; // This number centers on 1f, so 1.15f = 1.15x damage. } } diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index 93bbdc5796..e68e7c24ac 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -52,10 +52,6 @@ namespace CalamityMod.Items { public override bool InstancePerEntity => true; - // TODO -- split out a separate GlobalItem for rogue behavior? - /// Tracks the stealth strike damage modifier for this item, derived from its prefix. - internal float StealthStrikePrefixBonus; - private BitsByte flag0 = 0; #region Chargeable Item Variables @@ -150,11 +146,6 @@ namespace CalamityMod.Items public static readonly Color ExhumedTooltipColor = new Color(198, 27, 64); - public CalamityGlobalItem() - { - StealthStrikePrefixBonus = 0f; - } - // Ozzatron 21MAY2022: This function is required by TML 1.4's new clone behavior. // This behavior is sadly mandatory because there are a few places in vanilla Terraria which use cloning. // Most notably: reforging and item tooltips. @@ -169,9 +160,6 @@ namespace CalamityMod.Items // BitFlags myClone.flag0 = flag0; - // Rogue - myClone.StealthStrikePrefixBonus = StealthStrikePrefixBonus; - // Charge (Draedon's Arsenal) myClone.UsesCharge = UsesCharge; myClone.Charge = Charge; @@ -1684,13 +1672,6 @@ namespace CalamityMod.Items public static int RarityCalamityRedBuyPrice => Rarity17BuyPrice; #endregion - #region PreReforge - public override void PreReforge(Item item) - { - StealthStrikePrefixBonus = 0f; - } - #endregion - // // !! WARNING !! // diff --git a/Items/RogueGlobalItem.cs b/Items/RogueGlobalItem.cs new file mode 100644 index 0000000000..0215e92a00 --- /dev/null +++ b/Items/RogueGlobalItem.cs @@ -0,0 +1,33 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Items +{ + public sealed class RogueGlobalItem : GlobalItem + { + public override bool InstancePerEntity => true; + + /// Tracks the stealth strike damage modifier for this item, derived from its prefix. + internal float StealthStrikePrefixBonus = 0.0f; + + public override GlobalItem Clone(Item from, Item to) + { + RogueGlobalItem myClone = (RogueGlobalItem)base.Clone(from, to); + + // Rogue + myClone.StealthStrikePrefixBonus = StealthStrikePrefixBonus; + + return myClone; + } + + public override bool AppliesToEntity(Item entity, bool lateInstantiation) + { + return entity.CountsAsClass(); + } + + public override void PreReforge(Item item) + { + StealthStrikePrefixBonus = 0f; + } + } +} diff --git a/Prefixes/RogueWeaponPrefix.cs b/Prefixes/RogueWeaponPrefix.cs index 56bfb5bd0b..0298790b1d 100644 --- a/Prefixes/RogueWeaponPrefix.cs +++ b/Prefixes/RogueWeaponPrefix.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using CalamityMod.Items; using Terraria; using Terraria.Localization; using Terraria.ModLoader; @@ -153,8 +154,8 @@ namespace CalamityMod.Prefixes // Applying stealth strike damage public override void Apply(Item item) { - if (item.CountsAsClass()) - item.Calamity().StealthStrikePrefixBonus = stealthDmgMult; + if (item.CountsAsClass() && item.TryGetGlobalItem(out var rogueItem)) + rogueItem.StealthStrikePrefixBonus = stealthDmgMult; } // Changing value based on prefix tier (rarity is set automatically around value multiplier)