Files
CalamityModPublic/Projectiles/Melee/MendedBiomeBlade_TruePurityProjection.cs
T
2022-01-26 20:42:46 +01:00

107 lines
4.3 KiB
C#

using CalamityMod.Buffs.StatDebuffs;
using CalamityMod.DataStructures;
using CalamityMod.Particles;
using CalamityMod.Items.Weapons.Melee;
using Terraria.Graphics.Shaders;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
using static CalamityMod.CalamityUtils;
using Terraria.Audio;
namespace CalamityMod.Projectiles.Melee
{
public class TruePurityProjection : ModProjectile //The boring plain one. With cool homing now
{
public NPC target;
public Player Owner => Main.player[projectile.owner];
public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_PurityProjection";
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Purity Projection");
ProjectileID.Sets.TrailCacheLength[projectile.type] = 2;
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
}
public override void SetDefaults()
{
projectile.width = projectile.height = 32;
projectile.aiStyle = 27;
aiType = ProjectileID.LightBeam;
projectile.friendly = true;
projectile.penetrate = 1;
projectile.timeLeft = 40;
projectile.extraUpdates = 1;
projectile.melee = true;
projectile.tileCollide = false;
}
public override void AI()
{
if (target == null)
{
foreach (Projectile proj in Main.projectile)
{
if (proj.active && proj.type == ProjectileType<PurityProjectionSigil>() && proj.owner == Owner.whoAmI)
{
target = Main.npc[(int)proj.ai[0]];
break;
}
}
}
else if ((projectile.Center - target.Center).Length() >= (projectile.Center + projectile.velocity - target.Center).Length() && CalamityUtils.AngleBetween(projectile.velocity, target.Center - projectile.Center) < MathHelper.PiOver4 * 0.5f) //Home in
{
projectile.timeLeft = 30; //Remain alive
float angularTurnSpeed = MathHelper.ToRadians(MathHelper.Lerp(12.5f, 2.5f, MathHelper.Clamp(projectile.Distance(target.Center) / 10f, 0f, 1f)));
float idealDirection = projectile.AngleTo(target.Center);
float updatedDirection = projectile.velocity.ToRotation().AngleTowards(idealDirection, angularTurnSpeed);
projectile.velocity = updatedDirection.ToRotationVector2() * projectile.velocity.Length();
}
if (projectile.timeLeft < 35)
projectile.tileCollide = true;
Lighting.AddLight(projectile.Center, 0.75f, 1f, 0.24f);
int dustParticle = Dust.NewDust(projectile.position, projectile.width, projectile.height, 75, 0f, 0f, 100, default, 0.9f);
Main.dust[dustParticle].noGravity = true;
Main.dust[dustParticle].velocity *= 0.5f;
Main.dust[dustParticle].velocity += projectile.velocity * 0.1f;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
if (projectile.timeLeft > 35)
return false;
DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1);
return false;
}
public override void Kill(int timeLeft)
{
Main.PlaySound(SoundID.Item43, projectile.Center);
for (int i = 0; i <= 15; i++)
{
Vector2 displace = (projectile.rotation - MathHelper.PiOver4).ToRotationVector2() * (-0.5f + (i / 15f)) * 88f;
int dustParticle = Dust.NewDust(projectile.Center + displace, projectile.width, projectile.height, 75, 0f, 0f, 100, default, 2f);
Main.dust[dustParticle].noGravity = true;
Main.dust[dustParticle].velocity = projectile.oldVelocity;
}
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
int debuffTime = 90;
target.AddBuff(BuffType<ArmorCrunch>(), debuffTime);
}
}
}