Quantcast

Added achievement tracking for professions.

pschifferer [11-05-09 - 17:01]
Added achievement tracking for professions.
Filename
CauldronMain.lua
CauldronMainUI.lua
CauldronUtil.lua
diff --git a/CauldronMain.lua b/CauldronMain.lua
index eca671d..1df1a02 100644
--- a/CauldronMain.lua
+++ b/CauldronMain.lua
@@ -204,10 +204,14 @@ function Cauldron:OnEnable()
 	self:RegisterEvent("CRAFT_CLOSE", "OnCraftClose");
 --	self:RegisterEvent("PLAYER_LOGOUT");
 	self:RegisterEvent("UI_ERROR_MESSAGE", "OnError");
+	self:RegisterEvent("UNIT_QUEST_LOG_CHANGED", "OnQuestLogChanged");

 	-- setup hooks for tooltips
 	self:HookTooltips();

+	-- initialize the achievement map
+	self:CreateAchievementSkillMap();
+
 	-- clear init flag
 	self.initializing = false;

@@ -534,6 +538,18 @@ function Cauldron:OnBankClosed()
 --@end-alpha@
 end

+function Cauldron:OnQuestLogChanged()
+--@alpha@
+	self:info("OnQuestLogChanged enter");
+--@end-alpha@
+
+--	TODO
+
+--@alpha@
+	self:info("OnQuestLogChanged exit");
+--@end-alpha@
+end
+
 function Cauldron:OnError()
 --@alpha@
 	self:debug("OnError enter");
diff --git a/CauldronMainUI.lua b/CauldronMainUI.lua
index 49b8ded..99e6dd4 100644
--- a/CauldronMainUI.lua
+++ b/CauldronMainUI.lua
@@ -338,7 +338,8 @@ function Cauldron:UpdateSkillList()
 		elseif skillInfo.available > 0 then
 			nameText = nameText.." ["..skillInfo.available.."]";
 		end
-		if Cauldron:GetAchievementsForSkill(skillInfo) then
+		local achievements = Cauldron:GetAchievementsForSkill(skillInfo);
+		if achievements and #achievements > 0 then
 			nameText = nameText.." [A]";
 		end
 		frame:SetText(nameText);
diff --git a/CauldronUtil.lua b/CauldronUtil.lua
index 538c320..dd4b2d9 100644
--- a/CauldronUtil.lua
+++ b/CauldronUtil.lua
@@ -248,15 +248,51 @@ function Cauldron:SortTableIndices(t)
 	return a;
 end

+function Cauldron:CreateAchievementSkillMap()
+
+	Cauldron.vars.achievementMap = {};
+
+	-- TODO: get all achievement categories that have 169 (Professions) as parent
+	-- currently: 171 (Fishing), 170 (Cooking), 172 (First Aid)
+	local categories = { 170, 171, 172 };
+
+	for _,categoryID in ipairs(categories) do
+		-- get the number of achievements in this category
+		local numAchievements = GetCategoryNumAchievements(categoryID);
+		for i=1,numAchievements do
+			-- get the achievements in the category
+			local achievementID,_,_,achievementCompleted,_,_,_,_,_,_,_ = GetAchievementInfo(categoryID, i);
+			if not achievementCompleted then
+				local numCriteria = GetAchievementNumCriteria(achievementID);
+				for j=1,numCriteria do
+					-- get the criteria of the achievement
+					local criteriaString,criteriaType,criteriaCompleted,_,_,_,_,assetID,_,criteriaID = GetAchievementCriteriaInfo(achievementID, j);
+
+					-- check if the achievement has been completed
+					if not criteriaCompleted then
+						-- check if the criteria is the right type
+						if criteriaType == 29 or criteriaType == 112 then
+							if not Cauldron.vars.achievementMap[criteriaString] then
+								Cauldron.vars.achievementMap[criteriaString] = {};
+							end
+
+							table.insert(Cauldron.vars.achievementMap[criteriaString], achievementID);
+						end
+					end
+				end
+			end
+		end
+	end
+
+end
+
 function Cauldron:GetAchievementsForSkill(skillInfo)

 	if not skillInfo then
 		return nil;
 	end
-
-	-- TODO
-
-	return nil;
+
+	return Cauldron.vars.achievementMap[skillInfo.name];
 end

 function Cauldron:GetAutoBuy()