Skip to content

DamageResult ​

Inherits: RefCounted

Everything that happened to one hit, from the effect's number to the health that was lost.

Description ​

Created by CombatManager.apply_damage, completed by each phase (attacker's calculation, defender's calculation, pools) and then handed to every consumer: the combat log, damage numbers and animations, threat, leech, damage reflection, proc effects and event triggers. Replaces the untyped dictionaries that used to be passed between the layers. See docs/systems/entity-stats.md, section 17.

Variables ​

Variantattackernull
Varianttargetnull
EffectInstanceeffectnull
Stringability_name""
intdamage_type0
boolcan_be_avoidedtrue
intchain_depth0
floatraw0.0
floatdone0.0
floattaken0.0
floatredirected0.0
floatabsorbed0.0
floathealth_damage0.0
OutcomeoutcomeOutcome.HIT
boolglancingfalse
Stringavoid_kind""
booltarget_diedfalse
booltarget_was_deadfalse
intimmunity_id0
Stringerror""
Array[TriggerRecord]triggers_done[]
Array[TriggerRecord]triggers_taken[]
Array[ModifierStep]steps_done[]
Array[ModifierStep]steps_taken[]

Methods ​

DamageResultcreate( p_attacker: Variant, p_target: Variant, p_effect: EffectInstance, p_damage_type: int, p_raw: float, p_can_be_avoided: bool = true, p_chain_depth: int = 0 ) static
DamageResultfailed( reason: String, p_attacker: Variant = null, p_target: Variant = null ) static
voidadd_trigger_done( record: TriggerRecord )
voidadd_trigger_taken( record: TriggerRecord )
voidadd_step_done( step: ModifierStep )
voidadd_step_taken( step: ModifierStep )
voidmark_avoided( record: TriggerRecord )
voidmark_missed( record: TriggerRecord )
voidmark_immune( p_immunity_id: int = 0 )
voidmark_negated()
voidmark_target_dead()
voidmark_fully_redirected( amount: float )
intnext_chain_depth()
boolis_success()
boolis_hit()
boolwas_avoided()
boolwas_missed()
boolwas_crit()
boolhas_tag( tag: String )
floatblocked_amount( tag: String )
floatmitigated_amount()
floatget_amount( basis: DamageBasis )
TriggerRecordfind_avoid_record()
Stringfloating_text()
Stringlog_text()
Stringformat_phrase( template: String )
Stringname_of( unit: Variant ) static
floattag_magnitude( tag: String )

Enumerations ​

enum Outcome ​

How the hit ended

  • HIT = 0 - The hit landed (possibly reduced to 0 by modifiers: that is still a hit)
  • AVOIDED = 1 - An avoid trigger (dodge, parry) negated the hit
  • IMMUNE = 2 - The target was immune to this damage type
  • FULLY_REDIRECTED = 3 - All of the damage was redirected to someone else
  • TARGET_DEAD = 4 - The target was already dead: nothing happened
  • FAILED = 5 - The pipeline could not process the hit (see error)
  • NEGATED = 6 - Modifiers reduced the hit to nothing and the project says that is not a hit (GameplayConfig)
  • MISSED = 7 - An avoid trigger in the attacker's own phase (a miss) ended the hit before it reached the target

enum DamageBasis ​

Which number a consumer wants (threat, leech, damage reflection ...): a dev choice, see get_amount

  • RAW = 0 - The effect's own number, before anything
  • AFTER_DONE = 1 - After the attacker's modifiers
  • AFTER_TAKEN = 2 - After the defender's modifiers, before pools (includes what shields absorbed)
  • HEALTH_ONLY = 3 - Only what actually reached health

Variable descriptions ​

Variant attacker = null ​

Who dealt the hit.

Variant target = null ​

Who took the hit.

EffectInstance effect = null ​

The effect that hit.

String ability_name = "" ​

Display name of the ability / effect (captured so the log does not depend on the effect staying alive)

int damage_type = 0 ​

The damage type of the hit.

bool can_be_avoided = true ​

True when the hit can be dodged, parried or blocked.

int chain_depth = 0 ​

0 for a normal hit, +1 for damage caused by reacting to a hit (damage reflection, reactive damage). See max_reflect_chain

float raw = 0.0 ​

The effect's own number

float done = 0.0 ​

After the attacker's modifiers (damage-done phase)

float taken = 0.0 ​

After redirection and the defender's modifiers, before pools (damage-taken phase)

float redirected = 0.0 ​

Sent to another entity by redirection effects

