From 72916e0dd6607e1bb52dac97b6af532f5c5c9ca4 Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 26 Jan 2026 11:03:52 -0500 Subject: [PATCH] Fixing item stacking --- Game/Dungeon/DungeonHandler.cs | 39 ++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index 2ce8ac4..567221b 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -3746,7 +3746,8 @@ public sealed partial class DungeonHandler : IClientMessageHandler /// /// Checks if two items can be stacked together. /// Items without crafted data can always stack (if same definition and stackable). - /// Items with crafted data can only stack if they have the same CraftedItem.Id. + /// Items with crafted data can stack if both have no actual rolled stats (all bonuses are 0), + /// or if they have the same CraftedItem.Id. /// private static bool CanStackItems(DungeonCharacterItem source, DungeonCharacterItem target) { @@ -3754,12 +3755,38 @@ public sealed partial class DungeonHandler : IClientMessageHandler if (source.CraftedItem == null && target.CraftedItem == null) return true; - // If one has crafted data and the other doesn't, they can't stack - if (source.CraftedItem == null || target.CraftedItem == null) - return false; + // If one has crafted data and the other doesn't, check if the crafted one has no actual stats + if (source.CraftedItem == null) + return !HasRolledStats(target.CraftedItem); + if (target.CraftedItem == null) + return !HasRolledStats(source.CraftedItem); - // Both have crafted data - they can only stack if it's the same crafted item - return source.CraftedItem.Id == target.CraftedItem.Id; + // Both have crafted data - they can stack if neither has rolled stats, or if same crafted item + if (source.CraftedItem.Id == target.CraftedItem.Id) + return true; + + // Different crafted items can stack if neither has actual rolled stats + return !HasRolledStats(source.CraftedItem) && !HasRolledStats(target.CraftedItem); + } + + /// + /// Checks if a crafted item has any non-zero rolled stats. + /// + private static bool HasRolledStats(DungeonCraftedItem crafted) + { + return crafted.RolledBonusStrength != 0 || + crafted.RolledBonusIntelligence != 0 || + crafted.RolledBonusWisdom != 0 || + crafted.RolledBonusEndurance != 0 || + crafted.RolledBonusDexterity != 0 || + crafted.RolledBonusHealth != 0 || + crafted.RolledBonusMana != 0 || + crafted.RolledBonusArmor != 0 || + crafted.RolledBonusMagicResist != 0 || + crafted.RolledBonusMinDamage != 0 || + crafted.RolledBonusMaxDamage != 0 || + crafted.RolledBonusHealAmount != 0 || + crafted.RolledBonusManaRestore != 0; } private async Task HandleAutoStackInventory(IConnection connection, DungeonPlayerSession session, CancellationToken ct)