Stats

The stats class stores all base values for each stat, as well as all the current modifiers for each stat.
Return to Index
new ( )
__gc ( )
__eq ( am.stats rhs ) -> ( boolean )
base_stat ( string stat_name ) -> ( number )
base_stat ( string stat_name , number base_value ) -> ( am.stats )
stat ( string stat_name ) -> ( number )
add ( string stat_name , number value , string type , Booleam magical = true ) -> ( integer )
add ( am.stat_modifiers mods ) -> ( integer )
add ( string stat_name , am.stat_modifier 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 , am.stat_modifier mod ) -> ( integer )
mods ( ) -> ( am.stat_modifiers )
new ( )
Creates a new stats instance.
__gc ( )
Deletes a stats instance. TODO Check if it should do this.
__eq ( am.stats rhs ) -> ( boolean )
Compares this stats object against another stats object.
Parameters:
am.stats rhs : The other stats object to compare with.
Returns:
boolean : True if they are the same stats object.
base_stat ( string stat_name ) -> ( number )
Returns the base value for the given stat. This is the value of the stat before any stat modifiers are applied.
Parameters:
string stat_name : The name of the stat to get the base value of.
Returns:
number : The base value.
base_stat ( string stat_name , number base_value ) -> ( am.stats )
Sets the base value of the given stat with the given value.
Parameters:
string stat_name : The name of the stat to set the base value of.
number base_value : The new base value for the stat.
Returns:
am.stats : This
stat ( string stat_name ) -> ( number )
Returns the calculated stat value for the given stat. This uses the base value of the stat and any modifiers applied to that stat to return the value from this function.
Parameters:
string stat_name : The name of the stat to get the calculated value of.
Returns:
number : The calculated stat value.
add ( string stat_name , number value , string type , Booleam magical = true ) -> ( integer )
Adds a modifier to the stat modifiers collection. This behaves the same way as the stat modifiers class add function.
 stats = am.stats.new()
 stats:add("strength", 6, "+")
 stats:mods():add("strength", 4, "*")
 
 mods = stats:mods():mods()
 am_log("Mod 1: " .. mods["strength"][1].type .. " " .. mods["strength"][1].value) -- Outputs "Mod 1: + 6"
 am_log("Mod 2: " .. mods["strength"][2].type .. " " .. mods["strength"][2].value) -- Outputs "Mod 2: * 4"
 am_log("Strength: " .. stats:stat("strength", 5)) -- Outputs "Strength: 26"
Parameters:
string stat_name : The name of the stat to add the modifier to.
number value : The value of the stat modifier.
string type : The type of the modifier.
Booleam magical = true : If the modifier is magical in nature.
Returns:
integer : Return codes
  • 1: The stat modifier was added successfully.
  • 0: The context object was not a stats object.
  • -1: The given stat name was invalid.
  • -2: The given value was not a number.
  • -3: The given stat modifier was invalid.
add ( am.stat_modifiers mods ) -> ( integer )
Merges another stat modifiers collection into the stat modifiers collection of this stats object. This behaves as if all the modifiers were taken from the given collection and added through the other add modifier function.
Parameters:
am.stat_modifiers mods : The collection of stat modifiers to combine with this one.
Returns:
integer : Return code
  • 1: The stat modifiers were successfully merged.
  • 0: The context object was not a stats object.
  • -1: The given stat modifiers collection was not a stat modifier instance.
add ( string stat_name , am.stat_modifier mod ) -> ( integer )
Adds a stat modifier instance to this stats collection of modifiers.
Parameters:
string stat_name : The name of the stat this modifier will affect.
am.stat_modifier mod : The stat modifier to add.
Returns:
integer : Return code for success.
  • 1: The stat modifier was added successfully.
  • 0: The context object was not a stats object.
  • -1: The given stat name was invalid.
  • -4: The given stat modifier was not a valid stat modifier instance.
remove ( string stat_name , number value , string modifier_type , boolean magical = true ) -> ( integer )
Removes a modifier from the stat modifiers collection. This behaves the same way as the stat modifiers class remove function.
 stats = am.stats.new()
 stats:add("strength", 6, "+")
 stats:mods():add("strength", 4, "*")
 
 mods = stats:mods():mods()
 am_log("Mod 1: " .. mods["strength"][1].type .. " " .. mods["strength"][1].value) -- Outputs "Mod 1: + 6"
 am_log("Mod 2: " .. mods["strength"][2].type .. " " .. mods["strength"][2].value) -- Outputs "Mod 2: * 4"
 am_log("Strength: " .. stats:stat("strength", 5)) -- Outputs "Strength: 26"
 
 stats:remove("strength", 6, "+")
 mods = stats:mods()
 am_log("Mod 1: " .. mods["strength"][1].type .. " " .. mods["strength"][1].value) -- Outputs "Mod 1: * 4"
 am_log("Strength: " .. stats:stat("strength", 5)) -- Outputs "Strength: 20"
Parameters:
string stat_name : The name of the stat to remove this modifier from.
number value : The stat modifier value.
string modifier_type : The modifier type name.
boolean magical = true : If the added modifier was magical, it has be removed as magical.
Returns:
integer : Return codes
  • 1: The stat modifier was removed.
  • 0: The context object was not a stats object.
  • -1: The given stat name was invalid.
  • -2: The given value was not a number.
  • -3: The given stat modifier was invalid.
remove ( am.stat_modifiers mods ) -> ( integer )
Removes all the stat modifiers from the given collection from this stats modifiers collection. This behaves as if all the modifiers were taken from the given collection and removed through the other remove modifier function.
Parameters:
am.stat_modifiers mods : The collection of stat modifiers to remove.
Returns:
integer : Return codes
  • 1: The stat modifiers were successfully removed.
  • 0: The context object was not a stats object.
  • -1: The given stat modifiers collection was not a stat modifier instance.
remove ( string stat_name , am.stat_modifier mod ) -> ( integer )
Removes a stat modifier from this stats modifiers collection.
Parameters:
string stat_name : The name of the stat to remove this modifier from.
am.stat_modifier mod : The modifier to remove.
Returns:
integer : Return codes
  • 1: The stat modifier was removed.
  • 0: The context object was not a stats object.
  • -1: The given stat name was invalid.
  • -4: The given stat modifier was not a valid stat modifier instance.
mods ( ) -> ( am.stat_modifiers )
Returns the internal stat modifiers object.
Returns:
am.stat_modifiers : The internal stat modifiers object.