Files
CalamityModPublic/Projectiles/Summon/FrostMistFriendly.cs
T
CongratsIsTrash ae561d25bc Summon
HauntedDishes code can suffer in the icy depths of Treachery
2023-10-19 12:38:38 -04:00

114 lines
4.5 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.Audio;
namespace CalamityMod.Projectiles.Summon
{
public class FrostMistFriendly : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Summon";
public override void SetStaticDefaults()
{
Main.projFrames[Projectile.type] = 8;
ProjectileID.Sets.MinionShot[Projectile.type] = true;
}
public override void SetDefaults()
{
Projectile.width = Projectile.height = 20;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.timeLeft = 300;
Projectile.alpha = 255;
Projectile.coldDamage = true;
Projectile.DamageType = DamageClass.Summon;
}
public override void AI()
{
Projectile.frameCounter++;
if (Projectile.frameCounter > 4)
{
Projectile.frame++;
Projectile.frameCounter = 0;
}
if (Projectile.frame >= Main.projFrames[Projectile.type])
{
Projectile.frame = 0;
}
if (Projectile.ai[1] == 0f)
{
for (int i = 0; i < 5; i++)
{
int dust = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 187, 0f, 0f, 100, default, 2f);
Main.dust[dust].velocity *= 3f;
if (Main.rand.NextBool())
{
Main.dust[dust].scale = 0.5f;
Main.dust[dust].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f;
}
}
Projectile.ai[1] = 1f;
SoundEngine.PlaySound(SoundID.Item30, Projectile.position);
}
if (Projectile.localAI[0] == 0f)
{
Projectile.scale -= 0.02f;
Projectile.alpha += 30;
if (Projectile.alpha >= 250)
{
Projectile.alpha = 255;
Projectile.localAI[0] = 1f;
}
}
else if (Projectile.localAI[0] == 1f)
{
Projectile.scale += 0.02f;
Projectile.alpha -= 30;
if (Projectile.alpha <= 0)
{
Projectile.alpha = 0;
Projectile.localAI[0] = 0f;
}
}
int playerOwner = (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 playerDist = Main.player[playerOwner].Center - Projectile.Center;
playerDist.Normalize();
playerDist *= scaleFactor2;
Projectile.velocity = (Projectile.velocity * 24f + playerDist) / 25f;
Projectile.velocity.Normalize();
Projectile.velocity *= scaleFactor2;
}
if (Projectile.ai[0] < 0f)
{
if (Projectile.velocity.Length() < 18f)
{
Projectile.velocity *= 1.02f;
}
}
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
Lighting.AddLight(Projectile.Center, (255 - Projectile.alpha) * 0f / 255f, (255 - Projectile.alpha) * 0.35f / 255f, (255 - Projectile.alpha) * 0.35f / 255f);
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture2D13 = ModContent.Request<Texture2D>(Texture).Value;
int framing = texture2D13.Height / Main.projFrames[Projectile.type];
int y6 = framing * Projectile.frame;
Main.EntitySpriteDraw(texture2D13, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, framing)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)framing / 2f), Projectile.scale, SpriteEffects.None, 0);
return false;
}
public override Color? GetAlpha(Color lightColor)
{
return new Color(200, 200, 200, Projectile.alpha);
}
}
}