Character Stats
📊 CharacterStats Class
A component used to provide stats to a GameObject.
Namespace:
Esper.Inventool
Access:
public
Type:
class
Inherits:
MonoBehaviour
📦 Fields
public
profile
StatProfile
The stat profile.
public
boundEquipment
Equipment
The bound equipment instance. Use BindWithMain to set this value.
🔍 Properties
public
Level
int
The current level. Use LevelUp, LevelDown, or SetLevel to change this value.
public
MaxLevel
int
The max level.
public
Weight
float
The amount the target weighs.
public
Experience
ScalingValue
The experience points. Use AddExp or RemoveExp to manage this value.
public
Durability
ScalingValue
The durability points. Use AddDurability or ReduceDurability to manage this value.
public
Stats
List<Stat>
The list of stats.
public
IsMaxed
bool
If the level is maxed.
public
IsEquipmentBound
bool
Checks if a bound equipment has been set.
🎯 Static Events
public static
onDurabilityZero
UnityEvent<CharacterStats>
A callback for when the durability of any character reaches zero. This accepts 1 argument: the character stats (CharacterStats).
public static
onLeveledUp
UnityEvent<CharacterStats>
A callback for when a character is leveled up. This accepts 1 argument: the character stats (CharacterStats).
public static
onLeveledDown
UnityEvent<CharacterStats>
A callback for when a character is leveled down. This accepts 1 argument: the character stats (CharacterStats).
🧰 Methods
public
BindWithMain()
void
Binds this character stats with the main equipment instance.
public
Bind(Equipment equipment)
void
Binds this character stats with equipment. Use BindWithMain for now. Note: creating a separate equipment is not possible through the editor at the time. There is only one shared equipment. Support for this will be added in the future.
public
Unbind()
void
Unbinds from the currently bound equipment.
protected
PerformBindingUpdateEquip(ItemStack itemStack, EquipmentSlot equipmentSlot)
void
Unregisterable binding update for when an item is equipped.
protected
PerformBindingUpdateUnequip(ItemStack itemStack, EquipmentSlot equipmentSlot)
void
Unregisterable binding update for when an item is unequipped.
protected
PerformBindingUpdateEnchant(ItemStack enchanted, ItemStack enchanter)
void
Unregisterable binding update for when an equipped item is enchanted.
public
GetStat(int id)
Stat
Gets a stat by the StatIdentity ID of the stat to get. Returns the stat or null if it doesn't exist.
public
GetStat(string nameOrAbbreviation)
Stat
Gets a stat by the name or abbreviation of the stat to get. Returns the stat or null if it doesn't exist.
public
GetStat(StatIdentity statIdentity)
Stat
Gets a stat by the stat identity of the stat to get. Returns the stat or null if it doesn't exist.
public
MergeStats(params Stat[] stats)
void
Merges a list of stats with its own.
public
MergeStats(List<Stat> stats)
void
Merges a list of stats with its own.
public
CombineStats(params Stat[] stats)
void
Combines a list of stats with its own. Stats that don't exist in the profile will be ignored.
public
CombineStats(List<Stat> stats)
void
Combines a list of stats with its own. Stats that don't exist in the profile will be ignored.
public
UncombineStats(params Stat[] stats)
void
Uncombines a list of stats with its own. Stats that don't exist in the profile will be ignored.
public
UncombineStats(List<Stat> stats)
void
Uncombines a list of stats with its own. Stats that don't exist in the profile will be ignored.
public
SetMaxLevel(int maxLevel)
void
Sets the max level.
public
SetLevel(int level)
void
Sets the current level.
public
LevelUp()
void
Increases the current level by 1.
public
LevelDown()
void
Decreases the current level by 1.
public
AddExp(NumericValue value)
void
Adds to the current experience amount. This will result in a level up if the experience reaches the high value.
public
RemoveExp(NumericValue value)
void
Removes from the current experience amount. This will result in a level down if the experience goes below the low value.
public
IncreaseDurability(NumericValue value)
void
Increases the durability. The durability cannot go over the high value.
public
ReduceDurability(NumericValue value)
void
Reduces the durability. The durability cannot go below the low value.
public
CreateSavableData()
SavableProfile
Creates savable profile data.
public
SetData(SavableProfile savableProfile)
void
Sets the data based on the savable profile provided.
Equipment Binding
Equipment binding is a way to link the stats of a character with the stats of equipped items. Combining logic is used for this.
Bind With Main
Use BindWithMain
to bind the main equipment.
myCharacterStats.BindWithMain();
Use Unbind
to unbind from the bound equipment.
myCharacterStats.Unbind();
Managing Stats
Adding/Removing Stats
To add or remove a stat, simply use the Add
or Remove
methods of the Stats
field.
myCharacterStats.Stats.Add(myStat);
myCharacterStats.Stats.Remove(myStat);
Getting Stats
You can get a specific stat in the profile with the stat's ID, name or abbreviation.
var hpStat = myCharacterStats.GetStat("HP");
Merging Stats
You can merge a list of stats with the MergeStats
method. Stat merging is the process of permanently adding a stat's value to another of the same identity. If the stat cannot be merged with any existing stat in the profile, it will be added as a new stat instead.
myCharacterStats.MergeStats(stat1, stat2); //stat3, etc...
Combining/Uncombining Stats
Stat combining is the process of temporarily adding a stat's value to another of the same identity.
Combining
You can combine a list of stats with the CombineStats
method. Only similar stats can be combined with each other. Stats that aren't identical to any stat in the profile will be ignored.
myCharacterStats.CombineStats(stat1, stat2); //stat3, etc..
Uncombining
Use the UncombineStats
method to have the opposite effect.
myCharacterStats.UncombineStats(stat1, stat2); //stat3, etc..
Managing Levels
When setting the level of a StatProfile
, the methods below should be used as they will update all stats in the profile.
Set the Level
To set the max value, use the SetMaxLevel
method.
myCharacterStats.SetMaxLevel(100);
The SetLevel
will set the current level to a specific value.
myCharacterStats.SetLevel(1);
Level Up
The LevelUp
method increases the level by 1.
myCharacterStats.LevelUp();
Level Down
The LevelDown
method decreases the level by 1.
myCharacterStats.LevelDown();
Manage Experience
Add Exp
The AddExp
method adds experience points. This will result in a level up if the high value reached.
myCharacterStats.AddExp(100);
Remove Exp
The RemoveExp
method removes experience points. This will result in a level down if the value goes below zero.
myCharacterStats.RemoveExp(100);
Manage Durability
Increase Durability
The IncreaseDurability
method increases the durability. The durability cannot go over the high value.
myCharacterStats.IncreaseDurability(100);
Remove Exp
The ReduceDurability
method reduces the durability. The durability cannot go below the low value.
myCharacterStats.ReduceDurability(100);
Last updated