view data.lua @ 107:d64a19e5a47d

Bypass the filtering. Not fully tested, but mostly works.
author contrebasse
date Thu, 02 Jun 2011 00:57:17 +0200
parents b980c00affcd
children 618163a6d970
line wrap: on
line source
local addonName, A = ...

-- @todo: enchants, elementals, prospecting
-- @todo improve scanning

A.data = A.CommonData

do
	-- lua functions
	local print = print
	local ipairs = ipairs
	local tinsert = tinsert
	local select = select

	-- Wow functions
	local GetNumTradeSkills = GetNumTradeSkills
	local GetTradeSkillInfo = GetTradeSkillInfo
	local GetTradeSkillNumReagents = GetTradeSkillNumReagents
	local GetTradeSkillItemLink = GetTradeSkillItemLink
	local GetTradeSkillRecipeLink = GetTradeSkillRecipeLink
	local GetTradeSkillReagentItemLink = GetTradeSkillReagentItemLink
	local GetTradeSkillReagentInfo = GetTradeSkillReagentInfo
	local GetTradeSkillNumMade = GetTradeSkillNumMade
	local GetSpellInfo = GetSpellInfo

	-- Wow objects
	local GetTradeSkillLine = GetTradeSkillLine

	-- the function who scans the tradeskill
	function A:ScanSimpleRecipes()
		-- Do not scan while we modify the tradeskill display
		if A.blockScan then return end


		-- Check if the tradeskill is loaded
		-- Has to have recipes and begin with a header
		local NRecipes = GetNumTradeSkills()
		if NRecipes==0 or select(2,GetTradeSkillInfo(1))~="header" then
			return
		end
		
		tradeskillName = GetTradeSkillLine()

		-- Check if the pseudo tradeskills have to be added
		if tradeskillName == GetSpellInfo(25229) then -- Jewelcrafting
			if not A.ProspectingDataLoaded then
				for itemID,data in pairs(A.ProspectingData) do
					A.data[itemID] = data
				end
				A.ProspectingDataLoaded = true
			end
		elseif tradeskillName == GetSpellInfo(45357) then -- Inscription
			if not A.MillingDataLoaded then
				for itemID,data in pairs(A.MillingData) do
					A.data[itemID] = data
				end
				A.MillingDataLoaded = true
			end
		end

		local lastHeader
		for i = 1,NRecipes do
			-- skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(index)
			-- serviceType is nil if the recipe creates an item
			local skillName, skillType, _, _, serviceType = GetTradeSkillInfo(i)
			if skillType and skillType == "header" then
				lastHeader = skillName

			elseif skillType and skillType ~= "header" and serviceType==nil then
				-- item ID
				local itemID = A.link2ID(GetTradeSkillItemLink(i))

				local numReagents = GetTradeSkillNumReagents(i)
				local reagentID, reagentCount
				if numReagents==1 then
					-- reagent ID
					reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1))


					-- reagent number needed
					reagentCount = select(3,GetTradeSkillReagentInfo(i, 1))
				end

				-- number of reagent created by the recipe
				local minMade, maxMade = GetTradeSkillNumMade(i)

				-- recipe link (for tooltips)
				local recipeLink = GetTradeSkillRecipeLink(i)

				-- error checking
				if itemID and (numReagents ~= 1 or (reagentID and reagentCount)) and minMade and maxMade and recipeLink then
					-- remove unneeded minMade/maxMade
					if maxMade==minMade then
						maxMade = nil
						if minMade==1 then
							minMade = nil
						end -- if
					end -- if

					-- As we scan multiple times, check if this recipe is already stored
					local addSpell	= true
					if not A.data[itemID] then
						A.data[itemID] = {}
					else
						for _,v in ipairs(A.data[itemID]) do
							if v.spellLink==recipeLink then
								addSpell = nil
								break
							end -- if
						end -- for
					end -- if
				
					-- Cache the data
					if addSpell then
						local spell = {reagentID,reagentCount,minMade,maxMade}
						spell.spellName = tradeskillName
						spell.spellLink = recipeLink
						spell.header = lastHeader
						tinsert(A.data[itemID],spell)
					end

				--else -- Zap incomplete recipes, they will be scanned later
					--@debug@
					--print("Erreur de scan :",itemID,reagentID,reagentCount,minMade,maxMade,recipeLink)
					--@end-debug@
				end -- if
			end -- if
		end -- for
		-- the scanning is complete
		return true
	end -- function
end -- do