> For the complete documentation index, see [llms.txt](https://roofen-game.gitbook.io/roofen-game/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roofen-game.gitbook.io/roofen-game/frameworks/common-stat/runtime.md).

# 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://roofen-game.gitbook.io/roofen-game/frameworks/common-stat/runtime.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
