Files
CalamityModPublic/Projectiles/Melee/BalefulHarvesterProjectile.cs
T
DominicKarma42 55e89c9b98 Replaced (hopefully) every magic number with a constant
Note: Does not include item rarities, and appears to shown nonexistant using directive movement in the commit. This does not really affect anything, however.
2020-05-30 17:56:36 -04:00

154 lines
6.5 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Melee
{
public class BalefulHarvesterProjectile : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Pumpkin Skull");
ProjectileID.Sets.TrailCacheLength[projectile.type] = 5;
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
}
public override void SetDefaults()
{
projectile.width = 26;
projectile.height = 26;
projectile.friendly = true;
projectile.melee = true;
projectile.penetrate = 1;
projectile.timeLeft = 300;
projectile.alpha = 255;
projectile.tileCollide = false;
projectile.ignoreWater = true;
}
public override void AI()
{
if (projectile.ai[0] < 0f)
{
projectile.alpha = 0;
}
if (projectile.alpha > 0)
{
projectile.alpha -= 50;
}
if (projectile.alpha < 0)
{
projectile.alpha = 0;
}
int num123 = (int)Player.FindClosest(projectile.Center, 1, 1);
projectile.ai[1] += 1f;
if (projectile.ai[1] < 110f && projectile.ai[1] > 30f)
{
float scaleFactor2 = projectile.velocity.Length();
Vector2 vector17 = Main.player[num123].Center - projectile.Center;
vector17.Normalize();
vector17 *= scaleFactor2;
projectile.velocity = (projectile.velocity * 24f + vector17) / 25f;
projectile.velocity.Normalize();
projectile.velocity *= scaleFactor2;
}
if (projectile.velocity.Length() < 18f)
{
projectile.velocity *= 1.02f;
}
if (projectile.velocity.X < 0f)
{
projectile.spriteDirection = -1;
projectile.rotation = (float)Math.Atan2((double)-(double)projectile.velocity.Y, (double)-(double)projectile.velocity.X);
}
else
{
projectile.spriteDirection = 1;
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X);
}
if (projectile.localAI[0] == 0f)
{
projectile.localAI[0] = 1f;
Main.PlaySound(SoundID.Item8, projectile.position);
for (int num124 = 0; num124 < 10; num124++)
{
int num125 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, Main.rand.NextBool(2) ? 5 : 6, projectile.velocity.X, projectile.velocity.Y, 0, default, 2f);
Main.dust[num125].noGravity = true;
Main.dust[num125].velocity = projectile.Center - Main.dust[num125].position;
Main.dust[num125].velocity.Normalize();
Main.dust[num125].velocity *= -5f;
Main.dust[num125].velocity += projectile.velocity / 2f;
}
}
else
{
for (int num157 = 0; num157 < 2; num157++)
{
int num158 = Dust.NewDust(new Vector2(projectile.position.X + 4f, projectile.position.Y + 4f), projectile.width - 8, projectile.height - 8, Main.rand.NextBool(2) ? 5 : 6, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default, 2f);
Main.dust[num158].position -= projectile.velocity * 2f;
Main.dust[num158].noGravity = true;
Dust expr_7A4A_cp_0_cp_0 = Main.dust[num158];
expr_7A4A_cp_0_cp_0.velocity.X *= 0.3f;
Dust expr_7A65_cp_0_cp_0 = Main.dust[num158];
expr_7A65_cp_0_cp_0.velocity.Y *= 0.3f;
}
}
}
public override Color? GetAlpha(Color lightColor)
{
return new Color(200, 200, 200, Main.rand.Next(0, 128));
}
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.Dig, (int)projectile.position.X, (int)projectile.position.Y, 27);
for (int num621 = 0; num621 < 5; num621++)
{
int num622 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 5, 0f, 0f, 100, default, 2f);
Main.dust[num622].velocity *= 3f;
if (Main.rand.NextBool(2))
{
Main.dust[num622].scale = 0.5f;
Main.dust[num622].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
}
}
for (int num623 = 0; num623 < 10; num623++)
{
int num624 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 3f);
Main.dust[num624].noGravity = true;
Main.dust[num624].velocity *= 5f;
num624 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default, 2f);
Main.dust[num624].velocity *= 2f;
}
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.OnFire, 600);
if (projectile.owner == Main.myPlayer)
{
for (int k = 0; k < 2; k++)
{
Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 174, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f);
Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, (float)Main.rand.Next(-35, 36) * 0.2f, (float)Main.rand.Next(-35, 36) * 0.2f, ModContent.ProjectileType<TinyFlare>(),
(int)((double)projectile.damage * 0.35), projectile.knockBack * 0.35f, Main.myPlayer, 0f, 0f);
}
}
}
}
}