Mercurial > wow > askmrrobot
comparison Gear.lua @ 73:304d7ebb8e30 v29
small bug fixes for item upgrades, gear swapping
author | yellowfive |
---|---|
date | Tue, 17 Nov 2015 20:52:06 -0800 |
parents | 6abc0858b45e |
children | 0515882856f1 |
comparison
equal
deleted
inserted
replaced
72:55598ba0d435 | 73:304d7ebb8e30 |
---|---|
38 | 38 |
39 -- given a table of items (keyed or indexed doesn't matter) find closest match to item, or nil if none are a match | 39 -- given a table of items (keyed or indexed doesn't matter) find closest match to item, or nil if none are a match |
40 local function findMatchingItemFromTable(item, list, bestLink, bestItem, bestDiff, bestLoc, usedItems, tableType) | 40 local function findMatchingItemFromTable(item, list, bestLink, bestItem, bestDiff, bestLoc, usedItems, tableType) |
41 if not list then return nil end | 41 if not list then return nil end |
42 | 42 |
43 local found = false | |
43 for k,v in pairs(list) do | 44 for k,v in pairs(list) do |
44 local listItem = Amr.ParseItemLink(v) | 45 local listItem = Amr.ParseItemLink(v) |
45 if listItem then | 46 if listItem then |
46 local diff = countItemDifferences(item, listItem) | 47 local diff = countItemDifferences(item, listItem) |
47 if diff < bestDiff then | 48 if diff < bestDiff then |
50 if not usedItems[key] then | 51 if not usedItems[key] then |
51 bestLink = v | 52 bestLink = v |
52 bestItem = listItem | 53 bestItem = listItem |
53 bestDiff = diff | 54 bestDiff = diff |
54 bestLoc = string.format("%s_%s", tableType, k) | 55 bestLoc = string.format("%s_%s", tableType, k) |
56 found = true | |
55 end | 57 end |
56 end | 58 end |
57 if diff == 0 then break end | 59 if found then break end |
58 end | 60 end |
59 end | 61 end |
60 | 62 |
61 return bestLink, bestItem, bestDiff, bestLoc | 63 return bestLink, bestItem, bestDiff, bestLoc |
62 end | 64 end |
504 local bestLink = nil | 506 local bestLink = nil |
505 local bestDiff = 1000 | 507 local bestDiff = 1000 |
506 | 508 |
507 -- find the best matching item | 509 -- find the best matching item |
508 | 510 |
511 -- inventory | |
512 bestItem, bestDiff, bestLink = scanBagForItem(item, BACKPACK_CONTAINER, bestItem, bestDiff, bestLink) | |
513 for bagId = 1, NUM_BAG_SLOTS do | |
514 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink) | |
515 end | |
516 | |
509 -- equipped items, but skip slots we have just equipped (to avoid e.g. just moving 2 of the same item back and forth between mh oh weapon slots) | 517 -- equipped items, but skip slots we have just equipped (to avoid e.g. just moving 2 of the same item back and forth between mh oh weapon slots) |
510 for slotNum = 1, #Amr.SlotIds do | 518 for slotNum = 1, #Amr.SlotIds do |
511 local slotId = Amr.SlotIds[slotNum] | 519 local slotId = Amr.SlotIds[slotNum] |
512 if not _pendingEquip.doneSlots[slotId] then | 520 if not _pendingEquip.doneSlots[slotId] then |
513 local itemLink = GetInventoryItemLink("player", slotId) | 521 local itemLink = GetInventoryItemLink("player", slotId) |
523 end | 531 end |
524 end | 532 end |
525 end | 533 end |
526 end | 534 end |
527 | 535 |
528 -- inventory | |
529 bestItem, bestDiff, bestLink = scanBagForItem(item, BACKPACK_CONTAINER, bestItem, bestDiff, bestLink) | |
530 for bagId = 1, NUM_BAG_SLOTS do | |
531 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink) | |
532 end | |
533 | |
534 -- bank | 536 -- bank |
535 bestItem, bestDiff, bestLink = scanBagForItem(item, BANK_CONTAINER, bestItem, bestDiff, bestLink) | 537 bestItem, bestDiff, bestLink = scanBagForItem(item, BANK_CONTAINER, bestItem, bestDiff, bestLink) |
536 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do | 538 for bagId = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do |
537 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink) | 539 bestItem, bestDiff, bestLink = scanBagForItem(item, bagId, bestItem, bestDiff, bestLink) |
538 end | 540 end |
686 _pendingEquip = { | 688 _pendingEquip = { |
687 tries = _pendingEquip and _pendingEquip.spec == spec and _pendingEquip.tries or 0, | 689 tries = _pendingEquip and _pendingEquip.spec == spec and _pendingEquip.tries or 0, |
688 spec = spec, | 690 spec = spec, |
689 itemsToEquip = itemsToEquip, | 691 itemsToEquip = itemsToEquip, |
690 remaining = remaining, | 692 remaining = remaining, |
691 doneSlots = {}, | 693 doneSlots = _pendingEquip and _pendingEquip.spec == spec and _pendingEquip.doneSlots or {}, |
692 nextSlot = firstSlot | 694 nextSlot = firstSlot |
693 } | 695 } |
694 | 696 |
695 -- starting item | 697 -- starting item |
696 for slotId, item in pairs(_pendingEquip.itemsToEquip) do | 698 for slotId, item in pairs(_pendingEquip.itemsToEquip) do |