2,875
edits
(First version) |
m (Fix nil exceptions) |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function | local function clamp(value, min, max) | ||
return math.min(math.max(value, min), max) | return math.min(math.max(value, min), max) | ||
end | end | ||
Line 18: | Line 18: | ||
-- Clamp values and turn them into decimals | -- Clamp values and turn them into decimals | ||
local preservationP = | local preservationP = clamp(preservationChance, 0, 80) / 100 | ||
local duplicationP = | local duplicationP = clamp(duplicationChance, 0, 100) / 100 | ||
local extraItemP = math.max(extraItemChance, 0) / 100 | local extraItemP = math.max(extraItemChance, 0) / 100 | ||
local input = inputAmount | local input = inputAmount or 0 | ||
local totalActions = input / (1 - preservationP) | local totalActions = input / (1 - preservationP) | ||
Line 42: | Line 42: | ||
extraItemChance = extraItemChance or 0 | extraItemChance = extraItemChance or 0 | ||
local preservationP = | local preservationP = clamp(preservationChance, 0, 80) / 100 | ||
local duplicationP = | local duplicationP = clamp(duplicationChance, 0, 100) / 100 | ||
local extraItemP = math.max(extraItemChance, 0) / 100 | local extraItemP = math.max(extraItemChance, 0) / 100 | ||
local output = | local output = outputAmount or 0 | ||
return (output - output * preservationP) / (1 + duplicationP + extraItemP) | return (output - output * preservationP) / (1 + duplicationP + extraItemP) |
edits