From 0da4d317bc240faeba4b5e1cabd506caccc17d62 Mon Sep 17 00:00:00 2001 From: SheerExpanse Date: Sun, 14 Jul 2019 00:41:34 -0400 Subject: [PATCH] Nanoblack Reaper sub-blade rework --- Projectiles/Melee/NanoblackMainMelee.cs | 148 +++++++++++++---------- Projectiles/Melee/NanoblackSplitMelee.cs | 24 ++-- Projectiles/Rogue/NanoblackMainRogue.cs | 55 +++++---- Projectiles/Rogue/NanoblackSplitRogue.cs | 25 ++-- 4 files changed, 141 insertions(+), 111 deletions(-) diff --git a/Projectiles/Melee/NanoblackMainMelee.cs b/Projectiles/Melee/NanoblackMainMelee.cs index 70835b19c2..5d4b440415 100644 --- a/Projectiles/Melee/NanoblackMainMelee.cs +++ b/Projectiles/Melee/NanoblackMainMelee.cs @@ -10,7 +10,9 @@ namespace CalamityMod.Projectiles.Melee { private static float RotationIncrement = 0.22f; private static int Lifetime = 240; - private static float ReboundTime = 50f; + private static float ReboundTime = 50f; + private static int MinBladeTimer = 13; + private static int MaxBladeTimer = 18; public override void SetStaticDefaults() { @@ -30,13 +32,20 @@ namespace CalamityMod.Projectiles.Melee projectile.timeLeft = Lifetime; projectile.usesLocalNPCImmunity = true; projectile.localNPCHitCooldown = 2; - } - + } + public override void AI() { drawOffsetX = -11; drawOriginOffsetY = -4; - drawOriginOffsetX = 0; + drawOriginOffsetX = 0; + + // Initialize the frame counter and random blade delay on the very first frame. + if (projectile.timeLeft == Lifetime) + { + projectile.ai[0] = 0f; + projectile.ai[1] = GetBladeDelay(); + } // Produces electricity and green firework sparks constantly while in flight. if (Main.rand.Next(3) == 0) @@ -48,73 +57,73 @@ namespace CalamityMod.Projectiles.Melee Main.dust[idx].noGravity = true; Main.dust[idx].velocity = velocityMult * projectile.velocity; Main.dust[idx].scale = scale; - } - - // ai[0] stores whether the scythe is returning. If 0, it isn't. If 1, it is. - if (projectile.ai[0] == 0f) - { - projectile.ai[1] += 1f; - if (projectile.ai[1] >= ReboundTime) - { - projectile.ai[0] = 1f; - projectile.ai[1] = 0f; - projectile.netUpdate = true; - } - } - else - { - projectile.tileCollide = false; - float returnSpeed = NanoblackReaperMelee.Speed; - float acceleration = 2.4f; + } + + // ai[0] is a frame counter. ai[1] is a countdown to spawning the next nanoblack energy blade. + projectile.ai[0] += 1f; + projectile.ai[1] -= 1f; + + // On the frame the scythe begins returning, send a net update. + if (projectile.ai[0] == ReboundTime) + projectile.netUpdate = true; + + // The scythe runs its returning AI if the frame counter is greater than ReboundTime. + if (projectile.ai[0] >= ReboundTime) + { + float returnSpeed = NanoblackReaperMelee.Speed; + float acceleration = 2.4f; Player owner = Main.player[projectile.owner]; // Delete the scythe if it's excessively far away. - Vector2 playerCenter = owner.Center; - float xDist = playerCenter.X - projectile.Center.X; - float yDist = playerCenter.Y - projectile.Center.Y; - float dist = (float)Math.Sqrt(xDist * xDist + yDist * yDist); - if (dist > 3000f) - projectile.Kill(); + Vector2 playerCenter = owner.Center; + float xDist = playerCenter.X - projectile.Center.X; + float yDist = playerCenter.Y - projectile.Center.Y; + float dist = (float)Math.Sqrt(xDist * xDist + yDist * yDist); + if (dist > 3000f) + projectile.Kill(); + + dist = returnSpeed / dist; + xDist *= dist; + yDist *= dist; + + // Home back in on the player. + if (projectile.velocity.X < xDist) + { + projectile.velocity.X = projectile.velocity.X + acceleration; + if (projectile.velocity.X < 0f && xDist > 0f) + projectile.velocity.X += acceleration; + } + else if (projectile.velocity.X > xDist) + { + projectile.velocity.X = projectile.velocity.X - acceleration; + if (projectile.velocity.X > 0f && xDist < 0f) + projectile.velocity.X -= acceleration; + } + if (projectile.velocity.Y < yDist) + { + projectile.velocity.Y = projectile.velocity.Y + acceleration; + if (projectile.velocity.Y < 0f && yDist > 0f) + projectile.velocity.Y += acceleration; + } + else if (projectile.velocity.Y > yDist) + { + projectile.velocity.Y = projectile.velocity.Y - acceleration; + if (projectile.velocity.Y > 0f && yDist < 0f) + projectile.velocity.Y -= acceleration; + } + + // Delete the projectile if it touches its owner. + if (Main.myPlayer == projectile.owner) + if (projectile.Hitbox.Intersects(owner.Hitbox)) + projectile.Kill(); + } - dist = returnSpeed / dist; - xDist *= dist; - yDist *= dist; - - // Home back in on the player. - if (projectile.velocity.X < xDist) - { - projectile.velocity.X = projectile.velocity.X + acceleration; - if (projectile.velocity.X < 0f && xDist > 0f) - projectile.velocity.X += acceleration; - } - else if (projectile.velocity.X > xDist) - { - projectile.velocity.X = projectile.velocity.X - acceleration; - if (projectile.velocity.X > 0f && xDist < 0f) - projectile.velocity.X -= acceleration; - } - if (projectile.velocity.Y < yDist) - { - projectile.velocity.Y = projectile.velocity.Y + acceleration; - if (projectile.velocity.Y < 0f && yDist > 0f) - projectile.velocity.Y += acceleration; - } - else if (projectile.velocity.Y > yDist) - { - projectile.velocity.Y = projectile.velocity.Y - acceleration; - if (projectile.velocity.Y > 0f && yDist < 0f) - projectile.velocity.Y -= acceleration; - } - - // Delete the projectile if it touches its owner. - if (Main.myPlayer == projectile.owner) - if (projectile.Hitbox.Intersects(owner.Hitbox)) - projectile.Kill(); - } - - // Create nanoblack energy blades while in flight after a delay. - if(Lifetime - projectile.timeLeft >= 4 && Main.rand.Next(16) == 0) - SpawnEnergyBlade(); + // Create nanoblack energy blades at a somewhat-random rate while in flight. + if (projectile.ai[1] <= 0f) + { + SpawnEnergyBlade(); + projectile.ai[1] = GetBladeDelay(); + } // Rotate the scythe as it flies. float spin = (projectile.direction <= 0) ? -1f : 1f; @@ -122,6 +131,11 @@ namespace CalamityMod.Projectiles.Melee return; } + private int GetBladeDelay() + { + return Main.rand.Next(MinBladeTimer, MaxBladeTimer + 1); + } + private void SpawnEnergyBlade() { int bladeID = mod.ProjectileType("NanoblackSplitMelee"); diff --git a/Projectiles/Melee/NanoblackSplitMelee.cs b/Projectiles/Melee/NanoblackSplitMelee.cs index aa7dd717e0..23116b8978 100644 --- a/Projectiles/Melee/NanoblackSplitMelee.cs +++ b/Projectiles/Melee/NanoblackSplitMelee.cs @@ -10,12 +10,15 @@ namespace CalamityMod.Projectiles.Melee public class NanoblackSplitMelee : ModProjectile { private static int SpriteWidth = 52; - private static float MaxRotationSpeed = 0.25f; - private static int Lifetime = 90; - private static float HomingStartRange = 100f; - private static float HomingBreakRange = 600f; - private static float HomingBonusRange = 100f; - private static float MaxSpeed = 12f; + private static int Lifetime = 90; + private static float MaxRotationSpeed = 0.25f; + private static float MaxSpeed = 22f; + + private static float HomingStartRange = 500f; + private static float HomingBreakRange = 900f; + private static float HomingBonusRangeCap = 200f; + private static float BaseHomingFactor = 1.6f; + private static float MaxHomingFactor = 3.2f; public override void SetStaticDefaults() { @@ -30,7 +33,7 @@ namespace CalamityMod.Projectiles.Melee projectile.melee = true; projectile.ignoreWater = true; projectile.tileCollide = false; - projectile.penetrate = 6; + projectile.penetrate = 4; projectile.extraUpdates = 1; projectile.timeLeft = Lifetime; projectile.usesLocalNPCImmunity = true; @@ -153,12 +156,11 @@ namespace CalamityMod.Projectiles.Melee return target; } - // Energy blades home more aggressively the closer they are to their target. - // The homing factor ranges from 0.6 to 3.6 at point blank. + // Energy blades home even more aggressively if they are very close to their target. private float CalcHomingFactor(float dist) { - float baseFactor = 0.6f; - float bonus = 3f * (1f - dist / HomingBonusRange); + float baseFactor = BaseHomingFactor; + float bonus = (MaxHomingFactor - BaseHomingFactor) * (1f - dist / HomingBonusRangeCap); if (bonus < 0f) bonus = 0f; return baseFactor + bonus; diff --git a/Projectiles/Rogue/NanoblackMainRogue.cs b/Projectiles/Rogue/NanoblackMainRogue.cs index 17fddf73db..d0a25a7d7a 100644 --- a/Projectiles/Rogue/NanoblackMainRogue.cs +++ b/Projectiles/Rogue/NanoblackMainRogue.cs @@ -3,7 +3,6 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ModLoader; using CalamityMod.Items.Weapons; -using CalamityMod.Projectiles; namespace CalamityMod.Projectiles.Rogue { @@ -12,6 +11,8 @@ namespace CalamityMod.Projectiles.Rogue private static float RotationIncrement = 0.22f; private static int Lifetime = 240; private static float ReboundTime = 50f; + private static int MinBladeTimer = 13; + private static int MaxBladeTimer = 18; public override void SetStaticDefaults() { @@ -37,7 +38,14 @@ namespace CalamityMod.Projectiles.Rogue { drawOffsetX = -11; drawOriginOffsetY = -4; - drawOriginOffsetX = 0; + drawOriginOffsetX = 0; + + // Initialize the frame counter and random blade delay on the very first frame. + if (projectile.timeLeft == Lifetime) + { + projectile.ai[0] = 0f; + projectile.ai[1] = GetBladeDelay(); + } // Produces electricity and green firework sparks constantly while in flight. if (Main.rand.Next(3) == 0) @@ -49,22 +57,19 @@ namespace CalamityMod.Projectiles.Rogue Main.dust[idx].noGravity = true; Main.dust[idx].velocity = velocityMult * projectile.velocity; Main.dust[idx].scale = scale; - } - - // ai[0] stores whether the scythe is returning. If 0, it isn't. If 1, it is. - if (projectile.ai[0] == 0f) - { - projectile.ai[1] += 1f; - if (projectile.ai[1] >= ReboundTime) - { - projectile.ai[0] = 1f; - projectile.ai[1] = 0f; - projectile.netUpdate = true; - } - } - else - { - projectile.tileCollide = false; + } + + // ai[0] is a frame counter. ai[1] is a countdown to spawning the next nanoblack energy blade. + projectile.ai[0] += 1f; + projectile.ai[1] -= 1f; + + // On the frame the scythe begins returning, send a net update. + if (projectile.ai[0] == ReboundTime) + projectile.netUpdate = true; + + // The scythe runs its returning AI if the frame counter is greater than ReboundTime. + if (projectile.ai[0] >= ReboundTime) + { float returnSpeed = NanoblackReaperRogue.Speed; float acceleration = 2.4f; Player owner = Main.player[projectile.owner]; @@ -113,14 +118,22 @@ namespace CalamityMod.Projectiles.Rogue projectile.Kill(); } - // Create nanoblack energy blades while in flight after a delay. - if(Lifetime - projectile.timeLeft >= 4 && Main.rand.Next(16) == 0) - SpawnEnergyBlade(); + // Create nanoblack energy blades at a somewhat-random rate while in flight. + if (projectile.ai[1] <= 0f) + { + SpawnEnergyBlade(); + projectile.ai[1] = GetBladeDelay(); + } // Rotate the scythe as it flies. float spin = (projectile.direction <= 0) ? -1f : 1f; projectile.rotation += spin * RotationIncrement; return; + } + + private int GetBladeDelay() + { + return Main.rand.Next(MinBladeTimer, MaxBladeTimer + 1); } private void SpawnEnergyBlade() diff --git a/Projectiles/Rogue/NanoblackSplitRogue.cs b/Projectiles/Rogue/NanoblackSplitRogue.cs index 99a2a9fe24..f9240fa7af 100644 --- a/Projectiles/Rogue/NanoblackSplitRogue.cs +++ b/Projectiles/Rogue/NanoblackSplitRogue.cs @@ -4,19 +4,21 @@ using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; -using CalamityMod.Projectiles; namespace CalamityMod.Projectiles.Rogue { public class NanoblackSplitRogue : ModProjectile { private static int SpriteWidth = 52; - private static float MaxRotationSpeed = 0.25f; - private static int Lifetime = 90; - private static float HomingStartRange = 100f; - private static float HomingBreakRange = 600f; - private static float HomingBonusRange = 100f; - private static float MaxSpeed = 12f; + private static int Lifetime = 90; + private static float MaxRotationSpeed = 0.25f; + private static float MaxSpeed = 22f; + + private static float HomingStartRange = 500f; + private static float HomingBreakRange = 900f; + private static float HomingBonusRangeCap = 200f; + private static float BaseHomingFactor = 1.6f; + private static float MaxHomingFactor = 3.2f; public override void SetStaticDefaults() { @@ -31,7 +33,7 @@ namespace CalamityMod.Projectiles.Rogue projectile.GetGlobalProjectile(mod).rogue = true; projectile.ignoreWater = true; projectile.tileCollide = false; - projectile.penetrate = 6; + projectile.penetrate = 4; projectile.extraUpdates = 1; projectile.timeLeft = Lifetime; projectile.usesLocalNPCImmunity = true; @@ -154,12 +156,11 @@ namespace CalamityMod.Projectiles.Rogue return target; } - // Energy blades home more aggressively the closer they are to their target. - // The homing factor ranges from 0.6 to 3.6 at point blank. + // Energy blades home even more aggressively if they are very close to their target. private float CalcHomingFactor(float dist) { - float baseFactor = 0.6f; - float bonus = 3f * (1f - dist / HomingBonusRange); + float baseFactor = BaseHomingFactor; + float bonus = (MaxHomingFactor - BaseHomingFactor) * (1f - dist / HomingBonusRangeCap); if (bonus < 0f) bonus = 0f; return baseFactor + bonus;