Files
CalamityModPublic/Projectiles/Magic/RedirectingGildedSoul.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

89 lines
3.9 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 RedirectingGildedSoul : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Magic";
public ref float BurstIntensity => ref Projectile.ai[0];
public ref float Time => ref Projectile.ai[1];
public override void SetStaticDefaults()
{
Main.projFrames[Projectile.type] = 4;
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10;
ProjectileID.Sets.TrailingMode[Projectile.type] = 2;
}
public override void SetDefaults()
{
Projectile.scale = 0.6f;
Projectile.width = Projectile.height = 32;
Projectile.friendly = true;
Projectile.penetrate = 1;
Projectile.tileCollide = false;
Projectile.DamageType = DamageClass.Magic;
Projectile.ignoreWater = true;
}
public override void AI() => RedirectingVengefulSoul.DoSoulAI(Projectile, ref Time, 5f);
public override Color? GetAlpha(Color lightColor)
{
Color baseColor = Color.Lerp(Color.DarkGoldenrod, Color.Gold, Projectile.identity % 5f / 5f);
Color color = Color.Lerp(baseColor, Color.White, BurstIntensity * 0.5f + (float)Math.Cos(Main.GlobalTimeWrappedHourly * 2.7f) * 0.04f);
color.A = 127;
return color * Projectile.Opacity;
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D texture = ModContent.Request<Texture2D>(Texture).Value;
Rectangle frame = texture.Frame(1, Main.projFrames[Projectile.type], 0, Projectile.frame);
SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < Projectile.oldPos.Length / 2; j++)
{
Color drawColor = Projectile.GetAlpha(lightColor);
drawColor = Color.Lerp(drawColor, Color.White * Projectile.Opacity, 2f * j / Projectile.oldPos.Length) * (float)Math.Pow(1f - Utils.GetLerpValue(0f, Projectile.oldPos.Length / 2, j, true), 2D);
Vector2 drawPosition = Projectile.oldPos[j] + Projectile.Size * 0.5f + (MathHelper.TwoPi * i / 4f).ToRotationVector2() * 0.5f - Main.screenPosition;
float rotation = Projectile.oldRot[j];
Main.EntitySpriteDraw(texture, drawPosition, frame, drawColor, rotation, frame.Size() * 0.5f, Projectile.scale, direction, 0);
}
}
return false;
}
public override void OnKill(int timeLeft)
{
// Play a wraith death sound at max intensity and a dungeon spirit hit sound otherwise.
SoundEngine.PlaySound(BurstIntensity >= 1f ? SoundID.NPCDeath52 : SoundID.NPCHit35, Projectile.Center);
// As well as an "extinguished" sound.
SoundEngine.PlaySound(SoundID.NPCDeath55, Projectile.Center);
// Make a ghost sound and explode into ectoplasmic energy.
if (Main.dedServ)
return;
for (int i = 0; i < 45; i++)
{
Dust ectoplasm = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(80f, 80f) * (float)Math.Pow(BurstIntensity, 2D), 264);
ectoplasm.velocity = Main.rand.NextVector2Circular(2f, 2f);
ectoplasm.color = Projectile.GetAlpha(Color.White);
ectoplasm.scale = MathHelper.Lerp(1f, 1.6f, BurstIntensity);
ectoplasm.noGravity = true;
ectoplasm.noLight = true;
}
}
}
}