Module:Sandbox/User:Alsang/NodeDescriptionChecker: Difference between revisions

all needed functions, now need to decide how to shrink it
m (downtime for leatherworker)
(all needed functions, now need to decide how to shrink it)
Line 4:
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local discount = require('Module:MerchantHideDiscount')
local lang = mw.getContentLanguage()
 
Line 69 ⟶ 70:
-- do calculations and determine strings to go in cells
function p.formatResults(results)
local discountList = discount.main()
 
-- iterate through potionsproducts
for _, item in ipairs(results) do
Line 79 ⟶ 82:
-- some fields are easy to work out
item.outputQuantity = 1
item.reagentsmaterials = {}
item.intermediates = {}
item.buy = 0
Line 94 ⟶ 97:
local Materials = recipe._getTrueRawMaterials(unpackJSON.materials)
if next(Materials) ~= nil then
item.reagentsmaterials = Materials.rawMaterials
item.intermediates = Materials.intermediateMaterials
end
-- iterate through reagentsmaterials, adding buy price to running total (individuals not needed)
item.buy = 0
item.buyDiscount = 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 113 ⟶ 117:
end
item.buy = item.buy and item.buy + shopPrice * reagentmaterial.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
Line 161 ⟶ 178:
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.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.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
Line 168 ⟶ 189:
local downtime = 100
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)
item.profitPerHourDiscount = item.profitDiscount and item.productPerHour and math.floor(item.profitDiscount * item.productPerHour)
end
 
Line 188 ⟶ 210:
:tag('th')
:attr{ colspan = '3' }
:wikitext('PotionProduct')
:done()
:tag('th')
:wikitext('ReagentsMaterials')
:done()
:tag('th')
Line 210 ⟶ 232:
:done()
:tag('th')
:wikitext('[[File:Merchant_small_icon.png|18px]] level for<br> discount')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Profit/hr<br> with [[File:Merchant_small_icon.png|18px]] discount')
:done()
:tag('th')
Line 225 ⟶ 247:
:attr{ colspan = '10' }
:wikitext('Coins/XP')
:done()
:tag('th')
:attr{ colspan = '10' }
:wikitext('Coins/XP with [[File:Merchant_small_icon.png|18px]] discount')
:done()
:done()
Line 261 ⟶ 287:
:IF(not(item.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|30px|link=' .. item.reagentsmaterials[i].name .. ']]' .. '[[' .. item.reagentsmaterials[i].name .. ']]<br>')
end
Line 285 ⟶ 311:
:tag('td')
:css{ ['text-align'] = 'center' }
:wikitext('???'item.discountLevel)
:done()
:node(currency_cell(item.profitPerHourprofitPerHourDiscount))
 
:IF(item.XP)
Line 306 ⟶ 332:
 
:node(currency_cell(item.profitPerXP))
:node(currency_cell(item.profitPerXPDiscount))
 
:done()
21,283

edits