Quantcast

damn AV quests. They are marked as 'Available'!!!

Alex Shubert [02-14-12 - 16:58]
damn AV quests. They are marked as 'Available'!!!
Filename
AutoTurnIn.lua
options.lua
diff --git a/AutoTurnIn.lua b/AutoTurnIn.lua
index 4e36be5..6f8951d 100644
--- a/AutoTurnIn.lua
+++ b/AutoTurnIn.lua
@@ -82,24 +82,22 @@ function AutoTurnIn:ConsoleComand(arg)
 	end
 end

+local function GetItemAmount(isCurrency, item)
+	local amount = isCurrency and select(2, GetCurrencyInfo(item)) or GetItemCount(item, nil, true)
+	return amount and amount or 0
+end

 -- (gaq[i+3]) equals "1" if quest is complete, "nil" otherwise
 function AutoTurnIn:GOSSIP_SHOW()
+
 	if (GetGossipActiveQuests()) then
-		local gaq = {GetGossipActiveQuests()}
-
+		local gaq = {GetGossipActiveQuests()}
 		for i=1, #gaq, 4 do
-			if (gaq[i+3]) then
+			if (gaq[i+3]) then  -- complete status
 				local quest = L.quests[gaq[i]]
 				if AutoTurnInCharacterDB.all or quest  then
 					if quest and quest.amount then
-						local has = 0
-						if quest.currency then
-							_, has = GetCurrencyInfo(quest.item)
-						else
-							has = GetItemCount(quest.item, nil, true)
-						end
-						if has > quest.amount then
+						if GetItemAmount(quest.currency, quest.item) > quest.amount then
 							SelectGossipActiveQuest(math.floor(i/4)+1)
 							return
 						end
@@ -116,9 +114,16 @@ function AutoTurnIn:GOSSIP_SHOW()
 		gaq={GetGossipAvailableQuests()}
 		for i=1, #gaq, 5 do
 			local quest = L.quests[gaq[i]]
-			if AutoTurnInCharacterDB.all or (quest and (not quest.donotaccept)) then
-				SelectGossipAvailableQuest(math.floor(i/5)+1)
-				return
+			if AutoTurnInCharacterDB.all or (quest and (not quest.donotaccept)) then
+				if quest and quest.amount then
+					if GetItemAmount(quest.currency, quest.item) > quest.amount then
+						SelectGossipAvailableQuest(math.floor(i/5)+1)
+						return
+					end
+				else
+					SelectGossipAvailableQuest(math.floor(i/5)+1)
+					return
+				end
 			end
 		end
 	end
diff --git a/options.lua b/options.lua
index d886690..746487e 100644
--- a/options.lua
+++ b/options.lua
@@ -20,7 +20,7 @@ subText:SetText(notes)
 -- 'Enable' CheckBox
 local Enable = CreateFrame("CheckButton", O.."Enable", OptionsPanel, "OptionsCheckButtonTemplate")
 _G[O.."EnableText"]:SetText(L["enabled"])
-Enable:SetScript("OnClick", function(self) AutoTurnInCharacterDB.enabled = self:GetChecked() end)
+Enable:SetScript("OnClick", function(self) AutoTurnInCharacterDB.enabled = self:GetChecked() == 1 end)

 -- Quest types to handle
 local QuestLabel = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")