Module:AlchemistPassiveList: Difference between revisions

m
Alsang moved page Module:PassivePotionList to Module:AlchemistPassiveList without leaving a redirect: match the naming convention of the other "List" modules
(change code base to match PotionList which uses extensive search for all subreceipes and reagents, but keep it showing non-recipe passive activities)
m (Alsang moved page Module:PassivePotionList to Module:AlchemistPassiveList without leaving a redirect: match the naming convention of the other "List" modules)
 
(5 intermediate revisions by 2 users not shown)
Line 1:
require('strict')
require('Module:Mw.html extension')
local recipe = require('Module:Infobox Recipe') -- to make use of its extensive material searching function
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
Line 14 ⟶ 13:
local query = {
'[[Uses facility::Passive Potion Station]] OR [[Variant of::Ebsworth Work]]',
'?Variant of #- = variant',
'?Profession Level A = lvl',
'? #- = name',
Line 19:
'?Activity XP = XP',
'?Activity duration = duration',
'?Activity coins = coins',
'?Variant of #- = variant',
'?Value = sell',
'?Activity coins = coins',
'sort = Profession Level A',
'limit = 500'
}
local results = mw.smw.ask(query)
 
-- criterion for if an entry is a recipe, or a passive activity
for _, item in ipairs(results) do
item.passiveActivity = item.variant=='Ebsworth Work'
end
results = p.formatResults(results)
 
Line 53 ⟶ 57:
function p.formatResults(results)
 
-- iterate through potionsproducts
for _, item in ipairs(results) do
-- recipe in a workable format
if item.variant=='Ebsworth Work'passiveActivity then
-- if it is ebswortha work,passive subactivity inthat differentis fieldsnot fora the buy and sell valuesrecipe
-- some fields are easy to work out
item.outputQuantity = 1
item.reagentsmaterials = {}
item.intermediates = {}
item.buy = 0
item.sell = item.coins
 
else
local unpackJSON = mw.text.jsonDecode(item.recipeJSON)
item.outputQuantity = unpackJSON.output[1].quantity
-- SECTION REMOVED
-- do not need to extensively search for subrecipes, as passive recipe
-- passive recipes only ever have one step
item.materials = unpackJSON.materials
-- iterate through reagentsmaterials, adding buy price to running total (individuals not needed)
-- call the module:infobox recipe to extensively search for
-- all raw materials (to add to prices)
-- all intermediate materials (for intermediate XP and duration)
local Materials = recipe._getTrueRawMaterials(unpackJSON.materials)
if next(Materials) ~= nil then
item.reagents = Materials.rawMaterials
item.intermediates = Materials.intermediateMaterials
end
-- iterate through reagents, adding buy price to running total (individuals not needed)
item.buy = 0
for _, reagentmaterial in ipairs(item.reagentsmaterials) do
--shamelessley lifted from Module:Products
local shopPriceQuery = '[[:+]][[Sold item::' .. reagentmaterial.name .. ']]|?Shop buy price|mainlabel=' .. reagentmaterial.name
local shopPriceResult = mw.smw.ask(shopPriceQuery) or {}
local shopPrice = 0
Line 93 ⟶ 94:
else
item.buy = nil
end
item.buy = item.buy and item.buy + shopPrice * reagent.quantity
end
-- iterate through intermediaries to add to XP and duration parameters
for _, intermediate in ipairs(item.intermediates) do
-- look up activity XP and add it to running total
local XPQuery = '[[Recipe output::' .. intermediate.name .. ']]|?Activity XP|mainlabel=' .. intermediate.name
local XPResult = mw.smw.ask(XPQuery) or {}
local XPIncrease = 0
if XPResult[1] and XPResult[1]["Activity XP"] then
XPIncrease = tonumber(XPResult[1]["Activity XP"]) or 0
else
XPIncrease = nil
end
-- need to look up both the amount of the item used in this recipe and created in its own recipe to know how much of this xp to use
local QTYused = intermediate.quantity
item.buy = item.buy and item.buy + shopPrice * reagentmaterial.quantity
local QTYQuery = '[[Recipe output::' .. intermediate.name .. ']]|?Recipe JSON|mainlabel=' .. intermediate.name
local QTYResult = mw.smw.ask(QTYQuery) or {}
local QTYmade = 0
if QTYResult[1] and QTYResult[1]["Recipe JSON"] then
QTYmade = mw.text.jsonDecode(QTYResult[1]["Recipe JSON"]) or {}
end
QTYmade = QTYmade.output[1].quantity
item.XP = item.XP and XPIncrease and item.XP + XPIncrease * QTYused / QTYmade;
-- look up activity duration and add it to running total
local durationQuery = '[[Recipe output::' .. intermediate.name .. ']]|?Activity duration|mainlabel=' .. intermediate.name
local durationResult = mw.smw.ask(durationQuery) or {}
local durationIncrease = 0
if durationResult[1] and durationResult[1]["Activity duration"] then
durationIncrease = tonumber(durationResult[1]["Activity duration"]) or 0
else
durationIncrease = nil
end
item.duration = item.duration and durationIncrease and item.duration + durationIncrease * intermediate.quantity
end
Line 145 ⟶ 107:
item.profitPerXP = item.profit and item.XP and math.floor(item.profit / item.XP * 100) / 100
 
-- potionsproducts made in 200 lots of 0.005, no downtime for passive activities
local batchSize = 200
local downtime = 0
item.duration = item.duration and item.duration + 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.profitPerHour = item.profit and item.potionPerHourproductPerHour and math.floor(item.profit * item.potionPerHourproductPerHour)
end
 
Line 169 ⟶ 131:
:tag('th')
:attr{ colspan = '3' }
:wikitext('PotionProduct')
:done()
:tag('th')
:wikitext('ReagentsMaterials')
:done()
:tag('th')
Line 233 ⟶ 195:
:done()
:IF(not(item.variant=='Ebsworth Work'passiveActivity))
 
local reagentCellmaterialCell = row:tag('td')
for i, _ in ipairs(item.reagentsmaterials) do
reagentCellmaterialCell:wikitext(item.reagentsmaterials[i].quantity .. '&times; [[File:' .. item.reagentsmaterials[i].name .. '.png|18px|link=' .. item.reagentsmaterials[i].name .. ']]' .. '[[' .. item.reagentsmaterials[i].name .. ']]<br>')
end
10,210

edits