Anonymous

Module:Items/SourceTables/Sandbox: Difference between revisions

From Melvor Idle
Separate Rune costs in Creation Table; Add Township and Superheat creation data into Creation Table;
(Revert: "Use Recipe icon for source icons when available"; Purchase outputs no longer show icon text when in a table; Add more fallbacks to display N/A when data is nil)
(Separate Rune costs in Creation Table; Add Township and Superheat creation data into Creation Table;)
Line 325: Line 325:
for i, altSpell in ipairs(Magic.getSpellsBySpellBook('altMagic')) do
for i, altSpell in ipairs(Magic.getSpellsBySpellBook('altMagic')) do
if altSpell.produces == itemID then
if altSpell.produces == itemID then
local imgType = Magic._getSpellIconType(altSpell)
table.insert(tableData, {
table.insert(tableData, {
['skill'] = 'Magic',
['skill'] = 'Magic',
Line 330: Line 331:
['isAbyssal'] = false,
['isAbyssal'] = false,
['xp'] = altSpell.baseExperience,
['xp'] = altSpell.baseExperience,
['costs'] = altSpell.runesRequired,
['costs'] = Magic._getAltSpellCostText(altSpell),
['qty'] = altSpell.productionRatio,
['qty'] = altSpell.productionRatio,
['source'] = Icons.Icon({ altSpell.name, type='spell' }),
['source'] = Icons.Icon({ altSpell.name, type=imgType }),
['time'] = 2,
['time'] = 2,
['altCosts'] = Magic._getAltSpellCostText(altSpell)
['runeCost'] = Magic._getSpellRunes(altSpell)
})
})
end
end
Line 366: Line 367:
local showRequirements = false
local showRequirements = false
local showInputs = false
local showInputs = false
local showRunes = false
local showOutputs = false
local showOutputs = false
local showXP = false
local showXP = false
Line 383: Line 385:
if not showInputs and tableData[1].costs ~= tableData[i].costs then
if not showInputs and tableData[1].costs ~= tableData[i].costs then
showInputs = true
showInputs = true
colspan = colspan + 1
end
if not showRunes and  tableData[1].runeCost ~= tableData[i].runeCost then
showRunes = true
colspan = colspan + 1
colspan = colspan + 1
end
end
Line 422: Line 428:
end
end
else
else
costsRow:wikitext(data.costs)
local costStr = data.costs:gsub(', ', '<br>')
end
costsRow:wikitext(costStr)
 
