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:
| Member | What it is |
|---|---|
effect_enabled | A switch: a disabled effect stays on the stat but is skipped |
active_trigger_type | PERMANENT, IN_COMBAT, OUT_OF_COMBAT, checked against context.in_combat |
conditions | Array[Condition]: entity conditions that must all be true. Evaluated with the owner and the opponent in the context |
formula, returns, max_result | The value: the formula that turns points into a number, optional diminishing returns, a cap |
only_schools, only_abilities, only_effects, attack_style_filter, periodic_filter | Hit 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_MODIFIERNew 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 ​
| Type | Consumed by | When |
|---|---|---|
MultiplierStatEffect | StatsComponent._apply_multiplier_effects | When a stat changes. A cascade guard stops after 10 passes. Results are cached as bonuses and re-applied when a condition flips |
PoolModifierStatEffect | StatsComponent._update_pool_effects | When a stat changes and at the start and end of combat. Starts from the pool's own base each time, so it never compounds |
AbilityModifierStatEffect | StatsComponent.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_PROPERTIES | Every time the ability property is read; nothing is stored, so nothing goes stale |
CalculationModifierStatEffect | CalculationBase._run_modifiers | Phase 2 of a calculation |
CalculationTriggerStatEffect | CalculationBase._roll_triggers | Phase 1 of a calculation |
TriggerRuleStatEffect | CalculationBase._collect_rules | Before the triggers roll |
PoolRestorationStatEffect | StatsComponent hit and kill handlers | After a resolved hit (leech, mana on hit, health on kill) |
ReactiveDamageStatEffect | StatsComponent through CombatReactions | After a resolved hit taken (damage reflection) |
HitChanceStatEffect | HitRules.get_chance through get_accuracy and get_evasion | When an ability that can miss rolls its hit roll |
GainModifierStatEffect | StatsComponent.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:
| Key | Value |
|---|---|
owner | The entity that has the stat |
opponent | The other side of the hit being calculated, or null outside a hit |
in_combat | The combat state |
damage_type, calculation_target, is_damage_calculation, can_be_avoided | Added 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 ​
- Extend
StatEffectin a script and return your ownEffectType(add it after the last value) fromget_effect_type(). - Add it to the Add Stat Effect dialog: the type list and the
matchinStatEditor._create_new_stat_effect(addon code, so this one is a change to the addon).StatEffectPropertyEditordraws the fields of each type, so give a new type its own section there. - 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.