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
Tag: Undo |
m (Alsang moved page Module:PotionList to Module:AlchemistList without leaving a redirect: match the naming convention of the other "List" modules) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1:
require('strict')
require('Module:Mw.html extension')
local search = require('Module:RecipeTreeSearch')
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local p = {}
Line 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 32 ⟶ 28:
return p.displayTable(results)
--for debugging
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'
end
Line 39 ⟶ 38:
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' })
Line 52 ⟶ 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 97 ⟶ 70:
local batchSize = 12
local downtime = 40
item.duration = item.
item.
-- properties per hour
item.XPPerHour = item.XP and item.
item.
end
Line 111 ⟶ 83:
-- make the table
function p.displayTable(results)
local out = mw.html.create('table')
:addClass('wikitable sortable')
Line 119 ⟶ 90:
:done()
:tag('th')
:
:wikitext('Product')
:done()
:tag('th')
:wikitext('
:done()
:tag('th')
Line 151 ⟶ 123:
:done()
:done()
local unknown_value_cell = mw.html.create('td')
Line 166 ⟶ 129:
:wikitext("''unknown''")
for i, item in ipairs(results) do
local row = out:tag('tr')
:IF(item.lvl)
:tag('td')
Line 178 ⟶ 141:
:tag('td')
:css{ ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }
:attr{ ['data-sort-value'] = item.name }
: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.sell))
:node(currency_cell(item.profit))
:node(currency_cell(item.profitPerHour))
:IF(item.XP)
Line 209 ⟶ 183:
:END()
:
:done()
end
|