if type(data.altCosts) == 'string' then
local costStr = data.altCosts:gsub(', ', '<br>')
costsRow:wikitext('<br>' .. costStr)
end
end
end
end
Line 438: Line 440:
if showRequirements then tableHeader:tag('th'):wikitext('Requires') end
if showRequirements then tableHeader:tag('th'):wikitext('Requires') end
if showInputs then tableHeader:tag('th'):wikitext('Costs') end
if showInputs then tableHeader:tag('th'):wikitext('Costs') end
if showRunes then tableHeader:tag('th'):wikitext('Runes') end
if showOutputs then tableHeader:tag('th'):wikitext('Outputs') end
if showOutputs then tableHeader:tag('th'):wikitext('Outputs') end
if showXP then tableHeader:tag('th'):wikitext('Exp') end
if showXP then tableHeader:tag('th'):wikitext('Exp') end
Line 459: Line 462:
if data.costs ~= nil then
if data.costs ~= nil then
addCostsRow(recipeRow, data, 1)
addCostsRow(recipeRow, data, 1)
else
recipeRow:tag('td'):wikitext('N/A'):addClass('table-na')
end
end
if showRunes then
if data.runeCost ~= nil then
recipeRow:tag('td'):wikitext(data.runeCost):addClass('center')
else
else
recipeRow:tag('td'):wikitext('N/A'):addClass('table-na')
recipeRow:tag('td'):wikitext('N/A'):addClass('table-na')
Line 474: Line 485:
end
end
end
end
if showXP then
if showXP then
if data.skill ~= nil and data.xp ~= nil then
if data.skill ~= nil and data.xp ~= nil then
Line 494: Line 506:
if showChance then
if showChance then
if data.weight ~= nil then
if data.weight ~= nil then
recipeRow:tag('td'):wikitext(Num.fraction(data.weight, (data.totalWeight or 100)))
recipeRow:tag('td'):wikitext(Num.fraction(data.weight, (data.totalWeight or 100))):addClass('center')
recipeRow:tag('td'):wikitext(Num.round2(data.weight / (data.totalWeight or 100) * 100, 2) .. '%')
recipeRow:tag('td'):wikitext(Num.round2(data.weight / (data.totalWeight or 100) * 100, 2) .. '%'):addClass('center')
else
else
recipeRow:tag('td'):wikitext('100%'):addClass('center'):attr('colspan', 2)
recipeRow:tag('td'):wikitext('100%'):addClass('center'):attr('colspan', 2)
Line 508: Line 520:
:tag('td'):attr('colspan', colspan):wikitext(tableData[1].source)
:tag('td'):attr('colspan', colspan):wikitext(tableData[1].source)
end
end
if not showRequirements and tableData[1].reqs ~= nil then
if not showRequirements and tableData[1].reqs ~= nil then
local reqRow = resultTable:tag('tr')
local reqRow = resultTable:tag('tr')
Line 513: Line 526:
:tag('td'):wikitext(tableData[1].reqs):attr('colspan', colspan)
:tag('td'):wikitext(tableData[1].reqs):attr('colspan', colspan)
end
end
if not showInputs and tableData[1].costs ~= nil then
if not showInputs and tableData[1].costs ~= nil then
local costRow = resultTable:tag('tr')
local costRow = resultTable:tag('tr')
Line 519: Line 533:
addCostsRow(costRow, tableData[1], colspan)
addCostsRow(costRow, tableData[1], colspan)
end
end
if showRunes and type(tableData[1].runeCost) == 'string' then
local costStr = tableData[1].runeCost:gsub(', ', '<br>')
recipeRow:tag('td'):wikitext('<br>' .. costStr):addClass('center')
end
if not showOutputs and tableData[1].qty ~= nil then
if not showOutputs and tableData[1].qty ~= nil then
local outputRow = resultTable:tag('tr')
local outputRow = resultTable:tag('tr')
Line 529: Line 549:
end
end
end
end
if not showXP and tableData[1].xp ~= nil then
if not showXP and tableData[1].xp ~= nil then
local xpText = (tableData[1].isAbyssal and ' AXP' or ' XP')
local xpText = (tableData[1].isAbyssal and ' AXP' or ' XP')
Line 535: Line 556:
:tag('td'):attr('colspan', colspan):wikitext(Num.formatnum(tableData[1].xp) .. xpText)
:tag('td'):attr('colspan', colspan):wikitext(Num.formatnum(tableData[1].xp) .. xpText)
end
end
if not showTime and tableData[1].time ~= nil then
if not showTime and tableData[1].time ~= nil then
resultTable:tag('tr')
resultTable:tag('tr')
Line 546: Line 568:
end
end
end
end
if not showChance and tableData[1].weight ~= nil then
if not showChance and tableData[1].weight ~= nil then
local chanceData = resultTable:tag('tr')
local chanceData = resultTable:tag('tr')
Line 1,451: Line 1,474:
end
end


function p._getItemSuperheatTable(item)
function p._getItemSuperheatTableData(item, tableData)
--Manually build the Superheat Item table
if tableData == nil then tableData = {} end
 
-- Validate that the item can be superheated
-- Validate that the item can be superheated
local smithRecipe = p._getSuperheatSmithRecipe(item)
local smithRecipe = p._getSuperheatSmithRecipe(item)
Line 1,459: Line 1,483:
end
end


