Mercurial > wow > askmrrobot
comparison Gear.lua @ 191:4aeedce4c995 v93
Added better identification of duplicate items.
| author | yellowfive | 
|---|---|
| date | Fri, 30 Oct 2020 21:14:57 -0700 | 
| parents | a7f2ba17c39a | 
| children | 4ccc9ff6e824 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 190:4232d073a90b | 191:4aeedce4c995 | 
|---|---|
| 27 return 0 | 27 return 0 | 
| 28 end | 28 end | 
| 29 | 29 | 
| 30 -- one nil and other not, or different id, totally different | 30 -- one nil and other not, or different id, totally different | 
| 31 if (not item1 and item2) or (item1 and not item2) or item1.id ~= item2.id then | 31 if (not item1 and item2) or (item1 and not item2) or item1.id ~= item2.id then | 
| 32 return 100000 | 32 return 1000000 | 
| 33 end | 33 end | 
| 34 | 34 | 
| 35 -- different versions of same item (id + bonus ids + suffix + drop level, constitutes a different physical drop) | 35 -- different versions of same item (id + bonus ids + suffix + drop level, constitutes a different physical drop) | 
| 36 if Amr.GetItemUniqueId(item1, true, true) ~= Amr.GetItemUniqueId(item2, true, true) then | 36 if Amr.GetItemUniqueId(item1, true, true) ~= Amr.GetItemUniqueId(item2, true, true) then | 
| 37 return 10000 | 37 return 100000 | 
| 38 end | 38 end | 
| 39 | 39 | 
| 40 -- different upgrade levels of the same item | 40 -- different upgrade levels of the same item | 
| 41 if item1.upgradeId ~= item2.upgradeId then | 41 if item1.upgradeId ~= item2.upgradeId then | 
| 42 return 1000 | 42 return 10000 | 
| 43 end | 43 end | 
| 44 | 44 | 
| 45 -- a change that requires reforging is considered more different than a change that does not; | 45 -- a change that requires reforging is considered more different than a change that does not; | 
| 46 -- it is assumed that item1 is how we want the item to be in the end, and item2 is how it currently is | 46 -- it is assumed that item1 is how we want the item to be in the end, and item2 is how it currently is | 
| 47 local aztReforges = 0 | 47 local aztReforges = 0 | 
| 49 | 49 | 
| 50 if item1.id == item2.id and (item1.azerite or item2.azerite) then | 50 if item1.id == item2.id and (item1.azerite or item2.azerite) then | 
| 51 -- azerite that needs to be reforged | 51 -- azerite that needs to be reforged | 
| 52 if item2.azerite and not item1.azerite then | 52 if item2.azerite and not item1.azerite then | 
| 53 -- kind of a dumb case... but we would need to blank all azerite on item2 to match item1 | 53 -- kind of a dumb case... but we would need to blank all azerite on item2 to match item1 | 
| 54 aztReforges = #item2.azerite * 100 | 54 aztReforges = #item2.azerite * 1000 | 
| 55 elseif item2.azerite then | 55 elseif item2.azerite then | 
| 56 -- count up azerite on item2 but not on item1, these would need to be reforged | 56 -- count up azerite on item2 but not on item1, these would need to be reforged | 
| 57 for i = 1, #item2.azerite do | 57 for i = 1, #item2.azerite do | 
| 58 local missing = true | 58 local missing = true | 
| 59 for j = 1, #item1.azerite do | 59 for j = 1, #item1.azerite do | 
| 60 if item1.azerite[j] == item2.azerite[i] then | 60 if item1.azerite[j] == item2.azerite[i] then | 
| 61 missing = false | 61 missing = false | 
| 62 end | 62 end | 
| 63 end | 63 end | 
| 64 if missing then | 64 if missing then | 
| 65 aztReforges = aztReforges + 100 | 65 aztReforges = aztReforges + 1000 | 
| 66 end | 66 end | 
| 67 end | 67 end | 
| 68 end | 68 end | 
| 69 | 69 | 
| 70 -- azerite that needs to be selected | 70 -- azerite that needs to be selected | 
| 71 if item1.azerite and not item2.azerite then | 71 if item1.azerite and not item2.azerite then | 
| 72 -- item2 is blank, so just need to choose all the right ones | 72 -- item2 is blank, so just need to choose all the right ones | 
| 73 aztSelects = #item1.azerite * 10 | 73 aztSelects = #item1.azerite * 100 | 
| 74 elseif item1.azerite then | 74 elseif item1.azerite then | 
| 75 -- count up azerite on item1 but not on item2, these would need to be selected | 75 -- count up azerite on item1 but not on item2, these would need to be selected | 
| 76 for i = 1, #item1.azerite do | 76 for i = 1, #item1.azerite do | 
| 77 local missing = true | 77 local missing = true | 
| 78 for j = 1, #item2.azerite do | 78 for j = 1, #item2.azerite do | 
| 79 if item2.azerite[j] == item1.azerite[i] then | 79 if item2.azerite[j] == item1.azerite[i] then | 
| 80 missing = false | 80 missing = false | 
| 81 end | 81 end | 
| 82 end | 82 end | 
| 83 if missing then | 83 if missing then | 
| 84 aztSelects = aztSelects + 10 | 84 aztSelects = aztSelects + 100 | 
| 85 end | 85 end | 
| 86 end | 86 end | 
| 87 end | 87 end | 
| 88 end | 88 end | 
| 89 | 89 | 
| 90 -- different gems | 90 -- different gems | 
| 91 local gemDiffs = 0 | 91 local gemDiffs = 0 | 
| 92 for i = 1, 3 do | 92 for i = 1, 3 do | 
| 93 if item1.gemIds[i] ~= item2.gemIds[i] then | 93 if item1.gemIds[i] ~= item2.gemIds[i] then | 
| 94 gemDiffs = gemDiffs + 1 | 94 gemDiffs = gemDiffs + 10 | 
| 95 end | 95 end | 
| 96 end | 96 end | 
| 97 | 97 | 
| 98 -- different enchants | 98 -- different enchants | 
| 99 local enchantDiff = 0 | 99 local enchantDiff = 0 | 
| 100 if item1.enchantId ~= item2.enchantId then | 100 if item1.enchantId ~= item2.enchantId then | 
| 101 enchantDiff = 1 | 101 enchantDiff = 10 | 
| 102 end | 102 end | 
| 103 | 103 | 
| 104 return aztReforges + aztSelects + gemDiffs + enchantDiff | 104 -- different guid | 
| 105 local guidDiff = 0 | |
| 106 if item1.guid and item2.guid and item1.guid ~= item2.guid then | |
| 107 guidDiff = 1 | |
| 108 end | |
| 109 | |
| 110 return aztReforges + aztSelects + gemDiffs + enchantDiff + guidDiff | |
| 105 end | 111 end | 
| 106 | 112 | 
| 107 -- given a table of items (keyed or indexed doesn't matter) find closest match to item, or nil if none are a match | 113 -- given a table of items (keyed or indexed doesn't matter) find closest match to item, or nil if none are a match | 
| 108 local function findMatchingItemFromTable(item, list, bestItem, bestDiff, bestLoc, usedItems, tableType) | 114 local function findMatchingItemFromTable(item, list, bestItem, bestDiff, bestLoc, usedItems, tableType) | 
| 109 if not list then return nil end | 115 if not list then return nil end | 
| 132 -- search the player's equipped gear, bag, and bank for an item that best matches the specified item | 138 -- search the player's equipped gear, bag, and bank for an item that best matches the specified item | 
| 133 function Amr:FindMatchingItem(item, player, usedItems) | 139 function Amr:FindMatchingItem(item, player, usedItems) | 
| 134 if not item then return nil end | 140 if not item then return nil end | 
| 135 | 141 | 
| 136 local equipped = player.Equipped and player.Equipped[player.ActiveSpec] or nil | 142 local equipped = player.Equipped and player.Equipped[player.ActiveSpec] or nil | 
| 137 local bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, equipped, nil, 100000, nil, usedItems, "equip") | 143 local bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, equipped, nil, 1000000, nil, usedItems, "equip") | 
| 138 bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BagItems, bestItem, bestDiff, bestLoc, usedItems, "bag") | 144 bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BagItems, bestItem, bestDiff, bestLoc, usedItems, "bag") | 
| 139 if player.BankItems then | 145 if player.BankItems then | 
| 140 bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BankItems, bestItem, bestDiff, bestLoc, usedItems, "bank") | 146 bestItem, bestDiff, bestLoc = findMatchingItemFromTable(item, player.BankItems, bestItem, bestDiff, bestLoc, usedItems, "bank") | 
| 141 end | 147 end | 
| 142 | 148 | 
| 143 if bestDiff >= 100000 then | 149 if bestDiff >= 1000000 then | 
| 144 return nil, 100000 | 150 return nil, 1000000 | 
| 145 else | 151 else | 
| 146 usedItems[bestLoc] = true | 152 usedItems[bestLoc] = true | 
| 147 return bestItem, bestDiff | 153 return bestItem, bestDiff | 
| 148 end | 154 end | 
| 149 end | 155 end | 
| 300 | 306 | 
| 301 -- see if item is currently equipped, is false if don't have any item for that slot (e.g. OH for a 2-hander) | 307 -- see if item is currently equipped, is false if don't have any item for that slot (e.g. OH for a 2-hander) | 
| 302 local isEquipped = false | 308 local isEquipped = false | 
| 303 if equippedItem and optimalItem and Amr.GetItemUniqueId(equippedItem, false, true) == Amr.GetItemUniqueId(optimalItem, false, true) then | 309 if equippedItem and optimalItem and Amr.GetItemUniqueId(equippedItem, false, true) == Amr.GetItemUniqueId(optimalItem, false, true) then | 
| 304 | 310 | 
| 305 if slotId == 1 or slotId == 3 or slotId == 5 then | 311 if optimalItem.guid then | 
| 306 -- show the item as not equipped if azerite doesn't match... might mean they have to switch to another version of same item | 312 isEquipped = optimalItem.guid == equippedItem.guid | 
| 307 local aztDiff = countItemDifferences(optimalItem, equippedItem) | 313 else | 
| 308 if aztDiff < 10 then | 314 --[[if slotId == 1 or slotId == 3 or slotId == 5 then | 
| 315 -- show the item as not equipped if azerite doesn't match... might mean they have to switch to another version of same item | |
| 316 local aztDiff = countItemDifferences(optimalItem, equippedItem) | |
| 317 if aztDiff < 100 then | |
| 318 isEquipped = true | |
| 319 end | |
| 320 else]] | |
| 309 isEquipped = true | 321 isEquipped = true | 
| 310 end | 322 --end | 
| 311 else | |
| 312 isEquipped = true | |
| 313 end | 323 end | 
| 314 end | 324 end | 
| 315 | 325 | 
| 316 --local isAzerite = optimalItem and C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID(optimalItem.id) | 326 --local isAzerite = optimalItem and C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID(optimalItem.id) | 
| 317 --local isEssence = essences and optimalItem and optimalItem.id == 158075 | 327 --local isEssence = essences and optimalItem and optimalItem.id == 158075 | 
