Anonymous

Module:ItemEconomy/Sandbox: Difference between revisions

From Melvor Idle
no edit summary
(Rewrite output estimation functions)
 
No edit summary
Line 4: Line 4:


local ItemEconomy = {
local ItemEconomy = {
-- Amount of items required per action.
inputsPerAction,
-- Amount of items created per action. (ie. 3 bolts per action).
-- Amount of items created per action. (ie. 3 bolts per action).
itemsPerAction,
outputsPerAction,
-- The chance from 0 to 80 to preserve resources.
-- The chance from 0 to 80 to preserve resources.
preservationChance,
preservationChance,
Line 33: Line 35:
local function verifyEconomyValues(itemEconomy)
local function verifyEconomyValues(itemEconomy)
-- Set default values if some are nil
-- Set default values if some are nil
itemEconomy.itemsPerAction = itemEconomy.itemsPerAction or 1
itemEconomy.inputsPerAction = itemEconomy.inputsPerAction or 1
itemEconomy.outputsPerAction = itemEconomy.outputsPerAction or 1
     itemEconomy.preservationChance = itemEconomy.preservationChance or 0
     itemEconomy.preservationChance = itemEconomy.preservationChance or 0
     itemEconomy.duplicationChance = itemEconomy.duplicationChance or 0
     itemEconomy.duplicationChance = itemEconomy.duplicationChance or 0
Line 52: Line 55:


--- Estimates the output multiplier of a crafting process based on ItemEconomy values.
--- Estimates the output multiplier of a crafting process based on ItemEconomy values.
-- @param inputPerAction (number) The number of input items required per crafting action.
-- @param outputPerAction (number) The number of output items produced per crafting action.
-- @param itemEconomy (table) The ItemEconomy object containing ItemEconomy values.
-- @param itemEconomy (table) The ItemEconomy object containing ItemEconomy values.
-- @return (number) The estimated output multiplier of the crafting process.
-- @return (number) The estimated output multiplier of the crafting process.
function p.estimatedOutputMultiplier(inputPerAction, outputPerAction, itemEconomy)
function p.estimatedOutputMultiplier(itemEconomy)
-- Equal the inputAmount and inputPerAction, so the base action count is 1.
return p.estimatedOutput(nil, inputPerAction, outputPerAction, itemEconomy)
return p.estimatedOutput(inputPerAction, inputPerAction, outputPerAction, itemEconomy)
end
end


--- Estimates the output of a crafting process based on input and ItemEconomy values.
--- Estimates the output of a crafting process based on input and ItemEconomy values.
-- @param inputAmount (number) The total amount of input items available for crafting.
-- @param inputAmount (number) The total amount of input items available for crafting.
-- @param inputPerAction (number) The number of input items required per crafting action.
-- @param outputPerAction (number) The number of output items produced per crafting action.
-- @param itemEconomy (table) The ItemEconomy object containing ItemEconomy values.
-- @param itemEconomy (table) The ItemEconomy object containing ItemEconomy values.
-- @return (number) The estimated output of the crafting process.
-- @return (number) The estimated output of the crafting process.
function p.estimatedOutput(inputAmount, inputPerAction, outputPerAction, itemEconomy)
function p.estimatedOutput(inputAmount, itemEconomy)
eco = verifyEconomyValues(itemEconomy)
eco = verifyEconomyValues(itemEconomy)


inputPerAction = inputPerAction or 1
-- Equal inputAmount to inputsPerAction to get 1 baseAction
inputAmount = inputAmount or inputPerAction
inputAmount = inputAmount or eco.inputsPerAction
outputPerAction = outputPerAction or 1
baseActions = math.floor(inputAmount / eco.inputsPerAction)
baseActions = inputAmount / itemsPerAction
-- Calculate the effective actions taken.
-- Calculate the effective actions taken.
Line 83: Line 80:
-- Total output
-- Total output
local output = (1 + (eco.extraBaseItemChance * eco.extraBaseItems)) * (1 + eco.duplicationChance)
return (totalActions * baseItems * (1 + eco.duplicationChance)) + extraItems
end
end


Line 101: Line 98:
p.ItemEconomy = ItemEconomy
p.ItemEconomy = ItemEconomy


-- Test stuff....
function p.Test()
local eco = ItemEconomy:new()
return p.estimatedOutput()
end
return p
return p
2,875

edits