tModLoader v2024.03
A mod to make and play Terraria mods
NPC.HitModifiers Struct Reference

Represents a damage calculation in the process of being calculated for damage to be applied to an NPC. The final damage calculation will be present in the resulting HitInfo. More...

Public Member Functions

void DisableCrit ()
 Disables CritDamage calculations, and clears HitInfo.Crit flag from the resulting hit.
 
void DisableKnockback ()
 Sets the hit to have no knockback, regardless of Knockback values. Set automatically for NPC with NPC.knockBackResist values of 0 for consistency.
 
readonly int GetDamage (float baseDamage, bool crit, bool damageVariation=false, float luck=0f)
 
readonly float GetKnockback (float baseKnockback)
 
void HideCombatText ()
 Set to hide the damage number popup for this hit.
 
delegate void HitInfoModifier (ref HitInfo info)
 
void SetCrit ()
 Sets the hit to be a crit. Does nothing if DisableCrit has been called
 
void SetInstantKill ()
 Set to make the hit instantly kill the target, dealing as much damage as necessary.
Combat text will not be shown.
 
void SetMaxDamage (int limit)
 Sets an inclusive upper bound on the final damage of the hit.
Can be set by multiple mods, in which case the lowest limit will be used.
Cannot be set to less than 1
 
HitInfo ToHitInfo (float baseDamage, bool crit, float baseKnockback, bool damageVariation=false, float luck=0f)
 

Public Attributes

AddableFloat ArmorPenetration = new()
 Flat defense reduction. Applies after ScalingArmorPenetration.
Add to give bonus flat armor penetration.
Do not subtract or multiply, consider altering Defense or ScalingArmorPenetration instead.
Used by the Projectile.ArmorPenetration, Item.ArmorPenetration and Player.GetTotalArmorPenetration stats.
 
StatModifier CritDamage = new(2f, 1f)
 Applied to the final damage (after defense) result when the hit is a crit. Defaults to +1f additive (+100% damage).

Add to give hits extra crit damage (eg +0.1f for 10% extra crit damage (total +110% or 2.1 times base).
Add to StatModifier.Flat to give crits extra flat damage. Use with caution as this extra damage will not be reduced by armor.
Multiplication not recommended for buffs. Could be used to decrease the effectiveness of crits on an enemy without disabling completely.
Use of StatModifier.Base also not recommended.

 
MultipliableFloat DamageVariationScale = new()
 Multiply to adjust the damage variation of the hit.
Multiply by 0 to disable damage variation.
Default damage variation is 15%, so maximum scale is ~6.67
Only affects hits where damage variation is enabled (which is most projectile/item/NPC damage)
 
StatModifier Defense = new()
 The defense of the receiver, including any temporary modifiers (buffs/debuffs).

Increase StatModifier.Base to add extra defense.
Add for scaling buffs (eg +0.1f for +10% defense).
Multiply for debuffs (eg *0.9f for -10% defense).
Decrease StatModifier.Flat to provide flat debuffs like ichor or betsys curse

 
MultipliableFloat DefenseEffectiveness = MultipliableFloat.One * 0.5f
 The conversion ratio between defense and damage reduction. Defaults to 0.5 for NPCs. Depends on difficulty for players.
Increase to make defense more effective and armor penetration more important.

Recommend only multiplication, no addition or subtraction.
Not recommended to for buffs/debuffs. Use for gamemode tweaks, or if an enemy revolves very heavily around armor penetration.
 
StatModifier FinalDamage = new()
 Applied to the final damage result.
Used by NPC.takenDamageMultiplier to make enemies extra susceptible/resistant to damage.

Multiply to make your enemy more susceptible or resistant to damage.
Add to give 'bonus' post-mitigation damage.
Add to StatModifier.Base to deal damage which ignores armor, but still respects scaling damage reductions or increases.
Adding to StatModifier.Flat will ignore all reductions or increases to deal unconditional damage. Not recommended due to potential compatibility issues with enemy or player damage reduction effects, use StatModifier.Base instead.
 
AddableFloat FlatBonusDamage = new()
 Use this to add bonus damage to the hit, but not to on-hit effects.

Used by vanilla for most summon tag damage.
 
StatModifier Knockback = new()
 Used by NPC.onFire2 buff (additive) and NPC.knockBackResist (multiplicative)

Recommend using GlobalItem.ModifyWeaponKnockback or Player.GetKnockback instead where possible.

Add for knockback buffs.
Multiply for knockback resistances.
Subtraction not recommended.

Knockback falloff still applies after this, so high knockback has diminishing returns.

 
StatModifier NonCritDamage = new()
 Applied to damage after defense and before FinalDamage when the hit is not a crit.
Effectively a compliment for CritDamage
 
AddableFloat ScalingArmorPenetration = new()
 Used to ignore a fraction of enemy armor. Applies before flat ArmorPenetration.
Recommend only additive buffs, no multiplication or subtraction.

At 1f, the attack will completely ignore all defense.
 
AddableFloat ScalingBonusDamage = new()
 Use this to add bonus
Used by vanilla for melee parry buff (+4f) and some summon tag damage.
 
StatModifier SourceDamage = new()
 Use this to enhance or scale the base damage of the item/projectile/hit. This damage modifier will apply to HitInfo.SourceDamage and be transferred to on-hit effects.

For effects which apply to all damage dealt by the player, or a specific damage type, consider using Player.GetDamage instead.
For effects which apply to all damage dealt by an item, consider using GlobalItem.ModifyWeaponDamage instead.

Used by vanilla for weapons with unique scaling such as jousting lance, ham bat, breaker blade. And for accessories which enhance a projectile (strong bees)
 
MultipliableFloat TargetDamageMultiplier = new()
 Not recommended for modded use due to difficulty balancing around defense, consider multiplying FinalDamage instead.
Used by vanilla for banners, cultist projectile resistances, extra damage for stakes against vampires etc.
 

Properties

DamageClass DamageType = DamageClass.Default [get]
 The DamageType of the hit.
 
int HitDirection = default [get]
 The direction to apply knockback. If 0, no knockback will be applied.
Could potentially be used for directional resistances.
Can be overridden by HitDirectionOverride
 
int? HitDirectionOverride = default [set]
 Overrides the direction to apply knockback.
Will not affect HitDirection, only the final HitInfo.HitDirection
If set by multiple mods, only the last override will apply.
Intended for use by flails, or other projectiles which need to hit the NPC away from the player, even when striking from behind.
 
bool SuperArmor = false [get]
 If true, no amount of damage can get through the defense of this NPC, damage will be reduced to 1.
CritDamage will still apply, but only Additive and Multiplicative. Maximum crit damage will be capped at 4.

 

Events

HitInfoModifier ModifyHitInfo = null
 Use with caution and consider other alternatives first.
Can be used to register a callback to freely modify the HitInfo produced by ToHitInfo before it is returned
If multiple mods register different callbacks which modify the hit info in different ways the results could be a mess!
 

Detailed Description

Represents a damage calculation in the process of being calculated for damage to be applied to an NPC. The final damage calculation will be present in the resulting HitInfo.