using Microsoft.Xna.Framework; using Terraria; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { public class FlareBat : ModProjectile { public override void SetStaticDefaults() { DisplayName.SetDefault("Bat"); Main.projFrames[projectile.type] = 5; } public override void SetDefaults() { projectile.width = 24; projectile.height = 24; projectile.friendly = true; projectile.ranged = true; projectile.penetrate = 3; projectile.timeLeft = 300; projectile.light = 0.25f; projectile.usesLocalNPCImmunity = true; projectile.localNPCHitCooldown = 10; projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.basePointBlankShotDuration; } public override void AI() { int num103 = (int)Player.FindClosest(projectile.Center, 1, 1); projectile.ai[1] += 1f; if (projectile.ai[1] < 110f && projectile.ai[1] > 30f) { float scaleFactor2 = projectile.velocity.Length(); Vector2 vector11 = Main.player[num103].Center - projectile.Center; vector11.Normalize(); vector11 *= scaleFactor2; projectile.velocity = (projectile.velocity * 24f + vector11) / 25f; projectile.velocity.Normalize(); projectile.velocity *= scaleFactor2; } if (projectile.ai[0] < 0f) { if (projectile.velocity.Length() < 18f) { projectile.velocity *= 1.02f; } } int num192 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 6, 0f, 0f, 0, default, 1f); Main.dust[num192].noGravity = true; Main.dust[num192].velocity *= 0.2f; Main.dust[num192].position = (Main.dust[num192].position + projectile.Center) / 2f; projectile.frameCounter++; if (projectile.frameCounter >= 2) { projectile.frameCounter = 0; projectile.frame++; if (projectile.frame >= 5) { projectile.frame = 0; } } projectile.spriteDirection = projectile.direction = (projectile.velocity.X > 0).ToDirectionInt(); projectile.rotation = projectile.velocity.ToRotation() + (projectile.spriteDirection == 1 ? 0f : MathHelper.Pi) * projectile.direction; } public override bool OnTileCollide(Vector2 oldVelocity) { projectile.penetrate--; if (projectile.penetrate <= 0) { projectile.Kill(); } else { if (projectile.velocity.X != oldVelocity.X) { projectile.velocity.X = -oldVelocity.X; } if (projectile.velocity.Y != oldVelocity.Y) { projectile.velocity.Y = -oldVelocity.Y; } } return false; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { projectile.Kill(); } /*public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D texture2D13 = Main.projectileTexture[projectile.type]; int num214 = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; int y6 = num214 * projectile.frame; Main.spriteBatch.Draw(texture2D13, projectile.Center - Main.screenPosition + new Vector2(0f, projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, num214)), projectile.GetAlpha(lightColor), projectile.rotation * projectile.direction, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), projectile.scale, SpriteEffects.None, 0f); return false; }*/ public override void Kill(int timeLeft) { for (int k = 0; k < 10; k++) { Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 6, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f); } } } }