Module:Skills/Artisan: Difference between revisions

From Melvor Idle
m (Fix getRunecraftingTable error description)
m (Add space for separator for herb itemsources)
 
(53 intermediate revisions by 6 users not shown)
Line 2: Line 2:
--Contains function for skills that consume resources (ie smithing, cooking, herblore, etc.)
--Contains function for skills that consume resources (ie smithing, cooking, herblore, etc.)
local p = {}
local p = {}
local SkillData = mw.loadData('Module:Skills/data')
local ShopData = mw.loadData('Module:Shop/data')


local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Constants = require('Module:Constants')
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Shop = require('Module:Shop')
local ItemSourceTables = require('Module:Items/SourceTables')


function p.getCookedItemsTable(frame)
function p.getCookedItemsTable(frame)
  local result = '{| class="wikitable sortable stickyHeader"'
local category = frame.args ~= nil and frame.args[1] or frame
  result = result..'\r\n|- class="headerRow-0"'
local categoryMap = {
  result = result..'\r\n!colspan="2"|Cooked Item!!'..Icons.Icon({'Cooking', type='skill', notext=true})..' Level'
["Cooking Fire"] = 'melvorD:Fire',
  result = result..'!!XP!!Healing!!Value!!Ingredients'
["Furnace"] = 'melvorD:Furnace',
["Pot"] = 'melvorD:Pot'
}
local categoryID = categoryMap[category]
 
-- Find recipes for the relevant categories
-- Note: Excludes Lemon cake
local recipeArray = GameData.getEntities(SkillData.Cooking.recipes,
function(recipe)
return (categoryID == nil or recipe.categoryID == categoryID) and recipe.noMastery == nil
end)
table.sort(recipeArray, function(a, b) return a.level < b.level end)
 
-- Logic for generating some cells of the table which are consistent for normal & perfect items
local getHealingCell = function(item, qty)
if item ~= nil then
return 'data-sort-value="'..(math.floor(item.healsFor) * qty)..'"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..math.floor(item.healsFor * 10)..(qty > 1 and ' (x'..qty..')' or '')
else
return ' '
end
end
local getSaleValueCell = function(item, qty)
if item ~= nil then
return 'data-sort-value="'..math.floor(item.sellsFor * qty)..'"|'..Icons.GP(math.floor(item.sellsFor))..(qty > 1 and ' (x'..qty..')' or '')
else
return ' '
end
end
 
local resultPart = {}
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n!colspan="3" rowspan="2"|Cooked Item!!rowspan="2"|'..Icons.Icon({'Cooking', type='skill', notext=true})..' Level')
table.insert(resultPart, '!!rowspan="2"|Cook Time (s)!!rowspan="2"|XP!!rowspan="2"|XP/s!!colspan="2"|Healing!!colspan="2"|Value!!rowspan="2"|Ingredients')
table.insert(resultPart, '\r\n|- class="headerRow-1"')
table.insert(resultPart, '\r\n!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
table.insert(resultPart, '!!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))


  local itemArray = Items.getItems(function(item) return item.cookingID ~= nil end)
for i, recipe in ipairs(recipeArray) do
  table.sort(itemArray, function(a, b) return a.cookingLevel < b.cookingLevel end)
local item = Items.getItemByID(recipe.productID)
local perfectItem = nil
if recipe.perfectCookID ~= nil then
perfectItem = Items.getItemByID(recipe.perfectCookID)
end
local qty = recipe.baseQuantity or 1


  for i, item in Shared.skpairs(itemArray) do
table.insert(resultPart, '\r\n|-')
    local cookedItem = Items.getItemByID(item.cookedItemID)
table.insert(resultPart, '\r\n|class="table-img"|'..Icons.Icon({item.name, type='item', notext=true, size='50'}))
    result = result..'\r\n|-'
table.insert(resultPart, '\r\n|class="table-img"| ')
    result = result..'\r\n|style="min-width:25px"|'..Icons.Icon({cookedItem.name, type='item', notext='true', size='50'})..'||[['..cookedItem.name..']]'
if perfectItem ~= nil then
    result = result..'||style="text-align:right"|'..item.cookingLevel
table.insert(resultPart, Icons.Icon({perfectItem.name, type='item', notext=true, size='50'}))
    result = result..'||style="text-align:right"|'..item.cookingXP
end
    result = result..'||style="text-align:right" data-sort-value="'..cookedItem.healsFor..'"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..(cookedItem.healsFor * 10)
table.insert(resultPart, '||')
    result = result..'||style="text-align:right" data-sort-value="'..cookedItem.sellsFor..'"|'..Icons.GP(cookedItem.sellsFor)
if qty > 1 then
    result = result..'||'..Icons.Icon({item.name, type='item', qty = 1})
table.insert(resultPart, qty..'x ')
  end
end
table.insert(resultPart, Icons.getExpansionIcon(item.id))
table.insert(resultPart, Icons.Icon({item.name, type='item', noicon = true}))
table.insert(resultPart, '||style="text-align:right"|' .. recipe.level)
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseInterval .. '"|' .. Shared.round(recipe.baseInterval / 1000, 2, 0))
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseExperience .. '"|' .. Shared.formatnum(recipe.baseExperience))
local xpRate = recipe.baseExperience / (recipe.baseInterval / 1000)
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. xpRate .. '"|' .. Shared.round(xpRate, 2, 0))
table.insert(resultPart, '||'..getHealingCell(item, qty)..'||'..getHealingCell(perfectItem, qty))
table.insert(resultPart, '||'..getSaleValueCell(item, qty)..'||'..getSaleValueCell(perfectItem, qty))
local matArray = {}
for j, mat in ipairs(recipe.itemCosts) do
local matItem = Items.getItemByID(mat.id)
if matItem ~= nil then
table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.quantity}))
end
end
table.insert(resultPart, '\r\n|'..table.concat(matArray, ' '))
end


  result = result..'\r\n|}'
table.insert(resultPart, '\r\n|}')
  return result
return table.concat(resultPart)
end
end


local tierSuffix = { 'I', 'II', 'III', 'IV' }
local tierSuffix = { 'I', 'II', 'III', 'IV' }
function p._getHerblorePotionTable(category)
function p._getPotionDescription(potion)
  if string.upper(category) == 'COMBAT' then
