Skip to content

Commit

Permalink
HitModifiers.DisableKnockback to fix Flat modifier applying to knockB…
Browse files Browse the repository at this point in the history
…ackResist==0 NPC
  • Loading branch information
JavidPack committed Jan 25, 2024
1 parent b989739 commit 03a47b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion patches/tModLoader/Terraria/NPC.TML.Hit.cs
Expand Up @@ -148,6 +148,13 @@ public struct HitModifiers
/// </summary>
public void SetCrit() => _critOverride ??= true;

private bool _knockbackDisabled = false;

/// <summary>
/// Sets the hit to have no knockback, regardless of <see cref="Knockback"/> values. Set automatically for NPC with <see cref="NPC.knockBackResist"/> values of 0 for consistency.
/// </summary>
public void DisableKnockback() => _knockbackDisabled = true;

/// <summary>
/// Used by <see cref="NPC.onFire2"/> buff (additive) and <see cref="NPC.knockBackResist"/> (multiplicative) <br/>
/// <br/>
Expand Down Expand Up @@ -223,7 +230,7 @@ public struct HitModifiers
return Math.Clamp((int)FinalDamage.ApplyTo(damage), 1, _damageLimit);
}

public readonly float GetKnockback(float baseKnockback) => Math.Max(Knockback.ApplyTo(baseKnockback), 0);
public readonly float GetKnockback(float baseKnockback) => _knockbackDisabled ? 0 : Math.Max(Knockback.ApplyTo(baseKnockback), 0);

public HitInfo ToHitInfo(float baseDamage, bool crit, float baseKnockback, bool damageVariation = false, float luck = 0f)
{
Expand Down
4 changes: 3 additions & 1 deletion patches/tModLoader/Terraria/NPC.cs.patch
Expand Up @@ -2115,7 +2115,7 @@
public int checkArmorPenetration(int armorPenetration, float armorPenetrationPercent)
{
if (ichor)
@@ -64591,26 +_,163 @@
@@ -64591,26 +_,165 @@

return armorPenetration / 2;
}
Expand Down Expand Up @@ -2193,6 +2193,8 @@
+ modifiers.Knockback += 0.1f;
+
+ modifiers.Knockback *= knockBackResist;
+ if (knockBackResist == 0)
+ modifiers.DisableKnockback();
+
+ NPCLoader.ModifyIncomingHit(this, ref modifiers);
+ return modifiers;
Expand Down

0 comments on commit 03a47b8

Please sign in to comment.