view data.lua @ 67:cd7e41015586

Separate Mill and Prospect, and load them only if needed
author contrebasse
date Sat, 14 May 2011 16:27:34 +0200
parents 2ca04183f5f9
children 42aac950bd67
line wrap: on
line source
local addonName, A = ...

-- @todo: complete jewelcrafting items
-- @todo: enchants, elementals, prospecting

-- @todo improve scanning
-- @todo be sure that skillName is unique, or use something else
-- @todo add support for multi-reagents recipes

A.data = {}

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()
		-- 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

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

		for i = 2,NRecipes do -- The first one is a header
			local skillName, skillType, numAvailable, isExpanded, serviceType, numSkillUps = GetTradeSkillInfo(i)
			if skillType ~= "header" then
				--if GetTradeSkillNumReagents(i) == 1 then
					-- item ID
					local itemID = A.link2ID(GetTradeSkillItemLink(i))

					-- reagent ID, valid only if there's only one reagent as we take only the first one
					local reagentID = A.link2ID(GetTradeSkillReagentItemLink(i, 1))

					-- reagent number needed
					local _, _, reagentCount, _ = GetTradeSkillReagentInfo(i, 1)

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

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

					-- error checking
					if not reagentID or not reagentCount or not skillName or not itemID or not minMade or not maxMade or not recipeLink then
						--@debug@
						print("Erreur de scan :",itemID,skillName,reagentID,reagentCount,minMade,maxMade,recipeLink)
						--@end-debug@

					else -- Zap incomplete recipes, they will be scanned later
						-- remove unneeded minMade/maxMade
						if maxMade==minMade then
							maxMade = nil
							if minMade==1 then
								minMade = nil
							end -- if
						end -- if

						-- skillName or...???
						-- There's still a problem when multiple recipes craft the same item
						if not A.data[itemID] then
							A.data[itemID] = {}
						end -- if
						local newSpell = true
						for _,v in ipairs(A.data[itemID]) do
							if v.spellName==skillName then
								newSpell = nil
								break
							end -- if
						end -- for
						if newSpell then
							A.data[itemID].spellLink = recipeLink
							A.data[itemID].manyReagents = A.data[itemID].manyReagents or GetTradeSkillNumReagents(i)>1
							tinsert(A.data[itemID],{reagentID,reagentCount,minMade,maxMade,spellName=skillName})
						end -- if
					end -- if
				--end -- if
			end -- if
		end -- for

		-- the scanning is complete
		return true
	end -- function
end -- do