-- TODO: Temporary fix below for incorrect Traps Potion descriptions. To amend
    category = 0
-- once corrected within game data
  elseif string.upper(category) == 'SKILL' then
if potion.customDescription and not Shared.contains(potion.id, 'melvorTotH:Traps_Potion_') then
    category = 1
return potion.customDescription
  elseif type(category) == 'string' then
elseif type(potion.modifiers) == 'table' and not Shared.tableIsEmpty(potion.modifiers) then
    category = tonumber(category)
return Constants.getModifiersText(potion.modifiers, false, true)
  end
else
return ''
end
end
 
function p._getHerblorePotionTable(categoryName)
local categoryID = nil
if string.upper(categoryName) == 'COMBAT' then
categoryID = 'melvorF:CombatPotions'
elseif string.upper(categoryName) == 'SKILL' then
categoryID = 'melvorF:SkillPotions'
else
return Shared.printError('No such potion category ' .. (categoryName or 'nil'))
end


  local potionArray = {}
local potionArray = GameData.getEntities(SkillData.Herblore.recipes, function(potion) return potion.categoryID == categoryID end)
  for i, potion in Shared.skpairs(SkillData.Herblore.ItemData) do
table.sort(potionArray, function(a, b) return a.level < b.level end)
    if potion.category == category then
      table.insert(potionArray, potion)
    end
  end


  local result = '{|class = "wikitable sortable stickyHeader"'
local resultPart = {}
  result = result..'\r\n|- class="headerRow-0"'
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')
  result = result..'\r\n!Potion!!'..Icons.Icon({'Herblore', type='skill', notext=true})..' Level'
table.insert(resultPart, '\r\n|- class="headerRow-0"')
  result = result..'!!XP!!Ingredients!!colspan="2"|Tier!!Value!!Charges!!Effect'
table.insert(resultPart, '\r\n!Potion!!'..Icons.Icon({'Herblore', type='skill', notext=true})..' Level')
table.insert(resultPart, '!!XP!!Ingredients!!style="width:30px;"|Tier!!Value!!Charges!!Effect')


  table.sort(potionArray, function(a, b) return a.herbloreLevel < b.herbloreLevel end)
for i, potion in ipairs(potionArray) do
table.insert(resultPart, '\r\n|-')
local expIcon = Icons.getExpansionIcon(potion.potionIDs[1])
table.insert(resultPart, '\r\n|rowspan="4"|'..expIcon..'[['..potion.name..']]')
table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.level)
table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.baseExperience)


  for i, potion in Shared.skpairs(potionArray) do
local matArray = {}
    local tierPots = {}
for j, mat in ipairs(potion.itemCosts) do
    for j = 1, 4, 1 do
local matItem = Items.getItemByID(mat.id)
      table.insert(tierPots, Items.getItemByID(potion.itemID[j]))
table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.quantity}))
    end
end
    result = result..'\r\n|-'
table.insert(resultPart, '||rowspan="4"|'..table.concat(matArray, ', ')..'||')
    if potion.name == 'Bird Nests Potion' then
      result = result..'\r\n|rowspan="4"|[[Bird Nest Potion]]'
    else
      result = result..'\r\n|rowspan="4"|[['..potion.name..']]'
    end
    result = result..'||rowspan="4" style="text-align:right"|'..potion.herbloreLevel
    result = result..'||rowspan="4" style="text-align:right"|'..potion.herbloreXP


    local matArray = {}
local tierRows = {}
    for j, mat in Shared.skpairs(tierPots[1].herbloreReq) do
for j, potionID in ipairs(potion.potionIDs) do
      local matItem = Items.getItemByID(mat.id)
local rowTxt = {}
      table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.qty}))
local tierPot = Items.getItemByID(potionID)
    end
table.insert(rowTxt, Icons.Icon({tierPot.name, type='item', notext=true}))
    result = result..'||rowspan="4"|'..table.concat(matArray, ', ')..'||'
table.insert(rowTxt, Icons.Icon({tierPot.name, tierSuffix[j], type = 'item', noicon=true}))
   
table.insert(rowTxt, '||style="text-align:right;" data-sort-value="'..tierPot.sellsFor..'"|'..Icons.GP(tierPot.sellsFor))
    local tierRows = {}
table.insert(rowTxt, '||style="text-align:right;"|'..tierPot.charges..'|| '..p._getPotionDescription(tierPot))
    for j, tierPot in Shared.skpairs(tierPots) do
table.insert(tierRows, table.concat(rowTxt))
      local rowTxt = Icons.Icon({tierPot.name, type='item', notext=true})
end
      rowTxt = rowTxt..'||[['..tierPot.name..'|'..tierSuffix[j]..']]'
table.insert(resultPart, table.concat(tierRows, '\r\n|-\r\n|'))
      rowTxt = rowTxt..'||style="text-align:right;" data-sort-value="'..tierPot.sellsFor..'"|'..Icons.GP(tierPot.sellsFor)
end
      rowTxt = rowTxt..'||style="text-align:right;"|'..tierPot.potionCharges..'||'..tierPot.description
      table.insert(tierRows, rowTxt)
    end
    result = result..table.concat(tierRows, '\r\n|-\r\n|')
  end


  result = result..'\r\n|}'
table.insert(resultPart, '\r\n|}')
  return result
return table.concat(resultPart)
end
end


function p.getHerblorePotionTable(frame)
function p.getHerblorePotionTable(frame)
  local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
  return p._getHerblorePotionTable(category)
return p._getHerblorePotionTable(category)
end
end


function p.getCookingFireTable(frame)
function p._getHerbloreHerbTable(args)
  local toolArray = {}
local allHerbs = {}
  for i, upgrade in Shared.skpairs(ShopData.Shop.SkillUpgrades) do
local allPotions = GameData.getEntities(SkillData.Herblore.recipes, function() return true end)
    if Shared.contains(upgrade.name, 'Cooking Fire') then
      table.insert(toolArray, upgrade)
