using System; using System.Collections.Generic; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { public class Nuke : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Ranged"; public int flarePowderTimer = 12; private ref float RocketType => ref Projectile.ai[0]; public override void SetStaticDefaults() { Main.projFrames[Projectile.type] = 3; ProjectileID.Sets.TrailCacheLength[Projectile.type] = 3; ProjectileID.Sets.TrailingMode[Projectile.type] = 0; } public override void SetDefaults() { Projectile.width = 22; Projectile.height = 22; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.penetrate = 1; Projectile.timeLeft = 125; Projectile.DamageType = DamageClass.Ranged; } public override void AI() { //Animation Projectile.frameCounter++; if (Projectile.frameCounter > 7) { Projectile.frame++; Projectile.frameCounter = 0; } if (Projectile.frame > 2) { Projectile.frame = 0; } //Rotation Projectile.spriteDirection = Projectile.direction = (Projectile.velocity.X > 0).ToDirectionInt(); Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == 1 ? 0f : MathHelper.Pi) + MathHelper.ToRadians(90) * Projectile.direction; flarePowderTimer--; if (flarePowderTimer <= 0) { if (Projectile.owner == Main.myPlayer) { Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(Projectile.damage * 0.75), Projectile.knockBack, Projectile.owner, 0f, 0f); } flarePowderTimer = 6; } if (Math.Abs(Projectile.velocity.X) >= 8f || Math.Abs(Projectile.velocity.Y) >= 8f) { float halfX = Projectile.velocity.X * 0.5f; float halfY = Projectile.velocity.Y * 0.5f; int dust = Dust.NewDust(new Vector2(Projectile.position.X + 3f + halfX, Projectile.position.Y + 3f + halfY) - Projectile.velocity * 0.5f, Projectile.width - 8, Projectile.height - 8, DustID.CopperCoin, 0f, 0f, 100, default, 1f); Main.dust[dust].scale *= 2f + (float)Main.rand.Next(10) * 0.1f; Main.dust[dust].velocity *= 0.2f; Main.dust[dust].noGravity = true; dust = Dust.NewDust(new Vector2(Projectile.position.X + 3f + halfX, Projectile.position.Y + 3f + halfY) - Projectile.velocity * 0.5f, Projectile.width - 8, Projectile.height - 8, DustID.CopperCoin, 0f, 0f, 100, default, 0.5f); Main.dust[dust].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f; Main.dust[dust].velocity *= 0.05f; } if (RocketType == ItemID.DryRocket || RocketType == ItemID.WetRocket || RocketType == ItemID.LavaRocket || RocketType == ItemID.HoneyRocket) { Projectile.ignoreWater = false; if (Projectile.wet) Projectile.timeLeft = 1; } } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { target.AddBuff(ModContent.BuffType(), 300); Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(Projectile.damage * 0.33), Projectile.knockBack, Projectile.owner, 0f, 2f); } public override void OnHitPlayer(Player target, Player.HurtInfo info) { target.AddBuff(ModContent.BuffType(), 300); Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(Projectile.damage * 0.33), Projectile.knockBack, Projectile.owner, 0f, 2f); } public override void OnKill(int timeLeft) { Projectile.ExpandHitboxBy(192); Projectile.maxPenetrate = -1; Projectile.penetrate = -1; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 10; Projectile.Damage(); SoundEngine.PlaySound(SoundID.Item14, Projectile.position); for (int i = 0; i < 40; i++) { int idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.CopperCoin, 0f, 0f, 100, default, 2f); Main.dust[idx].velocity *= 3f; if (Main.rand.NextBool()) { Main.dust[idx].scale = 0.5f; Main.dust[idx].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; } } for (int i = 0; i < 60; i++) { int idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.CopperCoin, 0f, 0f, 100, default, 3f); Main.dust[idx].noGravity = true; Main.dust[idx].velocity *= 5f; idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.CopperCoin, 0f, 0f, 100, default, 2f); Main.dust[idx].velocity *= 2f; } if (Main.netMode != NetmodeID.Server) { Vector2 goreSource = Projectile.Center; int goreAmt = 10; Vector2 source = new Vector2(goreSource.X - 24f, goreSource.Y - 24f); for (int goreIndex = 0; goreIndex < goreAmt; goreIndex++) { float velocityMult = 0.33f; if (goreIndex < (goreAmt / 3)) { velocityMult = 0.66f; } if (goreIndex >= (2 * goreAmt / 3)) { velocityMult = 1f; } Mod mod = ModContent.GetInstance(); int type = Main.rand.Next(61, 64); int smoke = Gore.NewGore(Projectile.GetSource_Death(), source, default, type, 1f); Gore gore = Main.gore[smoke]; gore.velocity *= velocityMult; gore.velocity.X += 1f; gore.velocity.Y += 1f; type = Main.rand.Next(61, 64); smoke = Gore.NewGore(Projectile.GetSource_Death(), source, default, type, 1f); gore = Main.gore[smoke]; gore.velocity *= velocityMult; gore.velocity.X -= 1f; gore.velocity.Y += 1f; type = Main.rand.Next(61, 64); smoke = Gore.NewGore(Projectile.GetSource_Death(), source, default, type, 1f); gore = Main.gore[smoke]; gore.velocity *= velocityMult; gore.velocity.X += 1f; gore.velocity.Y -= 1f; type = Main.rand.Next(61, 64); smoke = Gore.NewGore(Projectile.GetSource_Death(), source, default, type, 1f); gore = Main.gore[smoke]; gore.velocity *= velocityMult; gore.velocity.X -= 1f; gore.velocity.Y -= 1f; } } // Only do rocket effects for the owner client side if (Projectile.owner != Main.myPlayer) return; int blastRadius = 0; if (RocketType == ItemID.RocketII) blastRadius = 6; else if (RocketType == ItemID.RocketIV) blastRadius = 12; else if (RocketType == ItemID.MiniNukeII) blastRadius = 18; Projectile.ExpandHitboxBy(22); if (blastRadius > 0) Projectile.ExplodeTiles(blastRadius); Point center = Projectile.Center.ToTileCoordinates(); DelegateMethods.v2_1 = center.ToVector2(); DelegateMethods.f_1 = 4f; if (RocketType == ItemID.DryRocket) { DelegateMethods.f_1 = 4.5f; Utils.PlotTileArea(center.X, center.Y, DelegateMethods.SpreadDry); } else if (RocketType == ItemID.WetRocket) { Utils.PlotTileArea(center.X, center.Y, DelegateMethods.SpreadWater); } else if (RocketType == ItemID.LavaRocket) { Utils.PlotTileArea(center.X, center.Y, DelegateMethods.SpreadLava); } else if (RocketType == ItemID.HoneyRocket) { Utils.PlotTileArea(center.X, center.Y, DelegateMethods.SpreadHoney); } } public override bool PreDraw(ref Color lightColor) { CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); return false; } } }