Stat
Scripting with the Stat class.
The Stat
class is the main class you'll be using when scripting with the stats system. The advantage of this class is that it allows you to easily create stats of a specific type using Stat Identity, while also assigning strengths and weaknesses with Attribute.
Fields & Properties
value
The current value of the stat.
StatValue
public
scalingSource
The scaling source used to scale the stat per level.
ScalingSource
public
excessValue
The last calculated excess value.
StatValue
protected
externalValue
The amount gained/lost from external stats added together.
StatValue
public
externalStats
A list of combined stats. Use Combine or Uncombine to manage this list.
List<Stat>
public
level
The current level of this stat.
int
public
maxLevel
The max level of this stat.
int
public
combineType
The combine type used for mathematical operations.
CombineType
public
attribute
The attribute of this stat.
Attribute
public
statID
The ID of the stat identity.
int
public
identity
The stat identity. Use Identity or SetIdentity instead.
StatIdentity
public
lowValue
The low value of the stat.
StatValue
protected
LowValue
The low value of the stat. This is basically zero.
StatValue
public
BaseValue
The value of the stat at the current level without any external value added.
StatValue
public
HighValue
The base value at the current level plus any added value from other sources.
StatValue
public
NextValue
The value of the stat if leveled up.
StatValue
public
MaxValue
The max value of the stat at the the max level.
StatValue
public
IsLevelMaxed
If the level of this stat is maxed.
bool
public
IsLow
If the current value is equal to the low value.
bool
public
IsHigh
If the current value is equal to the high value.
bool
public
Identity
The stat identity.
StatIdentity
public
CombineType
Supported stat combine types.
Value
When combined with another stat, the stat's value will be treated as is.
PercentMax
When combined with another stat, the stat's value will be treated as a percentage of the other stat's max value.
PercentCurrent
When combined with another stat, the stat's value will be treated as a percentage of the other stat's current value.
Creating a Stat
A Stat requires a StatIdentity
. Stats can have an Attribute
but they are optional.
To create a Stat
, you need to define the scaling. This can be done by creating and providing the Stat Scaling Source or by simply providing the appropriate values in the constructor.
The default current level set is 1 and the default max level set is the 'Default Max Level' value that you can set from Settings.
No Scaling
// Parameters: stat name, attribute name, current, intitial
Stat myStat = new Stat("My Stat", "My Attribute", 100, 100);
Linear Scaling
// Parameters: stat name, attribute name, current, intitial, increment
Stat myStat = new Stat("My Stat", "My Attribute", 100, 100, 10);
Curve Scaling
// Parameters: stat name, attribute name, current, intitial, min, max, animation curve
Stat myStat = new Stat("My Stat", "My Attribute", 100, 100, 1, 100, myAnimation);
Merging
Use the TryMerge
method to permanently increase the value of a stat based on the value of a given stat. This method will return true or false, depending on whether the merge was successful. Merging may fail if the stats were not identicalâonly identical stats can be merged.
myStat.TryMerge(otherStat);
Combining/Uncombining
Combining a stat with another temporarily increases its value based on the value of a given stat until the other stat is uncombined.
Combine
Use the Combine
method to combine a stat with another. Combining may fail if the StatIdentity
and Attribute
of the stats are not the same.
myStat.Combine(otherStat);
Uncombine
Use the Uncombine
method to uncombine a combined stat.
myStat.Uncombine(otherStat);
Arithmetic
Methods
You can use the Add
, Subtract
, Multiply
, and Divide
to perform mathematically operations on stats. You will need to provide another Stat
, a StatValue
, float
, or int
as a parameter.
When using arithmetic methods on 2 stats, you will have the option to apply the attribute effectiveness with the second bool parameter.
myStat.Add(otherStat, useEffectiveness);
Operators
Similar to the methods, stats support arithmetic operators. Attribute effectiveness will automatically apply when possible.
myStat += otherStat;
Managing Levels
Setting the Level
To set the max value, use the SetMaxLevel
method.
myStat.SetMaxLevel(100);
The SetLevel
will set the current level to a specific value.
myStat.SetLevel(1);
Increasing the Level
Use the LevelUp
method to increase the level by a given amount. This method returns the unused excess amount. The level cannot go over the max level.
myStat.LevelUp(1);
Decreasing the Level
Use the LevelDown
method to decrease the level by a given amount. This method returns the unused excess amount. The level cannot go lower than 1.
myStat.LevelDown(1);
Optionally, you can use the Deplete
method to set the level to 1.
myStat.Deplete();
Resetting Values
Reset Values
The ResetValues
method resets the current and external values.
myStat.ResetValues();
Reset Completely
The Reset
method resets a stat completely.
myStat.Reset();
Comparison
Is Similar
The IsSimilar
method checks if a stat is similar to another.
bool similar = myStat.IsSimilar(otherStat, Similarity.Everything);
Similarity Types
Nothing
No similarity requirement.
IdentityAndAttribute
If the StatIdentity and Attribute are identical.
Everything
If the StatIdentity, Attribute, and CombineType, are identical.
Name Matches
Use the NameMatches
method to check if a string matches either the name or abbreviation of a stat.
bool match = myStat.NameMatches("HP");
Last updated