diff --git a/NPCs/Abyss/Laserfish.cs b/NPCs/Abyss/Laserfish.cs index 3f933cc585..d926ddc4ac 100644 --- a/NPCs/Abyss/Laserfish.cs +++ b/NPCs/Abyss/Laserfish.cs @@ -269,10 +269,10 @@ namespace CalamityMod.NPCs.Abyss Vector2 center = new Vector2(npc.Center.X, npc.Center.Y); Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2)); Vector2 vector = center - Main.screenPosition; - vector -= new Vector2((float)ModContent.GetTexture("CalamityMod/NPCs/Abyss/Laserfishglow").Width, (float)(ModContent.GetTexture("CalamityMod/NPCs/Abyss/Laserfishglow").Height / Main.npcFrameCount[npc.type])) * 1f / 2f; + vector -= new Vector2((float)ModContent.GetTexture("CalamityMod/NPCs/Abyss/LaserfishGlow").Width, (float)(ModContent.GetTexture("CalamityMod/NPCs/Abyss/LaserfishGlow").Height / Main.npcFrameCount[npc.type])) * 1f / 2f; vector += vector11 * 1f + new Vector2(0f, 0f + 4f + npc.gfxOffY); Color color = new Color(127 - npc.alpha, 127 - npc.alpha, 127 - npc.alpha, 0).MultiplyRGBA(Microsoft.Xna.Framework.Color.Yellow); - Main.spriteBatch.Draw(ModContent.GetTexture("CalamityMod/NPCs/Abyss/Laserfishglow"), vector, + Main.spriteBatch.Draw(ModContent.GetTexture("CalamityMod/NPCs/Abyss/LaserfishGlow"), vector, new Microsoft.Xna.Framework.Rectangle?(npc.frame), color, npc.rotation, vector11, 1f, spriteEffects, 0f); } diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index e1b16577d7..cb0b84522f 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -1989,6 +1989,92 @@ namespace CalamityMod.Projectiles } return true; } - #endregion - } + #endregion + + #region Homing AI + public static void HomeInOnNPC(Projectile projectile, bool ignoreTiles, float distanceRequired, float homingVelocity, float N) + { + Vector2 center = projectile.Center; + float maxDistance = distanceRequired; + bool homeIn = false; + + for (int i = 0; i < 200; i++) + { + if (Main.npc[i].CanBeChasedBy(projectile, false)) + { + float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); + + bool canHit = true; + if (extraDistance < maxDistance && !ignoreTiles) + canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[i].Center, 1, 1); + + if (Vector2.Distance(Main.npc[i].Center, projectile.Center) < (maxDistance + extraDistance) && canHit) + { + center = Main.npc[i].Center; + homeIn = true; + break; + } + } + } + + if (homeIn) + { + Vector2 homeInVector = projectile.DirectionTo(center); + if (homeInVector.HasNaNs()) + homeInVector = Vector2.UnitY; + + projectile.velocity = (projectile.velocity * N + homeInVector * homingVelocity) / (N + 1f); + } + } + + public static void MagnetSphereHitscan(Projectile projectile, float distanceRequired, float homingVelocity, float projectileTimer, int maxTargets, int spawnedProjectile) + { + float maxDistance = distanceRequired; + bool homeIn = false; + int[] targetArray = new int[maxTargets]; + int targetArrayIndex = 0; + + for (int i = 0; i < 200; i++) + { + if (Main.npc[i].CanBeChasedBy(projectile, false)) + { + float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); + + bool canHit = true; + if (extraDistance < maxDistance) + canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[i].Center, 1, 1); + + if (Vector2.Distance(Main.npc[i].Center, projectile.Center) < (maxDistance + extraDistance) && canHit) + { + if (targetArrayIndex < maxTargets) + { + targetArray[targetArrayIndex] = i; + targetArrayIndex++; + homeIn = true; + } + else + break; + } + } + } + + if (homeIn) + { + int randomTarget = Main.rand.Next(targetArrayIndex); + randomTarget = targetArray[randomTarget]; + + projectile.localAI[0] += 1f; + if (projectile.localAI[0] > projectileTimer) + { + projectile.localAI[0] = 0f; + Vector2 value = projectile.Center + projectile.velocity * 4f; + Vector2 velocity = Vector2.Normalize(Main.npc[randomTarget].Center - value) * homingVelocity; + + if (projectile.owner == Main.myPlayer) + Projectile.NewProjectile(value.X, value.Y, velocity.X, velocity.Y, spawnedProjectile, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); + } + } + } + #endregion + } } diff --git a/Projectiles/Magic/AstralachneaFang.cs b/Projectiles/Magic/AstralachneaFang.cs index 8811997ce5..510d2c19d3 100644 --- a/Projectiles/Magic/AstralachneaFang.cs +++ b/Projectiles/Magic/AstralachneaFang.cs @@ -32,7 +32,7 @@ namespace CalamityMod.Projectiles.Magic { int num469 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, ModContent.DustType(), 0f, 0f, 100, default, 1f); Main.dust[num469].noGravity = true; - Main.dust[num469].velocity *= 0f; + if (projectile.velocity.X < 0f) { projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X); @@ -42,44 +42,7 @@ namespace CalamityMod.Projectiles.Magic projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X); } - float centerX = projectile.Center.X; - float centerY = projectile.Center.Y; - float distance = 250f; - bool homeIn = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - centerX = Main.npc[num475].Center.X; - centerY = Main.npc[num475].Center.Y; - homeIn = true; - } - } - } - - if (homeIn) - { - float num483 = 13f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = centerX - vector35.X; - float num485 = centerY - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 25f + num484) / 26f; - projectile.velocity.Y = (projectile.velocity.Y * 25f + num485) / 26f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 250f, 13f, 25f); } public override void Kill(int timeLeft) @@ -88,11 +51,8 @@ namespace CalamityMod.Projectiles.Magic for (int k = 0; k < 3; k++) { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, ModContent.DustType(), 0f, 0f); - } - for (int k = 0; k < 3; k++) - { - Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, ModContent.DustType(), 0f, 0f); - } + Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, ModContent.DustType(), 0f, 0f); + } } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) diff --git a/Projectiles/Magic/BeamingBolt2.cs b/Projectiles/Magic/BeamingBolt2.cs index 15e34bd4b9..7d02d3585c 100644 --- a/Projectiles/Magic/BeamingBolt2.cs +++ b/Projectiles/Magic/BeamingBolt2.cs @@ -42,45 +42,7 @@ namespace CalamityMod.Projectiles.Magic Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, randomDust, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 400f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 20f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - return; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 400f, 20f, 20f); } public override void Kill(int timeLeft) diff --git a/Projectiles/Magic/BeastScythe.cs b/Projectiles/Magic/BeastScythe.cs index 49c157c7de..11f1e7ffe6 100644 --- a/Projectiles/Magic/BeastScythe.cs +++ b/Projectiles/Magic/BeastScythe.cs @@ -130,44 +130,8 @@ namespace CalamityMod.Projectiles.Magic if (projectile.ai[0] >= 30f) { projectile.velocity *= 1.001f; - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 400f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 20f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 400f, 20f, 20f); } } diff --git a/Projectiles/Magic/BigBeamofDeath.cs b/Projectiles/Magic/BigBeamofDeath.cs index 6f1b3e0f20..c3354a8c60 100644 --- a/Projectiles/Magic/BigBeamofDeath.cs +++ b/Projectiles/Magic/BigBeamofDeath.cs @@ -41,19 +41,10 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num249 = 206; - int num448 = Dust.NewDust(vector33, 1, 1, num249, 0f, 0f, 0, default, 3f); - Main.dust[num448].position = vector33; - Main.dust[num448].velocity *= 0.1f; - } - } + if (projectile.localAI[0] > 9f) + { + Dust.NewDust(projectile.position, 1, 1, 206, 0f, 0f, 0, default, 3f); + } } } } diff --git a/Projectiles/Magic/BigBeamofDeath2.cs b/Projectiles/Magic/BigBeamofDeath2.cs index 7c5c7a3f43..a8ae9bd6af 100644 --- a/Projectiles/Magic/BigBeamofDeath2.cs +++ b/Projectiles/Magic/BigBeamofDeath2.cs @@ -26,21 +26,11 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num249 = 206; - int num448 = Dust.NewDust(vector33, 1, 1, num249, 0f, 0f, 0, default, 3f); - Main.dust[num448].position = vector33; - Main.dust[num448].velocity *= 0.1f; - } - return; - } - } + projectile.localAI[0] += 1f; + if (projectile.localAI[0] > 9f) + { + Dust.NewDust(projectile.position, 1, 1, 206, 0f, 0f, 0, default, 3f); + } + } } } diff --git a/Projectiles/Magic/BlackAnurianPlankton.cs b/Projectiles/Magic/BlackAnurianPlankton.cs index 6166975b2a..b5b2c163c6 100644 --- a/Projectiles/Magic/BlackAnurianPlankton.cs +++ b/Projectiles/Magic/BlackAnurianPlankton.cs @@ -79,6 +79,7 @@ namespace CalamityMod.Projectiles.Magic num373 = projectile.position.X + (float)(projectile.width / 2) + projectile.velocity.X * 100f; num374 = projectile.position.Y + (float)(projectile.height / 2) + projectile.velocity.Y * 100f; } + float num380 = 6f; float num381 = 0.1f; Vector2 vector30 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); diff --git a/Projectiles/Magic/BloodBolt.cs b/Projectiles/Magic/BloodBolt.cs index 55a7398c4d..ae52a6a3e9 100644 --- a/Projectiles/Magic/BloodBolt.cs +++ b/Projectiles/Magic/BloodBolt.cs @@ -22,21 +22,14 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 2; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 235, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } - return; - } + for (int num447 = 0; num447 < 2; num447++) + { + Vector2 vector33 = projectile.position; + vector33 -= projectile.velocity * ((float)num447 * 0.25f); + int num448 = Dust.NewDust(vector33, 1, 1, 235, 0f, 0f, 0, default, 1.25f); + Main.dust[num448].position = vector33; + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } } } diff --git a/Projectiles/Magic/BloodOrb.cs b/Projectiles/Magic/BloodOrb.cs index c1fe50f08e..21597178c0 100644 --- a/Projectiles/Magic/BloodOrb.cs +++ b/Projectiles/Magic/BloodOrb.cs @@ -24,67 +24,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 24f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); } } } diff --git a/Projectiles/Magic/BloodRay.cs b/Projectiles/Magic/BloodRay.cs index 1904ea48e9..ff95bf7fb9 100644 --- a/Projectiles/Magic/BloodRay.cs +++ b/Projectiles/Magic/BloodRay.cs @@ -27,8 +27,9 @@ namespace CalamityMod.Projectiles.Magic if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.6), projectile.knockBack, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.6), projectile.knockBack, projectile.owner, 0f, 0f); } + projectile.localAI[0] += 1f; if (projectile.localAI[0] > 9f) { @@ -36,13 +37,11 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 235, 0f, 0f, 0, default, 1.5f); Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; Main.dust[num448].velocity *= 0.2f; } - return; } } } diff --git a/Projectiles/Magic/BrimstoneHomer.cs b/Projectiles/Magic/BrimstoneHomer.cs index a0705e287d..49bf0a366f 100644 --- a/Projectiles/Magic/BrimstoneHomer.cs +++ b/Projectiles/Magic/BrimstoneHomer.cs @@ -26,55 +26,13 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 4f) - { - for (int num468 = 0; num468 < 2; num468++) - { - int num469 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 235, 0f, 0f, 100, default, 1f); - Main.dust[num469].noGravity = true; - Main.dust[num469].velocity *= 0f; - } - } - - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 500f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) + for (int num468 = 0; num468 < 2; num468++) { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } + int num469 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 235, 0f, 0f, 100, default, 1f); + Main.dust[num469].noGravity = true; } - if (flag17) - { - float num483 = 8f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 500f, 8f, 20f); } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) diff --git a/Projectiles/Magic/Climax2.cs b/Projectiles/Magic/Climax2.cs index 9ab58d475f..662fd26625 100644 --- a/Projectiles/Magic/Climax2.cs +++ b/Projectiles/Magic/Climax2.cs @@ -35,6 +35,7 @@ namespace CalamityMod.Projectiles.Magic projectile.velocity.X = (float)(Math.Sin(timeElapsed * (double)(0.5f * projectile.ai[0])) * circleSize); projectile.velocity.Y = (float)(Math.Cos(timeElapsed * (double)(0.5f * projectile.ai[0])) * circleSize); circleSize += circleGrowth; + if (projectile.velocity.X > 0f) { projectile.rotation += (Math.Abs(projectile.velocity.Y) + Math.Abs(projectile.velocity.X)) * 0.001f; @@ -43,6 +44,7 @@ namespace CalamityMod.Projectiles.Magic { projectile.rotation -= (Math.Abs(projectile.velocity.Y) + Math.Abs(projectile.velocity.X)) * 0.001f; } + projectile.frameCounter++; if (projectile.frameCounter > 6) { @@ -54,59 +56,7 @@ namespace CalamityMod.Projectiles.Magic } } - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (projectile.timeLeft < 30) - { - flag14 = false; - } - if (flag14) - { - int num440 = Main.rand.Next(num428); - num440 = array[num440]; - float num441 = Main.npc[num440].position.X + (float)(Main.npc[num440].width / 2); - float num442 = Main.npc[num440].position.Y + (float)(Main.npc[num440].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 4f) - { - projectile.localAI[0] = 0f; - float num443 = 8f; - Vector2 vector33 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - vector33 += projectile.velocity * 4f; - float num444 = num441 - vector33.X; - float num445 = num442 - vector33.Y; - float num446 = (float)Math.Sqrt((double)(num444 * num444 + num445 * num445)); - num446 = num443 / num446; - num444 *= num446; - num445 *= num446; - Projectile.NewProjectile(vector33.X, vector33.Y, num444, num445, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 8f, 4f, 5, ModContent.ProjectileType()); } public override Color? GetAlpha(Color lightColor) diff --git a/Projectiles/Magic/ClimaxBeam.cs b/Projectiles/Magic/ClimaxBeam.cs index 90dc41a551..df0076c920 100644 --- a/Projectiles/Magic/ClimaxBeam.cs +++ b/Projectiles/Magic/ClimaxBeam.cs @@ -20,23 +20,10 @@ namespace CalamityMod.Projectiles.Magic projectile.magic = true; } - public override void AI() - { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 206, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } - return; - } - } + public override void AI() + { + int num448 = Dust.NewDust(projectile.position, 1, 1, 206, 0f, 0f, 0, default, 1.25f); + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } } diff --git a/Projectiles/Magic/ClimaxProj.cs b/Projectiles/Magic/ClimaxProj.cs index d82a4caebb..6a0285d9b2 100644 --- a/Projectiles/Magic/ClimaxProj.cs +++ b/Projectiles/Magic/ClimaxProj.cs @@ -27,8 +27,8 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 0.98f; - projectile.velocity.Y *= 0.98f; + projectile.velocity *= 0.96f; + if (projectile.velocity.X > 0f) { projectile.rotation += (Math.Abs(projectile.velocity.Y) + Math.Abs(projectile.velocity.X)) * 0.001f; @@ -37,6 +37,7 @@ namespace CalamityMod.Projectiles.Magic { projectile.rotation -= (Math.Abs(projectile.velocity.Y) + Math.Abs(projectile.velocity.X)) * 0.001f; } + projectile.frameCounter++; if (projectile.frameCounter > 6) { @@ -47,64 +48,8 @@ namespace CalamityMod.Projectiles.Magic projectile.frame = 0; } } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - int[] array = new int[20]; - int num428 = 0; - float distance = 400f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (projectile.timeLeft < 30) - { - flag14 = false; - } - if (flag14) - { - int num440 = Main.rand.Next(num428); - num440 = array[num440]; - float num441 = Main.npc[num440].position.X + (float)(Main.npc[num440].width / 2); - float num442 = Main.npc[num440].position.Y + (float)(Main.npc[num440].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 4f) - { - projectile.localAI[0] = 0f; - float num443 = 8f; - Vector2 vector33 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - vector33 += projectile.velocity * 4f; - float num444 = num441 - vector33.X; - float num445 = num442 - vector33.Y; - float num446 = (float)Math.Sqrt((double)(num444 * num444 + num445 * num445)); - num446 = num443 / num446; - num444 *= num446; - num445 *= num446; - Projectile.NewProjectile(vector33.X, vector33.Y, num444, num445, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 400f, 8f, 4f, 5, ModContent.ProjectileType()); } public override Color? GetAlpha(Color lightColor) diff --git a/Projectiles/Magic/DivineRetributionSpear.cs b/Projectiles/Magic/DivineRetributionSpear.cs index 3fcaf239ed..0bf105abfc 100644 --- a/Projectiles/Magic/DivineRetributionSpear.cs +++ b/Projectiles/Magic/DivineRetributionSpear.cs @@ -35,6 +35,7 @@ namespace CalamityMod.Projectiles.Magic float num953 = 25f * projectile.ai[1]; //100 float scaleFactor12 = 5f * projectile.ai[1]; //5 float num954 = 1000f; + if (projectile.velocity.X < 0f) { projectile.spriteDirection = -1; @@ -45,6 +46,7 @@ namespace CalamityMod.Projectiles.Magic projectile.spriteDirection = 1; projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X); } + Lighting.AddLight(projectile.Center, 0.7f, 0.3f, 0f); if (Main.player[projectile.owner].active && !Main.player[projectile.owner].dead) { @@ -59,44 +61,7 @@ namespace CalamityMod.Projectiles.Magic return; } - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 600f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 9f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 600f, 9f, 20f); } else { diff --git a/Projectiles/Magic/ElementBolt.cs b/Projectiles/Magic/ElementBolt.cs index 62f5b6b035..bb0818ac1e 100644 --- a/Projectiles/Magic/ElementBolt.cs +++ b/Projectiles/Magic/ElementBolt.cs @@ -26,23 +26,18 @@ namespace CalamityMod.Projectiles.Magic if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 2; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.25f); - Main.dust[num448].noGravity = true; - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); } + + for (int num447 = 0; num447 < 2; num447++) + { + Vector2 vector33 = projectile.position; + vector33 -= projectile.velocity * ((float)num447 * 0.25f); + int num448 = Dust.NewDust(vector33, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.25f); + Main.dust[num448].noGravity = true; + Main.dust[num448].position = vector33; + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } } } diff --git a/Projectiles/Magic/ElementBolt2.cs b/Projectiles/Magic/ElementBolt2.cs index 0985a37250..50e9add7ff 100644 --- a/Projectiles/Magic/ElementBolt2.cs +++ b/Projectiles/Magic/ElementBolt2.cs @@ -20,23 +20,11 @@ namespace CalamityMod.Projectiles.Magic projectile.magic = true; } - public override void AI() - { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.25f); - Main.dust[num448].noGravity = true; - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } - } - } + public override void AI() + { + int num448 = Dust.NewDust(projectile.position, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.25f); + Main.dust[num448].noGravity = true; + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } } diff --git a/Projectiles/Magic/ElementOrb.cs b/Projectiles/Magic/ElementOrb.cs index 49a183b1e3..d264190678 100644 --- a/Projectiles/Magic/ElementOrb.cs +++ b/Projectiles/Magic/ElementOrb.cs @@ -24,70 +24,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 24f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); } } } diff --git a/Projectiles/Magic/ElementOrb2.cs b/Projectiles/Magic/ElementOrb2.cs index 9e55a49756..b950d639ac 100644 --- a/Projectiles/Magic/ElementOrb2.cs +++ b/Projectiles/Magic/ElementOrb2.cs @@ -24,70 +24,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 24f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); + } } } diff --git a/Projectiles/Magic/ElementalRayBeam.cs b/Projectiles/Magic/ElementalRayBeam.cs index 46d8f2dc44..ad60d7d0e7 100644 --- a/Projectiles/Magic/ElementalRayBeam.cs +++ b/Projectiles/Magic/ElementalRayBeam.cs @@ -29,8 +29,9 @@ namespace CalamityMod.Projectiles.Magic if (projectile.localAI[1] >= 22f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); } + projectile.localAI[0] += 1f; if (projectile.localAI[0] > 9f) { @@ -38,12 +39,10 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.25f); Main.dust[num448].noGravity = true; Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } } } diff --git a/Projectiles/Magic/FabBolt.cs b/Projectiles/Magic/FabBolt.cs index 44c7ea8b79..4b56a84ee4 100644 --- a/Projectiles/Magic/FabBolt.cs +++ b/Projectiles/Magic/FabBolt.cs @@ -20,23 +20,11 @@ namespace CalamityMod.Projectiles.Magic projectile.magic = true; } - public override void AI() - { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 4f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 234, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].noGravity = true; - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } - } - } + public override void AI() + { + int num448 = Dust.NewDust(projectile.position, 1, 1, 234, 0f, 0f, 0, default, 1.25f); + Main.dust[num448].noGravity = true; + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } } diff --git a/Projectiles/Magic/FabOrb.cs b/Projectiles/Magic/FabOrb.cs index 799ce66b35..2b2f09c52a 100644 --- a/Projectiles/Magic/FabOrb.cs +++ b/Projectiles/Magic/FabOrb.cs @@ -24,70 +24,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 24f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); } } } diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs index 382ef9b9db..90bf2ae062 100644 --- a/Projectiles/Magic/FabRay.cs +++ b/Projectiles/Magic/FabRay.cs @@ -29,8 +29,9 @@ namespace CalamityMod.Projectiles.Magic if (projectile.localAI[1] >= 9f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); } + projectile.localAI[0] += 1f; if (projectile.localAI[0] > 16f) { @@ -38,12 +39,10 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 234, 0f, 0f, 0, default, 1.25f); Main.dust[num448].noGravity = true; Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } } } diff --git a/Projectiles/Magic/ForbiddenAxeBlade.cs b/Projectiles/Magic/ForbiddenAxeBlade.cs index c328ad0f31..f020086bb1 100644 --- a/Projectiles/Magic/ForbiddenAxeBlade.cs +++ b/Projectiles/Magic/ForbiddenAxeBlade.cs @@ -31,60 +31,22 @@ namespace CalamityMod.Projectiles.Magic { projectile.alpha -= 3; projectile.rotation += 0.75f; + projectile.ai[1] += 1f; if (projectile.ai[1] <= 20f) { - projectile.velocity.X *= 0.85f; - projectile.velocity.Y *= 0.85f; + projectile.velocity *= 0.85f; } else if (projectile.ai[1] > 20f && projectile.ai[1] <= 39f) { - projectile.velocity.X *= 1.25f; - projectile.velocity.Y *= 1.25f; - - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 300f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 10f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + projectile.velocity *= 1.25f; + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 300f, 10f, 20f); } else if (projectile.ai[1] == 40f) { projectile.ai[1] = 0f; } + if (Main.rand.NextBool(8)) { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 159, projectile.velocity.X * 0.1f, projectile.velocity.Y * 0.1f); diff --git a/Projectiles/Magic/GraniteEnergy.cs b/Projectiles/Magic/GraniteEnergy.cs index 0d44d8eb25..d269f3af25 100644 --- a/Projectiles/Magic/GraniteEnergy.cs +++ b/Projectiles/Magic/GraniteEnergy.cs @@ -24,51 +24,9 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 4f) - { - int num469 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 229, 0f, 0f, 100, default, 0.6f); - Main.dust[num469].velocity *= 0f; - } + Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 229, 0f, 0f, 100, default, 0.6f); - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 500f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 22f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 500f, 22f, 20f); } } } diff --git a/Projectiles/Magic/HolyLaser.cs b/Projectiles/Magic/HolyLaser.cs index 8d814ad5fb..90d9548c7d 100644 --- a/Projectiles/Magic/HolyLaser.cs +++ b/Projectiles/Magic/HolyLaser.cs @@ -29,9 +29,6 @@ namespace CalamityMod.Projectiles.Magic projectile.localAI[0] += 1f; if (projectile.localAI[0] > 9f) { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * 0.25f; - projectile.alpha = 255; int num249 = Main.rand.Next(2); if (num249 == 0) { @@ -41,10 +38,8 @@ namespace CalamityMod.Projectiles.Magic { num249 = 246; } - int num448 = Dust.NewDust(vector33, 1, 1, num249, 0f, 0f, 0, default, 0.25f); - Main.dust[num448].position = vector33; + int num448 = Dust.NewDust(projectile.position, 1, 1, num249, 0f, 0f, 0, default, 0.25f); Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } } diff --git a/Projectiles/Magic/IceSpike.cs b/Projectiles/Magic/IceSpike.cs index a9680023c4..dab2eb5eb7 100644 --- a/Projectiles/Magic/IceSpike.cs +++ b/Projectiles/Magic/IceSpike.cs @@ -27,50 +27,13 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.rotation += 0.5f; - projectile.localAI[0] += 1f; - int num469 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 67, 0f, 0f, 100, default, 1f); + projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); + projectile.rotation = projectile.velocity.ToRotation() + (projectile.spriteDirection == 1 ? 0f : MathHelper.Pi) + (MathHelper.Pi * 0.5f * projectile.direction); + + int num469 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 67, 0f, 0f, 100, default, 1f); Main.dust[num469].noGravity = true; - Main.dust[num469].velocity *= 0f; - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 400f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 10f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 400f, 10f, 20f); } public override void Kill(int timeLeft) diff --git a/Projectiles/Magic/MadAlchemistsCocktailShrapnel.cs b/Projectiles/Magic/MadAlchemistsCocktailShrapnel.cs index 18e5adc5ba..b5bbf4b1ab 100644 --- a/Projectiles/Magic/MadAlchemistsCocktailShrapnel.cs +++ b/Projectiles/Magic/MadAlchemistsCocktailShrapnel.cs @@ -43,48 +43,11 @@ namespace CalamityMod.Projectiles.Magic Main.dust[num42].velocity = projectile.velocity; } } + int num458 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 173, 0f, 0f, 100, default, 1f); Main.dust[num458].noGravity = true; - Main.dust[num458].velocity *= 0f; - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 500f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 12f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 500f, 12f, 20f); } } } diff --git a/Projectiles/Magic/MagneticBeam.cs b/Projectiles/Magic/MagneticBeam.cs index bade18d8e3..026ec50971 100644 --- a/Projectiles/Magic/MagneticBeam.cs +++ b/Projectiles/Magic/MagneticBeam.cs @@ -20,23 +20,10 @@ namespace CalamityMod.Projectiles.Magic projectile.magic = true; } - public override void AI() - { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 173, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } - return; - } - } + public override void AI() + { + int num448 = Dust.NewDust(projectile.position, 1, 1, 173, 0f, 0f, 0, default, 1.25f); + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } } diff --git a/Projectiles/Magic/MagneticOrb.cs b/Projectiles/Magic/MagneticOrb.cs index 99acdeacd7..6270b2948d 100644 --- a/Projectiles/Magic/MagneticOrb.cs +++ b/Projectiles/Magic/MagneticOrb.cs @@ -27,8 +27,8 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 0.98f; - projectile.velocity.Y *= 0.98f; + projectile.velocity *= 0.96f; + if (projectile.velocity.X > 0f) { projectile.rotation += (Math.Abs(projectile.velocity.Y) + Math.Abs(projectile.velocity.X)) * 0.001f; @@ -37,6 +37,7 @@ namespace CalamityMod.Projectiles.Magic { projectile.rotation -= (Math.Abs(projectile.velocity.Y) + Math.Abs(projectile.velocity.X)) * 0.001f; } + projectile.frameCounter++; if (projectile.frameCounter > 6) { @@ -47,64 +48,8 @@ namespace CalamityMod.Projectiles.Magic projectile.frame = 0; } } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - int[] array = new int[20]; - int num428 = 0; - float distance = 400f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (projectile.timeLeft < 30) - { - flag14 = false; - } - if (flag14) - { - int num440 = Main.rand.Next(num428); - num440 = array[num440]; - float num441 = Main.npc[num440].position.X + (float)(Main.npc[num440].width / 2); - float num442 = Main.npc[num440].position.Y + (float)(Main.npc[num440].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 4f) - { - projectile.localAI[0] = 0f; - float num443 = 8f; - Vector2 vector33 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - vector33 += projectile.velocity * 4f; - float num444 = num441 - vector33.X; - float num445 = num442 - vector33.Y; - float num446 = (float)Math.Sqrt((double)(num444 * num444 + num445 * num445)); - num446 = num443 / num446; - num444 *= num446; - num445 *= num446; - Projectile.NewProjectile(vector33.X, vector33.Y, num444, num445, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 400f, 8f, 4f, 5, ModContent.ProjectileType()); } public override Color? GetAlpha(Color lightColor) diff --git a/Projectiles/Magic/NightBolt.cs b/Projectiles/Magic/NightBolt.cs index 6e85803f63..638da609d5 100644 --- a/Projectiles/Magic/NightBolt.cs +++ b/Projectiles/Magic/NightBolt.cs @@ -22,21 +22,14 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 2; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 27, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } - return; - } + for (int num447 = 0; num447 < 2; num447++) + { + Vector2 vector33 = projectile.position; + vector33 -= projectile.velocity * ((float)num447 * 0.25f); + int num448 = Dust.NewDust(vector33, 1, 1, 27, 0f, 0f, 0, default, 1.25f); + Main.dust[num448].position = vector33; + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } } } diff --git a/Projectiles/Magic/NightOrb.cs b/Projectiles/Magic/NightOrb.cs index d4fc7974bc..15429d5a0c 100644 --- a/Projectiles/Magic/NightOrb.cs +++ b/Projectiles/Magic/NightOrb.cs @@ -24,70 +24,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 24f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); } } } diff --git a/Projectiles/Magic/NightsRayBeam.cs b/Projectiles/Magic/NightsRayBeam.cs index 5f5c0cec95..5e56219ebb 100644 --- a/Projectiles/Magic/NightsRayBeam.cs +++ b/Projectiles/Magic/NightsRayBeam.cs @@ -27,8 +27,9 @@ namespace CalamityMod.Projectiles.Magic if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.6), projectile.knockBack, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.6), projectile.knockBack, projectile.owner, 0f, 0f); } + projectile.localAI[0] += 1f; if (projectile.localAI[0] > 9f) { @@ -36,13 +37,10 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 27, 0f, 0f, 0, default, 1.25f); Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } - return; } } } diff --git a/Projectiles/Magic/ParticleBeamofDoom.cs b/Projectiles/Magic/ParticleBeamofDoom.cs index a74df022bd..77073b2637 100644 --- a/Projectiles/Magic/ParticleBeamofDoom.cs +++ b/Projectiles/Magic/ParticleBeamofDoom.cs @@ -26,21 +26,11 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num249 = 206; - int num448 = Dust.NewDust(vector33, 1, 1, num249, 0f, 0f, 0, default, 2.5f); - Main.dust[num448].position = vector33; - Main.dust[num448].velocity *= 0.1f; - } - return; - } + projectile.localAI[0] += 1f; + if (projectile.localAI[0] > 9f) + { + Dust.NewDust(projectile.position, 1, 1, 206, 0f, 0f, 0, default, 2.5f); + } } } } diff --git a/Projectiles/Magic/Phantom.cs b/Projectiles/Magic/Phantom.cs index efeb3d27ef..4d2e505da1 100644 --- a/Projectiles/Magic/Phantom.cs +++ b/Projectiles/Magic/Phantom.cs @@ -25,53 +25,15 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - Lighting.AddLight(projectile.Center, (255 - projectile.alpha) * 0.2f / 255f, (255 - projectile.alpha) * 0.2f / 255f, (255 - projectile.alpha) * 0.2f / 255f); + Lighting.AddLight(projectile.Center, 0.2f, 0.2f, 0.2f); + for (int num457 = 0; num457 < 5; num457++) { int num458 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 175, 0f, 0f, 100, default, 1f); Main.dust[num458].noGravity = true; - Main.dust[num458].velocity *= 0.5f; - Main.dust[num458].velocity += projectile.velocity * 0.1f; } - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 800f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 30f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 800f, 30f, 20f); } } } diff --git a/Projectiles/Magic/PoseidonTyphoon.cs b/Projectiles/Magic/PoseidonTyphoon.cs index 0d041730ef..784e6f3dc4 100644 --- a/Projectiles/Magic/PoseidonTyphoon.cs +++ b/Projectiles/Magic/PoseidonTyphoon.cs @@ -27,44 +27,7 @@ namespace CalamityMod.Projectiles.Magic { projectile.rotation += projectile.velocity.X * 0.05f; - float centerX = projectile.Center.X; - float centerY = projectile.Center.Y; - float distance = 600f; - bool homeIn = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - centerX = Main.npc[num475].Center.X; - centerY = Main.npc[num475].Center.Y; - homeIn = true; - } - } - } - - if (homeIn) - { - float num483 = 6f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = centerX - vector35.X; - float num485 = centerY - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 30f + num484) / 31f; - projectile.velocity.Y = (projectile.velocity.Y * 30f + num485) / 31f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 600f, 6f, 30f); } public override void Kill(int timeLeft) diff --git a/Projectiles/Magic/SoulPiercerBolt.cs b/Projectiles/Magic/SoulPiercerBolt.cs index 6724370c68..af7215af00 100644 --- a/Projectiles/Magic/SoulPiercerBolt.cs +++ b/Projectiles/Magic/SoulPiercerBolt.cs @@ -29,7 +29,6 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 173, 0f, 0f, 0, default, 0.5f); Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.007f; diff --git a/Projectiles/Magic/TearsofHeavenProjectile.cs b/Projectiles/Magic/TearsofHeavenProjectile.cs index e5cff7ccab..b00d2bca3f 100644 --- a/Projectiles/Magic/TearsofHeavenProjectile.cs +++ b/Projectiles/Magic/TearsofHeavenProjectile.cs @@ -37,6 +37,7 @@ namespace CalamityMod.Projectiles.Magic if (projectile.alpha < 0) projectile.alpha = 0; } + projectile.localAI[0] += 1f; if (projectile.localAI[0] > 4f) { @@ -48,44 +49,8 @@ namespace CalamityMod.Projectiles.Magic Main.dust[num102].noGravity = true; } - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 500f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 500f, 8f, 20f); - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 8f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } projectile.rotation += 0.3f * (float)projectile.direction; } diff --git a/Projectiles/Magic/TerraBeam.cs b/Projectiles/Magic/TerraBeam.cs index ad1f356bfa..117263b18e 100644 --- a/Projectiles/Magic/TerraBeam.cs +++ b/Projectiles/Magic/TerraBeam.cs @@ -27,8 +27,9 @@ namespace CalamityMod.Projectiles.Magic if (projectile.localAI[1] >= 21f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.7), projectile.knockBack, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.7), projectile.knockBack, projectile.owner, 0f, 0f); } + projectile.localAI[0] += 1f; if (projectile.localAI[0] > 9f) { @@ -36,11 +37,9 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 107, 0f, 0f, 0, default, 1.25f); Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } } } diff --git a/Projectiles/Magic/TerraBolt.cs b/Projectiles/Magic/TerraBolt.cs index 173432e4aa..a774f4c152 100644 --- a/Projectiles/Magic/TerraBolt.cs +++ b/Projectiles/Magic/TerraBolt.cs @@ -26,22 +26,17 @@ namespace CalamityMod.Projectiles.Magic if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.7), projectile.knockBack, projectile.owner, 0f, 0f); - } - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 2; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 107, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(projectile.damage * 0.7), projectile.knockBack, projectile.owner, 0f, 0f); } + + for (int num447 = 0; num447 < 2; num447++) + { + Vector2 vector33 = projectile.position; + vector33 -= projectile.velocity * ((float)num447 * 0.25f); + int num448 = Dust.NewDust(vector33, 1, 1, 107, 0f, 0f, 0, default, 1.25f); + Main.dust[num448].position = vector33; + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) diff --git a/Projectiles/Magic/TerraBolt2.cs b/Projectiles/Magic/TerraBolt2.cs index 606061c020..d917253e5d 100644 --- a/Projectiles/Magic/TerraBolt2.cs +++ b/Projectiles/Magic/TerraBolt2.cs @@ -20,23 +20,11 @@ namespace CalamityMod.Projectiles.Magic projectile.magic = true; } - public override void AI() - { - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 9f) - { - for (int num447 = 0; num447 < 1; num447++) - { - Vector2 vector33 = projectile.position; - vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; - int num448 = Dust.NewDust(vector33, 1, 1, 107, 0f, 0f, 0, default, 1.25f); - Main.dust[num448].position = vector33; - Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; - } - } - } + public override void AI() + { + int num448 = Dust.NewDust(projectile.position, 1, 1, 107, 0f, 0f, 0, default, 1.25f); + Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; + } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { diff --git a/Projectiles/Magic/TerraOrb.cs b/Projectiles/Magic/TerraOrb.cs index b47ac56675..8ba63efb91 100644 --- a/Projectiles/Magic/TerraOrb.cs +++ b/Projectiles/Magic/TerraOrb.cs @@ -24,70 +24,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 24f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) diff --git a/Projectiles/Magic/TerraOrb2.cs b/Projectiles/Magic/TerraOrb2.cs index 3c605d7934..4489cadfde 100644 --- a/Projectiles/Magic/TerraOrb2.cs +++ b/Projectiles/Magic/TerraOrb2.cs @@ -24,70 +24,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 18f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 18f, 5, ModContent.ProjectileType()); } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) diff --git a/Projectiles/Magic/UndinesRetributionSpear.cs b/Projectiles/Magic/UndinesRetributionSpear.cs index e41b296ff5..2d8c38c196 100644 --- a/Projectiles/Magic/UndinesRetributionSpear.cs +++ b/Projectiles/Magic/UndinesRetributionSpear.cs @@ -70,44 +70,7 @@ namespace CalamityMod.Projectiles.Magic return; } - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = 600f; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 9f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 600f, 9f, 20f); } else { diff --git a/Projectiles/Magic/VisceraBeam.cs b/Projectiles/Magic/VisceraBeam.cs index d42f04c73b..82318b95b0 100644 --- a/Projectiles/Magic/VisceraBeam.cs +++ b/Projectiles/Magic/VisceraBeam.cs @@ -71,11 +71,9 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 5, 0f, 0f, 0, default, 1f); Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } } } diff --git a/Projectiles/Magic/VividBeam.cs b/Projectiles/Magic/VividBeam.cs index e33121670d..252cfd0cb9 100644 --- a/Projectiles/Magic/VividBeam.cs +++ b/Projectiles/Magic/VividBeam.cs @@ -55,12 +55,10 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1f); Main.dust[num448].noGravity = true; Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } } diff --git a/Projectiles/Magic/VividBolt.cs b/Projectiles/Magic/VividBolt.cs index b4130059e1..57eb497765 100644 --- a/Projectiles/Magic/VividBolt.cs +++ b/Projectiles/Magic/VividBolt.cs @@ -54,12 +54,10 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1f); Main.dust[num448].noGravity = true; Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.0065f; - Main.dust[num448].velocity *= 0.2f; } } } diff --git a/Projectiles/Magic/VividClarityBeam.cs b/Projectiles/Magic/VividClarityBeam.cs index 63e76a1d48..5ec2ac16d2 100644 --- a/Projectiles/Magic/VividClarityBeam.cs +++ b/Projectiles/Magic/VividClarityBeam.cs @@ -48,12 +48,14 @@ namespace CalamityMod.Projectiles.Magic Main.dust[num42].velocity = projectile.velocity; } } + projectile.localAI[1] += 1f; if (projectile.localAI[1] >= 29f && projectile.owner == Main.myPlayer) { projectile.localAI[1] = 0f; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.35f, projectile.velocity.Y * 0.35f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); } + projectile.localAI[0] += 1f; if (projectile.localAI[0] > 4f) { @@ -61,12 +63,10 @@ namespace CalamityMod.Projectiles.Magic { Vector2 vector33 = projectile.position; vector33 -= projectile.velocity * ((float)num447 * 0.25f); - projectile.alpha = 255; int num448 = Dust.NewDust(vector33, 1, 1, 66, 0f, 0f, 0, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1f); Main.dust[num448].noGravity = true; Main.dust[num448].position = vector33; Main.dust[num448].scale = (float)Main.rand.Next(70, 110) * 0.013f; - Main.dust[num448].velocity *= 0.2f; } } } diff --git a/Projectiles/Magic/VividLaser2.cs b/Projectiles/Magic/VividLaser2.cs index efb9ed4047..7fa4d31b8e 100644 --- a/Projectiles/Magic/VividLaser2.cs +++ b/Projectiles/Magic/VividLaser2.cs @@ -39,45 +39,12 @@ namespace CalamityMod.Projectiles.Magic Main.dust[num42].position = projectile.Center + value8; Main.dust[num42].velocity = projectile.velocity; } + if (projectile.timeLeft < 110) projectile.ai[0] = 1f; - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float num474 = 400f; - bool flag17 = false; + if (projectile.ai[0] >= 1f) - { - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false) && Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1)) - { - float num476 = Main.npc[num475].position.X + (float)(Main.npc[num475].width / 2); - float num477 = Main.npc[num475].position.Y + (float)(Main.npc[num475].height / 2); - float num478 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num476) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num477); - if (num478 < num474) - { - num474 = num478; - num472 = num476; - num473 = num477; - flag17 = true; - } - } - } - if (flag17) - { - float num483 = 30f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - return; - } - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, 400f, 30f, 20f); } public override void Kill(int timeLeft) diff --git a/Projectiles/Magic/VividOrb.cs b/Projectiles/Magic/VividOrb.cs index 20a3b8c5e2..711da6215c 100644 --- a/Projectiles/Magic/VividOrb.cs +++ b/Projectiles/Magic/VividOrb.cs @@ -26,70 +26,7 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { - projectile.velocity.X *= 1.01f; - projectile.velocity.Y *= 1.01f; - if (projectile.ai[0] == 0f) - { - projectile.ai[0] = projectile.velocity.X; - projectile.ai[1] = projectile.velocity.Y; - } - if (Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y)) > 2.0) - { - projectile.velocity *= 0.98f; - } - - int[] array = new int[20]; - int num428 = 0; - float distance = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) - { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num430].width / 2) + (float)(Main.npc[num430].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num430].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; - } - } - } - - if (flag14) - { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + (float)(Main.npc[num434].width / 2); - float num436 = Main.npc[num434].position.Y + (float)(Main.npc[num434].height / 2); - projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 24f) - { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt((double)(num438 * num438 + num439 * num439)); - num440 = num437 / num440; - num438 *= num440; - num439 *= num440; - if (projectile.owner == Main.myPlayer) - { - Projectile.NewProjectile(value10.X, value10.Y, num438, num439, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - } - } + CalamityGlobalProjectile.MagnetSphereHitscan(projectile, 300f, 6f, 24f, 5, ModContent.ProjectileType()); } } } diff --git a/Projectiles/Magic/WhiteFlame2.cs b/Projectiles/Magic/WhiteFlame2.cs index 0001aff866..ab9f5a372d 100644 --- a/Projectiles/Magic/WhiteFlame2.cs +++ b/Projectiles/Magic/WhiteFlame2.cs @@ -31,53 +31,15 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { Lighting.AddLight(projectile.Center, (255 - projectile.alpha) * 0.5f / 255f, (255 - projectile.alpha) * 0.5f / 255f, (255 - projectile.alpha) * 0.5f / 255f); + for (int num457 = 0; num457 < 5; num457++) { int num458 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 91, 0f, 0f, 100, default, 0.5f); Main.dust[num458].noGravity = true; - Main.dust[num458].velocity *= 0.5f; - Main.dust[num458].velocity += projectile.velocity * 0.1f; } homeTimer += 5f; - float num472 = projectile.Center.X; - float num473 = projectile.Center.Y; - float distance = homeTimer; - bool flag17 = false; - for (int num475 = 0; num475 < 200; num475++) - { - if (Main.npc[num475].CanBeChasedBy(projectile, false)) - { - float extraDistance = (float)(Main.npc[num475].width / 2) + (float)(Main.npc[num475].height / 2); - - bool useCollisionDetection = extraDistance < distance; - bool canHit = true; - if (useCollisionDetection) - canHit = Collision.CanHit(projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1); - - if (Vector2.Distance(Main.npc[num475].Center, projectile.Center) < (distance + extraDistance) && canHit) - { - distance = Vector2.Distance(Main.npc[num475].Center, projectile.Center); - num472 = Main.npc[num475].Center.X; - num473 = Main.npc[num475].Center.Y; - flag17 = true; - } - } - } - - if (flag17) - { - float num483 = 25f; - Vector2 vector35 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f); - float num484 = num472 - vector35.X; - float num485 = num473 - vector35.Y; - float num486 = (float)Math.Sqrt((double)(num484 * num484 + num485 * num485)); - num486 = num483 / num486; - num484 *= num486; - num485 *= num486; - projectile.velocity.X = (projectile.velocity.X * 20f + num484) / 21f; - projectile.velocity.Y = (projectile.velocity.Y * 20f + num485) / 21f; - } + CalamityGlobalProjectile.HomeInOnNPC(projectile, false, homeTimer, 25f, 20f); } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)