diff Junk.lua @ 163:f27a7c64b21f v76

Tweaks to item matching in junk list features.
author yellowfive
date Mon, 06 May 2019 18:05:16 -0700
parents f66108c1f674
children eec8032ba9df
line wrap: on
line diff
--- a/Junk.lua	Mon May 06 17:06:26 2019 -0700
+++ b/Junk.lua	Mon May 06 18:05:16 2019 -0700
@@ -25,6 +25,10 @@
         usedItems[bagId] = {}
     end
 
+    local bestMatchDiffs = 1000000
+    local bestMatch = nil
+    local threshold
+
     for slotId = 1, numSlots do
         if not usedItems[bagId][slotId] then
             local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
@@ -41,18 +45,39 @@
                     end
                     
                     -- see if it matches
-                    if Amr.CountItemDifferences(matchItem, itemData) == 0 then
+                    local diffs = Amr.CountItemDifferences(matchItem, itemData)
+                    if diffs == 0 then
                         usedItems[bagId][slotId] = true
                         itemData.bagId = bagId
                         itemData.slotId = slotId
                         return itemData
+                    elseif diffs < 10000 then                        
+                        if itemData.azerite and #itemData.azerite > 0 then
+                            threshold = 100
+                        else
+                            threshold = 10000
+                        end
+                        if diffs < threshold and diffs < bestMatchDiffs then
+                            -- closest match we could find
+                            bestMatchDiffs = diffs
+                            itemData.bagId = bagId
+                            itemData.slotId = slotId
+                            bestMatch = itemData
+                        end
                     end
                 end
             end
         end
     end
-    
-    return nil
+
+    -- if we couldn't get a perfect match, take the best match that might have some small differences like
+    -- an old school enchant or upgrade ID that didn't load    
+    if bestMatch then
+        usedItems[bestMatch.bagId][bestMatch.slotId] = true
+        return bestMatch
+    else
+        return nil
+    end
 end
 
 --
@@ -406,6 +431,10 @@
     end
     
     -- check bank data
+    local bestMatchDiffs = 100000
+    local bestMatch = nil
+    local threshold
+
     if Amr.db.char.BankItems then
         for bagId, v in pairs(Amr.db.char.BankItems) do            
             if not usedItems[bagId] then
@@ -415,18 +444,39 @@
             for i, itemData in ipairs(v) do
                 if itemData and not usedItems[bagId][i] then
                     -- see if it matches
-                    if Amr.CountItemDifferences(matchItem, itemData) == 0 then
+                    local diffs = Amr.CountItemDifferences(matchItem, itemData)
+                    if diffs == 0 then
                         usedItems[bagId][i] = true
                         itemData.bagId = bagId
                         itemData.slotId = i
                         return itemData
+                    elseif diffs < 10000 then                        
+                        if itemData.azerite and #itemData.azerite > 0 then
+                            threshold = 100
+                        else
+                            threshold = 10000
+                        end
+                        if diffs < threshold and diffs < bestMatchDiffs then
+                            -- closest match we could find
+                            bestMatchDiffs = diffs
+                            itemData.bagId = bagId
+                            itemData.slotId = i
+                            bestMatch = itemData
+                        end
                     end
                 end
             end
         end
     end
 
-    return nil
+    -- if we couldn't get a perfect match, take the best match that might have some small differences like
+    -- an old school enchant or upgrade ID that didn't load    
+    if bestMatch then
+        usedItems[bestMatch.bagId][bestMatch.slotId] = true
+        return bestMatch
+    else
+        return nil
+    end
 end
 
 local function renderItem(item, itemLink, scroll)