Files
CalamityModPublic/Projectiles/Melee/BloodScythe.cs
T
CongratsIsTrash e0e167346e Added ProjectileID.Sets.CultistIsResistantTo on every homing projectile in Calamity
This does nothing for Calamity since we disable Cultist's homing resist.
However, since this is effectively used as a homing projectile set, this will help with crossmod compatibility.
I ask that everyone else who changes homing projectiles in any way to help maintain this.
2024-09-09 23:52:07 -04:00

67 lines
2.8 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Melee
{
public class BloodScythe : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Melee";
public override void SetStaticDefaults() => ProjectileID.Sets.CultistIsResistantTo[Type] = true;
public override void SetDefaults()
{
Projectile.width = 28;
Projectile.height = 28;
Projectile.alpha = 100;
Projectile.friendly = true;
Projectile.DamageType = DamageClass.Melee;
Projectile.tileCollide = false;
Projectile.penetrate = 1;
Projectile.timeLeft = 600;
}
public override void AI()
{
Lighting.AddLight(Projectile.Center, (255 - Projectile.alpha) * 0.35f / 255f, (255 - Projectile.alpha) * 0.05f / 255f, (255 - Projectile.alpha) * 0.075f / 255f);
Projectile.velocity *= 0.935f;
Projectile.rotation += (Math.Abs(Projectile.velocity.X) + Math.Abs(Projectile.velocity.Y)) * 0.1f;
Projectile.Opacity = Utils.GetLerpValue(1f, 6f, Projectile.velocity.Length(), true);
if (Projectile.Opacity <= 0f)
Projectile.Kill();
// Weakly home in on enemies.
NPC potentialTarget = Projectile.Center.ClosestNPCAt(540f);
if (potentialTarget != null && Projectile.timeLeft >= 480)
{
float flySpeed = Projectile.velocity.Length();
if (flySpeed < 10f)
flySpeed = 10f;
Projectile.Center = Projectile.Center.MoveTowards(potentialTarget.Center, 1.75f);
Projectile.velocity = (Projectile.velocity * 14f + Projectile.SafeDirectionTo(potentialTarget.Center) * flySpeed) / 15f;
Projectile.velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY) * flySpeed;
}
if (Main.rand.NextBool(5))
Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.Blood, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f);
}
public override bool PreDraw(ref Color lightColor)
{
Texture2D tex = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value;
Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0);
return false;
}
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
{
target.AddBuff(BuffID.OnFire, 180);
}
}
}