Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions DataStore_Crafts/DataStore_Crafts_Retail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,16 @@ local function ScanProfessionLinks()
AddonFactory:Broadcast("DATASTORE_PROFESSION_LINKS_UPDATED")
end

local SKILL_GREY = 4

local SkillTypeToColor = {
["header"] = 0,
["subheader"] = 0, -- lists are grouped by header, and sometimes by subheader
["optimal"] = 1, -- orange
["medium"] = 2, -- yellow
["easy"] = 3, -- green
["trivial"] = 4, -- grey
["nodifficulty"] = 4, -- white, ie: recipes that never grant a skill up, mostly the epic ones. Grey is the closest match.
}

local function ScanCooldowns()
Expand Down Expand Up @@ -528,14 +532,15 @@ local function ScanRecipes_NonRetail()
end

-- Get recipeID


recipeID = nil -- reset it, or an entry without a valid link would inherit the previous entry's id
recipeLink = GetTradeSkillRecipeLink(i) -- add recipe link here to get recipeID
if not recipeLink then
recipeLink = GetCraftRecipeLink(i)
end
if recipeLink then
local found, _, enchantString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]")
recipeID = tonumber(enchantString:match("enchant:(%d+)"))
-- an unexpected link format must not throw, or the rest of the list would not be scanned at all
recipeID = tonumber(recipeLink:match("|Henchant:(%d+)"))
if recipeID then
reagentsDB[recipeID] = TableConcat(reagentsInfo, "|")
end
Expand Down Expand Up @@ -570,30 +575,31 @@ local function ScanRecipes_NonRetail()

end
-- Scan recipe
local color = SkillTypeToColor[skillType]
-- An unknown skill type must still be stored: dropping it not only loses the recipe,
-- it leaves a hole in the crafts array, and the readers stop at the first hole.
local color = SkillTypeToColor[skillType] or SKILL_GREY
local craftInfo

if color then
if skillType == "header" then
craftInfo = skillName or ""
TableInsert(profession.Categories, skillName)
else
-- cooldowns, if any
local cooldown = GetTradeSkillCooldown(i)
if cooldown then
-- ex: "Hexweave Cloth|86220|1533539676" expire at "now + cooldown"
TableInsert(profession.Cooldowns, format("%s|%d|%d", skillName, cooldown, cooldown + time()))
end
if color == 0 then
craftInfo = skillName or ""
TableInsert(profession.Categories, skillName)
else
-- cooldowns, if any
local cooldown = GetTradeSkillCooldown(i)
if cooldown then
-- ex: "Hexweave Cloth|86220|1533539676" expire at "now + cooldown"
TableInsert(profession.Cooldowns, format("%s|%d|%d", skillName, cooldown, cooldown + time()))
end

-- if there is a valid recipeID, save it
if recipeLink then
craftInfo = (recipeLink and recipeID) and recipeID or ""
else
craftInfo = (link and itemID) and itemID or ""
end
-- if there is a valid recipeID, save it
if recipeLink then
craftInfo = (recipeLink and recipeID) and recipeID or ""
else
craftInfo = (link and itemID) and itemID or ""
end
crafts[i] = format("%s|%s", color, craftInfo)
end

crafts[i] = format("%s|%s", color, craftInfo)
end

-- Old school enchanting
Expand Down Expand Up @@ -913,15 +919,26 @@ end

local function _GetNumRecipesByColor(profession)
-- counts the number of orange, yellow, green and grey recipes.
local counts = { [0] = 0, [1] = 0, [2] = 0, [3] = 0 }

_IterateRecipes(profession, 0, 0, function(recipeData)
local counts = { [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0 }

-- Non-retail hands the color index straight to the callback, and does not call back for headers.
if not isRetail then
_IterateRecipes(profession, 0, 0, function(color)
if color then
counts[color] = (counts[color] or 0) + 1
end
end)

return counts[1], counts[2], counts[3], counts[4] -- orange, yellow, green, grey
end

_IterateRecipes(profession, 0, 0, function(recipeData)
if recipeData then
local color = _GetRecipeInfo(recipeData)
counts[color] = counts[color] + 1
counts[color] = (counts[color] or 0) + 1
end
end)

return counts[3], counts[2], counts[1], counts[0] -- orange, yellow, green, grey
end

Expand Down