Table of Contents

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
object
EntityStats
Implements

Fields

_entityClass

protected IClassSource _entityClass

Field Value

IClassSource

_flatModifiers

protected StatSetInstance _flatModifiers

Field Value

StatSetInstance

_percentageModifiers

protected StatSetInstance _percentageModifiers

Field Value

StatSetInstance

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

IClassSource

EntityCore

The entity core associated with this stats component.

public EntityCore EntityCore { get; }

Property Value

EntityCore

OnStatChanged

Event raised when a stat changes due to a modifier.

public StatChangedGameEvent OnStatChanged { get; }

Property Value

StatChangedGameEvent

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

stat Stat

The stat to add the flat modifier to.

value long

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

stat Stat

The stat to add the percentage modifier to.

value Percentage

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

target Stat

The target stat.

source Stat

The source stat.

percentage Percentage

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:

  1. Base value
  2. Flat modifiers
  3. Stat to stat modifiers
  4. Percentage modifiers
public virtual long Get(Stat stat)

Parameters

stat Stat

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

stat Stat

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

entity EntityCore

The entity that leveled up.

newLevel int

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

stat Stat

The stat to set.

value long

The value to set.