Module:AlchemistList: Difference between revisions
m
Alsang moved page Module:PotionList to Module:AlchemistList without leaving a redirect: match the naming convention of the other "List" modules
(Use multiple rows for multiple reagents) |
m (Alsang moved page Module:PotionList to Module:AlchemistList without leaving a redirect: match the naming convention of the other "List" modules) |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1:
require('strict')
require('Module:Mw.html extension')
local
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local p = {}
Line 9 ⟶ 10:
-- non dynamic module, no inputs
function p.main()
-- returns only directly needed parameter needed for the row,
-- other parameters are determined by subqueries of chained pages
local query = {
'[[Uses facility::Standard Potion Station||Potent Potion Station]]',
'?Profession Level A = lvl',
'? #- = name',
'?
'?Activity XP = XP',
'?Activity duration = duration',
'?Value = sell',
'
'limit = 500'
}
local results = mw.smw.ask(query)
Line 31 ⟶ 28:
return p.displayTable(results)
--for debugging
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'
end
Line 36:
-- makes the html for the cells containing currency directly
-- Replaces nil with an "unknown" cell
local function currency_cell(amount
if not amount then
return
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:attr{ colspan = '10'
:wikitext("''unknown''")
:done(
end
return currency._cell(amount, { html = 'yes'
end
Line 53 ⟶ 51:
function p.formatResults(results)
-- iterate through
for
-- New module for recipe searching
local fullRecipe = search.main(item.name)
item.outputQuantity = fullRecipe.output[1].quantity
item.buy = fullRecipe.buyPrice
item.XP = fullRecipe.xp
item.duration = fullRecipe.duration
-- direct values
item.sell = item.sell and item.outputQuantity and item.sell * item.outputQuantity
item.profit = item.sell and item.buy and item.sell - item.buy
item.profitPerXP = item.profit and item.XP and math.floor(item.profit / item.XP * 100) / 100
Line 98 ⟶ 70:
local batchSize = 12
local downtime = 40
item.duration = item.
item.
-- properties per hour
item.XPPerHour = item.XP and item.
item.
end
Line 112 ⟶ 83:
-- make the table
function p.displayTable(results)
local out = mw.html.create('table')
:addClass('wikitable sortable')
Line 120 ⟶ 90:
:done()
:tag('th')
:
:wikitext('Product')
:done()
:tag('th')
:
:done()
:tag('th')
Line 154 ⟶ 124:
:done()
local unknown_value_cell = mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:wikitext("''unknown''")
for i, item in ipairs(results) do
local row = out:tag('tr')
:IF(item.lvl)
:tag('td')
:css{ ['text-align'] = 'center' }
:wikitext(item.lvl)
:done()
Line 205 ⟶ 141:
:tag('td')
:css{ ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }
:
:wikitext(item.outputQuantity .. ' ×')
:done()
:tag('td')
:addClass('plinkt-image no-border')
:css{ ['border-left'] = '0', ['padding-left'] = '0' }
:wikitext('[[File:' .. item.name .. '.png|link=' .. item.name .. '|30px]]')
:done()
:tag('td')
:addClass('plinkt-link no-border')
:wikitext('[[' .. item.name .. ']]')
:done()
local materialCell = row:tag('td')
for i, _ in ipairs(item.materials) do
materialCell:wikitext(item.materials[i].quantity .. '× [[File:' .. item.materials[i].name .. '.png|18px|link=' .. item.materials[i].name .. ']] [[' .. item.materials[i].name .. ']]<br>')
end
row
:node(currency_cell(item.buy))
:
:node(currency_cell(item.profit))
:node(currency_cell(item.profitPerHour))
:IF(item.XP)
:tag('td')
:wikitext(item.XP and lang:formatNum(tonumber(item.XP)))
:done()
Line 230 ⟶ 177:
:IF(item.XPPerHour)
:tag('td')
:wikitext(item.XPPerHour and lang:formatNum(tonumber(item.XPPerHour)))
:done()
Line 237 ⟶ 183:
:END()
:
:done()
end
|