Module:Supercompost profit calculator
Documentation for this module may be created at Module:Supercompost profit calculator/doc
local Coins = require( 'Module:Coins' )
local gePrice = require('Module:Exchange')._price
local p = {}
local bin = 15
local bigBin = 30
function p.invoke_main( frame )
return p.main(frame:getParent().args.ingredient, frame:getParent().args.cocomilk_offset, frame:getParent().args.bucket_offset, frame:getParent().args.grimy_herbs)
end
function p.main( item, cocomilk, bucket, grimy )
--List of herbs--
local herbs = { "Avantoe", "Cadantine", "Dwarf weed", "Kwuarm", "Lantadyme", "Snapdragon", "Toadflax", "Torstol"}
--Gets cost of ingredients and value of a bin/big bin of compost
if item == 'Coconut shell' and cocomilk == 'true' then
price = gePrice('Coconut') + gePrice('Vial') - gePrice('Coconut milk')
elseif item == 'Coconut shell' then
price = gePrice('Coconut')
elseif item == 'White tree fruit' or item == 'Tenti pineapple' or item == nil then
price = 0
elseif grimy == 'true' then
price = gePrice(item)
for i, h in ipairs(herbs) do
if item == h then
price = gePrice("Grimy " .. item:lower())
break
end
end
else
price = gePrice(item)
end
--Calculates profits
local superPrice = gePrice('Supercompost')
local profit = (superPrice * bin) - (price * bin)
local bigProfit = (superPrice * bigBin) - (price * bigBin)
if bucket == 'true' then
bucketPrice = gePrice('Bucket')
profit = profit - bucketPrice
bigProfit = bigProfit - bucketPrice
end
return p.resultsTable({(price * bin), (price * bigBin), profit, bigProfit})
end
--Creates table
function p.resultsTable(results)
local resultsTable = mw.html.create('table')
local header = mw.html.create('tr')
header:tag( 'th' )
:wikitext( '<small>Cost and profit<br/>per bin and big bin</small>' )
:done()
:tag( 'th' )
:wikitext( 'Cost' )
:done()
:tag( 'th' )
:wikitext( 'Profit' )
:done()
local bin = mw.html.create('tr')
bin:tag( 'th' )
:tag( 'b' )
:wikitext( 'Bin' )
:done()
:tag( 'td' )
:wikitext(Coins._amount(results[1] * -1))
:done()
:tag( 'td' )
:wikitext(Coins._amount(results[3]))
:done()
local bigbin = mw.html.create('tr')
bigbin:tag( 'th' )
:tag( 'b' )
:wikitext( 'Big bin' )
:done()
:tag( 'td' )
:wikitext(Coins._amount(results[2] * -1))
:done()
:tag( 'td' )
:wikitext(Coins._amount(results[4]))
:done()
resultsTable:addClass( 'wikitable' ):addClass( 'align-center-1' )
:node(header)
:node(bin)
:node(bigbin)
:done()
return resultsTable
end
return p