TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
Terraria.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 T:Terraria.NPC.HitInfo. More...

+ Collaboration diagram for Terraria.NPC.HitModifiers:

Public Member Functions

delegate void HitInfoModifier (ref HitInfo info)
 
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.
 
void DisableCrit ()
 Disables F:Terraria.NPC.HitModifiers.CritDamage calculations, and clears F:Terraria.NPC.HitInfo.Crit flag from the resulting hit.
 
void SetCrit ()
 Sets the hit to be a crit. Does nothing if M:Terraria.NPC.HitModifiers.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 HideCombatText ()
 Set to hide the damage number popup for this hit.
 
 HitModifiers ()
 
readonly int GetDamage (float baseDamage, bool crit, bool damageVariation=false, float luck=0f)
 
readonly float GetKnockback (float baseKnockback)
 
HitInfo ToHitInfo (float baseDamage, bool crit, float baseKnockback, bool damageVariation=false, float luck=0f)
 

Public Attributes

StatModifier SourceDamage
 Use this to enhance or scale the base damage of the item/projectile/hit. This damage modifier will apply to P:Terraria.NPC.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 M:Terraria.Player.GetDamage(Terraria.ModLoader.DamageClass) instead.
For effects which apply to all damage dealt by an item, consider using M:Terraria.ModLoader.GlobalItem.ModifyWeaponDamage(Terraria.Item,Terraria.Player,Terraria.ModLoader.StatModifier@) 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)
 
AddableFloat FlatBonusDamage
 Use this to add bonus damage to the hit, but not to on-hit effects.

Used by vanilla for most summon tag damage.
 
AddableFloat ScalingBonusDamage
 Use this to add bonus
Used by vanilla for melee parry buff (+4f) and some summon tag damage.
 
MultipliableFloat TargetDamageMultiplier
 Not recommended for modded use due to difficulty balancing around defense, consider multiplying F:Terraria.NPC.HitModifiers.FinalDamage instead.
Used by vanilla for banners, cultist projectile resistances, extra damage for stakes against vampires etc.
 
StatModifier Defense
 The defense of the receiver, including any temporary modifiers (buffs/debuffs).

Increase F:Terraria.ModLoader.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 F:Terraria.ModLoader.StatModifier.Flat to provide flat debuffs like ichor or betsys curse

 
AddableFloat ArmorPenetration
 Flat defense reduction. Applies after F:Terraria.NPC.HitModifiers.ScalingArmorPenetration.
Add to give bonus flat armor penetration.
Do not subtract or multiply, consider altering F:Terraria.NPC.HitModifiers.Defense or F:Terraria.NPC.HitModifiers.ScalingArmorPenetration instead.
Used by the P:Terraria.Projectile.ArmorPenetration, P:Terraria.Item.ArmorPenetration and M:Terraria.Player.GetTotalArmorPenetration(Terraria.ModLoader.DamageClass) stats.
 
AddableFloat ScalingArmorPenetration
 Used to ignore a fraction of enemy armor. Applies before flat F:Terraria.NPC.HitModifiers.ArmorPenetration.
Recommend only additive buffs, no multiplication or subtraction.

At 1f, the attack will completely ignore all defense.
 
MultipliableFloat DefenseEffectiveness
 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 CritDamage
 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 F:Terraria.ModLoader.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 F:Terraria.ModLoader.StatModifier.Base also not recommended.

 
StatModifier NonCritDamage
 Applied to damage after defense and before F:Terraria.NPC.HitModifiers.FinalDamage when the hit is not a crit.
Effectively a compliment for F:Terraria.NPC.HitModifiers.CritDamage
 
StatModifier FinalDamage
 Applied to the final damage result.
Used by F:Terraria.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 F:Terraria.ModLoader.StatModifier.Base to deal damage which ignores armor, but still respects scaling damage reductions or increases.
Adding to F:Terraria.ModLoader.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 F:Terraria.ModLoader.StatModifier.Base instead.
 
MultipliableFloat DamageVariationScale
 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 Knockback
 Used by F:Terraria.NPC.onFire2 buff (additive) and F:Terraria.NPC.knockBackResist (multiplicative)

Recommend using M:Terraria.ModLoader.GlobalItem.ModifyWeaponKnockback(Terraria.Item,Terraria.Player,Terraria.ModLoader.StatModifier@) or M:Terraria.Player.GetKnockback(Terraria.ModLoader.DamageClass) 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.

 

Properties

DamageClass DamageType [get]
 The DamageType of the hit.
 
int HitDirection [get]
 The direction to apply knockback. If 0, no knockback will be applied.
Could potentially be used for directional resistances.
Can be overridden by P:Terraria.NPC.HitModifiers.HitDirectionOverride
 
bool SuperArmor [get]
 If true, no amount of damage can get through the defense of this NPC, damage will be reduced to 1.
F:Terraria.NPC.HitModifiers.CritDamage will still apply, but only Additive and Multiplicative. Maximum crit damage will be capped at 4.

 
int? HitDirectionOverride [set, private get]
 Overrides the direction to apply knockback.
Will not affect P:Terraria.NPC.HitModifiers.HitDirection, only the final F:Terraria.NPC.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.
 

Events

HitInfoModifier ModifyHitInfo
 Use with caution and consider other alternatives first.
Can be used to register a callback to freely modify the T:Terraria.NPC.HitInfo produced by M:Terraria.NPC.HitModifiers.ToHitInfo(System.Single,System.Boolean,System.Single,System.Boolean,System.Single) before it is returned
If multiple mods register different callbacks which modify the hit info in different ways the results could be a mess!
 

Private Attributes

int _damageLimit
 
bool? _critOverride
 
bool _instantKill
 
bool _combatTextHidden
 

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 T:Terraria.NPC.HitInfo.

Definition at line 54 of file NPC.cs.


The documentation for this struct was generated from the following file: