From ce41e753a500fdec705da4e25dee4f2d4d317bb5 Mon Sep 17 00:00:00 2001 From: termigator1359 <45545085+termigator1359@users.noreply.github.com> Date: Sun, 26 Apr 2020 23:19:47 -0400 Subject: [PATCH] feather knife and eclipse stealth proj refactoring --- Projectiles/Rogue/EclipsesStealth.cs | 134 ++------------------ Projectiles/Rogue/FeatherKnifeProjectile.cs | 10 +- 2 files changed, 16 insertions(+), 128 deletions(-) diff --git a/Projectiles/Rogue/EclipsesStealth.cs b/Projectiles/Rogue/EclipsesStealth.cs index 924dcfb246..4cfa10ab98 100644 --- a/Projectiles/Rogue/EclipsesStealth.cs +++ b/Projectiles/Rogue/EclipsesStealth.cs @@ -9,7 +9,7 @@ namespace CalamityMod.Projectiles.Rogue { public class EclipsesStealth : ModProjectile { - private int deadinside = 0; //used to know when to drop spears from the sky + private bool changedTimeLeft = false; public override void SetStaticDefaults() { @@ -34,11 +34,9 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { - deadinside++; //congrats Pinkie - if (deadinside >= 5) //every 5 ticks + if (projectile.timeLeft % 5 == 0) //congrats Pinkie... every 5 ticks { - deadinside = 0; - if (Main.rand.Next(2) == 0) + if (Main.rand.NextBool(2)) { int spearAmt = Main.rand.Next(1, 4); //1 to 3 spears for (int n = 0; n < spearAmt; n++) @@ -54,136 +52,30 @@ namespace CalamityMod.Projectiles.Rogue num16 = (float)num15 / num16; num13 *= num16; num14 *= num16; - Projectile.NewProjectile(x, y, num13, num14, ModContent.ProjectileType(), (int)((double)projectile.damage * 0.08 * Main.rand.Next(4, 7)), (int)((double)projectile.knockBack * 0.1 * Main.rand.Next(7, 10)), projectile.owner, 0f, 0f); + Projectile.NewProjectile(x, y, num13, num14, ModContent.ProjectileType(), (int)(projectile.damage * Main.rand.NextFloat(0.32f, 0.56f)), projectile.knockBack * Main.rand.NextFloat(0.32f, 0.56f), projectile.owner, 0f, 0f); } //very complicated and painful } } if (projectile.ai[0] == 0f) { projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 0.785f; - if (Main.rand.Next(8) == 0) //dust + if (Main.rand.NextBool(8)) //dust { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 138, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); } } - if (projectile.ai[0] == 1f) //sticking to enemies - { - int num988 = 15; - bool flag54 = false; - bool flag55 = false; - projectile.localAI[0] += 1f; - if (projectile.localAI[0] % 30f == 0f) - { - flag55 = true; - } - int num989 = (int)projectile.ai[1]; - if (projectile.localAI[0] >= (float)(60 * num988)) - { - flag54 = true; - } - else if (num989 < 0 || num989 >= 200) - { - flag54 = true; - } - else if (Main.npc[num989].active && !Main.npc[num989].dontTakeDamage) - { - projectile.Center = Main.npc[num989].Center - projectile.velocity * 2f; - projectile.gfxOffY = Main.npc[num989].gfxOffY; - if (flag55) - { - Main.npc[num989].HitEffect(0, 1.0); - } - } - else - { - flag54 = true; - } - if (flag54) - { - projectile.Kill(); - } - } + if (projectile.ai[0] == 1f && !changedTimeLeft) + { + projectile.timeLeft = 900; + changedTimeLeft = true; + } + //Sticky Behaviour + CalamityUtils.StickyProjAI(projectile, 15); } - #region SpearBarrage - public void SpearBarrage(Player player) - { - } - #endregion - public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) { - Rectangle myRect = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height); - if (projectile.owner == Main.myPlayer) - { - for (int i = 0; i < 200; i++) - { - if (Main.npc[i].active && !Main.npc[i].dontTakeDamage && - ((projectile.friendly && (!Main.npc[i].friendly || projectile.type == 318 || (Main.npc[i].type == 22 && projectile.owner < 255 && Main.player[projectile.owner].killGuide) || (Main.npc[i].type == 54 && projectile.owner < 255 && Main.player[projectile.owner].killClothier))) || - (projectile.hostile && Main.npc[i].friendly && !Main.npc[i].dontTakeDamageFromHostiles)) && (projectile.owner < 0 || Main.npc[i].immune[projectile.owner] == 0 || projectile.maxPenetrate == 1)) - { - if (Main.npc[i].noTileCollide || !projectile.ownerHitCheck || projectile.CanHit(Main.npc[i])) - { - bool flag3; - if (Main.npc[i].type == 414) - { - Rectangle rect = Main.npc[i].getRect(); - int num5 = 8; - rect.X -= num5; - rect.Y -= num5; - rect.Width += num5 * 2; - rect.Height += num5 * 2; - flag3 = projectile.Colliding(myRect, rect); - } - else - { - flag3 = projectile.Colliding(myRect, Main.npc[i].getRect()); - } - if (flag3) - { - if (Main.npc[i].reflectingProjectiles && projectile.CanReflect()) - { - Main.npc[i].ReflectProjectile(projectile.whoAmI); - return; - } - projectile.ai[0] = 1f; - projectile.timeLeft = 900; //increase lifetime if sticking to something - projectile.ai[1] = (float)i; - projectile.velocity = (Main.npc[i].Center - projectile.Center) * 0.75f; - projectile.netUpdate = true; - projectile.StatusNPC(i); - //projectile.damage = 0; //aaaaaaa - int num28 = 1; - Point[] array2 = new Point[num28]; - int num29 = 0; - for (int l = 0; l < 1000; l++) - { - if (l != projectile.whoAmI && Main.projectile[l].active && Main.projectile[l].owner == Main.myPlayer && Main.projectile[l].type == projectile.type && Main.projectile[l].ai[0] == 1f && Main.projectile[l].ai[1] == (float)i) - { - array2[num29++] = new Point(l, Main.projectile[l].timeLeft); - if (num29 >= array2.Length) - { - break; - } - } - } - if (num29 >= array2.Length) - { - int num30 = 0; - for (int m = 1; m < array2.Length; m++) - { - if (array2[m].Y < array2[num30].Y) - { - num30 = m; - } - } - Main.projectile[array2[num30].X].Kill(); - } - } - } - } - } - } + CalamityUtils.ModifyHitNPCSticky(projectile, 1, true); } public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) diff --git a/Projectiles/Rogue/FeatherKnifeProjectile.cs b/Projectiles/Rogue/FeatherKnifeProjectile.cs index 33fe5ad8c2..8c088e0300 100644 --- a/Projectiles/Rogue/FeatherKnifeProjectile.cs +++ b/Projectiles/Rogue/FeatherKnifeProjectile.cs @@ -9,8 +9,6 @@ namespace CalamityMod.Projectiles.Rogue { public class FeatherKnifeProjectile : ModProjectile { - private int featherTimer = 35; - public override void SetStaticDefaults() { DisplayName.SetDefault("Knife"); @@ -36,21 +34,19 @@ namespace CalamityMod.Projectiles.Rogue public override void AI() { - if (featherTimer == 0) + if (projectile.timeLeft % 35 == 0) { if (projectile.owner == Main.myPlayer) { - int proj = Projectile.NewProjectile(projectile.position, new Vector2(projectile.velocity.X / 20, 2), ModContent.ProjectileType(), (int)((double)projectile.damage * 0.4), projectile.knockBack, projectile.owner); + int proj = Projectile.NewProjectile(projectile.position, new Vector2(projectile.velocity.X / 20, 2), ModContent.ProjectileType(), (int)(projectile.damage * 0.4), projectile.knockBack, projectile.owner); Main.projectile[proj].Calamity().forceRogue = true; } - featherTimer = 35; } - featherTimer--; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { - int proj = Projectile.NewProjectile(projectile.position, new Vector2(projectile.velocity.X / 20, 2), ModContent.ProjectileType(), (int)((double)projectile.damage * 0.69), projectile.knockBack, projectile.owner); + int proj = Projectile.NewProjectile(projectile.position, new Vector2(projectile.velocity.X / 20, 2), ModContent.ProjectileType(), (int)(projectile.damage * 0.69), projectile.knockBack, projectile.owner); Main.projectile[proj].Calamity().forceRogue = true; }