From 6aee63d78edbfef10d269073c3d43ca2e9767e89 Mon Sep 17 00:00:00 2001 From: termigator1359 <45545085+termigator1359@users.noreply.github.com> Date: Thu, 16 Apr 2020 20:23:01 -0400 Subject: [PATCH] 246debuff and seconds to frames utilities --- CalPlayer/CalamityPlayer.cs | 401 ++++-------------------------------- Utilities/CalamityUtils.cs | 34 +++ 2 files changed, 75 insertions(+), 360 deletions(-) diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index f65a591e2d..9925c53b64 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -3568,9 +3568,9 @@ namespace CalamityMod.CalPlayer if (player.FindBuffIndex(ModContent.BuffType()) > -1) { player.ClearBuff(ModContent.BuffType()); - player.AddBuff(ModContent.BuffType(), 3600); //1 minute + player.AddBuff(ModContent.BuffType(), CalamityUtils.SecondsToFrames(60f)); } - player.AddBuff(ModContent.BuffType(), 2700); + player.AddBuff(ModContent.BuffType(), CalamityUtils.SecondsToFrames(45f)); return false; } if (silvaSet && silvaCountdown > 0) @@ -3594,7 +3594,7 @@ namespace CalamityMod.CalPlayer if (player.FindBuffIndex(ModContent.BuffType()) > -1) { player.ClearBuff(ModContent.BuffType()); - player.AddBuff(ModContent.BuffType(), 3600); //1 minute + player.AddBuff(ModContent.BuffType(), CalamityUtils.SecondsToFrames(60f)); } } else if (silvaWings) @@ -3616,8 +3616,8 @@ namespace CalamityMod.CalPlayer } if (permafrostsConcoction && player.FindBuffIndex(ModContent.BuffType()) == -1) { - player.AddBuff(ModContent.BuffType(), 10800); - player.AddBuff(ModContent.BuffType(), 180); + player.AddBuff(ModContent.BuffType(), CalamityUtils.SecondsToFrames(180f)); + player.AddBuff(ModContent.BuffType(), CalamityUtils.SecondsToFrames(3f)); player.statLife = player.statLifeMax2 * 3 / 10; Main.PlaySound(SoundID.Item92, player.position); for (int i = 0; i < 60; i++) @@ -3971,7 +3971,7 @@ namespace CalamityMod.CalPlayer num340 *= 1.5f; num342 *= (float)player.direction; num341 *= player.gravDir; - Projectile.NewProjectile((float)(hitbox.X + hitbox.Width / 2) + num342, (float)(hitbox.Y + hitbox.Height / 2) + num341, (float)player.direction * num340, num339 * player.gravDir, ProjectileID.Mushroom, (int)((float)item.damage * 0.25f * player.meleeDamage), 0f, player.whoAmI, 0f, 0f); + Projectile.NewProjectile((float)(hitbox.X + hitbox.Width / 2) + num342, (float)(hitbox.Y + hitbox.Height / 2) + num341, (float)player.direction * num340, num339 * player.gravDir, ProjectileID.Mushroom, (int)(item.damage * 0.25f * player.MeleeDamage()), 0f, player.whoAmI, 0f, 0f); } } if (aWeapon) @@ -4073,126 +4073,38 @@ namespace CalamityMod.CalPlayer } if (cryogenSoul || frostFlare) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.Frostburn, 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.Frostburn, 240, false); - } - else - { - target.AddBuff(BuffID.Frostburn, 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, BuffID.Frostburn); } if (yInsignia) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (ataxiaFire) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.OnFire, 720, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.OnFire, 480, false); - } - else - { - target.AddBuff(BuffID.OnFire, 240, false); - } - } - } - if (aWeapon) - { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); + CalamityUtils.Inflict246DebuffsNPC(target, BuffID.OnFire, 4f); } + if (aWeapon) + { + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); + } } if (abyssalAmulet) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (dsSetBonus) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (alchFlask) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (armorCrumbling || armorShattering) { if (item.melee || item.Calamity().rogue) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } } if (item.Calamity().rogue) @@ -4303,33 +4215,11 @@ namespace CalamityMod.CalPlayer if (abyssalAmulet) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (dsSetBonus) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (uberBees && (proj.type == 566 || proj.type == 181 || proj.type == 189)) { @@ -4337,18 +4227,7 @@ namespace CalamityMod.CalPlayer } else if (alchFlask) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (proj.melee) { @@ -4370,81 +4249,26 @@ namespace CalamityMod.CalPlayer } if (aWeapon) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (cryogenSoul || frostFlare) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.Frostburn, 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.Frostburn, 240, false); - } - else - { - target.AddBuff(BuffID.Frostburn, 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, BuffID.Frostburn); } if (yInsignia) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } if (ataxiaFire) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.OnFire, 720, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.OnFire, 480, false); - } - else - { - target.AddBuff(BuffID.OnFire, 240, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, BuffID.OnFire, 4f); } } if (armorCrumbling || armorShattering) { if (proj.melee || proj.Calamity().rogue) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsNPC(target, ModContent.BuffType()); } } if (perforatorLore) @@ -4577,95 +4401,29 @@ namespace CalamityMod.CalPlayer } if (aWeapon) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } - } - if (abyssalAmulet) - { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } if (cryogenSoul || frostFlare) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.Frostburn, 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.Frostburn, 240, false); - } - else - { - target.AddBuff(BuffID.Frostburn, 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, BuffID.Frostburn); } if (yInsignia) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } if (ataxiaFire) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.OnFire, 720, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.OnFire, 480, false); - } - else - { - target.AddBuff(BuffID.OnFire, 240, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, BuffID.OnFire, 4f); } } if (alchFlask) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } + if (abyssalAmulet) + { + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); + } if (item.Calamity().rogue) { if (player.meleeEnchant > 0) @@ -4771,18 +4529,7 @@ namespace CalamityMod.CalPlayer if (abyssalAmulet) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } if (uberBees && (proj.type == 566 || proj.type == 181 || proj.type == 189)) { @@ -4790,18 +4537,7 @@ namespace CalamityMod.CalPlayer } else if (alchFlask) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } if (proj.melee) { @@ -4823,81 +4559,26 @@ namespace CalamityMod.CalPlayer } if (aWeapon) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } if (cryogenSoul || frostFlare) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.Frostburn, 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.Frostburn, 240, false); - } - else - { - target.AddBuff(BuffID.Frostburn, 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, BuffID.Frostburn); } if (yInsignia) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } if (ataxiaFire) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(BuffID.OnFire, 720, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(BuffID.OnFire, 480, false); - } - else - { - target.AddBuff(BuffID.OnFire, 240, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, BuffID.OnFire, 4f); } } if (armorCrumbling || armorShattering) { if (proj.melee || proj.Calamity().rogue) { - if (Main.rand.NextBool(4)) - { - target.AddBuff(ModContent.BuffType(), 360, false); - } - else if (Main.rand.NextBool(2)) - { - target.AddBuff(ModContent.BuffType(), 240, false); - } - else - { - target.AddBuff(ModContent.BuffType(), 120, false); - } + CalamityUtils.Inflict246DebuffsPvp(target, ModContent.BuffType()); } } if (perforatorLore) diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 3295751ea9..b0927f3782 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -2514,6 +2514,40 @@ namespace CalamityMod if (condition) list.Add(type); } + + public static void Inflict246DebuffsNPC(NPC target, int buff, float timeBase = 2f) + { + if (Main.rand.NextBool(4)) + { + target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false); + } + else if (Main.rand.NextBool(2)) + { + target.AddBuff(buff, SecondsToFrames(timeBase * 2f), false); + } + else + { + target.AddBuff(buff, SecondsToFrames(timeBase), false); + } + } + + public static void Inflict246DebuffsPvp(Player target, int buff, float timeBase = 2f) + { + if (Main.rand.NextBool(4)) + { + target.AddBuff(buff, SecondsToFrames(timeBase * 3f), false); + } + else if (Main.rand.NextBool(2)) + { + target.AddBuff(buff, SecondsToFrames(timeBase * 2f), false); + } + else + { + target.AddBuff(buff, SecondsToFrames(timeBase), false); + } + } + + public static int SecondsToFrames(float seconds) => (int)(seconds * 60); #endregion } }