Module:Sandbox/User:Alsang/NodeDescriptionChecker: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (downtime for leatherworker) |
(all needed functions, now need to decide how to shrink it) |
||
Line 4: | Line 4: | ||
local param = require( 'Module:Paramtest' ) |
local param = require( 'Module:Paramtest' ) |
||
local currency = require('Module:Currency') |
local currency = require('Module:Currency') |
||
local discount = require('Module:MerchantHideDiscount') |
|||
local lang = mw.getContentLanguage() |
local lang = mw.getContentLanguage() |
||
Line 69: | Line 70: | ||
-- do calculations and determine strings to go in cells |
-- do calculations and determine strings to go in cells |
||
function p.formatResults(results) |
function p.formatResults(results) |
||
local discountList = discount.main() |
|||
-- iterate through |
-- iterate through products |
||
for _, item in ipairs(results) do |
for _, item in ipairs(results) do |
||
Line 79: | Line 82: | ||
-- some fields are easy to work out |
-- some fields are easy to work out |
||
item.outputQuantity = 1 |
item.outputQuantity = 1 |
||
item. |
item.materials = {} |
||
item.intermediates = {} |
item.intermediates = {} |
||
item.buy = 0 |
item.buy = 0 |
||
Line 94: | Line 97: | ||
local Materials = recipe._getTrueRawMaterials(unpackJSON.materials) |
local Materials = recipe._getTrueRawMaterials(unpackJSON.materials) |
||
if next(Materials) ~= nil then |
if next(Materials) ~= nil then |
||
item. |
item.materials = Materials.rawMaterials |
||
item.intermediates = Materials.intermediateMaterials |
item.intermediates = Materials.intermediateMaterials |
||
end |
end |
||
-- iterate through |
-- iterate through materials, adding buy price to running total (individuals not needed) |
||
item.buy = 0 |
item.buy = 0 |
||
item.buyDiscount = 0 |
|||
for _, |
for _, material in ipairs(item.materials) do |
||
--shamelessley lifted from Module:Products |
--shamelessley lifted from Module:Products |
||
local shopPriceQuery = '[[:+]][[Sold item::' .. |
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 113: | Line 117: | ||
end |
end |
||
item.buy = item.buy and item.buy + shopPrice * |
item.buy = item.buy and item.buy + shopPrice * material.quantity |
||
--with the merchant discount, buy price is sell price |
|||
local shopPriceQuery = '[[:+]][[Sold item::' .. material.name .. ']]|?Shop sell price|mainlabel=' .. material.name |
|||
local shopPriceResult = mw.smw.ask(shopPriceQuery) or {} |
|||
local shopPrice = 0 |
|||
if shopPriceResult[1] and shopPriceResult[1]["Shop sell price"] then |
|||
shopPrice = tonumber(shopPriceResult[1]["Shop sell price"]) or 0 |
|||
else |
|||
item.buyDiscount = nil |
|||
end |
|||
item.buyDiscount = item.buyDiscount and item.buyDiscount + shopPrice * material.quantity |
|||
end |
end |
||
Line 161: | Line 178: | ||
item.sell = item.sell and item.outputQuantity and item.sell * item.outputQuantity |
item.sell = item.sell and item.outputQuantity and item.sell * item.outputQuantity |
||
item.profit = item.sell and item.buy and item.sell - item.buy |
item.profit = item.sell and item.buy and item.sell - item.buy |
||
item.profitDiscount = item.sell and item.buyDiscount and item.sell - item.buyDiscount |
|||
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 |
||
item.profitPerXPDiscount = item.profitDiscount and item.XP and math.floor(item.profitDiscount / item.XP * 100) / 100 |
|||
local hideName = string.gsub(item.name,'Leather','Hide') |
|||
item.discountLevel = discountList[hideName] |
|||
-- a lot of downtime in leatherworker |
-- a lot of downtime in leatherworker |
||
Line 168: | Line 189: | ||
local downtime = 100 |
local downtime = 100 |
||
item.duration = item.duration and item.duration + downtime/batchSize |
item.duration = item.duration and item.duration + downtime/batchSize |
||
item. |
item.productPerHour = item.duration and 1 / item.duration * 3600 |
||
-- properties per hour |
-- properties per hour |
||
item.XPPerHour = item.XP and item. |
item.XPPerHour = item.XP and item.productPerHour and math.floor(item.XP * item.productPerHour) |
||
item.profitPerHour = item.profit and item. |
item.profitPerHour = item.profit and item.productPerHour and math.floor(item.profit * item.productPerHour) |
||
item.profitPerHourDiscount = item.profitDiscount and item.productPerHour and math.floor(item.profitDiscount * item.productPerHour) |
|||
end |
end |
||
Line 188: | Line 210: | ||
:tag('th') |
:tag('th') |
||
:attr{ colspan = '3' } |
:attr{ colspan = '3' } |
||
:wikitext(' |
:wikitext('Product') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext(' |
:wikitext('Materials') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
Line 210: | Line 232: | ||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:wikitext('[[File:Merchant_small_icon.png|18px]] level for |
:wikitext('[[File:Merchant_small_icon.png|18px]] level for discount') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
:attr{ colspan = '10' } |
:attr{ colspan = '10' } |
||
:wikitext('Profit/hr |
:wikitext('Profit/hr with [[File:Merchant_small_icon.png|18px]] discount') |
||
:done() |
:done() |
||
:tag('th') |
:tag('th') |
||
Line 225: | Line 247: | ||
:attr{ colspan = '10' } |
:attr{ colspan = '10' } |
||
:wikitext('Coins/XP') |
:wikitext('Coins/XP') |
||
:done() |
|||
:tag('th') |
|||
:attr{ colspan = '10' } |
|||
:wikitext('Coins/XP with [[File:Merchant_small_icon.png|18px]] discount') |
|||
:done() |
:done() |
||
:done() |
:done() |
||
Line 261: | Line 287: | ||
:IF(not(item.passiveActivity)) |
:IF(not(item.passiveActivity)) |
||
local |
local materialCell = row:tag('td') |
||
for i, _ in ipairs(item. |
for i, _ in ipairs(item.materials) do |
||
materialCell:wikitext(item.materials[i].quantity .. '× [[File:' .. item.materials[i].name .. '.png|30px|link=' .. item.materials[i].name .. ']]' .. '[[' .. item.materials[i].name .. ']]<br>') |
|||
end |
end |
||
Line 285: | Line 311: | ||
:tag('td') |
:tag('td') |
||
:css{ ['text-align'] = 'center' } |
:css{ ['text-align'] = 'center' } |
||
:wikitext( |
:wikitext(item.discountLevel) |
||
:done() |
:done() |
||
:node(currency_cell(item. |
:node(currency_cell(item.profitPerHourDiscount)) |
||
:IF(item.XP) |
:IF(item.XP) |
||
Line 306: | Line 332: | ||
:node(currency_cell(item.profitPerXP)) |
:node(currency_cell(item.profitPerXP)) |
||
:node(currency_cell(item.profitPerXPDiscount)) |
|||
:done() |
:done() |