Module:Skills/Artisan: Difference between revisions

m
Add space for separator for herb itemsources
(Use classes rather than styles where possible)
m (Add space for separator for herb itemsources)
 
(4 intermediate revisions by 2 users not shown)
Line 9: Line 9:
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local ItemSourceTables = require('Module:Items/SourceTables')


function p.getCookedItemsTable(frame)
function p.getCookedItemsTable(frame)
Line 47: Line 48:
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n!colspan="3" rowspan="2"|Cooked Item!!rowspan="2"|'..Icons.Icon({'Cooking', type='skill', notext=true})..' Level')
table.insert(resultPart, '\r\n!colspan="3" rowspan="2"|Cooked Item!!rowspan="2"|'..Icons.Icon({'Cooking', type='skill', notext=true})..' Level')
table.insert(resultPart, '!!rowspan="2"|Cook Time!!rowspan="2"|XP!!rowspan="2"|XP/s!!colspan="2"|Healing!!colspan="2"|Value!!rowspan="2"|Ingredients')
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|- class="headerRow-1"')
table.insert(resultPart, '\r\n!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
table.insert(resultPart, '\r\n!Normal!!' .. Icons.Icon({'Perfect', type='bonus', ext='png', notext=true, nolink=true}))
Line 73: Line 74:
table.insert(resultPart, Icons.Icon({item.name, type='item', noicon = true}))
table.insert(resultPart, Icons.Icon({item.name, type='item', noicon = true}))
table.insert(resultPart, '||style="text-align:right"|' .. recipe.level)
table.insert(resultPart, '||style="text-align:right"|' .. recipe.level)
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseInterval .. '"|' .. Shared.timeString(recipe.baseInterval / 1000, true))
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseInterval .. '"|' .. Shared.round(recipe.baseInterval / 1000, 2, 0))
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseExperience .. '"|' .. Shared.formatnum(recipe.baseExperience))
table.insert(resultPart, '||style="text-align:right" data-sort-value="' .. recipe.baseExperience .. '"|' .. Shared.formatnum(recipe.baseExperience))
local xpRate = recipe.baseExperience / (recipe.baseInterval / 1000)
local xpRate = recipe.baseExperience / (recipe.baseInterval / 1000)
Line 94: Line 95:


