Anonymous

Module:Calculator/ItemEconomy: Difference between revisions

From Melvor Idle
Implement Economy module changes
m (Replace Shared module with Number module)
(Implement Economy module changes)
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(itemAmount, pChance, dChance, eChance)
local function calculateOutput(target, itemEconomy)
local estimatedOutput = eco.estimatedOutput(itemAmount, pChance, dChance, eChance)
local estimatedOutput = eco.estimatedOutput(target, itemEconomy)
local canUseRoW = eco.ringOfWealthHasEffect(pChance, dChance, eChance)
local useRoW = eco.ringOfWealthHasEffect(itemEconomy)
return math.floor(estimatedOutput), canUseRoW
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(itemAmount, pChance, dChance, eChance)
local function calculateInput(target, itemEconomy)
local estimatedInput = eco.estimatedInput(itemAmount, pChance, dChance, eChance)
local estimatedInput = eco.estimatedInput(target, itemEconomy)
local useRoW = eco.ringOfWealthHasEffect(itemEconomy)
local baseModifier = eco.estimatedInput(1, pChance, dChance, eChance)
local rowModifier = eco.estimatedInput(1, pChance - 3, dChance + 7, eChance)


return math.ceil(estimatedInput), rowModifier < baseModifier
return math.ceil(estimatedInput), useRoW
end
end


Line 64: Line 62:
end
end


local function createTable(userAmount, calcAmount, useRoW, ecoType)
local function createTable(userAmount, calcAmount, useRoW, ecoType, multiplier)
local RoWYN = useRoW and "Yes" or "No"
local RoWYN = useRoW and "Yes" or "No"
Line 90: Line 88:


function p._main(args)
function p._main(args)
local itemAmount = args.targetAmount
local target = args.targetAmount
local economyType = parseEconomy(args.economyType)
local economyType = parseEconomy(args.economyType)
 
local pChance = number.toNumberOrDefault(args.preservationChance, 0)
-- Create and fill ItemEconomy object.
local dChance = number.toNumberOrDefault(args.duplicationChance, 0)
local itemEconomy = eco.ItemEconomy:new()
local eChance = number.toNumberOrDefault(args.extraItemChance, 0)
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, 0)
itemEconomy.flatExtraItems = number.toNumberOrDefault(args.flatExtraItems, 0)
itemEconomy.extraBaseItemChance = number.toNumberOrDefault(args.extraBaseItemChance, 0)
itemEconomy.extraBaseItems = number.toNumberOrDefault(args.extraBaseItems, 0)
 
local result = 0
local result = 0
local row = false
local row = false
if economyType == ECOOUT then
if economyType == ECOOUT then
result, row = calculateOutput(itemAmount, pChance, dChance, eChance)
result, row = calculateOutput(target, itemEconomy)
else
else
result, row = calculateInput(itemAmount, pChance, dChance, eChance)
result, row = calculateInput(target, itemEconomy)
end
end


local tbl = createTable(itemAmount, result, row, economyType)
local tbl = createTable(target, result, row, economyType)
          
          
     return tostring(tbl)
     return tostring(tbl)
2,875

edits