Stats
Stats are concrete and simple caracteristics of your object that allows you to change the gameplay in an easy way.
Adding a stat
Via the stat list or AddComponent<MyStat>()
.
Accessing a stat
// Get the stat
var stat = GetComponent<HealthStat>();
// Set / Get value
stat.Value = 100;
// Add a modifier
stat.Add(new Clamp(5, 100));
A value is updated in
GameEntity
.LateUpdate
or when you get explicitly the value with myStat.Value
Custom stat
A stat is a value that can be of any IEquatable
type. It has a set of modifiers (modifications added at runtime) and applies them to change the base value of the stat.
Here is the minimal code to create a Charisma stat based on an integer value. Always keep in mind that it is a regular component and that you can do whatever you want in it.
using EODE.Wonderland;
[AddComponentMenu("YourGame/Stats/Charisma")]
public class CharismaStat: StatBase<int> {}
StatBase types
int
float
short // usefull for enums
string // without modifiers
Vector2
Vector3
vector4
Color
If a stat has another type, modifiers can't be applyed. (see modifers page)
Editor decorations
using EODE.Wonderland;
[AddComponentMenu("")]
public class CharismaStat: StatBase<int> {
public virtual string EditorTitle => "Custom title => " + Value;
public virtual string IconPath => "Charisma_StatIcon"; // Charisma_StatIcon.png in a Editor/Resources directory
}
Icon files must be imported with Texture Type =
Editor GUI and Legacy GUI
and Read/Write Enabled totrue
.
Helpers
myStat.GameEntity == myStat.GetComponent<GameEntity>();
myStat.Owner == myStat.GetComponent<GameEntity>().Owner;
bool hasModifier = myStat.Has(MyModifier);
var minValue = myStat.GetMin(); // search a clamp modifier and return its min
var maxValue = myStat.GetMax(); // search a clamp modifier and return its max
GetVectorMin && GetVectorMax // returns min values of all clamp modifiers (raw format -> vector4)