local tierSuffix = { 'I', 'II', 'III', 'IV' }
local tierSuffix = { 'I', 'II', 'III', 'IV' }
function p._getPotionDescription(potion)
-- TODO: Temporary fix below for incorrect Traps Potion descriptions. To amend
-- once corrected within game data
if potion.customDescription and not Shared.contains(potion.id, 'melvorTotH:Traps_Potion_') then
return potion.customDescription
elseif type(potion.modifiers) == 'table' and not Shared.tableIsEmpty(potion.modifiers) then
return Constants.getModifiersText(potion.modifiers, false, true)
else
return ''
end
end
function p._getHerblorePotionTable(categoryName)
function p._getHerblorePotionTable(categoryName)
local categoryID = nil
local categoryID = nil
Line 116: Line 129:
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|-')
local expIcon = Icons.getExpansionIcon(potion.potionIDs[1])
local expIcon = Icons.getExpansionIcon(potion.potionIDs[1])
if potion.name == 'Bird Nests Potion' then
table.insert(resultPart, '\r\n|rowspan="4"|'..expIcon..'[['..potion.name..']]')
table.insert(resultPart, '\r\n|rowspan="4"|'..expIcon..'[[Bird Nest Potion]]')
else
table.insert(resultPart, '\r\n|rowspan="4"|'..expIcon..'[['..potion.name..']]')
end
table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.level)
table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.level)
table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.baseExperience)
table.insert(resultPart, '||rowspan="4" style="text-align:right"|'..potion.baseExperience)
Line 135: Line 144:
local rowTxt = {}
local rowTxt = {}
local tierPot = Items.getItemByID(potionID)
local tierPot = Items.getItemByID(potionID)
local potDesc = ''
if type(tierPot.modifiers) == 'table' and not Shared.tableIsEmpty(tierPot.modifiers) then
potDesc = Constants.getModifiersText(tierPot.modifiers, false) or ''
end
table.insert(rowTxt, Icons.Icon({tierPot.name, type='item', notext=true}))
table.insert(rowTxt, Icons.Icon({tierPot.name, type='item', notext=true}))
table.insert(rowTxt, Icons.Icon({tierPot.name, tierSuffix[j], type = 'item', noicon=true}))
table.insert(rowTxt, Icons.Icon({tierPot.name, tierSuffix[j], type = 'item', noicon=true}))
table.insert(rowTxt, '||style="text-align:right;" data-sort-value="'..tierPot.sellsFor..'"|'..Icons.GP(tierPot.sellsFor))
table.insert(rowTxt, '||style="text-align:right;" data-sort-value="'..tierPot.sellsFor..'"|'..Icons.GP(tierPot.sellsFor))
table.insert(rowTxt, '||style="text-align:right;"|'..tierPot.charges..'|| '..potDesc)
table.insert(rowTxt, '||style="text-align:right;"|'..tierPot.charges..'|| '..p._getPotionDescription(tierPot))
table.insert(tierRows, table.concat(rowTxt))
table.insert(tierRows, table.concat(rowTxt))
end
end
Line 155: Line 160:
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
return p._getHerblorePotionTable(category)
return p._getHerblorePotionTable(category)
end
function p._getHerbloreHerbTable(args)
local allHerbs = {}
local allPotions = GameData.getEntities(SkillData.Herblore.recipes, function() return true end)
-- Finds the herb from a potion along with the level required to make the potion.
local function handlePotion(potion)
local potionCosts = potion.itemCosts
local level = potion.level
if potionCosts == nil or level == nil then
return
end
-- Find if this potion uses a herb, and which herb it is.
for _, ingredient in pairs(potionCosts) do
local ingredientID = ingredient.id
if ingredientID == nil or string.sub(ingredientID, -5) ~= "_Herb" then
return
end
-- Set the lowest level of potion this herb is used in.
local currLevel = allHerbs[ingredientID] or 9999999
if level < currLevel then
allHerbs[ingredientID] = level
end
end
end
for _, potion in pairs(allPotions) do
handlePotion(potion)
end
local sortedValues = Shared.sortDictionary(
allHerbs,
function (a, b) return a.value < b.value end)
local tbl = mw.html.create("table")
        :addClass("wikitable sortable stickyHeader")
       
    -- Add header
    tbl :tag("tr"):addClass("headerRow-0")
    :tag("th"):wikitext(Icons.Icon({'Herblore', type='skill', notext=true})..' Level')
    :tag("th"):wikitext("Herb")
    :tag("th"):wikitext("Value")
    :tag("th"):wikitext("Herb Sources")
    :done()
   
    -- Fill wikitable.
    for _, v in pairs(sortedValues) do
    local herbItem = Items.getItemByID(v['key'])
    local herbLevel = v['value']
    local dlcIcon = Icons.getExpansionIcon(herbItem.id)
    -- Add rows
    tbl :tag("tr")
    :tag("td"):wikitext(herbLevel)
    :tag("td"):wikitext(dlcIcon .. Icons.Icon({herbItem.name, type='item'}))
    :tag("td"):wikitext(Icons.GP(herbItem.sellsFor))
    :tag('td'):wikitext(ItemSourceTables._getItemSources(herbItem, false, nil, ' '))
    :done()
    end
return tostring(tbl)
end
function p.getHerbloreHerbTable(frame)
local args = frame:getParent().args
return p._getHerbloreHerbTable(args)
end
end


Line 167: Line 242:
local resultPart = {}
local resultPart = {}
table.insert(resultPart, '{| class="wikitable"')
table.insert(resultPart, '{| class="wikitable"')
--The Bird Nest Potion specifically has the wrong name in code
table.insert(resultPart, '\r\n!colspan=4|[['..potionName..']]')
if potionName == 'Bird Nests Potion' then
table.insert(resultPart, '\r\n!colspan=4|[[Bird Nest Potion]]')
else
table.insert(resultPart, '\r\n!colspan=4|[['..potionName..']]')
end
table.insert(resultPart, '\r\n|-\r\n!Potion!!Tier!!Charges!!Effect')
table.insert(resultPart, '\r\n|-\r\n!Potion!!Tier!!Charges!!Effect')


Line 179: Line 249:
local potion = Items.getItemByID(potionID)
local potion = Items.getItemByID(potionID)
if potion ~= nil then
if potion ~= nil then
local potDesc = potion.customDescription or ''
if potDesc == '' and type(potion.modifiers) == 'table' and not Shared.tableIsEmpty(potion.modifiers) then
potDesc = Constants.getModifiersText(potion.modifiers, false) or ''
end
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n| ' .. Icons.Icon({potion.name, type='item', notext=true, size='60'}))
table.insert(resultPart, '\r\n| ' .. Icons.Icon({potion.name, type='item', notext=true, size='60'}))
table.insert(resultPart, '|| ' .. Icons.getExpansionIcon(potion.id) .. Icons.Icon({potion.name, tier, type='item', noicon=true}))
table.insert(resultPart, '|| ' .. Icons.getExpansionIcon(potion.id) .. Icons.Icon({potion.name, tier, type='item', noicon=true}))
table.insert(resultPart, '|| ' .. potion.charges .. '|| ' .. potDesc)
table.insert(resultPart, '|| ' .. potion.charges .. '|| ' .. p._getPotionDescription(potion))
end
end
end
end
1,048

edits