Files
CalamityModPublic/Projectiles/Magic/SHPB.cs
T
Ozzatron ba14da9cdd Initial tModPorter run. Almost all of this is Kill -> OnKill in every Projectile ever.
Profaned Soul Crystal's anti-whip-stack only works on vanilla whips at the moment.
2023-09-30 01:17:11 -04:00

119 lines
4.6 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
namespace CalamityMod.Projectiles.Magic
{
public class SHPB : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
public int explosionTimer = 120;
public override void SetStaticDefaults()
{
Main.projFrames[Projectile.type] = 4;
}
public override void SetDefaults()
{
Projectile.width = 24;
Projectile.height = 24;
Projectile.friendly = true;
Projectile.alpha = 255;
Projectile.penetrate = 1;
Projectile.timeLeft = 300;
Projectile.DamageType = DamageClass.Magic;
}
public override void AI()
{
float num = (float)Main.rand.Next(90, 111) * 0.01f;
num *= Main.essScale;
Lighting.AddLight(Projectile.Center, 1f * num, 0.2f * num, 0.75f * num);
Projectile.alpha -= 2;
Projectile.frameCounter++;
if (Projectile.frameCounter > 4)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame > 3)
{
Projectile.frame = 0;
}
Projectile.ai[0] = (float)Main.rand.Next(-100, 101) * 0.0025f;
Projectile.ai[1] = (float)Main.rand.Next(-100, 101) * 0.0025f;
if (Projectile.localAI[0] == 0f)
{
Projectile.scale += 0.05f;
if ((double)Projectile.scale > 1.2)
{
Projectile.localAI[0] = 1f;
}
}
else
{
Projectile.scale -= 0.05f;
if ((double)Projectile.scale < 0.8)
{
Projectile.localAI[0] = 0f;
}
}
Projectile.velocity.X *= 0.985f;
Projectile.velocity.Y *= 0.985f;
float num472 = Projectile.Center.X;
float num473 = Projectile.Center.Y;
float num474 = 250f;
bool flag17 = false;
for (int num475 = 0; num475 < Main.maxNPCs; num475++)
{
if (Main.npc[num475].CanBeChasedBy(Projectile, false) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[num475].Center, 1, 1))
{
float num476 = Main.npc[num475].position.X + (float)(Main.npc[num475].width / 2);
float num477 = Main.npc[num475].position.Y + (float)(Main.npc[num475].height / 2);
float num478 = Math.Abs(Projectile.position.X + (float)(Projectile.width / 2) - num476) + Math.Abs(Projectile.position.Y + (float)(Projectile.height / 2) - num477);
if (num478 < num474)
{
num474 = num478;
flag17 = true;
}
}
}
if (flag17)
{
explosionTimer--;
if (explosionTimer <= 0)
{
Projectile.Kill();
}
}
}
public override Color? GetAlpha(Color lightColor)
{
return new Color(255, Main.DiscoG, 155, Projectile.alpha);
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture2D13 = ModContent.Request<Texture2D>(Texture).Value;
int num214 = ModContent.Request<Texture2D>(Texture).Value.Height / Main.projFrames[Projectile.type];
int y6 = num214 * Projectile.frame;
Main.spriteBatch.Draw(texture2D13, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, num214)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), Projectile.scale, SpriteEffects.None, 0);
return false;
}
public override void OnKill(int timeLeft)
{
SoundEngine.PlaySound(SoundID.Item105, Projectile.position);
if (Projectile.owner == Main.myPlayer)
{
Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, 0f, 0f, ModContent.ProjectileType<SHPExplosion>(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f);
}
}
}
}