/trunk
-- SkillDB.lua: interface to the characters' known skill database |
-- $Id: SkillDB.lua 1098 2009-08-10 04:38:33Z jnmiller $ |
local L = LibStub("AceLocale-3.0"):GetLocale("RecipeRadar") |
function RecipeRadar_SkillDB_Init() |
local db = RecipeRadar_SkillDB_GetPlayerProfessions() |
-- fishing doesn't get an auto-reset during the spellbook parsing |
if (not db[RRS("Fishing")] or not db[RRS("Fishing")].Recipes) then |
db[RRS("Fishing")] = { Rank = 0, Recipes = { } } |
if (not db[L["Fishing"]] or not db[L["Fishing"]].Spell) then |
db[L["Fishing"]] = { Rank = 0, Spell = { } } |
end |
end |
if (not profs[prof_name]) then profs[prof_name] = { } end |
profs[prof_name].Rank = prof_rank |
profs[prof_name].Recipes = { } |
profs[prof_name].Spell = { } |
-- this line might help avoid the 0 count that I seem to get on |
-- some early invocations of this function? |
local recipe, hdr = RecipeRadar_SkillDB_GetRecipeInfo(prof_type, i) |
if (recipe and hdr ~= "header") then |
-- map craft window names to real recipe names |
local map = RecipeRadar_NameMap[GetLocale()] |
if (map and map[recipe]) then |
profs[prof_name].Recipes[recipe] = nil |
recipe = map[recipe] |
end |
-- Spanish clients need the first letter to be lower case |
-- eg. "Toga de lino roja" vs. "Patrón: toga de lino rojo" |
if (GetLocale() == "esES" or GetLocale() == "ruRU") then |
recipe = string.gsub(recipe, "^%u", string.lower) |
end |
-- if it's not a header, the character knows this recipe |
profs[prof_name].Recipes[recipe] = 1 |
local ID_Spell = RecipeRadar_SkillDB_GetRecipeID(prof_type, i) |
profs[prof_name].Spell[ID_Spell] = 1 |
end |
-- Adds unlisted/implied "recipes" to the skill DB. |
function RecipeRadar_SkillDB_HandleSpecialCase(profs, prof_name, max_rank) |
if (prof_name == RRS("First Aid")) then |
if (prof_name == L["First Aid"]) then |
if (max_rank > 150) then |
-- Expert First Aid - Under Wraps |
local name = RecipeRadar_GetSafeItemInfo(16084) |
if (name ~= RRS("Uncached Recipe")) then |
profs[RRS("First Aid")].Recipes[name] = 1 |
if (name ~= L["Uncached Recipe"]) then |
profs[L["First Aid"]].Spell[7924] = 1 |
end |
end |
if (max_rank > 300) then |
-- Master First Aid - Doctor in the House |
local name = RecipeRadar_GetSafeItemInfo(22012) |
if (name ~= RRS("Uncached Recipe")) then |
profs[RRS("First Aid")].Recipes[name] = 1 |
if (name ~= L["Uncached Recipe"]) then |
profs[L["First Aid"]].Spell[27028] = 1 |
end |
end |
end |
if (prof_name == RRS("Fishing")) then |
if (prof_name == L["Fishing"]) then |
if (max_rank > 150) then |
-- Expert Fishing - The Bass and You |
local name = RecipeRadar_GetSafeItemInfo(16083) |
if (name ~= RRS("Uncached Recipe")) then |
profs[RRS("Fishing")].Recipes[name] = 1 |
if (name ~= L["Uncached Recipe"]) then |
profs[L["Fishing"]].Spell[7732] = 1 |
end |
end |
if (max_rank > 300) then |
-- Master Fishing - The Art of Angling |
local name = RecipeRadar_GetSafeItemInfo(27532) |
if (name ~= RRS("Uncached Recipe")) then |
profs[RRS("Fishing")].Recipes[name] = 1 |
if (name ~= L["Uncached Recipe"]) then |
profs[L["Fishing"]].Spell[33100] = 1 |
end |
end |
end |
if (prof_name == RRS("Cooking")) then |
if (prof_name == L["Cooking"]) then |
if (max_rank > 150) then |
-- Expert Cookbook |
local name = RecipeRadar_GetSafeItemInfo(16072) |
if (name ~= RRS("Uncached Recipe")) then |
profs[RRS("Cooking")].Recipes[name] = 1 |
if (name ~= L["Uncached Recipe"]) then |
profs[L["Cooking"]].Spell[3413] = 1 |
end |
end |
if (max_rank > 300) then |
-- Master Cookbook |
local name = RecipeRadar_GetSafeItemInfo(27736) |
if (name ~= RRS("Uncached Recipe")) then |
profs[RRS("Cooking")].Recipes[name] = 1 |
if (name ~= L["Uncached Recipe"]) then |
profs[L["Cooking"]].Spell[33359] = 1 |
end |
end |
end |
if (not note_type or note_type == "") then return true end |
if (note_type == "Class") then -- eg. 'Class: Rogue' |
return RecipeRadar_SkillDB_GetPlayerClass(player) == RRS(note_value) |
return RecipeRadar_SkillDB_GetPlayerClass(player) == L[note_value] |
end |
return true |
RecipeRadar_Print(hdr .. ".") |
if (profession == "FirstAid") then |
profession = "First Aid" |
profession = L["First Aid"] |
end |
for realm_name, player_table in pairs(RecipeRadar_SkillDB) do |
for prof_name, recipe_table in pairs(player_info.Professions) do |
if (profession == "" or profession == prof_name) then |
RecipeRadar_Print(" Skill: " .. prof_name .. |
" (Rank " .. recipe_table.Rank .. ")") |
if (recipe_table.Recipes) then |
for recipe_name, valid in pairs(recipe_table.Recipes) do |
RecipeRadar_Print(" Recipe: " .. recipe_name) |
RecipeRadar_Print(" Skill: " .. prof_name .. " (Rank " .. recipe_table.Rank .. ")") |
if (recipe_table.Spell) then |
for spell_number, valid in pairs(recipe_table.Spell) do |
RecipeRadar_Print(" Spell: " .. spell_number) |
end |
end |
end |
end |
function RecipeRadar_SkillDB_GetRecipeID(prof_type, index) |
local itemLink, ID_Spell |
if (prof_type == "trade") then |
itemLink = GetTradeSkillRecipeLink(index) |
elseif (prof_type == "craft") then |
itemLink = GetCraftRecipeLink(index) |
end |
ID_Spell = itemLink:match("enchant:(%d+)") |
return tonumber(ID_Spell) |
end |
------------------------------------------------------------------------------ |
-- Functions to open/parse various frames to update skill info. |
------------------------------------------------------------------------------ |
for i = 1, num_spells do |
local name = GetSpellBookItemName(i, BOOKTYPE_SPELL) |
-- local name = GetSpellName(i, BOOKTYPE_SPELL) |
if (not name) then return end |
-- open each of the player's crafting windows |
if (RecipeRadar_IsProfession(name) and name ~= RRS("Fishing")) then |
if (RecipeRadar_IsProfession(name) and name ~= L["Fishing"]) then |
CastSpell(i, BOOKTYPE_SPELL) |
end |
end |
--[[ |
-- Opens the character window and sets it to the skill frame. |
function RecipeRadar_SkillDB_ShowSkillFrame() |
local profs = RecipeRadar_SkillDB_GetPlayerProfessions() |
local known_skills = { } |
RecipeRadar_SkillDB_ShowSkillFrame() |
local prof1, prof2, archaeology, fishing, cooking, firstAid = GetProfessions() |
for i = 1, GetProfessions() do |
local name, hdr, _, rank, _, modifier, max_rank = GetProfessionInfo(i) |
known_skills[name] = 1 |
if (name == RRS("Fishing")) then |
if (not profs[name]) then |
profs[name] = { } |
end |
if prof1 ~= nil then |
local name, _, skillLevel, maxSkillLevel, _, _, _, skillModifier = GetProfessionInfo(prof1) |
known_skills[name] = 1 |
end |
if prof2 ~= nil then |
local name, _, skillLevel, maxSkillLevel, _, _, _, skillModifier = GetProfessionInfo(prof2) |
known_skills[name] = 1 |
end |
if archaeology ~= nil then |
local name, _, skillLevel, maxSkillLevel, _, _, _, skillModifier = GetProfessionInfo(archaeology) |
known_skills[name] = 1 |
end |
if fishing ~= nil then |
local name, _, skillLevel, maxSkillLevel, _, _, _, skillModifier = GetProfessionInfo(fishing) |
known_skills[name] = 1 |
if (not profs[name]) then |
profs[name] = { } |
end |
profs[name].Rank = skillLevel |
RecipeRadar_SkillDB_HandleSpecialCase(profs, name, maxSkillLevel) |
end |
if cooking ~= nil then |
local name, _, skillLevel, maxSkillLevel, _, _, _, skillModifier = GetProfessionInfo(cooking) |
known_skills[name] = 1 |
end |
if firstAid ~= nil then |
local name, _, skillLevel, maxSkillLevel, _, _, _, skillModifier = GetProfessionInfo(firstAid) |
known_skills[name] = 1 |
end |
profs[name].Rank = rank |
RecipeRadar_SkillDB_HandleSpecialCase(profs, name, max_rank) |
end |
end |
-- here we're validating that profs in the database match those that |
-- the character actually knows - those that aren't found are nulled |
-- to keep the database in sync |
end |
end |
RecipeRadar_SkillDB_HideSkillFrame() |
end |
--]] |
-- Opens the character window and sets it to the reputation frame. |
function RecipeRadar_SkillDB_ShowReputationFrame() |
-- Draw the supplied button on the world map. |
function RecipeRadar_Worldmap_UpdateButton(button) |
local Astrolabe = DongleStub("Astrolabe-0.4") |
local Astrolabe = DongleStub("Astrolabe-1.0") |
local mapId = Astrolabe:GetMapID(button.Continent, button.RegionID) |
Astrolabe:PlaceIconOnWorldMap(_G["WorldMapDetailFrame"], |
button, button.Continent, button.RegionID, |
button, mapId, nil, |
button.Vendor.Coordinates[1].x, button.Vendor.Coordinates[1].y) |
end |