Modify Stat Values

The StatsHandler has a list of stat instances to operate on. This page will explain how to deal damage or heal, how to modify a stat over time, buff or debuff and how to increase a stat.

ApplyDamage

Damage or healing can only be applied to an Attribute. An attributes Current Value will always be clamped between 0 and Attribute/Stat Value, so applying a damage of 20 to a stat with a Current Value of 10 will not result in -10 but 0.

using UnityEngine;
using DevionGames.StatSystem;

public class Example : MonoBehaviour
{
    // Start is called before the first frame update
    private void Start()
    {
        StatsHandler handler = GetComponent<StatsHandler>();
        handler.ApplyDamage("Health", 10f);
    }
}

AddModifier & RemoveModifier

StatModifiers add a new layer value to the stats value. For example if the characters strength is 35 and the character equips a sword, it could add a flat(or also percent) value to the strength of +5, which would make the strength of 40. Once the sword is unequiped the characters strength will be reset back to 35.

using UnityEngine;
using DevionGames.StatSystem;

public class Example : MonoBehaviour
{
    // Start is called before the first frame update
    private void Start()
    {
        StatsHandler handler = GetComponent<StatsHandler>();
        //Adds a flat modifier of 5 to Strength with binding to gameObject(Can be an item)
        handler.AddModifier("Strength", 5f, StatModType.Flat, gameObject);
        //Removes any modifier that is associated with gameObject(item)
        handler.RemoveModifiersFromSource("Strength", gameObject);
    }
}

AddEffect & RemoveEffect

StatEffects execute a predefined list of actions in a sequence. For example you could apply damage to health x times or regenerate health over time. See also Create Stat Effects.

using UnityEngine;
using DevionGames.StatSystem;

public class Example : MonoBehaviour
{
    //Select the effect in inspector
    public StatEffect effect;

    // Start is called before the first frame update
    private void Start()
    {
        StatsHandler handler = GetComponent<StatsHandler>();
        //Add the effect
        handler.AddEffect(effect);
        //Remove the effect. It is also possible to handle remove, once done inside 
        //the effect itself in the editor  
        handler.RemoveEffect(effect);
    }
}

TriggerAnimationEvent

Often you want to send damage to an enemy in the middle of a characters animation. This can be done through the Animation Event System.

DamageData (MeleeDamageData) holds information how the damage should be applied. For example it contains a stat definition that will return the damage that should be applied. To which stat it should apply damage? What is the maximum target distance¬† and angle to target? What sound or particle effect to play? And more…

Please see this as an example that you can discard or extend with a custom DamageHandler component and custom methods that you can enter inside the unity animation event system as string parameter(SendDamage).

Add & Subtract

Add and Subtract methods provide a way to increase or decrease a stat permanently. This is often done through the UI with free stat points, but you can also modify the stat through code.

using UnityEngine;
using DevionGames.StatSystem;

public class Example : MonoBehaviour
{
    // Start is called before the first frame update
    private void Start()
    {
        StatsHandler handler = GetComponent<StatsHandler>();
        //Stat to modify
        Stat vitality = handler.GetStat("Vitality");
        //This will permanently(with saving and loading enabled) add 1 vitality
        vitality.Add(1);
        //This will permanently(with saving and loading enabled) subtract 2 vitality
        vitality.Subtract(2);
    }
}