From 276ef8d90149a3d9016d345cc04811efbcc810e4 Mon Sep 17 00:00:00 2001 From: mountaindrew10 Date: Mon, 8 Jan 2024 07:20:21 -0600 Subject: [PATCH] Worm boss contact damage with velocity update, it's now 0 when velocity is at or below 2 units per frame, also added support for Aquatic Scourge and Astrum Deus. --- NPCs/CalamityAI.cs | 43 ++++++++++++++++++- .../VanillaNPCOverrides/Bosses/DestroyerAI.cs | 19 ++++++-- .../Bosses/EaterOfWorldsAI.cs | 19 ++++++-- 3 files changed, 71 insertions(+), 10 deletions(-) diff --git a/NPCs/CalamityAI.cs b/NPCs/CalamityAI.cs index 8c4eac6828..d802067b9a 100644 --- a/NPCs/CalamityAI.cs +++ b/NPCs/CalamityAI.cs @@ -62,7 +62,25 @@ namespace CalamityMod.NPCs npc.chaseable = true; npc.netUpdate = true; } - npc.damage = npc.defDamage; + + // Calculate contact damage based on velocity + float minimalContactDamageVelocity = 2f; + float minimalDamageVelocity = 8f; + if (npc.velocity.Length() <= minimalContactDamageVelocity) + { + if (head) + npc.damage = (int)(npc.defDamage * 0.5f); + else + npc.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((npc.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + if (head) + npc.damage = (int)MathHelper.Lerp(npc.defDamage * 0.5f, npc.defDamage, velocityDamageScalar); + else + npc.damage = (int)MathHelper.Lerp(0f, npc.defDamage, velocityDamageScalar); + } } else npc.damage = 0; @@ -3529,9 +3547,30 @@ namespace CalamityMod.NPCs // Deus cannot hit for 3 seconds or while invulnerable if (calamityGlobalNPC.newAI[1] < 180f || npc.dontTakeDamage) + { npc.damage = 0; + } else - npc.damage = npc.defDamage; + { + // Calculate contact damage based on velocity + float minimalContactDamageVelocity = 2f; + float minimalDamageVelocity = 8f; + if (npc.velocity.Length() <= minimalContactDamageVelocity) + { + if (head) + npc.damage = (int)(npc.defDamage * 0.5f); + else + npc.damage = 0; + } + else + { + float velocityDamageScalar = MathHelper.Clamp((npc.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + if (head) + npc.damage = (int)MathHelper.Lerp(npc.defDamage * 0.5f, npc.defDamage, velocityDamageScalar); + else + npc.damage = (int)MathHelper.Lerp(0f, npc.defDamage, velocityDamageScalar); + } + } // Get a target if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) diff --git a/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs b/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs index 78d03f474c..256abb0069 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/DestroyerAI.cs @@ -79,12 +79,23 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.realLife = (int)npc.ai[3]; // Calculate contact damage based on velocity + float minimalContactDamageVelocity = 2f; float minimalDamageVelocity = 8f; - float velocityDamageScalar = MathHelper.Clamp(npc.velocity.Length() / minimalDamageVelocity, 0f, 1f); - if (npc.type == NPCID.TheDestroyer) - npc.damage = (int)MathHelper.Lerp(npc.defDamage * 0.5f, npc.defDamage, velocityDamageScalar); + if (npc.velocity.Length() <= minimalContactDamageVelocity) + { + if (npc.type == NPCID.TheDestroyer) + npc.damage = (int)(npc.defDamage * 0.5f); + else + npc.damage = 0; + } else - npc.damage = (int)MathHelper.Lerp(0f, npc.defDamage, velocityDamageScalar); + { + float velocityDamageScalar = MathHelper.Clamp((npc.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + if (npc.type == NPCID.TheDestroyer) + npc.damage = (int)MathHelper.Lerp(npc.defDamage * 0.5f, npc.defDamage, velocityDamageScalar); + else + npc.damage = (int)MathHelper.Lerp(0f, npc.defDamage, velocityDamageScalar); + } // Get a target if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active) diff --git a/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs b/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs index c7c77239c0..4b69cb0067 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/EaterOfWorldsAI.cs @@ -30,12 +30,23 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses npc.reflectsProjectiles = true; // Calculate contact damage based on velocity + float minimalContactDamageVelocity = 2f; float minimalDamageVelocity = 8f; - float velocityDamageScalar = MathHelper.Clamp(npc.velocity.Length() / minimalDamageVelocity, 0f, 1f); - if (npc.type == NPCID.EaterofWorldsHead) - npc.damage = (int)MathHelper.Lerp(npc.defDamage * 0.5f, npc.defDamage, velocityDamageScalar); + if (npc.velocity.Length() <= minimalContactDamageVelocity) + { + if (npc.type == NPCID.EaterofWorldsHead) + npc.damage = (int)(npc.defDamage * 0.5f); + else + npc.damage = 0; + } else - npc.damage = (int)MathHelper.Lerp(0f, npc.defDamage, velocityDamageScalar); + { + float velocityDamageScalar = MathHelper.Clamp((npc.velocity.Length() - minimalContactDamageVelocity) / minimalDamageVelocity, 0f, 1f); + if (npc.type == NPCID.EaterofWorldsHead) + npc.damage = (int)MathHelper.Lerp(npc.defDamage * 0.5f, npc.defDamage, velocityDamageScalar); + else + npc.damage = (int)MathHelper.Lerp(0f, npc.defDamage, velocityDamageScalar); + } // Get a target if (npc.target < 0 || npc.target == Main.maxPlayers || Main.player[npc.target].dead || !Main.player[npc.target].active)