TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ GetDamage()

readonly int Terraria.NPC.HitModifiers.GetDamage ( float baseDamage,
bool crit,
bool damageVariation = false,
float luck = 0f )
inline

Definition at line 286 of file NPC.cs.

287 {
288 crit = _critOverride ?? crit;
289 if (SuperArmor)
290 {
291 float dmg = 1f;
292 if (crit)
293 {
294 dmg *= CritDamage.Additive * CritDamage.Multiplicative;
295 }
296 return Math.Clamp((int)dmg, 1, Math.Min(_damageLimit, 4));
297 }
299 damage += FlatBonusDamage.Value + ScalingBonusDamage.Value * damage;
301 int variationPercent = Utils.Clamp((int)Math.Round((float)Main.DefaultDamageVariationPercent * DamageVariationScale.Value), 0, 100);
303 {
304 damage = Main.DamageVar(damage, variationPercent, luck);
305 }
306 float num = Math.Max(Defense.ApplyTo(0f), 0f);
307 float armorPenetration = num * Math.Clamp(ScalingArmorPenetration.Value, 0f, 1f) + ArmorPenetration.Value;
308 float damageReduction = Math.Max(num - armorPenetration, 0f) * DefenseEffectiveness.Value;
310 damage = (crit ? CritDamage : NonCritDamage).ApplyTo(damage);
311 return Math.Clamp((int)FinalDamage.ApplyTo(damage), 1, _damageLimit);
312 }
int damage
The amount of contact damage this NPC deals. Changing this WILL NOT change the amount of damage done...
Definition NPC.cs:1027
float ApplyTo(float baseValue)
Use this to apply the modifiers of this T:Terraria.ModLoader.StatModifier to the baseValue ....
float Multiplicative
The combination of all multiplicative multipliers. Starts at 1. Applies 'after' all additive bonuses ...
StatModifier SourceDamage
Use this to enhance or scale the base damage of the item/projectile/hit. This damage modifier will ap...
Definition NPC.cs:66
MultipliableFloat DamageVariationScale
Multiply to adjust the damage variation of the hit. Multiply by 0 to disable damage variation....
Definition NPC.cs:156
StatModifier Defense
The defense of the receiver, including any temporary modifiers (buffs/debuffs). Increase F:Terrar...
Definition NPC.cs:95
StatModifier NonCritDamage
Applied to damage after defense and before F:Terraria.NPC.HitModifiers.FinalDamage when the hit is no...
Definition NPC.cs:137
StatModifier CritDamage
Applied to the final damage (after defense) result when the hit is a crit. Defaults to +1f additive (...
Definition NPC.cs:131
AddableFloat ScalingArmorPenetration
Used to ignore a fraction of enemy armor. Applies before flat F:Terraria.NPC.HitModifiers....
Definition NPC.cs:112
MultipliableFloat TargetDamageMultiplier
Not recommended for modded use due to difficulty balancing around defense, consider multiplying F:Ter...
Definition NPC.cs:85
StatModifier FinalDamage
Applied to the final damage result. Used by F:Terraria.NPC.takenDamageMultiplier to make enemies ex...
Definition NPC.cs:148
MultipliableFloat DefenseEffectiveness
The conversion ratio between defense and damage reduction. Defaults to 0.5 for NPCs....
Definition NPC.cs:121
AddableFloat ArmorPenetration
Flat defense reduction. Applies after F:Terraria.NPC.HitModifiers.ScalingArmorPenetration....
Definition NPC.cs:104
bool SuperArmor
If true, no amount of damage can get through the defense of this NPC, damage will be reduced to 1....
Definition NPC.cs:195

References Terraria.NPC.HitModifiers._critOverride, Terraria.NPC.HitModifiers._damageLimit, Terraria.ModLoader.StatModifier.ApplyTo(), Terraria.NPC.HitModifiers.ArmorPenetration, Terraria.NPC.HitModifiers.CritDamage, Terraria.NPC.damage, Terraria.Main.DamageVar(), Terraria.NPC.HitModifiers.DamageVariationScale, Terraria.Main.DefaultDamageVariationPercent, Terraria.NPC.HitModifiers.Defense, Terraria.NPC.HitModifiers.DefenseEffectiveness, Terraria.NPC.HitModifiers.FinalDamage, Terraria.ModLoader.StatModifier.Multiplicative, Terraria.NPC.HitModifiers.NonCritDamage, Terraria.NPC.HitModifiers.ScalingArmorPenetration, Terraria.NPC.HitModifiers.SourceDamage, Terraria.NPC.HitModifiers.SuperArmor, Terraria.NPC.HitModifiers.TargetDamageMultiplier, Terraria.ModLoader.AddableFloat.Value, and Terraria.ModLoader.MultipliableFloat.Value.

Referenced by Terraria.NPC.HitModifiers.ToHitInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: