# Runtime

This value system is borrowed from some well-known games such as World of Warcraft and Elden's Ring.

## SoleValueRuntime

If you need to edit update rules or add rules you can do so in `SoleValueRuntime.cs`.

```
SoleValueRuntime.cs
/// <summary>
/// Updates the cached current value.
/// </summary>
private void UpdateCurrentValue()
{
    int baseCurrentValue = mBaseValue + mValueAdd.GetValue();
    int mul = mValuePercentAdd.GetValue() * mValuePercentMul.GetValue();
    mCurrentValue = (baseCurrentValue * mul) / 10000;
}
```

You can change the value at runtime by using the following four functions. You can also change the relationship between the current value and the maximum value here.

```
//Direct modification Examples include using props to recover, 
//enemies attacking themselves, skill attacks, etc.
public void ModifyValue(int _modValue, bool _isMaxValue = false)

//Reference modifications, e.g. equipment, special buffs
public ModifyReference ReferenceModifyValue(StatModifyType _modifyType, int _modValue)

//Remove Reference e.g. touching equipment, end of special buffs
public void RemoveModifyReference(ModifyReference _modifyReference)SoleObjectRuntimeValueSO
```

## CommonStatRuntimeSO

This script manages all runtime values.

If you have a lot of enemies, you don't want to create a lot of this ScriptableObject for that purpose.&#x20;

<pre><code><strong>ScriptableObject.CreateInstance&#x3C;SoleObjectRuntimeValueSO>();
</strong>runtimeValueSO.SetValueConfigSO(mValueConfig);
</code></pre>

It will be initialized the first time it is used, so you need to make sure that SetConfig is initialized before you use it.

### Examples

The floowing are examples of use

<pre><code><strong>public class EnemyConfigSO : DescriptionBaseSO
</strong>{
    [SerializeField] private ValueConfigSO mValueConfig;
    public RuntimeAnimatorController MyAnimator;

    public SoleObjectRuntimeValueSO GetRuntimeValueSO()
    {
        var runtimeValueSO = ScriptableObject.CreateInstance&#x3C;SoleObjectRuntimeValueSO>();
        runtimeValueSO.SetValueConfigSO(mValueConfig);

        return runtimeValueSO;
    }
}
</code></pre>

There are also some APIs provided that may not be common that you can view directly in the code. All are commented.