float absorbed = 0.0 ​

Absorbed by protective pools (shields)

float health_damage = 0.0 ​

What actually reached health

Outcome outcome = Outcome.HIT ​

How the hit ended (hit, miss, dodge ...).

bool glancing = false ​

The hit was a glancing one (see HitRules): it landed, but weaker. Set when the result is made, from the effect that causes it

String avoid_kind = "" ​

The tag of the avoid trigger that fired (only for Outcome.AVOIDED and Outcome.MISSED)

bool target_died = false ​

True when the hit killed the target.

bool target_was_dead = false ​

True when the target was already dead.

int immunity_id = 0 ​

Why the pipeline failed (only for Outcome.FAILED) The immunity that blocked the hit (only for Outcome.IMMUNE)

String error = "" ​

What went wrong, when the hit could not be worked out.

Array[TriggerRecord] triggers_done = [] ​

Triggers that fired in the attacker's phase (critical strike ...)

Array[TriggerRecord] triggers_taken = [] ​

Triggers that fired in the defender's phase (dodge, block ...)

Array[ModifierStep] steps_done = [] ​

Modifiers that changed the number in the attacker's phase, in the order they ran

Array[ModifierStep] steps_taken = [] ​

Modifiers that changed the number in the defender's phase, in the order they ran

Method descriptions ​

DamageResult create( p_attacker: Variant, p_target: Variant, p_effect: EffectInstance, p_damage_type: int, p_raw: float, p_can_be_avoided: bool = true, p_chain_depth: int = 0 ) ​

A new result for a hit of p_raw from the attacker to the target. done and taken start at p_raw and the phases change them

DamageResult failed( reason: String, p_attacker: Variant = null, p_target: Variant = null ) ​

A result for a hit the pipeline could not process. Consumers must check is_success().

void add_trigger_done( record: TriggerRecord ) ​

Keeps a trigger that fired in the attacker's phase

void add_trigger_taken( record: TriggerRecord ) ​

Keeps a trigger that fired in the target's phase

void add_step_done( step: ModifierStep ) ​

Keeps a modifier that changed the number in the attacker's phase

void add_step_taken( step: ModifierStep ) ​

Keeps a modifier that changed the number in the target's phase

void mark_avoided( record: TriggerRecord ) ​

An avoid trigger negated the hit: nothing after this point reaches the pools

void mark_missed( record: TriggerRecord ) ​

An avoid trigger in the attacker's phase (a miss) ended the hit: the target is never touched

void mark_immune( p_immunity_id: int = 0 ) ​

Ends the hit as IMMUNE: nothing reaches the pools

void mark_negated() ​

The defender's modifiers reduced the hit to nothing and the project does not count that as a hit

void mark_target_dead() ​

The target was already dead: the hit does nothing

void mark_fully_redirected( amount: float ) ​

Ends the hit as FULLY_REDIRECTED: a guardian took all of it, nothing reaches the pools

int next_chain_depth() ​

The chain depth a hit caused by reacting to this one must carry

bool is_success() ​

False for a result made by failed

bool is_hit() ​

Did the hit land (outcome HIT)? An avoided, immune or redirected hit did not

bool was_avoided() ​

Did an avoid trigger (dodge) negate the hit?

bool was_missed() ​

Did the attacker miss (an avoid trigger in the attacker's phase)?

bool was_crit() ​

True when a boost trigger (critical strike) fired in the attacker's phase

bool has_tag( tag: String ) ​

True when a trigger with this tag fired in either phase

float blocked_amount( tag: String ) ​

How much the defender's modifiers that required this trigger tag took off (the log's "blocked 10")

float mitigated_amount() ​

How much the defender's side removed from the hit (redirection excluded)

float get_amount( basis: DamageBasis ) ​

The number a consumer should use, chosen by the dev (see DamageBasis)

TriggerRecord find_avoid_record() ​

The trigger record of the avoid trigger that negated this hit (null when there is none)

String floating_text() ​

The short text that floats over the target: the number for a hit, the trigger's own message (else its tag) for an avoided hit, "Immune", "No damage". Empty when nothing should show

String log_text() ​

One combat log line for the hit, built from the trigger phrases and the amounts

String format_phrase( template: String ) ​

Fills {attacker} {target} {ability} {damage} in a phrase template

String name_of( unit: Variant ) ​

A name for the log and the interface: the display name, else the node name, else "Unknown"

float tag_magnitude( tag: String ) ​

The magnitude of the first trigger with this tag in either phase (0 when the tag did not fire)