Module:AlchemistList: Difference between revisions

187 bytes removed ,  Yesterday at 23:02
m
Alsang moved page Module:PotionList to Module:AlchemistList without leaving a redirect: match the naming convention of the other "List" modules
m (currency_cell now returns a node)
m (Alsang moved page Module:PotionList to Module:AlchemistList without leaving a redirect: match the naming convention of the other "List" modules)
 
(4 intermediate revisions by 2 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')
Line 9 ⟶ 10:
-- non dynamic module, no inputs
function p.main()
-- returns almostonly everydirectly needed parameter needed for the row, except buy values for reagents
-- other parameters are determined by subqueries of chained pages
local query = {
'[[Category:Potions]]',
'[[Uses facility::Standard Potion Station||Potent Potion Station]]',
'?Profession Level A = lvl',
'? #- = name',
'?UsesRecipe item.Uses item #-JSON = reagentsrecipeJSON',
'?Activity KPXP = brewKPXP',
'?Activity duration = brewDurationduration',
'?Value = sell',
'?Activity XPsort = brewXPProfession Level A',
'limit = 500'
'?Uses item.Activity XP = prepXP',
'?Activity KP = brewKP',
'?Uses item.Activity KP = prepKP',
'?Activity duration = brewDuration',
'?Uses item.Activity duration = prepDuration',
'sort = Profession Level A'
}
local results = mw.smw.ask(query)
Line 30 ⟶ 28:
 
return p.displayTable(results)
--for debugging
--return '<pre>'..mw.text.jsonEncode(results, mw.text.JSON_PRETTY)..'</pre>'
 
end
Line 50 ⟶ 51:
function p.formatResults(results)
 
-- iterate through potionsproducts
for _, item in ipairs(results) do
 
-- New module for recipe searching
--in case of single reagent potions, make table of 1 element
local fullRecipe = search.main(item.name)
if type(item.reagents) ~= 'table' then
item.reagentsmaterials = {itemfullRecipe.reagents}materials
item.outputQuantity = fullRecipe.output[1].quantity
end
item.buy = 20fullRecipe.buyPrice
 
item.XP = fullRecipe.xp
-- iterate through reagents, adding buy price to running total (individuals not needed)
item.duration = fullRecipe.duration
-- starting value 20 is for bottle
item.buy = 20
for _, reagent in ipairs(item.reagents) do
 
--shamelessley lifted from Module:Products
local shopPriceQuery = '[[:+]][[Sold item::' .. reagent .. ']]|?Shop buy price|mainlabel=' .. reagent
local shopPriceResult = mw.smw.ask(shopPriceQuery) or {}
local shopPrice = 0
 
if shopPriceResult[1] and shopPriceResult[1]["Shop buy price"] then
shopPrice = tonumber(shopPriceResult[1]["Shop buy price"]) or 0
end
 
item.buy = item.buy + shopPrice
end
 
-- direct values
item.XPsell = item.brewXPsell and item.prepXPoutputQuantity and item.brewXPsell +* item.prepXPoutputQuantity
item.profit = item.sell and item.buy and item.sell - item.buy
item.XP = item.brewXP and item.prepXP and item.brewXP + item.prepXP
item.KP = item.brewKP and item.prepKP and item.brewKP + item.prepKP
item.profitPerXP = item.profit and item.XP and math.floor(item.profit / item.XP * 100) / 100
 
Line 84 ⟶ 70:
local batchSize = 12
local downtime = 40
item.duration = item.prepDurationduration and item.brewDuration and item.prepDuration + item.brewDurationduration + downtime/batchSize
item.potionPerHourproductPerHour = item.duration and 1 / item.duration * 3600
 
-- properties per hour
item.XPPerHour = item.XP and item.potionPerHourproductPerHour and math.floor(item.XP * item.potionPerHourproductPerHour)
item.KPPerHourprofitPerHour = item.KPprofit and item.potionPerHourproductPerHour and math.floor(item.KPprofit * item.potionPerHourproductPerHour) / 100
item.profitPerHour = item.profit and item.potionPerHour and math.floor(item.profit * item.potionPerHour)
end
 
Line 105 ⟶ 90:
:done()
:tag('th')
:wikitext(attr{ colspan = 'Potion3') }
:wikitext('Product')
:done()
:tag('th')
:wikitext('Reagents (plus bottle)Materials')
:done()
:tag('th')
Line 155 ⟶ 141:
 
:tag('td')
:css{ ['border-right'] = '0', ['padding-right'] = '0', ['text-align'] = 'right' }
:wikitext('[[File:' .. item.name .. '.png|30px|link=' .. item.name .. ']] [[' .. item.name .. ']]')
:attr{ ['data-sort-value'] = item.name }
:wikitext(item.outputQuantity .. ' &times;')
:done()
:tag('td')
:addClass('plinkt-image no-border')
:css{ ['border-left'] = '0', ['padding-left'] = '0' }
:wikitext('[[File:' .. item.name .. '.png|30px|link=' .. item.name .. ']] [[' .. item.name .. '|30px]]')
:done()
:tag('td')
:addClass('plinkt-link no-border')
:wikitext('[[' .. item.name .. ']]')
:done()
 
local reagentCellmaterialCell = row:tag('td')
 
for ji, reagent_ in ipairs(item.reagentsmaterials) do
reagentCellmaterialCell:wikitext(item.materials[i].quantity .. '&times; [[File:' .. reagentitem.materials[i].name .. '.png|30px18px|link=' .. reagentitem.materials[i].name .. ']] [[' .. reagentitem.materials[i].name .. ']]<br>')
end
 
row
:node(currency_cell(item.buy))
10,210

edits