diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index cd00980806..41c7f3315e 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -12,6 +12,7 @@ using CalamityMod.CalPlayer.Dashes; using CalamityMod.Cooldowns; using CalamityMod.DataStructures; using CalamityMod.Dusts; +using CalamityMod.Enums; using CalamityMod.Events; using CalamityMod.FluidSimulation; using CalamityMod.Items; @@ -2894,10 +2895,7 @@ namespace CalamityMod.CalPlayer int damage = Player.ApplyArmorAccDamageBonusesTo(proj.damage / 10); Projectile.NewProjectile(source, new Vector2((int)(Player.Center.X + (Math.Sin(projIndex * start) * 300)), (int)(Player.Center.Y + (Math.Cos(projIndex * start) * 300))), Vector2.Zero, ProjectileType(), damage, proj.knockBack / 10f, Player.whoAmI, Main.rand.Next(180), projIndex * start); - Player.statLife += 2; - Player.HealEffect(2); - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(2); } } if (CalamityKeybinds.SandCloakHotkey.JustPressed && sandCloak && Main.myPlayer == Player.whoAmI && !Player.HasCooldown(Cooldowns.SandCloak.ID)) diff --git a/CalPlayer/CalamityPlayerHitHurt.cs b/CalPlayer/CalamityPlayerHitHurt.cs index 385cbe0c6c..7d4745af4e 100644 --- a/CalPlayer/CalamityPlayerHitHurt.cs +++ b/CalPlayer/CalamityPlayerHitHurt.cs @@ -278,12 +278,7 @@ namespace CalamityMod.CalPlayer chaliceBleedoutBuffer = 0D; chaliceDamagePointPartialProgress = 0D; } - - Player.statLife += 100; - Player.HealEffect(100); - - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(100); Player.AddCooldown(Cooldowns.NebulousCore.ID, CalamityUtils.SecondsToFrames(90)); return false; @@ -307,11 +302,7 @@ namespace CalamityMod.CalPlayer if (silvaWings) { - Player.statLife += Player.statLifeMax2 / 3; - Player.HealEffect(Player.statLifeMax2 / 3); - - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(Player.statLifeMax2 / 3); } } diff --git a/CalPlayer/CalamityPlayerLifeRegen.cs b/CalPlayer/CalamityPlayerLifeRegen.cs index d164fa66b7..395f9c1d71 100644 --- a/CalPlayer/CalamityPlayerLifeRegen.cs +++ b/CalPlayer/CalamityPlayerLifeRegen.cs @@ -4,6 +4,7 @@ using CalamityMod.Buffs.Alcohol; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.Placeables; using CalamityMod.Cooldowns; +using CalamityMod.Enums; using CalamityMod.Items.Accessories; using CalamityMod.NPCs; using CalamityMod.Projectiles.Ranged; @@ -740,9 +741,7 @@ namespace CalamityMod.CalPlayer if (pinkCandleHealFraction >= 1D) { pinkCandleHealFraction = 0D; - - if (Player.statLife < Player.statLifeMax2) - Player.statLife++; + Player.HealPlayer(1, HealTextType.None); } } else diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index cf15b002b6..f323b2f6f3 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -12,6 +12,7 @@ using CalamityMod.Cooldowns; using CalamityMod.CustomRecipes; using CalamityMod.DataStructures; using CalamityMod.Dusts; +using CalamityMod.Enums; using CalamityMod.Events; using CalamityMod.ExtraTextures; using CalamityMod.Items; @@ -541,9 +542,7 @@ namespace CalamityMod.CalPlayer // 26AUG2024: Ozzatron: Cut Draedon's Heart healing in half by making it heal every other frame. if (draedonsHeart && Player.miscCounter % 2 == 1) { - Player.statLife += DraedonsHeart.NanomachinesHealPerFrame; - if (Player.statLife >= Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(DraedonsHeart.NanomachinesHealPerFrame, HealTextType.None); // Old Draedon's Heart dust effect from its standing still regen. Works just fine. int dustID = DustID.TerraBlade; @@ -1280,10 +1279,7 @@ namespace CalamityMod.CalPlayer if (Player.whoAmI == Main.myPlayer) { - Player.statLife += 15; - Player.HealEffect(15); - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(15); if (profanedCrystal) { @@ -1622,10 +1618,7 @@ namespace CalamityMod.CalPlayer --silverMedkitTimer; if (silverMedkitTimer == 0) { - Player.HealEffect(SilverArmorSetChange.SetBonusHealAmount, true); - Player.statLife += SilverArmorSetChange.SetBonusHealAmount; - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(SilverArmorSetChange.SetBonusHealAmount); SilverArmorSetChange.OnHealEffects(Player); } @@ -2847,10 +2840,7 @@ namespace CalamityMod.CalPlayer // Bloodflare Core's heal over time if (bloodflareCore && bloodflareCoreRemainingHealOverTime > 0 && Player.miscCounter % BloodflareCore.HealFrameCooldown == 0) { - Player.statLife += 1; - Player.HealEffect(1, false); - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(1, HealTextType.Local); // Produce an implosion of blood themed dust so it's obvious an effect is occurring for (int i = 0; i < 3; ++i) diff --git a/CalPlayer/CalamityPlayerOnHit.cs b/CalPlayer/CalamityPlayerOnHit.cs index c48bcca191..1517171627 100644 --- a/CalPlayer/CalamityPlayerOnHit.cs +++ b/CalPlayer/CalamityPlayerOnHit.cs @@ -7,6 +7,8 @@ using CalamityMod.Buffs.StatBuffs; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Cooldowns; using CalamityMod.Dusts; +using CalamityMod.Enums; +using CalamityMod.EntitySources; using CalamityMod.Items.Accessories; using CalamityMod.Items.Armor.Reaver; using CalamityMod.Items.Potions.Alcohol; @@ -118,10 +120,7 @@ namespace CalamityMod.CalPlayer int heal = 2; Player.lifeSteal -= heal; - Player.statLife += heal; - Player.HealEffect(heal); - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(heal); break; @@ -259,10 +258,7 @@ namespace CalamityMod.CalPlayer int heal = 2; Main.player[Main.myPlayer].lifeSteal -= heal; - Player.statLife += heal; - Player.HealEffect(heal); - if (Player.statLife > Player.statLifeMax2) - Player.statLife = Player.statLifeMax2; + Player.HealPlayer(heal); break; diff --git a/Enums/HealTextType.cs b/Enums/HealTextType.cs new file mode 100644 index 0000000000..fe69a25da0 --- /dev/null +++ b/Enums/HealTextType.cs @@ -0,0 +1,9 @@ +namespace CalamityMod.Enums +{ + public enum HealTextType + { + None, + Local, + Broadcast + } +} diff --git a/Items/Weapons/Melee/LifehuntScythe.cs b/Items/Weapons/Melee/LifehuntScythe.cs index 2141d6263b..54c3aaf1e1 100644 --- a/Items/Weapons/Melee/LifehuntScythe.cs +++ b/Items/Weapons/Melee/LifehuntScythe.cs @@ -1,4 +1,5 @@ -using CalamityMod.Items.Materials; +using CalamityMod.Enums; +using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Melee; using CalamityMod.Rarities; using Microsoft.Xna.Framework; @@ -44,10 +45,7 @@ namespace CalamityMod.Items.Weapons.Melee int heal = 5; player.lifeSteal -= heal; - player.statLife += heal; - player.HealEffect(heal); - if (player.statLife > player.statLifeMax2) - player.statLife = player.statLifeMax2; + player.HealPlayer(heal); } public override void OnHitPvp(Player player, Player target, Player.HurtInfo hurtInfo) @@ -57,10 +55,7 @@ namespace CalamityMod.Items.Weapons.Melee int heal = 5; player.lifeSteal -= heal; - player.statLife += heal; - player.HealEffect(heal); - if (player.statLife > player.statLifeMax2) - player.statLife = player.statLifeMax2; + player.HealPlayer(heal); } public override void AddRecipes() diff --git a/Projectiles/Boss/BrimstoneMonster.cs b/Projectiles/Boss/BrimstoneMonster.cs index 7ea0d0e4e0..661c9fd3d7 100644 --- a/Projectiles/Boss/BrimstoneMonster.cs +++ b/Projectiles/Boss/BrimstoneMonster.cs @@ -272,14 +272,20 @@ namespace CalamityMod.Projectiles.Boss if (cannotBeHurt) return true; - // Applies Vulnerability Hex and/or the effects of Supreme Cirrus' HAGE faces. - OnHitPlayer_Internal(player); - // Compute distance for direct health reduction from overlap. float distSQ = Projectile.DistanceSQ(player.Center); float radiusSQ = CircularHitboxRadius * CircularHitboxRadius * Projectile.scale * Projectile.scale; float radiusRatio = distSQ / radiusSQ; + // If this code happens to run when the player is not colliding, don't apply any effects. + // The performance impact of verifying this is marginal, especially since there's only ever one of this projectile. + // == false is necessary since the method is a nullable. + if (Colliding(Projectile.Hitbox, player.Hitbox) == false) + return false; + + // Applies Vulnerability Hex and/or the effects of Supreme Cirrus' HAGE faces. + OnHitPlayer_Internal(player); + // Check the player's speed. If they are moving fast enough, damage them more severely; this prevents trying to rush straight through the vortex. float playerSpeed = player.velocity.LengthSquared(); float speedRatio = playerSpeed / (SpeedToForceMaxDamage * SpeedToForceMaxDamage); diff --git a/Projectiles/Boss/HolyLight.cs b/Projectiles/Boss/HolyLight.cs index af177af1c4..1a0d114a9f 100644 --- a/Projectiles/Boss/HolyLight.cs +++ b/Projectiles/Boss/HolyLight.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Enums; using CalamityMod.NPCs.Providence; using CalamityMod.Particles; using Microsoft.Xna.Framework; @@ -63,12 +64,7 @@ namespace CalamityMod.Projectiles.Boss if (!player.immune && playerDist < 50f && !player.dead && Projectile.position.X < player.position.X + player.width && Projectile.position.X + Projectile.width > player.position.X && Projectile.position.Y < player.position.Y + player.height && Projectile.position.Y + Projectile.height > player.position.Y) { int healAmt = (int)Projectile.ai[1]; - player.HealEffect(healAmt, false); - player.statLife += healAmt; - if (player.statLife > player.statLifeMax2) - { - player.statLife = player.statLifeMax2; - } + player.HealPlayer(healAmt, HealTextType.Local); NetMessage.SendData(MessageID.SpiritHeal, -1, -1, null, index, healAmt); Projectile.Kill(); } diff --git a/Projectiles/Healing/GladiatorHealOrb.cs b/Projectiles/Healing/GladiatorHealOrb.cs index 1fc627f2a4..1b8bd6b2db 100644 --- a/Projectiles/Healing/GladiatorHealOrb.cs +++ b/Projectiles/Healing/GladiatorHealOrb.cs @@ -1,5 +1,6 @@ using System; using CalamityMod.Balancing; +using CalamityMod.Enums; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -76,10 +77,7 @@ namespace CalamityMod.Projectiles.Healing if (playerDist < 50f && Projectile.position.X < player.position.X + player.width && Projectile.position.X + Projectile.width > player.position.X && Projectile.position.Y < player.position.Y + player.height && Projectile.position.Y + Projectile.height > player.position.Y) { int heal = 10; - player.HealEffect(heal, false); - player.statLife += heal; - if (player.statLife > player.statLifeMax2) - player.statLife = player.statLifeMax2; + player.HealPlayer(heal, HealTextType.Local); SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Custom/OrbHeal", 5) { Volume = 0.15f }, Projectile.Center); diff --git a/Projectiles/Melee/RespiteblockHoldout.cs b/Projectiles/Melee/RespiteblockHoldout.cs index c166e097d7..4cd26ca080 100644 --- a/Projectiles/Melee/RespiteblockHoldout.cs +++ b/Projectiles/Melee/RespiteblockHoldout.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Enums; using CalamityMod.Particles; using CalamityMod.Buffs.DamageOverTime; using Microsoft.Xna.Framework; @@ -116,10 +117,7 @@ namespace CalamityMod.Projectiles.Melee int heal = Main.rand.NextBool(4) ? 2 : 1; player.lifeSteal -= heal; - player.statLife += heal; - player.HealEffect(heal); - if (player.statLife > player.statLifeMax2) - player.statLife = player.statLifeMax2; + player.HealPlayer(heal); } public void PlayChainsawSounds() diff --git a/Projectiles/Typeless/BlazingStarHeal.cs b/Projectiles/Typeless/BlazingStarHeal.cs index 4509aaf731..3fc91c4f9f 100644 --- a/Projectiles/Typeless/BlazingStarHeal.cs +++ b/Projectiles/Typeless/BlazingStarHeal.cs @@ -1,4 +1,5 @@ using System; +using CalamityMod.Enums; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -46,10 +47,7 @@ namespace CalamityMod.Projectiles.Typeless if (!player.immune && playerDist < 50f && !player.dead && Projectile.position.X < player.position.X + player.width && Projectile.position.X + Projectile.width > player.position.X && Projectile.position.Y < player.position.Y + player.height && Projectile.position.Y + Projectile.height > player.position.Y) { int healAmt = Utils.Clamp((200 - Projectile.timeLeft) / 10, 1, 10); //min heal is 5, max heal is 10, achievable after 2 seconds - player.HealEffect(healAmt, false); - player.statLife += healAmt; - if (player.statLife > player.statLifeMax2) - player.statLife = player.statLifeMax2; + player.HealPlayer(healAmt, HealTextType.Local); NetMessage.SendData(MessageID.SpiritHeal, -1, -1, null, index, healAmt); diff --git a/Projectiles/Typeless/RelicOfConvergenceCrystal.cs b/Projectiles/Typeless/RelicOfConvergenceCrystal.cs index 8887c58242..8cf5bdf606 100644 --- a/Projectiles/Typeless/RelicOfConvergenceCrystal.cs +++ b/Projectiles/Typeless/RelicOfConvergenceCrystal.cs @@ -1,4 +1,5 @@ using CalamityMod.Dusts; +using CalamityMod.Enums; using CalamityMod.Items; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -70,12 +71,7 @@ namespace CalamityMod.Projectiles.Typeless dust.fadeIn = Main.rand.NextFloat(3f, 4f); dust.noGravity = true; } - player.HealEffect(70, false); - player.statLife += 70; - if (player.statLife > player.statLifeMax2) - { - player.statLife = player.statLifeMax2; - } + player.HealPlayer(70, HealTextType.Local); SoundEngine.PlaySound(SoundID.DD2_DarkMageHealImpact, Projectile.Center); } } diff --git a/Utilities/GenericAIUtils.cs b/Utilities/GenericAIUtils.cs index 2303612ba1..05dd20001c 100644 --- a/Utilities/GenericAIUtils.cs +++ b/Utilities/GenericAIUtils.cs @@ -1,5 +1,6 @@ using System; using CalamityMod.CalPlayer; +using CalamityMod.Enums; using CalamityMod.Projectiles.Summon; using Microsoft.Xna.Framework; using Terraria; @@ -363,12 +364,7 @@ namespace CalamityMod if (projectile.owner == Main.myPlayer && !Main.player[Main.myPlayer].moonLeech) { int healAmt = healing; - player.HealEffect(healAmt, false); - player.statLife += healAmt; - if (player.statLife > player.statLifeMax2) - { - player.statLife = player.statLifeMax2; - } + player.HealPlayer(healAmt, HealTextType.Local); NetMessage.SendData(MessageID.SpiritHeal, -1, -1, null, target, healAmt, 0f, 0f, 0, 0, 0); } projectile.Kill(); diff --git a/Utilities/PlayerUtils.cs b/Utilities/PlayerUtils.cs index 08128135fb..e83ae6bd05 100644 --- a/Utilities/PlayerUtils.cs +++ b/Utilities/PlayerUtils.cs @@ -13,6 +13,7 @@ using Terraria; using Terraria.GameContent.Events; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.Enums; using static Terraria.Player; namespace CalamityMod @@ -930,6 +931,22 @@ namespace CalamityMod } + /// + /// A short method that heals the player. + /// All direct heals in Calamity should use this. + /// + /// The player being healed. + /// The amount of life being healed. + /// Whether the heal CombatText should be displayed, and whether it should be synced. Displays and syncs by default. + public static void HealPlayer(this Player player, int amount, HealTextType healTextType = HealTextType.Broadcast) + { + player.statLife += amount; + if (player.statLife > player.statLifeMax2) + player.statLife = player.statLifeMax2; + if (healTextType != HealTextType.None) + player.HealEffect(amount, healTextType == HealTextType.Broadcast); + } + /// /// Makes the given player send the given packet to all appropriate receivers.
/// If server is false, the packet is sent only to the multiplayer host.