Module:Skills/Artisan: Difference between revisions

From Melvor Idle
(Created page with p.getCookedItemsTable)
 
(Created getHerblorePotionTable)
Line 32: Line 32:
   result = result..'\r\n|}'
   result = result..'\r\n|}'
   return result
   return result
end
local tierSuffix = { 'I', 'II', 'III', 'IV' }
function p._getHerblorePotionTable(category)
  if string.upper(category) == 'COMBAT' then
    category = 0
  elseif string.upper(category) == 'SKILL' then
    category = 1
  elseif type(category) == 'string' then
    category = tonumber(category)
  end
  local potionArray = {}
  for i, potion in Shared.skpairs(SkillData.Herblore.ItemData) do
    if potion.category == category then
      table.insert(potionArray, potion)
    end
  end
  local result = '{|class = "wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!Potion!!'..Icons.Icon({'Herblore', type='skill', notext=true})..' Level'
  result = result..'!!XP!!Ingredients!!colspan="2"|Tier!!Value!!Charges!!Effect'
  table.sort(potionArray, function(a, b) return a.herbloreLevel < b.herbloreLevel end)
  for i, potion in Shared.skpairs(potionArray) do
    local tierPots = {}
    for j = 1, 4, 1 do
      table.insert(tierPots, Items.getItemByID(potion.itemID[j]))
    end
    result = result..'\r\n|-'
    result = result..'\r\n|rowspan="4"|[['..potion.name..']]'
    result = result..'||rowspan="4" style="text-align:right"|'..potion.herbloreLevel
    result = result..'||rowspan="4" style="text-align:right"|'..potion.herbloreXP
    local matArray = {}
    for j, mat in Shared.skpairs(tierPots[1].herbloreReq) do
      local matItem = Items.getItemByID(mat.id)
      table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.qty}))
    end
    result = result..'||rowspan="4"|'..table.concat(matArray, ', ')..'||'
   
    local tierRows = {}
    for j, tierPot in Shared.skpairs(tierPots) do
      local rowTxt = Icons.Icon({tierPot.name, type='item', notext=true})
      rowTxt = rowTxt..'||[['..tierPot.name..'|'..tierSuffix[j]..']]'
      rowTxt = rowTxt..'||style="text-align:right;" data-sort-value="'..tierPot.sellsFor..'"|'..Icons.GP(tierPot.sellsFor)
      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|}'
  return result
end
function p.getHerblorePotionTable(frame)
  local category = frame.args ~= nil and frame.args[1] or frame
  return p._getHerblorePotionTable(category)
end
end


return p
return p

Revision as of 14:41, 18 March 2021

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 SkillData = mw.loadData('Module:Skills/data')
local Constants = mw.loadData('Module:Constants/data')

local Shared = require('Module:Shared')
local Items = require('Module:Items')
local Icons = require('Module:Icons')

function p.getCookedItemsTable(frame)
  local result = '{| class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan="2"|Cooked Item!!'..Icons.Icon({'Cooking', type='skill', notext=true})..' Level'
  result = result..'!!XP!!Healing!!Value!!Ingredients'

  local itemArray = Items.getItems(function(item) return item.cookingID ~= nil end)
  table.sort(itemArray, function(a, b) return a.cookingLevel < b.cookingLevel end)

  for i, item in Shared.skpairs(itemArray) do
    local cookedItem = Items.getItemByID(item.cookedItemID)
    result = result..'\r\n|-'
    result = result..'\r\n|'..Icons.Icon({cookedItem.name, type='item', notext='true', size='50'})..'||[['..cookedItem.name..']]'
    result = result..'||style="text-align:right"|'..item.cookingLevel
    result = result..'||style="text-align:right"|'..item.cookingXP
    result = result..'||style="text-align:right" data-sort-value="'..cookedItem.healsFor..'"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..(cookedItem.healsFor * 10)
    result = result..'||style="text-align:right" data-sort-value="'..cookedItem.sellsFor..'"|'..Icons.GP(cookedItem.sellsFor)
    result = result..'||'..Icons.Icon({item.name, type='item', qty = 1})
  end

  result = result..'\r\n|}'
  return result
end

local tierSuffix = { 'I', 'II', 'III', 'IV' }
function p._getHerblorePotionTable(category)
  if string.upper(category) == 'COMBAT' then
    category = 0
  elseif string.upper(category) == 'SKILL' then
    category = 1
  elseif type(category) == 'string' then
    category = tonumber(category)
  end

  local potionArray = {}
  for i, potion in Shared.skpairs(SkillData.Herblore.ItemData) do
    if potion.category == category then
      table.insert(potionArray, potion)
    end
  end

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

  table.sort(potionArray, function(a, b) return a.herbloreLevel < b.herbloreLevel end)

  for i, potion in Shared.skpairs(potionArray) do
    local tierPots = {}
    for j = 1, 4, 1 do
      table.insert(tierPots, Items.getItemByID(potion.itemID[j]))
    end
    result = result..'\r\n|-'
    result = result..'\r\n|rowspan="4"|[['..potion.name..']]'
    result = result..'||rowspan="4" style="text-align:right"|'..potion.herbloreLevel
    result = result..'||rowspan="4" style="text-align:right"|'..potion.herbloreXP

    local matArray = {}
    for j, mat in Shared.skpairs(tierPots[1].herbloreReq) do
      local matItem = Items.getItemByID(mat.id)
      table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.qty}))
    end
    result = result..'||rowspan="4"|'..table.concat(matArray, ', ')..'||'
    
    local tierRows = {}
    for j, tierPot in Shared.skpairs(tierPots) do
      local rowTxt = Icons.Icon({tierPot.name, type='item', notext=true})
      rowTxt = rowTxt..'||[['..tierPot.name..'|'..tierSuffix[j]..']]'
      rowTxt = rowTxt..'||style="text-align:right;" data-sort-value="'..tierPot.sellsFor..'"|'..Icons.GP(tierPot.sellsFor)
      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|}'
  return result
end

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

return p