local oreStringPart, coalString = {}, ''
local oreStringPart, coalString, smithingReq = {}, '', Icons._SkillReq('Smithing', smithRecipe.level, false)
for i, mat in ipairs(smithRecipe.itemCosts) do
for i, mat in ipairs(smithRecipe.itemCosts) do
local matItem = Items.getItemByID(mat.id)
local matItem = Items.getItemByID(mat.id)
if mat.id == 'melvorD:Coal_Ore' then
if mat.id == 'melvorD:Coal_Ore' then
coalString = Icons.Icon({matItem.name, type='item', notext='true', qty=mat.quantity})
coalString = Icons.Icon({ matItem.name, type='item', qty=mat.quantity })
else
else
table.insert(oreStringPart, Icons.Icon({matItem.name, type='item', notext='true', qty=mat.quantity}))
table.insert(oreStringPart, Icons.Icon({ matItem.name, type='item', qty=mat.quantity }))
end
end
end
end
--Set up the header
local superheatTable = {}
table.insert(superheatTable, '{|class="wikitable"\r\n!colspan="2"|Spell')
table.insert(superheatTable, '!!'..Icons.Icon({'Smithing', type='skill', notext='true'})..' Level')
table.insert(superheatTable, '!!'..Icons.Icon({'Magic', type='skill', notext='true'})..' Level')
table.insert(superheatTable, '!!'..Icons.Icon({'Magic', type='skill', notext='true'})..' XP')
table.insert(superheatTable, '!!'..Icons.Icon({item.name, type='item', notext='true'})..' Bars')
table.insert(superheatTable, '!!Ore!!Runes')


--Loop through all the variants
--Loop through all the variants
Line 1,483: Line 1,498:
if spell.specialCost ~= nil and Shared.contains({ 'BarIngredientsWithCoal', 'BarIngredientsWithoutCoal' }, spell.specialCost.type) then
if spell.specialCost ~= nil and Shared.contains({ 'BarIngredientsWithCoal', 'BarIngredientsWithoutCoal' }, spell.specialCost.type) then
local imgType = Magic._getSpellIconType(spell)
local imgType = Magic._getSpellIconType(spell)
table.insert(superheatTable, '\r\n|-\r\n|'..Icons.Icon({spell.name, type=imgType, notext=true, size=50}))
local costs = table.concat(oreStringPart, '<br>')
table.insert(superheatTable, '||'..Icons.Icon({spell.name, type=imgType, noicon=true})..'||style="text-align:right;"|'..smithRecipe.level)
 
table.insert(superheatTable, '||style="text-align:right;"|'..spell.level..'||style="text-align:right;"|'..spell.baseExperience)
table.insert(superheatTable, '||style="text-align:right;"|'..spell.productionRatio)
table.insert(superheatTable, '|| '..table.concat(oreStringPart, ', '))
if spell.specialCost.type == 'BarIngredientsWithCoal' and coalString ~= '' then
if spell.specialCost.type == 'BarIngredientsWithCoal' and coalString ~= '' then
table.insert(superheatTable, (not Shared.tableIsEmpty(oreStringPart) and ', ' or '') .. coalString)
costs = costs .. '<br>' .. coalString
end
end
table.insert(superheatTable, '||style="text-align:center"| ' .. Magic._getSpellRunes(spell))
 
table.insert(tableData, {
['skill'] = 'Magic',
['reqs'] = smithingReq .. '<br>' .. Icons._SkillReq('Magic', spell.level, false),
['isAbyssal'] = false,
['xp'] = spell.baseExperience,
['costs'] = costs,
['qty'] = spell.productionRatio,
['source'] = Icons.Icon({ spell.name, type=imgType }),
['time'] = 2,
['runeCost'] = Magic._getSpellRunes(spell)
})
end
end
end
end


--Add the table end and add the table to the result string
return tableData
table.insert(superheatTable, '\r\n|}')
return table.concat(superheatTable)
end
end


Line 1,507: Line 1,528:
end
end


return p._getItemSuperheatTable(item)
return p.buildCreationTable(p._getItemSuperheatTableData(item), item)
end
end


function p._getTownshipTraderTable(item)
function p._getTownshipTraderTableData(item, tableData)
if tableData == nil then tableData = {} end
 
