Editing Module:AlchemistList

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
require('strict')
require('strict')
require('Module:Mw.html extension')
require('Module:Mw.html extension')
local search = require('Module:RecipeTreeSearch')
local recipe = require('Module:Infobox Recipe') -- to make use of its extensive material searching function
local param = require( 'Module:Paramtest' )
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local currency = require('Module:Currency')
Line 51: Line 51:
function p.formatResults(results)
function p.formatResults(results)


-- iterate through products
-- iterate through potions
for _, item in ipairs(results) do
for _, item in ipairs(results) do
-- New module for recipe searching
-- recipe in a workable format
local fullRecipe = search.main(item.name)
local unpackJSON = mw.text.jsonDecode(item.recipeJSON)
item.materials = fullRecipe.materials
item.outputQuantity = unpackJSON.output[1].quantity

item.outputQuantity = fullRecipe.output[1].quantity
-- call the module:infobox recipe to extensively search for
item.buy = fullRecipe.buyPrice
-- all raw materials (to add to prices)
item.XP = fullRecipe.xp
-- all intermediate materials (for intermediate XP and duration)
item.duration = fullRecipe.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 _, reagent in ipairs(item.reagents) do
--shamelessley lifted from Module:Products
local shopPriceQuery = '[[:+]][[Sold item::' .. reagent.name .. ']]|?Shop buy price|mainlabel=' .. reagent.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 * 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

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
-- direct values
Line 71: Line 134:
local downtime = 40
local downtime = 40
item.duration = item.duration and item.duration + downtime/batchSize
item.duration = item.duration and item.duration + downtime/batchSize
item.productPerHour = item.duration and 1 / item.duration * 3600
item.potionPerHour = item.duration and 1 / item.duration * 3600


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


Line 91: Line 154:
:tag('th')
:tag('th')
:attr{ colspan = '3' }
:attr{ colspan = '3' }
:wikitext('Product')
:wikitext('Potion')
:done()
:done()
:tag('th')
:tag('th')
:wikitext('Materials')
:wikitext('Reagents')
:done()
:done()
:tag('th')
:tag('th')
Line 155: Line 218:
:done()
:done()


local materialCell = row:tag('td')
local reagentCell = row:tag('td')


for i, _ in ipairs(item.materials) do
for i, _ in ipairs(item.reagents) do
materialCell:wikitext(item.materials[i].quantity .. '&times; [[File:' .. item.materials[i].name .. '.png|18px|link=' .. item.materials[i].name .. ']] [[' .. item.materials[i].name .. ']]<br>')
reagentCell:wikitext(item.reagents[i].quantity .. '&times; [[File:' .. item.reagents[i].name .. '.png|18px|link=' .. item.reagents[i].name .. ']]' .. '[[' .. item.reagents[i].name .. ']]<br>')
end
end
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see Brighter Shores:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

This page is a member of a hidden category: