new
(
)
__gc
(
)
__eq
(
am.stat_modifiers
modifiers
)
->
(
boolean
)
add
(
string
stat_name
,
number
value
,
string
modifier_type
,
boolean
magical
= true
)
->
(
integer
)
add
(
am.stat_modifiers
mods
)
->
(
integer
)
add
(
string
stat_name
,
StatModifier
mod
)
->
(
integer
)
remove
(
string
stat_name
,
number
value
,
string
modifier_type
,
boolean
magical
= true
)
->
(
integer
)
remove
(
am.stat_modifiers
mods
)
->
(
integer
)
remove
(
string
stat_name
,
StatModifier
mod
)
->
(
integer
)
mods
(
)
->
(
table
)
calculate_stat
(
string
stat_name
,
number
baseValue
)
->
(
number
)
new
(
)
__gc
(
)
__eq
(
am.stat_modifiers
modifiers
)
->
(
boolean
)
add
(
string
stat_name
,
number
value
,
string
modifier_type
,
boolean
magical
= true
)
->
(
integer
)
mods = am.stat_modifiers.new() base_health = 5 mods:add("health", 4, "+") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 9 (5 + 4) mods:add("health", 3, "*") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 19 (5 * 3 + 4) mods:add("health", 7, "=") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 25 (7 * 3 + 4)
add
(
am.stat_modifiers
mods
)
->
(
integer
)
add
(
string
stat_name
,
StatModifier
mod
)
->
(
integer
)
remove
(
string
stat_name
,
number
value
,
string
modifier_type
,
boolean
magical
= true
)
->
(
integer
)
Note: Internally the values are stored as 32-bit floats, as such two different modifier values are considered the same if their different is less than 0.00001.
mods = am.stat_modifiers.new() base_health = 5 mods:add("health", 4, "+") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 9 (5 + 4) mods:add("health", 3, "*") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 19 (5 * 3 + 4) mods:add("health", 7, "=") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 25 (7 * 3 + 4) -- Remove them all again but in a different order. mods:remove("health", 3, "*") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 11 (7 + 4) mods:remove("health", 4, "+") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 7 (7) mods:remove("health", 7, "=") am_log("Calculated Health: " .. mods:calculate_stat("health", base_health)) -- Outputs 5 (5)
remove
(
am.stat_modifiers
mods
)
->
(
integer
)
remove
(
string
stat_name
,
StatModifier
mod
)
->
(
integer
)
mods
(
)
->
(
table
)
statMods = am.stat_modifiers.new() statMods:add("health", 5, "+", false) statMods:add("health", 8, "=") statMods:add("health", 2, "*") mods = statMods:mods() am_log("Magical: " .. tostring(mods["health"][1].magical)) -- Outputs "Magical: false" am_log("Type: " .. mods["health"][2].type) -- Outputs "Type: =" am_log("Value: " .. mods["health"][1].value) -- Outputs "Value: 2"
calculate_stat
(
string
stat_name
,
number
baseValue
)
->
(
number
)