2,875
edits
(getCookedItemsTable: Change formatting of interval column) |
(Add function to get a table of all herbs) |
||
Line 159: | Line 159: | ||
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") | |||
: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)) | |||
:done() | |||
end | |||
return tostring(tbl) | |||
end | |||
function p.getHerbloreHerbTable(frame) | |||
local args = frame:getParent().args | |||
return p._getHerbloreHerbTable(args) | |||
end | end | ||
edits