Files
CalamityModPublic/Projectiles/Rogue/EquanimityDarkShard.cs
T
Ozzatron 60688c4259 Merge of BasicallyIAmFox's Entity Iterators PR with 2.0.4.001
- Some entity iterators were intentionally excluded due to complex merge conflicts with fully reworked weapons.
- NOTABLE: ProjectileUtils generic homing code had its iterator excluded due to a behavioral change which was not easily resolved.
2024-05-13 21:42:17 -04:00

87 lines
2.7 KiB
C#

using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Rogue
{
public class EquanimityDarkShard : ModProjectile, ILocalizedModType
{
public new string LocalizationCategory => "Projectiles.Rogue";
public override void SetDefaults()
{
Projectile.width = 12;
Projectile.height = 14;
Projectile.friendly = true;
Projectile.ignoreWater = true;
Projectile.alpha = 0;
Projectile.penetrate = 1;
Projectile.tileCollide = true;
Projectile.timeLeft = 120;
Projectile.DamageType = RogueDamageClass.Instance;
}
public override void AI()
{
Projectile.velocity.Y += 0.1f;
Projectile.rotation += 0.4f * Projectile.direction;
if (Projectile.timeLeft < 130)
{
float minDist = 999f;
int index = 0;
foreach (NPC npc in Main.ActiveNPCs)
{
if (npc.CanBeChasedBy(Projectile, false))
{
float dist = (Projectile.Center - npc.Center).Length();
if (dist < minDist)
{
minDist = dist;
index = npc.whoAmI;
}
}
}
Vector2 velocityNew;
if (minDist < 999f)
{
velocityNew = Main.npc[index].Center - Projectile.Center;
velocityNew.Normalize();
Projectile.velocity += velocityNew;
if (Projectile.velocity.Length() > 10f)
{
Projectile.velocity.Normalize();
Projectile.velocity *= 10f;
}
}
}
if (Projectile.timeLeft < 51)
{
Projectile.alpha += 5;
}
}
public override bool? CanHitNPC(NPC target)
{
if (Projectile.timeLeft < 130)
{
return null;
}
else
{
return false;
}
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
Collision.HitTiles(Projectile.position + Projectile.velocity, Projectile.velocity, Projectile.width, Projectile.height);
SoundEngine.PlaySound(SoundID.Dig, Projectile.position);
Projectile.Kill();
return true;
}
}
}