17,101
edits
(Amend incomplete category & indentation) |
(Update for v1.0.2) |
||
Line 90: | Line 90: | ||
end | end | ||
result = result..'!!Seed Sources' | result = result..'!!Seed Sources' | ||
table.sort(seedList, function(a, b) return a.farmingLevel < b.farmingLevel end) | table.sort(seedList, function(a, b) return a.farmingLevel < b.farmingLevel end) | ||
Line 124: | Line 124: | ||
result = result..'\r\n!colspan="2"|Crop!!'..Icons.Icon({"Farming", type="skill", notext=true})..' Level' | result = result..'\r\n!colspan="2"|Crop!!'..Icons.Icon({"Farming", type="skill", notext=true})..' Level' | ||
result = result..'!!Healing!!Value' | result = result..'!!Healing!!Value' | ||
local itemArray = Items.getItems(function(item) return item.grownItemID ~= nil end) | local itemArray = Items.getItems(function(item) return item.grownItemID ~= nil end) | ||
Line 163: | Line 163: | ||
for i, patch in Shared.skpairs(patches) do | for i, patch in Shared.skpairs(patches) do | ||
result = result..'\r\n|-\r\n|'..i | result = result..'\r\n|-\r\n|'..i | ||
result = result..'||style="text-align:right;" data-sort-value=" | result = result..'||style="text-align:right;" data-sort-value="' .. patch.level .. '"|'..patch.level | ||
if patch.cost == 0 then | if patch.cost == 0 then | ||
result = result..'||Free' | result = result..'||Free' | ||
Line 175: | Line 175: | ||
end | end | ||
-- Accepts 1 parameter, being either: | |||
-- 'Smelting', for which a table of all bars is generated, or | |||
-- A bar or tier name, which if valid generates a table of all smithing recipes using that bar/tier | |||
function p.getSmithingTable(frame) | function p.getSmithingTable(frame) | ||
local tableType = frame.args ~= nil and frame.args[1] or frame | local tableType = frame.args ~= nil and frame.args[1] or frame | ||
tableType = Shared.splitString(tableType, ' ')[1] | |||
-- Translates Smithing category names to Smithing recipe data categories | |||
local categoryMap = { | |||
['Smelting'] = 0, | |||
['Bronze'] = 1, | |||
['Iron'] = 2, | |||
['Steel'] = 3, | |||
['Mithril'] = 4, | |||
['Adamant'] = 5, | |||
['Adamantite'] = 5, | |||
['Rune'] = 6, | |||
['Runite'] = 6, | |||
['Dragon'] = 7, | |||
['Dragonite'] = 7 | |||
} | |||
local categoryID = categoryMap[tableType] | |||
if categoryID == nil then | |||
return 'ERROR: Invalid Smithing category: "' .. tableType .. '"[[Category:Pages with script errors]]' | |||
end | end | ||
local | -- Build a list of recipes to be included, and a list of bars while we're at it | ||
for i, | -- The bar list will be used later for value/bar calculations | ||
if | local recipeList, barIDList = {}, {} | ||
for i, recipe in ipairs(SkillData.Smithing.Recipes) do | |||
if recipe.category == categoryID then | |||
local recipeItem = Items.getItemByID(recipe.itemID) | |||
if recipeItem ~= nil then | |||
table.insert(recipeList, { id = i, level = recipe.level, itemName = recipeItem.name, itemValue = recipeItem.sellsFor }) | |||
end | end | ||
elseif recipe.category == 0 then | |||
barIDList[recipe.itemID] = true | |||
end | end | ||
end | end | ||
local | -- Generate output table | ||
local resultPart = {} | |||
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"') | |||
table.insert(resultPart, '\r\n|-class="headerRow-0"') | |||
table.insert(resultPart, '\r\n!Item!!Name!!'..Icons.Icon({'Smithing', type='skill', notext=true})..' Level!!XP!!Value!!Ingredients') | |||
--Adding value/bar for things other than smelting | --Adding value/bar for things other than smelting | ||
if | if categoryID > 0 then | ||
table.insert(resultPart, '!!Value/Bar') | |||
end | |||
table.sort(recipeList, function(a, b) | |||
if a.level ~= b.level then | |||
return a.level < b.level | |||
else | |||
return a.itemName < b.itemName | |||
end | |||
end) | |||
for i, recipeDef in ipairs(recipeList) do | |||
local recipe = SkillData.Smithing.Recipes[recipeDef.id] | |||
local totalValue = recipe.baseQuantity * recipeDef.itemValue | |||
-- Determine the bar quantity & build the recipe cost string | |||
local barQty, costString = 0, {} | |||
for j, itemCost in ipairs(recipe.itemCosts) do | |||
local costItem = Items.getItemByID(itemCost.id) | |||
if costItem ~= nil then | |||
table.insert(costString, Icons.Icon({costItem.name, type='item', qty=itemCost.qty, notext=true})) | |||
end | |||
if barIDList[itemCost.id] then | |||
barQty = barQty + itemCost.qty | |||
end | |||
end | end | ||
table.insert(resultPart, '\r\n|-') | |||
table.insert(resultPart, '\r\n| ' .. Icons.Icon({recipeDef.itemName, type='item', size=50, notext=true})) | |||
table.insert(resultPart, '\r\n| ') | |||
if recipe.baseQuantity > 1 then | |||
if | table.insert(resultPart, recipe.baseQuantity .. 'x ') | ||
end | end | ||
table.insert(resultPart, Icons.Icon({recipeDef.itemName, type='item', noicon=true})) | |||
table.insert(resultPart, '\r\n|data-sort-value="' .. recipe.level .. '"| ' .. Icons._SkillReq('Smithing', recipe.level)) | |||
table.insert(resultPart, '\r\n|data-sort-value="' .. recipe.baseXP .. '"| ' .. Shared.formatnum(recipe.baseXP)) | |||
table.insert(resultPart, '\r\n|data-sort-value="' .. totalValue .. '"| ' .. Icons.GP(recipeDef.itemValue)) | |||
if recipe.baseQuantity > 1 then | |||
table.insert(resultPart, ' (x' .. recipe.baseQuantity .. ')') | |||
end | end | ||
table.insert(resultPart, '\r\n| ' .. table.concat(costString, ', ')) | |||
if | if categoryID > 0 then | ||
local barVal, barValTxt = 0, 'N/A' | |||
if barQty > 0 then | |||
barVal = totalValue / barQty | |||
barTxt = Icons.GP(Shared.round(barVal, 1, 1)) | |||
end | end | ||
table.insert(resultPart, '\r\n|data-sort-value="' .. barVal .. '"| ' .. barTxt) | |||
end | end | ||
end | end | ||
table.insert(resultPart, '\r\n|}') | |||
return table.concat(resultPart) | |||
end | end | ||
Line 277: | Line 296: | ||
table.insert(resultPart, '\r\n|data-sort-value="'..name..'"|'..Icons.Icon({name, type='item', size='50', notext=true})) | table.insert(resultPart, '\r\n|data-sort-value="'..name..'"|'..Icons.Icon({name, type='item', size='50', notext=true})) | ||
table.insert(resultPart, '||[['..name..']]') | table.insert(resultPart, '||[['..name..']]') | ||
table.insert(resultPart, '||style ="text-align: right;"|'..logData. | table.insert(resultPart, '||style ="text-align: right;"|'..logData.level) | ||
table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..burnTime..'"|'..Shared.timeString(burnTime, true)) | table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..burnTime..'"|'..Shared.timeString(burnTime, true)) | ||
table.insert(resultPart, '||style ="text-align: right;"|'..logData.baseXP) | table.insert(resultPart, '||style ="text-align: right;"|'..logData.baseXP) | ||
Line 294: | Line 313: | ||
local baseTokenChance = 18500 | local baseTokenChance = 18500 | ||
local masterySkills = {} | local masterySkills = {} | ||
-- Find all mastery tokens | -- Find all mastery tokens | ||
local masteryTokens = Items.getItems(function(item) return item.isToken ~= nil and item.skill ~= nil and item.isToken end) | local masteryTokens = Items.getItems(function(item) return item.isToken ~= nil and item.skill ~= nil and item.isToken end) | ||
Line 310: | Line 329: | ||
end | end | ||
end) | end) | ||
-- Generate output table | -- Generate output table | ||
local resultPart = {} | local resultPart = {} | ||
Line 333: | Line 352: | ||
end | end | ||
table.insert(resultPart, '\r\n|}') | table.insert(resultPart, '\r\n|}') | ||
return table.concat(resultPart) | return table.concat(resultPart) | ||
end | end |