using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; using Terraria.ModLoader; using Terraria.ID; namespace CalamityMod.Projectiles.Magic { public class WaterLeechProj : ModProjectile { public override string Texture => "CalamityMod/NPCs/AcidRain/WaterLeech"; public override void SetStaticDefaults() { DisplayName.SetDefault("Leech"); Main.projFrames[projectile.type] = 4; } public override void SetDefaults() { projectile.width = projectile.height = 18; projectile.friendly = true; projectile.penetrate = -1; projectile.timeLeft = 540; projectile.magic = true; } public override void AI() { projectile.frameCounter++; if (projectile.frameCounter > 4) { projectile.frame++; projectile.frameCounter = 0; } if (projectile.frame >= Main.projFrames[projectile.type]) { projectile.frame = 0; } if (projectile.ai[0] == 0f) { projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + MathHelper.Pi; } //Sticky Behaviour projectile.StickyProjAI(5); } public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) { projectile.ModifyHitNPCSticky(3, false); } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { target.AddBuff(ModContent.BuffType(), 180); } public override void OnHitPvp(Player target, int damage, bool crit) { target.AddBuff(ModContent.BuffType(), 180); } public override bool OnTileCollide(Vector2 oldVelocity) { Collision.HitTiles(projectile.position + projectile.velocity, projectile.velocity, projectile.width, projectile.height); projectile.Kill(); return false; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D texture = Main.projectileTexture[projectile.type]; int height = texture.Height / Main.projFrames[projectile.type]; int drawStart = height * projectile.frame; Vector2 origin = projectile.Size / 2; SpriteEffects spriteEffects = SpriteEffects.None; if (projectile.spriteDirection == -1) spriteEffects = SpriteEffects.FlipHorizontally; spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, drawStart, texture.Width, height)), Color.White, projectile.rotation, origin, projectile.scale, spriteEffects, 0f); return false; } public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D texture = Main.projectileTexture[projectile.type]; int height = texture.Height / Main.projFrames[projectile.type]; int drawStart = height * projectile.frame; Vector2 origin = projectile.Size / 2; SpriteEffects spriteEffects = SpriteEffects.None; if (projectile.spriteDirection == -1) spriteEffects = SpriteEffects.FlipHorizontally; spriteBatch.Draw(ModContent.GetTexture("CalamityMod/NPCs/AcidRain/WaterLeechGlow"), projectile.Center - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, drawStart, texture.Width, height)), Color.White, projectile.rotation, origin, projectile.scale, spriteEffects, 0f); } public override void Kill(int timeLeft) { Main.PlaySound(SoundID.NPCKilled, (int)projectile.position.X, (int)projectile.position.Y, 1, 0.5f, 0f); for (int i = 0; i < 5; i++) { int dust = Dust.NewDust(projectile.Center, 1, 1, (int)CalamityDusts.SulfurousSeaAcid, 0, 0, 0, default, 1.5f); Main.dust[dust].noGravity = true; } } } }