918
edits
m (Numberic formatting) |
m (Chance extra item amounts to 1 by default instead of 0) |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | local number = require('Module:Number') | ||
local eco = require("Module:ItemEconomy") | local eco = require("Module:ItemEconomy") | ||
Line 24: | Line 24: | ||
-- Returns the estimated output items and TRUE/FALSE if the Ring of Wealth has a benefit. | -- Returns the estimated output items and TRUE/FALSE if the Ring of Wealth has a benefit. | ||
-- | -- | ||
local function calculateOutput( | local function calculateOutput(target, itemEconomy) | ||
local estimatedOutput = eco.estimatedOutput( | local estimatedOutput = eco.estimatedOutput(target, itemEconomy) | ||
local | local useRoW = eco.ringOfWealthHasEffect(itemEconomy) | ||
return estimatedOutput, | return math.floor(estimatedOutput), useRoW | ||
end | end | ||
Line 34: | Line 34: | ||
-- Returns the estimated input items and TRUE/FALSE if the Ring of Wealth has a benefit. | -- Returns the estimated input items and TRUE/FALSE if the Ring of Wealth has a benefit. | ||
-- | -- | ||
local function calculateInput( | local function calculateInput(target, itemEconomy) | ||
local estimatedInput = eco.estimatedInput( | local estimatedInput = eco.estimatedInput(target, itemEconomy) | ||
local useRoW = eco.ringOfWealthHasEffect(itemEconomy) | |||
local | |||
return | return math.ceil(estimatedInput), useRoW | ||
end | end | ||
Line 51: | Line 49: | ||
end | end | ||
local function createTable(target, calcAmount, useRoW, ecoType, multiplier) | |||
local function createTable( | |||
local RoWYN = useRoW and "Yes" or "No" | local RoWYN = useRoW and "Yes" or "No" | ||
Line 71: | Line 56: | ||
if ecoType == ECOIN then | if ecoType == ECOIN then | ||
addTableRow(tbl, "Desired Output", | addTableRow(tbl, "Desired Output", number.formatnum(target)) | ||
addTableRow(tbl, "Estimated Input", | addTableRow(tbl, "Estimated Input", number.formatnum(calcAmount)) | ||
else | else | ||
addTableRow(tbl, "Starting Items", | addTableRow(tbl, "Starting Items", number.formatnum(target)) | ||
addTableRow(tbl, "Estimated Output", | addTableRow(tbl, "Estimated Output", number.formatnum(calcAmount)) | ||
end | end | ||
addTableRow(tbl, "Economy Factor", | addTableRow(tbl, "Economy Factor", string.format("x%.2f", multiplier)) | ||
addTableRow(tbl, "[[Ring of Wealth]] benefits", RoWYN) | addTableRow(tbl, "[[Ring of Wealth]] benefits", RoWYN) | ||
Line 90: | Line 75: | ||
function p._main(args) | function p._main(args) | ||
local | local target = number.toNumberOrDefault(args.targetAmount, 0) | ||
local economyType = parseEconomy(args.economyType) | local economyType = parseEconomy(args.economyType) | ||
local | -- Create and fill ItemEconomy object. | ||
local itemEconomy = eco.ItemEconomy:new() | |||
itemEconomy.inputsPerAction = number.toNumberOrDefault(args.inputsPerAction, 1) | |||
itemEconomy.outputsPerAction = number.toNumberOrDefault(args.outputsPerAction, 1) | |||
itemEconomy.preservationChance = number.toNumberOrDefault(args.preservationChance, 0) | |||
itemEconomy.duplicationChance = number.toNumberOrDefault(args.duplicationChance, 0) | |||
itemEconomy.extraItemChance = number.toNumberOrDefault(args.extraItemChance, 0) | |||
itemEconomy.extraItemAmount = number.toNumberOrDefault(args.extraItemAmount, 1) | |||
itemEconomy.flatExtraItems = number.toNumberOrDefault(args.flatExtraItems, 0) | |||
itemEconomy.extraBaseItemChance = number.toNumberOrDefault(args.extraBaseItemChance, 0) | |||
itemEconomy.extraBaseItems = number.toNumberOrDefault(args.extraBaseItems, 1) | |||
local result = 0 | local result = 0 | ||
local row = false | local row = false | ||
if economyType == ECOOUT then | if economyType == ECOOUT then | ||
result, row = calculateOutput( | result, row = calculateOutput(target, itemEconomy) | ||
else | else | ||
result, row = calculateInput( | result, row = calculateInput(target, itemEconomy) | ||
end | end | ||
local tbl = createTable( | local multiplier = eco.estimatedOutputMultiplier(itemEconomy) | ||
local tbl = createTable(target, result, row, economyType, multiplier) | |||
return tostring(tbl) | return tostring(tbl) |
edits