> For the complete documentation index, see [llms.txt](https://roogame.gitbook.io/roogame/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roogame.gitbook.io/roogame/ultimate-stats-framework/creating-your-dynamic-gameplay-formulas/core-concepts.md).

# Core Concepts

The Roo Formula System lets you create reusable gameplay calculations without writing the same calculation logic in multiple Blueprints or C++ classes.

A Formula can read Stats and Attributes from the current character, read values from a target, and use a Progression Table for level-based calculations.

### Formula

A **Formula** is a Data Asset that contains a calculation expression.

For example, a normal attack damage Formula can be written as:

```
self.stat.Attack - target.stat.Defense
```

The Formula calculates a result at runtime.

```
Attacker Attack = 30
Target Defense = 10

Damage = 30 - 10
Damage = 20
```

The same Formula Data Asset can be reused by multiple characters, weapons, skills, or enemies.

### Self and Target

A Formula can read values from two components:

```
self
target
```

`self` refers to the Ultimate Stats Framewor Component that evaluates the Formula.

`target` refers to an optional second Ultimate Stats Framework Component.

For a normal attack:

```
self   = Attacker
target = Defender
```

Example:

```
self.stat.Attack - target.stat.Defense
```

```
Attacker Attack = 30
Defender Defense = 10

Result = 20
```

### Read a Calculated Stat

Use `stat` to read the current calculated value of a Stat.

```
self.stat.Attack
target.stat.Defense
self.stat.HealthMax
```

Use `stat` when the calculation should include the Stat's current runtime result.

Example:

```
self.stat.Attack * 2
```

### Read a Base Stat

Use `base` to read a Stat's base value.

```
self.base.Attack
target.base.Defense
```

Use `base` when the Formula needs the original base value instead of the current calculated value.

Example:

```
self.base.Attack + 10
```

### Read an Attribute

Use `attr` to read the current value of an Attribute.

```
self.attr.Health
self.attr.Mana
target.attr.Health
```

Example:

```
target.attr.Health * 0.1
```

This Formula returns 10% of the target's current Health.

### Formula Syntax

Formulas support basic arithmetic operators.

```
+
-
*
/
()
```

Example:

```
(self.stat.Attack * 2) - target.stat.Defense
```

Parentheses can be used to control calculation order.

### Progression Tables

A Formula can use a Progression Table for character growth, equipment growth, experience, or level-based calculations.

A Progression Table converts a cumulative value into information such as:

```
Current Stage
Value required for the next Stage
Current Stage progress
Current Stage progress ratio
```

Example use cases:

```
Character Experience → Character Level
Weapon Experience    → Weapon Level
Skill Experience     → Skill Level
```

Common Progression Table functions include:

```
curve.stage(value)
curve.value(stage)
curve.increment(stage)
curve.current(value)
curve.next(value)
curve.ratio(value)
```

Example:

```
curve.stage(self.stat.Experience)
```

This returns the current Stage based on the character's Experience Stat.

### Automatic and Manual Evaluation

A Formula can be assigned to a Stat.

When that Stat is read, the system evaluates the Formula automatically.

```
HealthMax Stat
    ↓
HealthMax Formula
    ↓
Calculated HealthMax Value
```

You can also evaluate a Formula manually with the `Calculate` function.

```
Calculate
Self   = Current Character Component
Target = Target Character Component
```

This is useful for one-time calculations such as attack damage, healing amount, or skill cost.

### Example: Normal Attack Damage

```
Formula:
self.stat.Attack - target.stat.Defense
```

```
Attacker:
Attack = 30

Target:
Defense = 10
```

```
Result:
Damage = 20
```

### Example: Maximum Health

```
Formula:
100 + self.stat.Vitality * 20
```

```
Vitality = 5

Result:
HealthMax = 200
```

### Next Step

After understanding these concepts, continue with:

* Formula Properties
* Formula API
* Progression Tables
* Common Formula Examples
