Damagetyperesist
Overview
The Damagetyperesist component provides functionality for entities to define and apply resistance multipliers against specific types of damage. It allows for multiple sources to contribute to a single damage type's resistance and dynamically calculates the total resistance based on the attacker's or weapon's tags, ultimately modifying incoming damage.
Dependencies & Tags
- Dependencies:
util/sourcemodifierlist
- Tags:
This component does not add or remove tags from the
instit is attached to. Instead, it defines and evaluates resistance based on stringtagidentifiers (e.g., "fire", "melee") which are then checked against theattackerorweaponentities usingattacker:HasTag(k)orweapon:HasTag(k).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | N/A | A reference to the entity this component is attached to. |
tags | table | {} | A table where keys are damage type tags (strings) and values are SourceModifierList instances, each managing modifiers for that specific tag. |
Main Functions
AddResist(tag, src, pct, key)
- Description: Adds or updates a damage resistance modifier for a specific
tag. If aSourceModifierListfor the giventagdoes not exist, it is created. Thepctvalue represents a multiplier applied to damage (e.g.,0.5for 50% resistance,1.0for no change,1.5for 50% vulnerability). - Parameters:
tag(string): The string identifier for the damage type (e.g., "fire", "cold", "melee").src(any): The source object or identifier granting this specific resistance modifier (e.g., an item, an aura).pct(number): The resistance multiplier to apply for this source.key(any, optional): An optional key used to differentiate multiple modifiers from the samesrc.
RemoveResist(tag, src, key)
- Description: Removes a specific damage resistance modifier previously added with
AddResist. If removing a modifier causes aSourceModifierListfor atagto become empty, that list is removed from the component'stagstable. - Parameters:
tag(string): The string identifier for the damage type from which to remove resistance.src(any): The source identifier used whenAddResistwas called.key(any, optional): The key that was optionally provided whenAddResistwas called.
GetResistForTag(tag)
- Description: Retrieves the combined resistance multiplier for a single, specified damage type
tag. If no resistance is defined for the tag, it defaults to1(no change). - Parameters:
tag(string): The string identifier for the damage type.
GetResist(attacker, weapon)
- Description: Calculates the total damage multiplier by iterating through all defined resistance tags within this component. For each resistance tag, it checks if the
attackeror theirweaponpossesses that tag. If a match is found, the resistance multiplier for that tag is applied (multiplied) to the total. - Parameters:
attacker(entity, optional): The attacking entity. Can benil.weapon(entity, optional): The weapon entity used by the attacker. Can benil.
GetDebugString()
- Description: Generates a formatted string intended for debugging, listing all active damage resistance tags and their combined resistance multipliers.
- Parameters: None.