-- Finds the herb from a potion along with the level required to make the potion.
local function handlePotion(potion)
local potionCosts = potion.itemCosts
local level = potion.level
if potionCosts == nil or level == nil then
return
end
-- Find if this potion uses a herb, and which herb it is.
for _, ingredient in pairs(potionCosts) do
local ingredientID = ingredient.id
if ingredientID == nil or string.sub(ingredientID, -5) ~= "_Herb" then
return
end
-- Set the lowest level of potion this herb is used in.
local currLevel = allHerbs[ingredientID] or 9999999
if level < currLevel then
allHerbs[ingredientID] = level
end
end
end
 
for _, potion in pairs(allPotions) do
handlePotion(potion)
end
local sortedValues = Shared.sortDictionary(
allHerbs,
function (a, b) return a.value < b.value end)
 
local tbl = mw.html.create("table")
        :addClass("wikitable sortable stickyHeader")
       
    -- Add header
    tbl :tag("tr"):addClass("headerRow-0")
    :tag("th"):wikitext(Icons.Icon({'Herblore', type='skill', notext=true})..' Level')
    :tag("th"):wikitext("Herb")
    :tag("th"):wikitext("Value")
    :tag("th"):wikitext("Herb Sources")
    :done()
   
    -- Fill wikitable.
    for _, v in pairs(sortedValues) do
    local herbItem = Items.getItemByID(v['key'])
    local herbLevel = v['value']
    local dlcIcon = Icons.getExpansionIcon(herbItem.id)
 
    -- Add rows
    tbl :tag("tr")
    :tag("td"):wikitext(herbLevel)
    :tag("td"):wikitext(dlcIcon .. Icons.Icon({herbItem.name, type='item'}))
    :tag("td"):wikitext(Icons.GP(herbItem.sellsFor))
    :tag('td'):wikitext(ItemSourceTables._getItemSources(herbItem, false, nil, ' '))
    :done()
     end
     end
  end


  local result = '{| class="wikitable"'
return tostring(tbl)
  result = result..'\r\n!colspan="4"| !!colspan="2"|Bonus '..Icons.Icon({'Cooking', type='skill', notext=true})..' XP'
end
  result = result..'\r\n|- class="headerRow-0"'
 
  result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Firemaking', type='skill', notext=true})..' Level'
function p.getHerbloreHerbTable(frame)
  result = result..'!!Cost!!This Fire!!Total'
local args = frame:getParent().args
return p._getHerbloreHerbTable(args)
end


  local total = 0
function p.getPotionTable(frame)
  local total2 = 0
local potionName = frame.args ~= nil and frame.args[1] or frame


  for i, tool in Shared.skpairs(toolArray) do
local recipe = GameData.getEntityByName(SkillData.Herblore.recipes, potionName)
    result = result..'\r\n|-'
if recipe == nil then
    result = result..'\r\n|style="min-width:25px" data-sort-value="'..tool.name..'"|'..Icons.Icon({tool.name, type='upgrade', size='50', notext=true})
return Shared.printError('No potion named "' .. potionName .. '" was found')
    result = result..'||'..tool.name
end
    local level = 1
    if tool.unlockRequirements ~= nil and tool.unlockRequirements.skillLevel ~= nil then
      --Gonna be lazy and assume there's only the one skill level and it's the one we care about
      level = tool.unlockRequirements.skillLevel[1][2]
    end
    result = result..'||style="text-align:right"|'..level
    result = result..'||style="text-align:right" data-sort-value="'..tool.cost.gp..'"|'..Shop.getCostString(tool.cost)


    local bonusXP = tool.contains.modifiers.increasedSkillXP[1][2]
local resultPart = {}
    total = total + bonusXP
table.insert(resultPart, '{| class="wikitable"')
table.insert(resultPart, '\r\n!colspan=4|[['..potionName..']]')
table.insert(resultPart, '\r\n|-\r\n!Potion!!Tier!!Charges!!Effect')


    result = result..'||style="text-align:right"|+'..bonusXP..'%'
for i, potionID in ipairs(recipe.potionIDs) do
    result = result..'||style="text-align:right"|+'..total..'%'
local tier = tierSuffix[i]
  end
local potion = Items.getItemByID(potionID)
if potion ~= nil then
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n| ' .. Icons.Icon({potion.name, type='item', notext=true, size='60'}))
table.insert(resultPart, '|| ' .. Icons.getExpansionIcon(potion.id) .. Icons.Icon({potion.name, tier, type='item', noicon=true}))
table.insert(resultPart, '|| ' .. potion.charges .. '|| ' .. p._getPotionDescription(potion))
end
end


  result = result..'\r\n|}'
table.insert(resultPart, '\r\n|}')
  return result
return table.concat(resultPart)
end
end


function p.getRunecraftingTable(frame)
function p.getRunecraftingTable(frame)
  local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
  local data = nil
