From 03a47b82c764e73243aa809f0d033f4dfbaaa793 Mon Sep 17 00:00:00 2001 From: JavidPack Date: Thu, 25 Jan 2024 12:41:24 -0700 Subject: [PATCH] HitModifiers.DisableKnockback to fix Flat modifier applying to knockBackResist==0 NPC --- patches/tModLoader/Terraria/NPC.TML.Hit.cs | 9 ++++++++- patches/tModLoader/Terraria/NPC.cs.patch | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/patches/tModLoader/Terraria/NPC.TML.Hit.cs b/patches/tModLoader/Terraria/NPC.TML.Hit.cs index c0c2ef45348..187909ed12b 100644 --- a/patches/tModLoader/Terraria/NPC.TML.Hit.cs +++ b/patches/tModLoader/Terraria/NPC.TML.Hit.cs @@ -148,6 +148,13 @@ public struct HitModifiers /// public void SetCrit() => _critOverride ??= true; + private bool _knockbackDisabled = false; + + /// + /// Sets the hit to have no knockback, regardless of values. Set automatically for NPC with values of 0 for consistency. + /// + public void DisableKnockback() => _knockbackDisabled = true; + /// /// Used by buff (additive) and (multiplicative)
///
@@ -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) { diff --git a/patches/tModLoader/Terraria/NPC.cs.patch b/patches/tModLoader/Terraria/NPC.cs.patch index 4870a385cd5..fd5938ea182 100644 --- a/patches/tModLoader/Terraria/NPC.cs.patch +++ b/patches/tModLoader/Terraria/NPC.cs.patch @@ -2115,7 +2115,7 @@ public int checkArmorPenetration(int armorPenetration, float armorPenetrationPercent) { if (ichor) -@@ -64591,26 +_,163 @@ +@@ -64591,26 +_,165 @@ return armorPenetration / 2; } @@ -2193,6 +2193,8 @@ + modifiers.Knockback += 0.1f; + + modifiers.Knockback *= knockBackResist; ++ if (knockBackResist == 0) ++ modifiers.DisableKnockback(); + + NPCLoader.ModifyIncomingHit(this, ref modifiers); + return modifiers;