Quantcast

Drycode of mainhand and offhand weapon support

James Whitehead II [08-16-08 - 10:52]
Drycode of mainhand and offhand weapon support
Filename
DressToKill.lua
diff --git a/DressToKill.lua b/DressToKill.lua
index e4463ac..9ef5785 100644
--- a/DressToKill.lua
+++ b/DressToKill.lua
@@ -40,15 +40,15 @@ local slotNames = {
 	HeadSlot = L["Head"],
 	HandsSlot = L["Hands"],
 	LegsSlot = L["Legs"],
-	MainHandSlot = L["Main Hand"],
 	NeckSlot = L["Neck Slot"],
 	RangedSlot = L["Ranged Slot"],
-	--SecondaryHandSlot = L["Secondary Hand"],
 	ShoulderSlot = L["Shoulders"],
 	Trinket0Slot = L["Trinket 0"],
 	Trinket1Slot = L["Trinket 1"],
 	WaistSlot = L["Waist"],
 	WristSlot = L["Wrist"],
+	--MainHandSlot = L["Main Hand"],
+	--SecondaryHandSlot = L["Secondary Hand"],
 }

 local slotIds = {}
@@ -108,6 +108,91 @@ local function scanFunction(weightFunction)
 		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
@@ -128,13 +213,17 @@ local function scanFunction(weightFunction)
 			coroutine.yield()
 		end

+		-- Get the base score for this slot, so we can normalize our scores
+		local linen_shirt = "\124cffffffff\124Hitem:2576:0:0:0:0:0:0:0\124h[White Linen Shirt]\124h\124r"
+		local base = weightFunction(linen_shirt, slotId) or 0
+
 		-- Loop through all of the available items, and try equipping each of them
 		for mask,item in pairs(avail) do
 			if not blacklist[mask] then
 				local equipped = DressToKill:EquipItem(slotId, mask, stash)
 				if equipped then
 					local link = GetInventoryItemLink("player", slotId)
-					local score = weightFunction(link, slotId)
+					local score = weightFunction(link, slotId) - base
 					debug("Got score of %s for %s", score, link)
 					if score >= maxScore then
 						maxScore = score