From 67ce410d35baee25dbaf5f12fff60fcd30489074 Mon Sep 17 00:00:00 2001 From: termigator1359 <45545085+termigator1359@users.noreply.github.com> Date: Sat, 18 Jul 2020 14:06:56 -0400 Subject: [PATCH] refactored nebula star & deadly microbe a bit fixed microbe having i frame interferance --- Projectiles/Typeless/NebulaStar.cs | 214 +++------------ Projectiles/Typeless/ReaverSpore.cs | 19 +- .../Typeless/TheDeadlyMicrobeProjectile.cs | 245 ++++-------------- Utilities/CalamityUtils.cs | 150 +++++++++++ 4 files changed, 246 insertions(+), 382 deletions(-) diff --git a/Projectiles/Typeless/NebulaStar.cs b/Projectiles/Typeless/NebulaStar.cs index a2d726d91e..a21ec81a21 100644 --- a/Projectiles/Typeless/NebulaStar.cs +++ b/Projectiles/Typeless/NebulaStar.cs @@ -5,188 +5,42 @@ using Terraria; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Typeless { - public class NebulaStar : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Star"); - } + public class NebulaStar : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Star"); + } - public override void SetDefaults() - { - projectile.width = 34; - projectile.height = 34; - projectile.friendly = true; - projectile.alpha = 255; - projectile.penetrate = 1; - projectile.tileCollide = false; - projectile.ignoreWater = true; - projectile.timeLeft = 3600; - } + public override void SetDefaults() + { + projectile.width = projectile.height = 34; + projectile.friendly = true; + projectile.alpha = 255; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.timeLeft = 3600; + } - public override void AI() - { - float num944 = 1f - (float)projectile.alpha / 255f; - num944 *= projectile.scale; - Lighting.AddLight(projectile.Center, 0.25f * num944, 0.025f * num944, 0.275f * num944); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] >= 90f) - { - projectile.localAI[0] *= -1f; - } - if (projectile.localAI[0] >= 0f) - { - projectile.scale += 0.003f; - } - else - { - projectile.scale -= 0.003f; - } - projectile.rotation += 0.0025f * projectile.scale; - float num945 = 1f; - float num946 = 1f; - if (projectile.identity % 6 == 0) - { - num946 *= -1f; - } - if (projectile.identity % 6 == 1) - { - num945 *= -1f; - } - if (projectile.identity % 6 == 2) - { - num946 *= -1f; - num945 *= -1f; - } - if (projectile.identity % 6 == 3) - { - num946 = 0f; - } - if (projectile.identity % 6 == 4) - { - num945 = 0f; - } - projectile.localAI[1] += 1f; - if (projectile.localAI[1] > 60f) - { - projectile.localAI[1] = -180f; - } - if (projectile.localAI[1] >= -60f) - { - projectile.velocity.X = projectile.velocity.X + 0.002f * num946; - projectile.velocity.Y = projectile.velocity.Y + 0.002f * num945; - } - else - { - projectile.velocity.X = projectile.velocity.X - 0.002f * num946; - projectile.velocity.Y = projectile.velocity.Y - 0.002f * num945; - } - projectile.ai[0] += 1f; - if (projectile.ai[0] > 5400f) - { - projectile.damage = 0; - projectile.ai[1] = 1f; - if (projectile.alpha < 255) - { - projectile.alpha += 5; - if (projectile.alpha > 255) - { - projectile.alpha = 255; - } - } - else if (projectile.owner == Main.myPlayer) - { - projectile.Kill(); - } - } - else - { - float num947 = (projectile.Center - Main.player[projectile.owner].Center).Length() / 100f; - if (num947 > 4f) - { - num947 *= 1.1f; - } - if (num947 > 5f) - { - num947 *= 1.2f; - } - if (num947 > 6f) - { - num947 *= 1.3f; - } - if (num947 > 7f) - { - num947 *= 1.4f; - } - if (num947 > 8f) - { - num947 *= 1.5f; - } - if (num947 > 9f) - { - num947 *= 1.6f; - } - if (num947 > 10f) - { - num947 *= 1.7f; - } - projectile.ai[0] += num947; - if (projectile.alpha > 50) - { - projectile.alpha -= 10; - if (projectile.alpha < 50) - { - projectile.alpha = 50; - } - } - } - bool flag49 = false; - Vector2 center12 = new Vector2(0f, 0f); - float num948 = 600f; - for (int num949 = 0; num949 < Main.maxNPCs; num949++) - { - if (Main.npc[num949].CanBeChasedBy(projectile, false)) - { - float num950 = Main.npc[num949].position.X + (float)(Main.npc[num949].width / 2); - float num951 = Main.npc[num949].position.Y + (float)(Main.npc[num949].height / 2); - float num952 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num950) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num951); - if (num952 < num948) - { - num948 = num952; - center12 = Main.npc[num949].Center; - flag49 = true; - } - } - } - if (flag49) - { - Vector2 vector101 = center12 - projectile.Center; - vector101.Normalize(); - vector101 *= 0.75f; - projectile.velocity = (projectile.velocity * 10f + vector101) / 11f; - return; - } - if ((double)projectile.velocity.Length() > 0.2) - { - projectile.velocity *= 0.98f; - } - } + public override void AI() + { + projectile.SporeSacAI(); + } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - if (projectile.owner == Main.myPlayer && projectile.ai[1] == 0f) - { - Vector2 value10 = new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101)); - value10.Normalize(); - value10 *= 0.3f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, value10.X, value10.Y, ModContent.ProjectileType(), projectile.damage, 0f, projectile.owner, 0f, 0f); - } - } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (projectile.owner == Main.myPlayer && projectile.ai[1] == 0f) + { + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 1f, 1f, 0.3f); + Projectile.NewProjectile(projectile.Center, velocity, ModContent.ProjectileType(), projectile.damage, 0f, projectile.owner, 0f, 0f); + } + } - public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) - { - Rectangle frame = new Rectangle(0, 0, Main.projectileTexture[projectile.type].Width, Main.projectileTexture[projectile.type].Height); - spriteBatch.Draw(ModContent.GetTexture("CalamityMod/Projectiles/Typeless/NebulaStarGlow"), projectile.Center - Main.screenPosition, frame, Color.White, projectile.rotation, projectile.Size / 2, 1f, SpriteEffects.None, 0f); - } - } + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + Rectangle frame = new Rectangle(0, 0, Main.projectileTexture[projectile.type].Width, Main.projectileTexture[projectile.type].Height); + spriteBatch.Draw(ModContent.GetTexture("CalamityMod/Projectiles/Typeless/NebulaStarGlow"), projectile.Center - Main.screenPosition, frame, Color.White, projectile.rotation, projectile.Size / 2, 1f, SpriteEffects.None, 0f); + } + } } diff --git a/Projectiles/Typeless/ReaverSpore.cs b/Projectiles/Typeless/ReaverSpore.cs index 199e598ce9..fb2d03a80c 100644 --- a/Projectiles/Typeless/ReaverSpore.cs +++ b/Projectiles/Typeless/ReaverSpore.cs @@ -17,23 +17,28 @@ namespace CalamityMod.Projectiles.Typeless public override void SetDefaults() { projectile.width = projectile.height = 16; - projectile.aiStyle = 105; projectile.friendly = true; projectile.penetrate = 1; projectile.alpha = 255; projectile.timeLeft = 3600; projectile.tileCollide = false; projectile.ignoreWater = true; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 60; + } + + public override void AI() + { + projectile.SporeSacAI(); } public override void Kill(int timeLeft) { - Vector2 velocity = CalamityUtils.RandomVelocity(100f, 1f, 1f, 0.3f); - int gas = Projectile.NewProjectile(projectile.Center, velocity, ProjectileID.SporeGas + Main.rand.Next(3), projectile.damage, 0f, projectile.owner); - Main.projectile[gas].usesLocalNPCImmunity = true; - Main.projectile[gas].localNPCHitCooldown = 30; + if (projectile.owner == Main.myPlayer) + { + Vector2 velocity = CalamityUtils.RandomVelocity(100f, 1f, 1f, 0.3f); + int gas = Projectile.NewProjectile(projectile.Center, velocity, ProjectileID.SporeGas + Main.rand.Next(3), projectile.damage, 0f, projectile.owner); + Main.projectile[gas].usesLocalNPCImmunity = true; + Main.projectile[gas].localNPCHitCooldown = 30; + } } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Typeless/TheDeadlyMicrobeProjectile.cs b/Projectiles/Typeless/TheDeadlyMicrobeProjectile.cs index 2882484679..f4815e83ce 100644 --- a/Projectiles/Typeless/TheDeadlyMicrobeProjectile.cs +++ b/Projectiles/Typeless/TheDeadlyMicrobeProjectile.cs @@ -6,201 +6,56 @@ using Terraria.ModLoader; namespace CalamityMod.Projectiles.Typeless { - public class TheDeadlyMicrobeProjectile : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Star"); - } - - public override void SetDefaults() - { - projectile.width = 14; - projectile.height = 14; - projectile.friendly = true; - projectile.alpha = 255; - projectile.penetrate = 1; - projectile.tileCollide = false; - projectile.ignoreWater = true; - projectile.timeLeft = 3600; - } - - public override void AI() - { - float num944 = 1f - (float)projectile.alpha / 255f; - num944 *= projectile.scale; - Lighting.AddLight(projectile.Center, 0.25f * num944, 0.025f * num944, 0.275f * num944); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] >= 90f) - { - projectile.localAI[0] *= -1f; - } - if (projectile.localAI[0] >= 0f) - { - projectile.scale += 0.003f; - } - else - { - projectile.scale -= 0.003f; - } - projectile.rotation += 0.0025f * projectile.scale; - float num945 = 1f; - float num946 = 1f; - if (projectile.identity % 6 == 0) - { - num946 *= -1f; - } - if (projectile.identity % 6 == 1) - { - num945 *= -1f; - } - if (projectile.identity % 6 == 2) - { - num946 *= -1f; - num945 *= -1f; - } - if (projectile.identity % 6 == 3) - { - num946 = 0f; - } - if (projectile.identity % 6 == 4) - { - num945 = 0f; - } - projectile.localAI[1] += 1f; - if (projectile.localAI[1] > 60f) - { - projectile.localAI[1] = -180f; - } - if (projectile.localAI[1] >= -60f) - { - projectile.velocity.X = projectile.velocity.X + 0.002f * num946; - projectile.velocity.Y = projectile.velocity.Y + 0.002f * num945; - } - else - { - projectile.velocity.X = projectile.velocity.X - 0.002f * num946; - projectile.velocity.Y = projectile.velocity.Y - 0.002f * num945; - } - projectile.ai[0] += 1f; - if (projectile.ai[0] > 5400f) - { - projectile.damage = 0; - projectile.ai[1] = 1f; - if (projectile.alpha < 255) - { - projectile.alpha += 5; - if (projectile.alpha > 255) - { - projectile.alpha = 255; - } - } - else if (projectile.owner == Main.myPlayer) - { - projectile.Kill(); - } - } - else - { - float num947 = (projectile.Center - Main.player[projectile.owner].Center).Length() / 100f; - if (num947 > 4f) - { - num947 *= 1.1f; - } - if (num947 > 5f) - { - num947 *= 1.2f; - } - if (num947 > 6f) - { - num947 *= 1.3f; - } - if (num947 > 7f) - { - num947 *= 1.4f; - } - if (num947 > 8f) - { - num947 *= 1.5f; - } - if (num947 > 9f) - { - num947 *= 1.6f; - } - if (num947 > 10f) - { - num947 *= 1.7f; - } - projectile.ai[0] += num947; - if (projectile.alpha > 50) - { - projectile.alpha -= 10; - if (projectile.alpha < 50) - { - projectile.alpha = 50; - } - } - } - bool flag49 = false; - Vector2 center12 = new Vector2(0f, 0f); - float num948 = 600f; - for (int num949 = 0; num949 < 200; num949++) - { - if (Main.npc[num949].CanBeChasedBy(projectile, false)) - { - float num950 = Main.npc[num949].position.X + (float)(Main.npc[num949].width / 2); - float num951 = Main.npc[num949].position.Y + (float)(Main.npc[num949].height / 2); - float num952 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num950) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num951); - if (num952 < num948) - { - num948 = num952; - center12 = Main.npc[num949].Center; - flag49 = true; - } - } - } - if (flag49) - { - Vector2 vector101 = center12 - projectile.Center; - vector101.Normalize(); - vector101 *= 0.75f; - projectile.velocity = (projectile.velocity * 10f + vector101) / 11f; - return; - } - if ((double)projectile.velocity.Length() > 0.2) - { - projectile.velocity *= 0.98f; - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - target.AddBuff(BuffID.CursedInferno, 90); - } - - public override void OnHitPvp(Player target, int damage, bool crit) - { - target.AddBuff(BuffID.CursedInferno, 90); + public class TheDeadlyMicrobeProjectile : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Microbe"); } - public override void Kill(int timeLeft) - { - projectile.position = projectile.Center; - projectile.width = projectile.height = 56; - projectile.position.X = projectile.position.X - (float)(projectile.width / 2); - projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); - int num226 = 36; - for (int num227 = 0; num227 < num226; num227++) - { - Vector2 vector6 = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.75f; - vector6 = vector6.RotatedBy((double)((float)(num227 - (num226 / 2 - 1)) * 6.28318548f / (float)num226), default) + projectile.Center; - Vector2 vector7 = vector6 - projectile.Center; - int num228 = Dust.NewDust(vector6 + vector7, 0, 0, 44, vector7.X, vector7.Y, 100, default, 0.5f); - Main.dust[num228].noGravity = true; - Main.dust[num228].noLight = true; - Main.dust[num228].velocity = vector7; - } - projectile.Damage(); - } - } + public override void SetDefaults() + { + projectile.width = projectile.height = 14; + projectile.friendly = true; + projectile.alpha = 255; + projectile.penetrate = 1; + projectile.tileCollide = false; + projectile.ignoreWater = true; + projectile.timeLeft = 3600; + } + + public override void AI() + { + projectile.SporeSacAI(); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(BuffID.CursedInferno, 90); + } + + public override void OnHitPvp(Player target, int damage, bool crit) + { + target.AddBuff(BuffID.CursedInferno, 90); + } + + public override void Kill(int timeLeft) + { + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 56); + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 10; + int dustAmt = 36; + for (int d = 0; d < dustAmt; d++) + { + Vector2 source = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.75f; + source = source.RotatedBy((double)((float)(d - (dustAmt / 2 - 1)) * MathHelper.TwoPi / (float)dustAmt), default) + projectile.Center; + Vector2 dustVel = source - projectile.Center; + int index = Dust.NewDust(source + dustVel, 0, 0, 44, dustVel.X, dustVel.Y, 100, default, 0.5f); + Main.dust[index].noGravity = true; + Main.dust[index].noLight = true; + Main.dust[index].velocity = dustVel; + } + projectile.Damage(); + } + } } diff --git a/Utilities/CalamityUtils.cs b/Utilities/CalamityUtils.cs index 904aa22370..b369cd4f2d 100644 --- a/Utilities/CalamityUtils.cs +++ b/Utilities/CalamityUtils.cs @@ -1014,6 +1014,156 @@ namespace CalamityMod return velocity; } + public static void SporeSacAI(this Projectile projectile) + { + Player player = Main.player[projectile.owner]; + + float scaleAmt = 1f - (float)projectile.alpha / 255f; + scaleAmt *= projectile.scale; + Lighting.AddLight(projectile.Center, 0.25f * scaleAmt, 0.025f * scaleAmt, 0.275f * scaleAmt); + + projectile.localAI[0] += 1f; + if (projectile.localAI[0] >= 90f) + { + projectile.localAI[0] *= -1f; + } + if (projectile.localAI[0] >= 0f) + { + projectile.scale += 0.003f; + } + else + { + projectile.scale -= 0.003f; + } + projectile.rotation += 0.0025f * projectile.scale; + float yVel = 1f; + float xVel = 1f; + if (projectile.identity % 6 == 0) + { + xVel *= -1f; + } + if (projectile.identity % 6 == 1) + { + yVel *= -1f; + } + if (projectile.identity % 6 == 2) + { + xVel *= -1f; + yVel *= -1f; + } + if (projectile.identity % 6 == 3) + { + xVel = 0f; + } + if (projectile.identity % 6 == 4) + { + yVel = 0f; + } + projectile.localAI[1] += 1f; + if (projectile.localAI[1] > 60f) + { + projectile.localAI[1] = -180f; + } + if (projectile.localAI[1] >= -60f) + { + projectile.velocity.X += 0.002f * xVel; + projectile.velocity.Y += 0.002f * yVel; + } + else + { + projectile.velocity.X -= 0.002f * xVel; + projectile.velocity.Y -= 0.002f * yVel; + } + projectile.ai[0] += 1f; + if (projectile.ai[0] > 5400f) + { + projectile.damage = 0; + projectile.ai[1] = 1f; + if (projectile.alpha < 255) + { + projectile.alpha += 5; + if (projectile.alpha > 255) + { + projectile.alpha = 255; + } + } + else if (projectile.owner == Main.myPlayer) + { + projectile.Kill(); + } + } + else + { + float playerDist = (projectile.Center - player.Center).Length() / 100f; + if (playerDist > 4f) + { + playerDist *= 1.1f; + } + if (playerDist > 5f) + { + playerDist *= 1.2f; + } + if (playerDist > 6f) + { + playerDist *= 1.3f; + } + if (playerDist > 7f) + { + playerDist *= 1.4f; + } + if (playerDist > 8f) + { + playerDist *= 1.5f; + } + if (playerDist > 9f) + { + playerDist *= 1.6f; + } + if (playerDist > 10f) + { + playerDist *= 1.7f; + } + projectile.ai[0] += playerDist; + if (projectile.alpha > 50) + { + projectile.alpha -= 10; + if (projectile.alpha < 50) + { + projectile.alpha = 50; + } + } + } + bool foundTarget = false; + Vector2 targetPos = new Vector2(0f, 0f); + float maxDist = 600f; + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC npc = Main.npc[i]; + if (npc.CanBeChasedBy(projectile, false)) + { + float targetDist = Vector2.Distance(projectile.Center, npc.Center); + if (targetDist < maxDist) + { + targetPos = npc.Center; + foundTarget = true; + break; + } + } + } + if (foundTarget) + { + Vector2 targetVec = targetPos - projectile.Center; + targetVec.Normalize(); + targetVec *= 0.75f; + projectile.velocity = (projectile.velocity * 10f + targetVec) / 11f; + return; + } + if (projectile.velocity.Length() > 0.2f) + { + projectile.velocity *= 0.98f; + } + } + public static void MinionAntiClump(this Projectile projectile, float pushForce = 0.05f) { for (int k = 0; k < Main.maxProjectiles; k++)