Quantcast

Queue items if the cache doesn't have it yet

Adrian L Lange [02-05-12 - 14:43]
Queue items if the cache doesn't have it yet
Filename
Monomyth.lua
diff --git a/Monomyth.lua b/Monomyth.lua
index 8d01436..9e2beba 100644
--- a/Monomyth.lua
+++ b/Monomyth.lua
@@ -85,6 +85,13 @@ Monomyth:Register('QUEST_PROGRESS', function()
 	end
 end)

+local choiceQueue, choiceFinished
+Monomyth:Register('QUEST_ITEM_UPDATE', function(...)
+	if(choiceQueue) then
+		Monomyth.QUEST_COMPLETE()
+	end
+end)
+
 Monomyth:Register('QUEST_COMPLETE', function()
 	if(GetNumQuestChoices() <= 1) then
 		GetQuestReward(QuestFrameRewardPanel.itemChoice)
@@ -93,24 +100,30 @@ Monomyth:Register('QUEST_COMPLETE', function()

 		for index = 1, GetNumQuestChoices() do
 			local link = GetQuestItemLink('choice', index)
-			if(not link) then
-				-- Item is not located in the cache yet, let it request it
-				-- from the server and run this again after its received
-				return
-			end
-
-			local _, _, _, _, _, _, _, _, _, _, value = GetItemInfo(link)
-			if(value > bestValue) then
-				bestValue, bestIndex = value, index
+			if(link) then
+				local _, _, _, _, _, _, _, _, _, _, value = GetItemInfo(link)
+				if(value > bestValue) then
+					bestValue, bestIndex = value, index
+				end
+			else
+				choiceQueue = true
+				return GetQuestItemInfo('choice', index)
 			end
 		end

 		if(bestIndex) then
+			choiceFinished = true
 			_G['QuestInfoItem' .. bestIndex]:Click()
 		end
 	end
 end)

+Monomyth:Register('QUEST_FINISHED', function()
+	if(choiceFinished) then
+		choiceQueue = false
+	end
+end)
+
 Monomyth:Register('QUEST_AUTOCOMPLETE', function(id)
 	local index = GetQuestLogIndexByID(id)
 	if(GetQuestLogIsAutoComplete(index)) then