using System.Collections.Generic; using CalamityMod.CalPlayer; using CalamityMod.NPCs; using CalamityMod.NPCs.NormalNPCs; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Ranged { public class NullFlash : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Ranged"; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; public ref float time => ref Projectile.ai[0]; public Color baseColor = new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB, Main.DiscoR); public override void SetDefaults() { Projectile.width = 70; Projectile.height = 70; Projectile.friendly = true; Projectile.penetrate = -1; Projectile.timeLeft = 40; Projectile.DamageType = DamageClass.Ranged; Projectile.extraUpdates = 2; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = -1; Projectile.tileCollide = false; Projectile.ignoreWater = true; } public override void AI() { if (time == 0) { Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; } float rate = (Main.GlobalTimeWrappedHourly * 5); List eColors = new List() { Color.Turquoise, Color.Orchid }; int colorIndex = (int)(rate / 2 % eColors.Count); Color currentColor = eColors[colorIndex]; Color nextColor = eColors[(colorIndex + 1) % eColors.Count]; if (!Main.zenithWorld) baseColor = Color.Lerp(currentColor, nextColor, rate % 2f > 1f ? 1f : rate % 1f); if (Projectile.ai[1] == 5 && !Main.zenithWorld) baseColor = Color.White; Projectile.velocity *= 0.95f; time++; } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { Player Owner = Main.player[Projectile.owner]; if (Projectile.numHits == 0) { SoundStyle fire = new("CalamityMod/Sounds/Item/NullImpact"); SoundEngine.PlaySound(fire with { Volume = 0.5f, Pitch = 0.5f }, Projectile.Center); } if (target.CanBeMoved(true)) { // Custom knockback Vector2 launchVel = (Owner.Center - Owner.Calamity().mouseWorld).SafeNormalize(Vector2.UnitY) * -20; target.velocity = launchVel * (target.knockBackResist == 0 ? 0.5f : 1f); } if (Main.zenithWorld) { #region NPC Nullification int nullBuff = Main.rand.Next(8); switch (nullBuff) { case 0: if (target.type != ModContent.NPCType()) target.damage += 10; break; case 1: target.damage -= 10; break; case 2: target.knockBackResist = 0f; break; case 3: target.knockBackResist = 1f; break; case 4: target.defense += 5; break; case 5: target.defense -= 5; break; case 6: target.scale *= 2f; break; case 7: target.scale *= 0.5f; break; default: break; } #endregion } } public override bool PreDraw(ref Color lightColor) { if (time < 1) return false; Vector2 placement = Projectile.Center - Projectile.velocity.SafeNormalize(Vector2.UnitX) * 50; Asset tex = ModContent.Request("CalamityMod/Particles/VerticalSmear"); for (int i = 0; i < 3; i++) { Vector2 scale = new Vector2(1 - (time * 0.025f) + i * 0.1f, 1 + (time * 0.025f) - i * 0.1f) * Projectile.scale * (0.7f - (i * 0.05f)); Main.EntitySpriteDraw(tex.Value, placement - Main.screenPosition, null, baseColor with { A = 0 } * 0.5f, Projectile.rotation, tex.Size() * 0.5f, scale, SpriteEffects.None); } return false; } } }