end |
end |
|
-- Let's handle the weapons, since they're somewhat complicated |
local mh_stash, oh_stash = {}, {} |
local mainslot, offslot = slotIds["MainHandSlot"], slotIds["SecondaryHandSlot"] |
|
-- Unequip both weapon slots |
local mh_link = GetInventoryItemLink("player", mainslot) |
local oh_link = GetInventoryItemLink("player", offslot) |
if mh_link then |
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 |
end |
|
if oh_link then |
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 |
end |
|
-- 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 weapon_max, weapon_win = 0, {} |
|
-- Try on each mainhand weapon |
for mh_mask,item in pairs(slotAvail[mainslot]) do |
local mh_equipped = DressToKill:EquipItem(mainslot, mh_mask, mh_stash) |
blacklist[mh_mask] = true |
|
if mh_equipped then |
-- 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) |
|
local mh_link = GetInventoryItemLink("player", mainslot) |
local mh_score = weightFunction(mh_link, mainslot) - weapon_base |
local score = mh_score |
|
-- 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 = mh_score + oh_score |
end |
|
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 |
|
-- Unequip this mainhand item |
DressToKill:UnequipItem(mainslot, mh_mask, mh_stash) |
blacklist[mh_mask] = false |
end |
end |
|
-- Equip the weapon winners (MAINHAND) |
DressToKill:EquipItem(mainslot, weapon_win.mh, mh_stash) |
local link = GetInventoryItemLink("player", mainslot) |
print("Choosing %s", link) |
blacklist[weapon_win.mh] = true |
-- Equip the offhand winner, if there was one |
if weapon_min.oh then |
DressToKill:EquipItem(offslot, weapon_win.oh, oh_stash) |
local link = GetInventoryItemLink("player", offslot) |
print("Choosing %s", link) |
blacklist[weapon_win.oh] = true |
end |
|
local stash = {} |
-- Loop through all of the inventory slots |
for slotId,avail in pairs(slotAvail) do |