Class EntityStats
- Namespace
- ElectricDrill.SoapRpgFramework.Stats
- Assembly
- com.electricdrill.soap-rpg-framework.Runtime.dll
Component that manages the statistics of an entity in the game.
It handles base stats, flat stat modifiers, stat to stat modifiers, and percentage stat modifiers.
Base stats can either be fixed or come from the entity's class (if one is available on the Game Object).
When stats change because of a modifier of any kind, the assigned StatChangedGameEvent is raised.
[DisallowMultipleComponent]
[RequireComponent(typeof(EntityCore))]
public class EntityStats : MonoBehaviour, IHasStatSet, IValueProvider<Stat, long>- Inheritance
- 
      objectEntityStats
- Implements
Fields
_entityClass
protected IClassSource _entityClassField Value
_flatModifiers
protected StatSetInstance _flatModifiersField Value
_percentageModifiers
protected StatSetInstance _percentageModifiersField Value
Properties
EntityClass
The class source of the entity. In most cases, this is the EntityClass component attached to the entity.
public IClassSource EntityClass { get; }Property Value
EntityCore
The entity core associated with this stats component.
public EntityCore EntityCore { get; }Property Value
OnStatChanged
Event raised when a stat changes due to a modifier.
public StatChangedGameEvent OnStatChanged { get; }Property Value
StatSet
The stat set used to calculate the entity's stats.
public virtual StatSet StatSet { get; }Property Value
- StatSet
- If _useBaseStatsFromClass is true, it returns the stat set of the entity's class. Otherwise, it returns the fixed base stats stat set. 
UseClassBaseStats
Gets or sets whether to use the base stats from the entity's class. If true, the base stats are taken from the EntityClass. If false, the base stats are taken from the fixed base stats defined in this component.
public bool UseClassBaseStats { get; }Property Value
- bool
Methods
AddFlatModifier(Stat, long)
Adds a flat modifier to a stat.
public void AddFlatModifier(Stat stat, long value)Parameters
- statStat
- The stat to add the flat modifier to. 
- valuelong
- The value of the flat modifier. 
AddPercentageModifier(Stat, Percentage)
Adds a Percentage modifier to a stat. Such modifiers consider the base value of the stat, the flat modifiers, and the stat-to-stat modifiers.
public void AddPercentageModifier(Stat stat, Percentage value)Parameters
- statStat
- The stat to add the percentage modifier to. 
- valuePercentage
- The value of the percentage modifier. 
AddStatToStatModifer(Stat, Stat, Percentage)
Adds a stat-to-stat modifier. Such modifiers add a percentage of the source stat to the target stat. Such modifiers consider the base value and the flat modifiers of the source stat.
public void AddStatToStatModifer(Stat target, Stat source, Percentage percentage)Parameters
- targetStat
- The target stat. 
- sourceStat
- The source stat. 
- percentagePercentage
- The Percentage of the source stat to add to the target stat. 
Get(Stat)
The final value of a stat, considering all the modifiers.
Calculation is done in the following order:
- Base value
- Flat modifiers
- Stat to stat modifiers
- Percentage modifiers
public virtual long Get(Stat stat)Parameters
- statStat
- The stat to get the final value of. 
Returns
- long
- The final value of the stat if the component is enabled (clamped to min/max values); otherwise, 0 
GetBase(Stat)
The base value is the value of the stat without any modifiers. If UseClassBaseStats is true, it returns the value from the entity's class. Otherwise, it returns the value from the fixed base stats.
public long GetBase(Stat stat)Parameters
- statStat
- The stat to get the base value of. 
Returns
- long
- The base value of the stat (clamped to the stat's min and max values) if enabled; otherwise, 0 
OnLevelUp(EntityCore, int)
Callback method called when the entity levels up.
protected virtual void OnLevelUp(EntityCore entity, int newLevel)Parameters
- entityEntityCore
- The entity that leveled up. 
- newLevelint
- The new level of the entity. 
SetFixed(Stat, long)
Sets the value of a fixed base stat. This is only applicable when UseClassBaseStats is false.
public void SetFixed(Stat stat, long value)Parameters
- statStat
- The stat to set. 
- valuelong
- The value to set.