end |
|
local function scanFunction(weightFunction) |
debug(L["Beginning an inventory scan"]) |
debug(L["********** Beginning an inventory scan **********"]) |
UIErrorsFrame:AddMessage("Please do not change buffs or forms during scan...", 1, 0.2, 0.2) |
|
local blacklist = {} |
local slotAvail = {} |
for slotName,slotId in pairs(slotIds) do |
debug(L["Collecting available items for %s"], slotName) |
local avail = GetInventoryItemsForSlot(slotId) |
if next(avail) then |
local c = 0 |
for k,v in pairs(avail) do c = c + 1 end |
debug(L["Found %d available items"], c) |
slotAvail[slotId] = avail |
else |
debug(L["Found no available items"]) |
end |
end |
|
-- Let's handle the weapons, since they're somewhat complicated |
local mh_stash, oh_stash = {}, {} |
local mainslot, offslot = slotIds["MainHandSlot"], slotIds["SecondaryHandSlot"] |
local mainslot = GetInventorySlotInfo("MainHandSlot") |
local offslot = GetInventorySlotInfo("SecondaryHandSlot") |
|
-- Unequip both weapon slots |
local mh_link = GetInventoryItemLink("player", mainslot) |
local oh_link = GetInventoryItemLink("player", offslot) |
|
debug(L["Mainhand link: %s"], tostring(mh_link)) |
debug(L["Offhand link: %s"], tostring(oh_link)) |
|
if mh_link then |
debug(L["Found a mainhand weapon: %s"], mh_link) |
local mh_bag, mh_slot = DressToKill:FindEmptySlot() |
if not mh_bag then |
print(L["Out of inventory space, cannot proceed"]) |
return |
end |
mh_stash.bag = mh_bag |
mh_stash.slot = mh_slot |
debug(L["Unequipping the mainhand weapon"]) |
PickupInventoryItem(mainslot) |
PickupContainerItem(mh_bag, mh_slot) |
coroutine.yield() |
end |
|
if oh_link then |
debug(L["Found an offhand weapon: %s"], oh_link) |
local oh_bag, oh_slot = DressToKill:FindEmptySlot() |
if not oh_bag then |
print(L["Out of inventory space, cannot proceed"]) |
return |
end |
oh_stash.bag = oh_bag |
oh_stash.slot = oh_slot |
debug(L["Unequipping the offhand weapon"]) |
PickupInventoryItem(offslot) |
PickupContainerItem(oh_bag, oh_slot) |
coroutine.yield() |
end |
|
local mh_avail = GetInventoryItemsForSlot(mainslot) |
local oh_avail = GetInventoryItemsForSlot(offslot) |
|
-- Calculate weapon base score with nothing equipped |
local linen_shirt = "\124cffffffff\124Hitem:2576:0:0:0:0:0:0:0\124h[White Linen Shirt]\124h\124r" |
local weapon_base = weightFunction(linen_shirt, mainslot) + weightFunction(linen_shirt, offslot) |
local mh_base = weightFunction(linen_shirt, mainslot) or 0 |
local oh_base = mh_base |
local weapon_max, weapon_win = 0, {} |
|
debug(L["Weapon base score: %s"], mh_base) |
|
-- Try on each mainhand weapon |
for mh_mask,item in pairs(slotAvail[mainslot]) do |
local mh_equipped = DressToKill:EquipItem(mainslot, mh_mask, mh_stash) |
for mh_mask,item in pairs(mh_avail) do |
local name, link = GetItemInfo(item) |
debug(L["Equipping mainhand weapon: %s"], link) |
|
local mh_equipped = DressToKill:EquipItem(mainslot, mh_mask) |
blacklist[mh_mask] = true |
|
if mh_equipped then |
debug(L["Successfully equipped %s"], link) |
local mh_link = GetInventoryItemLink("player", mainslot) |
local mh_score = weightFunction(mh_link, mainslot) - weapon_base |
local mh_score = weightFunction(mh_link, mainslot) - mh_base |
local score = mh_score |
debug(L["Mainhand score: %d"], score) |
|
if not IsEquippedItemType("Two-Hand") then |
debug(L["This is a one hand weapon, try offhand weapons"]) |
-- Try to equip each off-hand weapon to compliment this one |
for oh_mask,item in pairs(slotAvail[offslot]) do |
local oh_equipped = DressToKill:EquipItem(offslot, oh_mask, oh_stash) |
for oh_mask,item in pairs(oh_avail) do |
if not blacklist[oh_mask] then |
local name, link = GetItemInfo(item) |
|
-- If we equipped offhand, then score it too |
if oh_equipped then |
local oh_link = GetInventoryItemLink("player", offslot) or linen_shirt |
local oh_score = weightFunction(oh_link, offslot) - weapon_base |
score = score + oh_score |
end |
debug(L["Equipping offhand weapon: %s"], link) |
local oh_equipped = DressToKill:EquipItem(offslot, oh_mask) |
|
debug("Got score of %s for %s and %s", score, mh_link, oh_link or "empty") |
if score >= weapon_max then |
weapon_max = score |
weapon_win.mh = mh_mask |
weapon_win.oh = oh_equipped and oh_mask or nil |
end |
-- If we equipped offhand, then score it too |
if oh_equipped then |
local oh_link = GetInventoryItemLink("player", offslot) or linen_shirt |
local oh_score = weightFunction(oh_link, offslot) - score |
score = score + oh_score |
end |
|
-- Unequip the offhand item |
if oh_equipped then |
DressToKill:UnequipItem(offslot, oh_mask, oh_stash) |
debug("Got score of %s for %s and %s", score, mh_link, oh_link or "empty") |
if score >= weapon_max then |
weapon_max = score |
weapon_win.mh = mh_mask |
weapon_win.oh = oh_equipped and oh_mask or nil |
end |
|
-- Unequip the offhand item |
if oh_equipped then |
DressToKill:UnequipItem(offslot, oh_mask, oh_stash) |
end |
end |
end |
else |