2,873
edits
No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
local Num = require('Module:Number') | local Num = require('Module:Number') | ||
local tierSuffix = { 'I', 'II', 'III', 'IV' } | |||
function p.getCookedItemsTable(frame) | function p.getCookedItemsTable(frame) | ||
local args = frame.args ~= nil and frame.args or frame | |||
local category = args[1] | |||
local realmName = args.realm | |||
local realm = Skills.getRealmFromName(realmName) | |||
if realm == nil then | |||
return Shared.printError('Failed to find a realm with name ' .. (realmName or 'nil')) | |||
end | |||
local skillID = 'Cooking' | |||
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 | |||
and Skills.getRecipeRealm(recipe) == realm.id | |||
) | |||
end | |||
) | |||
table.sort(recipeArray, function(a, b) return Skills.standardRecipeSort(skillID, a, b) 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})..' '..Num.formatnum(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)..'"|'..Items.getValueText(item)..(qty > 1 and ' (x'..qty..')' or '') | |||
else | |||
return ' ' | |||
end | |||
end | |||
local tableHtml = mw.html.create('table') | |||
:addClass('wikitable sortable stickyHeader') | |||
local headerRow0 = tableHtml:tag('tr'):addClass('headerRow-0') | |||
headerRow0:tag('th'):attr('colspan', '3') | |||
:attr('rowspan', '2') | |||
:wikitext('Cooked Item') | |||
headerRow0:tag('th'):attr('rowspan', '2') | |||
:wikitext('Requirements') | |||
headerRow0:tag('th'):attr('rowspan', '2') | |||
:wikitext('Cook Time (s)') | |||
headerRow0:tag('th'):attr('rowspan', '2') | |||
:wikitext('XP') | |||
headerRow0:tag('th'):attr('rowspan', '2') | |||
:wikitext('XP/s') | |||
headerRow0:tag('th'):attr('colspan', '2') | |||
:wikitext('Healing') | |||
headerRow0:tag('th'):attr('colspan', '2') | |||
:wikitext('Value') | |||
headerRow0:tag('th'):attr('rowspan', '2') | |||
:wikitext('Ingredients') | |||
local headerRow1 = tableHtml:tag('tr'):addClass('headerRow-1') | |||
headerRow1:tag('th'):wikitext('Normal') | |||
headerRow1:tag('th'):wikitext(Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true})) | |||
headerRow1:tag('th'):wikitext('Normal') | |||
headerRow1:tag('th'):wikitext(Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true})) | |||
for i, recipe in ipairs(recipeArray) do | |||
local level = Skills.getRecipeLevel(skillID, recipe) | |||
local baseXP = recipe.baseAbyssalExperience or recipe.baseExperience | |||
local baseInt = recipe.baseInterval / 1000 | |||
local reqText = Skills.getRecipeRequirementText(SkillData.Cooking.name, recipe) | |||
local xpRate = baseXP / baseInt | |||
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 | |||
local row = tableHtml:tag('tr') | |||
row:tag('td'):addClass('table-img') | |||
:wikitext(Icons.Icon({item.name, type='item', notext=true, size='50'})) | |||
row:tag('td'):addClass('table-img') | |||
if perfectItem ~= nil then | |||
row:wikitext(Icons.Icon({perfectItem.name, type='item', notext=true, size='50'})) | |||
end | |||
row:tag('td'):wikitext(qty > 1 and (qty .. 'x ') or '') | |||
row:wikitext(Icons.getExpansionIcon(item.id)) | |||
row:wikitext(Icons.Icon({item.name, type='item', noicon = true})) | |||
row:tag('td'):css('text-align', 'right') | |||
:attr('data-sort-value', level) | |||
:wikitext(reqText) | |||
row:tag('td'):css('text-align', 'right') | |||
:attr('data-sort-value', baseInt) | |||
:wikitext(Num.round(baseInt, 2, 0)) | |||
row:tag('td'):css('text-align', 'right') | |||
:attr('data-sort-value', baseXP) | |||
:wikitext(Num.formatnum(baseXP)) | |||
row:tag('td'):css('text-align', 'right') | |||
:attr('data-sort-value', xpRate) | |||
:wikitext(Num.formatnum(Num.round(xpRate, 2, 0))) | |||
row:tag('td'):wikitext(getHealingCell(item, qty)) | |||
row:tag('td'):wikitext(getHealingCell(perfectItem, qty)) | |||
row:tag('td'):wikitext(getSaleValueCell(item, qty)) | |||
row:tag('td'):wikitext(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 | |||
row:tag('td'):wikitext(table.concat(matArray, ' ')) | |||
end | |||
return tostring(tableHtml) | |||
end | end | ||
function p._getPotionDescription(potion) | function p._getPotionDescription(potion) | ||
-- TODO: Temporary fix below for incorrect Traps Potion descriptions. To amend | -- TODO: Temporary fix below for incorrect Traps Potion descriptions. To amend |
edits