comparison 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
comparison
equal deleted inserted replaced
162:f66108c1f674 163:f27a7c64b21f
22 local loc = ItemLocation.CreateEmpty() 22 local loc = ItemLocation.CreateEmpty()
23 23
24 if not usedItems[bagId] then 24 if not usedItems[bagId] then
25 usedItems[bagId] = {} 25 usedItems[bagId] = {}
26 end 26 end
27
28 local bestMatchDiffs = 1000000
29 local bestMatch = nil
30 local threshold
27 31
28 for slotId = 1, numSlots do 32 for slotId = 1, numSlots do
29 if not usedItems[bagId][slotId] then 33 if not usedItems[bagId][slotId] then
30 local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId) 34 local _, itemCount, _, _, _, _, itemLink = GetContainerItemInfo(bagId, slotId)
31 if itemLink ~= nil then 35 if itemLink ~= nil then
39 itemData.azerite = powers 43 itemData.azerite = powers
40 end 44 end
41 end 45 end
42 46
43 -- see if it matches 47 -- see if it matches
44 if Amr.CountItemDifferences(matchItem, itemData) == 0 then 48 local diffs = Amr.CountItemDifferences(matchItem, itemData)
49 if diffs == 0 then
45 usedItems[bagId][slotId] = true 50 usedItems[bagId][slotId] = true
46 itemData.bagId = bagId 51 itemData.bagId = bagId
47 itemData.slotId = slotId 52 itemData.slotId = slotId
48 return itemData 53 return itemData
54 elseif diffs < 10000 then
55 if itemData.azerite and #itemData.azerite > 0 then
56 threshold = 100
57 else
58 threshold = 10000
59 end
60 if diffs < threshold and diffs < bestMatchDiffs then
61 -- closest match we could find
62 bestMatchDiffs = diffs
63 itemData.bagId = bagId
64 itemData.slotId = slotId
65 bestMatch = itemData
66 end
49 end 67 end
50 end 68 end
51 end 69 end
52 end 70 end
53 end 71 end
54 72
55 return nil 73 -- if we couldn't get a perfect match, take the best match that might have some small differences like
74 -- an old school enchant or upgrade ID that didn't load
75 if bestMatch then
76 usedItems[bestMatch.bagId][bestMatch.slotId] = true
77 return bestMatch
78 else
79 return nil
80 end
56 end 81 end
57 82
58 -- 83 --
59 -- Find a matching item in the player's bags 84 -- Find a matching item in the player's bags
60 -- 85 --
404 end 429 end
405 end 430 end
406 end 431 end
407 432
408 -- check bank data 433 -- check bank data
434 local bestMatchDiffs = 100000
435 local bestMatch = nil
436 local threshold
437
409 if Amr.db.char.BankItems then 438 if Amr.db.char.BankItems then
410 for bagId, v in pairs(Amr.db.char.BankItems) do 439 for bagId, v in pairs(Amr.db.char.BankItems) do
411 if not usedItems[bagId] then 440 if not usedItems[bagId] then
412 usedItems[bagId] = {} 441 usedItems[bagId] = {}
413 end 442 end
414 443
415 for i, itemData in ipairs(v) do 444 for i, itemData in ipairs(v) do
416 if itemData and not usedItems[bagId][i] then 445 if itemData and not usedItems[bagId][i] then
417 -- see if it matches 446 -- see if it matches
418 if Amr.CountItemDifferences(matchItem, itemData) == 0 then 447 local diffs = Amr.CountItemDifferences(matchItem, itemData)
448 if diffs == 0 then
419 usedItems[bagId][i] = true 449 usedItems[bagId][i] = true
420 itemData.bagId = bagId 450 itemData.bagId = bagId
421 itemData.slotId = i 451 itemData.slotId = i
422 return itemData 452 return itemData
453 elseif diffs < 10000 then
454 if itemData.azerite and #itemData.azerite > 0 then
455 threshold = 100
456 else
457 threshold = 10000
458 end
459 if diffs < threshold and diffs < bestMatchDiffs then
460 -- closest match we could find
461 bestMatchDiffs = diffs
462 itemData.bagId = bagId
463 itemData.slotId = i
464 bestMatch = itemData
465 end
423 end 466 end
424 end 467 end
425 end 468 end
426 end 469 end
427 end 470 end
428 471
429 return nil 472 -- if we couldn't get a perfect match, take the best match that might have some small differences like
473 -- an old school enchant or upgrade ID that didn't load
474 if bestMatch then
475 usedItems[bestMatch.bagId][bestMatch.slotId] = true
476 return bestMatch
477 else
478 return nil
479 end
430 end 480 end
431 481
432 local function renderItem(item, itemLink, scroll) 482 local function renderItem(item, itemLink, scroll)
433 483
434 local panel = AceGUI:Create("AmrUiPanel") 484 local panel = AceGUI:Create("AmrUiPanel")