Skip to content

CalculationFormula ​

Inherits: Resource

Inherited by: FlatCalculationFormula, HyperbolicCalculationFormula, LinearCalculationFormula

Slot 2 of every per-point stat effect: turns (effective) stat points into the value the effect applies.

Description ​

Armor is a Hyperbolic formula, a flat damage bonus is a Linear one, a fixed crit bonus is a Flat one. To add your own, create a child class in your project folder (see docs/systems/entity-stats.md, section 18.2):

@tool class_name MyArmorFormula extends CalculationFormula @export var k: float = 120.0 func evaluate(points: float, context: FormulaContext = null) -> float: return 100.0 * points / (points + k)

Rules for your own formulas: @tool (so the editor can draw the preview), a pure function of the inputs (no state, no scene access), and a class_name. Override evaluate and, if you like, get_label, get_description, get_preview_range and validate.

Properties ​

LevelScalinglevel_scaling

Methods ​

floatevaluate( points: float, context: FormulaContext = null )
Stringget_label()
Stringget_description()
Vector2get_preview_range()
Array[String]validate()
floatget_level_factor( context: FormulaContext )

Constants ​

  • float MIN_LEVEL_FACTOR = 0.0001 - Below this a level factor is treated as this value, so a formula never divides by zero

Property descriptions ​

LevelScaling level_scaling ​

Optional level dependence. Null (default): level is ignored

Method descriptions ​

float evaluate( points: float, context: FormulaContext = null ) ​

Points in, value out. The base class is the identity so a bare CalculationFormula is harmless

String get_label() ​

Short name shown in the editor's formula picker

String get_description() ​

One-line description with the current numbers (tooltips, editor)

Vector2 get_preview_range() ​

The points range the editor graph and table draw (x from, x to)

Array[String] validate() ​

Configuration problems, as readable messages (empty = fine). Shown in the editor

float get_level_factor( context: FormulaContext ) ​

The level factor of this formula's LevelScaling for the context (1.0 when level scaling is off)