Files
CalamityModPublic/Projectiles/Rogue/NightsGazeStar.cs
T

142 lines
4.9 KiB
C#

using CalamityMod.Buffs.DamageOverTime;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Rogue
{
public class NightsGazeStar : ModProjectile
{
public static int lifetime = 150;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Night's Gaze Star");
ProjectileID.Sets.TrailCacheLength[projectile.type] = 8;
ProjectileID.Sets.TrailingMode[projectile.type] = 1;
}
public override void SetDefaults()
{
projectile.width = 10;
projectile.height = 10;
projectile.friendly = true;
projectile.penetrate = 5;
projectile.timeLeft = lifetime;
projectile.Calamity().rogue = true;
projectile.localAI[0] = 10f;
}
public override void AI()
{
projectile.rotation += projectile.direction * 0.05f;
if (projectile.ai[0] == 0f)
{
if (projectile.timeLeft < (lifetime - projectile.ai[1]) && projectile.localAI[0] >= 0)
{
projectile.velocity.Normalize();
projectile.velocity *= projectile.localAI[0];
projectile.localAI[0]--;
}
else if (projectile.timeLeft >= (lifetime - projectile.ai[1]))
{
for (int i = 0; i < 3; i++)
{
float dustVelocity = Main.rand.NextFloat(0f, 0.5f);
int dustToUse = Main.rand.Next(0, 3);
int dustType = 0;
switch (dustToUse)
{
case 0:
dustType = 109;
break;
case 1:
dustType = 111;
break;
case 2:
dustType = 132;
break;
}
int dust = Dust.NewDust(projectile.Center, 1, 1, dustType, projectile.velocity.X, projectile.velocity.Y, 0, default, 1.5f);
Main.dust[dust].noGravity = true;
Main.dust[dust].velocity *= dustVelocity;
}
}
}
else if (projectile.ai[0] == 1f)
{
float minDist = 999f;
int index = 0;
for (int i = 0; i < Main.npc.Length; i++)
{
NPC npc = Main.npc[i];
if (!npc.friendly && !npc.townNPC && npc.active && !npc.dontTakeDamage && npc.chaseable)
{
float dist = (projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = i;
}
}
}
if (minDist < 999f)
{
Vector2 velocityNew = Main.npc[index].Center - projectile.Center;
float speed = 10f;
velocityNew.Normalize();
projectile.velocity = velocityNew * speed;
}
}
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(ModContent.BuffType<Nightwither>(), 120);
}
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)
{
CalamityGlobalProjectile.DrawCenteredAndAfterimage(projectile, Color.White, ProjectileID.Sets.TrailingMode[projectile.type], 3);
return false;
}
public override void Kill(int timeLeft)
{
for (int i = 0; i < 5; i++)
{
int dustToUse = Main.rand.Next(0, 3);
int dustType = 0;
switch (dustToUse)
{
case 0:
dustType = 109;
break;
case 1:
dustType = 111;
break;
case 2:
dustType = 132;
break;
}
int dust = Dust.NewDust(projectile.Center, 1, 1, dustType, projectile.velocity.X, projectile.velocity.Y, 0, default, 1.5f);
Main.dust[dust].noGravity = true;
}
}
}
}