Skip to content

Growth, core stats and gain channels ​

Three things sit around the stat system proper: how stats grow with the level, the nine stats the engine itself reads, and the named channels through which stats change what an entity is given.

Level growth ​

A stat or pool grows with the level of its entity through three fields (the same on StatDefinition, PoolDefinition and GrowthOverride):

FieldMeaning
growth_formulaA CalculationFormula. The input is the levels gained: level - 1
growth_returnsOptional DiminishingReturns on the levels gained
growth_maxA ceiling on the total growth (0 = none)

calculate_growth(level, context) returns FormulaPipeline.growth_at(level, formula, returns, context, growth_max). The result is 0 without a formula.

The value of the stat is (base + growth + bonus) x multiplier, and the growth of a pool is added to its capacity.

The layers ​

StatsComponent.growth_of(definition, context) is the one place that decides the growth of a stat or pool. It tries four layers and the first with an answer wins:

#LayerHeld by
1The entity's own overrideStatsData.growth_overrides, a GrowthOverride per stat or pool id
2The entity's growth profile and its parentsGrowthProfile, chosen by StatsData.growth_profile_id
3The project's default profileGameplayConfig.default_npc_growth_profile_id, read through CombatOptions.default_npc_growth_profile_id()
4The definitionStatDefinition.calculate_growth / PoolDefinition.calculate_growth

An entry replaces the layers below, even an empty one, which stops the stat from growing for that entity. StatsData.remove_growth_override goes back to the layers below.

GrowthProfile is a database resource of type growth_profile (src/data/stats/growth_profiles/) with parent_profile_id and growth_overrides (the same get_growth_override / set_growth_override / remove_growth_override calls as StatsData, so one editor serves both). get_chain() returns the profile, its parent, the parent's parent... stopping at a missing parent, a loop and MAX_CHAIN (8); GrowthProfile.build_chain(profile_id, default_profile_id) adds the default; find_entry(chain, target_id) gives the nearest entry; validate() lists the problems the editor shows in yellow. The toolkit makes an empty profile GrowthProfile.ID_DEFAULT for every project (Database._ensure_default_growth_profile).

Who gets the default. The chain is built in StatsComponent.setup_from_stats_data from stats_data.growth_profile_id and StatsComponent.default_growth_profile_id. EntityComponentRegistry sets the second one before the setup, for an entity whose definition is an NPCDefinition; a player's component keeps 0, so only the profile its class names (if any) applies. A UniqueEntityData with a stats override duplicates the whole StatsData, so the profile carries over.

Weapon damage. The core stat Weapon Damage can have an entry like any stat. growth_of returns 0 for it while the entity's own base weapon damage is 0, so a profile cannot give a weaponless NPC a weapon.

When the level changes ​

StatsComponent.set_level(new_level) recomputes the growth of every stat, then the stat effects that depend on the level, then the capacity of every pool. The rule for the current value of a pool whose maximum changed is chosen by _level_change_capacity_rule():

  • an NPC (an entity whose definition is an NPCDefinition) always uses keep percentage: 65 % of the old maximum is 65 % of the new one, up or down, whatever the project settings say;
  • everyone else uses the level_up_capacity_rule of the game settings.

See Pools and damage layers.

Core stats ​

Nine stats are read by the engine by id (StatsComponent.CoreStats). They are ordinary stats in every other respect: they have a definition in res://src/data/stats/, show in the Stats editor, and take formulas, growth, conditions and effects like any stat.

CoreStatDefaults lists them:

IdStatDefaultHidden
1Movement Speed6 m/sno
2Attack Speed1xno
3Global Cooldown2 sno
4Weapon Speed3 syes
5Cast Speed1xno
6Carry Weight50no
7Sight Range12 mno
8Weapon Damage0yes
9Weapon Damage Variance0yes

Database creates the definition of any core stat that does not exist yet, the first time it is used (in the editor or when the game starts), so a project never has to author them and an older project gets them by itself. Once the file exists it is the project's: edit it freely, but keep the id, which the engine looks for. The ids 1 to 9 are reserved (CoreStatDefaults.MAX_CORE_ID); project stats get seven-digit ids.

Per entity, the core stat overrides of StatsData (set_movement_speed_base and the like) set the base value; 0 means "the definition's base value". clear_core_stat_overrides sets them all to 0.

The weapon stats (4, 8 and 9) are set by the equipped weapon, or by StatsData for an entity with an intrinsic weapon (a wolf's bite): set_weapon_damage_variance, set_weapon_speed_base, has_any_weapon_stats.

Gain channels ​

A gain channel is a name for something an entity is given. GainChannels lists the ones the toolkit asks about:

ChannelThe amount
experienceExperience points the player receives
currencyGold from rewards: gold find
loot_quantityThe quantity of every item stack of loot a killer gets. A fraction is a chance of one more
loot_rarityMagic find: raises the weight of the rarer-than-average entries of a loot table
threatThe threat a hit generates
resourceThe resource an ability gains for its user (Rage, Combo ...)
status_durationThe duration of a status effect put on the entity: tenacity
effect_durationThe duration of the timed effects the entity applies, to others or to itself (EffectInstance.initialize, after the time strategy is set up; never below the minimum duration)
shield_strengthThe size of the shield an AddHealthPoolEffect puts up, for its originator
resource_drain_takenWhat another entity drains from a resource pool (ModifyResourcePoolEffect, calculation type Add with a negative value): the victim's channel shortens it

A project can use any other name from its own code.

gdscript
var gold: float = player.components.stats().modify_gain(GainChannels.CURRENCY, 100.0)
var items: int = stats.modify_gain_int(GainChannels.LOOT_QUANTITY, 3, true)   # 1.2 items = 20 % chance of 2

StatsComponent.modify_gain(channel, amount) collects every GainModifierStatEffect of the entity's stats on the channel, and returns:

(amount + flat) x max(1 + percent / 100, 0) x factor      never below 0

The effect's calculation type says which of the three it adds to: Add and Minus to flat, the percentage types to percent, Multiply to factor. With no effect on the channel the amount comes back unchanged. modify_gain_int rounds to the nearest whole number; with probabilistic set, a fraction is a chance of one more.

Because channels are plain strings, a stat can change something without any system knowing which stat it is.

Stat groups ​

A stat joins StatGroupDefinitions in its groups array. StatGroupUtility answers the questions the character sheet, the tooltips and the group-targeting effects ask: which stats are in a group, which section a stat is listed under, which stats are hidden. A group changes nothing about how a stat is calculated.