return p._getRecipeTable('Runecrafting', category, {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients', 'SkillXPSec', 'GPSec'})
  if    category == "Runes"      then data = SkillData.Runecrafting.Runes
end
  elseif category == "ComboRunes" then data = SkillData.Runecrafting.ComboRunes
  elseif category == "Weapons"    then data = SkillData.Runecrafting.Weapons
  elseif category == "AirGear"    then data = SkillData.Runecrafting.AirGear
  elseif category == "WaterGear"  then data = SkillData.Runecrafting.WaterGear
  elseif category == "EarthGear"  then data = SkillData.Runecrafting.EarthGear
  elseif category == "FireGear"  then data = SkillData.Runecrafting.FireGear
  end


  if data == nil then
function p.getFletchingTable(frame)
    return "ERROR: Invalid Runecrafting category name.[[Category:Pages with script errors]]"
local category = frame.args ~= nil and frame.args[1] or frame
  end
return p._getRecipeTable('Fletching', category, {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients'})
end


  local result = '{| class="wikitable sortable stickyHeader"'
function p.getCraftingTable(frame)
  result = result..'\r\n|- class="headerRow-0"'
local category = frame.args ~= nil and frame.args[1] or frame
  result = result..'\r\n!Item\r\n!Name\r\n!Runecrafting Level\r\n!Experience'
local columns = {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients'}
  result = result..'\r\n!Item Price\r\n!Ingredients\r\n!XP/s\r\n!GP/s'
if category == 'Rings' or category == 'Necklaces' then
table.insert(columns, "Description")
end
return p._getRecipeTable('Crafting', category, columns)
end


  local rcArray = {}
function p.getSmithingTable(frame)
  for i, rc in Shared.skpairs(data) do
local category = frame.args ~= nil and frame.args[1] or frame
    table.insert(rcArray, rc)
local columns = {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients'}
  end
if category ~= 'Bars' then
  table.sort(rcArray, function(a, b) return a.runecraftingLevel < b.runecraftingLevel end)
table.insert(columns, 'GPBar')
end
return p._getRecipeTable('Smithing', category, columns)
end
 
-- Given a skill name, category, and column list, produces a table of recipes for that
-- skill & category combination. If categoryName is '', all recipes are returned.
-- Note: This only supports a number of skills with consistent recipe data structures, being:
-- Fletching, Crafting, and Runecrafting
-- Valid column list options are: Item, SkillLevel, SkillXP, GP, Ingredients, SkillXPSec, GPSec
function p._getRecipeTable(skillName, categoryName, columnList)
-- Validation: Parameters
if type(skillName) ~= 'string' then
return Shared.printError('skillName must be a string')
elseif not Shared.contains({'string', 'nil'}, type(categoryName)) then
return Shared.printError('category must be a string or nil')
elseif type(columnList) ~= 'table' or Shared.tableIsEmpty(columnList) then
return Shared.printError('columnList must be a table with 1+ elements')
end
 
local supportedSkills = {
'Smithing',
'Crafting',
'Fletching',
'Runecrafting'
}
if not Shared.contains(supportedSkills, skillName) then
return Shared.printError('The ' .. skillName .. ' skill is not supported by this function')
end


  for i, rune in Shared.skpairs(rcArray) do
-- Validation: Category
    result = result..'\r\n|-'
local category = GameData.getEntityByName(SkillData[skillName].categories, categoryName)
    result = result..'\r\n| style="text-align: left;" | '..Icons.Icon({rune.name, type='item', size='50', notext=true})
if category == nil then
    result = result..'\r\n| style ="text-align: left;" |[['..rune.name..']]'
local catNames = {}
    result = result..'\r\n| style="text-align:right"|'..rune.runecraftingLevel
for i, cat in pairs(SkillData[skillName].categories) do
    result = result..'\r\n| style="text-align:right"|'..rune.runecraftingXP
table.insert(catNames, cat.name)
    result = result..'\r\n| style="text-align:right"|'..rune.sellsFor
end
return Shared.printError('No such category ' .. categoryName .. ' for skill ' .. skillName .. ', the following are available: ' .. table.concat(catNames, ', '))
end
local actionInterval = SkillData[skillName].baseInterval / 1000


    local matArray = {}
-- Validation: Skill data
    for j, mat in Shared.skpairs(rune.runecraftReq) do
local recipeKey = 'recipes'
      local matItem = Items.getItemByID(mat.id)
if SkillData[skillName] == nil then
      table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.qty}))
return Shared.printError('Could not locate skill data for ' .. skillName)
    end
elseif SkillData[skillName][recipeKey] == nil then
    result = result..'\r\n|'..table.concat(matArray, ' ')
return Shared.printError('Could not locate recipe data for ' .. skillName)
end
 
-- Validation: Column list
local columnDef = {
["ItemImage"] = {["header"] = 'Item', ["altRepeat"] = false},
["ItemName"] = {["header"] = 'Name', ["altRepeat"] = true},
["SkillLevel"] = {["header"] = Icons.Icon({skillName, type='skill', notext=true}) .. ' Level', ["altRepeat"] = false},
["SkillXP"] = {["header"] = 'XP', ["altRepeat"] = false},
["GP"] = {["header"] = 'Value', ["altRepeat"] = true},
["Ingredients"] = {["header"] = 'Ingredients', ["altRepeat"] = true},
["SkillXPSec"] = {["header"] = 'XP/s', ["altRepeat"] = false},
["GPSec"] = {["header"] = 'GP/s', ["altRepeat"] = true},
["GPBar"] = {["header"] = 'Value/Bar', ["altRepeat"] = true },
["Description"] = {["header"] = "Description", ["altRepeat"] = true}
}
-- Build the table header while we're here
local resultPart, barIDList = {}, {}
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|- class="headerRow-0"')
for i, colID in ipairs(columnList) do
if columnDef[colID] == nil then
return Shared.printError('Invalid column ' .. colID .. ' requested')
else
table.insert(resultPart, '\r\n! ' .. columnDef[colID].header)
if colID == 'GPBar' then
-- For Smithing, a GP value per bar column is included. If this
-- is requested, then obtain a list of bar item IDs
barIDList = p.getBarItemIDs()
end
end
end
 
-- Determine which recipes to include
local recipeList = GameData.getEntities(SkillData[skillName][recipeKey],
function(recipe)
return category.id == nil or recipe.categoryID == category.id
end)
if Shared.tableIsEmpty(recipeList) then
return ''
end
table.sort(recipeList, function(a, b) return a.level < b.level end)


    local rcCraftTime = 2.00
-- Build rows based on recipes
    local xps = rune.runecraftingXP / rcCraftTime
for i, recipe in ipairs(recipeList) do
    local gps = rune.sellsFor / rcCraftTime
local ns, _ = GameData.getLocalID(recipe.id)
    result = result..'\r\n| style="text-align:right"|'..string.format("%.2f", xps)
local item = Items.getItemByID(recipe.productID)
    result = result..'\r\n| style="text-align:right"|'..string.format("%.2f", gps)
if item ~= nil then
  end
-- Some recipes have alternative costs, so the recipe may require multiple rows
local costList = nil
if recipe.alternativeCosts ~= nil and not Shared.tableIsEmpty(recipe.alternativeCosts) then
costList = recipe.alternativeCosts
else
costList = {{["itemCosts"] = recipe.itemCosts}}
end
local costCount = Shared.tableCount(costList)
-- Build one row per element within costList
for recipeRow, costDef in ipairs(costList) do
local rowspanStr = (recipeRow == 1 and costCount > 1 and 'rowspan="' .. costCount .. '" ') or ''
local qty = (costDef.quantityMultiplier or 1) * (recipe.baseQuantity or 1)
table.insert(resultPart, '\n|-')
for j, colID in ipairs(columnList) do
local altRepeat = columnDef[colID].altRepeat
-- All columns must be generated if this is the very first row for a recipe,
-- for subsequent rows only columns marked as altRepeat = true are generated
if recipeRow == 1 or altRepeat then
local spanStr = (not altRepeat and rowspanStr) or ''
if colID == 'ItemImage' then
table.insert(resultPart, '\n|' .. spanStr .. 'class="table-img"| ' .. Icons.Icon({item.name, type='item', size='50', notext=true}))
elseif colID == "ItemName" then
local namePrefix = spanStr
if qty > 1 then
namePrefix = namePrefix .. 'data-sort-value="' .. item.name .. '"'
end
table.insert(resultPart, '\n|'.. (namePrefix ~= '' and namePrefix .. '| ' or ' ') .. Icons.getExpansionIcon(item.id) .. (qty > 1 and '<b>' .. qty .. 'x</b> ' or '') .. Icons.Icon({item.name, type='item', noicon=true}))
elseif colID == 'SkillLevel' then
table.insert(resultPart, '\n|' .. spanStr .. 'style="text-align:right"| ' .. recipe.level)
elseif colID == 'SkillXP' then
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. recipe.baseExperience ..'" style="text-align:right"| ' .. Shared.formatnum(recipe.baseExperience))
elseif colID == 'GP' then
local val = math.floor(item.sellsFor)
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. (val * qty) .. '"| ' .. Icons.GP(val) .. (qty > 1 and ' (x' .. qty .. ')' or ''))
elseif colID == 'Ingredients' then
local matArray = {}
for k, mat in ipairs(costDef.itemCosts) do
local matItem = Items.getItemByID(mat.id)
if matItem ~= nil then
table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.quantity}))
end
end
if recipe.gpCost ~= nil and recipe.gpCost > 0 then
table.insert(matArray, Icons.GP(recipe.gpCost))
end
if recipe.scCost ~= nil and recipe.scCost > 0 then
table.insert(matArray, Icons.SC(recipe.scCost))
end
table.insert(resultPart, '\n|' .. (spanStr ~= '' and spanStr .. '| ' or ' ') .. table.concat(matArray, ', '))
elseif colID == 'SkillXPSec' then
table.insert(resultPart, '\n|' .. spanStr .. 'style="text-align:right"| ' .. string.format('%.2f', recipe.baseExperience / actionInterval))
elseif colID == 'GPSec' then
local val = math.floor(item.sellsFor) * qty / actionInterval
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. val .. '"| ' .. Icons.GP(string.format('%.2f', val)))
elseif colID == 'GPBar' then
local barQty = 0
for k, mat in ipairs(costDef.itemCosts) do
if Shared.contains(barIDList, mat.id) then
barQty = barQty + mat.quantity
end
end
if barQty > 0 then
local barVal = Shared.round(math.floor(item.sellsFor) * qty / barQty, 1, 1)
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. barVal .. '"| ' .. Icons.GP(barVal))
else
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="0" class="table-na"| N/A')
end
elseif colID == 'Description' then
local descrip = Items._getItemStat(item, 'description')
if descrip == 'No Description' and item.modifiers ~= nil and not Shared.tableIsEmpty(item.modifiers) then
descrip = Constants.getModifiersText(item.modifiers, false)
end
table.insert(resultPart, '\n| '..spanStr..'|'..descrip)
else
table.insert(resultPart, '\n| ')
end
end
end
end
end
end
table.insert(resultPart, '\n|}')
return table.concat(resultPart)
end


  result = result..'\r\n|}'
