Module:Skills/Artisan: Difference between revisions

no edit summary
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 args = frame.args ~= nil and frame.args or frame
local category = args[1]
    local category = args[1]
local realmName = args.realm
    local realmName = args.realm
local realm = Skills.getRealmFromName(realmName)
    local realm = Skills.getRealmFromName(realmName)
if realm == nil then
    if realm == nil then
return Shared.printError('Failed to find a realm with name ' .. (realmName or 'nil'))
        return Shared.printError('Failed to find a realm with name ' .. (realmName or 'nil'))
end
    end
local skillID = 'Cooking'
    local skillID = 'Cooking'


local categoryMap = {
    local categoryMap = {
["Cooking Fire"] = 'melvorD:Fire',
        ["Cooking Fire"] = 'melvorD:Fire',
["Furnace"] = 'melvorD:Furnace',
        ["Furnace"] = 'melvorD:Furnace',
["Pot"] = 'melvorD:Pot'
        ["Pot"] = 'melvorD:Pot'
}
    }
local categoryID = categoryMap[category]
    local categoryID = categoryMap[category]


-- Find recipes for the relevant categories
    -- Find recipes for the relevant categories
-- Note: Excludes Lemon cake
    -- Note: Excludes Lemon cake
local recipeArray = GameData.getEntities(SkillData.Cooking.recipes,
    local recipeArray = GameData.getEntities(SkillData.Cooking.recipes,
function(recipe)
        function(recipe)
return (
            return (
(categoryID == nil or recipe.categoryID == categoryID)
                (categoryID == nil or recipe.categoryID == categoryID)
and recipe.noMastery == nil
                and recipe.noMastery == nil
and Skills.getRecipeRealm(recipe) == realm.id
                and Skills.getRecipeRealm(recipe) == realm.id
)
            )
end
        end
)
    )
table.sort(recipeArray, function(a, b) return Skills.standardRecipeSort(skillID, a, b) 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
    -- Logic for generating some cells of the table which are consistent for normal & perfect items
local getHealingCell = function(item, qty)
    local getHealingCell = function(item, qty)
if item ~= nil then
        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 '')
            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
        else
return ' '
            return ' '
end
        end
end
    end
local getSaleValueCell = function(item, qty)
    local getSaleValueCell = function(item, qty)
if item ~= nil then
        if item ~= nil then
return 'data-sort-value="'..math.floor(item.sellsFor * qty)..'"|'..Items.getValueText(item)..(qty > 1 and ' (x'..qty..')' or '')
            return 'data-sort-value="'..math.floor(item.sellsFor * qty)..'"|'..Items.getValueText(item)..(qty > 1 and ' (x'..qty..')' or '')
else
        else
return ' '
            return ' '
end
        end
end
    end


local resultPart = {}
    local tableHtml = mw.html.create('table')
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
        :addClass('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')
    local headerRow0 = tableHtml:tag('tr'):addClass('headerRow-0')
table.insert(resultPart, '!!rowspan="2"|Cook Time (s)!!rowspan="2"|XP!!rowspan="2"|XP/s!!colspan="2"|Healing!!colspan="2"|Value!!rowspan="2"|Ingredients')
    headerRow0:tag('th'):attr('colspan', '3')
table.insert(resultPart, '\r\n|- class="headerRow-1"')
                        :attr('rowspan', '2')
table.insert(resultPart, '\r\n!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
                        :wikitext('Cooked Item')
table.insert(resultPart, '!!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
    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')


for i, recipe in ipairs(recipeArray) do
    local headerRow1 = tableHtml:tag('tr'):addClass('headerRow-1')
local level = Skills.getRecipeLevel(skillID, recipe)
    headerRow1:tag('th'):wikitext('Normal')
local baseXP = recipe.baseAbyssalExperience or recipe.baseExperience
    headerRow1:tag('th'):wikitext(Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
local baseInt = recipe.baseInterval / 1000
    headerRow1:tag('th'):wikitext('Normal')
local reqText = Skills.getRecipeRequirementText(SkillData.Cooking.name, recipe)
    headerRow1:tag('th'):wikitext(Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
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|-')
    for i, recipe in ipairs(recipeArray) do
table.insert(resultPart, '\r\n|class="table-img"|'..Icons.Icon({item.name, type='item', notext=true, size='50'}))
        local level = Skills.getRecipeLevel(skillID, recipe)
table.insert(resultPart, '\r\n|class="table-img"| ')
        local baseXP = recipe.baseAbyssalExperience or recipe.baseExperience
if perfectItem ~= nil then
        local baseInt = recipe.baseInterval / 1000
table.insert(resultPart, Icons.Icon({perfectItem.name, type='item', notext=true, size='50'}))
        local reqText = Skills.getRecipeRequirementText(SkillData.Cooking.name, recipe)
end
        local xpRate = baseXP / baseInt
table.insert(resultPart, '||')
        local item = Items.getItemByID(recipe.productID)
if qty > 1 then
        local perfectItem = nil
table.insert(resultPart, qty..'x ')
        if recipe.perfectCookID ~= nil then
end
            perfectItem = Items.getItemByID(recipe.perfectCookID)
table.insert(resultPart, Icons.getExpansionIcon(item.id))
        end
table.insert(resultPart, Icons.Icon({item.name, type='item', noicon = true}))
        local qty = recipe.baseQuantity or 1
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|}')
        local row = tableHtml:tag('tr')
return table.concat(resultPart)
        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


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
2,875

edits