Quantcast

RC2

Alex Shubert [04-05-12 - 08:37]
RC2
Filename
AutoTurnIn.lua
RewardOptions.lua
readme.txt
rewards.lua
diff --git a/AutoTurnIn.lua b/AutoTurnIn.lua
index cb30025..0924c20 100644
--- a/AutoTurnIn.lua
+++ b/AutoTurnIn.lua
@@ -5,7 +5,10 @@ local C = ptable.CONST
 AutoTurnIn = LibStub("AceAddon-3.0"):NewAddon("AutoTurnIn", "AceEvent-3.0", "AceConsole-3.0")
 AutoTurnIn.defaults = {enabled = true, all = false, dontloot = 1, tournament = 2, darkmoonteleport=true, togglekey=1}
 AutoTurnIn.ldb, AutoTurnIn.allowed = nil, nil
-local ldbstruct = {
+AutoTurnIn.caption = addonName ..' [%s]'
+AutoTurnIn.funcList = {[1] = function() return false end, [2]=IsAltKeyDown, [3]=IsControlKeyDown, [4]=IsShiftKeyDown}
+
+AutoTurnIn.ldbstruct = {
 		type = "data source",
 		icon = "Interface\\QUESTFRAME\\UI-QuestLog-BookIcon",
 		label = addonName,
@@ -23,12 +26,11 @@ local ldbstruct = {
 		end,
 	}

-local caption = addonName ..' [%s]'
 function AutoTurnIn:SetEnabled(enabled)
 	AutoTurnInCharacterDB.enabled = not not enabled
-	if AutoTurnIn.ldb then
-		AutoTurnIn.ldb.text = caption:format((AutoTurnInCharacterDB.enabled) and 'on' or 'off' )
-		AutoTurnIn.ldb.label = AutoTurnIn.ldb.text
+	if self.ldb then
+		self.ldb.text = self.caption:format((AutoTurnInCharacterDB.enabled) and 'on' or 'off' )
+		self.ldb.label = self.ldb.text
 	end
 end
 -- quest autocomplete handlers and functions
@@ -42,7 +44,7 @@ function AutoTurnIn:OnEnable()
 	end

 	if not AutoTurnInCharacterDB then
-		_G.AutoTurnInCharacterDB = CopyTable(AutoTurnIn.defaults)
+		_G.AutoTurnInCharacterDB = CopyTable(self.defaults)
 	end
 	if (tonumber(AutoTurnInCharacterDB.dontloot) == nil) then
 		AutoTurnInCharacterDB.dontloot = 1
@@ -57,7 +59,7 @@ function AutoTurnIn:OnEnable()

 	local LDB = LibStub:GetLibrary("LibDataBroker-1.1", true)
 	if LDB then
-		AutoTurnIn.ldb = LDB:NewDataObject("AutoTurnIn", ldbstruct)
+		self.ldb = LDB:NewDataObject("AutoTurnIn", self.ldbstruct)
 	end

 	self:SetEnabled(AutoTurnInCharacterDB.enabled)
@@ -104,25 +106,25 @@ function AutoTurnIn:ConsoleComand(arg)
 	end
 end

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

-local funcList = {[1] = function() return false end, [2]=IsAltKeyDown, [3]=IsControlKeyDown, [4]=IsShiftKeyDown}
-local function AllowedToHandle(forcecheck)
-	if ( AutoTurnIn.allowed == nil or forcecheck ) then
+
+function AutoTurnIn:AllowedToHandle(forcecheck)
+	if ( self.allowed == nil or forcecheck ) then
 		-- Double 'not' converts possible 'nil' to boolean representation
-		local IsModifiedClick = not not funcList[AutoTurnInCharacterDB.togglekey]()
+		local IsModifiedClick = not not self.funcList[AutoTurnInCharacterDB.togglekey]()
 		-- it's a simple xor implementation (a ~= b)
-		AutoTurnIn.allowed = (not not AutoTurnInCharacterDB.enabled) ~= (IsModifiedClick)
+		self.allowed = (not not AutoTurnInCharacterDB.enabled) ~= (IsModifiedClick)
 	end
-	return AutoTurnIn.allowed
+	return self.allowed
 end

 -- OldGossip interaction system. Burn in hell See http://wowprogramming.com/docs/events/QUEST_GREETING
 function AutoTurnIn:QUEST_GREETING()
-	if (not AllowedToHandle(true)) then
+	if (not self:AllowedToHandle(true)) then
 		return
 	end

@@ -137,7 +139,7 @@ function AutoTurnIn:QUEST_GREETING()
 		local quest = L.quests[GetAvailableTitle(index)]
 		if (AutoTurnInCharacterDB.all or quest)then
 			if quest and quest.amount then
-				if GetItemAmount(quest.currency, quest.item) >= quest.amount then
+				if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
 					SelectAvailableQuest(index)
 					return
 				end
@@ -150,60 +152,61 @@ end

 -- (gaq[i+3]) equals "1" if quest is complete, "nil" otherwise
 -- why not 	gaq={GetGossipAvailableQuests()}? Well, tables in lua are truncated for values with ending `nil`. So: '#' for {1,nil, "b", nil} returns 1
-function AutoTurnIn:GOSSIP_SHOW()
-	if (not AllowedToHandle(true)) then
-		return
-	end
-
-	if (AutoTurnInCharacterDB.darkmoonteleport and (L["DarkmoonFaireTeleport"]==UnitName("target"))) then
-		SelectGossipOption(1)
-		StaticPopup1Button1:Click()
-	end
-
-	local function VarArgForActiveQuests(...)
-		for i=1, select("#", ...), 4 do
-			local completeStatus = select(i+3, ...)
-			if (completeStatus) then  -- complete status
-				local questname = select(i, ...)
-				local quest = L.quests[questname]
-				if AutoTurnInCharacterDB.all or quest  then
-					if quest and quest.amount then
-						if GetItemAmount(quest.currency, quest.item) >= quest.amount then
-							SelectGossipActiveQuest(math.floor(i/4)+1)
-							return
-						end
-					else
+function AutoTurnIn:VarArgForActiveQuests(...)
+	for i=1, select("#", ...), 4 do
+		local completeStatus = select(i+3, ...)
+		if (completeStatus) then  -- complete status
+			local questname = select(i, ...)
+			local quest = L.quests[questname]
+			if AutoTurnInCharacterDB.all or quest  then
+				if quest and quest.amount then
+					if self:GetItemAmount(quest.currency, quest.item) >= quest.amount then
 						SelectGossipActiveQuest(math.floor(i/4)+1)
 						return
 					end
+				else
+					SelectGossipActiveQuest(math.floor(i/4)+1)
+					return
 				end
 			end
 		end
 	end
+end

-	local function VarArgForAvailableQuests(...)
-		for i=1, select("#", ...), 5 do
-			local questname = select(i, ...)
-			local quest = L.quests[questname]
-			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
+function AutoTurnIn:VarArgForAvailableQuests(...)
+	for i=1, select("#", ...), 5 do
+		local questname = select(i, ...)
+		local quest = L.quests[questname]
+		if AutoTurnInCharacterDB.all or (quest and (not quest.donotaccept)) then
+			if quest and quest.amount then
+				if self: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
-	VarArgForActiveQuests(GetGossipActiveQuests())
-	VarArgForAvailableQuests(GetGossipAvailableQuests())
+end
+
+function AutoTurnIn:GOSSIP_SHOW()
+	if (not self:AllowedToHandle(true)) then
+		return
+	end
+
+	if (AutoTurnInCharacterDB.darkmoonteleport and (L["DarkmoonFaireTeleport"]==UnitName("target"))) then
+		SelectGossipOption(1)
+		StaticPopup1Button1:Click()
+	end
+
+	self:VarArgForActiveQuests(GetGossipActiveQuests())
+	self:VarArgForAvailableQuests(GetGossipAvailableQuests())
 end

 function AutoTurnIn:QUEST_DETAIL()
-	if AllowedToHandle() and (AutoTurnInCharacterDB.all or L.quests[GetTitleText()]) then
+	if self:AllowedToHandle() and (AutoTurnInCharacterDB.all or L.quests[GetTitleText()]) then
 		QuestInfoDescriptionText:SetAlphaGradient(0, math.huge)
 		QuestInfoDescriptionText:SetAlpha(1)
 		AcceptQuest()
@@ -211,20 +214,25 @@ function AutoTurnIn:QUEST_DETAIL()
 end

 function AutoTurnIn:QUEST_PROGRESS()
-    if  AllowedToHandle() and (AutoTurnInCharacterDB.all or L.quests[GetTitleText()]) and IsQuestCompletable() then
+    if  self:AllowedToHandle() and (AutoTurnInCharacterDB.all or L.quests[GetTitleText()]) and IsQuestCompletable() then
 		CompleteQuest()
     end
 end

-local function IsRangedAndRequired(subclass)
-	return (AutoTurnInCharacterDB.items['Ranged'] and
+function AutoTurnIn:IsRangedAndRequired(subclass)
+	return (AutoTurnInCharacterDB.weapon['Ranged'] and
 		(C.ITEMS['Crossbows'] == subclass or C.ITEMS['Guns'] == subclass or C.ITEMS['Bows'] == subclass))
 end

-local function IsJewelryAndRequired(equipSlot)
-	return AutoTurnInCharacterDB.items['Jewelry'] and (C.JEWELRY[equipSlot])
+function AutoTurnIn:IsOffhandAndRequired(equipSlot)
+	return (AutoTurnInCharacterDB.armor[INVTYPE_HOLDABLE] and INVTYPE_HOLDABLE == equipSlot)
 end

+function AutoTurnIn:IsJewelryAndRequired(equipSlot)
+	return AutoTurnInCharacterDB.armor['Jewelry'] and (C.JEWELRY[equipSlot])
+end
+
+
 --[[ doesn't work. Frame appear faster than items loaded. Need rework. It is called nowhere right now
 local function TryToLoadRewards()
 	local title = GetTitleText()
@@ -243,59 +251,68 @@ local function TryToLoadRewards()
 	end
 end]]--

+function AutoTurnIn:TurnInQuest(rewardIndex)
+	if (AutoTurnInCharacterDB.showrewardtext) then
+		self:Print((UnitName("target") and  UnitName("target") or '')..'\n', GetRewardText())
+	end
+	GetQuestReward(rewardIndex)
+end
+
 function AutoTurnIn:Greed()
 	local index, money = 0, 0;

-	if (AutoTurnInCharacterDB.dontloot == 2) then
-		for i=1, GetNumQuestChoices() do
-			local link = GetQuestItemLink("choice", i)
-			if ( link == nil ) then
-				return
-			end
-			local m = select(11, GetItemInfo(link))
-			if m > money then
-				money = m
-				index = i
-			end
+	for i=1, GetNumQuestChoices() do
+		local link = GetQuestItemLink("choice", i)
+		if ( link == nil ) then
+			return
 		end
-		if money > 0 then  -- some quests, like tournament ones, offer reputation rewards and they have no cost.
-			GetQuestReward(index)
+		local m = select(11, GetItemInfo(link))
+		if m > money then
+			money = m
+			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
 end

-local found, stattable = {}, {}
+AutoTurnIn.found, AutoTurnIn.stattable = {}, {}
+AutoTurnIn.MSG_STOPITEM = INVTYPE_RELIC .. ' | ' .. INVTYPE_TRINKET.. ': '.. ERR_QUEST_MUST_CHOOSE..' '..TRACKER_SORT_MANUAL
+AutoTurnIn.MSG_ITEMLINKISNULL= BUTTON_LAG_LOOT_TOOLTIP.. '. '..ERR_QUEST_MUST_CHOOSE
 function AutoTurnIn:Need()
-	wipe(found)
-
+	wipe(self.found)
 	for i=1, GetNumQuestChoices() do
 		local link = GetQuestItemLink("choice", i)

 		if ( link == nil ) then
+			self:Print(MSG_ITEMLINKISNULL)
 			return true
 		end

 		local class, subclass, _, equipSlot = select(6, GetItemInfo(link))
 		--[[relics and trinkets are out of autoloot]]--
 		if  (UnitHasRelicSlot("player") and 'INVTYPE_RELIC' == equipSlot) or 'INVTYPE_TRINKET' == equipSlot then
-			self:Print(INVTYPE_RELIC .. ' or ' .. INVTYPE_TRINKET.. ' found. Choose reward manually pls.')
+			self:Print(MSG_STOPITEM)
 			return true
 		end
-
+
 		-- item is suitable is there are no type cpecified at all or item type is required
 		local OkByType = false
 		if class == C.WEAPONLABEL then
-			OkByType = (not next(AutoTurnInCharacterDB.weapon)) or (AutoTurnInCharacterDB.weapon[subclass] or IsRangedAndRequired(subclass))
+			OkByType = (not next(AutoTurnInCharacterDB.weapon)) or (AutoTurnInCharacterDB.weapon[subclass] or
+						self:IsRangedAndRequired(subclass))
 		else
-			OkByType = (not next(AutoTurnInCharacterDB.armor)) or (AutoTurnInCharacterDB.armor[subclass] or IsJewelryAndRequired(equipSlot))
+			OkByType = (not next(AutoTurnInCharacterDB.armor)) or (AutoTurnInCharacterDB.armor[subclass] or
+						self:IsJewelryAndRequired(equipSlot) or self:IsOffhandAndRequired(equipSlot))
 		end
-
+
 		--Same here: if no stat specified or item stat is chosen then item is wanted
-		local OkByStat = not not next(AutoTurnInCharacterDB.stat) -- true if table is not empty
-		if OkByStat then
-			wipe(stattable)
-			GetItemStats(link, stattable)
-			for stat, value in pairs(stattable) do
+		local OkByStat = (not next(AutoTurnInCharacterDB.stat)) -- true if table is empty
+		if not OkByStat then
+			wipe(self.stattable)
+			GetItemStats(link, self.stattable)
+			for stat, value in pairs(self.stattable) do
 				if ( AutoTurnInCharacterDB.stat[C.STATS[stat]] ) then
 					OkByStat = true
 				end
@@ -303,53 +320,50 @@ function AutoTurnIn:Need()
 		end

 		if (OkByType and OkByStat) then
-			tinsert(found, i)
+			tinsert(self.found, i)
 		end
 	end

 	-- HANDLE RESULT
-	if #found > 1 then
+	if #self.found > 1 then
 		local vars = ""
-		for _, reward in pairs(found) do
+		for _, reward in pairs(self.found) do
 			vars = vars..' '..GetQuestItemLink("choice", reward)
 		end
-		self:Print("Found few items. Choose manually pls" ..vars)
-	elseif(#found == 1) then
-		GetQuestReward(found[1])
+		self:Print('Found more thatn one candidate. '..ERR_QUEST_MUST_CHOOSE..' '..TRACKER_SORT_MANUAL)
+	elseif(#self.found == 1) then
+		self:TurnInQuest(self.found[1])
 	end

-	return ( #found ~= 0 )
+	return ( #self.found ~= 0 )
 end

 function AutoTurnIn:QUEST_COMPLETE()
 	-- blasted Lands citadel wonderful NPC. They do not trigger any events except quest_complete.
-	if not AllowedToHandle() then
+	if not self:AllowedToHandle() then
 		return
 	end

-	if (AutoTurnInCharacterDB.showrewardtext) then
-		self:Print((UnitName("target") and  UnitName("target") or '')..'\n', GetRewardText())
-	end
-
 	local quest = L.quests[GetTitleText()]
     if AutoTurnInCharacterDB.all or quest then
 		if GetNumQuestChoices() > 0 then
 			if AutoTurnInCharacterDB.dontloot > 1 then -- Auto Loot enabled!
 				-- Tournament quest found
 				if (quest == "tournament") then
-					GetQuestReward(AutoTurnInCharacterDB.tournament)
+					self:TurnInQuest(AutoTurnInCharacterDB.tournament)
 					return
 				end
+
 				local forceGreed = false
 				if (AutoTurnInCharacterDB.dontloot == 3) then
 					forceGreed = (not self:Need() ) and AutoTurnInCharacterDB.greedifnothingfound
-				end
+				end
 				if (AutoTurnInCharacterDB.dontloot == 2 or forceGreed) then
 					self:Greed()
 				end
 			end
 		else
-			GetQuestReward(index)
+			self:TurnInQuest(index)
 		end
     end
 end
diff --git a/RewardOptions.lua b/RewardOptions.lua
index 28db8df..0aed525 100644
--- a/RewardOptions.lua
+++ b/RewardOptions.lua
@@ -76,7 +76,8 @@ CreateCheckbox(armor[4], ArmorPanel, 292, -8)
 CreateCheckbox(armor[5], ArmorPanel, 436, -8)
 	-- 2nd line
 CreateCheckbox(armor[6], ArmorPanel, 10, -40)
-CreateCheckbox("Jewelry", ArmorPanel, 292, -40, L['Jewelry'] )
+CreateCheckbox("Jewelry", ArmorPanel, 190, -40, L['Jewelry'] )
+CreateCheckbox(INVTYPE_HOLDABLE, ArmorPanel, 380, -40)

 -- ATTRIBUTES
 local StatPanel = CreatePanel("StatPanel", STAT_CATEGORY_ATTRIBUTES, 590, 40)
diff --git a/readme.txt b/readme.txt
index 45aebf7..44a8cae 100644
--- a/readme.txt
+++ b/readme.txt
@@ -7,7 +7,6 @@ May turn in quests with rewards and choose most expensive one for future selling
 /au 		- for GUI
 /au all 	- any quest would by accepted and turned in
 /au list 	- only specified quest
-/au loot 	- toggles quest completition: do not complete quests with a list of rewards at all or choose most expensive one of rewards
 /au off 	- turns addon off
 /au on 		- turns addon on
 /au help 	- brief help and active settings
diff --git a/rewards.lua b/rewards.lua
index d67a43f..242c2e8 100644
--- a/rewards.lua
+++ b/rewards.lua
@@ -5,7 +5,7 @@ local C = ptable.CONST
 local weapon = {GetAuctionItemSubClasses(1)}
 local armor = {GetAuctionItemSubClasses(2)}

--- C.STOPTOKENS = {['INVTYPE_RELIC']='', ['INVTYPE_TRINKET']=''}
+-- C.STOPTOKENS = {['INVTYPE_RELIC']='', ['INVTYPE_TRINKET']='', ['INVTYPE_HOLDABL']=''}
 C.WEAPONLABEL, C.ARMORLABEL = GetAuctionItemClasses()
 C.JEWELRY = {['INVTYPE_FINGER']='', ['INVTYPE_NECK']=''}
 C.STATS = {
@@ -46,43 +46,4 @@ C.ITEMS = {
 	['Idols'] = armor[8],
 	['Totems'] = armor[9],
 	]]--
-}
-
-
-
---[[
-(\[('.+')\]\s+=\s+((weapon|armor)\[\d+\]),)
-
-:    . ,  -   .  - .
-  :      
-
-if not _G.AutoTurnInCharacterDB.items then
-	AutoTurnInCharacterDB.items = {}
-	for k, v in pairs(ptable.C.ITEMS) do
-		AutoTurnInCharacterDB.items[k]=0
-	end
-end
-/run table.foreach(OPEN_FILTER_LIST, function(value) for v,k in pairs(value) do print(v,k) end)
-
-/run for k,v in pairs(OPEN_FILTER_LIST) do for n,m in pairs(v) do print(n,m) end end
-/run for k,v in pairs(InterfaceOptionsFrameAddOnsButton2.element) do print(k,v) end
-
-/run print(_G[INVTYPE_CLOAK])
-/run print(select(6, GetItemInfo(" ")))
-
-/run function a(...) for i=1, select("#", ...), 2 do invType = _G[select(i, ...)] print(invType, select(i, ...)) end end a(GetAuctionInvTypes(2,2))
-00:08:47  INVTYPE_CLOAK 1 INVTYPE_HOLDABLE nil
-
-SPELL_STAT1_NAME = "Strength";
-SPELL_STAT2_NAME = "Agility";
-SPELL_STAT3_NAME = "Stamina";
-SPELL_STAT4_NAME = "Intellect";
-SPELL_STAT5_NAME = "Spirit";
-
-STAT_CATEGORY_ATTRIBUTES = "Attributes";
-STAT_CATEGORY_DEFENSE = "Defense";
-STAT_CATEGORY_GENERAL = "General";
-STAT_CATEGORY_MELEE = "Melee";
-STAT_CATEGORY_RANGED = "Ranged";
-
-]]--
\ No newline at end of file
+}
\ No newline at end of file