function p.getBarItemIDs()
  return result
local barIDList = {}
for i, recipe in ipairs(SkillData.Smithing.recipes) do
if recipe.categoryID == 'melvorD:Bars' then
table.insert(barIDList, recipe.productID)
end
end
return barIDList
end
end


return p
return p

Latest revision as of 22:27, 26 March 2024

Documentation for this module may be created at Module:Skills/Artisan/doc

--Splitting some functions into here to avoid bloating a single file
--Contains function for skills that consume resources (ie smithing, cooking, herblore, etc.)
local p = {}

local Shared = require('Module:Shared')
local Constants = require('Module:Constants')
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local ItemSourceTables = require('Module:Items/SourceTables')

function p.getCookedItemsTable(frame)
	local category = frame.args ~= nil and frame.args[1] or frame
	local categoryMap = {
		["Cooking Fire"] = 'melvorD:Fire',
		["Furnace"] = 'melvorD:Furnace',
		["Pot"] = 'melvorD:Pot'
	}
	local categoryID = categoryMap[category]

	-- Find recipes for the relevant categories
	-- Note: Excludes Lemon cake
	local recipeArray = GameData.getEntities(SkillData.Cooking.recipes,
		function(recipe)
			return (categoryID == nil or recipe.categoryID == categoryID) and recipe.noMastery == nil
		end)
	table.sort(recipeArray, function(a, b) return a.level < b.level end)

	-- Logic for generating some cells of the table which are consistent for normal & perfect items
	local getHealingCell = function(item, qty)
		if item ~= nil then
			return 'data-sort-value="'..(math.floor(item.healsFor) * qty)..'"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..math.floor(item.healsFor * 10)..(qty > 1 and ' (x'..qty..')' or '')
		else
			return ' '
		end
	end
	local getSaleValueCell = function(item, qty)
		if item ~= nil then
			return 'data-sort-value="'..math.floor(item.sellsFor * qty)..'"|'..Icons.GP(math.floor(item.sellsFor))..(qty > 1 and ' (x'..qty..')' or '')
		else
			return ' '
		end
	end

	local resultPart = {}
	table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
	table.insert(resultPart, '\r\n|- class="headerRow-0"')
	table.insert(resultPart, '\r\n!colspan="3" rowspan="2"|Cooked Item!!rowspan="2"|'..Icons.Icon({'Cooking', type='skill', notext=true})..' Level')
	table.insert(resultPart, '!!rowspan="2"|Cook Time (s)!!rowspan="2"|XP!!rowspan="2"|XP/s!!colspan="2"|Healing!!colspan="2"|Value!!rowspan="2"|Ingredients')
	table.insert(resultPart, '\r\n|- class="headerRow-1"')
	table.insert(resultPart, '\r\n!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
	table.insert(resultPart, '!!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))

	for i, recipe in ipairs(recipeArray) do
		local item = Items.getItemByID(recipe.productID)
		local perfectItem = nil
		if recipe.perfectCookID ~= nil then
			perfectItem = Items.getItemByID(recipe.perfectCookID)
		end
		local qty = recipe.baseQuantity or 1

		table.insert(resultPart, '\r\n|-')
		table.insert(resultPart, '\r\n|class="table-img"|'..Icons.Icon({item.name, type='item', notext=true, size='50'}))
		table.insert(resultPart, '\r\n|class="table-img"| ')
		if perfectItem ~= nil then
			table.insert(resultPart, Icons.Icon({perfectItem.name, type='item', notext=true, size='50'}))
		end
		table.insert(resultPart, '||')
		if qty > 1 then
			table.insert(resultPart, qty..'x ')
		end
		table.insert(resultPart, Icons.getExpansionIcon(item.id))
		table.insert(resultPart, Icons.Icon({item.name, type='item', noicon = true}))
		table.insert(resultPart, '||style="text-align:right"|' .. recipe.level)
		table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseInterval .. '"|' .. Shared.round(recipe.baseInterval / 1000, 2, 0))
		table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseExperience .. '"|' .. Shared.formatnum(recipe.baseExperience))
		local xpRate = recipe.baseExperience / (recipe.baseInterval / 1000)
		table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. xpRate .. '"|' .. Shared.round(xpRate, 2, 0))
		table.insert(resultPart, '||'..getHealingCell(item, qty)..'||'..getHealingCell(perfectItem, qty))
		table.insert(resultPart, '||'..getSaleValueCell(item, qty)..'||'..getSaleValueCell(perfectItem, qty))
		local matArray = {}
		for j, mat in ipairs(recipe.itemCosts) do
			local matItem = Items.getItemByID(mat.id)
			if matItem ~= nil then
				table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.quantity}))
			end
		end
		table.insert(resultPart, '\r\n|'..table.concat(matArray, ' '))
	end

	table.insert(resultPart, '\r\n|}')
	return table.concat(resultPart)
