2,877
edits
No edit summary |
Tag: Undo |
||
Line 14: | Line 14: | ||
local Num = require('Module:Number') | local Num = require('Module:Number') | ||
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 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"|Requirements') | |||
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 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 | |||
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" data-sort-value="' .. level .. '"|' .. reqText) | |||
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. baseInt .. '"|' .. Num.round(baseInt, 2, 0)) | |||
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. baseXP .. '"|' .. Num.formatnum(baseXP)) | |||
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. xpRate .. '"|' .. Num.formatnum(Num.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 | end | ||
local tierSuffix = { 'I', 'II', 'III', 'IV' } | |||
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