Skip to content

PoolInstance ​

Inherits: RefCounted

One pool (health, mana, rage, a shield) on one entity: the current value, the capacity bonus, the overfill, and the regeneration or decay timers.

Description ​

The definition (PoolDefinition) is shared; the instance holds what is particular to the entity. The maximum is base_max_value plus the capacity bonus; overfill is on top of it. Raising the capacity can raise the current value with it, by the project's capacity rule (GameplayConfig, Pools); lowering it only caps the current value.

Variables ​

PoolDefinitiondefinition
floatcurrent_value0.0
floatbase_max_value0.0
floatmax_value0.0
floatoverfill_current0.0
Entityentity
intpool_gen0 # GenerationLogic enum value
floatgen_rate0.0
floatgen_value0.0
boolregeneration_blockedfalse
ChronoManagerchrono_manager

Methods ​

voidsetup_from_definition( p_chrono_manager: ChronoManager, pool_def: PoolDefinition, initial_current: float = -1.0 )
voidset_entity( p_entity: Entity )
voidset_capacity_bonus( new_bonus: float, rule: int = -1 )
voidadd_capacity_bonus( amount: float )
floatget_capacity_bonus()
floatabsorb_damage( incoming_damage: float, damage_type: int )
floatadd_value( amount: float )
voidtick( delta: float )
voidset_generation_properties( new_gen_logic: int, new_gen_rate: float, new_gen_value: float )
Stringget_generation_description()
floatget_total_current_value()
floatget_total_max_value()
floatget_effective_max_value()
floatget_base_max_value()
floatget_fill_percentage()
floatget_normal_fill_percentage()
boolis_empty()
boolis_full()
boolhas_overfill()
boolcan_absorb_damage()
voidset_current_value( new_value: float )
voidset_max_value( new_max: float )
Stringget_display_string()
voidcleanup()
Dictionaryto_save_data()
voidfrom_save_data( data: Dictionary )
boolis_valid()

Signals ​

value_changed( new_current: float, new_max: float ) ​

========== SIGNALS ==========

overfill_changed( new_overfill: float ) ​

Emitted when the overfill changes: the new overfill.

absorbed_damage( damage_absorbed: float, damage_type: int ) ​

Emitted when the pool absorbs damage: the amount and the damage type.

pool_depleted() ​

Emitted when the pool reaches zero.

pool_restored() ​

Emitted when the pool goes up from zero.

pool_capacity_increased( amount: float ) ​

Emitted when the maximum of the pool grows: by how much.

pool_healed( amount: float, source: String ) ​

Emitted when the pool is healed: the amount and where it came from.

Variable descriptions ​

PoolDefinition definition ​

========== CORE PROPERTIES ==========

float current_value = 0.0 ​

The value of the pool now.

float base_max_value = 0.0 ​

Store the actual base max separately!

float max_value = 0.0 ​

This becomes a computed property (base + bonuses)

float overfill_current = 0.0 ​

The overfill the pool holds now (above its maximum).

Entity entity ​

Entity reference for callbacks

int pool_gen = 0 # GenerationLogic enum value ​

Live generation/decay properties (can be modified at runtime)

float gen_rate = 0.0 ​

Ticks per second

float gen_value = 0.0 ​

Amount per tick

bool regeneration_blocked = false ​

Set by the stats component while its owner is dead

ChronoManager chrono_manager ​

Regeneration, decay and overfill decay run on the chrono manager's shared pool tick (one timer for every pool of every entity), not on a timer each

Method descriptions ​

void setup_from_definition( p_chrono_manager: ChronoManager, pool_def: PoolDefinition, initial_current: float = -1.0 ) ​

Sets the pool up from its definition: the maximum, the generation settings (copied, so effects can change them for this entity) and the starting value (initial_current, or by the definition's start value)

void set_entity( p_entity: Entity ) ​

Tells the pool which entity it belongs to

void set_capacity_bonus( new_bonus: float, rule: int = -1 ) ​

rule is a GameplayConfig.CapacityRule to use instead of the project's capacity change rule (-1: the project's); the stats component passes the level-up rule while an entity levels up

void add_capacity_bonus( amount: float ) ​

Adds amount to the capacity bonus (negative to take it away)

float get_capacity_bonus() ​

The capacity bonus: what stats, growth and equipment add to the maximum

float absorb_damage( incoming_damage: float, damage_type: int ) ​

Takes the part of incoming_damage the pool absorbs (overfill first, by the definition's per-hit cap and damage types) and returns how much that was. Emits pool_depleted when the pool is empty afterwards

float add_value( amount: float ) ​

A positive amount heals the pool (fills the normal value, then the overfill) and returns what was added; a negative amount consumes that much and returns it

void tick( delta: float ) ​

Called by the chrono manager's pool tick with the real time since the last tick: runs the ticks of regeneration / decay (gen_rate per second) and of overfill decay (once a second) that fell in that time

void set_generation_properties( new_gen_logic: int, new_gen_rate: float, new_gen_value: float ) ​

Changes how the pool regenerates or decays at runtime: the logic, the ticks per second and the amount per tick

String get_generation_description() ​

A line that says how the pool regenerates or decays, for tooltips

float get_total_current_value() ​

The current value including the overfill

float get_total_max_value() ​

The effective maximum plus the overfill capacity of the definition

float get_effective_max_value() ​

The maximum including the capacity bonus: the real size of the pool

float get_base_max_value() ​

The maximum without the capacity bonus

float get_fill_percentage() ​

How full the pool is, overfill included, as a fraction of the effective maximum

float get_normal_fill_percentage() ​

How full the pool is, without the overfill, as a fraction of the effective maximum

bool is_empty() ​

True when nothing is left, overfill included

bool is_full() ​

True when the normal value has reached the effective maximum

bool has_overfill() ​

True while there is overfill

bool can_absorb_damage() ​

True while the pool has anything to absorb damage with

void set_current_value( new_value: float ) ​

Sets the current value outright, kept inside the limits of the definition. Emits value_changed, and pool_restored when it rises from empty or pool_depleted when it falls to empty

void set_max_value( new_max: float ) ​

Sets the base maximum outright (the capacity bonus is added on top) and caps the current value

String get_display_string() ​

The pool as text for the interface: current/max, with (+overfill) when there is overfill

void cleanup() ​

Stops the regeneration and decay timers. Called when the pool is removed

Dictionary to_save_data() ​

The values a save keeps: the pool id, the current value and the overfill. Everything else is rebuilt on load

void from_save_data( data: Dictionary ) ​

Restores the values of to_save_data, never above the maximum the pool has right now

bool is_valid() ​

Does the instance have a definition with an id?