121 lines
4.2 KiB
C#
121 lines
4.2 KiB
C#
using CalamityMod.Buffs.StatDebuffs;
|
|
using CalamityMod.Items.Weapons.Magic;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
using Terraria.Audio;
|
|
namespace CalamityMod.Projectiles.Magic
|
|
{
|
|
public class VolatileStarcore : ModProjectile
|
|
{
|
|
private static int Lifetime = 240;
|
|
private static int NumAnimationFrames = 6;
|
|
private static int AnimationFrameTime = 2;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Volatile Starcore");
|
|
Main.projFrames[Projectile.type] = NumAnimationFrames;
|
|
}
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 26;
|
|
Projectile.height = 26;
|
|
Projectile.DamageType = DamageClass.Magic;
|
|
Projectile.friendly = true;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.extraUpdates = 2;
|
|
Projectile.timeLeft = Lifetime;
|
|
Projectile.alpha = 48;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
// Draw offsets
|
|
DrawOffsetX = -10;
|
|
DrawOriginOffsetY = -10;
|
|
DrawOriginOffsetX = 0;
|
|
|
|
// Play sound and set rotation on frame 1
|
|
if (Projectile.localAI[0] == 0f)
|
|
{
|
|
Projectile.localAI[0] = 1f;
|
|
SoundEngine.PlaySound(SoundID.NPCDeath56, Projectile.Center);
|
|
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4;
|
|
}
|
|
|
|
// Dust only shows up after the first few frames
|
|
if (Projectile.localAI[0] >= 5f)
|
|
SpawnDust();
|
|
|
|
// Lighting and spin
|
|
Lighting.AddLight(Projectile.Center, 1.8f, 1.6f, 0.5f);
|
|
Projectile.rotation += 0.11f;
|
|
|
|
// Increment frame counter
|
|
Projectile.localAI[0] += 1f;
|
|
|
|
// Update animation
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter > AnimationFrameTime)
|
|
{
|
|
Projectile.frame++;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
if (Projectile.frame >= NumAnimationFrames)
|
|
Projectile.frame = 0;
|
|
}
|
|
|
|
private void SpawnDust()
|
|
{
|
|
int coreDustCount = 2; //3
|
|
int coreDustType = 262;
|
|
for (int i = 0; i < coreDustCount; ++i)
|
|
{
|
|
float scale = Main.rand.NextFloat(1.0f, 1.4f);
|
|
int idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, coreDustType);
|
|
Main.dust[idx].velocity *= 0.7f;
|
|
Main.dust[idx].velocity += Projectile.velocity * 1.4f;
|
|
Main.dust[idx].scale = scale;
|
|
Main.dust[idx].noGravity = true;
|
|
}
|
|
|
|
int trailDustCount = 4; //5
|
|
int trailDustType = 264;
|
|
for (int i = 0; i < trailDustCount; ++i)
|
|
{
|
|
float scale = Main.rand.NextFloat(1.0f, 1.4f);
|
|
int idx = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, trailDustType, 0f, 0f);
|
|
Main.dust[idx].velocity = Projectile.velocity * 0.8f;
|
|
Main.dust[idx].scale = scale;
|
|
Main.dust[idx].noGravity = true;
|
|
}
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
|
|
{
|
|
target.AddBuff(BuffID.Daybreak, 180);
|
|
target.AddBuff(ModContent.BuffType<Irradiated>(), 180);
|
|
}
|
|
|
|
public override void OnHitPvp(Player target, int damage, bool crit)
|
|
{
|
|
target.AddBuff(BuffID.Daybreak, 180);
|
|
target.AddBuff(ModContent.BuffType<Irradiated>(), 180);
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
if (Projectile.owner != Main.myPlayer)
|
|
return;
|
|
|
|
// Spawn a Helium Flash on impact
|
|
int type = ModContent.ProjectileType<HeliumFlashBlast>();
|
|
int damage = (int)(HeliumFlash.ExplosionDamageMultiplier * Projectile.damage);
|
|
float kb = 9.5f;
|
|
Projectile.NewProjectile(Projectile.GetProjectileSource_FromThis(), Projectile.Center, Vector2.Zero, type, damage, kb, Projectile.owner, 0f, 0f);
|
|
}
|
|
}
|
|
}
|