diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 610df8f528..c8dbefa58a 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -136,6 +136,7 @@ namespace CalamityMod.CalPlayer public bool GivenBrimstoneLocus = false; public DoGCartSegment[] DoGCartSegments = new DoGCartSegment[DoGCartMount.SegmentCount]; public float SmoothenedMinecartRotation; + public bool LungingDown = false; #endregion #region IL Editing Constants @@ -2562,6 +2563,7 @@ namespace CalamityMod.CalPlayer potionTimer = 0; bloodflareCoreLostDefense = 0; persecutedEnchantSummonTimer = 0; + LungingDown = false; if (BossRushEvent.BossRushActive) { diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index ff505ef68e..09d7f446a6 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -1094,15 +1094,16 @@ namespace CalamityMod.CalPlayer player.maxFallSpeed = 15f; if (gSabatonFall > 0 || player.PortalPhysicsEnabled) player.maxFallSpeed = 20f; - if (player.HeldItem.modItem is TrueBiomeBlade blade) - { - if (blade.strongLunge) - { - player.maxFallSpeed = 80f; - player.noFallDmg = true; - } - } } + + if (LungingDown) + { + player.maxFallSpeed = 80f; + player.noFallDmg = true; + } + + + } // Omega Blue Armor bonus diff --git a/Items/Weapons/Melee/OmegaBiomeBlade.cs b/Items/Weapons/Melee/OmegaBiomeBlade.cs index 79b9805a5e..d7d8977246 100644 --- a/Items/Weapons/Melee/OmegaBiomeBlade.cs +++ b/Items/Weapons/Melee/OmegaBiomeBlade.cs @@ -24,7 +24,7 @@ namespace CalamityMod.Items.Weapons.Melee public Attunement? mainAttunement = null; public Attunement? secondaryAttunement = null; public int Combo = 0; - public bool strongLunge = false; + public int UseTimer = 0; public override void SetStaticDefaults() { @@ -104,7 +104,7 @@ namespace CalamityMod.Items.Weapons.Melee AttunementInfo.name = "Swordsmith's Pride"; AttunementInfo.function_description = "Hold LMB to swing the sword around you, powering up as it spins. Extra ghostly swords are summoned during the spin"; AttunementInfo.function_extra = "Releasing LMB during a spin will throw the sword out. Ghostly swords will home onto enemies hit by the sword throw"; - AttunementInfo.function_passive = "IDK"; + AttunementInfo.function_passive = "While attacking, extra ghost swords have a chance to be shot out"; AttunementInfo.color = new Color(188, 155, 185); AttunementInfo.color2 = new Color(204, 184, 144); break; @@ -112,7 +112,7 @@ namespace CalamityMod.Items.Weapons.Melee AttunementInfo.name = "Sanguine Fury"; AttunementInfo.function_description = "Conjures molten blades in front of you that get larger and stronger the more you hit enemies. The blades can also be used to bounce off tiles when in the air"; AttunementInfo.function_extra = "Releasing LMB sends the charged blades flying in a wheel. Using LMB right after the throw makes the player perform dash towards the blade wheel, shredding anything inbetween"; - AttunementInfo.function_passive = "IDK"; + AttunementInfo.function_passive = "Successful strikes rarely grant lifesteal"; AttunementInfo.color = new Color(216, 55, 22); AttunementInfo.color2 = new Color(216, 131, 22); break; @@ -120,7 +120,7 @@ namespace CalamityMod.Items.Weapons.Melee AttunementInfo.name = "Mercurial Tides"; AttunementInfo.function_description = "Hold LMB to charge up a heaven-shattering sword thrust, and release to unleash the devastating blow. Small shockwaves are released as you charge the sword"; AttunementInfo.function_extra = "Striking the ground after a jump will create an impact so powerful, a shockwave of ancient monoliths will rise up and propagate through the ground"; - AttunementInfo.function_passive = "IDK"; + AttunementInfo.function_passive = "While attacking, release small shockwaves around you"; AttunementInfo.color = new Color(132, 109, 233); AttunementInfo.color2 = new Color(122, 213, 233); break; @@ -128,7 +128,7 @@ namespace CalamityMod.Items.Weapons.Melee AttunementInfo.name = "Lamentations of the Chained"; AttunementInfo.function_description = "Throw out a flurry of chained blades in front of you. Striking enemies with the tip of the blades guarantees a critical hit."; AttunementInfo.function_extra = "Critical strikes create extra ghostly chains to latch onto extra targets or onto the struck foe"; - AttunementInfo.function_passive = "IDK"; + AttunementInfo.function_passive = "Gain a magical chain hook. On enemy hits the hook quickly spins around you, freezing any struck foe"; //No way sentient meat hook AttunementInfo.color = new Color(127, 173, 168); AttunementInfo.color2 = new Color(203, 201, 168); break; @@ -246,9 +246,13 @@ namespace CalamityMod.Items.Weapons.Melee { player.Calamity().rightClickListener = true; + UseTimer++; //Reset the strong lunge thing just in case it didnt get caught beofre. if (CanUseItem(player)) - strongLunge = false; + { + player.Calamity().LungingDown = false; + UseTimer = 0; + } //Change the swords function based on its attunement switch (mainAttunement) @@ -275,7 +279,7 @@ namespace CalamityMod.Items.Weapons.Melee item.channel = true; item.noUseGraphic = true; item.useStyle = ItemUseStyleID.HoldingOut; - item.shoot = ProjectileType(); + item.shoot = ProjectileType(); item.shootSpeed = 12f; item.UseSound = null; item.noMelee = true; @@ -298,6 +302,23 @@ namespace CalamityMod.Items.Weapons.Melee break; } + switch (secondaryAttunement) + { + case Attunement.Whirlwind: + break; + case Attunement.SuperPogo: + break; + case Attunement.Shockwave: + if (UseTimer % 120 == 119) + Projectile.NewProjectile(player.Center, Vector2.Zero, ProjectileType(), (int)(item.damage * 0.6f), 10f, player.whoAmI, 1f); + break; + case Attunement.FlailBlade: + break; + default: + break; + } + + if (player.Calamity().mouseRight && CanUseItem(player) && player.whoAmI == Main.myPlayer && !Main.mapFullscreen) { //Don't shoot out a visual blade if you already have one out @@ -310,12 +331,12 @@ namespace CalamityMod.Items.Weapons.Melee public override bool CanUseItem(Player player) { - return true; - //!Main.projectile.Any(n => n.active && n.owner == player.whoAmI && - //(n.type == ProjectileType() || - // n.type == ProjectileType() || + return !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && + (n.type == ProjectileType() || + n.type == ProjectileType() //|| // n.type == ProjectileType() || - // n.type == ProjectileType())); + // n.type == ProjectileType() + )); } diff --git a/Items/Weapons/Melee/TrueBiomeBlade.cs b/Items/Weapons/Melee/TrueBiomeBlade.cs index 1c309431a4..2d2d61a864 100644 --- a/Items/Weapons/Melee/TrueBiomeBlade.cs +++ b/Items/Weapons/Melee/TrueBiomeBlade.cs @@ -26,7 +26,6 @@ namespace CalamityMod.Items.Weapons.Melee public int Combo = 0; public int StoredLunges = 2; public int PowerLungeCounter = 0; - public bool strongLunge = false; public override void SetStaticDefaults() { DisplayName.SetDefault("Biome Blade"); @@ -265,7 +264,7 @@ namespace CalamityMod.Items.Weapons.Melee //Reset the strong lunge thing just in case it didnt get caught beofre. if (CanUseItem(player)) - strongLunge = false; + player.Calamity().LungingDown = false; //Change the swords function based on its attunement switch (mainAttunement) @@ -404,8 +403,6 @@ namespace CalamityMod.Items.Weapons.Melee public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - strongLunge = false; - if (mainAttunement == null) return false; diff --git a/Particles/BloomRing.cs b/Particles/BloomRing.cs new file mode 100644 index 0000000000..cba140f7c4 --- /dev/null +++ b/Particles/BloomRing.cs @@ -0,0 +1,43 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class BloomRing : Particle + { + public override string Texture => "CalamityMod/Particles/BloomRing"; + public override bool UseAdditiveBlend => true; + public override bool SetLifetime => true; + + private float opacity; + private Color BaseColor; + + public BloomRing(Vector2 position, Vector2 velocity, Color color, float scale, int lifeTime) + { + Position = position; + Velocity = velocity; + BaseColor = color; + Scale = scale; + Lifetime = lifeTime; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + } + + public override void Update() + { + opacity = (float)Math.Sin(MathHelper.PiOver2 + LifetimeCompletion * MathHelper.PiOver2); + Color = BaseColor * opacity; + Lighting.AddLight(Position, Color.R / 255f, Color.G / 255f, Color.B / 255f); + Velocity *= 0.95f; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D tex = GeneralParticleHandler.GetTexture(Type); + + spriteBatch.Draw(tex, Position - Main.screenPosition, null, Color * opacity, Rotation, tex.Size() / 2f, Scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/BloomRing.png b/Particles/BloomRing.png new file mode 100644 index 0000000000..d1925865f6 Binary files /dev/null and b/Particles/BloomRing.png differ diff --git a/Projectiles/Melee/MendedBiomeBladeProjectiles.cs b/Projectiles/Melee/MendedBiomeBladeProjectiles.cs index 0e99e544f3..8f139c9106 100644 --- a/Projectiles/Melee/MendedBiomeBladeProjectiles.cs +++ b/Projectiles/Melee/MendedBiomeBladeProjectiles.cs @@ -236,8 +236,8 @@ namespace CalamityMod.Projectiles.Melee if (dashTimer == maxDash) { Owner.velocity *= 0.1f; //Abrupt stop - if (Owner.HeldItem.modItem is TrueBiomeBlade blade) - blade.strongLunge = false; + Owner.Calamity().LungingDown = true; + Projectile proj = Projectile.NewProjectileDirect(Owner.Center + (PowerLungeEnd - PowerLungeStart) / 2f, Vector2.Zero, ProjectileType(), projectile.damage * 2, 0, Owner.whoAmI); if (proj.modProjectile is DecaysRetortDash dash) { @@ -275,8 +275,7 @@ namespace CalamityMod.Projectiles.Melee public void PowerLunge() { - if (Owner.HeldItem.modItem is TrueBiomeBlade blade) - blade.strongLunge = true; + Owner.Calamity().LungingDown = true; PowerLungeStart = Owner.Center; dashTimer = 1f; Owner.GiveIFrames(60); @@ -1940,10 +1939,7 @@ namespace CalamityMod.Projectiles.Melee projectile.Center = Owner.Center + Vector2.Lerp(lastDisplacement, direction * 40f, MathHelper.Clamp(((dashDuration - projectile.timeLeft) / dashDuration) * 2f, 0f, 1f)); Owner.fallStart = (int)(Owner.position.Y / 16f); - if (Owner.HeldItem.modItem is TrueBiomeBlade blade) - { - blade.strongLunge = true; //Needed for the downwards velocity uncap. - } + Owner.Calamity().LungingDown = true; if (Collision.SolidCollision(Owner.Center + (direction * 120 * projectile.scale) - Vector2.One * 5f, 10, 10)) { @@ -2096,10 +2092,7 @@ namespace CalamityMod.Projectiles.Melee if (State == 1f) Owner.velocity *= 0.33f; - if (Owner.HeldItem.modItem is TrueBiomeBlade blade) - { - blade.strongLunge = false; //Needed for the downwards velocity uncap. - } + Owner.Calamity().LungingDown = false; projectile.active = false; } diff --git a/Projectiles/Melee/TrueBiomeBladeProjectiles.cs b/Projectiles/Melee/TrueBiomeBladeProjectiles.cs new file mode 100644 index 0000000000..bac48dbbb0 --- /dev/null +++ b/Projectiles/Melee/TrueBiomeBladeProjectiles.cs @@ -0,0 +1,1018 @@ +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.CalPlayer; +using CalamityMod.DataStructures; +using CalamityMod.Particles; +using CalamityMod.Items.Weapons.Melee; +using Terraria.Graphics.Shaders; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using static Terraria.ModLoader.ModContent; +using static CalamityMod.CalamityUtils; +using Terraria.Audio; + +namespace CalamityMod.Projectiles.Melee +{ + public class SwordsmithsPride : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_HeavensMight"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + Vector2 oldDirection = Vector2.Zero; + public ref float CurrentState => ref projectile.ai[0]; + public Player Owner => Main.player[projectile.owner]; + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + public const float throwOutTime = 90f; + public const float throwOutDistance = 440f; + + public static float snapPoint = 0.45f; + public float snapTimer => (throwTimer / throwOutTime) < snapPoint ? 0 : ((throwTimer / throwOutTime) - snapPoint) / (1f - snapPoint); + public static float retractionPoint = 0.6f; + public float retractionTimer => (throwTimer / throwOutTime) < retractionPoint ? 0 : ((throwTimer / throwOutTime) - retractionPoint) / (1f - retractionPoint); + public ref float Empowerment => ref projectile.ai[1]; + public ref float hasMadeSound => ref projectile.localAI[0]; + public ref float hasMadeChargeSound => ref projectile.localAI[1]; + + public const float maxEmpowerment = 600f; + //How much damage reduction applies on uncharged attacks + public const float initialDamage = 0.2f; + //How much extra damage applies when fully charged. This goes ontop of the initial damage, so a max empowerment boost of 2 with an initial damage of 0.1 makes the total damage multiplier be 1.9 + public float maxEmpowermentBoost = 2f; + public float throwTimer => throwOutTime - projectile.timeLeft; + + public Particle smear; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Heaven's Might"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 10; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 74; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 16; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 100 * projectile.scale; + float bladeWidth = 20 * projectile.scale; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + (direction * bladeLenght), bladeWidth, ref collisionPoint); + } + + + public CurveSegment launch = new CurveSegment(EasingType.CircOut, 0f, 0f, 1f, 4); + public CurveSegment hold = new CurveSegment(EasingType.Linear, snapPoint, 1f, 0f); + public CurveSegment retract = new CurveSegment(EasingType.PolyInOut, retractionPoint, 1f, -1.05f, 3); + internal float ThrowCurve() => PiecewiseAnimation((throwOutTime - projectile.timeLeft) / throwOutTime, new CurveSegment[] { launch, hold, retract }); + + public override void AI() + { + if (!initialized) //Initialization. Here its litterally just playing a sound tho lmfao + { + Main.PlaySound(SoundID.Item90, projectile.Center); + projectile.velocity = Vector2.Zero; + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + oldDirection = direction; + initialized = true; + } + + projectile.rotation = direction.ToRotation(); //Only done for afterimages + + if (!OwnerCanShoot) + { + if (CurrentState == 2f || (CurrentState == 0f && Empowerment / maxEmpowerment < 0.5)) + { + Main.PlaySound(SoundID.Item77, projectile.Center); + projectile.Kill(); + return; + } + + else if (CurrentState == 0f) + { + CurrentState = 1f; + Main.PlaySound(SoundID.Item80, projectile.Center); + direction = Owner.DirectionTo(Main.MouseWorld); + //PARTICLES LOTS OF PARTICLES LOTS OF SPARKLES YES YES MH YES YES + for (int i = 0; i <= 8; i++) + { + float variation = Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4); + float strength = (float)Math.Sin(variation * 2f + MathHelper.PiOver2); + Particle Sparkle = new CritSpark(projectile.Center, Owner.velocity + direction.RotatedBy(variation) * (1 + strength) * 2f * Main.rand.NextFloat(7.5f, 20f), Color.White, Color.HotPink, 2f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + for (int i = 0; i <= 8; i++) + { + float variation = Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4); + float strength = (float)Math.Sin(variation * 2f + MathHelper.PiOver2); + Particle Sparkle = new CritSpark(projectile.Center, Owner.velocity + direction.RotatedBy(variation) * (1 + strength) * Main.rand.NextFloat(7.5f, 20f), Color.White, Color.Cyan, 2f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + } + + if (CurrentState == 0f) + { + if (Owner.whoAmI == Main.myPlayer) + { + if (hasMadeChargeSound == 0f && Empowerment / maxEmpowerment >= 0.5) + { + hasMadeChargeSound = 1f; + Main.PlaySound(SoundID.Item76); + } + + float rotation = direction.ToRotation(); + if (rotation > -MathHelper.PiOver2 - MathHelper.PiOver4 && rotation < -MathHelper.PiOver2 + MathHelper.PiOver4 && hasMadeSound == 1f) + hasMadeSound = 0f; + + else if (rotation > MathHelper.PiOver2 - MathHelper.PiOver4 && rotation < MathHelper.PiOver2 + MathHelper.PiOver4 && hasMadeSound == 0f) + { + hasMadeSound = 1f; + Main.PlaySound(SoundID.Item71); + } + } + + if (Empowerment / maxEmpowerment >= 0.75) + { + if (smear == null) + { + smear = new CircularSmearVFX(Owner.Center, Color.HotPink, direction.ToRotation(), projectile.scale * 1.5f); + GeneralParticleHandler.SpawnParticle(smear); + } + //Update the variables of the smear + else + { + smear.Rotation = direction.ToRotation() + MathHelper.PiOver2; + smear.Time = 0; + smear.Position = Owner.Center; + smear.Scale = projectile.scale * 1.5f; + smear.Color = Color.Lerp(Color.HotPink, Color.Cyan, (float)Math.Sin(Main.GlobalTime * 2f)) * (((Empowerment / maxEmpowerment) - 0.75f) / 0.25f * 0.8f); + } + } + + + //Manage position and rotation + projectile.scale = 1 + Empowerment / maxEmpowerment * 1.5f; + + oldDirection = direction; + direction = direction.RotatedBy(MathHelper.Clamp(Empowerment / maxEmpowerment, 0.4f, 1f) * MathHelper.PiOver4 * 0.20f); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + projectile.Center = Owner.Center + (direction * projectile.scale * 10); + projectile.timeLeft = (int)throwOutTime + 1; + Empowerment++; + if (Empowerment > maxEmpowerment) + Empowerment = maxEmpowerment; + } + + if (CurrentState == 1f) + { + projectile.Center = Owner.Center + (direction * projectile.scale * 10) + (direction * throwOutDistance * ThrowCurve()); + projectile.scale = (1 + Empowerment / maxEmpowerment * 1.5f) * MathHelper.Clamp(1 - retractionTimer, 0.3f, 1f); + } + + //Make the owner look like theyre holding the sword bla bla + Owner.heldProj = projectile.whoAmI; + Owner.direction = Math.Sign(direction.X); + Owner.itemRotation = direction.ToRotation(); + if (Owner.direction != 1) + { + Owner.itemRotation -= 3.14f; + } + Owner.itemRotation = MathHelper.WrapAngle(Owner.itemRotation); + Owner.itemTime = 2; + Owner.itemAnimation = 2; + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + damage = (int)(damage * (initialDamage + (maxEmpowermentBoost * Empowerment / maxEmpowerment))); + } + + public override void Kill(int timeLeft) + { + if (smear != null) + smear.Kill(); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/TrueBiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_HeavensMight"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = projectile.Center - Main.screenPosition; + + //Afterimages + if (CalamityConfig.Instance.Afterimages && CurrentState == 0f && Empowerment / maxEmpowerment > 0.4f) + { + for (int i = 0; i < projectile.oldRot.Length; ++i) + { + Color color = projectile.GetAlpha(lightColor) * (1f - (i / (float)projectile.oldRot.Length)); + float afterimageRotation = projectile.oldRot[i] + MathHelper.PiOver4; + Main.spriteBatch.Draw(handle, drawOffset, null, color * MathHelper.Lerp(0f, 0.5f, MathHelper.Clamp(Empowerment / maxEmpowerment - 0.4f / 0.1f, 0f, 1f)), afterimageRotation, drawOrigin, projectile.scale - 0.2f * ((i / (float)projectile.oldRot.Length)), 0f, 0f); + } + + spriteBatch.End(); //Haha sup babe what if i restarted the spritebatch way too many times haha /blushes + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Vector2 afterimageDrawOrigin = new Vector2(0f, blade.Height); + for (int i = 0; i < projectile.oldRot.Length; ++i) + { + Color color = projectile.GetAlpha(lightColor) * (1f - (i / (float)projectile.oldRot.Length)); + float afterimageRotation = projectile.oldRot[i] + MathHelper.PiOver4; + Main.spriteBatch.Draw(blade, drawOffset, null, color * MathHelper.Lerp(0f, 0.5f, MathHelper.Clamp((Empowerment / maxEmpowerment - 0.4f) / 0.1f, 0f, 1f)), afterimageRotation, afterimageDrawOrigin, projectile.scale - 0.2f * ((i / (float)projectile.oldRot.Length)), 0f, 0f); + } + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + } + + + spriteBatch.Draw(handle, drawOffset, null, lightColor, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + //Turn on additive blending + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + //Update the parameters + drawOrigin = new Vector2(0f, blade.Height); + + //Don't draw the glowing blade after the retraction + float opacityFade = CurrentState == 0f ? 1f : 1f - retractionTimer; + //Add basic tint (my beloved) during the snap + if (snapTimer > 0 && retractionTimer <= 0) + { + GameShaders.Misc["CalamityMod:BasicTint"].UseOpacity(MathHelper.Clamp(0.8f - snapTimer, 0f, 1f)); + GameShaders.Misc["CalamityMod:BasicTint"].UseColor(Color.White); + GameShaders.Misc["CalamityMod:BasicTint"].Apply(); + } + + spriteBatch.Draw(blade, drawOffset, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.9f * opacityFade, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + if (CurrentState == 1f && snapTimer > 0) + { + drawChain(spriteBatch, snapTimer, retractionTimer); + } + + //Back to normal + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + return false; + } + + public void drawChain(SpriteBatch spriteBatch, float snapProgress, float retractProgress) + { + Texture2D chainTex = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_HeavensMightChain"); + + float opacity = retractProgress < 0.5 ? 1 : (retractProgress - 0.5f) / 0.5f; + + Vector2 Shake = retractProgress > 0 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (1f - snapProgress) * 10f; + + int dist = (int)Vector2.Distance(Owner.Center, projectile.Center) / 16; + Vector2[] Nodes = new Vector2[dist + 1]; + Nodes[0] = Owner.Center; + Nodes[dist] = projectile.Center; + + for (int i = 1; i < dist + 1; i++) + { + Rectangle frame = new Rectangle(0, 0 + 18 * (i % 2), 12, 18); + Vector2 positionAlongLine = Vector2.Lerp(Owner.Center, projectile.Center, i / (float)dist); //Get the position of the segment along the line, as if it were a flat line + Nodes[i] = positionAlongLine + Shake * (float)Math.Sin(i / (float)dist * MathHelper.Pi); + + float rotation = (Nodes[i] - Nodes[i - 1]).ToRotation() - MathHelper.PiOver2; //Calculate rotation based on direction from last point + float yScale = Vector2.Distance(Nodes[i], Nodes[i - 1]) / frame.Height; //Calculate how much to squash/stretch for smooth chain based on distance between points + Vector2 scale = new Vector2(1, yScale); + + Color chainLightColor = Lighting.GetColor((int)Nodes[i].X / 16, (int)Nodes[i].Y / 16); //Lighting of the position of the chain segment + + Vector2 origin = new Vector2(frame.Width / 2, frame.Height); //Draw from center bottom of texture + spriteBatch.Draw(chainTex, Nodes[i] - Main.screenPosition, frame, chainLightColor * opacity * 0.7f, rotation, origin, scale, SpriteEffects.None, 0); + } + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + } + } + + public class SwordsmithsPrideBeam : ModProjectile //The boring plain one. I need to find something different to make it do compared to the original one. + { + public NPC target; + public Player Owner => Main.player[projectile.owner]; + public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_PurityProjection"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Ghostly projection"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 2; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 32; + projectile.aiStyle = 27; + aiType = ProjectileID.LightBeam; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.timeLeft = 40; + projectile.extraUpdates = 1; + projectile.melee = true; + projectile.tileCollide = false; + } + + public override void AI() + { + + if (target == null) + { + foreach (Projectile proj in Main.projectile) + { + if (proj.active && proj.type == ProjectileType() && proj.owner == Owner.whoAmI) + { + target = Main.npc[(int)proj.ai[0]]; + break; + } + } + } + else if ((projectile.Center - target.Center).Length() >= (projectile.Center + projectile.velocity - target.Center).Length() && CalamityUtils.AngleBetween(projectile.velocity, target.Center - projectile.Center) < MathHelper.PiOver4 * 0.5f) //Home in + { + projectile.timeLeft = 30; //Remain alive + float angularTurnSpeed = MathHelper.ToRadians(MathHelper.Lerp(12.5f, 2.5f, MathHelper.Clamp(projectile.Distance(target.Center) / 10f, 0f, 1f))); + float idealDirection = projectile.AngleTo(target.Center); + float updatedDirection = projectile.velocity.ToRotation().AngleTowards(idealDirection, angularTurnSpeed); + projectile.velocity = updatedDirection.ToRotationVector2() * projectile.velocity.Length(); + } + + if (projectile.timeLeft < 35) + projectile.tileCollide = true; + + Lighting.AddLight(projectile.Center, 0.75f, 1f, 0.24f); + int dustParticle = Dust.NewDust(projectile.position, projectile.width, projectile.height, DustID.CursedTorch, 0f, 0f, 100, default, 0.9f); + Main.dust[dustParticle].noGravity = true; + Main.dust[dustParticle].velocity *= 0.5f; + Main.dust[dustParticle].velocity += projectile.velocity * 0.1f; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (projectile.timeLeft > 35) + return false; + + DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); + return false; + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.Item43, projectile.Center); + for (int i = 0; i <= 15; i++) + { + Vector2 displace = (projectile.rotation - MathHelper.PiOver4).ToRotationVector2() * (-0.5f + (i / 15f)) * 88f; + int dustParticle = Dust.NewDust(projectile.Center + displace, projectile.width, projectile.height, DustID.CursedTorch, 0f, 0f, 100, default, 2f); + Main.dust[dustParticle].noGravity = true; + Main.dust[dustParticle].velocity = projectile.oldVelocity; + } + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + int debuffTime = 90; + target.AddBuff(BuffType(), debuffTime); + } + } + + public class MercurialTides : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_MercurialTides"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public Player Owner => Main.player[projectile.owner]; + public ref float Charge => ref projectile.ai[0]; //Charge + public ref float State => ref projectile.ai[1]; //State 0 is "charging", State 1 is "thrusting" + public ref float CurrentIndicator => ref projectile.localAI[0]; //What "indicator" stage are you on. + public ref float OverCharge => ref projectile.localAI[1]; + + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + const float MaxCharge = 500; + + public Vector2 lastDisplacement; + public float dashDuration; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Mercurial Tides"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 70; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 16; + } + + public override bool CanDamage() + { + return (State == 1); + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 120 * projectile.scale; + float bladeWidth = 20 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center, Owner.Center + (direction * bladeLenght), bladeWidth, ref collisionPoint); + } + + public CurveSegment QuickOut = new CurveSegment(EasingType.PolyIn, 0f, 0f, 0.2f, 3); + public CurveSegment Bump = new CurveSegment(EasingType.SineBump, 0.06f, 0.2f, 0.1f); + public CurveSegment QuickDraw = new CurveSegment(EasingType.Linear, 0.25f, 0.2f, -0.45f); + public CurveSegment SlowDrawOut = new CurveSegment(EasingType.PolyIn, 0.50f, -0.25f, -0.2f, 3); + public CurveSegment OverShoot = new CurveSegment(EasingType.SineBump, 0.93f, -0.45f, -0.1f); + + internal float ChargeDisplacement() => PiecewiseAnimation(Charge / MaxCharge, new CurveSegment[] { QuickOut, Bump, QuickDraw, SlowDrawOut, OverShoot }); + + public override void AI() + { + if (!initialized) //Initialization. Here its litterally just playing a sound tho lmfao + { + projectile.velocity = Vector2.Zero; + Main.PlaySound(SoundID.Item101, projectile.Center); + initialized = true; + } + + if (!OwnerCanShoot) + { + if (State == 0f) + { + if (Charge / MaxCharge < 0.25f) + { + Main.PlaySound(SoundID.Item109, projectile.Center); + projectile.Kill(); + return; + } + else + { + + var dashSound = Main.PlaySound(SoundID.Item120, projectile.Center); + if (dashSound != null) + dashSound.Volume *= 0.5f; + State = 1f; + projectile.timeLeft = (7 + (int)((Charge / MaxCharge - 0.25f) * 20)) * 2; //Keep that even, if its an odd number itll fuck off and wont reset the players velocity on death + dashDuration = projectile.timeLeft; + lastDisplacement = projectile.Center - Owner.Center; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + } + } + + if (State == 0f) + { + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.Center = Owner.Center + (direction * 70f * ChargeDisplacement()); + + Charge++; + OverCharge--; + projectile.timeLeft = 2; + if ((Charge / MaxCharge >= 0.25f && CurrentIndicator == 0f) || (Charge / MaxCharge >= 0.5f && CurrentIndicator == 1f) || (Charge / MaxCharge >= 0.75f && CurrentIndicator == 2f)) + { + + Projectile.NewProjectile(Owner.Center, Vector2.Zero, ProjectileType(), (int)(projectile.damage * 0.6f), 10f, Owner.whoAmI, 1f + CurrentIndicator * 0.15f); + Main.PlaySound(SoundID.DD2_WitherBeastAuraPulse, projectile.Center); + CurrentIndicator++; + OverCharge = 20f; + } + + if (Charge >= MaxCharge) + { + Charge = MaxCharge; + if (Owner.whoAmI == Main.myPlayer && CurrentIndicator < 4f) + { + + Projectile.NewProjectile(Owner.Center, Vector2.Zero, ProjectileType(), (int)(projectile.damage * 0.6f), 10f, Owner.whoAmI, 1f + CurrentIndicator * 0.15f); + OverCharge = 20f; + Main.PlaySound(mod.GetLegacySoundSlot(Terraria.ModLoader.SoundType.Custom, "Sounds/Custom/CorvinaScream"), projectile.Center); + CurrentIndicator++; + } + } + } + + if (State == 1f) + { + projectile.Center = Owner.Center + Vector2.Lerp(lastDisplacement, direction * 40f, MathHelper.Clamp(((dashDuration - projectile.timeLeft) / dashDuration) * 2f, 0f, 1f)); + Owner.fallStart = (int)(Owner.position.Y / 16f); + + Owner.Calamity().LungingDown = true; + + if (Collision.SolidCollision(Owner.Center + (direction * 120 * projectile.scale) - Vector2.One * 5f, 10, 10)) + { + SlamDown(); + projectile.timeLeft = 0; + projectile.active = false; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + Owner.velocity = direction * 30f; + + float variation = Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4); + float strength = (float)Math.Sin(variation * 2f + MathHelper.PiOver2); + Particle Sparkle = new CritSpark(projectile.Center, Owner.velocity - direction.RotatedBy(variation) * (1 + strength) * 2f * Main.rand.NextFloat(7.5f, 20f), Color.White, Main.rand.NextBool() ? Color.MediumTurquoise : Color.DarkOrange, 0.1f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + Lighting.AddLight(projectile.Center, new Vector3(1f, 0.56f, 0.56f) * Charge / MaxCharge); + + //Manage position and rotation + projectile.rotation = direction.ToRotation(); + + //Scaling based on charge + projectile.scale = 1f + (Charge / MaxCharge * 0.3f); + + Owner.direction = Math.Sign(direction.X); + Owner.itemRotation = direction.ToRotation(); + + if (Owner.direction != 1) + { + Owner.itemRotation -= 3.14f; + } + + Owner.itemRotation = MathHelper.WrapAngle(Owner.itemRotation); + Owner.itemTime = 2; + Owner.itemAnimation = 2; + } + + public void SlamDown() + { + var slamSound = Main.PlaySound(SoundID.DD2_MonkStaffGroundImpact, projectile.Center); + if (slamSound != null) + slamSound.Volume *= 1.5f; + + if (Owner.whoAmI != Main.myPlayer || Owner.velocity.Y == 0f) + return; + + if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < 5) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = 5; + + Projectile.NewProjectile(Owner.Center + (direction * 120 * projectile.scale), -direction, ProjectileType(), projectile.damage * 2, 10f, Owner.whoAmI, Main.rand.Next(4), 1f); + + SideSprouts(1, 150f, 1f * Charge / MaxCharge); + SideSprouts(-1, 150f, 1f * Charge / MaxCharge); + + } + + public bool SideSprouts(float facing, float distance, float projSize) + { + float widestAngle = 0f; + float widestSurfaceAngle = 0f; + bool validPositionFound = false; + for (float i = 0f; i < 1; i += 1 / distance) + { + Vector2 positionToCheck = Owner.Center + (direction * 120 * projectile.scale) + direction.RotatedBy((i * MathHelper.PiOver2 + MathHelper.PiOver4) * facing) * distance; + + if (Main.tile[(int)(positionToCheck.X / 16), (int)(positionToCheck.Y / 16)].IsTileSolidGround()) + widestAngle = i; + + else if (widestAngle != 0) + { + validPositionFound = true; + widestSurfaceAngle = widestAngle; + } + } + + if (validPositionFound) + { + Vector2 projPosition = Owner.Center + (direction * 120 * projectile.scale) + direction.RotatedBy((widestSurfaceAngle * MathHelper.PiOver2 + MathHelper.PiOver4) * facing) * distance; + Vector2 monolithRotation = direction.RotatedBy(Utils.AngleLerp(widestSurfaceAngle * -facing, 0f, projSize)); + Projectile proj = Projectile.NewProjectileDirect(projPosition, -monolithRotation, ProjectileType(), projectile.damage * 2, 10f, Owner.whoAmI, Main.rand.Next(4), projSize); + if (proj.modProjectile is MercurialTidesMonolith monolith) + { + monolith.WaitTimer = (1 - projSize) * 34f; + monolith.OriginDirection = direction; + monolith.Facing = facing; + } + } + + return validPositionFound; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + Owner.GiveIFrames(30); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + damage = (int)(damage * (1f + Charge / MaxCharge)); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/OmegaBiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_MercurialTides"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = projectile.Center - Main.screenPosition; + + spriteBatch.Draw(handle, drawOffset, null, lightColor, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + //Turn on additive blending + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + //Just in case + if (OverCharge < 0) + OverCharge = 0f; + //When the blink is + GameShaders.Misc["CalamityMod:BasicTint"].UseOpacity(OverCharge / 20f); + GameShaders.Misc["CalamityMod:BasicTint"].UseColor(new Color(154, 244, 240)); + GameShaders.Misc["CalamityMod:BasicTint"].Apply(); + + //Update the parameters + drawOrigin = new Vector2(0f, blade.Height); + + spriteBatch.Draw(blade, drawOffset, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.9f, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + //Back to normal + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + return false; + } + + public override void Kill(int timeLeft) + { + //Cut the velocity short if dashing + if (State == 1f) + Owner.velocity *= 0.33f; + + Owner.Calamity().LungingDown = false; + + projectile.active = false; + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + writer.Write(CurrentIndicator); + writer.WriteVector2(lastDisplacement); + writer.Write(dashDuration); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + CurrentIndicator = reader.ReadSingle(); + lastDisplacement = reader.ReadVector2(); + dashDuration = reader.ReadSingle(); + } + } + + public class MercurialTidesMonolith : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_MercurialTidesMonolith"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => (100f - projectile.timeLeft) / 100f; + public ref float Variant => ref projectile.ai[0]; //Yes + public ref float Size => ref projectile.ai[1]; //Yes + public float WaitTimer; //How long until the monoliths appears + public Vector2 OriginDirection; //The direction of the original strike + public float Facing; //The direction of the original strike + public const float BaseWidth = 90f; + public const float BaseHeight = 420f; + + public CurveSegment StaySmall = new CurveSegment(EasingType.Linear, 0f, 0.2f, 0f); + public CurveSegment GoBig = new CurveSegment(EasingType.SineOut, 0.25f, 0.2f, 1f); + public CurveSegment GoNormal = new CurveSegment(EasingType.CircIn, 0.4f, 1.2f, -0.2f); + public CurveSegment StayNormal = new CurveSegment(EasingType.Linear, 0.5f, 1f, 0f); + + internal float Width() => PiecewiseAnimation(Timer, new CurveSegment[] { StaySmall, GoBig, GoNormal, StayNormal }) * BaseWidth * Size; + + public CurveSegment Anticipate = new CurveSegment(EasingType.CircIn, 0f, 0f, 0.15f); + public CurveSegment Overextend = new CurveSegment(EasingType.SineOut, 0.2f, 0.15f, 1f); + public CurveSegment Unextend = new CurveSegment(EasingType.CircIn, 0.25f, 1.15f, -0.15f); + public CurveSegment Hold = new CurveSegment(EasingType.ExpOut, 0.70f, 1f, -0.1f); + internal float Height() => PiecewiseAnimation(Timer, new CurveSegment[] { Anticipate, Overextend, Unextend, Hold }) * BaseHeight * Size; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Mercurial Monolith"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 70; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 102; + projectile.hide = true; + } + + public override bool CanDamage() => WaitTimer <= 0; + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + ((projectile.rotation - MathHelper.PiOver2).ToRotationVector2() * Height()), Width(), ref collisionPoint); + } + + public override void DrawBehind(int index, List drawCacheProjsBehindNPCsAndTiles, List drawCacheProjsBehindNPCs, List drawCacheProjsBehindProjectiles, List drawCacheProjsOverWiresUI) + { + drawCacheProjsBehindNPCsAndTiles.Add(index); + } + + public override void AI() + { + if (projectile.velocity != Vector2.Zero) + { + SurfaceUp(); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + projectile.velocity = Vector2.Zero; + } + + if (WaitTimer > 0) + { + projectile.timeLeft = 102; + WaitTimer--; + } + + if (projectile.timeLeft == 100) + { + if (Size >= 1) //Big monoliths create sparkles even before sprouting up + { + + for (int i = 0; i < 20; i++) + { + Particle Sparkle = new CritSpark(projectile.Center, Main.rand.NextVector2Circular(1f, 1f) * Main.rand.NextFloat(7.5f, 20f), Color.White, Main.rand.NextBool() ? Color.MediumTurquoise : Color.DarkOrange, 0.1f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + + if (Size * 0.8 > 0.4 && Facing != 0) + { + SideSprouts(Facing, 150f, Size * 0.8f); + } + } + + if (projectile.timeLeft == 80) + { + Vector2 particleDirection = (projectile.rotation - MathHelper.PiOver2).ToRotationVector2(); + Main.PlaySound(SoundID.DD2_EtherianPortalDryadTouch, projectile.Center); + + for (int i = 0; i < 8; i++) + { + Vector2 hitPositionDisplace = particleDirection.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(0f, 10f); + Vector2 flyDirection = particleDirection.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver2, MathHelper.PiOver2)) * Main.rand.NextFloat(5f, 15f); + Particle smoke = new SmallSmokeParticle(projectile.Center + hitPositionDisplace, flyDirection, Color.Lerp(Color.DarkOrange, Color.MediumTurquoise, Main.rand.NextFloat()), new Color(130, 130, 130), Main.rand.NextFloat(2.8f, 3.6f) * Size, 165 - Main.rand.Next(30), 0.1f); + GeneralParticleHandler.SpawnParticle(smoke); + } + for (int i = 0; i < 6; i++) + { + Vector2 hitPositionDisplace = particleDirection.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(10f, 30f); + Vector2 flyDirection = particleDirection.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)); + + Particle Rock = new StoneDebrisParticle(projectile.Center + hitPositionDisplace * 3, flyDirection * Main.rand.NextFloat(3f, 6f), Color.Lerp(Color.DarkSlateBlue, Color.LightSlateGray, Main.rand.NextFloat()), (1f + Main.rand.NextFloat(0f, 2.4f)) * Size, 30 + Main.rand.Next(50), 0.1f); + GeneralParticleHandler.SpawnParticle(Rock); + } + } + } + + //Go up to the "surface" so you're not stuck in the middle of the ground like a complete moron. + public void SurfaceUp() + { + for (float i = 0; i < 40; i += 0.5f) + { + Vector2 positionToCheck = projectile.Center + projectile.velocity * i; + if (!Main.tile[(int)(positionToCheck.X / 16), (int)(positionToCheck.Y / 16)].IsTileSolidGround()) + { + projectile.Center = projectile.Center + projectile.velocity * i; + return; + } + } + projectile.Center = projectile.Center + projectile.velocity * 40f; + } + + public bool SideSprouts(float facing, float distance, float projSize) + { + float widestAngle = 0f; + float widestSurfaceAngle = 0f; + bool validPositionFound = false; + for (float i = 0f; i < 1; i += 1 / distance) + { + Vector2 positionToCheck = projectile.Center + OriginDirection.RotatedBy((i * MathHelper.PiOver2 + MathHelper.PiOver4) * facing) * distance; + + if (Main.tile[(int)(positionToCheck.X / 16), (int)(positionToCheck.Y / 16)].IsTileSolidGround()) + widestAngle = i; + + else if (widestAngle != 0) + { + validPositionFound = true; + widestSurfaceAngle = widestAngle; + } + } + + if (validPositionFound) + { + Vector2 projPosition = projectile.Center + OriginDirection.RotatedBy((widestSurfaceAngle * MathHelper.PiOver2 + MathHelper.PiOver4) * facing) * distance; + Vector2 monolithRotation = OriginDirection.RotatedBy(Utils.AngleLerp(widestSurfaceAngle * -facing, 0f, projSize)); + Projectile proj = Projectile.NewProjectileDirect(projPosition, -monolithRotation, ProjectileType(), projectile.damage * 2, 10f, Owner.whoAmI, Main.rand.Next(4), projSize); + if (proj.modProjectile is MercurialTidesMonolith monolith) + { + monolith.WaitTimer = (float)Math.Sqrt(1.0 - Math.Pow(projSize - 1.0, 2)) * 3f ; + monolith.OriginDirection = OriginDirection; + monolith.Facing = facing; + } + } + + return validPositionFound; + } + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (WaitTimer > 0) + return false; + + Texture2D tex = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_MercurialTidesMonolith"); + + Vector2 Shake = projectile.timeLeft < 70 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (70 - projectile.timeLeft / 30f) * 0.05f; + + float drawAngle = projectile.rotation; + Rectangle frame = new Rectangle(0 + (int)Variant * 94, 0, 94, 420); + + Vector2 drawScale = new Vector2(Width() / BaseWidth, Height() / BaseHeight); + Vector2 drawPosition = projectile.Center - Main.screenPosition - (projectile.rotation - MathHelper.PiOver2).ToRotationVector2() * 26f; + Vector2 drawOrigin = new Vector2(frame.Width / 2f, frame.Height); + + float opacity = MathHelper.Clamp(1f - ((Timer - 0.85f) / 0.15f), 0f, 1f); + + spriteBatch.Draw(tex, drawPosition + Shake, frame, lightColor * opacity, drawAngle, drawOrigin, drawScale, 0f, 0f); + + return false; + } + public override void PostDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (WaitTimer > 0) + return; + + Texture2D tex = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith_Glow"); + + float drawAngle = projectile.rotation; + Rectangle frame = new Rectangle(0 + (int)Variant * 94, 0, 94, 420); + + Vector2 drawScale = new Vector2(Width() / BaseWidth, Height() / BaseHeight); + Vector2 drawPosition = projectile.Center - Main.screenPosition - (projectile.rotation - MathHelper.PiOver2).ToRotationVector2() * 26f; + Vector2 drawOrigin = new Vector2(frame.Width / 2f, frame.Height); + + float opacity = MathHelper.Clamp(1f - ((Timer - 0.85f) / 0.15f), 0f, 1f); + + spriteBatch.Draw(tex, drawPosition, frame, Color.White * opacity, drawAngle, drawOrigin, drawScale, 0f, 0f); + } + + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(WaitTimer); + writer.Write(Facing); + writer.WriteVector2(OriginDirection); + + } + public override void ReceiveExtraAI(BinaryReader reader) + { + WaitTimer = reader.ReadSingle(); + Facing = reader.ReadSingle(); + OriginDirection = reader.ReadVector2(); + } + } + + public class MercurialTidesBlast : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_MercurialTidesShockwave"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => (60f - projectile.timeLeft) / 100f; + public ref float Variant => ref projectile.ai[0]; //Yes + public ref float Size => ref projectile.ai[0]; //Yes + + public Particle BloomRing; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Mercurial Blast"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 170; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 60; + } + + public override bool CanDamage() => projectile.timeLeft < 40; + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + return Collision.CheckAABBvAABBCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center + (projHitbox.Size() * projectile.scale * 0.5f), projHitbox.Size() * projectile.scale); + } + + public override void AI() + { + projectile.velocity = Vector2.Zero; + projectile.scale = (1 + (float)Math.Sin(projectile.timeLeft / 60f * MathHelper.Pi) * 0.2f) * Size; + + if (projectile.timeLeft == 60) + { + Main.PlaySound(SoundID.Item79, projectile.Center); + Particle Sparkle = new GenericSparkle(projectile.Center, Vector2.Zero, Color.White, Main.rand.NextBool() ? Color.Aqua : Color.SpringGreen, projectile.scale, 20 ,0.2f, 2); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + + + if (projectile.timeLeft == 40) + { + Main.PlaySound(SoundID.DD2_ExplosiveTrapExplode, projectile.Center); + + BloomRing = new BloomRing(projectile.Center, Vector2.Zero, Color.Aqua, projectile.scale, 40); + GeneralParticleHandler.SpawnParticle(BloomRing); + + Particle Bloom = new StrongBloom(projectile.Center, Vector2.Zero, Main.rand.NextBool() ? Color.Aqua * 0.6f : Color.SpringGreen * 0.6f, projectile.scale * (1f + Main.rand.NextFloat(0f, 1.5f)), 20); + GeneralParticleHandler.SpawnParticle(Bloom); + for (int i = 0; i < 10; i++) + { + Particle Sparkle = new CritSpark(projectile.Center, Main.rand.NextVector2Circular(1f, 1f) * Main.rand.NextFloat(17.5f, 25f) * projectile.scale, Color.White, Main.rand.NextBool() ? Color.DarkSlateBlue : Color.Chocolate, 0.1f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + for (float i = 0f; i < 1; i += 0.05f) + { + float rotation = i * MathHelper.TwoPi; + Particle Sparkle = new CritSpark(projectile.Center + rotation.ToRotationVector2() * 65f * projectile.scale, rotation.ToRotationVector2() * 10f, Color.White, Main.rand.NextBool() ? Color.Aqua : Color.SpringGreen, 0.1f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + + if (BloomRing != null) + { + BloomRing.Scale = projectile.scale; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D tex = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_MercurialTidesShockwave"); + + float drawAngle = projectile.rotation; + int animFrame = 6 - (int)Math.Ceiling(projectile.timeLeft / 10f); + Rectangle frame = new Rectangle(0, 0 + animFrame * 168, 170, 166); + + Vector2 drawPosition = projectile.Center - Main.screenPosition; + Vector2 drawOrigin = frame.Size() / 2f; + + spriteBatch.Draw(tex, drawPosition, frame, Color.White, drawAngle, drawOrigin, projectile.scale, 0f, 0f); + + + return false; + } + } +} + + diff --git a/Projectiles/Melee/TrueBiomeBlade_MercurialTides.png b/Projectiles/Melee/TrueBiomeBlade_MercurialTides.png new file mode 100644 index 0000000000..a2f1e480c3 Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_MercurialTides.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_MercurialTidesMonolith.png b/Projectiles/Melee/TrueBiomeBlade_MercurialTidesMonolith.png new file mode 100644 index 0000000000..9d931f1918 Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_MercurialTidesMonolith.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_MercurialTidesShockwave.png b/Projectiles/Melee/TrueBiomeBlade_MercurialTidesShockwave.png new file mode 100644 index 0000000000..55dd6345b9 Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_MercurialTidesShockwave.png differ