From 277b065a284ee9a2b2bb3839b0ed2fd291eb4f60 Mon Sep 17 00:00:00 2001 From: avirar Date: Fri, 15 Nov 2024 01:19:14 +1100 Subject: [PATCH] Updated ItemUsageValue to handle unique items that are not equipped (#712) * Update ItemUsageValue.cpp Added logic to handle unique/unique-equippable items that are not equipped yet. Reevaluated dest from dstSlot in cases where dest ==0 * Update ItemUsageValue.cpp Merged logic for both types of unique items. --- src/strategy/values/ItemUsageValue.cpp | 44 ++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/strategy/values/ItemUsageValue.cpp b/src/strategy/values/ItemUsageValue.cpp index c82a3e25..5c5e38e1 100644 --- a/src/strategy/values/ItemUsageValue.cpp +++ b/src/strategy/values/ItemUsageValue.cpp @@ -170,8 +170,38 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) pItem->RemoveFromUpdateQueueOf(bot); delete pItem; - if (result != EQUIP_ERR_OK) + if (result != EQUIP_ERR_OK && result != EQUIP_ERR_CANT_CARRY_MORE_OF_THIS) + { return ITEM_USAGE_NONE; + } + // Check is unique items are equipped or not + bool needToCheckUnique = false; + if (result == EQUIP_ERR_CANT_CARRY_MORE_OF_THIS) + { + needToCheckUnique = true; + } + else if (itemProto->Flags & ITEM_FLAG_UNIQUE_EQUIPPABLE) + { + needToCheckUnique = true; + } + + if (needToCheckUnique) + { + // Count the total number of the item (equipped + in bags) + uint32 totalItemCount = bot->GetItemCount(itemProto->ItemId, true); + + // Count the number of the item in bags only + uint32 bagItemCount = bot->GetItemCount(itemProto->ItemId, false); + + // Determine if the unique item is already equipped + bool isEquipped = (totalItemCount > bagItemCount); + + if (isEquipped) + { + return ITEM_USAGE_NONE; // Item is already equipped + } + // If not equipped, continue processing + } if (itemProto->Class == ITEM_CLASS_QUIVER) if (bot->getClass() != CLASS_HUNTER) @@ -207,7 +237,17 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) uint8 possibleSlots = 1; uint8 dstSlot = botAI->FindEquipSlot(itemProto, NULL_SLOT, true); - + // Check if dest wasn't set correctly by CanEquipItem and use FindEquipSlot instead + // This occurs with unique items that are already in the bots bags when CanEquipItem is called + if (dest == 0) + { + if (dstSlot != NULL_SLOT) + { + // Construct dest from dstSlot + dest = (INVENTORY_SLOT_BAG_0 << 8) | dstSlot; + } + } + if (dstSlot == EQUIPMENT_SLOT_FINGER1 || dstSlot == EQUIPMENT_SLOT_TRINKET1) { possibleSlots = 2;