using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Projectiles.Healing; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Melee { public class Exocomet : ModProjectile { public override void SetStaticDefaults() { DisplayName.SetDefault("Comet"); Main.projFrames[projectile.type] = 5; ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; ProjectileID.Sets.TrailingMode[projectile.type] = 0; } public override void SetDefaults() { projectile.width = 12; projectile.height = 12; projectile.friendly = true; projectile.ignoreWater = true; projectile.tileCollide = false; projectile.melee = true; projectile.penetrate = 1; projectile.alpha = 50; projectile.timeLeft = 360; } public override bool? CanHitNPC(NPC target) => projectile.timeLeft < 240 && target.CanBeChasedBy(projectile); public override void AI() { projectile.frameCounter++; if (projectile.frameCounter > 5) { projectile.frame++; projectile.frameCounter = 0; } if (projectile.frame > 4) projectile.frame = 0; if (projectile.timeLeft > 30 && projectile.alpha > 0) projectile.alpha -= 25; if (projectile.timeLeft > 30 && projectile.alpha < 128 && Collision.SolidCollision(projectile.position, projectile.width, projectile.height)) projectile.alpha = 128; if (projectile.alpha < 0) projectile.alpha = 0; if (projectile.alpha < 40) { int num309 = Dust.NewDust(new Vector2(projectile.position.X - projectile.velocity.X * 4f + 2f, projectile.position.Y + 2f - projectile.velocity.Y * 4f), 8, 8, 107, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, new Color(0, 255, 255), 0.5f); Main.dust[num309].velocity *= -0.25f; num309 = Dust.NewDust(new Vector2(projectile.position.X - projectile.velocity.X * 4f + 2f, projectile.position.Y + 2f - projectile.velocity.Y * 4f), 8, 8, 107, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, new Color(0, 255, 255), 0.5f); Main.dust[num309].velocity *= -0.25f; Main.dust[num309].position -= projectile.velocity * 0.5f; } projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; Lighting.AddLight(projectile.Center, 0f, 0.5f, 0.5f); if (projectile.timeLeft < 240) CalamityGlobalProjectile.HomeInOnNPC(projectile, true, 600f, 12f, 20f); else { float num953 = 100f * projectile.ai[1]; float scaleFactor12 = 20f * projectile.ai[1]; float num954 = 40f; if (Main.player[projectile.owner].active && !Main.player[projectile.owner].dead) { if (projectile.Distance(Main.player[projectile.owner].Center) > num954) { Vector2 moveDirection = projectile.SafeDirectionTo(Main.player[projectile.owner].Center, Vector2.UnitY); projectile.velocity = (projectile.velocity * (num953 - 1f) + moveDirection * scaleFactor12) / num953; } } } } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { target.ExoDebuffs(); float healAmt = damage * 0.01f; if ((int)healAmt == 0) return; if (Main.player[Main.myPlayer].lifeSteal <= 0f) return; if (healAmt > CalamityMod.lifeStealCap) healAmt = CalamityMod.lifeStealCap; CalamityGlobalProjectile.SpawnLifeStealProjectile(projectile, Main.player[projectile.owner], healAmt, ModContent.ProjectileType(), 1200f, 3f); } public override void OnHitPvp(Player target, int damage, bool crit) { target.ExoDebuffs(); float healAmt = damage * 0.01f; if ((int)healAmt == 0) return; if (Main.player[Main.myPlayer].lifeSteal <= 0f) return; if (healAmt > CalamityMod.lifeStealCap) healAmt = CalamityMod.lifeStealCap; CalamityGlobalProjectile.SpawnLifeStealProjectile(projectile, Main.player[projectile.owner], healAmt, ModContent.ProjectileType(), 1200f, 3f); } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); return false; } public override Color? GetAlpha(Color lightColor) { return new Color(0, 255, 255, projectile.alpha); } public override void Kill(int timeLeft) { Main.PlaySound(SoundID.Zombie, (int)projectile.position.X, (int)projectile.position.Y, 103, 1f, 0f); projectile.position = projectile.Center; projectile.width = projectile.height = 80; projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); for (int num193 = 0; num193 < 2; num193++) { Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); } for (int num194 = 0; num194 < 20; num194++) { int num195 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 107, 0f, 0f, 0, new Color(0, 255, 255), 2.5f); Main.dust[num195].noGravity = true; Main.dust[num195].velocity *= 3f; num195 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 107, 0f, 0f, 100, new Color(0, 255, 255), 1.5f); Main.dust[num195].velocity *= 2f; Main.dust[num195].noGravity = true; } } } }