5,003
edits
(_getItemUseTable: Add cooking utility (fire/furnace/pot) as a requirement for cooking uses) |
(Fix Currencies not being displayed; Add 'table-na' class to cells without any data; Hide Requires and Exp columns if no data is present; Rename some headers to be slightly shorter and consistent with Creation Table; Reduce icon size on Use and Magic tables;) |
||
Line 19: | Line 19: | ||
local itemUseArray = { | local itemUseArray = { | ||
Agility = {}, | Agility = {}, | ||
Astrology = {'melvorF:Stardust', 'melvorF:Golden_Stardust', 'melvorItA:Abyssal_Stardust'}, | Astrology = {'melvorF:Stardust', 'melvorF:Golden_Stardust', 'melvorItA:Abyssal_Stardust', 'melvorItA:Eternal_Stardust'}, | ||
Archaeology = {}, | Archaeology = {}, | ||
Attack = {}, | Attack = {}, | ||
Line 442: | Line 442: | ||
function p._getItemUseTable(item) | function p._getItemUseTable(item) | ||
local | local tableData = {} | ||
-- Loop through all upgrades to find anything that can be upgraded using our source | -- Loop through all upgrades to find anything that can be upgraded using our source | ||
Line 448: | Line 448: | ||
for j, itemCost in ipairs(upgrade.itemCosts) do | for j, itemCost in ipairs(upgrade.itemCosts) do | ||
if itemCost.id == item.id then | if itemCost.id == item.id then | ||
local | local reqs = nil | ||
-- Potions do have upgrade requirements though | -- Potions do have upgrade requirements though | ||
local upgradeItem = Items.getItemByID(upgrade.upgradedItemID) | local upgradeItem = Items.getItemByID(upgrade.upgradedItemID) | ||
Line 454: | Line 454: | ||
local levelUnlock = GameData.getEntityByProperty(SkillData.Herblore.masteryLevelUnlocks, 'descriptionID', upgradeItem.tier + 1) | local levelUnlock = GameData.getEntityByProperty(SkillData.Herblore.masteryLevelUnlocks, 'descriptionID', upgradeItem.tier + 1) | ||
if levelUnlock ~= nil then | if levelUnlock ~= nil then | ||
reqs = Icons._MasteryReq(upgradeItem.name, levelUnlock.level) | |||
end | end | ||
end | end | ||
local upgradeCost = Common.getCostString({ | |||
["items"] = upgrade.itemCosts, | |||
["currencies"] = upgrade.currencyCosts | |||
}) | |||
table.insert(tableData, { | |||
['skill'] = 'Upgrade', | |||
['useType'] = '[[Upgrading Items|Upgrade]]', | |||
['reqs'] = reqs, | |||
['costs'] = upgradeCost, | |||
['productName'] = upgradeItem.name, | |||
['qty'] = (upgrade.quantity or 1) | |||
}) | |||
end | end | ||
end | end | ||
Line 494: | Line 505: | ||
local recipeItem = Items.getItemByID(recipeItemID) | local recipeItem = Items.getItemByID(recipeItemID) | ||
if recipeItem ~= nil then | if recipeItem ~= nil then | ||
local | local lvl, isAbyssal = Skills.getRecipeLevelRealm(recipeSkillID, recipe) | ||
local reqs = nil | |||
local | |||
if recipeSkillID == 'melvorD:Cooking' then | if recipeSkillID == 'melvorD:Cooking' then | ||
-- Cooking includes the required utility (fire, furnace, pot) as a special requirement | -- Cooking includes the required utility (fire, furnace, pot) as a special requirement | ||
Line 513: | Line 521: | ||
if categoryIconName ~= nil and categoryName ~= nil then | if categoryIconName ~= nil and categoryName ~= nil then | ||
local utilReq = Icons.Icon({'Cooking', categoryName, section = 'Cooking Upgrades', img = categoryIconName, type = 'upgrade'}) | local utilReq = Icons.Icon({'Cooking', categoryName, section = 'Cooking Upgrades', img = categoryIconName, type = 'upgrade'}) | ||
reqs = Icons._SkillReq(skillName, lvl, false, (isAbyssal and "melvorItA:Abyssal" or nil)) .. '<br>' .. utilReq | |||
end | end | ||
elseif recipeSkillID == 'melvorD:Herblore' then | elseif recipeSkillID == 'melvorD:Herblore' then | ||
Line 520: | Line 528: | ||
if levelUnlock ~= nil and levelUnlock.level > 1 then | if levelUnlock ~= nil and levelUnlock.level > 1 then | ||
local masteryReq = Icons._MasteryReq(recipeItem.name, levelUnlock.level) | local masteryReq = Icons._MasteryReq(recipeItem.name, levelUnlock.level) | ||
reqs = Icons._SkillReq(skillName, lvl, false, (isAbyssal and "melvorItA:Abyssal" or nil)) .. '<br>' .. masteryReq | |||
-- Slightly increase level per potion tier for proper ordering using data-sort-value | |||
lvl = lvl + levelUnlock.level * 0.01 | |||
end | end | ||
end | end | ||
table.insert( | local costs = Common.getCostString({ | ||
["items"] = costDef.itemCosts, | |||
["currencies"] = recipe.currencyCosts | |||
}) | |||
table.insert(tableData, { | |||
['skill'] = skillName, | |||
['lvl'] = lvl, | |||
['isAbyssal'] = isAbyssal, | |||
['useType'] = Icons.Icon({skillName, type='skill'}), | |||
['reqs'] = (reqs or Icons._SkillReq(skillName, lvl, false, (isAbyssal and "melvorItA:Abyssal" or nil))), | |||
['costs'] = costs, | |||
['productName'] = recipeItem.name, | |||
['qty'] = (recipe.baseQuantity or 1) * (costDef.quantityMultiplier or 1), | |||
['xp'] = recipe.baseAbyssalExperience or recipe.baseExperience | |||
}) | |||
end | end | ||
end | end | ||
Line 538: | Line 561: | ||
for i, recipe in ipairs(SkillData.Farming.recipes) do | for i, recipe in ipairs(SkillData.Farming.recipes) do | ||
if recipe.seedCost.id == item.id then | if recipe.seedCost.id == item.id then | ||
local category = GameData.getEntityByID(SkillData.Farming.categories, recipe.categoryID) | |||
local lvl, isAbyssal = Skills.getRecipeLevelRealm('melvorD:Farming', recipe) | |||
local product = Items.getItemByID(recipe.productId) | local product = Items.getItemByID(recipe.productId) | ||
table.insert(tableData, { | |||
['skill'] = 'Farming', | |||
['lvl'] = lvl, | |||
['isAbyssal'] = isAbyssal, | |||
['useType'] = Icons.Icon({'Farming', type='skill'}), | |||
['reqs'] = Icons._SkillReq('Farming', lvl, false, (isAbyssal and 'melvorItA:Abyssal' or nil)), | |||
['costs'] = { recipe.seedCost }, | |||
['productName'] = product.name, | |||
['qty'] = (5 * category.harvestMultiplier), | |||
['xp'] = recipe.baseAbyssalExperience or recipe.baseExperience | |||
}) | |||
end | end | ||
end | end | ||
Line 551: | Line 582: | ||
local obstacles = Agility.getObstaclesForItem(item.id) | local obstacles = Agility.getObstaclesForItem(item.id) | ||
for i, obstacle in ipairs(obstacles) do | for i, obstacle in ipairs(obstacles) do | ||
local | local costs = Common.getCostString({ | ||
["items"] = obstacle.itemCosts, | |||
["currencies"] = obstacle.currencyCosts | |||
}) | |||
table.insert(tableData, { | |||
['skill'] = 'Agility', | |||
['lvl'] = Skills.getRecipeLevelRealm('Agility', obstacle), | |||
['isAbyssal'] = obstacle.realm == 'melvorItA:Abyssal', | |||
['useType'] = Icons.Icon({'Agility', type='skill'}), | |||
['reqs'] = Agility._getObstacleRequirements(obstacle), | |||
['costs'] = costs, | |||
['productName'] = obstacle.name, | |||
['iconType'] = 'agility', | |||
['qty'] = 1 | |||
}) | |||
end | end | ||
Line 590: | Line 629: | ||
local recipeCosts = Shared.clone(recipe.itemCosts) | local recipeCosts = Shared.clone(recipe.itemCosts) | ||
local xp = recipe.baseAbyssalExperience or recipe.baseExperience | local xp = recipe.baseAbyssalExperience or recipe.baseExperience | ||
local | local lvl, isAbyssal = Skills.getRecipeLevelRealm('melvorD:Summoning', recipe) | ||
local recipeCosts = {} | local recipeCosts = {} | ||
for k, itemCost in ipairs(recipe.itemCosts) do | for k, itemCost in ipairs(recipe.itemCosts) do | ||
Line 599: | Line 638: | ||
local itemValue = math.max(nonShardItem.sellsFor, 20) | local itemValue = math.max(nonShardItem.sellsFor, 20) | ||
local nonShardQty = math.max(1, math.ceil(recipeCost / itemValue)) | local nonShardQty = math.max(1, math.ceil(recipeCost / itemValue)) | ||
table.insert(recipeCosts, {id = nonShardItemID, quantity = nonShardQty}) | table.insert(recipeCosts, { id = nonShardItemID, quantity = nonShardQty }) | ||
end | end | ||
local costs = Common.getCostString({ | |||
["items"] = recipeCosts, | |||
["currencies"] = recipe.currencyCosts | |||
}) | |||
table.insert(tableData, { | |||
['skill'] = 'Summoning', | |||
['lvl'] = lvl, | |||
['isAbyssal'] = isAbyssal, | |||
['useType'] = Icons.Icon({ 'Summoning', type='skill' }), | |||
['reqs'] = Icons._SkillReq('Summoning', lvl, false, (isAbyssal and 'melvorItA:Abyssal' or nil)), | |||
['costs'] = costs, | |||
['productName'] = recipeItem.name, | |||
['qty'] = recipe.baseQuantity, | |||
['xp'] = xp | |||
}) | |||
end | end | ||
end | end | ||
Line 610: | Line 663: | ||
for i, shopUse in ipairs(shopUses) do | for i, shopUse in ipairs(shopUses) do | ||
local purchase = shopUse.purchase | local purchase = shopUse.purchase | ||
table.insert(tableData, { | |||
['skill'] = 'Shop', | |||
['lvl'] = (not Shared.tableIsEmpty(purchase.purchaseRequirements) and purchase.purchaseRequirements[1].level or nil), | |||
['useType'] = Icons.Icon({'Shop'}), | |||
['reqs'] = Common.getRequirementString(purchase.purchaseRequirements), | |||
['costs'] = Common.getCostString(purchase.cost), | |||
['productName'] = Common.getPurchaseName(purchase), | |||
['iconType'] = Common.getPurchaseIconType(purchase), | |||
['qty'] = (purchase.qty or 1) | |||
}) | |||
end | end | ||
--Finally build the table using what we've learned | --Finally build the table using what we've learned | ||
table.sort( | table.sort(tableData, function(a, b) | ||
local | local aLvl = a.lvl | ||
local | local bLvl = b.lvl | ||
if a.skill ~= b.skill then | if a.skill ~= b.skill then | ||
return a.skill < b.skill | return a.skill < b.skill | ||
elseif type( | elseif type(aLvl) ~= type(bLvl) then | ||
return tostring( | return tostring(aLvl) < tostring(bLvl) | ||
elseif | elseif aLvl ~= bLvl then | ||
return | return aLvl < bLvl | ||
else | else | ||
return a. | return a.productName < b.productName | ||
end | end | ||
end) | end) | ||
local useTable = p.buildUseTable(item, tableData) | |||
local spellUseTable = p._getSpellUseTable(item) | |||
if spellUseTable ~= nil and spellUseTable ~= '' then | |||
useTable = useTable .. '\r\n===' .. Icons.Icon({'Magic', type='skill', size=30}) .. '===\r\n' .. spellUseTable | |||
end | |||
if useTable == '' then | |||
return '' | |||
else | |||
return '==Uses==\r\n' .. useTable | |||
end | |||
end | |||
function p.buildUseTable(item, tableData) | |||
if Shared.tableIsEmpty(tableData) then return '' end | |||
local | local showRequirements = false | ||
if not | local showXP = false | ||
for i, data in ipairs(tableData) do | |||
if not showRequirements and tableData[i].reqs ~= nil then showRequirements = true end | |||
if not showXP and tableData[i].xp ~= nil then showXP = true end | |||
if showRequirements and showXP then break end | |||
end | |||
local resultTable = mw.html.create('table') | |||
resultTable:addClass('wikitable stickyHeader sortable col-1-img') | |||
local tableHeader = resultTable:tag('tr') | |||
:tag('th'):wikitext('Product'):attr('colspan', 2) | |||
:tag('th'):wikitext('Used In') | |||
if showRequirements then tableHeader:tag('th'):wikitext('Requires') end | |||
if showXP then tableHeader:tag('th'):wikitext('Exp') end | |||
tableHeader:tag('th'):wikitext('Costs') | |||
for i, data in ipairs(tableData) do | |||
local recipeRow = resultTable:tag('tr') | |||
:tag('td'):wikitext(Icons.Icon({ data.productName, type=(data.iconType or 'item'), notext=true })):attr('data-sort-value', data.productName) -- Icon Image | |||
:tag('td') | |||
:wikitext((data.qty ~= nil and data.qty > 1 and ("'''" .. data.qty .. "x''' ") or '')) -- Icon Qty | |||
if | :wikitext(Icons.Icon({ data.productName, type=(data.iconType or 'item'), noicon=true })) -- Icon Text | ||
:tag('td'):wikitext(data.useType):attr('data-sort-value', (data.skill or nil)) -- Used In | |||
-- Requirements | |||
if showRequirements then | |||
if data.reqs ~= nil then | |||
recipeRow:tag('td'):wikitext(data.reqs):attr('data-sort-value', (data.lvl or 0)) | |||
else | |||
recipeRow:tag('td'):wikitext('N/A'):addClass('table-na') | |||
end | end | ||
end | |||
-- Exp | |||
if showXP then | |||
if data.skill ~= nil and data.xp ~= nil then | |||
local iconClass = (data.isAbyssal and 'abyss-icon' or nil) | |||
local xpText = (data.isAbyssal and ' AXP' or ' XP') | |||
recipeRow:tag('td'):attr('data-sort-value', data.xp) | |||
:wikitext(Icons.Icon({ data.skill, notext=true, type='skill', class=iconClass })) | |||
:wikitext(' ' .. Num.formatnum(data.xp) .. xpText) | |||
else | |||
recipeRow:tag('td'):wikitext('N/A'):addClass('table-na'):attr('data-sort-value', 0) | |||
end | end | ||
end | |||
-- Costs | |||
local costsRow = recipeRow:tag('td') | |||
if type(data.costs) == 'table' then | |||
for i, mat in ipairs(data.costs) do | |||
if i > 1 then costsRow:tag('br') end | |||
local matItem = Items.getItemByID(mat.id) | |||
if matItem == nil then | |||
costsRow:wikitext(mat.quantity .. 'x ?????') | |||
else | |||
costsRow:wikitext(Icons.Icon({ matItem.name, type='item', qty=mat.quantity })) | |||
end | end | ||
end | end | ||
else | |||
costsRow:wikitext(data.costs) | |||
end | end | ||
end | end | ||
return tostring(resultTable) | |||
end | end | ||
Line 762: | Line 789: | ||
return '' | return '' | ||
end | end | ||
--Adding a check for if the Items column is needed | --Adding a check for if the Items column is needed | ||
local hasItems = false | local hasItems = false | ||
Line 774: | Line 801: | ||
local resultPart = {} | local resultPart = {} | ||
table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"|Spell') | table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"|Spell') | ||
table.insert(resultPart, '!! | table.insert(resultPart, '!!Requires') | ||
table.insert(resultPart, '!!Type!!style="width:275px"|Description') | table.insert(resultPart, '!!Type!!style="width:275px"|Description') | ||
table.insert(resultPart, '!!Runes') | table.insert(resultPart, '!!Runes') | ||
Line 780: | Line 807: | ||
table.insert(resultPart, '!!Item Cost') | table.insert(resultPart, '!!Item Cost') | ||
end | end | ||
for i, spell in pairs(spellList) do | for i, spell in pairs(spellList) do | ||
local spellBook = Magic.getSpellBookFromSpell(spell) | local spellBook = Magic.getSpellBookFromSpell(spell) | ||
Line 787: | Line 813: | ||
table.insert(rowPart, '\r\n|-\r\n|data-sort-value="'..spell.name..'"|') | table.insert(rowPart, '\r\n|-\r\n|data-sort-value="'..spell.name..'"|') | ||
local iconType = Magic._getSpellIconType(spell) | local iconType = Magic._getSpellIconType(spell) | ||
table.insert(rowPart, Icons.Icon({spell.name, type=iconType, notext=true | table.insert(rowPart, Icons.Icon({spell.name, type=iconType, notext=true})) | ||
table.insert(rowPart, '||'..Icons.Icon({spell.name, type=iconType, noicon=true})) | table.insert(rowPart, '||'..Icons.Icon({spell.name, type=iconType, noicon=true})) | ||
table.insert(rowPart, '||data-sort-value="'..Skills.getRecipeLevel('melvorD:Summoning', spell)..'"|'..Magic._getSpellRequirements(spell)) | table.insert(rowPart, '||data-sort-value="'..Skills.getRecipeLevel('melvorD:Summoning', spell)..'"|'..Magic._getSpellRequirements(spell)) | ||
Line 796: | Line 822: | ||
table.insert(rowPart, Magic._getSpellRunes(spell)) | table.insert(rowPart, Magic._getSpellRunes(spell)) | ||
if hasItems then | if hasItems then | ||
table.insert(rowPart, '| | table.insert(rowPart, '||') | ||
table.insert(rowPart, Magic._getSpellItems(spell)) | table.insert(rowPart, Magic._getSpellItems(spell)) | ||
end | end | ||
Line 816: | Line 842: | ||
end | end | ||
--[ | --[[ | ||
-- Uncomment this block and execute 'p.test()' within the debug console | -- Uncomment this block and execute 'p.test()' within the debug console | ||
-- to test after making changes | -- to test after making changes | ||
Line 854: | Line 880: | ||
'Abyssal Stone', | 'Abyssal Stone', | ||
'Withered Ash', | 'Withered Ash', | ||
'Wrath Rune' | 'Wrath Rune', | ||
'Magic Bones', | |||
'Bowstring', | |||
'Superior Max Skillcape', | |||
'Abyssal Coin Contract II', | |||
'Dark Summon Consumable II', | |||
'Abyssal Slayer Gear Upgrade Kit', | |||
'Topaz Bolts (Enchanted)', | |||
'Summoning Shard (Black)', | |||
'Dragon Javelin', | |||
} | } | ||
local checkFuncs = { | local checkFuncs = { | ||
p.getItemUses, | --p.getItemUses, | ||
p.getItemUseTable | p.getItemUseTable | ||
} | } | ||
Line 880: | Line 915: | ||
end | end | ||
end | end | ||
--] | --]] | ||
return p | return p |