Quantcast

fixed auto equiping items received by greed. Equip logic changed that rewards with itemlevel lower thatn already worn by player are not getting swaped

Alex Shubert [09-11-12 - 19:57]
fixed auto equiping items received by greed. Equip logic changed that rewards with itemlevel lower thatn already worn by player are not getting swaped
Filename
AutoTurnIn.lua
rewards_const.lua
diff --git a/AutoTurnIn.lua b/AutoTurnIn.lua
index 2528fbe..05fba3f 100644
--- a/AutoTurnIn.lua
+++ b/AutoTurnIn.lua
@@ -277,8 +277,8 @@ AutoTurnIn.delayFrame:SetScript('OnUpdate', function()
 				local name = GetItemInfo(link)
 				if ( name and AutoTurnIn.autoEquipList[name] ) then
 					AutoTurnIn:Print(L["equipping reward"], link)
+					EquipItemByName(name, AutoTurnIn.autoEquipList[name])
 					AutoTurnIn.autoEquipList[name]=nil
-					EquipItemByName(name)
 				end
 			end
 		end
@@ -297,11 +297,31 @@ function AutoTurnIn:TurnInQuest(rewardIndex)
 		self:Print(L["gogreedy"])
 	end

-	local name = GetQuestItemInfo("choice", rewardIndex)
-	if (AutoTurnInCharacterDB.autoequip and name) then
-		self.autoEquipList[name] = true
-		self.delayFrame.delay = time() + 2
-		self.delayFrame:Show()
+	if (not self.forceGreed) then
+		local name = GetQuestItemInfo("choice", rewardIndex)
+		if (AutoTurnInCharacterDB.autoequip and (strlen(name) > 0)) then
+			local lootLevel, _, _, _, _, equipSlot = select(4, GetItemInfo(GetQuestItemLink("choice", rewardIndex)))
+
+			-- Compares reward and already equiped item levels. If reward level is greater than equiped item, auto equip reward
+			local slots = C.SLOTS[equipSlot]
+			local slotNumber = GetInventorySlotInfo(slots[1])
+			local invLink = GetInventoryItemLink("player", slotNumber)
+			local eqLevel = select(4, GetItemInfo(invLink))
+			-- If reward is a ring  trinket or one-handed weapons all slots must be checked in order to swap one with a lesser item-level
+			if (#slots > 1) then
+				invLink = GetInventoryItemLink("player", GetInventorySlotInfo(slots[2]))
+				if (invLink) then
+					local eq2Level = select(4, GetItemInfo(invLink))
+					eqLevel = (eqLevel > eq2Level) and eq2Level or eqLevel
+					slotNumber = (eqLevel > eq2Level) and GetInventorySlotInfo(slots[2]) or slotNumber
+				end
+			end
+			if(lootLevel > eqLevel) then
+				self.autoEquipList[name] = slotNumber
+				self.delayFrame.delay = time() + 2
+				self.delayFrame:Show()
+			end
+		end
 	end

 	if (AutoTurnInCharacterDB.debug) then
@@ -330,6 +350,7 @@ function AutoTurnIn:Greed()
 			index = i
 		end
 	end
+
 	if money > 0 then  -- some quests, like tournament ones, offer reputation rewards and they have no cost.
 		self:TurnInQuest(index)
 	end
diff --git a/rewards_const.lua b/rewards_const.lua
index 5a79530..9d80d62 100644
--- a/rewards_const.lua
+++ b/rewards_const.lua
@@ -5,7 +5,6 @@ local C = ptable.CONST
 local weapon = {GetAuctionItemSubClasses(1)}
 local armor = {GetAuctionItemSubClasses(2)}

--- C.STOPTOKENS = {['INVTYPE_RELIC']='', ['INVTYPE_TRINKET']='', ['INVTYPE_HOLDABL']=''}
 C.WEAPONLABEL, C.ARMORLABEL = GetAuctionItemClasses()
 C.JEWELRY = {['INVTYPE_FINGER']='', ['INVTYPE_NECK']=''}

@@ -42,6 +41,32 @@ C.ITEMS = {
 	]]--
 }

+C.SLOTS = {
+	["INVTYPE_AMMO"]={"AmmoSlot"},
+	["INVTYPE_HEAD"]={"HeadSlot"},
+	["INVTYPE_NECK"]={"NeckSlot"},
+	["INVTYPE_SHOULDER"]={"ShoulderSlot"},
+	["INVTYPE_CHEST"]={"ChestSlot"},
+	["INVTYPE_WAIST"]={"WaistSlot"},
+	["INVTYPE_LEGS"]={"LegsSlot"},
+	["INVTYPE_FEET"]={"FeetSlot"},
+	["INVTYPE_WRIST"]={"WristSlot"},
+	["INVTYPE_HAND"]={"HandsSlot"},
+	["INVTYPE_FINGER"]={"Finger0Slot", "Finger1Slot"},
+	["INVTYPE_TRINKET"]={"Trinket0Slot", "Trinket1Slot"},
+	["INVTYPE_CLOAK"]={"BackSlot"},
+
+	["INVTYPE_WEAPON"]={"MainHandSlot", "SecondaryHandSlot"},
+	["INVTYPE_2HWEAPON"]={"MainHandSlot"},
+	["INVTYPE_RANGED"]={"MainHandSlot"},
+	["INVTYPE_RANGEDRIGHT"]={"MainHandSlot"},
+	["INVTYPE_WEAPONMAINHAND"]={"MainHandSlot"},
+	["INVTYPE_SHIELD"]={"SecondaryHandSlot"},
+	["INVTYPE_WEAPONOFFHAND"]={"SecondaryHandSlot"},
+	["INVTYPE_HOLDABLE"]={"SecondaryHandSlot"}
+}
+
+
 --[[
 from GlobalStrings.lua
 ITEM_MOD_CRIT_RATING_SHORT = "Critical Strike";
@@ -55,5 +80,4 @@ ITEM_MOD_HIT_RATING_SHORT = "Hit";
 ITEM_MOD_MASTERY_RATING_SHORT = "Mastery";
 ITEM_MOD_SPELL_PENETRATION_SHORT = "Spell Penetration";
 ITEM_MOD_SPELL_POWER_SHORT = "Spell Power";
-
 ]]--
\ No newline at end of file