Skip to content

Stat effects: how they work ​

A stat effect is a Resource in the stat_effects array of a StatDefinition. The entity's StatInstance for the stat keeps the effects, and the system that consumes each type asks it for the effects of that type (get_effects_by_type). A stat only takes part when the entity has points in it (get_total() != 0) and the stat is active.

The basic page lists the nine types and their fields. This page is about how they are read.

The base class ​

StatEffect holds what every type shares:

MemberWhat it is
effect_enabledA switch: a disabled effect stays on the stat but is skipped
active_trigger_typePERMANENT, IN_COMBAT, OUT_OF_COMBAT, checked against context.in_combat
conditionsArray[Condition]: entity conditions that must all be true. Evaluated with the owner and the opponent in the context
formula, returns, max_resultThe value: the formula that turns points into a number, optional diminishing returns, a cap
only_schools, only_abilities, only_effects, attack_style_filter, periodic_filterHit filters: the effect only works for hits and heals of those schools, abilities and effects, melee or ranged attacks, direct or periodic. passes_hit_filters(context) checks them against the school, ability_id, effect_ids, is_ranged and is_periodic keys of the context (a context without a key passes); applies_to_context and the rule collection call it
evaluate_points(points, formula_context)The value of the effect for the points: formula, then returns, then the cap
is_active(context)Enabled, the trigger type fits the combat state, the conditions are met
validate()The problems the editor shows (a missing target, an empty list)

get_effect_type() returns the EffectType the consumers look for:

MULTIPLIER, POOL_MODIFIER, ABILITY_MODIFIER, CALCULATION_MODIFIER, CALCULATION_TRIGGER,
POOL_RESTORATION, REACTIVE_DAMAGE, CUSTOM, TRIGGER_RULE, GAIN_MODIFIER

New types were appended after CUSTOM, so the saved numbers of the older ones never change. CUSTOM is reserved and nothing reads it.

The fields value_per_point, use_scaling, scaling_mode, scaling_threshold, scaling_curve and curve_max_value are kept only so that old saved effects load; a legacy effect gets its formula built from them (ensure_formula).

Who reads each type ​

TypeConsumed byWhen
MultiplierStatEffectStatsComponent._apply_multiplier_effectsWhen a stat changes. A cascade guard stops after 10 passes. Results are cached as bonuses and re-applied when a condition flips
PoolModifierStatEffectStatsComponent._update_pool_effectsWhen a stat changes and at the start and end of combat. Starts from the pool's own base each time, so it never compounds
AbilityModifierStatEffectStatsComponent.get_ability_modifier_entries, asked by the ability for its cooldown, cost or resource gain, and by its use and target strategies for the cast time (cast_duration) and the range (max_range): apply_modifiers of UseStrategyInstance and TargetStrategyInstance add the entries of the stats for the properties in AbilityInstance.STAT_MODIFIED_PROPERTIESEvery time the ability property is read; nothing is stored, so nothing goes stale
CalculationModifierStatEffectCalculationBase._run_modifiersPhase 2 of a calculation
CalculationTriggerStatEffectCalculationBase._roll_triggersPhase 1 of a calculation
TriggerRuleStatEffectCalculationBase._collect_rulesBefore the triggers roll
PoolRestorationStatEffectStatsComponent hit and kill handlersAfter a resolved hit (leech, mana on hit, health on kill)
ReactiveDamageStatEffectStatsComponent through CombatReactionsAfter a resolved hit taken (damage reflection)
HitChanceStatEffectHitRules.get_chance through get_accuracy and get_evasionWhen an ability that can miss rolls its hit roll
GainModifierStatEffectStatsComponent.modify_gain(channel, amount)When the game gives the entity experience, gold, loot, threat or a resource

Trigger effects and rules ​

CalculationTriggerStatEffect rolls its tag with the value of the formula as the chance in percent (get_effective_trigger_chance, kept between 0 and 100).

TriggerRuleStatEffect has applies_to (RuleSide: OWNER, OPPONENT_ACTING_ON_ME, OPPONENT_DEFENDING_AGAINST_ME) target_calculations (the calculations the rule works in, as numbers; empty = all) and, when no tag is chosen, tag_kind (TagKindFilter: any, avoid, mitigate, boost). The two enums are in that class; CalculationBase uses plain numbers for the sides because the class needs CalculationBase and the compiler does not allow the cycle.

Conditions, the opponent and the context ​

A condition on a stat effect is an EntityCondition. It gets the effect's context dictionary:

KeyValue
ownerThe entity that has the stat
opponentThe other side of the hit being calculated, or null outside a hit
in_combatThe combat state
damage_type, calculation_target, is_damage_calculation, can_be_avoidedAdded by the calculations
the tag of a fired trigger, and "magnitude:<tag>"Added when a trigger fires, so later modifiers can require it

The target kind of an entity condition picks who it asks: Argument Entity is the owner and Opponent the opponent. This is how "+30 % damage against Undead" works: the condition EntityHasTagCondition is asked about the opponent.

Effects that are cached as bonuses (multiplier, pool modifier) cannot ask the opponent. StatsComponent remembers whether each conditional effect was active at the last check (_condition_snapshot) and re-applies them only when one flipped: at the start and end of combat and when the master pool changes.

Writing a new type ​

  1. Extend StatEffect in a script and return your own EffectType (add it after the last value) from get_effect_type().
  2. Add it to the Add Stat Effect dialog: the type list and the match in StatEditor._create_new_stat_effect (addon code, so this one is a change to the addon). StatEffectPropertyEditor draws the fields of each type, so give a new type its own section there.
  3. Write the consumer: the place in your game that calls stat_instance.get_effects_by_type(...) and applies them.

For a new formula, diminishing returns or condition nothing needs registering. Put the script in the project folder (res://src/stat_formulas/, res://src/stat_diminishing_returns/, res://src/stat_conditions/) and the editor finds it with StatClassScanner. The addon folder is overwritten by updates, so keep your own classes in the project.

Class pages ​

The classes are in the list for this section: StatEffect and its nine children.