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 ​
Variant | attacker | null |
Variant | target | null |
EffectInstance | effect | null |
String | ability_name | "" |
int | damage_type | 0 |
bool | can_be_avoided | true |
int | chain_depth | 0 |
float | raw | 0.0 |
float | done | 0.0 |
float | taken | 0.0 |
float | redirected | 0.0 |
float | absorbed | 0.0 |
float | health_damage | 0.0 |
Outcome | outcome | Outcome.HIT |
bool | glancing | false |
String | avoid_kind | "" |
bool | target_died | false |
bool | target_was_dead | false |
int | immunity_id | 0 |
String | error | "" |
Array[TriggerRecord] | triggers_done | [] |
Array[TriggerRecord] | triggers_taken | [] |
Array[ModifierStep] | steps_done | [] |
Array[ModifierStep] | steps_taken | [] |
Methods ​
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 ) static |
DamageResult | failed( reason: String, p_attacker: Variant = null, p_target: Variant = null ) static |
void | add_trigger_done( record: TriggerRecord ) |
void | add_trigger_taken( record: TriggerRecord ) |
void | add_step_done( step: ModifierStep ) |
void | add_step_taken( step: ModifierStep ) |
void | mark_avoided( record: TriggerRecord ) |
void | mark_missed( record: TriggerRecord ) |
void | mark_immune( p_immunity_id: int = 0 ) |
void | mark_negated() |
void | mark_target_dead() |
void | mark_fully_redirected( amount: float ) |
int | next_chain_depth() |
bool | is_success() |
bool | is_hit() |
bool | was_avoided() |
bool | was_missed() |
bool | was_crit() |
bool | has_tag( tag: String ) |
float | blocked_amount( tag: String ) |
float | mitigated_amount() |
float | get_amount( basis: DamageBasis ) |
TriggerRecord | find_avoid_record() |
String | floating_text() |
String | log_text() |
String | format_phrase( template: String ) |
String | name_of( unit: Variant ) static |
float | tag_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 (seeerror) - 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)