Module:AlchemistPassiveList: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(remove dependency on Module:Infobox Recipe, as it does not need the recursive recipe finding subroutine)
m (change "potion" to "product" and "reagent" to "material" so it matches all the other crafting profession tables. functionality unchanged.)
Line 57: Line 57:
function p.formatResults(results)
function p.formatResults(results)


-- iterate through potions
-- iterate through products
for _, item in ipairs(results) do
for _, item in ipairs(results) do
Line 66: Line 66:
-- some fields are easy to work out
-- some fields are easy to work out
item.outputQuantity = 1
item.outputQuantity = 1
item.reagents = {}
item.materials = {}
item.intermediates = {}
item.intermediates = {}
item.buy = 0
item.buy = 0
Line 79: Line 79:
-- do not need to extensively search for subrecipes, as passive recipe
-- do not need to extensively search for subrecipes, as passive recipe
-- passive recipes only ever have one step
-- passive recipes only ever have one step
item.reagents = unpackJSON.materials
item.materials = unpackJSON.materials
-- iterate through reagents, adding buy price to running total (individuals not needed)
-- iterate through materials, adding buy price to running total (individuals not needed)
item.buy = 0
item.buy = 0
for _, reagent in ipairs(item.reagents) do
for _, material in ipairs(item.materials) do
--shamelessley lifted from Module:Products
--shamelessley lifted from Module:Products
local shopPriceQuery = '[[:+]][[Sold item::' .. reagent.name .. ']]|?Shop buy price|mainlabel=' .. reagent.name
local shopPriceQuery = '[[:+]][[Sold item::' .. material.name .. ']]|?Shop buy price|mainlabel=' .. material.name
local shopPriceResult = mw.smw.ask(shopPriceQuery) or {}
local shopPriceResult = mw.smw.ask(shopPriceQuery) or {}
local shopPrice = 0
local shopPrice = 0
Line 96: Line 96:
end
end
item.buy = item.buy and item.buy + shopPrice * reagent.quantity
item.buy = item.buy and item.buy + shopPrice * material.quantity
end
end
Line 107: Line 107:
item.profitPerXP = item.profit and item.XP and math.floor(item.profit / item.XP * 100) / 100
item.profitPerXP = item.profit and item.XP and math.floor(item.profit / item.XP * 100) / 100


-- potions made in 200 lots of 0.005, no downtime for passive activities
-- products made in 200 lots of 0.005, no downtime for passive activities
local batchSize = 200
local batchSize = 200
local downtime = 0
local downtime = 0
item.duration = item.duration and item.duration + downtime/batchSize
item.duration = item.duration and item.duration + downtime/batchSize
item.potionPerHour = item.duration and 1 / item.duration * 3600
item.productPerHour = item.duration and 1 / item.duration * 3600


-- properties per hour
-- properties per hour
item.XPPerHour = item.XP and item.potionPerHour and math.floor(item.XP * item.potionPerHour)
item.XPPerHour = item.XP and item.productPerHour and math.floor(item.XP * item.productPerHour)
item.profitPerHour = item.profit and item.potionPerHour and math.floor(item.profit * item.potionPerHour)
item.profitPerHour = item.profit and item.productPerHour and math.floor(item.profit * item.productPerHour)
end
end


Line 131: Line 131:
:tag('th')
:tag('th')
:attr{ colspan = '3' }
:attr{ colspan = '3' }
:wikitext('Potion')
:wikitext('Product')
:done()
:done()
:tag('th')
:tag('th')
:wikitext('Reagents')
:wikitext('Materials')
:done()
:done()
:tag('th')
:tag('th')
Line 197: Line 197:
:IF(not(item.passiveActivity))
:IF(not(item.passiveActivity))


local reagentCell = row:tag('td')
local materialCell = row:tag('td')
for i, _ in ipairs(item.reagents) do
for i, _ in ipairs(item.materials) do
reagentCell:wikitext(item.reagents[i].quantity .. '&times; [[File:' .. item.reagents[i].name .. '.png|18px|link=' .. item.reagents[i].name .. ']] [[' .. item.reagents[i].name .. ']]<br>')
materialCell:wikitext(item.materials[i].quantity .. '&times; [[File:' .. item.materials[i].name .. '.png|18px|link=' .. item.materials[i].name .. ']] [[' .. item.materials[i].name .. ']]<br>')
end
end