From fe923732d6aae855d5674a394de618b5dfcee2b6 Mon Sep 17 00:00:00 2001 From: ben-tk <45545085+ben-tk@users.noreply.github.com> Date: Thu, 6 Jan 2022 16:14:52 -0500 Subject: [PATCH] Scorched Earth changes as per request --- Projectiles/Ranged/ScorchedEarthBlast.cs | 89 +++++++++++++++++++++++ Projectiles/Ranged/ScorchedEarthRocket.cs | 53 ++++---------- 2 files changed, 103 insertions(+), 39 deletions(-) create mode 100644 Projectiles/Ranged/ScorchedEarthBlast.cs diff --git a/Projectiles/Ranged/ScorchedEarthBlast.cs b/Projectiles/Ranged/ScorchedEarthBlast.cs new file mode 100644 index 0000000000..9f8ebdcdd6 --- /dev/null +++ b/Projectiles/Ranged/ScorchedEarthBlast.cs @@ -0,0 +1,89 @@ +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class ScorchedEarthBlast : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + private static int Lifetime = 20; + private static float ExplosionRadius = 150f; + private static float StartDustQuantity = 36f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Earth Scorcher"); + } + + public override void SetDefaults() + { + // Width and height don't actually do anything because the explosion uses custom collision + projectile.width = projectile.height = 300; + projectile.friendly = true; + projectile.ranged = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.penetrate = -1; + projectile.timeLeft = Lifetime; + + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = -1; + } + + // localAI[0] = frame counter + // localAI[1] = dust quantity + public override void AI() + { + // Play sound on frame 1 and initialize dust quantity + if (projectile.localAI[0] == 0f) + { + projectile.localAI[1] = StartDustQuantity; + } + + // Pure dust projectile + DrawProjectile(); + + // Increment frame counter + projectile.localAI[0] += 1f; + } + + private void DrawProjectile() + { + // Taper down the dust amount for the last bit of the projectile's life + if (projectile.localAI[0] >= Lifetime - 15) + projectile.localAI[1] -= 1f; + + int dustCount = (int)projectile.localAI[1]; + for (int i = 0; i < dustCount; ++i) + { + int dustType = Main.rand.NextBool() ? 6 : 244; + float scale = Main.rand.NextFloat(2.0f, 2.5f); + float randX = Main.rand.NextFloat(-30f, 30f); + float randY = Main.rand.NextFloat(-30f, 30f); + float randVelocity = Main.rand.NextFloat(5f, 19f); + float speed = (float)Math.Sqrt((double)(randX * randX + randY * randY)); + speed = randVelocity / speed; + randX *= speed; + randY *= speed; + int idx = Dust.NewDust(projectile.position, projectile.width, projectile.height, dustType); + Main.dust[idx].position.X = projectile.Center.X + Main.rand.NextFloat(-10f, 10f); + Main.dust[idx].position.Y = projectile.Center.Y + Main.rand.NextFloat(-10f, 10f); + Main.dust[idx].velocity.X = randX; + Main.dust[idx].velocity.Y = randY; + Main.dust[idx].scale = scale; + Main.dust[idx].noGravity = true; + } + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + target.AddBuff(BuffID.Daybreak, 300); + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(projectile.Center, ExplosionRadius, targetHitbox); + } +} diff --git a/Projectiles/Ranged/ScorchedEarthRocket.cs b/Projectiles/Ranged/ScorchedEarthRocket.cs index ca1f046310..c4efbcb0a5 100644 --- a/Projectiles/Ranged/ScorchedEarthRocket.cs +++ b/Projectiles/Ranged/ScorchedEarthRocket.cs @@ -52,51 +52,26 @@ namespace CalamityMod.Projectiles.Ranged //Rotation projectile.rotation = projectile.velocity.ToRotation(); - if (Math.Abs(projectile.velocity.X) >= 8f || Math.Abs(projectile.velocity.Y) >= 8f) - { - float xVel = projectile.velocity.X * 0.5f; - float yVel = projectile.velocity.Y * 0.5f; - int d = Dust.NewDust(new Vector2(projectile.position.X + 3f + xVel, projectile.position.Y + 3f + yVel) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 244, 0f, 0f, 100, default, 1f); - Main.dust[d].scale *= 2f + (float)Main.rand.Next(10) * 0.1f; - Main.dust[d].velocity *= 0.2f; - Main.dust[d].noGravity = true; - d = Dust.NewDust(new Vector2(projectile.position.X + 3f + xVel, projectile.position.Y + 3f + yVel) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 244, 0f, 0f, 100, default, 0.5f); - Main.dust[d].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f; - Main.dust[d].velocity *= 0.05f; - - } + float xVel = projectile.velocity.X * 0.5f; + float yVel = projectile.velocity.Y * 0.5f; + int d = Dust.NewDust(new Vector2(projectile.position.X + 3f + xVel, projectile.position.Y + 3f + yVel) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 244, 0f, 0f, 100, default, 1f); + Main.dust[d].scale *= 2f + (float)Main.rand.Next(10) * 0.1f; + Main.dust[d].velocity *= 0.2f; + Main.dust[d].noGravity = true; + d = Dust.NewDust(new Vector2(projectile.position.X + 3f + xVel, projectile.position.Y + 3f + yVel) - projectile.velocity * 0.5f, projectile.width - 8, projectile.height - 8, 244, 0f, 0f, 100, default, 0.5f); + Main.dust[d].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f; + Main.dust[d].velocity *= 0.05f; } public override void Kill(int timeLeft) { - CalamityGlobalProjectile.ExpandHitboxBy(projectile, 300); - projectile.maxPenetrate = projectile.penetrate = -1; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; - projectile.Damage(); - Main.PlaySound(SoundID.Item14, projectile.position); - for (int i = 0; i < 40; i++) - { - int d = Dust.NewDust(projectile.position, projectile.width, projectile.height, 244, 0f, 0f, 100, default, 2f); - Main.dust[d].velocity *= 3f; - if (Main.rand.NextBool(2)) - { - Main.dust[d].scale = 0.5f; - Main.dust[d].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; - } - } - for (int i = 0; i < 60; i++) - { - int d = Dust.NewDust(projectile.position, projectile.width, projectile.height, 244, 0f, 0f, 100, default, 3f); - Main.dust[d].noGravity = true; - Main.dust[d].velocity *= 5f; - d = Dust.NewDust(projectile.position, projectile.width, projectile.height, 244, 0f, 0f, 100, default, 2f); - Main.dust[d].velocity *= 2f; - } - CalamityUtils.ExplosionGores(projectile.Center, 10); - if (projectile.owner == Main.myPlayer) { + CalamityGlobalProjectile.ExpandHitboxBy(projectile, 300); + Main.PlaySound(SoundID.Item14, projectile.position); + CalamityUtils.ExplosionGores(projectile.Center, 10); + + Projectile.NewProjectile(projectile.Center, Vector2.Zero, ModContent.ProjectileType(), projectile.damage, projectile.knockBack * 2f, projectile.owner); for (int j = 0; j < 5; j++) { Vector2 velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(8f, 10f);