end

local tierSuffix = { 'I', 'II', 'III', 'IV' }
function p._getPotionDescription(potion)
	-- TODO: Temporary fix below for incorrect Traps Potion descriptions. To amend
	-- once corrected within game data
	if potion.customDescription and not Shared.contains(potion.id, 'melvorTotH:Traps_Potion_') then
		return potion.customDescription
	elseif type(potion.modifiers) == 'table' and not Shared.tableIsEmpty(potion.modifiers) then
		return Constants.getModifiersText(potion.modifiers, false, true)
	else
		return ''
	end
end

function p._getHerblorePotionTable(categoryName)
	local categoryID = nil
	if string.upper(categoryName) == 'COMBAT' then
		categoryID = 'melvorF:CombatPotions'
	elseif string.upper(categoryName) == 'SKILL' then
		categoryID = 'melvorF:SkillPotions'
	else
		return Shared.printError('No such potion category ' .. (categoryName or 'nil'))
	end

	local potionArray = GameData.getEntities(SkillData.Herblore.recipes, function(potion) return potion.categoryID == categoryID end)
	table.sort(potionArray, function(a, b) return a.level < b.level end)

	local resultPart = {}
	table.insert(resultPart, '{|class="wikitable sortable stickyHeader"')
	table.insert(resultPart, '\r\n|- class="headerRow-0"')
	table.insert(resultPart, '\r\n!Potion!!'..Icons.Icon({'Herblore', type='skill', notext=true})..' Level')
	table.insert(resultPart, '!!XP!!Ingredients!!style="width:30px;"|Tier!!Value!!Charges!!Effect')

	for i, potion in ipairs(potionArray) do
		table.insert(resultPart, '\r\n|-')
		local expIcon = Icons.getExpansionIcon(potion.potionIDs[1])
		table.insert(resultPart, '\r\n|rowspan="4"|'..expIcon..'[['..potion.name..']]')
		table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.level)
		table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.baseExperience)

		local matArray = {}
		for j, mat in ipairs(potion.itemCosts) do
			local matItem = Items.getItemByID(mat.id)
			table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.quantity}))
		end
		table.insert(resultPart, '||rowspan="4"|'..table.concat(matArray, ', ')..'||')

		local tierRows = {}
		for j, potionID in ipairs(potion.potionIDs) do
			local rowTxt = {}
			local tierPot = Items.getItemByID(potionID)
			table.insert(rowTxt, Icons.Icon({tierPot.name, type='item', notext=true}))
			table.insert(rowTxt, Icons.Icon({tierPot.name, tierSuffix[j], type = 'item', noicon=true}))
			table.insert(rowTxt, '||style="text-align:right;" data-sort-value="'..tierPot.sellsFor..'"|'..Icons.GP(tierPot.sellsFor))
			table.insert(rowTxt, '||style="text-align:right;"|'..tierPot.charges..'|| '..p._getPotionDescription(tierPot))
			table.insert(tierRows, table.concat(rowTxt))
		end
		table.insert(resultPart, table.concat(tierRows, '\r\n|-\r\n|'))
	end

	table.insert(resultPart, '\r\n|}')
	return table.concat(resultPart)
end

function p.getHerblorePotionTable(frame)
	local category = frame.args ~= nil and frame.args[1] or frame
	return p._getHerblorePotionTable(category)
end

