diff --git a/Buffs/Alcohol/BloodyMaryBuff.cs b/Buffs/Alcohol/BloodyMaryBuff.cs index f987a68ad0..1e3ef36857 100644 --- a/Buffs/Alcohol/BloodyMaryBuff.cs +++ b/Buffs/Alcohol/BloodyMaryBuff.cs @@ -1,4 +1,4 @@ -using Terraria; +using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -19,6 +19,8 @@ namespace CalamityMod.Buffs.Alcohol public override void Update(Player player, ref int buffIndex) { player.Calamity().bloodyMary = true; + if (Main.bloodMoon) + player.GetAttackSpeed() += 0.15f; } } } diff --git a/Buffs/DamageOverTime/BurningBlood.cs b/Buffs/DamageOverTime/BurningBlood.cs index c40357b17b..0065ebdd31 100644 --- a/Buffs/DamageOverTime/BurningBlood.cs +++ b/Buffs/DamageOverTime/BurningBlood.cs @@ -1,4 +1,4 @@ -using Terraria; +using Terraria; using Terraria.ModLoader; namespace CalamityMod.Buffs.DamageOverTime @@ -17,6 +17,7 @@ namespace CalamityMod.Buffs.DamageOverTime public override void Update(Player player, ref int buffIndex) { player.Calamity().bBlood = true; + player.GetAttackSpeed() += 0.025f; } public override void Update(NPC npc, ref int buffIndex) diff --git a/Buffs/Potions/YharimPower.cs b/Buffs/Potions/YharimPower.cs index 5b3eed7c8b..90ebf79c09 100644 --- a/Buffs/Potions/YharimPower.cs +++ b/Buffs/Potions/YharimPower.cs @@ -1,4 +1,4 @@ -using Terraria; +using Terraria; using Terraria.ModLoader; namespace CalamityMod.Buffs.Potions @@ -17,6 +17,7 @@ namespace CalamityMod.Buffs.Potions public override void Update(Player player, ref int buffIndex) { player.Calamity().yPower = true; + player.GetAttackSpeed() += 0.05f; } } } diff --git a/Buffs/StatBuffs/ReaverRage.cs b/Buffs/StatBuffs/ReaverRage.cs index e49e984c1b..608e3c9b7c 100644 --- a/Buffs/StatBuffs/ReaverRage.cs +++ b/Buffs/StatBuffs/ReaverRage.cs @@ -1,4 +1,4 @@ -using Terraria; +using Terraria; using Terraria.ModLoader; namespace CalamityMod.Buffs.StatBuffs @@ -17,6 +17,7 @@ namespace CalamityMod.Buffs.StatBuffs public override void Update(Player player, ref int buffIndex) { player.Calamity().rRage = true; + player.GetAttackSpeed() += 0.05f; } } } diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 6a468ee196..d8cd5fc815 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -437,8 +437,6 @@ namespace CalamityMod.CalPlayer public bool badgeOfBravery = false; public bool warbannerOfTheSun = false; public float warBannerBonus = 0f; - private const float maxWarBannerBonus = 0.2f; - private const float maxWarBannerDistance = 480f; public bool cryogenSoul = false; public bool yInsignia = false; public bool eGauntlet = false; @@ -3400,90 +3398,8 @@ namespace CalamityMod.CalPlayer // Increase wall placement speed to speed up early game a bit and make building more fun Player.wallSpeed += 0.5f; - // TODO -- Melee speed boosts can all go back into their own files. - #region MeleeSpeed + #region Melee Speed for Projectile Melee Weapons float meleeSpeedMult = 0f; - if (bBlood) - { - meleeSpeedMult += 0.025f; - } - if (rRage) - { - meleeSpeedMult += 0.05f; - } - if (yPower) - { - meleeSpeedMult += 0.05f; - } - if (darkSunRing) - { - meleeSpeedMult += 0.12f; - } - if (badgeOfBravery) - { - meleeSpeedMult += 0.15f; - } - if (warbannerOfTheSun) - { - int closestNPC = -1; - for (int i = 0; i < Main.maxNPCs; i++) - { - NPC nPC = Main.npc[i]; - if (nPC.active && !nPC.friendly && (nPC.damage > 0 || nPC.boss) && !nPC.dontTakeDamage) - { - closestNPC = i; - break; - } - } - float distance = -1f; - for (int j = 0; j < Main.maxNPCs; j++) - { - NPC nPC = Main.npc[j]; - if (nPC.active && !nPC.friendly && (nPC.damage > 0 || nPC.boss) && !nPC.dontTakeDamage) - { - float distance2 = Math.Abs(nPC.position.X + (float)(nPC.width / 2) - (Player.position.X + (float)(Player.width / 2))) + Math.Abs(nPC.position.Y + (float)(nPC.height / 2) - (Player.position.Y + (float)(Player.height / 2))); - if (distance == -1f || distance2 < distance) - { - distance = distance2; - closestNPC = j; - } - } - } - - if (closestNPC != -1) - { - NPC actualClosestNPC = Main.npc[closestNPC]; - - float generousHitboxWidth = Math.Max(actualClosestNPC.Hitbox.Width / 2f, actualClosestNPC.Hitbox.Height / 2f); - float hitboxEdgeDist = actualClosestNPC.Distance(Player.Center) - generousHitboxWidth; - - if (hitboxEdgeDist < 0) - hitboxEdgeDist = 0; - - if (hitboxEdgeDist < maxWarBannerDistance) - { - warBannerBonus = MathHelper.Lerp(0f, maxWarBannerBonus, 1f - (hitboxEdgeDist / maxWarBannerDistance)); - - if (warBannerBonus > maxWarBannerBonus) - warBannerBonus = maxWarBannerBonus; - } - - meleeSpeedMult += warBannerBonus; - } - } - if (eGauntlet) - { - meleeSpeedMult += 0.15f; - } - if (yInsignia) - { - meleeSpeedMult += 0.1f; - } - if (bloodyMary) - { - if (Main.bloodMoon) - meleeSpeedMult += 0.15f; - } if (community) { float floatTypeBoost = 0.05f + @@ -3504,22 +3420,14 @@ namespace CalamityMod.CalPlayer (DownedBossSystem.downedYharon ? 0.01f : 0f); // 0.2 meleeSpeedMult += floatTypeBoost * 0.25f; } - if (eArtifact) - { - meleeSpeedMult += 0.1f; - } - if (bloodyWormTooth) - { - meleeSpeedMult += 0.07f; - } + + // Nerfs the effectiveness of Beetle Scale Mail. if (Player.beetleOffense && Player.beetleOrbs > 0) - { meleeSpeedMult -= 0.1f * Player.beetleOrbs; - } + if (CalamityConfig.Instance.Proficiency) - { meleeSpeedMult += GetMeleeSpeedBonus(); - } + if (GemTechSet && GemTechState.IsYellowGemActive) meleeSpeedMult += GemTechHeadgear.MeleeSpeedBoost; diff --git a/Items/Accessories/BadgeofBravery.cs b/Items/Accessories/BadgeofBravery.cs index 1324380d43..3c54867dec 100644 --- a/Items/Accessories/BadgeofBravery.cs +++ b/Items/Accessories/BadgeofBravery.cs @@ -31,6 +31,7 @@ namespace CalamityMod.Items.Accessories { CalamityPlayer modPlayer = player.Calamity(); modPlayer.badgeOfBravery = true; + player.GetAttackSpeed() += 0.15f; } public override void AddRecipes() diff --git a/Items/Accessories/BloodyWormTooth.cs b/Items/Accessories/BloodyWormTooth.cs index f6c90871f3..dd8333536d 100644 --- a/Items/Accessories/BloodyWormTooth.cs +++ b/Items/Accessories/BloodyWormTooth.cs @@ -28,6 +28,7 @@ namespace CalamityMod.Items.Accessories { CalamityPlayer modPlayer = player.Calamity(); modPlayer.bloodyWormTooth = true; + player.GetAttackSpeed() += 0.07f; } } } diff --git a/Items/Accessories/DarkSunRing.cs b/Items/Accessories/DarkSunRing.cs index 17b288481a..15f0a3b04f 100644 --- a/Items/Accessories/DarkSunRing.cs +++ b/Items/Accessories/DarkSunRing.cs @@ -40,6 +40,7 @@ namespace CalamityMod.Items.Accessories { CalamityPlayer modPlayer = player.Calamity(); modPlayer.darkSunRing = true; + player.GetAttackSpeed() += 0.12f; } public override void AddRecipes() diff --git a/Items/Accessories/EldritchSoulArtifact.cs b/Items/Accessories/EldritchSoulArtifact.cs index 78c996b0a2..1b22219fab 100644 --- a/Items/Accessories/EldritchSoulArtifact.cs +++ b/Items/Accessories/EldritchSoulArtifact.cs @@ -34,6 +34,7 @@ namespace CalamityMod.Items.Accessories CalamityPlayer modPlayer = player.Calamity(); modPlayer.eArtifact = true; player.buffImmune[ModContent.BuffType()] = true; + player.GetAttackSpeed() += 0.1f; } public override void AddRecipes() diff --git a/Items/Accessories/ElementalGauntlet.cs b/Items/Accessories/ElementalGauntlet.cs index 6eb5022546..badf0d03e3 100644 --- a/Items/Accessories/ElementalGauntlet.cs +++ b/Items/Accessories/ElementalGauntlet.cs @@ -38,6 +38,7 @@ namespace CalamityMod.Items.Accessories modPlayer.eGauntlet = true; player.autoReuseGlove = true; player.meleeScaleGlove = true; + player.GetAttackSpeed() += 0.15f; } public override void AddRecipes() diff --git a/Items/Accessories/WarbanneroftheSun.cs b/Items/Accessories/WarbanneroftheSun.cs index b35df13bf6..17a164d58d 100644 --- a/Items/Accessories/WarbanneroftheSun.cs +++ b/Items/Accessories/WarbanneroftheSun.cs @@ -1,4 +1,6 @@ -using CalamityMod.CalPlayer; +using System; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; using Terraria.ID; @@ -9,6 +11,9 @@ namespace CalamityMod.Items.Accessories [AutoloadEquip(EquipType.Balloon)] public class WarbanneroftheSun : ModItem { + internal const float MaxBonus = 0.2f; + internal const float MaxDistance = 480f; + public override void SetStaticDefaults() { SacrificeTotal = 1; @@ -31,6 +36,59 @@ namespace CalamityMod.Items.Accessories { CalamityPlayer modPlayer = player.Calamity(); modPlayer.warbannerOfTheSun = true; + + player.GetAttackSpeed() += CalculateMeleeSpeedBonus(player); + } + + private static float CalculateMeleeSpeedBonus(Player player) + { + float bonus = 0f; + + int closestNPC = -1; + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC nPC = Main.npc[i]; + if (nPC.active && !nPC.friendly && (nPC.damage > 0 || nPC.boss) && !nPC.dontTakeDamage) + { + closestNPC = i; + break; + } + } + float distance = -1f; + for (int j = 0; j < Main.maxNPCs; j++) + { + NPC nPC = Main.npc[j]; + if (nPC.active && !nPC.friendly && (nPC.damage > 0 || nPC.boss) && !nPC.dontTakeDamage) + { + float distance2 = Math.Abs(nPC.position.X + (float)(nPC.width / 2) - (player.position.X + (float)(player.width / 2))) + Math.Abs(nPC.position.Y + (float)(nPC.height / 2) - (player.position.Y + (float)(player.height / 2))); + if (distance == -1f || distance2 < distance) + { + distance = distance2; + closestNPC = j; + } + } + } + + if (closestNPC != -1) + { + NPC actualClosestNPC = Main.npc[closestNPC]; + + float generousHitboxWidth = Math.Max(actualClosestNPC.Hitbox.Width / 2f, actualClosestNPC.Hitbox.Height / 2f); + float hitboxEdgeDist = actualClosestNPC.Distance(player.Center) - generousHitboxWidth; + + if (hitboxEdgeDist < 0) + hitboxEdgeDist = 0; + + if (hitboxEdgeDist < MaxDistance) + { + bonus = MathHelper.Lerp(0f, MaxBonus, 1f - (hitboxEdgeDist / MaxDistance)); + + if (bonus > MaxBonus) + bonus = MaxBonus; + } + } + + return bonus; } } } diff --git a/Items/Accessories/YharimsInsignia.cs b/Items/Accessories/YharimsInsignia.cs index 0460dabe1f..51eeaf34f9 100644 --- a/Items/Accessories/YharimsInsignia.cs +++ b/Items/Accessories/YharimsInsignia.cs @@ -34,6 +34,7 @@ namespace CalamityMod.Items.Accessories { CalamityPlayer modPlayer = player.Calamity(); modPlayer.yInsignia = true; + player.GetAttackSpeed() += 0.1f; } public override void AddRecipes()