Skip to content

Entity Stats: how they are built ​

The Entity Stats chapter is about what stats do. This section is about how the code does it. Every class below has its own page, written from the comments in the code.

The pieces ​

PieceWhere it livesClass
A statThe database (DatabaseResource, stat)StatDefinition
A poolThe database (pool)PoolDefinition
What a stat doesThe stat_effects array of a statA child of StatEffect
What an entity starts withStatsData of a class, NPC or destructibleStatsData
The numbers of one entityA node componentStatsComponent
One stat of one entityInside the componentStatInstance
One pool of one entityInside the componentPoolInstance
A hit, worked outMade for every hitDamageResult, HealingResult
The four calculationsBuilt once per gameCombatCalculations
A skill of the playerThe database (proficiency), levels in the playerProficiencyDefinition, ProficiencyTracker

Everything the generated class pages list is in addons/chroniclenode/data_classes/stats/ (data) and runtime_classes/ (entity/components/stats/ and combat/).

Data and runtime ​

The same split as the rest of the toolkit: a definition is a saved resource that is shared and never changes while the game runs, an instance belongs to one entity and holds the numbers that change.

StatDefinition  --(one for every stat in the database)-->  StatInstance  (base, bonus, multiplier, growth)
PoolDefinition  --(only the pools the entity's StatsData names)-->  PoolInstance  (current, capacity, overfill)
StatsData       (starting values of one class or NPC; read, never changed, shared by all entities of the definition)

How a StatsComponent is built ​

StatsComponent.setup_from_stats_data(data) runs once when the entity starts. The data comes from the placed entity's own stats_override, else the NPC definition, else the player's class.

  1. The ImmunityComponent and StatusEffectComponent are made and their signals connected.
  2. Pools. The master pool id, then one PoolInstance for each health pool and resource pool, with the base values from the StatsData.
  3. One StatInstance for every stat in the database, whether the entity "uses" it or not. A stat with 0 points does nothing.
  4. The StatsData is applied: the base value and active flag of each stat, the weapon stats, the core stat overrides, the growth overrides.
  5. Permanent immunities are switched on.
  6. Pool capacity and regeneration are worked out from the stat effects, and the cached multiplier effects are applied.

EnvironmentalEffects builds a component with setup_from_stats_data(null): no pools and the default core stats.

The value of a stat ​

total = clamp((base + growth + bonus) x multiplier, min_value, max_value)
PartWritten by
baseStatsData at spawn, the Set base stat modifier effect
growthStatDefinition.calculate_growth(level), or the entity's GrowthOverride
bonusEquipment, the Add stat modifier effect, the multiplier stat effects of other stats
multiplierStarts at 1.0. Effects add to it

The result is limited by min_value and max_value (no negatives unless allow_negative_values), and is rounded last, after the multiplier, with decimal_places for floats.

Details in Growth, core stats and gain channels.

What the pages cover ​

PageContents
Stat effects: how they workThe base class, the nine types, how each is consumed, and how to write your own
The hit and heal pipelineFrom CombatManager.apply_damage to the pools, phase by phase
Pools and damage layersCapacity, generation, overfill, damage layers, heal absorbs
Growth, core stats and gain channelsLevel growth, overrides, the nine core stats, gain channels
Trigger tags and stat groups: how they are builtTrigger tags and stat groups. The other labels are in Types & Groups and Immunities
Proficiencies: how they are builtLevels, experience from use, the stat, requirement and reward

Signals ​

The signals worth knowing, all on StatsComponent:

SignalWhen
damage_incomingA hit is about to be worked out on the entity
damage_takenA hit reached the pools, with the damage that reached health
pool_value_changed, pool_depletedA pool changed or ran out
school_effect_blocked_by_immunityA school immunity refused an effect (the ImmunityComponent also has damage_blocked_by_immunity and status_effect_blocked_by_immunity)
master_pool_depletedThe master pool is empty: the entity dies

CombatManager announces every resolved hit and heal with damage_pipeline_completed and healing_pipeline_completed, and the entities with entity_hit_dealt, entity_hit_received, entity_heal_dealt, entity_heal_received.

Tests ​

The stats_audit suite checks the whole system with the real player (160 checks), and the effect_types_audit suite the effects that use it.