Module:Skills: Difference between revisions

1,139 bytes added ,  3 February 2022
Update for v1.0.2
(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="0"|'..patch.level
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
local bar = nil
tableType = Shared.splitString(tableType, ' ')[1]
if tableType ~= 'Smelting' then
-- Translates Smithing category names to Smithing recipe data categories
bar = Items.getItem(tableType)
local categoryMap = {
if bar == nil then
['Smelting'] = 0,
return 'ERROR: Could not find an item named '..tableType..' to build a smithing table with'
['Bronze'] = 1,
elseif bar.type ~= 'Bar' then
['Iron'] = 2,
return 'ERROR: '..tableType.." is not a bar and thus can't be used for smithing"
['Steel'] = 3,
end
['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 smithList = {}
-- Build a list of recipes to be included, and a list of bars while we're at it
for i, item in pairs(ItemData.Items) do
-- The bar list will be used later for value/bar calculations
if item.smithingLevel ~= nil then
local recipeList, barIDList = {}, {}
if tableType == 'Smelting' then
for i, recipe in ipairs(SkillData.Smithing.Recipes) do
if item.type == 'Bar' then
if recipe.category == categoryID then
table.insert(smithList, item)
local recipeItem = Items.getItemByID(recipe.itemID)
end
if recipeItem ~= nil then
else
table.insert(recipeList, { id = i, level = recipe.level, itemName = recipeItem.name, itemValue = recipeItem.sellsFor })
for j, req in pairs(item.smithReq) do
if req.id == bar.id then
table.insert(smithList, item)
end
end
end
end
elseif recipe.category == 0 then
barIDList[recipe.itemID] = true
end
end
end
end


local result = '{|class="wikitable sortable stickyHeader"'
-- Generate output table
result = result..'\r\n|-class="headerRow-0"'
local resultPart = {}
result = result..'\r\n!Item!!Name!!'..Icons.Icon({'Smithing', type='skill', notext=true})..' Level!!XP!!Value!!Ingredients'
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 bar ~= nil then result = result..'!!Value/Bar' end
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)


table.sort(smithList, function(a, b)
for i, recipeDef in ipairs(recipeList) do
if a.smithingLevel ~= b.smithingLevel then
local recipe = SkillData.Smithing.Recipes[recipeDef.id]
return a.smithingLevel < b.smithingLevel
local totalValue = recipe.baseQuantity * recipeDef.itemValue
else
-- Determine the bar quantity & build the recipe cost string
return a.name < b.name
local barQty, costString = 0, {}
end end)
for j, itemCost in ipairs(recipe.itemCosts) do
for i, item in Shared.skpairs(smithList) do
local costItem = Items.getItemByID(itemCost.id)
result = result..'\r\n|-'
if costItem ~= nil then
result = result..'\r\n|'..Icons.Icon({item.name, type='item', size='50', notext=true})..'||'
table.insert(costString, Icons.Icon({costItem.name, type='item', qty=itemCost.qty, notext=true}))
local qty = item.smithingQty ~= nil and item.smithingQty or 1
end
if qty > 1 then
if barIDList[itemCost.id] then
result = result..item.smithingQty..'x '
barQty = barQty + itemCost.qty
end
end
end
result = result..'[['..item.name..']]'
 
result = result..'||data-sort-value="'..item.smithingLevel..'"|'..Icons._SkillReq('Smithing', item.smithingLevel)
table.insert(resultPart, '\r\n|-')
result = result..'||'..item.smithingXP
table.insert(resultPart, '\r\n| ' .. Icons.Icon({recipeDef.itemName, type='item', size=50, notext=true}))
local totalValue = item.sellsFor * qty
table.insert(resultPart, '\r\n| ')
result = result..'||data-sort-value="'..totalValue..'"|'..Icons.GP(item.sellsFor)
if recipe.baseQuantity > 1 then
if qty > 1 then
table.insert(resultPart, recipe.baseQuantity .. 'x ')
result = result..' (x'..qty..')'
end
end
result = result..'||'
table.insert(resultPart, Icons.Icon({recipeDef.itemName, type='item', noicon=true}))
local barQty = 0
table.insert(resultPart, '\r\n|data-sort-value="' .. recipe.level .. '"| ' .. Icons._SkillReq('Smithing', recipe.level))
for i, mat in Shared.skpairs(item.smithReq) do
table.insert(resultPart, '\r\n|data-sort-value="' .. recipe.baseXP .. '"| ' .. Shared.formatnum(recipe.baseXP))
matItem = Items.getItemByID(mat.id)
table.insert(resultPart, '\r\n|data-sort-value="' .. totalValue .. '"| ' .. Icons.GP(recipeDef.itemValue))
if i > 1 then result = result..', ' end
if recipe.baseQuantity > 1 then
result = result..Icons.Icon({matItem.name, type='item', qty=mat.qty, notext=true})
table.insert(resultPart, ' (x' .. recipe.baseQuantity .. ')')
if bar ~= nil and mat.id == bar.id then
barQty = mat.qty
end
end
end
--Add the data for the value per bar
table.insert(resultPart, '\r\n| ' .. table.concat(costString, ', '))
if bar ~= nil then
if categoryID > 0 then
if barQty == 0 then
local barVal, barValTxt = 0, 'N/A'
result = result..'||data-sort-value="0"|N/A'
if barQty > 0 then
else
barVal = totalValue / barQty
local barVal = totalValue / barQty
barTxt = Icons.GP(Shared.round(barVal, 1, 1))
result = result..'||data-sort-value="'..barVal..'"|'..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|}')


result = result..'\r\n|}'
return table.concat(resultPart)
return result
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.levelRequired)
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