> For the complete documentation index, see [llms.txt](https://enchantedmobs.superiormc.cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://enchantedmobs.superiormc.cn/format/math-calculate-format.md).

# Math Calculate Format

When `config.yml -> math.enabled` is enabled, supported numeric fields may use expressions instead of fixed values.

```yaml
value: '2 + {level} * 0.5'
random: '0.1 + {level} * 0.02'
```

The expression syntax is almost identical to UltimateShop's math format. See the [UltimateShop format documentation](https://ultimateshop.superiormc.cn/format) for the complete operator and function reference.

## Available values

Depending on the receiving field and current trigger, expressions may include:

* `level` or `{level}`;
* root power `variables`;
* runtime entity values such as `{owner_health}`, `{source_health}`, `{target_health_percent}`, and `{skill_fall_distance}`;
* `{distance}` between `SOURCE` and `TARGET` when both exist in the same world;
* numeric trigger context placeholders listed below;
* field-specific values such as `{original}`, `{now}`, `{max}`, or other values documented by that Ability, Power Condition, or Power Modifier;
* numeric PlaceholderAPI results when a player viewer is available.

## Numeric trigger context placeholders

Every numeric entry created through `BuiltinContextKeys` is automatically exposed using its key name inside braces. Only `Number` types such as `Double`, `Float`, and `Integer` are registered; booleans, entities, items, and enum values are not treated as mathematical variables.

| Placeholder           | Number type | Context value                                                         |
| --------------------- | ----------- | --------------------------------------------------------------------- |
| `{original_damage}`   | `Double`    | Damage captured before compatible damage modifiers execute.           |
| `{original_amount}`   | `Double`    | Original generic mutable amount, such as health-regain amount.        |
| `{original_duration}` | `Float`     | Original duration supplied by a duration-capable trigger.             |
| `{original_yield}`    | `Float`     | Original explosion yield supplied by a compatible explosion trigger.  |
| `{original_radius}`   | `Float`     | Original explosion radius supplied by a compatible explosion trigger. |
| `{minimum_damage}`    | `Double`    | Minimum-damage floor carried by compatible damage triggers.           |
| `{bow_force}`         | `Float`     | Bow draw force supplied by a compatible ranged trigger.               |
| `{target_count}`      | `Integer`   | Number of targets supplied by a compatible targeting context.         |

A placeholder is replaced only when the active trigger supplied that value. An unavailable context value remains unresolved, so use each placeholder only with compatible triggers.

```yaml
on-attack:
  abilities:
    heal-from-damage:
      type: set_health
      target: OWNER
      amount: 'min({owner_health} + {original_damage} * 0.25, {owner_max_health})'
```

The same placeholders work in context-aware text fields and in numeric fields resolved through `getDouble(...)` or `getInt(...)`.

## Variables and resolution order

Root power variables are resolved before numeric trigger context placeholders. A reusable variable may therefore reference runtime values:

```yaml
variables:
  damage-bonus: '{original_damage} * (0.1 + {level} * 0.01)'

on-attack:
  modifiers:
    increase-damage:
      type: damage
      operation: ADD
      value: '{damage-bonus}'
```

Resolution follows this order:

1. level and field-specific arguments;
2. root power variables;
3. numeric trigger context placeholders;
4. entity and distance placeholders;
5. PlaceholderAPI values.

Adding another numeric built-in `ContextKey` automatically creates a placeholder with the same key name; no separate expression-parser registration is required.

## Random ranges

```yaml
amount: 2~5
```

This selects a value between the two endpoints using the resolver expected by the field.

## Level selectors

```yaml
amount:
  '==1': 2
  '>=2;;<=4': '2 + {level}'
  '>=5': 10
```

Entries are evaluated from top to bottom, and the first matching selector is used. Quote selector keys in YAML.
