Files
CalamityModPublic/Projectiles/Magic/WaterLeechProj.cs
T
2022-10-18 20:08:19 -05:00

113 lines
4.3 KiB
C#

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;
using Terraria.Audio;
namespace CalamityMod.Projectiles.Magic
{
public class WaterLeechProj : ModProjectile
{
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.DamageType = DamageClass.Magic;
}
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<Irradiated>(), 180);
}
public override void OnHitPvp(Player target, int damage, bool crit)
{
target.AddBuff(ModContent.BuffType<Irradiated>(), 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(ref Color lightColor)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
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;
Color color = Projectile.GetAlpha(lightColor);
Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, drawStart, texture.Width, height)), color, Projectile.rotation, origin, Projectile.scale, spriteEffects, 0);
return false;
}
public override void PostDraw(Color lightColor)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
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;
Color color = Projectile.GetAlpha(Color.White);
Main.EntitySpriteDraw(ModContent.Request<Texture2D>("CalamityMod/Projectiles/Magic/WaterLeechGlow").Value, Projectile.Center - Main.screenPosition, new Rectangle(0, drawStart, texture.Width, height), Color.White, Projectile.rotation, origin, Projectile.scale, spriteEffects, 0);
}
public override void Kill(int timeLeft)
{
SoundEngine.PlaySound(SoundID.NPCDeath1 with { Volume = SoundID.NPCDeath1.Volume * 0.5f }, Projectile.position);
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;
}
}
}
}