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.
134 lines
4.8 KiB
C#
134 lines
4.8 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
using CalamityMod.Buffs.StatDebuffs;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.Audio;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.Projectiles.Summon
|
|
{
|
|
public class EndoIceShard : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Summon";
|
|
public override void SetStaticDefaults()
|
|
{
|
|
ProjectileID.Sets.CultistIsResistantTo[Type] = true;
|
|
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4;
|
|
ProjectileID.Sets.TrailingMode[Projectile.type] = 0;
|
|
ProjectileID.Sets.MinionShot[Projectile.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.friendly = true;
|
|
Projectile.width = Projectile.height = 14;
|
|
Projectile.ignoreWater = true;
|
|
Projectile.tileCollide = false;
|
|
Projectile.extraUpdates = 1;
|
|
Projectile.alpha = 255;
|
|
Projectile.timeLeft = 240;
|
|
Projectile.coldDamage = true;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
|
|
Lighting.AddLight(Projectile.Center, new Vector3(46, 203, 255) * (1.2f / 255));
|
|
Projectile.ai[0]++;
|
|
Projectile.ai[1]++;
|
|
if (Projectile.ai[0] >= 30f)
|
|
{
|
|
Vector2 dspeed = Projectile.velocity * Main.rand.NextFloat(0.3f, 0.6f);
|
|
int dust = Dust.NewDust(Projectile.Center, 1, 1, DustID.IceRod, dspeed.X, dspeed.Y, 50, default, 1.2f);
|
|
Main.dust[dust].noGravity = true;
|
|
Projectile.ai[0] = 0f;
|
|
}
|
|
|
|
//Homing
|
|
if (Projectile.ai[1] > 20f)
|
|
HomingAI();
|
|
//Fade in
|
|
if (Projectile.alpha > 0)
|
|
{
|
|
Projectile.alpha -= 15;
|
|
}
|
|
if (Projectile.alpha < 0)
|
|
{
|
|
Projectile.alpha = 0;
|
|
}
|
|
}
|
|
|
|
private void HomingAI()
|
|
{
|
|
Player player = Main.player[Projectile.owner];
|
|
int targetIdx = -1;
|
|
float maxHomingRange = 800f;
|
|
bool hasHomingTarget = false;
|
|
if (player.HasMinionAttackTargetNPC)
|
|
{
|
|
NPC npc = Main.npc[player.MinionAttackTargetNPC];
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float dist = (Projectile.Center - npc.Center).Length();
|
|
if (dist < maxHomingRange)
|
|
{
|
|
targetIdx = player.MinionAttackTargetNPC;
|
|
maxHomingRange = dist;
|
|
hasHomingTarget = true;
|
|
}
|
|
}
|
|
}
|
|
if (!hasHomingTarget)
|
|
{
|
|
foreach (NPC npc in Main.ActiveNPCs)
|
|
{
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float dist = (Projectile.Center - npc.Center).Length();
|
|
if (dist < maxHomingRange)
|
|
{
|
|
targetIdx = npc.whoAmI;
|
|
maxHomingRange = dist;
|
|
hasHomingTarget = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Home in on said closest NPC.
|
|
if (hasHomingTarget)
|
|
{
|
|
NPC target = Main.npc[targetIdx];
|
|
Vector2 homingVector = (target.Center - Projectile.Center).SafeNormalize(Vector2.Zero) * 32f;
|
|
float homingRatio = 40f;
|
|
Projectile.velocity = (Projectile.velocity * homingRatio + homingVector) / (homingRatio + 1f);
|
|
}
|
|
}
|
|
|
|
public override void OnKill(int timeLeft)
|
|
{
|
|
SoundEngine.PlaySound(SoundID.Item27, Projectile.position);
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
Vector2 dspeed = new Vector2(Main.rand.NextFloat(-7f, 7f), Main.rand.NextFloat(-7f, 7f));
|
|
int dust = Dust.NewDust(Projectile.Center, 1, 1, DustID.IceRod, dspeed.X, dspeed.Y, 50, default, 1.2f);
|
|
Main.dust[dust].noGravity = true;
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1);
|
|
return false;
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
|
|
{
|
|
target.AddBuff(ModContent.BuffType<GlacialState>(), 60);
|
|
target.AddBuff(ModContent.BuffType<Voidfrost>(), 180);
|
|
}
|
|
}
|
|
}
|