for i, tsResource in ipairs(SkillData.Township.itemConversions.fromTownship) do
for i, tsResource in ipairs(SkillData.Township.itemConversions.fromTownship) do
for j, tradeDef in ipairs(tsResource.items) do
for j, tradeDef in ipairs(tsResource.items) do
if tradeDef.itemID == item.id then
if tradeDef.itemID == item.id then
-- Item found, build table
-- Item found, insert the data
local res = GameData.getEntityByID(SkillData.Township.resources, tsResource.resourceID)
local res = GameData.getEntityByID(SkillData.Township.resources, tsResource.resourceID)
local resName = (res ~= nil and res.name) or 'Unknown'
local resName = (res ~= nil and res.name) or 'Unknown'
local resQty = math.max(item.sellsFor, 2)
local resQty = math.max(item.sellsFor, 2)


local resultPart = {}
table.insert(tableData, {
table.insert(resultPart, '{| class="wikitable"\n|-')
['reqs'] = Shop.getRequirementString(tradeDef.unlockRequirements),
table.insert(resultPart, '\n!colspan="2"| ' .. Icons.Icon({'Township', 'Trader', type='skill'}))
['isAbyssal'] = namespace == 'melvorItA',
table.insert(resultPart, '\n|-\n!style="text-align:right;"| Cost')
['costs'] = Icons.Icon({ resName, qty=resQty, type='resource' }),
table.insert(resultPart, '\n| ' .. Icons.Icon({resName, qty=resQty, type='resource'}))
['qty'] = 1,
table.insert(resultPart, '\n|-\n!style="text-align:right;| Requirements')
['source'] = Icons.Icon({'Township', 'Trader', type='skill'}),
table.insert(resultPart, '\n| ' .. Shop.getRequirementString(tradeDef.unlockRequirements))
})
table.insert(resultPart, '\n|}')
break
 
return table.concat(resultPart)
end
end
end
end
end
end
return ''
 
return tableData
end
end
-- TODO: Remove this maybe?
-- TODO: Remove this maybe?
function p._getItemShopTableData(item, tableData)
function p._getItemShopTableData(item, tableData)
Line 1,571: Line 1,594:
local resultPart = {}
local resultPart = {}
local sourceData = {}
local sourceData = {}
 
-- Is the item Created or Produced by anything?
p._getCreationTableData(item, sourceData)
p._getCreationTableData(item, sourceData)
-- Can the item be obtained by upgrading?
p._getItemUpgradeTableData(item, sourceData)
p._getItemUpgradeTableData(item, sourceData)
-- Can the item be obtained by Superheating?
if p._getSuperheatSmithRecipe(item) ~= nil then
p._getItemSuperheatTableData(item, sourceData)
end
-- Can the item be traded for in Township?
p._getTownshipTraderTableData(item, sourceData)
-- Can the item be purchased?
p._getItemShopTableData(item, sourceData)
p._getItemShopTableData(item, sourceData)


Line 1,581: Line 1,612:
end
end
--[[ TODO: Uncomment this section
--[[ TODO: Uncomment this section
local townshipTable = p._getTownshipTraderTable(item)
if townshipTable ~= '' then
if not Shared.tableIsEmpty(resultPart) then table.insert(resultPart, '\n') end
table.insert(resultPart, '===Township===\n' .. townshipTable)
end
if p._getSuperheatSmithRecipe(item) ~= nil then
table.insert(resultPart, '\r\n==='..Icons.Icon({'Alt. Magic', type='skill'})..'===\r\n'..p._getItemSuperheatTable(item))
end
local lootTable = p._getItemLootSourceTable(item)
local lootTable = p._getItemLootSourceTable(item)
if lootTable ~= '' then
if lootTable ~= '' then
Line 1,737: Line 1,757:
"Coal Ore",
"Coal Ore",
"Rune Essence",
"Rune Essence",
"Gold Bar",
"Dragonite Bar",
-- "Rune Platebody",
-- "Rune Platebody",
"Arrow Shafts",
"Arrow Shafts",