function p._getHerbloreHerbTable(args)
	local allHerbs = {}
	local allPotions = GameData.getEntities(SkillData.Herblore.recipes, function() return true end)
	
	-- Finds the herb from a potion along with the level required to make the potion.
	local function handlePotion(potion)
		local potionCosts = potion.itemCosts
		local level = potion.level
		
		if potionCosts == nil or level == nil then
			return
		end
		
		-- Find if this potion uses a herb, and which herb it is.
		for _, ingredient in pairs(potionCosts) do
			local ingredientID = ingredient.id
			if ingredientID == nil or string.sub(ingredientID, -5) ~= "_Herb" then
				return
			end
			
			-- Set the lowest level of potion this herb is used in.
			local currLevel = allHerbs[ingredientID] or 9999999
			if level < currLevel then
				allHerbs[ingredientID] = level
			end
		end
	end

	for _, potion in pairs(allPotions) do
		handlePotion(potion)
	end
	
	local sortedValues = Shared.sortDictionary(
		allHerbs, 
		function (a, b) return a.value < b.value end)

	local tbl = mw.html.create("table")
        :addClass("wikitable sortable stickyHeader")
        
    -- Add header
    tbl :tag("tr"):addClass("headerRow-0")
    	:tag("th"):wikitext(Icons.Icon({'Herblore', type='skill', notext=true})..' Level')
    	:tag("th"):wikitext("Herb")
    	:tag("th"):wikitext("Value")
    	:tag("th"):wikitext("Herb Sources")
    	:done()
    
    -- Fill wikitable.
    for _, v in pairs(sortedValues) do
    	local herbItem = Items.getItemByID(v['key'])
    	local herbLevel = v['value']
    	local dlcIcon = Icons.getExpansionIcon(herbItem.id)

    	-- Add rows
    	tbl :tag("tr")
    		:tag("td"):wikitext(herbLevel)
    		:tag("td"):wikitext(dlcIcon .. Icons.Icon({herbItem.name, type='item'}))
    		:tag("td"):wikitext(Icons.GP(herbItem.sellsFor))
    		:tag('td'):wikitext(ItemSourceTables._getItemSources(herbItem, false, nil, ' '))
    		:done()
    end

	return tostring(tbl)
end

function p.getHerbloreHerbTable(frame)
	local args = frame:getParent().args
	return p._getHerbloreHerbTable(args)
end

function p.getPotionTable(frame)
	local potionName = frame.args ~= nil and frame.args[1] or frame

	local recipe = GameData.getEntityByName(SkillData.Herblore.recipes, potionName)
	if recipe == nil then
		return Shared.printError('No potion named "' .. potionName .. '" was found')
	end

	local resultPart = {}
	table.insert(resultPart, '{| class="wikitable"')
	table.insert(resultPart, '\r\n!colspan=4|[['..potionName..']]')
	table.insert(resultPart, '\r\n|-\r\n!Potion!!Tier!!Charges!!Effect')

	for i, potionID in ipairs(recipe.potionIDs) do
		local tier = tierSuffix[i]
		local potion = Items.getItemByID(potionID)
		if potion ~= nil then
			table.insert(resultPart, '\r\n|-')
			table.insert(resultPart, '\r\n| ' .. Icons.Icon({potion.name, type='item', notext=true, size='60'}))
			table.insert(resultPart, '|| ' .. Icons.getExpansionIcon(potion.id) .. Icons.Icon({potion.name, tier, type='item', noicon=true}))
			table.insert(resultPart, '|| ' .. potion.charges .. '|| ' .. p._getPotionDescription(potion))
		end
	end

	table.insert(resultPart, '\r\n|}')
	return table.concat(resultPart)
end

