Module:Sandbox/User:Alsang/PotionList: Difference between revisions
mostly done, minor formatting left (commas in numbes, decimal places, zero currency replacement)
(back to testing, wont format properly through template) |
(mostly done, minor formatting left (commas in numbes, decimal places, zero currency replacement)) |
||
(One intermediate revision by the same user not shown) | |||
Line 1:
require('Module:Mw.html extension')
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local p = {}
-- non dynamic module, no inputs
Line 10 ⟶ 13:
'[[Category:Potions]]',
'[[Uses facility::Standard Potion Station||Potent Potion Station]]',
'?Profession Level A = lvl',
'? #- = name',
Line 25 ⟶ 27:
local results = mw.smw.ask(query)
results = p.
return p.displayTable(results)
end
-- makes the html for the cells containing currency directly, no tags needed
-- flag is for if the number should not be known, replaces with zero
local function currency_cell(amount,flag)
local a = {}
if flag then
a = currency._cell(amount, { html = 'yes' })
else
a = currency._cell(0, { html = 'yes' }) -- replace this with blank, if I can figure out how to
end
return a
end
-- do calculations and determine strings to go in cells
function p.
-- iterate through potions
Line 65 ⟶ 75:
-- sanitise data, set to 0 if its not there
local lvl = item.lvl or
local buy = item.buy or 0
local sell = item.sell or 0
local brewXP = item.brewXP or 0
Line 75 ⟶ 86:
-- direct values
item.profit = sell -
item.XP = brewXP + prepXP
item.KP = brewKP + prepKP
Line 91 ⟶ 102:
item.profitPerHour = math.floor(item.profit * item.potionPerHour)
--
item.hasProfit = item.hasBuy and item.hasSell
item.hasXP = param.has_content(item.brewXP) and param.has_content(item.prepXP)
item.hasKP = param.has_content(item.brewKP) and param.has_content(item.prepKP)
item.hasDuration = param.has_content(item.brewDuration) and param.has_content(item.prepDuration)
-- XP/KP strings, if the requisite data isnt there then display "unknown"
if item.hasXP then
item.xp = tostring(item.xp) -- format to include commas
else
item.XP = 'Unknown'
end
if
item.
else
item.
end
if item.hasXP and item.hasDuration then
item.
else
item.
end
if item.hasKP and item.hasDuration then
item.
else
item.
end
Line 156 ⟶ 144:
function p.displayTable(results)
local out =
:addClass('wikitable sortable')
:tag('tr')
:tag('th')
:wikitext('Level')
:done()
:tag('th')
:wikitext('Potion')
:done()
:tag('th')
:wikitext('Reagents (plus bottle)')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Buy Value')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Sell Value')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Profit')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Profit/hr')
:done()
:tag('th')
:wikitext('XP')
:done()
:tag('th')
:wikitext('XP/hr')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Profit/XP')
:done()
:tag('th')
:wikitext('KP')
:done()
:tag('th')
:wikitext('KP/hr')
:done()
:done()
for i,item in ipairs(results) do
-- need to generate the text for the reagent cell before starting the row
local reagentCell = ''
for j, reagent in ipairs(item.reagents) do
end
out
:tag('tr')
:tag('td')
:wikitext('[[File:Alchemist small icon.png|15px]] ' .. item.lvl)
:done()
:tag('td')
:wikitext('[[File:' .. item.name .. '.png|30px|link=' .. item.name .. ']] [[' .. item.name .. ']]')
:done()
:tag('td')
:wikitext(reagentCell)
:done()
:wikitext(currency_cell(item.buy,item.hasBuy))
:wikitext(currency_cell(item.sell,item.hasSell))
:wikitext(currency_cell(item.profit,item.hasProfit))
:wikitext(currency_cell(item.profitPerHour,item.hasProfit and item.hasDuration))
:tag('td')
:wikitext(item.XP,item.hasXP)
:done()
:tag('td')
:wikitext(item.XPPerHour)
:done()
:wikitext(currency_cell(item.profitPerXP,item.hasXP and item.hasProfit))
:tag('td')
:wikitext(item.KP)
:done()
:tag('td')
:wikitext(item.KPPerHour)
:done()
:done()
end
return out
end
|