Stat

📊 Stat Class

Represents a stat that can be managed. 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.

Namespace: Esper.Inventool.Stats Access: public Type: class Attributes: [Serializable]


📦 Fields

Access
Field
Type
Description

public (Obsolete)

initialValue

StatValue

Starting value of the stat. Use scalingSource.initialValue instead.

public

value

StatValue

The current value of the stat.

public (Obsolete)

currentValue

StatValue

Old current value field. Use value instead.

public (Obsolete)

scaling

StatValue

Old scaling per level. Use scalingSource instead.

public

scalingSource

StatScalingSource

Scaling source used to scale the stat per level.

protected

excessValue

StatValue

Last calculated excess value.

public

externalValue

StatValue

Amount gained/lost from external stats.

public

totalEnchantmentMultiplier

float

Multiplier applied from enchantments. Defaults to 1.

public

externalStats

List<Stat>

Combined stats list. Managed via Combine/Uncombine.

public

level

int

Current level of this stat. Defaults to 1.

public

maxLevel

int

Maximum level of this stat. Defaults to 1.

public

combineType

CombineType

How this stat combines with others.

public (Obsolete)

combineOperator

CombineOperator

Old combine operator (no longer supported).

public

attribute

Attribute

Attribute associated with this stat.

public

statID

int

ID of the stat identity.

public

clampWithinRange

bool

If the value should automatically be clamped within the low and high range whenever it's changed.

public

identity

StatIdentity

The stat identity.

protected

lowValue

StatValue

The low value of the stat.


🔍 Properties

Access
Property
Type
Description

public

LowValue

StatValue

The low value (defaults to 0 unless changed).

public

BaseValue

StatValue

Value at current level without external modifiers.

public

HighValue

StatValue

Base value + external value, with enchantment multipliers applied.

public

NextValue

StatValue

Value if leveled up.

public

MaxValue

StatValue

Value at maximum level.

public (Obsolete)

NextBaseValue

StatValue

Old calculation for next value. Use NextValue instead.

public (Obsolete)

MaxBaseValue

StatValue

Old calculation for max value. Use MaxValue instead.

public

IsLevelMaxed

bool

True if level == maxLevel.

public

IsLow

bool

True if current value ≤ low value.

public

IsHigh

bool

True if current value ≥ high value.

public (Obsolete)

IsMaxed

bool

Old check for maxed level. Use IsLevelMaxed instead.

public

Identity

StatIdentity

Gets/sets the stat identity.


📢 Events

Access
Event
Type
Description

public

onChanged

UnityEvent<StatValue, StatValue, float>

Invoked when value changes. Args: new value, previous value, effectiveness.

public

onReachedHigh

UnityEvent

Invoked when value reaches high.

public

onReachedLow

UnityEvent

Invoked when value reaches low.

public

onLeveledUp

UnityEvent

Invoked when level increases.

public

onLeveledDown

UnityEvent

Invoked when level decreases.

public static (Obsolete)

onValueChanged

UnityEvent<Stat, StatValue, float>

Old global event for value changes.

public static (Obsolete)

onValueReachedMax

UnityEvent<Stat>

Old global event for reaching max.

public static (Obsolete)

onValueReachedMin

UnityEvent<Stat>

Old global event for reaching min.

public static (Obsolete)

onUpgraded

UnityEvent<Stat>

Old global event for level up.

public static (Obsolete)

onDowngraded

UnityEvent<Stat>

Old global event for level down.


🔧 Constructors

Access
Signature
Description

public

Stat()

Default constructor.

public

Stat(StatIdentity identity)

Creates a stat with a given identity. Initializes level = 1 and maxLevel from settings.

public

Stat(StatIdentity identity, Attribute attribute, StatValue value, StatScalingSource scalingSource = default, CombineType combineType = CombineType.Value)

Creates a stat with a scaling source. Initializes level = 1, maxLevel, and sets identity, attribute, value, scaling source, and combine type.

public

Stat(StatIdentity identity, Attribute attribute, StatValue value, StatValue initialValue, CombineType combineType = CombineType.Value)

Creates a stat with no scaling. Initializes scaling source with initialValue.

public

Stat(StatIdentity identity, Attribute attribute, StatValue value, StatValue initialValue, StatValue increment, CombineType combineType = CombineType.Value)

Creates a stat with linear scaling. Initializes scaling source with initialValue and increment.

public

Stat(StatIdentity identity, Attribute attribute, StatValue value, StatValue initialValue, StatValue min, StatValue max, AnimationCurve curve, CombineType combineType = CombineType.Value)

Creates a stat with curve scaling. Initializes scaling source with initialValue, min, max, and curve.


🧰 Methods

Access
Method
Returns
Description

