Click or drag to resize

Stats Class

Represents the base and current values of stats of an entity as a dictionary. Can be used with both POCO objects or MonoBehaviours with Odin's SerializedMonoBehaviour.
Inheritance Hierarchy
SystemObject
  System.Collections.GenericDictionaryString, StatBaseProperty
    Kit.ContainersStats

Namespace:  Kit.Containers
Assembly:  Assembly-CSharp (in Assembly-CSharp.dll) Version: 0.0
Syntax
C#
public class Stats : Dictionary<string, StatBaseProperty>, 
	IDisposable
Request Example View Source

The Stats type exposes the following members.

Constructors
  NameDescription
Public methodStats
Initializes a new instance of the Stats class
Public methodStats(IUpgradeable)
Initializes a new instance of the Stats class
Top
Properties
  NameDescription
Public propertyItem
Returns the current value of a stat or allows to set the base value.
Top
Methods
  NameDescription
Public methodAdd
Set the base value of a stat.
Public methodStatic memberCalculateValue(ValueTupleSingle, Single, Single, Single)
Calculate current value from a base value and aggregates.
Public methodStatic memberCalculateValue(IUpgradeable, String, Single)
Calculate the current value of an stat based on base value.
Public methodStatic memberCreateCurrentProperty
Create a property that changes values when the base property changes or an upgrade is added or removed.
Public methodDispose
Releases all resources used by the Stats
Public methodStatic memberGetAggregates(IEnumerableEffect)
Calculate aggregates from a list of effects.
Public methodStatic memberGetAggregates(IUpgradeable, String)
Calculate aggregates of an stat.
Public methodGetBaseProperty
Get the base value property of a stat.
Public methodGetBaseValue
Get the base value of a stat.
Public methodGetCurrentProperty
Get the current value property of a stat.
Public methodGetCurrentValue
Get the current value of a stat.
Public methodStatic memberGetEffects
Get all effects on an IUpgradeable for a given stat.
Public methodStatic memberGetEffectsAndUpgrades
Get all upgrades and effects on an IUpgradeable for a given stat.
Public methodSetBaseProperty
Set the base value property of a stat.
Public methodSetBaseValue
Set the base value of a stat.
Public methodToString
Returns all the base and current values as a formatted table.
(Overrides ObjectToString.)
Top
Fields
  NameDescription
Public fieldUpgradeable
The IUpgradeable to use for calculating current values.
Top
Remarks
The class is highly-optimized as the current values are only updated when the IUpgradeable adds or removes an Upgrade or the base value of the property changes. When used in a MonoBehaviour, it also provides custom inspectors for viewing and changing values.
Examples
public class Player: IUpgradeable
{
    public Stats Stats;
    public AsyncReactiveList<Upgrade> Upgrades = new AsyncReactiveList<Upgrade>();

    public void Initialize()
    {
        Stats = new Stats(this);
        Stats["Health"] = 100.0f;
        Stats["Damage"] = 15.0f;

        Upgrade upgrade = new Upgrade("SturdyHelmet");
        upgrade.AddEffect("Health", "+50");
        upgrade.AddEffect("Damage", "+25%");
        Upgrades.Add(upgrade);

        Debug.Log(Stats.ToString());
    }

   public AsyncReactiveList<Upgrade> GetUpgrades()
   {
       return Upgrades;
   }
}
See Also