using CalamityMod.Buffs.DamageOverTime; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Summon { public class CalamariInk : ModProjectile { public override void SetStaticDefaults() { DisplayName.SetDefault("Ink"); 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 = 1; projectile.timeLeft = 180; projectile.minion = true; projectile.minionSlots = 0f; projectile.extraUpdates = 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(SpriteBatch spriteBatch, Color lightColor) { Texture2D texture2D13 = Main.projectileTexture[projectile.type]; int num214 = Main.projectileTexture[projectile.type].Height / Main.projFrames[projectile.type]; int y6 = num214 * projectile.frame; Main.spriteBatch.Draw(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, 0f); return false; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { target.AddBuff(ModContent.BuffType(), 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); Main.PlaySound(SoundID.NPCKilled, (int)projectile.Center.X, (int)projectile.Center.Y, 28); 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; } } } }