using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; namespace CalamityMod.Projectiles.Rogue { public class IceStarProjectile : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Rogue"; public override string Texture => "CalamityMod/Items/Weapons/Rogue/IceStar"; private bool initStealth = false; private Vector2 initialVelocity; public override void SetDefaults() { Projectile.width = 30; Projectile.height = 30; Projectile.friendly = true; Projectile.penetrate = 3; Projectile.aiStyle = ProjAIStyleID.ThrownProjectile; AIType = ProjectileID.ThrowingKnife; Projectile.DamageType = RogueDamageClass.Instance; Projectile.coldDamage = true; Projectile.MaxUpdates = 2; Projectile.timeLeft = 60 * Projectile.MaxUpdates; //60 effective, 120 total Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 30 * Projectile.MaxUpdates; //30 effective, 60 total } public override void AI() { if (!initStealth && Projectile.Calamity().stealthStrike) { Projectile.penetrate = -1; Projectile.tileCollide = false; Projectile.timeLeft = 90 * Projectile.MaxUpdates; initialVelocity = Projectile.velocity; initStealth = true; } //Projectile.rotation = Projectile.velocity.ToRotation(); if (Main.rand.NextBool(3)) { Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 67, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f); } Vector2 center = Projectile.Center; float maxDistance = Projectile.Calamity().stealthStrike ? 800f : 400f; bool homeIn = false; for (int i = 0; i < Main.maxNPCs; i++) { if (Main.npc[i].CanBeChasedBy(Projectile, false)) { float extraDistance = (float)(Main.npc[i].width / 2) + (float)(Main.npc[i].height / 2); if (Vector2.Distance(Main.npc[i].Center, Projectile.Center) < (maxDistance + extraDistance) && Collision.CanHit(Projectile.Center, 1, 1, Main.npc[i].Center, 1, 1)) { center = Main.npc[i].Center; homeIn = true; break; } } } if (homeIn) { Vector2 moveDirection = Projectile.SafeDirectionTo(center, Vector2.UnitY); Projectile.velocity = (Projectile.velocity * 20f + moveDirection * 14f) / 21f; } Projectile.velocity = initStealth && !homeIn ? initialVelocity : Projectile.velocity; } public override void Kill(int timeLeft) { SoundEngine.PlaySound(SoundID.Item27, Projectile.position); for (int k = 0; k < 5; k++) { Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 67, Projectile.oldVelocity.X * 0.5f, Projectile.oldVelocity.Y * 0.5f); } } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => OnHitEffects(); public override void OnHitPlayer(Player target, Player.HurtInfo info) => OnHitEffects(); public void OnHitEffects() { if (initStealth && Projectile.owner == Main.myPlayer && Projectile.numHits < 1) { for (int i = 0; i < 8; i++) { Vector2 velocity = (MathHelper.TwoPi * i / 8f).ToRotationVector2() * 4f; Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); } } } } }