From 83140f3d44a38f38fc3409751504704cc3837726 Mon Sep 17 00:00:00 2001 From: termigator1359 <45545085+termigator1359@users.noreply.github.com> Date: Mon, 23 Nov 2020 13:16:15 -0500 Subject: [PATCH] cleaned up Terra Disk code --- Projectiles/Rogue/AccretionDiskProj.cs | 6 +- Projectiles/Rogue/TerraDiskProjectile.cs | 80 ++++++++++-------------- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/Projectiles/Rogue/AccretionDiskProj.cs b/Projectiles/Rogue/AccretionDiskProj.cs index 4ab27f7b64..3206416831 100644 --- a/Projectiles/Rogue/AccretionDiskProj.cs +++ b/Projectiles/Rogue/AccretionDiskProj.cs @@ -85,10 +85,8 @@ namespace CalamityMod.Projectiles.Rogue for (int i = 0; i < 4; i++) { offsetAngle = startAngle + deltaAngle * (i + i * i) / 2f + 32f * i; - int disk = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), splitProj, projectile.damage, projectile.knockBack, projectile.owner); - Main.projectile[disk].Calamity().forceRogue = true; - int disk2 = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), splitProj, projectile.damage, projectile.knockBack, projectile.owner); - Main.projectile[disk2].Calamity().forceRogue = true; + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), splitProj, projectile.damage, projectile.knockBack, projectile.owner); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), splitProj, projectile.damage, projectile.knockBack, projectile.owner); } } } diff --git a/Projectiles/Rogue/TerraDiskProjectile.cs b/Projectiles/Rogue/TerraDiskProjectile.cs index 14ea002e19..1ebf13ae8e 100644 --- a/Projectiles/Rogue/TerraDiskProjectile.cs +++ b/Projectiles/Rogue/TerraDiskProjectile.cs @@ -20,16 +20,15 @@ namespace CalamityMod.Projectiles.Rogue public override void SetDefaults() { - projectile.width = 46; - projectile.height = 46; + projectile.width = projectile.height = 46; projectile.friendly = true; projectile.tileCollide = false; projectile.usesLocalNPCImmunity = true; projectile.localNPCHitCooldown = 10; projectile.penetrate = -1; projectile.aiStyle = 3; - projectile.timeLeft = 180; aiType = ProjectileID.WoodenBoomerang; + projectile.timeLeft = 180; projectile.Calamity().rogue = true; } @@ -38,60 +37,49 @@ namespace CalamityMod.Projectiles.Rogue Lighting.AddLight(projectile.Center, 0f, (255 - projectile.alpha) * 0.75f / 255f, 0f); if (Main.rand.NextBool(5)) Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 107, projectile.velocity.X, projectile.velocity.Y); - int[] array = new int[20]; - int num428 = 0; - float num429 = 300f; - bool flag14 = false; - for (int num430 = 0; num430 < 200; num430++) + + float maxDistance = 300f; + bool homeIn = false; + + for (int i = 0; i < Main.maxNPCs; i++) { - if (Main.npc[num430].CanBeChasedBy(projectile, false)) + NPC npc = Main.npc[i]; + if (npc.CanBeChasedBy(projectile, false)) { - float num431 = Main.npc[num430].position.X + Main.npc[num430].width / 2; - float num432 = Main.npc[num430].position.Y + Main.npc[num430].height / 2; - float num433 = Math.Abs(projectile.position.X + projectile.width / 2 - num431) + Math.Abs(projectile.position.Y + projectile.height / 2 - num432); - if (num433 < num429 && Collision.CanHit(projectile.Center, 1, 1, Main.npc[num430].Center, 1, 1)) + float extraDistance = npc.width / 2 + npc.height / 2; + + bool canHit = true; + if (extraDistance < maxDistance) + canHit = Collision.CanHit(projectile.Center, 1, 1, npc.Center, 1, 1); + + if (Vector2.Distance(npc.Center, projectile.Center) < maxDistance + extraDistance && canHit) { - if (num428 < 20) - { - array[num428] = num430; - num428++; - } - flag14 = true; + homeIn = true; + break; } } } - if (flag14) + + if (!projectile.friendly) + homeIn = false; + + if (homeIn) { - int num434 = Main.rand.Next(num428); - num434 = array[num434]; - float num435 = Main.npc[num434].position.X + Main.npc[num434].width / 2; - float num436 = Main.npc[num434].position.Y + Main.npc[num434].height / 2; projectile.localAI[0] += 1f; - if (projectile.localAI[0] > 8f) + if (projectile.localAI[0] % 8f == 0f && Main.rand.NextBool(5)) { - projectile.localAI[0] = 0f; - float num437 = 6f; - Vector2 value10 = new Vector2(projectile.position.X + projectile.width * 0.5f, projectile.position.Y + projectile.height * 0.5f); - value10 += projectile.velocity * 4f; - float num438 = num435 - value10.X; - float num439 = num436 - value10.Y; - float num440 = (float)Math.Sqrt(num438 * num438 + num439 * num439); - num440 = num437 / num440; - if (Main.rand.NextBool(5)) + int splitProj = ModContent.ProjectileType(); + if (projectile.owner == Main.myPlayer) { - if (projectile.owner == Main.myPlayer) + float spread = 60f * 0.0174f; + double startAngle = Math.Atan2(projectile.velocity.X, projectile.velocity.Y) - spread / 2; + double deltaAngle = spread / 6f; + double offsetAngle; + for (int i = 0; i < 3; i++) { - float spread = 60f * 0.0174f; - double startAngle = Math.Atan2(projectile.velocity.X, projectile.velocity.Y) - spread / 2; - double deltaAngle = spread / 6f; - double offsetAngle; - int i; - for (i = 0; i < 3; i++) - { - offsetAngle = startAngle + deltaAngle * (i + i * i) / 2f + 32f * i; - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), ModContent.ProjectileType(), projectile.damage / 2, projectile.knockBack, projectile.owner, 0f, 0f); - } + offsetAngle = startAngle + deltaAngle * (i + i * i) / 2f + 32f * i; + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), splitProj, projectile.damage / 2, projectile.knockBack / 2f, projectile.owner); + Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), splitProj, projectile.damage / 2, projectile.knockBack / 2f, projectile.owner); } } }