Stat
Stat
Modifiable statistic. Allows non-destructive linear arithmetic. Useful when we wish to be able to reverse part or the whole of the computation
Main purpose of the class is to facilitate implementation of RPG-like stats, such as maximum health, or armor. These stats can then be modified by various skills, equipment and effects. Each such modification will be added as a separate LinearModifier and can be reversed by removing the modifier.
Kind: global class
- Stat
- new Stat([value])
- instance
- .id :
number - .postprocess :
function - .base :
Vector1 - .value :
Vector1 - .onModifierAdded ⇒
Signal.<LinearModifier> - .onModifierRemoved ⇒
Signal.<LinearModifier> - .onChanged ⇒
Signal - .isStat :
boolean - .resetModifiers()
- .valueOf() ⇒
number - .toString() ⇒
string - .getValue() ⇒
number - .getBaseValue() ⇒
number - .setBaseValue(v)
- .getModifiers() ⇒
Array.<LinearModifier> - .addModifier(mod)
- .hasModifier(mod) ⇒
boolean - .removeModifier(mod) ⇒
boolean - .equals(other) ⇒
boolean - .copy(other)
- .copyBase(other)
- .setBaseFromParametricFunction(f, v)
- .addNonTransientModifiersFromStat(other)
- .id :
- static
- .applyModifiers(input, modifiers) ⇒
number
- .applyModifiers(input, modifiers) ⇒
new Stat([value])
| Param | Type | Default |
|---|---|---|
| [value] | number | 0 |
stat.id : number
Unique identifier of a stat, such a health, armor etc.
Kind: instance property of Stat
stat.postprocess : function
Computed value will be pass through this function before being exposed. Useful for rounding and clamping. see Stat.Process for some options.
Kind: instance property of Stat
stat.base : Vector1
Base value that modifiers will affect
Kind: instance property of Stat
stat.value : Vector1
Final computed value. Do not modify this directly
Kind: instance property of Stat
stat.onModifierAdded ⇒ Signal.<LinearModifier>
Kind: instance property of Stat
stat.onModifierRemoved ⇒ Signal.<LinearModifier>
Kind: instance property of Stat
stat.onChanged ⇒ Signal
Kind: instance property of Stat
stat.isStat : boolean
Kind: instance property of Stat
Read only: true
stat.resetModifiers()
Remove all modifiers from the stat
Kind: instance method of Stat
stat.valueOf() ⇒ number
Kind: instance method of Stat
stat.toString() ⇒ string
Kind: instance method of Stat
stat.getValue() ⇒ number
Kind: instance method of Stat
stat.getBaseValue() ⇒ number
Kind: instance method of Stat
stat.setBaseValue(v)
Kind: instance method of Stat
| Param | Type |
|---|---|
| v | number |
stat.getModifiers() ⇒ Array.<LinearModifier>
NOTE: do not modify result
Kind: instance method of Stat
stat.addModifier(mod)
Kind: instance method of Stat
| Param | Type |
|---|---|
| mod | LinearModifier |
stat.hasModifier(mod) ⇒ boolean
Kind: instance method of Stat
| Param | Type |
|---|---|
| mod | LinearModifier |
stat.removeModifier(mod) ⇒ boolean
Kind: instance method of Stat
| Param | Type |
|---|---|
| mod | LinearModifier |
stat.equals(other) ⇒ boolean
Kind: instance method of Stat
| Param | Type |
|---|---|
| other | Stat |
stat.copy(other)
Kind: instance method of Stat
| Param | Type |
|---|---|
| other | Stat |
stat.copyBase(other)
Copy base value from another stat
Kind: instance method of Stat
| Param | Type |
|---|---|
| other | Stat |
stat.setBaseFromParametricFunction(f, v)
Kind: instance method of Stat
| Param | Type |
|---|---|
| f | function |
| v | number |
stat.addNonTransientModifiersFromStat(other)
Kind: instance method of Stat
| Param | Type |
|---|---|
| other | Stat |
Stat.applyModifiers(input, modifiers) ⇒ number
Kind: static method of Stat
| Param | Type |
|---|---|
| input | number |
| modifiers | List.<LinearModifier> |