Quantcast
Getting required profession levels for Recipes/Patterns/Plans/Schematics etc.? - Page 2 - WoWInterface
Thread Tools Display Modes
10-28-18, 03:50 PM   #21
LudiusMaximus
A Cobalt Mageweaver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 248
So here is how I eventually got the expansion and required level of a recipe by scanning the tooltip:

First I need a table like this to know in which order the expansion name (like "" for Vanilla, "Outland" for BC, "Northrend" for WotLK, etc.) and the profession name are given depending on the locale.

Code:
-- The %s in _G.ITEM_MIN_SKILL = "Requires %s (%d)" is replaced
-- by an expansion identifier and the profession name.
-- But the order depends on the locale.
-- e: expansion identifier
-- p: profession name
local itemMinSkillString = {
  ["enUS"] = "e p",
  ["enGB"] = "e p",
  ["deDE"] = "p e",
  ["frFR"] = "p e",
  ["itIT"] = "p e",
}

Let professionName be the localised itemSubType of the respective recipe as returned by getItemInfo(). Then the search pattern for scanning the tooltip must be built like this:

Code:
-- Need %%%%s here, because this string will be inserted twice.
local localisedItemMinSkill = string.gsub(string.gsub(string.gsub(itemMinSkillString[GetLocale()], " ", "%%%%s?"), "e", "(.*)"), "p", professionName)

-- "%s?%%.-s%s" matches both " %s " (EN), "%s " (FR) and " %1$s " (DE) in _G.ITEM_MIN_SKILL.
-- "%(%%.-d%)%s?" matches both " (%d)" (EN), " (%d) " (FR) and " (%2$d)" (DE) in _G.ITEM_MIN_SKILL.
local searchPattern = string.gsub(string.gsub("^" .. _G.ITEM_MIN_SKILL .. "$", "%s?%%.-s%s", "%%s?" .. localisedItemMinSkill .. "%%s"), "%(%%.-d%)%s?", "%%((%%d+)%%)%%s?")

-- Let msg be the respective line of the tooltip. Then you use string.match to get the (still localised) expansion identifier and the required skill out of this line:
Code:
local expansionIdentifier, requiredSkill = string.match(msg, searchPattern)

-- Trim trailing blank space if any.
expansionIdentifier = string.gsub(expansionIdentifier, "^(.-)%s$", "%1")

To change the localised expansion identifier into a non-localised one you need a table like this:

Code:
expansionIdentifierToVersionNumber = {
  ["enUS"] = {
    [""] =                      EP_VANILLA,
    ["Outland"] =               EP_BC,
    ["Northrend"] =             EP_WOTLK,
    ["Cataclysm"] =             EP_CATA,
    ["Pandaria"] =              EP_PANDARIA,
    ["Draenor"] =               EP_WOD,
    ["Legion"] =                EP_LEGION,
    ["Zandalari"] =             EP_BFA,
    ["Kul Tiran"] =             EP_BFA,
  },
  ["enGB"] = {
    [""] =                      EP_VANILLA,
    ["Outland"] =               EP_BC,
    ["Northrend"] =             EP_WOTLK,
    ["Cataclysm"] =             EP_CATA,
    ["Pandaria"] =              EP_PANDARIA,
    ["Draenor"] =               EP_WOD,
    ["Legion"] =                EP_LEGION,
    ["Zandalari"] =             EP_BFA,
    ["Kul Tiran"] =             EP_BFA,
  },
  ["deDE"] = {
    [""] =                      EP_VANILLA,
    ["der Scherbenwelt"] =      EP_BC,
    ["von Nordend"] =           EP_WOTLK,
    ["des Kataklysmus"] =       EP_CATA,
    ["von Pandaria"] =          EP_PANDARIA,
    ["von Draenor"] =           EP_WOD,
    ["der Verheerten Inseln"] = EP_LEGION,
    ["von Zandalar"] =          EP_BFA,
    ["von Kul Tiras"] =         EP_BFA,
  },
  ["frFR"] = {
    [""] =                      EP_VANILLA,
    ["de l’Outreterre"] =       EP_BC,
    ["du Norfendre"] =          EP_WOTLK,
    ["de Cataclysm"] =          EP_CATA,
    ["de Pandarie"] =           EP_PANDARIA,
    ["de Draenor"] =            EP_WOD,
    ["de Legion"] =             EP_LEGION,
    ["de Zandalar"] =           EP_BFA,
    ["de Kul Tiras"] =          EP_BFA,
  },
  ["itIT"] = {
    [""] =                      EP_VANILLA,
    ["delle Terre Esterne"] =   EP_BC,
    ["di Nordania"] =           EP_WOTLK,
    ["di Cataclysm"] =          EP_CATA,
    ["di Pandaria"] =           EP_PANDARIA,
    ["di Draenor"] =            EP_WOD,
    ["di Legion"] =             EP_LEGION,
    ["di Zandalar"] =           EP_BFA,
    ["di Kul Tiras"] =          EP_BFA,
  },
}
To do this:

Code:
local globalExpansionIdentifier = expansionIdentifierToVersionNumber[GetLocale()][expansionIdentifier]

If you want to see this in action, check out my first ever released addon: Bagnon RequiredLevel

Thanks to all of you for getting me there! :-)
  Reply With Quote
08-24-19, 04:15 PM   #22
LudiusMaximus
A Cobalt Mageweaver
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 248
Originally Posted by Xrystal View Post
Hmm
https://www.wowhead.com/item=6657/sa...eviate-delight
https://www.wowhead.com/item=6661/re...eviate-delight
https://www.wowhead.com/spell=8238/s...eviate-delight

One seems to be the recipe after it is learned (8238) and one (6661) the recipe scroll that is picked up and the other (6657) is the resulting food stack item.
So, unless there is something in the recipe list that points to the sourceID ( recipe scroll ) you might not be able to tie them together to guarantee a match.
I just found this great lib which does exactly that!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Getting required profession levels for Recipes/Patterns/Plans/Schematics etc.?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off