function p.getRunecraftingTable(frame)
	local category = frame.args ~= nil and frame.args[1] or frame
	return p._getRecipeTable('Runecrafting', category, {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients', 'SkillXPSec', 'GPSec'})
end

function p.getFletchingTable(frame)
	local category = frame.args ~= nil and frame.args[1] or frame
	return p._getRecipeTable('Fletching', category, {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients'})
end

function p.getCraftingTable(frame)
	local category = frame.args ~= nil and frame.args[1] or frame
	local columns = {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients'}
	if category == 'Rings' or category == 'Necklaces' then
		table.insert(columns, "Description")
	end
	return p._getRecipeTable('Crafting', category, columns)
end

function p.getSmithingTable(frame)
	local category = frame.args ~= nil and frame.args[1] or frame
	local columns = {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'GP', 'Ingredients'}
	if category ~= 'Bars' then
		table.insert(columns, 'GPBar')
	end
	return p._getRecipeTable('Smithing', category, columns)
end

-- Given a skill name, category, and column list, produces a table of recipes for that
-- skill & category combination. If categoryName is '', all recipes are returned.
-- Note: This only supports a number of skills with consistent recipe data structures, being:
-- Fletching, Crafting, and Runecrafting
-- Valid column list options are: Item, SkillLevel, SkillXP, GP, Ingredients, SkillXPSec, GPSec
function p._getRecipeTable(skillName, categoryName, columnList)
	-- Validation: Parameters
	if type(skillName) ~= 'string' then
		return Shared.printError('skillName must be a string')
	elseif not Shared.contains({'string', 'nil'}, type(categoryName)) then
		return Shared.printError('category must be a string or nil')
	elseif type(columnList) ~= 'table' or Shared.tableIsEmpty(columnList) then
		return Shared.printError('columnList must be a table with 1+ elements')
	end

	local supportedSkills = {
		'Smithing',
		'Crafting',
		'Fletching',
		'Runecrafting'
	}
	if not Shared.contains(supportedSkills, skillName) then
		return Shared.printError('The ' .. skillName .. ' skill is not supported by this function')
	end

	-- Validation: Category
	local category = GameData.getEntityByName(SkillData[skillName].categories, categoryName)
	if category == nil then
		local catNames = {}
		for i, cat in pairs(SkillData[skillName].categories) do
			table.insert(catNames, cat.name)
		end
		return Shared.printError('No such category ' .. categoryName .. ' for skill ' .. skillName .. ', the following are available: ' .. table.concat(catNames, ', '))
	end
	local actionInterval = SkillData[skillName].baseInterval / 1000

	-- Validation: Skill data
	local recipeKey = 'recipes'
	if SkillData[skillName] == nil then
		return Shared.printError('Could not locate skill data for ' .. skillName)
	elseif SkillData[skillName][recipeKey] == nil then
		return Shared.printError('Could not locate recipe data for ' .. skillName)
	end

	-- Validation: Column list
	local columnDef = {
		["ItemImage"] = {["header"] = 'Item', ["altRepeat"] = false},
		["ItemName"] = {["header"] = 'Name', ["altRepeat"] = true},
		["SkillLevel"] = {["header"] = Icons.Icon({skillName, type='skill', notext=true}) .. ' Level', ["altRepeat"] = false},
		["SkillXP"] = {["header"] = 'XP', ["altRepeat"] = false},
		["GP"] = {["header"] = 'Value', ["altRepeat"] = true},
		["Ingredients"] = {["header"] = 'Ingredients', ["altRepeat"] = true},
		["SkillXPSec"] = {["header"] = 'XP/s', ["altRepeat"] = false},
		["GPSec"] = {["header"] = 'GP/s', ["altRepeat"] = true},
		["GPBar"] = {["header"] = 'Value/Bar', ["altRepeat"] = true },
		["Description"] = {["header"] = "Description", ["altRepeat"] = true}
	}
	-- Build the table header while we're here
	local resultPart, barIDList = {}, {}
	table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|- class="headerRow-0"')
	for i, colID in ipairs(columnList) do
		if columnDef[colID] == nil then
			return Shared.printError('Invalid column ' .. colID .. ' requested')
		else
			table.insert(resultPart, '\r\n! ' .. columnDef[colID].header)
			if colID == 'GPBar' then
				-- For Smithing, a GP value per bar column is included. If this
				-- is requested, then obtain a list of bar item IDs
				barIDList = p.getBarItemIDs()
			end
		end
	end

	-- Determine which recipes to include
	local recipeList = GameData.getEntities(SkillData[skillName][recipeKey],
		function(recipe)
			return category.id == nil or recipe.categoryID == category.id
		end)
	if Shared.tableIsEmpty(recipeList) then
		return ''
	end
	table.sort(recipeList, function(a, b) return a.level < b.level end)

	-- Build rows based on recipes
	for i, recipe in ipairs(recipeList) do
		local ns, _ = GameData.getLocalID(recipe.id)
		local item = Items.getItemByID(recipe.productID)
		if item ~= nil then
			-- Some recipes have alternative costs, so the recipe may require multiple rows
			local costList = nil
			if recipe.alternativeCosts ~= nil and not Shared.tableIsEmpty(recipe.alternativeCosts) then
				costList = recipe.alternativeCosts
			else
				costList = {{["itemCosts"] = recipe.itemCosts}}
			end
			local costCount = Shared.tableCount(costList)
			-- Build one row per element within costList
			for recipeRow, costDef in ipairs(costList) do
				local rowspanStr = (recipeRow == 1 and costCount > 1 and 'rowspan="' .. costCount .. '" ') or ''
				local qty = (costDef.quantityMultiplier or 1) * (recipe.baseQuantity or 1)
				table.insert(resultPart, '\n|-')
				for j, colID in ipairs(columnList) do
					local altRepeat = columnDef[colID].altRepeat
					-- All columns must be generated if this is the very first row for a recipe,
					-- for subsequent rows only columns marked as altRepeat = true are generated
					if recipeRow == 1 or altRepeat then
						local spanStr = (not altRepeat and rowspanStr) or ''
						if colID == 'ItemImage' then
							table.insert(resultPart, '\n|' .. spanStr .. 'class="table-img"| ' .. Icons.Icon({item.name, type='item', size='50', notext=true}))
						elseif colID == "ItemName" then
							local namePrefix = spanStr
							if qty > 1 then
								namePrefix = namePrefix .. 'data-sort-value="' .. item.name .. '"'
							end
							table.insert(resultPart, '\n|'.. (namePrefix ~= '' and namePrefix .. '| ' or ' ') .. Icons.getExpansionIcon(item.id) .. (qty > 1 and '<b>' .. qty .. 'x</b> ' or '') .. Icons.Icon({item.name, type='item', noicon=true}))
						elseif colID == 'SkillLevel' then
							table.insert(resultPart, '\n|' .. spanStr .. 'style="text-align:right"| ' .. recipe.level)
						elseif colID == 'SkillXP' then
							table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. recipe.baseExperience ..'" style="text-align:right"| ' .. Shared.formatnum(recipe.baseExperience))
						elseif colID == 'GP' then
							local val = math.floor(item.sellsFor)
							table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. (val * qty) .. '"| ' .. Icons.GP(val) .. (qty > 1 and ' (x' .. qty .. ')' or ''))
						elseif colID == 'Ingredients' then
							local matArray = {}
							for k, mat in ipairs(costDef.itemCosts) do
								local matItem = Items.getItemByID(mat.id)
								if matItem ~= nil then
									table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.quantity}))
								end
							end
							if recipe.gpCost ~= nil and recipe.gpCost > 0 then
								table.insert(matArray, Icons.GP(recipe.gpCost))
							end
							if recipe.scCost ~= nil and recipe.scCost > 0 then
								table.insert(matArray, Icons.SC(recipe.scCost))
							end
							table.insert(resultPart, '\n|' .. (spanStr ~= '' and spanStr .. '| ' or ' ') .. table.concat(matArray, ', '))
						elseif colID == 'SkillXPSec' then
							table.insert(resultPart, '\n|' .. spanStr .. 'style="text-align:right"| ' .. string.format('%.2f', recipe.baseExperience / actionInterval))
						elseif colID == 'GPSec' then
							local val = math.floor(item.sellsFor) * qty / actionInterval
							table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. val .. '"| ' .. Icons.GP(string.format('%.2f', val)))
						elseif colID == 'GPBar' then
							local barQty = 0
							for k, mat in ipairs(costDef.itemCosts) do
								if Shared.contains(barIDList, mat.id) then
									barQty = barQty + mat.quantity
								end
							end
							if barQty > 0 then
								local barVal = Shared.round(math.floor(item.sellsFor) * qty / barQty, 1, 1)
								table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. barVal .. '"| ' .. Icons.GP(barVal))
							else
								table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="0" class="table-na"| N/A')
							end
						elseif colID == 'Description' then
							local descrip = Items._getItemStat(item, 'description')
							if descrip == 'No Description' and item.modifiers ~= nil and not Shared.tableIsEmpty(item.modifiers) then
								descrip = Constants.getModifiersText(item.modifiers, false)
							end
							table.insert(resultPart, '\n| '..spanStr..'|'..descrip)
						else
							table.insert(resultPart, '\n| ')
						end
					end
				end
			end
		end
	end
	table.insert(resultPart, '\n|}')
	return table.concat(resultPart)
end

function p.getBarItemIDs()
	local barIDList = {}
	for i, recipe in ipairs(SkillData.Smithing.recipes) do
		if recipe.categoryID == 'melvorD:Bars' then
			table.insert(barIDList, recipe.productID)
		end
	end
	return barIDList
end

return p