Module:ItemEconomy: Difference between revisions
From Melvor Idle
m (Fix nil exceptions) |
m (Replace Shared module with Number module) |
||
Line 1: | Line 1: | ||
local number = require('Module:Number') | |||
local p = {} | local p = {} | ||
-- | -- | ||
Line 18: | Line 16: | ||
-- Clamp values and turn them into decimals | -- Clamp values and turn them into decimals | ||
local preservationP = clamp(preservationChance, 0, 80) / 100 | local preservationP = number.clamp(preservationChance, 0, 80) / 100 | ||
local duplicationP = clamp(duplicationChance, 0, 100) / 100 | local duplicationP = number.clamp(duplicationChance, 0, 100) / 100 | ||
local extraItemP = math.max(extraItemChance, 0) / 100 | local extraItemP = math.max(extraItemChance, 0) / 100 | ||
Line 42: | Line 40: | ||
extraItemChance = extraItemChance or 0 | extraItemChance = extraItemChance or 0 | ||
local preservationP = clamp(preservationChance, 0, 80) / 100 | local preservationP = number.clamp(preservationChance, 0, 80) / 100 | ||
local duplicationP = clamp(duplicationChance, 0, 100) / 100 | local duplicationP = number.clamp(duplicationChance, 0, 100) / 100 | ||
local extraItemP = math.max(extraItemChance, 0) / 100 | local extraItemP = math.max(extraItemChance, 0) / 100 | ||
Revision as of 22:15, 12 March 2024
Documentation for this module may be created at Module:ItemEconomy/doc
local number = require('Module:Number')
local p = {}
--
-- Calculates the expected output given the player's starting items and item economy modifiers.
-- PreservationChance (number from 0 - 80)
-- DuplicationChance (number from 0 - 100)
-- ExtraItemChance (number from 0 - ?)
--
function p.estimatedOutput(inputAmount, preservationChance, duplicationChance, extraItemChance)
-- Default values to zero if they haven't been provided.
preservationChance = preservationChance or 0
duplicationChance = duplicationChance or 0
extraItemChance = extraItemChance or 0
-- Clamp values and turn them into decimals
local preservationP = number.clamp(preservationChance, 0, 80) / 100
local duplicationP = number.clamp(duplicationChance, 0, 100) / 100
local extraItemP = math.max(extraItemChance, 0) / 100
local input = inputAmount or 0
local totalActions = input / (1 - preservationP)
local extraItems = totalActions * extraItemP
return (totalActions * (1 + duplicationP)) + extraItems
end
--
-- Calculates the expected input required for an output given the player's item economy modifiers.
-- PreservationChance (number from 0 - 80)
-- DuplicationChance (number from 0 - 100)
-- ExtraItemChance (number from 0 - ?)
--
function p.estimatedInput(outputAmount, preservationChance, duplicationChance, extraItemChance)
-- Default values to zero if they haven't been provided.
preservationChance = preservationChance or 0
duplicationChance = duplicationChance or 0
extraItemChance = extraItemChance or 0
local preservationP = number.clamp(preservationChance, 0, 80) / 100
local duplicationP = number.clamp(duplicationChance, 0, 100) / 100
local extraItemP = math.max(extraItemChance, 0) / 100
local output = outputAmount or 0
return (output - output * preservationP) / (1 + duplicationP + extraItemP)
end
--
-- Calculates if equipping the Ring Of Wealth will result in more items for the player.
-- PreservationChance (number from 0 - 80)
-- DuplicationChance (number from 0 - 100)
-- ExtraItemChance (number from 0 - ?)
--
function p.ringOfWealthHasEffect(preservationChance, duplicationChance, extraItemChance)
-- Default values to zero if they haven't been provided.
preservationChance = preservationChance or 0
duplicationChance = duplicationChance or 0
extraItemChance = extraItemChance or 0
local currentModifier = p.estimatedOutput(1, preservationChance, duplicationChance, extraItemChance)
local rowPreserve = math.max(0, preservationChance - 3)
local rowDupe = math.min(100, duplicationChance + 7)
local rowModifier = p.estimatedOutput(1, rowPreserve, rowDupe, extraItemChance)
return rowModifier > currentModifier
end
return p