Module:Skills/Artisan: Difference between revisions

updated getCookedItemsTable
(Get runecrafting data from Items directly)
(updated getCookedItemsTable)
Line 12: Line 12:


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 itemArray = nil
  result = result..'\r\n!colspan="2"|Cooked Item!!'..Icons.Icon({'Cooking', type='skill', notext=true})..' Level'
  result = result..'!!XP!!Healing!!Value!!Ingredients'
if category == "Cooking Fire" then
itemArray = Items.getItems(function(item) return item.cookingCategory == 0 end)
elseif category == "Furnace" then
itemArray = Items.getItems(function(item) return item.cookingCategory == 1 end)
elseif category == "Pot"  then
itemArray = Items.getItems(function(item) return item.cookingCategory == 2 end)
else
itemArray = Items.getItems(function(item) return item.cookingCategory ~= nil end)
end
table.sort(itemArray, function(a, b) return a.cookingLevel < b.cookingLevel end)
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)
for i, item in Shared.skpairs(itemArray) do
  table.sort(itemArray, function(a, b) return a.cookingLevel < b.cookingLevel end)
local qty = item.cookingQty
if qty == nil then
qty = 1
end
result = result..'\r\n|-'
result = result..'\r\n|style="min-width:25px"|'..Icons.Icon({item.name, type='item', notext='true', size='50'})
result = result..'||'
if qty > 1 then
result = result..qty..'x '
end
result = result..'[['..item.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="'..item.healsFor..'"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..(item.healsFor * 10)
result = result..'||style="text-align:right" data-sort-value="'..(item.sellsFor * qty)..'"|'..Icons.GP(item.sellsFor)
if qty > 1 then
result = result..' (x'..qty..')'
end
    local matArray = {}
    for j, reqSet in pairs(item.recipeRequirements)  do
    for k, mat in pairs(reqSet) do
local matItem = Items.getItemByID(mat.id)
table.insert(matArray, Icons.Icon({matItem.name, type='item', notext=true, qty=mat.qty}))
    end
end
    result = result..'\r\n|'..table.concat(matArray, ' ')
end


  for i, item in Shared.skpairs(itemArray) do
result = result..'\r\n|}'
    local cookedItem = Items.getItemByID(item.cookedItemID)
return result
    result = result..'\r\n|-'
    result = result..'\r\n|style="min-width:25px"|'..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
end


Line 202: Line 231:
   local data = nil
   local data = nil


   if    category == "Arrows"    then data =  
   if    category == "Arrows"    then  
        Items.getItems(function(item) return item.fletchingCategory == 0 end)
  data = Items.getItems(function(item) return item.fletchingCategory == 0 end)
   elseif category == "Shortbows" then data =  
   elseif category == "Shortbows" then  
        Items.getItems(function(item) return item.fletchingCategory == 1 end)
  data = Items.getItems(function(item) return item.fletchingCategory == 1 end)
   elseif category == "Longbows"  then data =  
   elseif category == "Longbows"  then  
        Items.getItems(function(item) return item.fletchingCategory == 2 end)
  data = Items.getItems(function(item) return item.fletchingCategory == 2 end)
   elseif category == "Bolts"    then data =  
   elseif category == "Bolts"    then  
        Items.getItems(function(item) return item.fletchingCategory == 3 end)
  data = Items.getItems(function(item) return item.fletchingCategory == 3 end)
   elseif category == "Crossbows" then data =  
   elseif category == "Crossbows" then  
        Items.getItems(function(item) return item.fletchingCategory == 4 end)
  data = Items.getItems(function(item) return item.fletchingCategory == 4 end)
   elseif category == "Javelins"  then data =  
   elseif category == "Javelins"  then  
        Items.getItems(function(item) return item.fletchingCategory == 5 end)
  data = Items.getItems(function(item) return item.fletchingCategory == 5 end)
   end
   end