Module:AlchemistList: Difference between revisions

2,709 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 (change "potion" to "product" and "reagent" to "material" so it matches all the other crafting profession tables. functionality unchanged.)
m (Alsang moved page Module:PotionList to Module:AlchemistList without leaving a redirect: match the naming convention of the other "List" modules)
 
(One intermediate revision by the same user not shown)
Line 1:
require('strict')
require('Module:Mw.html extension')
local recipesearch = require('Module:Infobox RecipeRecipeTreeSearch') -- to make use of its extensive material searching function
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
Line 54:
for _, item in ipairs(results) do
-- recipeNew inmodule afor workablerecipe formatsearching
local unpackJSONfullRecipe = mwsearch.text.jsonDecodemain(item.recipeJSONname)
item.outputQuantitymaterials = unpackJSONfullRecipe.output[1].quantitymaterials
QTYmadeitem.outputQuantity = QTYmadefullRecipe.output[1].quantity
 
item.buy = 0fullRecipe.buyPrice
-- call the module:infobox recipe to extensively search for
item.XP = fullRecipe.xp
-- all raw materials (to add to prices)
item.duration = fullRecipe.duration
-- all intermediate materials (for intermediate XP and duration)
local Materials = recipe._getTrueRawMaterials(unpackJSON.materials)
if next(Materials) ~= nil then
item.materials = Materials.rawMaterials
item.intermediates = Materials.intermediateMaterials
end
-- iterate through materials, adding buy price to running total (individuals not needed)
item.buy = 0
for _, material in ipairs(item.materials) do
--shamelessley lifted from Module:Products
local shopPriceQuery = '[[:+]][[Sold item::' .. material.name .. ']]|?Shop buy price|mainlabel=' .. material.name
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
else
item.buy = nil
end
 
item.buy = item.buy and item.buy + shopPrice * material.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
 
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
-- direct values
10,210

edits