public

CreateCopy()

Stat

Creates a copy of this stat.

public

SetIdentity(StatIdentity identity)

void

Sets the identity for all values.

public

IsSimilar(Stat other, Similarity similarity)

bool

Checks if another stat is similar.

public

NameMatches(string name)

bool

Checks if the name or abbreviation matches.

public

TryMerge(Stat stat)

bool

Attempts to merge with another stat.

public

Combine(Stat stat)

void

Adds another stat as external.

public

Uncombine(Stat stat)

void

Removes an external stat.

public

RecalculateExternalValue()

void

Recalculates external value.

public

Add(Stat stat, bool useEffectiveness = true)

void

Adds another stat’s value.

public

Add(StatValue value)

void

Adds a stat value.

public

Add(int value)

void

Adds an integer.

public

Add(float value)

void

Adds a float.

public

Subtract(Stat stat)

void

Subtracts another stat’s value.

public

Subtract(StatValue value)

void

Subtracts a stat value.

public

Subtract(int value)

void

Subtracts an integer.

public

Subtract(float value)

void

Subtracts a float.

public

Multiply(Stat stat)

void

Multiplies by another stat’s value.

public

Multiply(StatValue value)

void

Multiplies by a stat value.

public

Multiply(int value)

void

Multiplies by an integer.

public

Multiply(float value)

void

Multiplies by a float.

public

Divide(Stat stat)

void

Divides by another stat’s value.

public

Divide(StatValue value)

void

Divides by a stat value.

public

Divide(int value)

void

Divides by an integer.

public

Divide(float value)

void

Divides by a float.

public

GetExcessValue()

StatValue

Gets the last calculated excess value.

public

SetMaxLevel(int maxLevel)

void

Sets the maximum level.

public

SetLevel(int level)

void

Sets the current level.

public

LevelUp(int amount = 1)

int

Increases the level. Returns excess amount.

public

LevelDown(int amount = 1)

int

Decreases the level. Returns excess amount.

public

TryUpgrade(int amount = 1) (Obsolete)

int

Old upgrade method.

public

TryDowngrade(int amount = 1) (Obsolete)

int

Old downgrade method.

public

Deplete()

void

Sets the current level to 1.

public

ResetExternalValue()

void

Resets external value.

public

ResetValue()

void

Resets current value.

public

ToString()

string

Returns the value as a string.

public

ToFloat()

float

Converts the value to a float.

public

ToInt()

int

Converts the value to an int.


➗ Operator Overloads

Operator
Signature
Returns
Description

+

Stat + Stat

Stat

Adds two stats together.

+

Stat + StatValue

Stat

Adds a stat value.

+

Stat + int

Stat

Adds an integer.

+

Stat + float

Stat

Adds a float.

-

Stat - Stat

Stat

Subtracts one stat from another.

-

Stat - StatValue

Stat

Subtracts a stat value.

-

Stat - int

Stat

Subtracts an integer.

-

Stat - float

Stat

Subtracts a float.

*

Stat * Stat

Stat

Multiplies two stats.

*

Stat * StatValue

Stat

Multiplies by a stat value.

*

Stat * int

Stat

Multiplies by an integer.

*

Stat * float

Stat

Multiplies by a float.

/

Stat / Stat

Stat

Divides one stat by another.

/

Stat / StatValue

Stat

Divides by a stat value.

/

Stat / int

Stat

Divides by an integer.

/

Stat / float

Stat

Divides by a float.

==

Stat == Stat

bool

Checks equality between two stats.

!=

Stat != Stat

bool

Checks inequality between two stats.

>

Stat > Stat

bool

Greater‑than comparison.

<

Stat < Stat

bool

Less‑than comparison.

>=

Stat >= Stat

bool

Greater‑than‑or‑equal comparison.

<=

Stat <= Stat

bool

Less‑than‑or‑equal comparison.

implicit

int -> Stat

Stat

Implicit conversion from int.

implicit

float -> Stat

Stat

Implicit conversion from float.

implicit

Stat -> int

int

Implicit conversion to int.

implicit

Stat -> float

float

Implicit conversion to float.


🧩 Nested Types

public enum CombineType

Name
Description

Value

When combined, the stat’s value is treated as-is.

Percent

When combined, the stat’s value is treated as a percentage.

PercentMax

Obsolete. Percentage of the other stat’s max value.

PercentCurrent

Obsolete. Percentage of the other stat’s current value.


public enum Similarity

Name
Description

Nothing

No similarity requirement.

IdentityAndAttribute

StatIdentity and Attribute must be identical.

Everything

StatIdentity, Attribute, and CombineType must be identical.


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. These methods apply automatic clamping.

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. Operators apply automatic clamping.

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);

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