124 lines
4.1 KiB
C#
124 lines
4.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Typeless
|
|
{
|
|
public class KelvinCatalystStar : ModProjectile
|
|
{
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Kelvin Catalyst Star");
|
|
ProjectileID.Sets.TrailCacheLength[projectile.type] = 4;
|
|
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
projectile.width = 16;
|
|
projectile.height = 16;
|
|
projectile.friendly = true;
|
|
projectile.penetrate = 1;
|
|
projectile.tileCollide = false;
|
|
projectile.coldDamage = true;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (projectile.ai[0] < 90f)
|
|
{
|
|
projectile.ai[0] += 1f;
|
|
projectile.velocity.X *= 0.98f;
|
|
projectile.velocity.Y *= 0.98f;
|
|
}
|
|
else
|
|
{
|
|
projectile.extraUpdates = 1;
|
|
|
|
Vector2 center = projectile.Center;
|
|
float maxDistance = 500f;
|
|
bool homeIn = false;
|
|
|
|
for (int i = 0; i < Main.maxNPCs; i++)
|
|
{
|
|
if (Main.npc[i].CanBeChasedBy(projectile, false))
|
|
{
|
|
float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2);
|
|
|
|
if (Vector2.Distance(Main.npc[i].Center, projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(projectile.Center, 1, 1, Main.npc[i].Center, 1, 1))
|
|
{
|
|
center = Main.npc[i].Center;
|
|
homeIn = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (homeIn)
|
|
{
|
|
Vector2 homeInVector = projectile.DirectionTo(center);
|
|
if (homeInVector.HasNaNs())
|
|
homeInVector = Vector2.UnitY;
|
|
|
|
projectile.velocity = (projectile.velocity * 20f + homeInVector * 12f) / (21f);
|
|
}
|
|
else
|
|
projectile.Kill();
|
|
}
|
|
|
|
Lighting.AddLight(projectile.Center, Main.DiscoR * 0.075f / 255f, Main.DiscoR * 0.1f / 255f, Main.DiscoR * 0.125f / 255f);
|
|
|
|
if (Main.rand.NextBool(6))
|
|
{
|
|
int dust = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 67, 0f, 0f, 100, default, 0.4f);
|
|
Main.dust[dust].velocity *= 0.3f;
|
|
Main.dust[dust].noGravity = true;
|
|
}
|
|
|
|
projectile.rotation += 0.25f;
|
|
}
|
|
|
|
public override bool CanDamage()
|
|
{
|
|
return projectile.ai[0] >= 90f;
|
|
}
|
|
|
|
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
|
|
{
|
|
CalamityGlobalProjectile.DrawCenteredAndAfterimage(projectile, lightColor, ProjectileID.Sets.TrailingMode[projectile.type], 1);
|
|
return false;
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
Main.PlaySound(SoundID.Item27, projectile.position);
|
|
CalamityGlobalProjectile.ExpandHitboxBy(projectile, 24);
|
|
int num226 = 36;
|
|
for (int num227 = 0; num227 < num226; num227++)
|
|
{
|
|
Vector2 vector6 = Vector2.Normalize(projectile.velocity) * new Vector2((float)projectile.width / 2f, (float)projectile.height) * 0.75f;
|
|
vector6 = vector6.RotatedBy((double)((float)(num227 - (num226 / 2 - 1)) * 6.28318548f / (float)num226), default) + projectile.Center;
|
|
Vector2 vector7 = vector6 - projectile.Center;
|
|
int num228 = Dust.NewDust(vector6 + vector7, 0, 0, 67, vector7.X * 0.5f, vector7.Y * 0.5f, 100, default, 0.75f);
|
|
Main.dust[num228].noGravity = true;
|
|
}
|
|
projectile.usesLocalNPCImmunity = true;
|
|
projectile.localNPCHitCooldown = 10;
|
|
projectile.Damage();
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
|
{
|
|
target.AddBuff(BuffID.Frostburn, 60);
|
|
}
|
|
|
|
public override void OnHitPvp(Player target, int damage, bool crit)
|
|
{
|
|
target.AddBuff(BuffID.Frostburn, 60);
|
|
}
|
|
}
|
|
}
|