using System; using System.IO; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; using Terraria.GameContent; using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Melee { public class MawOfInfinityJaws : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Melee"; public override string Texture => "CalamityMod/Particles/Jaws"; public int time = 0; public override void SetDefaults() { Projectile.width = 500; Projectile.height = 500; Projectile.DamageType = DamageClass.Melee; Projectile.ignoreWater = true; Projectile.penetrate = -1; Projectile.timeLeft = 35; Projectile.alpha = 100; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 10; } public override void SendExtraAI(BinaryWriter writer) { writer.WriteVector2(GoalPos); writer.WriteVector2(StartPos); } public override void ReceiveExtraAI(BinaryReader reader) { GoalPos = reader.ReadVector2(); StartPos = reader.ReadVector2(); } Vector2 GoalPos = Vector2.Zero; Vector2 StartPos = Vector2.Zero; float offset = 0; public override void AI() { var player = Main.player[Projectile.owner]; if (GoalPos == Vector2.Zero) { GoalPos = player.Calamity().mouseWorld; StartPos = Projectile.Center; Projectile.netUpdate = true; } Projectile.Center = Vector2.Lerp(StartPos, GoalPos, MathHelper.Min(1,MathF.Pow(1 - (Projectile.timeLeft - 5) / 30f,0.5f))); Projectile.rotation = StartPos.DirectionTo(GoalPos).ToRotation(); offset = 200*MathHelper.Min(MathF.Pow(1-(Projectile.timeLeft-5)/30f,0.4f), (Projectile.timeLeft - 5) / 5f); if (offset < 16) offset = 16; if (Projectile.timeLeft == 5) { Projectile.friendly = true; SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/NPCKilled/DevourerSegmentBreak1") { Volume = 0.3f, PitchVariance = 0.3f }, Projectile.position); SoundEngine.PlaySound(SoundID.Item62 with { Volume = 0.5f, PitchVariance = 0.3f }, Projectile.position); for (int i = 0; i < 35; i++) { Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.GiantCursedSkullBolt, new Vector2(4.5f, 4.5f).RotatedByRandom(100) * Main.rand.NextFloat(0.2f, 1.9f), 0, default, Main.rand.NextFloat(1.5f, 2.8f)); dust.shader = GameShaders.Armor.GetSecondaryShader(player.cShield, player); dust.noGravity = true; } for (int j = 0; j < 14; j++) { Vector2 dustVel = new Vector2(6, 6).RotatedByRandom(100) * Main.rand.NextFloat(0.5f, 1.2f); Dust dust = Dust.NewDustPerfect(Projectile.Center + dustVel * 2, DustID.WitherLightning, dustVel, 0, default, 1f); dust.shader = GameShaders.Armor.GetSecondaryShader(player.cShield, player); Dust dust2 = Dust.NewDustPerfect(Projectile.Center + dustVel * 2, DustID.Electric, dustVel, 0, default, 1f); dust.shader = GameShaders.Armor.GetSecondaryShader(player.cShield, player); } if (Main.LocalPlayer.Distance(Projectile.Center) < 1600) Main.LocalPlayer.SetScreenshake(5f); Particle pulse = new DirectionalPulseRing(Projectile.Center, Vector2.Zero, Color.Aqua, new Vector2(2f, 2f), 0, 0.2f, 1.7f, 36); GeneralParticleHandler.SpawnParticle(pulse); Particle explosion2 = new DetailedExplosion(Projectile.Center, Vector2.Zero, Color.Magenta, Vector2.One, Main.rand.NextFloat(-5, 5), 0f, 1.3f, 26); GeneralParticleHandler.SpawnParticle(explosion2); } time++; } public override bool OnTileCollide(Vector2 oldVelocity) { Projectile.tileCollide = false; if (Projectile.timeLeft > 85) { Projectile.timeLeft = 85; } return false; } public override Color? GetAlpha(Color lightColor) { if (Projectile.timeLeft < 85) { byte b2 = (byte)(Projectile.timeLeft * 3); byte a2 = (byte)(100f * ((float)b2 / 255f)); return new Color((int)b2, (int)b2, (int)b2, (int)a2); } return default(Color); } public override bool PreDraw(ref Color lightColor) { var tex = TextureAssets.Projectile[Type].Value; float jawScaleMult = 1f + (0.007f * time); jawScaleMult = MathF.Pow(jawScaleMult, 3); float rotationOff = 0.5f * MathHelper.Min(MathF.Pow(MathHelper.Clamp(1 - (Projectile.timeLeft - 5) / 30f,0,1),0.5f), MathF.Pow(MathHelper.Clamp((Projectile.timeLeft - 5) / 10f,0,1),0.5f)); if (rotationOff < 0.01f) rotationOff = 0.01f; float drawRot = Projectile.rotation; Main.spriteBatch.SetBlendState(BlendState.Additive); Main.spriteBatch.Draw(tex, Projectile.Center + new Vector2(0, offset).RotatedBy(drawRot) - Main.screenPosition, tex.Frame(2, 1, 0, 0), Color.Fuchsia, Projectile.rotation + rotationOff + MathHelper.PiOver2, new Vector2(tex.Width * 0.25f, tex.Height * 0.5f), jawScaleMult, Projectile.spriteDirection == -1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0); Main.spriteBatch.Draw(tex, Projectile.Center + new Vector2(0, -offset).RotatedBy(drawRot) - Main.screenPosition, tex.Frame(2, 1, 1, 0), Color.Aqua, Projectile.rotation - rotationOff + MathHelper.PiOver2, new Vector2(tex.Width * 0.25f, tex.Height * 0.5f), jawScaleMult, Projectile.spriteDirection == -1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0); Main.spriteBatch.SetBlendState(BlendState.AlphaBlend); return false; } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { target.AddBuff(ModContent.BuffType(), 360); } } }