fix: sorting quiver, ammo fixed

This commit is contained in:
Salikh Gurgenidze
2025-11-19 17:35:38 +04:00
parent 8a885d0ad9
commit a6957fc16a
3 changed files with 151 additions and 93 deletions
+84 -74
View File
@@ -46,6 +46,33 @@ end
-- Get item info with caching -- Get item info with caching
local itemCache = {} local itemCache = {}
local function DebugGetItemInfo(itemID, itemName)
if not itemID then
addon:Print("NO ITEM ID for: " .. tostring(itemName))
return
end
local itemName, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount,
itemSubType, itemTexture, itemEquipLoc, itemSellPrice = GetItemInfo(itemID)
addon:Print("=== GetItemInfo DEBUG ===")
addon:Print(string.format("Input ItemID: %d", itemID))
addon:Print(string.format("Input Name: %s", tostring(itemName)))
addon:Print("--- Return Values ---")
addon:Print(string.format("1. itemName: '%s'", tostring(itemName)))
addon:Print(string.format("2. itemLink: '%s'", tostring(itemLink)))
addon:Print(string.format("3. itemRarity: %s", itemRarity or 0))
addon:Print(string.format("4. itemLevel: %s", itemLevel or 0))
addon:Print(string.format("5. itemMinLevel: %s", itemMinLevel or 0))
addon:Print(string.format("6. itemType: '%s'", tostring(itemType)))
addon:Print(string.format("7. itemSubType: '%s'", tostring(itemSubType)))
addon:Print(string.format("8. itemStackCount: %s", itemStackCount or 0))
addon:Print(string.format("9. itemEquipLoc: '%s'", tostring(itemEquipLoc)))
addon:Print(string.format("10. itemTexture: '%s'", tostring(itemTexture)))
addon:Print(string.format("11. itemSellPrice: %s", itemSellPrice or 0))
addon:Print("=====================")
end
function Utils:GetItemInfo(itemLink) function Utils:GetItemInfo(itemLink)
if not itemLink then return nil end if not itemLink then return nil end
@@ -53,11 +80,16 @@ function Utils:GetItemInfo(itemLink)
return unpack(itemCache[itemLink]) return unpack(itemCache[itemLink])
end end
local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture = GetItemInfo(itemLink) -- Extract itemID from itemLink
local _, _, itemID = string.find(itemLink, "item:(%d+)")
if not itemID then return nil end
if name then -- Turtle WoW GetItemInfo signature:
itemCache[itemLink] = {name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture} -- itemName, itemLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice
return name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture local itemName, retLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice = GetItemInfo(tonumber(itemID))
if itemName then
itemCache[itemLink] = {itemName, retLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice}
return itemName, retLink, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, itemSubType, itemTexture, itemEquipLoc, itemSellPrice
end end
return nil return nil
@@ -227,25 +259,30 @@ function Utils:GetSpecializedBagType(bagID)
return nil return nil
end end
-- Use GetItemInfo to get subclass (more reliable than tooltip scanning) -- Extract itemID from link
local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link) local _, _, itemID = string.find(link, "item:(%d+)")
if not itemID then
return nil
end
if subclass then -- Use GetItemInfo to get subType (Turtle WoW signature)
-- Check for exact subclass matches local itemName, _, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, itemSubType = GetItemInfo(tonumber(itemID))
local subclassLower = string.lower(subclass) if itemType then
-- Check for exact subtype matches
local typeLower = string.lower(itemType)
-- Soul Bag / Soul Pouch -- Soul Bag / Soul Pouch
if string.find(subclassLower, "soul bag") or string.find(subclassLower, "soul pouch") then if string.find(typeLower, "soul bag") or string.find(typeLower, "soul pouch") then
return "soul" return "soul"
end end
-- Quiver -- Quiver
if string.find(subclassLower, "quiver") then if string.find(typeLower, "quiver") then
return "quiver" return "quiver"
end end
-- Ammo Pouch -- Ammo Pouch
if string.find(subclassLower, "ammo pouch") then if string.find(typeLower, "ammo pouch") then
return "ammo" return "ammo"
end end
end end
@@ -285,72 +322,45 @@ local function ExtractHyperlink(itemLink)
end end
-- Check if item is Arrow or Bullet (for Quiver routing) -- Check if item is Arrow or Bullet (for Quiver routing)
function Utils:IsArrowOrBullet(itemLink) function Utils:IsArrowOrBullet(itemType)
if not itemLink then return false end if not itemType then return false end
-- Exact matching only
local hyperlink = ExtractHyperlink(itemLink) return itemType == "Arrow" or itemType == "Bullet"
if not hyperlink then return false end
-- Use tooltip scanning
local tooltip = GetScanTooltip()
tooltip:ClearLines()
tooltip:SetHyperlink(hyperlink)
for i = 1, tooltip:NumLines() do
local line = getglobal("GudaBagScanTooltipTextLeft" .. i)
if line then
local text = line:GetText()
if text then
if string.find(text, "Arrow") or string.find(text, "Bullet") then
return true
end
end
end
end
return false
end end
-- Check if item is Ammo (any type) -- Check if item is Ammo (any type - for Ammo Pouch)
function Utils:IsAmmo(itemLink) function Utils:IsAmmo(itemType)
if not itemLink then return false end if not itemType then return false end
return itemType == "Arrow" or itemType == "Bullet"
local hyperlink = ExtractHyperlink(itemLink)
if not hyperlink then return false end
-- Use tooltip scanning
local tooltip = GetScanTooltip()
tooltip:ClearLines()
tooltip:SetHyperlink(hyperlink)
for i = 1, tooltip:NumLines() do
local line = getglobal("GudaBagScanTooltipTextLeft" .. i)
if line then
local text = line:GetText()
if text then
-- Check for ammo keywords
if string.find(text, "Arrow") or
string.find(text, "Bullet") or
string.find(text, "Ammo") or
string.find(text, "Projectile") then
return true
end
end
end
end
return false
end end
-- Get preferred container type for an item -- Get preferred container type for an item
-- Returns: "soul", "quiver", "ammo", or nil -- Returns: "soul", "quiver", "ammo", or nil
function Utils:GetItemPreferredContainer(itemLink) function Utils:GetItemPreferredContainer(itemLink)
if self:IsSoulShard(itemLink) then if not itemLink then return nil end
return "soul"
elseif self:IsArrowOrBullet(itemLink) then -- Check for soul shards first
return "quiver" if self:IsSoulShard(itemLink) then
elseif self:IsAmmo(itemLink) then return "soul"
return "ammo" end
end
return nil -- Extract itemID and get item info
end local _, _, itemID = string.find(itemLink, "item:(%d+)")
if not itemID then return nil end
local itemName, _, itemRarity, itemLevel, itemCategory, itemType, itemStackCount, itemSubType = GetItemInfo(tonumber(itemID))
if not itemType then return nil end
-- Only route PROJECTILE category items that are specifically arrows or bullets
if itemCategory == "Projectile" then
if itemType == "Arrow" then
addon:Print("-> Routing to QUIVER (Projectile - Arrow)")
return "quiver"
elseif itemType == "Bullet" then
addon:Print("-> Routing to AMMO (Projectile - Bullet)")
return "ammo"
end
end
return nil
end
+6 -1
View File
@@ -36,7 +36,12 @@ function EquipmentScanner:ScanEquippedItems()
local itemLink = GetInventoryItemLink("player", slotID) local itemLink = GetInventoryItemLink("player", slotID)
if itemLink then if itemLink then
local itemName = GetItemInfo(itemLink) -- Extract itemID from link
local _, _, itemID = string.find(itemLink, "item:(%d+)")
local itemName
if itemID then
itemName = GetItemInfo(tonumber(itemID))
end
equipped[slotName] = { equipped[slotName] = {
link = itemLink, link = itemLink,
name = itemName, name = itemName,
+61 -18
View File
@@ -598,28 +598,52 @@ end
-- Main Sort Functions -- Main Sort Functions
--=========================================================================== --===========================================================================
--===========================================================================
-- Main Sort Functions
--===========================================================================
function SortEngine:SortBags() function SortEngine:SortBags()
local bagIDs = addon.Constants.BAGS local bagIDs = addon.Constants.BAGS
-- Phase 1: Detect specialized bags -- Phase 1: Detect specialized bags
local containers = DetectSpecializedBags(bagIDs) local containers = DetectSpecializedBags(bagIDs)
-- Phase 2: Route specialized items to their preferred bags -- Phase 2: Route specialized items to their bags
local routeCount = RouteSpecializedItems(bagIDs, containers) local routeCount = RouteSpecializedItems(bagIDs, containers)
-- Phase 3: Consolidate stacks in all bags -- Phase 3: Consolidate stacks in ALL bags (including specialized)
local consolidateCount = ConsolidateStacks(bagIDs) local consolidateCount = ConsolidateStacks(bagIDs)
-- Phase 4: Sort all bags together (ensures all equippable gear is grouped) -- Phase 4: Sort items WITHIN each specialized bag (soul, quiver, ammo)
local items = CollectItems(bagIDs) local specializedMoves = 0
local sortMoves = 0 for _, bagType in ipairs({"soul", "quiver", "ammo"}) do
if table.getn(items) > 0 then local specialBags = containers[bagType]
items = SortItems(items) for _, bagID in ipairs(specialBags) do
local targetPositions = BuildTargetPositions(bagIDs, table.getn(items)) -- Sort items within this single specialized bag
sortMoves = ApplySort(bagIDs, items, targetPositions) local items = CollectItems({bagID})
if table.getn(items) > 0 then
items = SortItems(items)
local targetPositions = BuildTargetPositions({bagID}, table.getn(items))
local moveCount = ApplySort({bagID}, items, targetPositions)
specializedMoves = specializedMoves + moveCount
end
end
end end
return routeCount + consolidateCount + sortMoves -- Phase 5: Categorical sort regular bags TOGETHER
local regularMoves = 0
local regularBagIDs = containers.regular
if table.getn(regularBagIDs) > 0 then
local items = CollectItems(regularBagIDs)
if table.getn(items) > 0 then
items = SortItems(items)
local targetPositions = BuildTargetPositions(regularBagIDs, table.getn(items))
regularMoves = ApplySort(regularBagIDs, items, targetPositions)
end
end
-- Return total moves made
return routeCount + consolidateCount + specializedMoves + regularMoves
end end
function SortEngine:SortBank() function SortEngine:SortBank()
@@ -639,14 +663,33 @@ function SortEngine:SortBank()
-- Phase 3: Consolidate stacks -- Phase 3: Consolidate stacks
local consolidateCount = ConsolidateStacks(bagIDs) local consolidateCount = ConsolidateStacks(bagIDs)
-- Phase 4: Sort all bags together -- Phase 4: Sort items WITHIN each specialized bag
local items = CollectItems(bagIDs) local specializedMoves = 0
local sortMoves = 0 for _, bagType in ipairs({"soul", "quiver", "ammo"}) do
if table.getn(items) > 0 then local specialBags = containers[bagType]
items = SortItems(items) for _, bagID in ipairs(specialBags) do
local targetPositions = BuildTargetPositions(bagIDs, table.getn(items)) local items = CollectItems({bagID})
sortMoves = ApplySort(bagIDs, items, targetPositions) if table.getn(items) > 0 then
items = SortItems(items)
local targetPositions = BuildTargetPositions({bagID}, table.getn(items))
local moveCount = ApplySort({bagID}, items, targetPositions)
specializedMoves = specializedMoves + moveCount
end
end
end end
return routeCount + consolidateCount + sortMoves -- Phase 5: Sort regular bags TOGETHER
local regularBagIDs = containers.regular
local regularMoves = 0
if table.getn(regularBagIDs) > 0 then
local items = CollectItems(regularBagIDs)
if table.getn(items) > 0 then
items = SortItems(items)
local targetPositions = BuildTargetPositions(regularBagIDs, table.getn(items))
regularMoves = ApplySort(regularBagIDs, items, targetPositions)
end
end
-- Return total moves made
return routeCount + consolidateCount + specializedMoves + regularMoves
end end