154 lines
6.3 KiB
C#
154 lines
6.3 KiB
C#
using CalamityMod.Buffs.DamageOverTime;
|
|
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.Summon
|
|
{
|
|
public class CalamariInk : ModProjectile, ILocalizedModType
|
|
{
|
|
public new string LocalizationCategory => "Projectiles.Summon";
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.projFrames[Projectile.type] = 5;
|
|
ProjectileID.Sets.MinionShot[Projectile.type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Projectile.width = 14;
|
|
Projectile.height = 14;
|
|
Projectile.friendly = true;
|
|
Projectile.penetrate = 5;
|
|
Projectile.timeLeft = 180;
|
|
Projectile.minion = true;
|
|
Projectile.minionSlots = 0f;
|
|
Projectile.extraUpdates = 2;
|
|
Projectile.DamageType = DamageClass.Summon;
|
|
Projectile.usesLocalNPCImmunity = true;
|
|
Projectile.localNPCHitCooldown = -1;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Projectile.frameCounter++;
|
|
if (Projectile.frameCounter > 8)
|
|
{
|
|
Projectile.frame++;
|
|
Projectile.frameCounter = 0;
|
|
}
|
|
if (Projectile.frame > 4)
|
|
{
|
|
Projectile.frame = 0;
|
|
}
|
|
Projectile.rotation = (float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X) - MathHelper.PiOver2;
|
|
|
|
Player player = Main.player[Projectile.owner];
|
|
int targetIdx = -1;
|
|
float maxHomingRange = 400f;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
else if (Main.npc[(int)Projectile.ai[0]].active && Projectile.ai[0] != -1f)
|
|
{
|
|
NPC npc = Main.npc[(int)Projectile.ai[0]];
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float dist = (Projectile.Center - npc.Center).Length();
|
|
if (dist < maxHomingRange)
|
|
{
|
|
targetIdx = (int)Projectile.ai[0];
|
|
maxHomingRange = dist;
|
|
hasHomingTarget = true;
|
|
}
|
|
}
|
|
}
|
|
if (!hasHomingTarget)
|
|
{
|
|
for (int i = 0; i < Main.npc.Length; ++i)
|
|
{
|
|
NPC npc = Main.npc[i];
|
|
if (npc is null || !npc.active)
|
|
continue;
|
|
|
|
if (npc.CanBeChasedBy(Projectile, false))
|
|
{
|
|
float dist = (Projectile.Center - npc.Center).Length();
|
|
if (dist < maxHomingRange)
|
|
{
|
|
targetIdx = i;
|
|
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) * 10f;
|
|
float homingRatio = 20f;
|
|
Projectile.velocity = (Projectile.velocity * homingRatio + homingVector) / (homingRatio + 1f);
|
|
}
|
|
}
|
|
|
|
public override bool PreDraw(ref Color lightColor)
|
|
{
|
|
Texture2D texture2D13 = ModContent.Request<Texture2D>(Texture).Value;
|
|
int num214 = texture2D13.Height / Main.projFrames[Projectile.type];
|
|
int y6 = num214 * Projectile.frame;
|
|
Main.EntitySpriteDraw(texture2D13, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Rectangle(0, y6, texture2D13.Width, num214)), Projectile.GetAlpha(lightColor), Projectile.rotation, new Vector2((float)texture2D13.Width / 2f, (float)num214 / 2f), Projectile.scale, SpriteEffects.None, 0);
|
|
return false;
|
|
}
|
|
|
|
public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
|
|
{
|
|
target.AddBuff(ModContent.BuffType<CrushDepth>(), 180);
|
|
}
|
|
|
|
public override void Kill(int timeLeft)
|
|
{
|
|
Projectile.position = Projectile.Center;
|
|
Projectile.width = Projectile.height = 48;
|
|
Projectile.position.X = Projectile.position.X - (Projectile.width / 2);
|
|
Projectile.position.Y = Projectile.position.Y - (Projectile.height / 2);
|
|
SoundEngine.PlaySound(SoundID.NPCDeath28, Projectile.Center);
|
|
for (int num621 = 0; num621 < 10; num621++)
|
|
{
|
|
int num622 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 54, 0f, 0f, 100, default, 1f);
|
|
Main.dust[num622].velocity *= 3f;
|
|
if (Main.rand.NextBool(2))
|
|
{
|
|
Main.dust[num622].scale = 0.5f;
|
|
Main.dust[num622].fadeIn = 1f + Main.rand.Next(10) * 0.1f;
|
|
}
|
|
}
|
|
for (int num623 = 0; num623 < 15; num623++)
|
|
{
|
|
int num624 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 109, 0f, 0f, 100, default, 1.5f);
|
|
Main.dust[num624].noGravity = true;
|
|
Main.dust[num624].velocity *= 5f;
|
|
num624 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width, Projectile.height, 109, 0f, 0f, 100, default, 1f);
|
|
Main.dust[num624].velocity *= 2f;
|
|
}
|
|
}
|
|
}
|
|
}
|