diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 650222484f..6b00c1c965 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 @@ -2557,6 +2558,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 4b21257aa2..1178dd67cc 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -129,6 +129,9 @@ namespace CalamityMod.CalPlayer // This must be done here instead of in the item logic because these sets are not properly instanced // in the global classes. Attempting to update them there will cause multiple updates to one set for multiple items. CalamityGlobalItem.UpdateAllParticleSets(); + BiomeBlade.UpdateAllParticleSets(); + TrueBiomeBlade.UpdateAllParticleSets(); + OmegaBiomeBlade.UpdateAllParticleSets(); // Update the gem tech armor set. GemTechState.Update(); @@ -1062,6 +1065,15 @@ namespace CalamityMod.CalPlayer if (gSabatonFall > 0 || player.PortalPhysicsEnabled) player.maxFallSpeed = 20f; } + + if (LungingDown) + { + player.maxFallSpeed = 80f; + player.noFallDmg = true; + } + + + } // Omega Blue Armor bonus diff --git a/Dusts/PumplerDust.cs b/Dusts/PumplerDust.cs deleted file mode 100644 index ea6b3fc929..0000000000 --- a/Dusts/PumplerDust.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; - - -namespace CalamityMod.Dusts { - public class PumplerDust : ModDust //TURN THAT INTO A PARTICLE WHEN I REMEMBER - { - public override bool Autoload(ref string name, ref string texture) - { - texture = "CalamityMod/Particles/SmallSmoke"; - return true; - } - public override void OnSpawn(Dust dust) - { - dust.noGravity = true; - dust.frame = new Rectangle(0, 0, 24, 24); - } - - public override Color? GetAlpha(Dust dust, Color lightColor) - { - Color gray = new Color(40, 40, 40); - Color ret; - ret = Color.Lerp(Color.Orange, gray, MathHelper.Clamp((float)(dust.alpha - 100) / 80, 0f, 1f)); - return ret * ((255 - dust.alpha) / 255f); - } - - public override bool Update(Dust dust) - { - dust.velocity *= 0.85f; - - if (dust.alpha < 165) - { - Lighting.AddLight(dust.position, dust.color.ToVector3() * 0.1f); - dust.scale += 0.01f; - dust.alpha += 3; - } - else - { - dust.scale *= 0.975f; - dust.alpha += 2; - } - - dust.position += dust.velocity; - if (dust.alpha >= 255) - dust.active = false; - - return false; - } - } -} \ No newline at end of file diff --git a/Items/Weapons/Melee/ArkoftheAncients.cs b/Items/Weapons/Melee/ArkoftheAncients.cs index 4facc0e5ac..a77ed2fb94 100644 --- a/Items/Weapons/Melee/ArkoftheAncients.cs +++ b/Items/Weapons/Melee/ArkoftheAncients.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { - item.width = 50; + item.width = item.height = 60; item.damage = 80; item.melee = true; item.useAnimation = 22; @@ -29,7 +29,6 @@ namespace CalamityMod.Items.Weapons.Melee item.knockBack = 6.25f; item.UseSound = SoundID.Item1; item.autoReuse = true; - item.height = 50; item.value = Item.buyPrice(0, 48, 0, 0); item.rare = ItemRarityID.LightPurple; item.shoot = ModContent.ProjectileType(); diff --git a/Items/Weapons/Melee/ArkoftheAncients.png b/Items/Weapons/Melee/ArkoftheAncients.png index 6551c21ef9..bca8cbe06d 100644 Binary files a/Items/Weapons/Melee/ArkoftheAncients.png and b/Items/Weapons/Melee/ArkoftheAncients.png differ diff --git a/Items/Weapons/Melee/BiomeBlade.cs b/Items/Weapons/Melee/BiomeBlade.cs index 0e79db0564..f7b0bc9831 100644 --- a/Items/Weapons/Melee/BiomeBlade.cs +++ b/Items/Weapons/Melee/BiomeBlade.cs @@ -1,64 +1,641 @@ +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.CalPlayer; +using CalamityMod.DataStructures; +using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables; +using CalamityMod.Particles; using CalamityMod.Projectiles.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 Terraria.ModLoader.IO; +using static CalamityMod.Items.Weapons.Melee.BiomeBlade; +using static CalamityMod.CalamityUtils; namespace CalamityMod.Items.Weapons.Melee { public class BiomeBlade : ModItem { + public enum Attunement : byte { Default, Hot, Cold, Tropical, Evil } + public Attunement? mainAttunement = null; + public Attunement? secondaryAttunement = null; + public int Combo = 0; + public int CanLunge = 1; + + #region stats + public static int DefaultAttunement_BaseDamage = 55; + + public static int EvilAttunement_BaseDamage = 102; + public static int EvilAttunement_Lifesteal = 3; + public static int EvilAttunement_BounceIFrames = 10; + + public static int ColdAttunement_BaseDamage = 70; + public static float ColdAttunement_SecondSwingBoost = 1.8f; + public static float ColdAttunement_ThirdSwingBoost = 3f; + + public static int HotAttunement_BaseDamage = 70; + public static int HotAttunement_ShredIFrames = 8; + public static int HotAttunement_LocalIFrames = 30; //Be warned its got one extra update so all the iframes should be divided in 2 + public static int HotAttunement_LocalIFramesCharged = 16; + + public static int TropicalAttunement_BaseDamage = 55; + public static float TropicalAttunement_ChainDamageReduction = 0.5f; + public static int TropicalAttunement_LocalIFrames = 60; //Be warned its got 2 extra updates so all the iframes should be divided in 3 + #endregion + public override void SetStaticDefaults() { - DisplayName.SetDefault("Biome Blade"); - Tooltip.SetDefault("Fires different projectiles based on what biome you're in"); + DisplayName.SetDefault("Broken Biome Blade"); //Broken Ecoliburn lmfao. Tbh a proper name instead of just "biome blade" may be neat given the importance of the sword + Tooltip.SetDefault("FUNCTION_DESC\n" + + "Use RMB while standing still on the ground to attune the weapon to the powers of the surrounding biome\n" + + "Using RMB otherwise switches between the current attunement and an extra stored one\n" + + "Main attunement : None\n" + + "Secondary attunement: None\n"); //Theres potential for flavor text as well but im not a writer } + #region tooltip editing + + public override void ModifyTooltips(List list) + { + Player player = Main.player[Main.myPlayer]; + if (player is null) + return; + + foreach (TooltipLine l in list) + { + if (l.text.StartsWith("FUNCTION_DESC")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = info.function_description; + } + + if (l.text.StartsWith("Main attunement")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = "Main Attumenent : ["+ info.name + "]"; + } + + if (l.text.StartsWith("Secondary attunement")) + { + AttunementInfo info = GetAttunementInfo(secondaryAttunement); + l.overrideColor = Color.Lerp(info.color, Color.Gray, 0.5f); + l.text = "Secondary Attumenent : [" + info.name + "]"; + } + } + } + + internal struct AttunementInfo + { + public string name; + public string function_description; + public Color color; + } + + internal AttunementInfo GetAttunementInfo(Attunement? attunement) + { + AttunementInfo AttunementInfo = new AttunementInfo(); + + switch (attunement) + { + case Attunement.Default: + AttunementInfo.name = "Pure Clarity"; + AttunementInfo.function_description = "Fires a weak projectile that crushes enemy defenses"; + AttunementInfo.color = new Color(171, 180, 73); + break; + case Attunement.Hot: + AttunementInfo.name = "Arid Grandeur"; + AttunementInfo.function_description = "Conjures searing 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.color = new Color(238, 156, 73); + break; + case Attunement.Cold: + AttunementInfo.name = "Biting Embrace"; + AttunementInfo.function_description = "Perform a 3 strike combo with a glacial blade. The final strike freezes foes for a split second"; + AttunementInfo.color = new Color(165, 235, 235); + break; + case Attunement.Tropical: + AttunementInfo.name = "Grovetender's Touch"; + AttunementInfo.function_description = "Throw out the blade using a vine whip. Striking enemies with the tip of the whip as it cracks guarantees a critical hit. The whip will also propel you towards struck tiles"; + AttunementInfo.color = new Color(162, 200, 85); + break; + case Attunement.Evil: + AttunementInfo.name = "Decay's Retort"; + AttunementInfo.function_description = "Lunge forward using a ghostly rapier projection that leeches life off any struck foes. You also get bounced away from hit targets"; + AttunementInfo.color = new Color(211, 64, 147); + break; + default: + AttunementInfo.name = "None"; + AttunementInfo.function_description = "Does nothing... yet"; + AttunementInfo.color = new Color(163, 163, 163); + break; + } + + return AttunementInfo; + } + + #endregion + public override void SetDefaults() { - item.width = 42; + item.width = item.height = 36; item.damage = 55; item.melee = true; item.useAnimation = 30; item.useTime = 30; item.useTurn = true; item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileID.PurificationPowder; item.knockBack = 5f; - item.UseSound = SoundID.Item1; item.autoReuse = true; - item.height = 42; item.value = Item.buyPrice(0, 4, 0, 0); item.rare = ItemRarityID.Orange; - item.shoot = ModContent.ProjectileType(); item.shootSpeed = 12f; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); - recipe.AddIngredient(ItemID.WoodenSword); - recipe.AddIngredient(ItemID.DirtBlock, 20); - recipe.AddIngredient(ItemID.SandBlock, 20); - recipe.AddIngredient(ItemID.IceBlock, 20); //intentionally not any ice - recipe.AddRecipeGroup("AnyEvilBlock", 20); - recipe.AddIngredient(ItemID.GlowingMushroom, 20); - recipe.AddIngredient(ItemID.Marble, 20); - recipe.AddIngredient(ItemID.Granite, 20); - recipe.AddIngredient(ItemID.Hellstone, 20); - recipe.AddIngredient(ItemID.Coral, 20); - recipe.AddIngredient(ModContent.ItemType(), 20); + recipe.AddRecipeGroup("AnyWoodenSword"); + recipe.AddIngredient(ItemID.DirtBlock, 50); + recipe.AddIngredient(ItemID.StoneBlock, 50); + recipe.AddIngredient(ItemID.HellstoneBar, 5); + recipe.AddIngredient(ItemType(), 5); recipe.AddTile(TileID.Anvils); recipe.SetResult(this); recipe.AddRecipe(); } - public override void MeleeEffects(Player player, Rectangle hitbox) + #region Saving and syncing attunements + public override bool CloneNewInstances => true; + + public override ModItem Clone(Item item) { - if (Main.rand.NextBool(5)) + var clone = base.Clone(item); + + if (Main.mouseItem.type == ItemType()) + item.modItem.HoldItem(Main.player[Main.myPlayer]); + + (clone as BiomeBlade).mainAttunement = (item.modItem as BiomeBlade).mainAttunement; + (clone as BiomeBlade).secondaryAttunement = (item.modItem as BiomeBlade).secondaryAttunement; + + //As funny as a Broken Broken Biome Blade would be, its also quite funny to make it turn into that. This is only done for a new instance of the item since the goblin tinkerer changes prevent it from happening through reforging + if (clone.item.prefix == PrefixID.Broken) { - int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 0); + clone.item.Prefix(PrefixID.Legendary); + clone.item.prefix = PrefixID.Legendary; + } + + return clone; + } + + public override ModItem Clone() //ditto + { + var clone = base.Clone(); + + (clone as BiomeBlade).mainAttunement = mainAttunement; + (clone as BiomeBlade).secondaryAttunement = secondaryAttunement; + + if (clone.item.prefix == PrefixID.Broken) + { + clone.item.Prefix(PrefixID.Legendary); + clone.item.prefix = PrefixID.Legendary; + } + + return clone; + } + + public override TagCompound Save() + { + int attunement1 = mainAttunement == null? -1 : (int)mainAttunement; + int attunement2 = secondaryAttunement == null ? -1 : (int)secondaryAttunement; + TagCompound tag = new TagCompound + { + { "mainAttunement", attunement1 }, + { "secondaryAttunement", attunement2 } + }; + return tag; + } + + public override void Load(TagCompound tag) + { + int attunement1 = tag.GetInt("mainAttunement"); + int attunement2 = tag.GetInt("secondaryAttunement"); + if (attunement1 == -1) + mainAttunement = null; + else + mainAttunement = (Attunement?)attunement1; + + if (attunement2 == -1 || (attunement1 == attunement2)) + secondaryAttunement = null; + else + secondaryAttunement = (Attunement?)attunement2; + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write((byte)mainAttunement); + writer.Write((byte)secondaryAttunement); + } + + public override void NetRecieve(BinaryReader reader) + { + mainAttunement = (Attunement?)reader.ReadByte(); + secondaryAttunement = (Attunement?)reader.ReadByte(); + } + + #endregion + + public override void HoldItem(Player player) + { + + player.Calamity().rightClickListener = true; + + if (player.velocity.Y == 0) //Reset the lunge ability on ground contact + CanLunge = 1; + + //Change the swords function based on its attunement + switch (mainAttunement) + { + case Attunement.Default: + item.damage = DefaultAttunement_BaseDamage; + item.channel = false; + item.noUseGraphic = false; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = SoundID.Item1; + item.noMelee = false; + + Combo = 0; + break; + case Attunement.Hot: + item.damage = HotAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + break; + case Attunement.Cold: + item.damage = ColdAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + case Attunement.Tropical: + item.damage = TropicalAttunement_BaseDamage; + item.channel = false; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileType(); + item.shootSpeed = 30; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + break; + case Attunement.Evil: + item.damage = EvilAttunement_BaseDamage; + item.channel = false; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.Stabbing; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + break; + default: + item.noUseGraphic = false; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileID.PurificationPowder; + item.shootSpeed = 12f; + item.UseSound = SoundID.Item1; + + Combo = 0; + 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 + if (Main.projectile.Any(n => n.active && n.type == ProjectileType() && n.owner == player.whoAmI)) + return; + + int x = (int)player.Center.X / 16; + int y = (int)(player.position.Y + (float)player.height - 1f) / 16; + Tile tileStandingOn = Main.tile[x, y + 1]; + + bool mayAttune = player.StandingStill() && !player.mount.Active && tileStandingOn.IsTileSolidGround(); + Vector2 displace = new Vector2(18f, 0f); + Projectile.NewProjectile(player.Top + displace, Vector2.Zero, ProjectileType(), 0, 0, player.whoAmI, mayAttune ? 0f : 1f); } } + + public override bool CanUseItem(Player player) + { + return !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && + (n.type == ProjectileType() || n.type == ProjectileType() || n.type == ProjectileType())); + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (mainAttunement == null) + return false; + + switch (mainAttunement) + { + case Attunement.Cold: + switch (Combo) + { + case 0: + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 0, 15); + break; + + case 1: + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 1, 20); + break; + + case 2: + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 2, 50); + break; + } + Combo++; + if (Combo > 2) + Combo = 0; + return false; + + case Attunement.Evil: + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 26, (float) CanLunge); + CanLunge = 0; + return false; + + default: + return base.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack); + } + } + + internal static ChargingEnergyParticleSet BiomeEnergyParticles = new ChargingEnergyParticleSet(-1, 2, Color.DarkViolet, Color.White, 0.04f, 20f); + internal static void UpdateAllParticleSets() + { + BiomeEnergyParticles.Update(); + } + + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + Texture2D itemTexture = Main.itemTexture[item.type]; + Rectangle itemFrame = (Main.itemAnimations[item.type] == null) ? itemTexture.Frame() : Main.itemAnimations[item.type].GetFrame(itemTexture); + + if (mainAttunement == null) + return true; + + // Draw all particles. + + Vector2 particleDrawCenter = position + new Vector2(12f, 16f) * Main.inventoryScale; + + switch (mainAttunement) + { + case Attunement.Default: + BiomeEnergyParticles.EdgeColor = new Color(117, 126, 72); + BiomeEnergyParticles.CenterColor = new Color(200, 184, 136); + break; + case Attunement.Hot: + BiomeEnergyParticles.EdgeColor = new Color(137, 32, 0); + BiomeEnergyParticles.CenterColor = new Color(209, 154, 0); + break; + case Attunement.Cold: + BiomeEnergyParticles.EdgeColor = new Color(165, 235, 235); + BiomeEnergyParticles.CenterColor = new Color(58, 110, 141); + break; + case Attunement.Tropical: + BiomeEnergyParticles.EdgeColor = new Color(53, 112, 4); + BiomeEnergyParticles.CenterColor = new Color(131, 173, 39); + break; + case Attunement.Evil: + BiomeEnergyParticles.EdgeColor = new Color(112, 4, 35); + BiomeEnergyParticles.CenterColor = new Color(195, 42, 200); + break; + } + BiomeEnergyParticles.InterpolationSpeed = 0.1f; + BiomeEnergyParticles.DrawSet(particleDrawCenter + Main.screenPosition); + + Vector2 displacement = Vector2.UnitX.RotatedBy(Main.GlobalTime * 3f) * 2f * (float)Math.Sin(Main.GlobalTime); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); + spriteBatch.Draw(itemTexture, position + displacement, itemFrame, BiomeEnergyParticles.CenterColor, 0f, origin, scale, SpriteEffects.None, 0f); + spriteBatch.Draw(itemTexture, position - displacement, itemFrame, BiomeEnergyParticles.CenterColor, 0f, origin, scale, SpriteEffects.None, 0f); + spriteBatch.End(); + spriteBatch.Begin(default, default); + + return true; + } + } + + public class BrokenBiomeBladeVisuals : ModProjectile //Visuals + { + private Player Owner => Main.player[projectile.owner]; + + public bool OwnerOnGround => Main.tile[(int)Owner.Center.X / 16, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround() && Main.tile[(int)Owner.Center.X / 16 + Owner.direction, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround(); + public bool OwnerCanUseItem => Owner.HeldItem == associatedItem ? (Owner.HeldItem.modItem as BiomeBlade).CanUseItem(Owner) : false; + public bool OwnerMayChannel => OwnerCanUseItem && Owner.Calamity().mouseRight && Owner.active && !Owner.dead && Owner.StandingStill() && !Owner.mount.Active && OwnerOnGround; + public ref float ChanneledState => ref projectile.ai[0]; + public ref float ChannelTimer => ref projectile.ai[1]; + public ref float Initialized => ref projectile.localAI[0]; + + private Item associatedItem; + const int ChannelTime = 120; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Broken Biome Blade"); + } + public override string Texture => "CalamityMod/Items/Weapons/Melee/BiomeBlade"; + public bool drawIndrawHeldProjInFrontOfHeldItemAndArms = true; + public override void SetDefaults() + { + projectile.width = projectile.height = 36; + projectile.aiStyle = -1; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 60; + projectile.tileCollide = false; + projectile.damage = 0; + } + + public CurveSegment anticipation = new CurveSegment(EasingType.SineOut, 0f, 1f, 0.35f); + public CurveSegment thrust = new CurveSegment(EasingType.ExpIn, 0.85f, 1.35f, -1.45f); + public CurveSegment bounceback = new CurveSegment(EasingType.SineOut, 0.95f, -0.1f, 0.1f); + internal float SwordHeight() => PiecewiseAnimation(ChannelTimer / (float)ChannelTime, new CurveSegment[] { anticipation, thrust, bounceback }); + + + + public override void AI() + { + + if (Initialized == 0f) + { + //If dropped, kill it instantly + if (Owner.HeldItem.type != ItemType()) + { + projectile.Kill(); + return; + } + + if (Owner.whoAmI == Main.myPlayer) + Main.PlaySound(SoundID.DD2_DarkMageHealImpact); + + associatedItem = Owner.HeldItem; + //Switch up the attunements + Attunement? temporaryAttunementStorage = (associatedItem.modItem as BiomeBlade).mainAttunement; + (associatedItem.modItem as BiomeBlade).mainAttunement = (associatedItem.modItem as BiomeBlade).secondaryAttunement; + (associatedItem.modItem as BiomeBlade).secondaryAttunement = temporaryAttunementStorage; + Initialized = 1f; + } + + if (!OwnerMayChannel && ChanneledState == 0f) //IF the channeling gets interrupted for any reason + { + projectile.Center = Owner.Top + new Vector2(18f, 0f); + ChanneledState = 1f; + projectile.timeLeft = 60; + return; + } + + if (ChanneledState == 0f) + { + Owner.heldProj = projectile.whoAmI; + + projectile.Center = Owner.Center + new Vector2(16f * Owner.direction, -30 * SwordHeight() + 10f) ; + projectile.rotation = Utils.AngleLerp(-MathHelper.PiOver4, MathHelper.PiOver4 + MathHelper.PiOver2, MathHelper.Clamp(((ChannelTimer - 20f) / 50f), 0f, 1f)); + ChannelTimer++; + projectile.timeLeft = 60; + + if (ChannelTimer >= ChannelTime) + { + Attune((BiomeBlade)associatedItem.modItem); + projectile.timeLeft = 120; + ChanneledState = 2f; //State where it stays invisible doing nothing. Acts as a cooldown + + Color particleColor = (associatedItem.modItem as BiomeBlade).GetAttunementInfo((associatedItem.modItem as BiomeBlade).mainAttunement).color; + + for (int i = 0; i <= 5; i++) + { + Vector2 displace = Vector2.UnitX * 20 * Main.rand.NextFloat(-1f, 1f); + Particle Glow = new GenericBloom(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, 0.02f + Main.rand.NextFloat(0f, 0.2f), 20 + Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(Glow); + } + for (int i = 0; i <= 10; i++) + { + Vector2 displace = Vector2.UnitX * 16 * Main.rand.NextFloat(-1f, 1f); + Particle Sparkle = new GenericSparkle(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, particleColor, 0.5f + Main.rand.NextFloat(-0.2f, 0.2f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + } + + if (ChanneledState == 1f) + projectile.position += Vector2.UnitY * -0.3f * (1f + projectile.timeLeft/60f); + } + + public void Attune(BiomeBlade item) + { + bool jungle = Owner.ZoneJungle; + bool snow = Owner.ZoneSnow; + bool evil = Owner.ZoneCorrupt || Owner.ZoneCrimson; + bool desert = Owner.ZoneDesert; + bool hell = Owner.ZoneUnderworldHeight; + bool ocean = Owner.ZoneBeach; + + Attunement attunement = Attunement.Default; + + if (desert || hell) + { + attunement = Attunement.Hot; + } + if (snow) + { + attunement = Attunement.Cold; + } + if (jungle || ocean) + { + attunement = Attunement.Tropical; + } + if (evil) + { + attunement = Attunement.Evil; + } + + //If the owner already had the attunement , break out of it (And unswap) + if (item.secondaryAttunement == attunement) + { + Main.PlaySound(SoundID.DD2_LightningBugZap, projectile.Center); + item.secondaryAttunement = item.mainAttunement; + item.mainAttunement = attunement; + return; + } + + Main.PlaySound(SoundID.DD2_MonkStaffGroundImpact, projectile.Center); + item.mainAttunement = attunement; + + //Lots of particles!!! yay!! visuals!! + } + + public override void Kill(int timeLeft) + { + if (associatedItem == null) + { + return; + } + + //If we swapped out the main attunement for the second one despite the second attunement being empty at the time, unswap them. + if ((associatedItem.modItem as BiomeBlade).mainAttunement == null && (associatedItem.modItem as BiomeBlade).secondaryAttunement != null) + { + (associatedItem.modItem as BiomeBlade).mainAttunement = (associatedItem.modItem as BiomeBlade).secondaryAttunement; + (associatedItem.modItem as BiomeBlade).secondaryAttunement = null; + } + + //Cool particles + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (ChanneledState == 0f && ChannelTimer > 6f) + return base.PreDraw(spriteBatch, lightColor); + + else if (ChanneledState == 1f) + { + Texture2D tex = GetTexture(Texture); + Vector2 squishyScale = new Vector2(Math.Abs((float)Math.Sin(MathHelper.Pi + MathHelper.TwoPi * projectile.timeLeft / 30f)), 1f); + SpriteEffects flip = (float)Math.Sin(MathHelper.Pi + MathHelper.TwoPi * projectile.timeLeft / 30f) > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + spriteBatch.Draw(tex, projectile.position - Main.screenPosition, null, lightColor * (projectile.timeLeft / 60f), 0, tex.Size() / 2, squishyScale * (2f - (projectile.timeLeft / 60f)), flip, 0); + + return false; + } + + else + return false; + } + } + } + + diff --git a/Items/Weapons/Melee/BiomeBlade.png b/Items/Weapons/Melee/BiomeBlade.png index 785aff563e..d6f1f3e56f 100644 Binary files a/Items/Weapons/Melee/BiomeBlade.png and b/Items/Weapons/Melee/BiomeBlade.png differ diff --git a/Items/Weapons/Melee/FourSeasonsGalaxia.cs b/Items/Weapons/Melee/FourSeasonsGalaxia.cs index 30ce17dd99..d20afe6992 100644 --- a/Items/Weapons/Melee/FourSeasonsGalaxia.cs +++ b/Items/Weapons/Melee/FourSeasonsGalaxia.cs @@ -7,22 +7,211 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.Items.Placeables; +using CalamityMod.Particles; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Terraria.ModLoader.IO; +using static CalamityMod.CalamityUtils; +using static CalamityMod.Items.Weapons.Melee.FourSeasonsGalaxia; +using static Terraria.ModLoader.ModContent; + namespace CalamityMod.Items.Weapons.Melee { public class FourSeasonsGalaxia : ModItem { + public enum Attunement : byte { SuperPogo, Whirlwind, Shockwave, FlailBlade } + public Attunement? mainAttunement = null; + + //Used for passive effects? Unless we make em different idk lol + public int UseTimer = 0; + public bool OnHitProc = false; + + #region stats + public static int WhirlwindAttunement_BaseDamage = 800; + public static int WhirlwindAttunement_LocalIFrames = 20; //Remember its got one extra update + public static float WhirlwindAttunement_BoltDamageReduction = 0.5f; + public static float WhirlwindAttunement_BoltThrowDamageMultiplier = 1.5f; + public static float WhirlwindAttunement_BaseDamageReduction = 0.2f; + public static float WhirlwindAttunement_FullChargeDamageBoost = 2f; + + public static int SuperPogoAttunement_BaseDamage = 1200; + public static int SuperPogoAttunement_ShredIFrames = 10; + public static int SuperPogoAttunement_LocalIFrames = 30; //Be warned its got one extra update so all the iframes should be divided in 2 + public static int SuperPogoAttunement_LocalIFramesCharged = 16; + public static float SuperPogoAttunement_SlashDamageBoost = 5f; //Keep in mind the slice always crits + public static int SuperPogoAttunement_SlashBoltsDamage = 1300; + public static int SuperPogoAttunement_SlashIFrames = 60; + public static float SuperPogoAttunement_ShotDamageBoost = 2f; //The shots fired if the dash connects + + public static int ShockwaveAttunement_BaseDamage = 3500; + public static int ShockwaveAttunement_DashHitIFrames = 60; + public static float ShockwaveAttunement_FullChargeBoost = 1f; //The EXTRA damage boost. So putting 1 here will make it deal double damage. Putting 0.5 here will make it deal 1.5x the damage. + public static float ShockwaveAttunement_MonolithDamageBoost = 2f; + public static float ShockwaveAttunement_BoltsDamageReduction = 0.2f; //The shots fired as it charges + + public static int FlailBladeAttunement_BaseDamage = 1420; + public static int FlailBladeAttunement_LocalIFrames = 10; + public static int FlailBladeAttunement_Reach = 600; + public static float FlailBladeAttunement_ChainDamageReduction = 0.5f; + public static float FlailBladeAttunement_OnHitBoltDamageReduction = 0.5f; + + public static int CancerPassiveDamage = 3000; + public static int CancerPassiveLifeSteal = 3; + public static float CancerPassiveLifeStealProc = 0.4f; + public static int CapricornPassiveDebuffTime = 200; + + + #endregion + + public override string Texture => "CalamityMod/Items/Weapons/Melee/GalaxiaExtra"; //Just in case the player SOMEHOW gets to swing galaxia itself. Sprite also used as the base for other attacks + public override void SetStaticDefaults() { DisplayName.SetDefault("Galaxia"); - Tooltip.SetDefault("Fires a spread of homing projectiles that inflict different debuffs depending on what biome you're in\n" + - "Upon hitting an enemy you are granted a buff based on what biome you're in\n" + - "Projectiles also change based on moon events"); + Tooltip.SetDefault("FUNCTION_DESC\n" + + "FUNCTION_EXTRA\n" + + "FUNCTION_PASSIVE\n" + + "Upgrading the sword let it break free from its earthly boundaries. You now have access to every single attunement at all times!\n" + + "Use RMB to cycle the sword's attunement forward or backwards depending on the position of your cursor\n" + + "Active attunement : None\n" + + "Passive blessing: None\n"); ; } + #region tooltip editing + + public override void ModifyTooltips(List list) + { + Player player = Main.player[Main.myPlayer]; + if (player is null) + return; + + foreach (TooltipLine l in list) + { + if (l.text.StartsWith("FUNCTION_DESC")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = info.function_description; + } + + if (l.text.StartsWith("FUNCTION_EXTRA")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = info.function_extra; + } + + if (l.text.StartsWith("FUNCTION_PASSIVE")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.passive_color; + l.text = info.passive_desc; + } + + if (l.text.StartsWith("Active attunement")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = Color.Lerp(info.color, info.color2, 0.5f + (float)Math.Sin(Main.GlobalTime) * 0.5f); + l.text = "Active Attumenent : [" + info.name + "]"; + } + + if (l.text.StartsWith("Passive blessing")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.passive_color; + l.text = "Passive blessing : [" + info.passive_name + "]"; + } + } + } + + internal struct AttunementInfo + { + public string name; + public string function_description; + public string function_extra; + public string passive_name; + public string passive_desc; + public Color color; + public Color color2; + public Color passive_color; + } + + internal AttunementInfo GetAttunementInfo(Attunement? attunement) + { + AttunementInfo AttunementInfo = new AttunementInfo(); + + switch (attunement) + { + case Attunement.Whirlwind: + AttunementInfo.name = "Phoenix's Pride"; + AttunementInfo.function_description = "Hold LMB to swing Galaxia around you, powering up as it spins. Homing cosmic bolts get released around you as you spin"; + AttunementInfo.function_extra = "Releasing LMB during a spin will throw the sword out alongside a blast of 6 stronger cosmic bolts"; + AttunementInfo.color = new Color(255, 87, 0); + AttunementInfo.color2 = new Color(255, 143, 0); + break; + case Attunement.SuperPogo: + AttunementInfo.name = "Polaris's Gaze"; //It carries the mark of the Northern Star + AttunementInfo.function_description = "Channels the mark of the Northern Star into a short ranged shredding blade, surrounded by spinning stars. The blade powers up over time and when hitting enemies"; + AttunementInfo.function_extra = "Releasing LMB sends the charged star flying. Using LMB right after it makes the player perform a dash towards the star, releasing cosmic bolts at the end of the lunge"; + AttunementInfo.color = new Color(128, 189, 255); + AttunementInfo.color2 = new Color(255, 128, 140); + break; + case Attunement.Shockwave: + AttunementInfo.name = "Andromeda's Stride"; //EHEEHEHEHE GOD ERASING BECAUSE THE ANDROMEDA BOSS WAS SCRAPPED (ALSO KNOWN AS A "GOD" BEING "ERASED") EHEHEHE + AttunementInfo.function_description = "Hold LMB to charge up a god-erasing sword thrust, and release to unleash the devastating blow. Small cosmic bolts are released as you charge the sword"; + AttunementInfo.function_extra = "Striking the ground with the charge will create an impact so powerful large homing cosmic energies will rise from the ground"; + AttunementInfo.color = new Color(132, 128, 255); + AttunementInfo.color2 = new Color(194, 166, 255); + break; + case Attunement.FlailBlade: + AttunementInfo.name = "Aries's Wrath"; + AttunementInfo.function_description = "Send out Galaxia flying, circling at your cursor's position, connected to you by constellations"; + AttunementInfo.function_extra = "Enemy hits explode into extra homing cosmic bolts"; + AttunementInfo.color = new Color(196, 89, 201); + AttunementInfo.color2 = new Color(255, 0, 0); + break; + default: + AttunementInfo.name = "None"; + AttunementInfo.function_description = ""; + AttunementInfo.function_extra = ""; + AttunementInfo.color = new Color(163, 163, 163); + AttunementInfo.color2 = new Color(163, 163, 163); + break; + } + + switch (attunement) + { + case Attunement.Whirlwind: + case Attunement.FlailBlade: + AttunementInfo.passive_name = "Capricorn's Blessing"; + AttunementInfo.passive_desc = "Periodically releases a ring of weakening stars around your cursor when attacking\nThe ring is repelled away from you at first, before slowing down over time"; + AttunementInfo.passive_color = new Color(76, 137, 237); + break; + case Attunement.SuperPogo: + case Attunement.Shockwave: + AttunementInfo.passive_name = "Cancer's Blessing"; + AttunementInfo.passive_desc = "Periodically releases a ring of lifestealing stars around yourself when attacking\nThe ring is attracted towards you at first, before slowing down over time"; + AttunementInfo.passive_color = new Color(203, 25, 119); + break; + default: + AttunementInfo.passive_name = "None"; + AttunementInfo.passive_desc = "Based on your current attunement, you are granted a passive blessing"; + AttunementInfo.passive_color = new Color(163, 163, 163); + break; + } + return AttunementInfo; + } + + #endregion + public override void SetDefaults() { - item.width = 70; + item.width = item.height = 108; item.damage = 99; item.melee = true; item.useAnimation = 18; @@ -32,234 +221,394 @@ namespace CalamityMod.Items.Weapons.Melee item.knockBack = 9f; item.UseSound = SoundID.Item1; item.autoReuse = true; - item.height = 70; item.value = Item.buyPrice(1, 80, 0, 0); item.rare = ItemRarityID.Red; - item.shoot = ModContent.ProjectileType(); + item.shoot = ProjectileID.PurificationPowder; item.shootSpeed = 24f; item.Calamity().customRarity = CalamityRarity.DarkBlue; } - public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) - { - for (int projectiles = 0; projectiles < 3; projectiles++) - { - float SpeedX = speedX + Main.rand.Next(-40, 41) * 0.05f; - float SpeedY = speedY + Main.rand.Next(-40, 41) * 0.05f; - Projectile.NewProjectile(position.X, position.Y, SpeedX, SpeedY, type, damage, knockBack, player.whoAmI); - } - return false; - } - public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); - recipe.AddIngredient(ModContent.ItemType()); - recipe.AddIngredient(ModContent.ItemType(), 8); - recipe.AddIngredient(ModContent.ItemType(), 8); - recipe.AddTile(ModContent.TileType()); + recipe.AddIngredient(ItemType()); + recipe.AddIngredient(ItemType(), 8); + recipe.AddIngredient(ItemType(), 8); + recipe.AddTile(TileType()); recipe.SetResult(this); recipe.AddRecipe(); } - public override void MeleeEffects(Player player, Rectangle hitbox) + #region saving and syncing attunements + public override bool CloneNewInstances => true; + + public override ModItem Clone(Item item) { - if (Main.rand.NextBool(5)) - { - int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 0); - } + var clone = base.Clone(item); + if (Main.mouseItem.type == ItemType()) + item.modItem.HoldItem(Main.player[Main.myPlayer]); + (clone as FourSeasonsGalaxia).mainAttunement = (item.modItem as FourSeasonsGalaxia).mainAttunement; + + return clone; } - public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) + public override ModItem Clone() //ditto { - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool corrupt = player.ZoneCorrupt; - bool crimson = player.ZoneCrimson; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool holy = player.ZoneHoly; - bool nebula = player.ZoneTowerNebula; - bool stardust = player.ZoneTowerStardust; - bool solar = player.ZoneTowerSolar; - bool vortex = player.ZoneTowerVortex; - bool bloodMoon = Main.bloodMoon; - bool snowMoon = Main.snowMoon; - bool pumpkinMoon = Main.pumpkinMoon; - if (bloodMoon) + var clone = base.Clone(); + (clone as FourSeasonsGalaxia).mainAttunement = mainAttunement; + + return clone; + } + + public override TagCompound Save() + { + int attunement1 = mainAttunement == null ? 1 : (int)mainAttunement; + TagCompound tag = new TagCompound { - player.AddBuff(BuffID.Battle, 600); - } - if (snowMoon) + { "mainAttunement", attunement1 } + }; + return tag; + } + + public override void Load(TagCompound tag) + { + int attunement1 = tag.GetInt("mainAttunement"); + if (attunement1 == -1) + mainAttunement = Attunement.Whirlwind; + else + mainAttunement = (Attunement?)attunement1; + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write((byte)mainAttunement); + } + + public override void NetRecieve(BinaryReader reader) + { + mainAttunement = (Attunement?)reader.ReadByte(); + } + +#endregion + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (mainAttunement == null) + return false; + return true; + } + + public override void HoldItem(Player player) + { + player.Calamity().rightClickListener = true; + + if (CanUseItem(player)) { - player.AddBuff(BuffID.RapidHealing, 600); - } - if (pumpkinMoon) - { - player.AddBuff(BuffID.WellFed, 600); - } - if (astral) - { - player.AddBuff(ModContent.BuffType(), 600); - } - else if (jungle) - { - player.AddBuff(BuffID.Thorns, 600); - } - else if (snow) - { - player.AddBuff(BuffID.Warmth, 600); - } - else if (beach) - { - player.AddBuff(BuffID.Wet, 600); - } - else if (corrupt) - { - player.AddBuff(BuffID.Wrath, 600); - } - else if (crimson) - { - player.AddBuff(BuffID.Rage, 600); - } - else if (dungeon) - { - player.AddBuff(BuffID.Dangersense, 600); - } - else if (desert) - { - player.AddBuff(BuffID.Endurance, 600); - } - else if (glow) - { - player.AddBuff(BuffID.Spelunker, 600); - } - else if (hell) - { - player.AddBuff(BuffID.Inferno, 600); - } - else if (holy) - { - player.AddBuff(BuffID.Heartreach, 600); - } - else if (nebula) - { - player.AddBuff(BuffID.MagicPower, 600); - } - else if (stardust) - { - player.AddBuff(BuffID.Summoning, 600); - } - else if (solar) - { - player.AddBuff(BuffID.Titan, 600); - } - else if (vortex) - { - player.AddBuff(BuffID.AmmoReservation, 600); + player.Calamity().LungingDown = false; } else { - player.AddBuff(BuffID.DryadsWard, 600); + UseTimer++; + } + + //Change the swords function based on its attunement + switch (mainAttunement) + { + case Attunement.Whirlwind: + item.damage = WhirlwindAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + case Attunement.SuperPogo: + item.damage = SuperPogoAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + case Attunement.Shockwave: + item.damage = ShockwaveAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + case Attunement.FlailBlade: + item.damage = FlailBladeAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + default: + mainAttunement = Attunement.Whirlwind; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileID.PurificationPowder; + item.shootSpeed = 12f; + item.UseSound = SoundID.Item1; + break; + } + + //Passive effects only jappen player side haha + if (player.whoAmI != Main.myPlayer) + return; + + switch (mainAttunement) + { + case Attunement.SuperPogo: + case Attunement.Shockwave: + if (UseTimer % 500 == 449) + { + Main.PlaySound(SoundID.Item78); + Projectile.NewProjectile(player.Center, Vector2.Zero, ProjectileType(), CancerPassiveDamage, 0f, player.whoAmI, 0f); + UseTimer++; + } + break; + case Attunement.FlailBlade: + case Attunement.Whirlwind: + if (UseTimer % 500 == 449) + { + Main.PlaySound(SoundID.Item78); + Projectile.NewProjectile(Main.MouseWorld, Vector2.Zero, ProjectileType(), 0, 0f, player.whoAmI, 1f); + UseTimer++; + } + 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 + if (Main.projectile.Any(n => n.active && n.type == ProjectileType() && n.owner == player.whoAmI)) + return; + + Projectile.NewProjectile(player.Top, Vector2.Zero, ProjectileType(), 0, 0, player.whoAmI, 0, Math.Sign(player.position.X - Main.MouseWorld.X)); } } - public override void OnHitPvp(Player player, Player target, int damage, bool crit) + public override bool CanUseItem(Player player) { - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool corrupt = player.ZoneCorrupt; - bool crimson = player.ZoneCrimson; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool holy = player.ZoneHoly; - bool nebula = player.ZoneTowerNebula; - bool stardust = player.ZoneTowerStardust; - bool solar = player.ZoneTowerSolar; - bool vortex = player.ZoneTowerVortex; - bool bloodMoon = Main.bloodMoon; - bool snowMoon = Main.snowMoon; - bool pumpkinMoon = Main.pumpkinMoon; - if (bloodMoon) - { - player.AddBuff(BuffID.Battle, 600); - } - if (snowMoon) - { - player.AddBuff(BuffID.RapidHealing, 600); - } - if (pumpkinMoon) - { - player.AddBuff(BuffID.WellFed, 600); - } - if (jungle) - { - player.AddBuff(BuffID.Thorns, 600); - } - else if (snow) - { - player.AddBuff(BuffID.Warmth, 600); - } - else if (beach) - { - player.AddBuff(BuffID.Wet, 600); - } - else if (corrupt) - { - player.AddBuff(BuffID.Wrath, 600); - } - else if (crimson) - { - player.AddBuff(BuffID.Rage, 600); - } - else if (dungeon) - { - player.AddBuff(BuffID.Dangersense, 600); - } - else if (desert) - { - player.AddBuff(BuffID.Endurance, 600); - } - else if (glow) - { - player.AddBuff(BuffID.Spelunker, 600); - } - else if (hell) - { - player.AddBuff(BuffID.Inferno, 600); - } - else if (holy) - { - player.AddBuff(BuffID.Heartreach, 600); - } - else if (nebula) - { - player.AddBuff(BuffID.MagicPower, 600); - } - else if (stardust) - { - player.AddBuff(BuffID.Summoning, 600); - } - else if (solar) - { - player.AddBuff(BuffID.Titan, 600); - } - else if (vortex) - { - player.AddBuff(BuffID.AmmoReservation, 600); - } - else - { - player.AddBuff(BuffID.DryadsWard, 600); - } + return !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && + (n.type == ProjectileType() || + n.type == ProjectileType() || + n.type == ProjectileType() || + n.type == ProjectileType() + )); + } + + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (mainAttunement == null) + mainAttunement = Attunement.Whirlwind; + + Texture2D itemTexture = GetTexture((mainAttunement == Attunement.SuperPogo || mainAttunement == Attunement.Shockwave) ? "CalamityMod/Items/Weapons/Melee/GalaxiaRed" : "CalamityMod/Items/Weapons/Melee/GalaxiaBlue"); + spriteBatch.Draw(itemTexture, position, null, Color.White, 0f, origin, scale, SpriteEffects.None, 0f); + return false; + } + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) + { + Texture2D itemTexture = GetTexture((mainAttunement == Attunement.SuperPogo || mainAttunement == Attunement.Shockwave) ? "CalamityMod/Items/Weapons/Melee/GalaxiaRed" : "CalamityMod/Items/Weapons/Melee/GalaxiaBlue"); + spriteBatch.Draw(itemTexture, item.Center - Main.screenPosition, null, lightColor, rotation, item.Size * 0.5f, scale, SpriteEffects.None, 0f); + return false; } } + + public class GalaxiaVisuals : ModProjectile //Visuals. Now much simpler than before! + { + private Player Owner => Main.player[projectile.owner]; + public bool OwnerCanUseItem => Owner.HeldItem == associatedItem ? (Owner.HeldItem.modItem as FourSeasonsGalaxia).CanUseItem(Owner) : false; + public ref float Initialized => ref projectile.ai[0]; + public ref float CycleDirection => ref projectile.ai[1]; + + private Item associatedItem; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Galactic Formation"); + } + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public override void SetDefaults() + { + projectile.width = projectile.height = 2; + projectile.aiStyle = -1; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 40; + projectile.tileCollide = false; + projectile.damage = 0; + } + + public override void AI() + { + + if (Initialized == 0f) + { + //If dropped, kill it instantly + if (Owner.HeldItem.type != ItemType()) + { + projectile.Kill(); + return; + } + + projectile.Center = Owner.Center; + associatedItem = Owner.HeldItem; + + //Switch up the attunements + Reattune((FourSeasonsGalaxia)associatedItem.modItem); + + //Do particles around the player + + Color particleColor = (associatedItem.modItem as FourSeasonsGalaxia).GetAttunementInfo((associatedItem.modItem as FourSeasonsGalaxia).mainAttunement).color; + for (int i = 0; i <= 5; i++) + { + Vector2 displace = Vector2.UnitX * 20 * Main.rand.NextFloat(-1f, 1f); + Particle Glow = new GenericBloom(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, 0.02f + Main.rand.NextFloat(0f, 0.2f), 20 + Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(Glow); + } + for (int i = 0; i <= 10; i++) + { + Vector2 displace = Vector2.UnitX * 16 * Main.rand.NextFloat(-1f, 1f); + Particle Sparkle = new GenericSparkle(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, particleColor, 0.5f + Main.rand.NextFloat(-0.2f, 0.2f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + Initialized = 1f; + } + } + + public void Reattune(FourSeasonsGalaxia item) + { + Attunement attunement; + Vector2[] StarPositions; + Vector2[] ExtraLines; //Extra lines vector give us an indication of the index between the 2 stars we need to connect + List IgnoredLines = new List(); + + Particle Star; + Particle Line; + Color StarColor; + + if (CycleDirection == -1) //Cycles goes Whirlwind => Flailblade => Superpogo => Shockwave + { + switch (item.mainAttunement) + { + case Attunement.Whirlwind: //Switching to the flailblade attunement. + attunement = Attunement.FlailBlade; + break; + case Attunement.FlailBlade: //Switching to the superpogo attunement. + attunement = Attunement.SuperPogo; + break; + case Attunement.SuperPogo: //Switching to the shockwave attunement. + attunement = Attunement.Shockwave; + break; + case Attunement.Shockwave: //Switching to the whirlwind attunement. + default: + attunement = Attunement.Whirlwind; + break; + } + } + else //Cycles goes Whirlwind <= Flailblade <= Superpogo <= Shockwave + { + switch (item.mainAttunement) + { + case Attunement.Whirlwind: //Switching to the shockwave attunement. + attunement = Attunement.Shockwave; + break; + case Attunement.Shockwave: //Switching to the superpogo attunement. + attunement = Attunement.SuperPogo; + break; + case Attunement.SuperPogo: //Switching to the flailblade attunement. + attunement = Attunement.FlailBlade; + break; + case Attunement.FlailBlade: //Switching to the whirlwind attunement. + default: + attunement = Attunement.Whirlwind; + break; + } + } + + switch (attunement) + { + case Attunement.FlailBlade: // Drawing Aries + StarPositions = new Vector2[] { new Vector2(-160, -150), new Vector2(45, -170), new Vector2(137, 40), new Vector2(146, 126), new Vector2(129, 151) }; + ExtraLines = new Vector2[] { }; + StarColor = Color.Orchid; + break; + case Attunement.SuperPogo: //Drawing Ursa Minor + StarPositions = new Vector2[] { new Vector2(69, -188), new Vector2(18, -122), new Vector2(-23, -39), new Vector2(-13, 63), new Vector2(42, 147), new Vector2(-8, 184), new Vector2(-61, 83) }; + ExtraLines = new Vector2[] { new Vector2(3, 6) }; + StarColor = Color.CornflowerBlue; + break; + case Attunement.Shockwave: //Drawing Andromeda + //https://media.discordapp.net/attachments/802291445360623686/934200685254291546/unknown.png + StarPositions = new Vector2[] { + new Vector2(-210, -46), new Vector2(-150, -35), new Vector2(-69, 18), new Vector2(33, 61), new Vector2(127, 72), //The horizontal line + new Vector2(-41, -27), new Vector2(-41, -67), new Vector2(-100, -124), new Vector2(-160, -130), //The first branch from the left + new Vector2(15, 147), new Vector2(35, 126), new Vector2(37, 23), new Vector2(67, -47), new Vector2(126, -109), new Vector2(146, -136), //The second branch from the left + new Vector2(95, -117) + }; + ExtraLines = new Vector2[] { new Vector2(2, 5) , new Vector2(13, 15) }; + IgnoredLines.Add(5); + IgnoredLines.Add(9); + IgnoredLines.Add(15); + StarColor = Color.MediumSlateBlue; + break; + case Attunement.Whirlwind: //Drawing Phoenix + default: + StarPositions = new Vector2[] { new Vector2(-206, -99), new Vector2(-150, -43), new Vector2(-120, -146), new Vector2(-60, -71), new Vector2(-106, 71), new Vector2(-59, 138), new Vector2(116, -22),//The main line + new Vector2(246, -26), new Vector2(192, 36), new Vector2(138, 81), //The side bit + new Vector2(88, -107), new Vector2(84, -75) }; //Complete the loop + ExtraLines = new Vector2[] { new Vector2(3, 10), new Vector2(11, 6) }; + IgnoredLines.Add(10); + StarColor = Color.OrangeRed; + break; + } + + //Only draw the cool effect if you have enough particle slots left. Itd look really ugly to have a half complete constellation + if (GeneralParticleHandler.FreeSpacesAvailable() > StarPositions.Length * 2) + { + for (int i = 0; i < StarPositions.Length; i++) + { + //The polar star gets bigger than the others. Also since andromeda has so many stars, make em smaller + Star = new GenericSparkle(Owner.Center + StarPositions[i], Vector2.Zero, Color.White, StarColor, (attunement == Attunement.SuperPogo && i == 0) ? 3f : Main.rand.NextFloat(1f, 1.5f) * (attunement == Attunement.Shockwave ? 0.8f : 1f), 20, 0f, 3f); + GeneralParticleHandler.SpawnParticle(Star); + + if (i > 0 && !IgnoredLines.Contains(i)) + { + Line = new BloomLineVFX(Owner.Center + StarPositions[i - 1], StarPositions[i] - StarPositions[i - 1], 0.5f, StarColor, 20, true); + GeneralParticleHandler.SpawnParticle(Line); + } + } + + for (int i = 0; i < ExtraLines.Length; i++) + { + Line = new BloomLineVFX(Owner.Center + StarPositions[(int)ExtraLines[i].Y], StarPositions[(int)ExtraLines[i].X] - StarPositions[(int)ExtraLines[i].Y], 0.5f, StarColor, 20, true); + GeneralParticleHandler.SpawnParticle(Line); + } + } + + //Chunger + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/ThunderStrike"), projectile.Center); + if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < 5) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = 5; + item.mainAttunement = attunement; + } + } } diff --git a/Items/Weapons/Melee/FourSeasonsGalaxia.png b/Items/Weapons/Melee/FourSeasonsGalaxia.png deleted file mode 100644 index 89aa4426cc..0000000000 Binary files a/Items/Weapons/Melee/FourSeasonsGalaxia.png and /dev/null differ diff --git a/Items/Weapons/Melee/GalaxiaBlue.png b/Items/Weapons/Melee/GalaxiaBlue.png new file mode 100644 index 0000000000..83e7599cde Binary files /dev/null and b/Items/Weapons/Melee/GalaxiaBlue.png differ diff --git a/Items/Weapons/Melee/GalaxiaExtra.png b/Items/Weapons/Melee/GalaxiaExtra.png new file mode 100644 index 0000000000..3eab3f5872 Binary files /dev/null and b/Items/Weapons/Melee/GalaxiaExtra.png differ diff --git a/Items/Weapons/Melee/GalaxiaExtra2.png b/Items/Weapons/Melee/GalaxiaExtra2.png new file mode 100644 index 0000000000..f625f1a98e Binary files /dev/null and b/Items/Weapons/Melee/GalaxiaExtra2.png differ diff --git a/Items/Weapons/Melee/GalaxiaRed.png b/Items/Weapons/Melee/GalaxiaRed.png new file mode 100644 index 0000000000..8d0b7ed61f Binary files /dev/null and b/Items/Weapons/Melee/GalaxiaRed.png differ diff --git a/Items/Weapons/Melee/OmegaBiomeBlade.cs b/Items/Weapons/Melee/OmegaBiomeBlade.cs index 6dc37762b3..aed3d19d30 100644 --- a/Items/Weapons/Melee/OmegaBiomeBlade.cs +++ b/Items/Weapons/Melee/OmegaBiomeBlade.cs @@ -1,26 +1,217 @@ using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables; +using CalamityMod.Particles; using CalamityMod.Projectiles.Melee; using CalamityMod.Items.Placeables.Ores; 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 Terraria.ModLoader.IO; +using static CalamityMod.CalamityUtils; +using static CalamityMod.Items.Weapons.Melee.OmegaBiomeBlade; +using static Terraria.ModLoader.ModContent; namespace CalamityMod.Items.Weapons.Melee { public class OmegaBiomeBlade : ModItem { + public enum Attunement : byte { SuperPogo, Whirlwind, Shockwave, FlailBlade } + public Attunement? mainAttunement = null; + public Attunement? secondaryAttunement = null; + public Projectile MeatHook; + + //Used for passive effects + public int UseTimer = 0; + public bool OnHitProc = false; + + #region stats + public static int WhirlwindAttunement_BaseDamage = 400; + public static int WhirlwindAttunement_LocalIFrames = 20; //Remember its got one extra update + public static int WhirlwindAttunement_SigilTime = 1200; + public static float WhirlwindAttunement_BeamDamageReduction = 0.5f; + public static float WhirlwindAttunement_BaseDamageReduction = 0.2f; + public static float WhirlwindAttunement_FullChargeDamageBoost = 2f; + + public static int WhirlwindAttunement_PassiveBaseDamage = 200; + + + public static int SuperPogoAttunement_BaseDamage = 500; + public static int SuperPogoAttunement_ShredIFrames = 10; + public static int SuperPogoAttunement_LocalIFrames = 30; //Be warned its got one extra update so all the iframes should be divided in 2 + public static int SuperPogoAttunement_LocalIFramesCharged = 16; + public static float SuperPogoAttunement_SlashDamageBoost = 5f; //Keep in mind the slice always crits + public static int SuperPogoAttunementSlashLifesteal = 6; + public static int SuperPogoAttunement_SlashIFrames = 60; + public static float SuperPogoAttunement_ShotDamageBoost = 2f; + + public static int SuperPogoAttunement_PassiveLifeSteal = 10; + + + public static int ShockwaveAttunement_BaseDamage = 2500; + public static int ShockwaveAttunement_DashHitIFrames = 60; + public static float ShockwaveAttunement_FullChargeBoost = 1f; //The EXTRA damage boost. So putting 1 here will make it deal double damage. Putting 0.5 here will make it deal 1.5x the damage. + public static float ShockwaveAttunement_MonolithDamageBoost = 2f; + public static float ShockwaveAttunement_BlastDamageReduction = 0.6f; + + public static int ShockwaveAttunement_PassiveBaseDamage = 200; + + + public static int FlailBladeAttunement_BaseDamage = 320; + public static int FlailBladeAttunement_LocalIFrames = 30; + public static int FlailBladeAttunement_FlailTime = 10; + public static int FlailBladeAttunement_Reach = 400; + public static float FlailBladeAttunement_ChainDamageReduction = 0.5f; + public static float FlailBladeAttunement_GhostChainDamageReduction = 0.5f; + + public static int FlailBladeAttunement_PassiveBaseDamage = 500; + + //Proc coefficients. aka the likelihood of any given attack to trigger a on-hit passive. + public static float WhirlwindAttunement_WhirlwindProc = 0.24f; + public static float WhirlwindAttunement_SwordThrowProc = 1f; + public static float WhirlwindAttunement_SwordBeamProc = 0.05f; + + public static float SuperPogoAttunement_ShredderProc = 0.1f; + public static float SuperPogoAttunement_WheelProc = 0.4f; + public static float SuperPogoAttunement_DashProc = 1f; + + public static float ShockwaveAttunement_SwordProc = 1f; + public static float ShockwaveAttunement_MonolithProc = 1f; + public static float ShockwaveAttunement_BlastProc = 0.5f; + + public static float FlailBladeAttunement_BladeProc = 0.1f; + public static float FlailBladeAttunement_ChainProc = 0.05f; + public static float FlailBladeAttunement_GhostChainProc = 0.1f; + #endregion + public override void SetStaticDefaults() { - DisplayName.SetDefault("Omega Biome Blade"); - Tooltip.SetDefault("Fires different homing projectiles based on what biome you're in\n" + - "Projectiles also change based on moon events"); + DisplayName.SetDefault("True Biome Blade"); + Tooltip.SetDefault("FUNCTION_DESC\n" + + "FUNCTION_EXTRA\n" + + "FUNCTION_PASSIVE\n" + + "Holding down RMB for 2 seconds attunes the weapon to the powers of the surrounding biome\n" + + "Using RMB for a shorter period of time switches your active and passive attunements around\n" + + "Active attunement : None\n" + + "Passive attunement: None\n"); } + #region tooltip editing + public override void ModifyTooltips(List list) + { + Player player = Main.player[Main.myPlayer]; + if (player is null) + return; + + foreach (TooltipLine l in list) + { + if (l.text.StartsWith("FUNCTION_DESC")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = info.function_description; + } + + if (l.text.StartsWith("FUNCTION_EXTRA")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = info.function_extra; + } + + if (l.text.StartsWith("FUNCTION_PASSIVE")) + { + AttunementInfo info = GetAttunementInfo(secondaryAttunement); + l.overrideColor = info.color; + l.text = info.function_passive; + } + + if (l.text.StartsWith("Active attunement")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = Color.Lerp(info.color, info.color2, 0.5f + (float)Math.Sin(Main.GlobalTime) * 0.5f); + l.text = "Active Attumenent : [" + info.name + "]"; + } + + if (l.text.StartsWith("Passive attunement")) + { + AttunementInfo info = GetAttunementInfo(secondaryAttunement); + l.overrideColor = Color.Lerp(Color.Lerp(info.color, info.color2, 0.5f + (float)Math.Sin(Main.GlobalTime) * 0.5f), Color.Gray, 0.5f); + l.text = "Passive Attumenent : [" + info.name + "]"; + } + } + } + + internal struct AttunementInfo + { + public string name; + public string function_description; + public string function_extra; + public string function_passive; + public Color color; + public Color color2; + } + + internal AttunementInfo GetAttunementInfo(Attunement? attunement) + { + AttunementInfo AttunementInfo = new AttunementInfo(); + + switch (attunement) + { + case Attunement.Whirlwind: + 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 = "While attacking, extra ghost swords have a chance to be shot out"; + AttunementInfo.color = new Color(220, 105, 197); + AttunementInfo.color2 = new Color(171, 239, 113); + break; + case Attunement.SuperPogo: + 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 = "Successful strikes rarely grant lifesteal"; + AttunementInfo.color = new Color(216, 55, 22); + AttunementInfo.color2 = new Color(216, 131, 22); + break; + case Attunement.Shockwave: + 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 = "While attacking, release small shockwaves around you"; + AttunementInfo.color = new Color(132, 109, 233); + AttunementInfo.color2 = new Color(122, 213, 233); + break; + case Attunement.FlailBlade: + 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"; + 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(113, 239, 177); + AttunementInfo.color2 = new Color(169, 207, 255); + break; + default: + AttunementInfo.name = "None"; + AttunementInfo.function_description = "Does nothing... yet"; + AttunementInfo.function_extra = "It seems upgrading the blade expanded the scope of the previous attunements"; + AttunementInfo.function_passive = "Your secondary attunement can now provide passive bonuses"; + AttunementInfo.color = new Color(163, 163, 163); + AttunementInfo.color2 = new Color(163, 163, 163); + break; + } + return AttunementInfo; + } + + #endregion + public override void SetDefaults() { - item.width = 62; + item.width = item.height = 92; item.damage = 130; item.melee = true; item.useAnimation = 18; @@ -30,43 +221,485 @@ namespace CalamityMod.Items.Weapons.Melee item.knockBack = 8; item.UseSound = SoundID.Item1; item.autoReuse = true; - item.height = 62; item.value = CalamityGlobalItem.Rarity11BuyPrice; item.rare = ItemRarityID.Purple; - item.shoot = ModContent.ProjectileType(); + item.shoot = ProjectileID.PurificationPowder; item.shootSpeed = 15f; } - public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) - { - for (int projectiles = 0; projectiles < 3; projectiles++) - { - float SpeedX = speedX + Main.rand.Next(-40, 41) * 0.05f; - float SpeedY = speedY + Main.rand.Next(-40, 41) * 0.05f; - Projectile.NewProjectile(position.X, position.Y, SpeedX, SpeedY, type, damage, knockBack, player.whoAmI); - } - return false; - } - public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); - recipe.AddIngredient(ModContent.ItemType()); - recipe.AddIngredient(ModContent.ItemType()); - recipe.AddIngredient(ModContent.ItemType(), 3); - recipe.AddIngredient(ModContent.ItemType(), 3); - recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ItemType()); + recipe.AddIngredient(ItemType()); + recipe.AddIngredient(ItemType(), 3); + recipe.AddIngredient(ItemType(), 3); + recipe.AddIngredient(ItemType(), 5); recipe.AddTile(TileID.LunarCraftingStation); recipe.SetResult(this); recipe.AddRecipe(); } - public override void MeleeEffects(Player player, Rectangle hitbox) + #region Saving and syncing attunements + public override bool CloneNewInstances => true; + + public override ModItem Clone(Item item) { - if (Main.rand.NextBool(5)) + var clone = base.Clone(item); + if (Main.mouseItem.type == ItemType()) + item.modItem.HoldItem(Main.player[Main.myPlayer]); + (clone as OmegaBiomeBlade).mainAttunement = (item.modItem as OmegaBiomeBlade).mainAttunement; + (clone as OmegaBiomeBlade).secondaryAttunement = (item.modItem as OmegaBiomeBlade).secondaryAttunement; + + return clone; + } + + public override ModItem Clone() //ditto + { + var clone = base.Clone(); + (clone as OmegaBiomeBlade).mainAttunement = mainAttunement; + (clone as OmegaBiomeBlade).secondaryAttunement = secondaryAttunement; + + return clone; + } + + public override TagCompound Save() + { + int attunement1 = mainAttunement == null ? -1 : (int)mainAttunement; + int attunement2 = secondaryAttunement == null ? -1 : (int)secondaryAttunement; + TagCompound tag = new TagCompound { - int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 0); + { "mainAttunement", attunement1 }, + { "secondaryAttunement", attunement2 } + }; + return tag; + } + + public override void Load(TagCompound tag) + { + int attunement1 = tag.GetInt("mainAttunement"); + int attunement2 = tag.GetInt("secondaryAttunement"); + if (attunement1 == -1) + mainAttunement = null; + else + mainAttunement = (Attunement?)attunement1; + + if (attunement2 == -1 || (attunement1 == attunement2)) + secondaryAttunement = null; + else + secondaryAttunement = (Attunement?)attunement2; + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write((byte)mainAttunement); + writer.Write((byte)secondaryAttunement); + } + + public override void NetRecieve(BinaryReader reader) + { + mainAttunement = (Attunement?)reader.ReadByte(); + secondaryAttunement = (Attunement?)reader.ReadByte(); + } + + #endregion + + public override void HoldItem(Player player) + { + player.Calamity().rightClickListener = true; + + //Reset the strong lunge thing just in case it didnt get caught beofre. + + if (CanUseItem(player)) + { + player.Calamity().LungingDown = false; } + else + { + UseTimer++; + } + + //Change the swords function based on its attunement + switch (mainAttunement) + { + case Attunement.Whirlwind: + item.damage = WhirlwindAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + case Attunement.SuperPogo: + item.damage = SuperPogoAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + case Attunement.Shockwave: + item.damage = ShockwaveAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + case Attunement.FlailBlade: + item.damage = FlailBladeAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + break; + default: + item.noUseGraphic = false; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileID.PurificationPowder; + item.shootSpeed = 12f; + item.UseSound = SoundID.Item1; + break; + } + + if (player.whoAmI != Main.myPlayer) + return; + + //PAssive effetcsts only happen on the side of the owner + if (secondaryAttunement != Attunement.FlailBlade || MeatHook == null || !MeatHook.active) + MeatHook = null; + + switch (secondaryAttunement) + { + case Attunement.Whirlwind: + if (UseTimer % 30 == 29 && Main.rand.Next(2) == 0) + { + Main.PlaySound(SoundID.Item78); + Projectile beamSword = Projectile.NewProjectileDirect(player.Center, player.DirectionTo(Main.MouseWorld) * 15f, ProjectileType(), (int)(WhirlwindAttunement_PassiveBaseDamage * player.MeleeDamage()), 10f, player.whoAmI, 1f); + beamSword.timeLeft = 50; + UseTimer++; + } + break; + + case Attunement.SuperPogo: + if (OnHitProc) + { + player.statLife += SuperPogoAttunement_PassiveLifeSteal; + player.HealEffect(SuperPogoAttunement_PassiveLifeSteal); + + OnHitProc = false; + } + break; + + case Attunement.Shockwave: + if (UseTimer % 120 == 119) + { + Projectile.NewProjectile(player.Center, Vector2.Zero, ProjectileType(), (int)(ShockwaveAttunement_PassiveBaseDamage * player.MeleeDamage()), 10f, player.whoAmI, 1f); + UseTimer++; + } + break; + + case Attunement.FlailBlade: + + if (MeatHook == null) + { + MeatHook = Projectile.NewProjectileDirect(player.Center, Vector2.Zero, ProjectileType(), (int)(FlailBladeAttunement_PassiveBaseDamage * player.MeleeDamage()), 0f, player.whoAmI); + } + + if (OnHitProc) + { + if (MeatHook.modProjectile is ChainedMeatHook hook && hook.Twirling == 0f) + { + hook.Twirling = 1f; + hook.projectile.timeLeft = (int)ChainedMeatHook.MaxTwirlTime; + } + OnHitProc = false; + } + 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 + if (Main.projectile.Any(n => n.active && n.type == ProjectileType() && n.owner == player.whoAmI)) + return; + + Projectile.NewProjectile(player.Top, Vector2.Zero, ProjectileType(), 0, 0, player.whoAmI); + } + } + + public override bool CanUseItem(Player player) + { + return !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && + (n.type == ProjectileType() || + n.type == ProjectileType() || + n.type == ProjectileType() || + n.type == ProjectileType() + )); + } + + //No need for any wacky zany hijinx in the shoot method for once??? damn + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) => mainAttunement == null ? false : true; + + internal static ChargingEnergyParticleSet BiomeEnergyParticles = new ChargingEnergyParticleSet(-1, 2, Color.White, Color.White, 0.04f, 20f); + internal static void UpdateAllParticleSets() + { + BiomeEnergyParticles.Update(); + } + + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (mainAttunement == null) + return true; + + position.Y -= 6f * scale; + + Texture2D itemTexture = GetTexture("CalamityMod/Items/Weapons/Melee/OmegaBiomeBladeExtra"); + Rectangle itemFrame = (Main.itemAnimations[item.type] == null) ? itemTexture.Frame() : Main.itemAnimations[item.type].GetFrame(itemTexture); + + // Draw all particles. + + Vector2 particleDrawCenter = position + new Vector2(12f, 16f) * Main.inventoryScale; + + AttunementInfo info = GetAttunementInfo(mainAttunement); + BiomeEnergyParticles.EdgeColor = info.color2; + BiomeEnergyParticles.CenterColor = info.color; + BiomeEnergyParticles.InterpolationSpeed = 0.1f; + BiomeEnergyParticles.DrawSet(particleDrawCenter + Main.screenPosition); + + Vector2 displacement = Vector2.UnitX.RotatedBy(Main.GlobalTime * 3f) * 2f * (float)Math.Sin(Main.GlobalTime); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); + spriteBatch.Draw(itemTexture, position + displacement, itemFrame, BiomeEnergyParticles.CenterColor, 0f, origin, scale, SpriteEffects.None, 0f); + spriteBatch.Draw(itemTexture, position - displacement, itemFrame, BiomeEnergyParticles.CenterColor, 0f, origin, scale, SpriteEffects.None, 0f); + spriteBatch.End(); + spriteBatch.Begin(default, default); + + spriteBatch.Draw(itemTexture, position, itemFrame, Color.White, 0f, origin, scale, SpriteEffects.None, 0f); + return false; + } + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) + { + if (mainAttunement == null) + return true; + + //Draw the charged version if you can + Texture2D itemTexture = GetTexture("CalamityMod/Items/Weapons/Melee/OmegaBiomeBladeExtra"); + spriteBatch.Draw(itemTexture, item.Center - Main.screenPosition, null, lightColor, rotation, item.Size * 0.5f, scale, SpriteEffects.None, 0f); + return false; + } + } + + public class TrueBiomeBladeVisuals : ModProjectile //Visuals + { + private Player Owner => Main.player[projectile.owner]; + public bool OwnerCanUseItem => Owner.HeldItem == associatedItem ? (Owner.HeldItem.modItem as OmegaBiomeBlade).CanUseItem(Owner) : false; + public bool OwnerMayChannel => OwnerCanUseItem && Owner.Calamity().mouseRight && Owner.active && !Owner.dead; + public ref float ChanneledState => ref projectile.ai[0]; + public ref float ChannelTimer => ref projectile.ai[1]; + public ref float Initialized => ref projectile.localAI[0]; + + private Item associatedItem; + const int ChannelTime = 120; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("True Biome Blade"); + } + public override string Texture => "CalamityMod/Items/Weapons/Melee/OmegaBiomeBlade"; + public bool drawIndrawHeldProjInFrontOfHeldItemAndArms = true; + public override void SetDefaults() + { + projectile.width = projectile.height = 36; + projectile.aiStyle = -1; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 60; + projectile.tileCollide = false; + projectile.damage = 0; + } + + public CurveSegment anticipation = new CurveSegment(EasingType.SineBump, 0f, 0f, -0.3f); + public CurveSegment rise = new CurveSegment(EasingType.ExpIn, 0f, 0f, 1f); + public CurveSegment overshoot = new CurveSegment(EasingType.SineBump, 0.80f, 1f, 0.1f); + internal float SwordHeight() => PiecewiseAnimation(ChannelTimer / (float)ChannelTime, new CurveSegment[] {rise, overshoot }); + + public override void AI() + { + + if (Initialized == 0f) + { + //If dropped, kill it instantly + if (Owner.HeldItem.type != ItemType()) + { + projectile.Kill(); + return; + } + + if (Owner.whoAmI == Main.myPlayer) + Main.PlaySound(SoundID.DD2_DarkMageHealImpact); + + associatedItem = Owner.HeldItem; + //Switch up the attunements + Attunement? temporaryAttunementStorage = (associatedItem.modItem as OmegaBiomeBlade).mainAttunement; + (associatedItem.modItem as OmegaBiomeBlade).mainAttunement = (associatedItem.modItem as OmegaBiomeBlade).secondaryAttunement; + (associatedItem.modItem as OmegaBiomeBlade).secondaryAttunement = temporaryAttunementStorage; + Initialized = 1f; + } + + if (!OwnerMayChannel && ChanneledState == 0f) //IF the channeling gets interrupted for any reason + { + projectile.Center = Owner.Top + new Vector2(18f, 0f); + ChanneledState = 1f; + projectile.timeLeft = 60; + return; + } + + if (ChanneledState == 0f) + { + Owner.heldProj = projectile.whoAmI; + Owner.itemRotation = (-Vector2.UnitY).ToRotation(); + + projectile.Center = Owner.Top + new Vector2(0f, -20f * SwordHeight() - 50f); + projectile.rotation = -MathHelper.PiOver4; // No more silly turnaround with the repaired one? + ChannelTimer++; + projectile.timeLeft = 60; + + if (ChannelTimer == ChannelTime - 15) + { + Attune((OmegaBiomeBlade)associatedItem.modItem); + Color particleColor = (associatedItem.modItem as OmegaBiomeBlade).GetAttunementInfo((associatedItem.modItem as OmegaBiomeBlade).mainAttunement).color; + + for (int i = 0; i <= 5; i++) + { + Vector2 displace = Vector2.UnitX * 20 * Main.rand.NextFloat(-1f, 1f); + Particle Glow = new GenericBloom(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, 0.02f + Main.rand.NextFloat(0f, 0.2f), 20 + Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(Glow); + } + for (int i = 0; i <= 10; i++) + { + Vector2 displace = Vector2.UnitX * 16 * Main.rand.NextFloat(-1f, 1f); + Particle Sparkle = new GenericSparkle(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, particleColor, 0.5f + Main.rand.NextFloat(-0.2f, 0.2f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + + if (ChannelTimer >= ChannelTime - 15) + { + Vector2 Shake = Main.rand.NextVector2Circular(6f, 6f); + projectile.Center += Shake; + + Vector2 Bottom = projectile.Center + Vector2.UnitY * 20f; + Particle Sparkle = new ElectricSpark(Bottom, -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2) * Main.rand.NextFloat(10f, 20f), Color.White, Main.rand.NextBool() ? Main.rand.NextBool() ? Color.Goldenrod : Color.GreenYellow : Main.rand.NextBool() ? Color.Cyan : Color.Magenta, 1f + Main.rand.NextFloat(0f, 1f), 34, rotationSpeed : 0.1f, bloomScale : 4f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + if (ChannelTimer >= ChannelTime) + { + projectile.timeLeft = 60; + ChanneledState = 2f; //State where it stays invisible doing nothing. Acts as a cooldown + } + } + + if (ChanneledState == 1f) + projectile.position += Vector2.UnitY * -0.3f * (1f + projectile.timeLeft / 60f); + } + + public void Attune(OmegaBiomeBlade item) + { + bool jungle = Owner.ZoneJungle; + bool snow = Owner.ZoneSnow; + bool evil = Owner.ZoneCorrupt || Owner.ZoneCrimson; + bool desert = Owner.ZoneDesert; + bool hell = Owner.ZoneUnderworldHeight; + bool ocean = Owner.ZoneBeach; + bool holy = Owner.ZoneHoly; + bool astral = Owner.Calamity().ZoneAstral; + bool marine = Owner.Calamity().ZoneAbyss || Owner.Calamity().ZoneSunkenSea; + + Attunement attunement = Attunement.Whirlwind; + if (desert || hell) + attunement = Attunement.SuperPogo; + if (jungle || ocean || snow) //Check put after the desert check so ocean doesnt get overriden as desert + attunement = Attunement.FlailBlade; + if (evil) //Evil check separated so that it overrides corrupted beach & snow biomes + attunement = Attunement.SuperPogo; + if (astral || marine) + attunement = Attunement.Shockwave; + if (holy) + attunement = Attunement.Whirlwind; //Putting holy attunement at the end so it may override hallowed variants of biomes + + //If the owner already had the attunement , break out of it (And unswap) + if (item.secondaryAttunement == attunement) + { + Main.PlaySound(SoundID.DD2_LightningBugZap, projectile.Center); + item.secondaryAttunement = item.mainAttunement; + item.mainAttunement = attunement; + return; + } + //Chunger + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/ThunderStrike"), projectile.Center); + Particle thunder = new ThunderBoltVFX(projectile.Center + Vector2.UnitY * 20f, Main.rand.NextBool() ? Main.rand.NextBool() ? Color.Goldenrod : Color.GreenYellow : Main.rand.NextBool() ? Color.Cyan : Color.Magenta, 0f, 1.5f, Vector2.One, 1f, 15f, projectile, 20f); + GeneralParticleHandler.SpawnParticle(thunder); + + if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < 5) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = 5; + + item.mainAttunement = attunement; + } + + public override void Kill(int timeLeft) + { + if (associatedItem == null) + { + return; + } + //If we swapped out the main attunement for the second one despite the second attunement being empty at the time, unswap them. + if ((associatedItem.modItem as OmegaBiomeBlade).mainAttunement == null && (associatedItem.modItem as OmegaBiomeBlade).secondaryAttunement != null) + { + (associatedItem.modItem as OmegaBiomeBlade).mainAttunement = (associatedItem.modItem as OmegaBiomeBlade).secondaryAttunement; + (associatedItem.modItem as OmegaBiomeBlade).secondaryAttunement = null; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + + + if (ChanneledState == 0f && ChannelTimer > 10f) + { + Texture2D tex = GetTexture(Texture); + spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, lightColor, projectile.rotation, tex.Size() / 2, 1, 0, 0); + + return false; + + } + else if (ChanneledState == 1f) + { + Texture2D tex = GetTexture(Texture); + Vector2 squishyScale = new Vector2(Math.Abs((float)Math.Sin(MathHelper.Pi + MathHelper.TwoPi * projectile.timeLeft / 30f)), 1f); + SpriteEffects flip = (float)Math.Sin(MathHelper.Pi + MathHelper.TwoPi * projectile.timeLeft / 30f) > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + spriteBatch.Draw(tex, projectile.position - Main.screenPosition, null, lightColor * (projectile.timeLeft / 60f), 0, tex.Size() / 2, squishyScale * (2f - (projectile.timeLeft / 60f)), flip, 0); + + return false; + } + + else + return false; } } } diff --git a/Items/Weapons/Melee/OmegaBiomeBlade.png b/Items/Weapons/Melee/OmegaBiomeBlade.png index 993994f714..8c2adfd24b 100644 Binary files a/Items/Weapons/Melee/OmegaBiomeBlade.png and b/Items/Weapons/Melee/OmegaBiomeBlade.png differ diff --git a/Items/Weapons/Melee/OmegaBiomeBladeExtra.png b/Items/Weapons/Melee/OmegaBiomeBladeExtra.png new file mode 100644 index 0000000000..1e3cd0bf70 Binary files /dev/null and b/Items/Weapons/Melee/OmegaBiomeBladeExtra.png differ diff --git a/Items/Weapons/Melee/TrueArkoftheAncients.cs b/Items/Weapons/Melee/TrueArkoftheAncients.cs index da95fb46ad..a9b9e38708 100644 --- a/Items/Weapons/Melee/TrueArkoftheAncients.cs +++ b/Items/Weapons/Melee/TrueArkoftheAncients.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { - item.width = 60; + item.width = item.height = 72; item.damage = 98; item.melee = true; item.useAnimation = 25; @@ -29,7 +29,6 @@ namespace CalamityMod.Items.Weapons.Melee item.knockBack = 6.5f; item.UseSound = SoundID.Item1; item.autoReuse = true; - item.height = 60; item.value = Item.buyPrice(0, 80, 0, 0); item.rare = ItemRarityID.Yellow; item.shoot = ModContent.ProjectileType(); diff --git a/Items/Weapons/Melee/TrueArkoftheAncients.png b/Items/Weapons/Melee/TrueArkoftheAncients.png index 9bcb7bd2f8..40a3d0338a 100644 Binary files a/Items/Weapons/Melee/TrueArkoftheAncients.png and b/Items/Weapons/Melee/TrueArkoftheAncients.png differ diff --git a/Items/Weapons/Melee/TrueBiomeBlade.cs b/Items/Weapons/Melee/TrueBiomeBlade.cs index d3798af489..37f544ed1c 100644 --- a/Items/Weapons/Melee/TrueBiomeBlade.cs +++ b/Items/Weapons/Melee/TrueBiomeBlade.cs @@ -1,24 +1,201 @@ using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables; +using CalamityMod.Particles; using CalamityMod.Projectiles.Melee; 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 Terraria.ModLoader.IO; +using static CalamityMod.CalamityUtils; +using static CalamityMod.Items.Weapons.Melee.TrueBiomeBlade; +using static Terraria.ModLoader.ModContent; namespace CalamityMod.Items.Weapons.Melee { public class TrueBiomeBlade : ModItem { + public enum Attunement : byte { Default, Hot, Cold, Tropical, Evil, Holy, Astral, Marine } + public Attunement? mainAttunement = null; + public Attunement? secondaryAttunement = null; + public int Combo = 0; + public int StoredLunges = 2; + public int PowerLungeCounter = 0; + + #region stats + public static int DefaultAttunement_BaseDamage = 160; + public static int DefaultAttunement_SigilTime = 600; + + public static int EvilAttunement_BaseDamage = 320; + public static int EvilAttunement_Lifesteal = 4; + public static int EvilAttunement_BounceIFrames = 10; + public static float EvilAttunement_SlashDamageBoost = 3f; + public static int EvilAttunement_SlashIFrames = 60; + + public static int ColdAttunement_BaseDamage = 320; + public static float ColdAttunement_SecondSwingBoost = 1.8f; + public static float ColdAttunement_ThirdSwingBoost = 3f; + public static float ColdAttunement_MistDamageReduction = 0.2f; + + public static int HotAttunement_BaseDamage = 320; + public static int HotAttunement_ShredIFrames = 8; + public static float HotAttunement_ShotDamageBoost = 2; + public static int HotAttunement_LocalIFrames = 30; //Be warned its got one extra update so all the iframes should be divided in 2 + public static int HotAttunement_LocalIFramesCharged = 16; + + public static int TropicalAttunement_BaseDamage = 160; + public static float TropicalAttunement_ChainDamageReduction = 0.5f; + public static float TropicalAttunement_VineDamageReduction = 0.5f; + public static int TropicalAttunement_LocalIFrames = 60; //Be warned its got 2 extra updates so all the iframes should be divided in 3 + + public static int HolyAttunement_BaseDamage = 160; + public static float HolyAttunement_BaseDamageReduction = 0.2f; + public static float HolyAttunement_FullChargeDamageBoost = 2f; + public static int HolyAttunement_LocalIFrames = 16; //Be warned its got 1 extra update yadda yadda + + public static int AstralAttunement_BaseDamage = 500; + public static int AstralAttunement_DashHitIFrames = 30; + public static float AstralAttunement_FullChargeBoost = 1f; //The EXTRA damage boost. So putting 1 here will make it deal double damage. Putting 0.5 here will make it deal 1.5x the damage. + public static float AstralAttunement_MonolithDamageBoost = 2f; + + public static int MarineAttunement_BaseDamage = 160; + #endregion + + public override void SetStaticDefaults() { - DisplayName.SetDefault("True Biome Blade"); - Tooltip.SetDefault("Fires different projectiles based on what biome you're in"); + DisplayName.SetDefault("Biome Blade"); + Tooltip.SetDefault("FUNCTION_DESC\n" + + "FUNCTION_EXTRA\n" + + "Use RMB while standing still on the ground to attune the weapon to the powers of the surrounding biome\n" + + "Using RMB otherwise switches between the current attunement and an extra stored one\n" + + "Main attunement : None\n" + + "Secondary attunement: None\n"); //Theres potential for flavor text as well but im not a writer } + #region tooltip editing + + public override void ModifyTooltips(List list) + { + Player player = Main.player[Main.myPlayer]; + if (player is null) + return; + + foreach (TooltipLine l in list) + { + if (l.text.StartsWith("FUNCTION_DESC")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = info.function_description; + } + + if (l.text.StartsWith("FUNCTION_EXTRA")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = info.function_extra; + } + + if (l.text.StartsWith("Main attunement")) + { + AttunementInfo info = GetAttunementInfo(mainAttunement); + l.overrideColor = info.color; + l.text = "Main Attumenent : [" + info.name + "]"; + } + + if (l.text.StartsWith("Secondary attunement")) + { + AttunementInfo info = GetAttunementInfo(secondaryAttunement); + l.overrideColor = Color.Lerp(info.color, Color.Gray, 0.5f); + l.text = "Secondary Attumenent : [" + info.name + "]"; + } + } + } + + internal struct AttunementInfo + { + public string name; + public string function_description; + public string function_extra; + public Color color; + } + + internal AttunementInfo GetAttunementInfo(Attunement? attunement) + { + AttunementInfo AttunementInfo = new AttunementInfo(); + + switch (attunement) + { + case Attunement.Default: + AttunementInfo.name = "Pure Clarity"; + AttunementInfo.function_description = "Fires a weak projectile that crushes enemy defenses"; + AttunementInfo.function_extra = "Landing true melee hits places a sigil of purity over the enemy. Your projectiles home onto the marked foes"; + AttunementInfo.color = new Color(171, 180, 73); + break; + case Attunement.Hot: + AttunementInfo.name = "Arid Grandeur"; + AttunementInfo.function_description = "Conjures searing 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 after charging up the blades sends them out flying to shred your foes"; + AttunementInfo.color = new Color(238, 156, 73); + break; + case Attunement.Cold: + AttunementInfo.name = "Biting Embrace"; + AttunementInfo.function_description = "Perform a 3 strike combo with a glacial blade. The final strike freezes foes for a split second"; + AttunementInfo.function_extra = "Lingering glacial mist is released on each swing, dealing damage to enemies wandering into it"; + AttunementInfo.color = new Color(165, 235, 235); + break; + case Attunement.Tropical: + AttunementInfo.name = "Grovetender's Touch"; + AttunementInfo.function_description = "Throw out the blade using a vine whip. Striking enemies with the tip of the whip as it cracks guarantees a critical hit. The whip will also propel you towards struck tiles"; + AttunementInfo.function_extra = "Critical strikes sprout up extra vines that can hit up to three targets"; + AttunementInfo.color = new Color(162, 200, 85); + break; + case Attunement.Evil: + AttunementInfo.name = "Decay's Retort"; + AttunementInfo.function_description = "Lunge forward using a ghostly rapier projection that leeches life off any struck foes. You also get bounced away from hit targets"; + AttunementInfo.function_extra = "Lining up three strikes without touching the ground empowers the next strike into a powerful dash thrust "; + AttunementInfo.color = new Color(211, 64, 147); + break; + case Attunement.Holy: + AttunementInfo.name = "Heaven's Might"; + AttunementInfo.function_description = "Hold LMB to swing the sword around you, powering up as it spins"; + AttunementInfo.function_extra = "Releasing LMB will throw the sword in front of you, flying a short distance away before coming back"; + AttunementInfo.color = new Color(220, 143, 255); + break; + case Attunement.Astral: + AttunementInfo.name = "Their Abhorrence"; + AttunementInfo.function_description = "Hold LMB to charge up a star-piercing sword thrust, and release to unleash the devastating blow"; + AttunementInfo.function_extra = "Striking the ground after a jump will create an impact so powerful massive otherwordly monoliths will rise up from the earth"; + AttunementInfo.color = new Color(91, 73, 196); + break; + case Attunement.Marine: + AttunementInfo.name = "Gesture for the Drowned"; + AttunementInfo.function_description = "Shoot out two water balls at your sides. On ground contact the water balls will turn into small waves that ride along the ground"; + AttunementInfo.function_extra = "If used while submerged, or if the waves contact water, the waves will turn into bigger and faster ones"; + AttunementInfo.color = new Color(98, 225, 255); + break; + default: + AttunementInfo.name = "None"; + AttunementInfo.function_description = "Does nothing... yet"; + AttunementInfo.function_extra = "Repairing the blade did increase its attuning capacities"; + AttunementInfo.color = new Color(163, 163, 163); + break; + } + + return AttunementInfo; + } + + #endregion + public override void SetDefaults() { - item.width = 54; + item.width = item.height = 68; item.damage = 160; item.melee = true; item.useAnimation = 21; @@ -28,33 +205,577 @@ namespace CalamityMod.Items.Weapons.Melee item.knockBack = 7.5f; item.UseSound = SoundID.Item1; item.autoReuse = true; - item.height = 54; item.value = Item.buyPrice(0, 80, 0, 0); item.rare = ItemRarityID.Yellow; - item.shoot = ModContent.ProjectileType(); + item.shoot = ProjectileID.PurificationPowder; item.shootSpeed = 12f; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); - recipe.AddIngredient(ModContent.ItemType()); - recipe.AddIngredient(ModContent.ItemType(), 5); - recipe.AddIngredient(ItemID.Ectoplasm, 5); - recipe.AddIngredient(ModContent.ItemType(), 10); - recipe.AddIngredient(ModContent.ItemType(), 10); - recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ItemType()); + recipe.AddIngredient(ItemType(), 5); + recipe.AddIngredient(ItemID.PixieDust, 2); + recipe.AddIngredient(ItemType(), 10); + recipe.AddIngredient(ItemType(), 5); + recipe.AddIngredient(ItemType(), 5); + recipe.AddIngredient(ItemType(), 5); recipe.AddTile(TileID.MythrilAnvil); recipe.SetResult(this); recipe.AddRecipe(); } - public override void MeleeEffects(Player player, Rectangle hitbox) + #region Saving and syncing attunements + public override bool CloneNewInstances => true; + + public override ModItem Clone(Item item) { - if (Main.rand.NextBool(5)) + var clone = base.Clone(item); + if (Main.mouseItem.type == ItemType()) + item.modItem.HoldItem(Main.player[Main.myPlayer]); + (clone as TrueBiomeBlade).mainAttunement = (item.modItem as TrueBiomeBlade).mainAttunement; + (clone as TrueBiomeBlade).secondaryAttunement = (item.modItem as TrueBiomeBlade).secondaryAttunement; + + return clone; + } + + public override ModItem Clone() //ditto + { + var clone = base.Clone(); + (clone as TrueBiomeBlade).mainAttunement = mainAttunement; + (clone as TrueBiomeBlade).secondaryAttunement = secondaryAttunement; + + return clone; + } + + public override TagCompound Save() + { + int attunement1 = mainAttunement == null ? -1 : (int)mainAttunement; + int attunement2 = secondaryAttunement == null ? -1 : (int)secondaryAttunement; + TagCompound tag = new TagCompound { - int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 0); + { "mainAttunement", attunement1 }, + { "secondaryAttunement", attunement2 } + }; + return tag; + } + + public override void Load(TagCompound tag) + { + int attunement1 = tag.GetInt("mainAttunement"); + int attunement2 = tag.GetInt("secondaryAttunement"); + if (attunement1 == -1) + mainAttunement = null; + else + mainAttunement = (Attunement?)attunement1; + + if (attunement2 == -1 || (attunement1 == attunement2)) + secondaryAttunement = null; + else + secondaryAttunement = (Attunement?)attunement2; + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write((byte)mainAttunement); + writer.Write((byte)secondaryAttunement); + } + + public override void NetRecieve(BinaryReader reader) + { + mainAttunement = (Attunement?)reader.ReadByte(); + secondaryAttunement = (Attunement?)reader.ReadByte(); + } + + #endregion + + + public override void HoldItem(Player player) + { + + player.Calamity().rightClickListener = true; + + if (player.velocity.Y == 0) //reset the amount of lunges on ground contact + { + StoredLunges = 2; + if (PowerLungeCounter != 3) + PowerLungeCounter = 0; } + + + + //Change the swords function based on its attunement + switch (mainAttunement) + { + case Attunement.Default: + item.damage = DefaultAttunement_BaseDamage; + item.channel = false; + item.noUseGraphic = false; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = SoundID.Item1; + item.noMelee = false; + + Combo = 0; + PowerLungeCounter = 0; + break; + case Attunement.Hot: + item.damage = HotAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + PowerLungeCounter = 0; + break; + case Attunement.Cold: + item.damage = ColdAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + PowerLungeCounter = 0; + break; + case Attunement.Tropical: + item.damage = TropicalAttunement_BaseDamage; + item.channel = false; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileType(); + item.shootSpeed = 30; + item.UseSound = null; + item.noMelee = true; + + PowerLungeCounter = 0; + break; + case Attunement.Evil: + item.damage = EvilAttunement_BaseDamage; + item.channel = false; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.Stabbing; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + break; + case Attunement.Holy: + item.damage = HolyAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.HoldingOut; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + PowerLungeCounter = 0; + break; + case Attunement.Astral: + item.damage = AstralAttunement_BaseDamage; + item.channel = true; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.Stabbing; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + PowerLungeCounter = 0; + break; + case Attunement.Marine: + item.damage = MarineAttunement_BaseDamage; + item.channel = false; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.Stabbing; + item.shoot = ProjectileType(); + item.shootSpeed = 12f; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + PowerLungeCounter = 0; + break; + default: + item.noUseGraphic = false; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileID.PurificationPowder; + item.shootSpeed = 12f; + item.UseSound = SoundID.Item1; + + Combo = 0; + PowerLungeCounter = 0; + 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 + if (Main.projectile.Any(n => n.active && n.type == ProjectileType() && n.owner == player.whoAmI)) + return; + + int x = (int)player.Center.X / 16; + int y = (int)(player.position.Y + (float)player.height - 1f) / 16; + Tile tileStandingOn = Main.tile[x, y + 1]; + + bool mayAttune = player.StandingStill() && !player.mount.Active && tileStandingOn.IsTileSolidGround(); + Vector2 displace = new Vector2(18f, 0f); + Projectile.NewProjectile(player.Top + displace, Vector2.Zero, ProjectileType(), 0, 0, player.whoAmI, mayAttune ? 0f : 1f); + } + } + + public override bool CanUseItem(Player player) + { + 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() || + n.type == ProjectileType())); + } + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + if (mainAttunement == null) + return false; + + switch (mainAttunement) + { + case Attunement.Cold: + switch (Combo) + { + case 0: + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 0, 15); + break; + + case 1: + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 1, 20); + break; + + case 2: + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 2, 50); + break; + } + Combo++; + if (Combo > 2) + Combo = 0; + return false; + + case Attunement.Tropical: + Projectile whipProj = Projectile.NewProjectileDirect(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 0, 0); + if (whipProj.modProjectile is TrueGrovetendersTouch whip) + whip.flipped = Combo == 0 ? 1 : -1; + Combo++; + if (Combo > 1) + Combo = 0; + return false; + + case Attunement.Evil: + bool powerLungeAvailable = false; + if (PowerLungeCounter == 3) + { + powerLungeAvailable = true; + PowerLungeCounter = 0; + } + Projectile proj = Projectile.NewProjectileDirect(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage, knockBack, player.whoAmI, 26f, StoredLunges > 0 ? 1f : 0f); + if (proj.modProjectile is TrueDecaysRetort rapier) + rapier.ChargedUp = powerLungeAvailable; + StoredLunges --; + if (StoredLunges < 0) + StoredLunges = 0; + return false; + + default: + return base.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack); + } + } + + //This is only used for the purity sigil effect of the default attunement + public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit) + { + if (mainAttunement != Attunement.Default || player.whoAmI != Main.myPlayer) + return; + + foreach (Projectile proj in Main.projectile) + { + if (proj.active && proj.type == ProjectileType() && proj.owner == player.whoAmI) + { + //Reset the timeleft on the sigil & give it its new target (or the same, it doesnt matter really. + proj.ai[0] = target.whoAmI; + proj.timeLeft = DefaultAttunement_SigilTime; + return; + } + } + Projectile.NewProjectile(target.Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0, player.whoAmI, target.whoAmI); + } + + internal static ChargingEnergyParticleSet BiomeEnergyParticles = new ChargingEnergyParticleSet(-1, 2, Color.White, Color.White, 0.04f, 20f); + internal static void UpdateAllParticleSets() + { + BiomeEnergyParticles.Update(); + } + + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + Texture2D itemTexture = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade"); + + if (mainAttunement == null) + { + spriteBatch.Draw(itemTexture, position, null, drawColor, 0f, origin, scale, SpriteEffects.None, 0f); + return true; + } + + + // Draw all particles. + + Vector2 particleDrawCenter = position + new Vector2(12f, 16f) * Main.inventoryScale; + + switch (mainAttunement) + { + case Attunement.Default: + BiomeEnergyParticles.EdgeColor = new Color(117, 126, 72); + BiomeEnergyParticles.CenterColor = new Color(200, 184, 136); + break; + case Attunement.Hot: + BiomeEnergyParticles.EdgeColor = new Color(137, 32, 0); + BiomeEnergyParticles.CenterColor = new Color(209, 154, 0); + break; + case Attunement.Cold: + BiomeEnergyParticles.EdgeColor = new Color(165, 235, 235); + BiomeEnergyParticles.CenterColor = new Color(58, 110, 141); + break; + case Attunement.Tropical: + BiomeEnergyParticles.EdgeColor = new Color(53, 112, 4); + BiomeEnergyParticles.CenterColor = new Color(131, 173, 39); + break; + case Attunement.Evil: + BiomeEnergyParticles.EdgeColor = new Color(112, 4, 35); + BiomeEnergyParticles.CenterColor = new Color(195, 42, 200); + break; + case Attunement.Holy: + case Attunement.Astral: + BiomeEnergyParticles.EdgeColor = new Color(62, 55, 110); + BiomeEnergyParticles.CenterColor = new Color(255, 143, 255); + break; + case Attunement.Marine: + BiomeEnergyParticles.EdgeColor = new Color(27, 59, 101); + BiomeEnergyParticles.CenterColor = new Color(27, 112643, 255); + break; + } + BiomeEnergyParticles.InterpolationSpeed = 0.1f; + BiomeEnergyParticles.DrawSet(particleDrawCenter + Main.screenPosition); + + Vector2 displacement = Vector2.UnitX.RotatedBy(Main.GlobalTime * 3f) * 2f * (float)Math.Sin(Main.GlobalTime); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); + spriteBatch.Draw(itemTexture, position + displacement, null, BiomeEnergyParticles.CenterColor, 0f, origin, scale, SpriteEffects.None, 0f); + spriteBatch.Draw(itemTexture, position - displacement, null, BiomeEnergyParticles.CenterColor, 0f, origin, scale, SpriteEffects.None, 0f); + spriteBatch.End(); + spriteBatch.Begin(default, default); + + spriteBatch.Draw(itemTexture, position, null, drawColor, 0f, origin, scale, SpriteEffects.None, 0f); + return false; + } + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) + { + Texture2D itemTexture = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade"); //Use the "projectile" sprite which is flipped so its consistent in lighting with the rest of the line, since its actual sprite is flipped so the swings may look normal + spriteBatch.Draw(itemTexture, item.Center - Main.screenPosition, null, lightColor, rotation, item.Size * 0.5f, scale, SpriteEffects.None, 0f); + return false; + } + + } + + public class MendedBiomeBladeVisuals : ModProjectile //Visuals + { + private Player Owner => Main.player[projectile.owner]; + public bool OwnerOnGround => Main.tile[(int)Owner.Center.X / 16, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround() && Main.tile[(int)Owner.Center.X / 16 + Owner.direction, (int)(Owner.position.Y + (float)Owner.height - 1f) / 16 + 1].IsTileSolidGround(); + public bool OwnerCanUseItem => Owner.HeldItem == associatedItem ? (Owner.HeldItem.modItem as TrueBiomeBlade).CanUseItem(Owner) : false; + public bool OwnerMayChannel => OwnerCanUseItem && Owner.Calamity().mouseRight && Owner.active && !Owner.dead && Owner.StandingStill() && !Owner.mount.Active && OwnerOnGround; + public ref float ChanneledState => ref projectile.ai[0]; + public ref float ChannelTimer => ref projectile.ai[1]; + public ref float Initialized => ref projectile.localAI[0]; + + private Item associatedItem; + const int ChannelTime = 120; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Mended Biome Blade"); + } + public override string Texture => "CalamityMod/Items/Weapons/Melee/TrueBiomeBlade"; + public bool drawIndrawHeldProjInFrontOfHeldItemAndArms = true; + public override void SetDefaults() + { + projectile.width = projectile.height = 36; + projectile.aiStyle = -1; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 60; + projectile.tileCollide = false; + projectile.damage = 0; + } + + public CurveSegment anticipation = new CurveSegment(EasingType.SineOut, 0f, 1f, 0.35f); + public CurveSegment thrust = new CurveSegment(EasingType.ExpIn, 0.85f, 1.35f, -1.45f); + public CurveSegment bounceback = new CurveSegment(EasingType.SineOut, 0.95f, -0.1f, 0.1f); + internal float SwordHeight() => PiecewiseAnimation(ChannelTimer / (float)ChannelTime, new CurveSegment[] { anticipation, thrust, bounceback }); + + public override void AI() + { + + if (Initialized == 0f) + { + //If dropped, kill it instantly + if (Owner.HeldItem.type != ItemType()) + { + projectile.Kill(); + return; + } + + if (Owner.whoAmI == Main.myPlayer) + Main.PlaySound(SoundID.DD2_DarkMageHealImpact); + + associatedItem = Owner.HeldItem; + //Switch up the attunements + Attunement? temporaryAttunementStorage = (associatedItem.modItem as TrueBiomeBlade).mainAttunement; + (associatedItem.modItem as TrueBiomeBlade).mainAttunement = (associatedItem.modItem as TrueBiomeBlade).secondaryAttunement; + (associatedItem.modItem as TrueBiomeBlade).secondaryAttunement = temporaryAttunementStorage; + Initialized = 1f; + } + + if (!OwnerMayChannel && ChanneledState == 0f) //IF the channeling gets interrupted for any reason + { + projectile.Center = Owner.Top + new Vector2(18f, 0f); + ChanneledState = 1f; + projectile.timeLeft = 60; + return; + } + + if (ChanneledState == 0f) + { + Owner.heldProj = projectile.whoAmI; + + projectile.Center = Owner.Center + new Vector2(16f * Owner.direction + Owner.direction < 0 ? -26f : 16f, -30 * SwordHeight() + 10f); + projectile.rotation = MathHelper.PiOver4 + MathHelper.PiOver2; // No more silly turnaround with the repaired one? + ChannelTimer++; + projectile.timeLeft = 60; + + if (ChannelTimer >= ChannelTime) + { + Attune((TrueBiomeBlade)associatedItem.modItem); + projectile.timeLeft = 120; + ChanneledState = 2f; //State where it stays invisible doing nothing. Acts as a cooldown + + Color particleColor = (associatedItem.modItem as TrueBiomeBlade).GetAttunementInfo((associatedItem.modItem as TrueBiomeBlade).mainAttunement).color; + + for (int i = 0; i <= 5; i++) + { + Vector2 displace = Vector2.UnitX * 20 * Main.rand.NextFloat(-1f, 1f); + Particle Glow = new GenericBloom(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, 0.02f + Main.rand.NextFloat(0f, 0.2f), 20 + Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(Glow); + } + for (int i = 0; i <= 10; i++) + { + Vector2 displace = Vector2.UnitX * 16 * Main.rand.NextFloat(-1f, 1f); + Particle Sparkle = new GenericSparkle(Owner.Bottom + displace, -Vector2.UnitY * Main.rand.NextFloat(1f, 5f), particleColor, particleColor, 0.5f + Main.rand.NextFloat(-0.2f, 0.2f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + } + + if (ChanneledState == 1f) + projectile.position += Vector2.UnitY * -0.3f * (1f + projectile.timeLeft / 60f); + } + + public void Attune(TrueBiomeBlade item) + { + bool jungle = Owner.ZoneJungle; + bool snow = Owner.ZoneSnow; + bool evil = Owner.ZoneCorrupt || Owner.ZoneCrimson; + bool desert = Owner.ZoneDesert; + bool hell = Owner.ZoneUnderworldHeight; + bool ocean = Owner.ZoneBeach; + bool holy = Owner.ZoneHoly; + bool astral = Owner.Calamity().ZoneAstral; + bool marine = Owner.Calamity().ZoneAbyss || Owner.Calamity().ZoneSunkenSea; + + Attunement attunement = Attunement.Default; + + if (desert || hell) + attunement = Attunement.Hot; + if (snow) + attunement = Attunement.Cold; + if (jungle || ocean) + attunement = Attunement.Tropical; + if (evil) + attunement = Attunement.Evil; + if (holy) + attunement = Attunement.Holy; + if (astral) + attunement = Attunement.Astral; + if (marine) + attunement = Attunement.Marine; + + //If the owner already had the attunement , break out of it (And unswap) + if (item.secondaryAttunement == attunement) + { + Main.PlaySound(SoundID.DD2_LightningBugZap, projectile.Center); + item.secondaryAttunement = item.mainAttunement; + item.mainAttunement = attunement; + return; + } + + Main.PlaySound(SoundID.DD2_MonkStaffGroundImpact, projectile.Center); + item.mainAttunement = attunement; + } + + public override void Kill(int timeLeft) + { + if (associatedItem == null) + { + return; + } + //If we swapped out the main attunement for the second one despite the second attunement being empty at the time, unswap them. + if ((associatedItem.modItem as TrueBiomeBlade).mainAttunement == null && (associatedItem.modItem as TrueBiomeBlade).secondaryAttunement != null) + { + (associatedItem.modItem as TrueBiomeBlade).mainAttunement = (associatedItem.modItem as TrueBiomeBlade).secondaryAttunement; + (associatedItem.modItem as TrueBiomeBlade).secondaryAttunement = null; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (ChanneledState == 0f && ChannelTimer > 6f) + return base.PreDraw(spriteBatch, lightColor); + + else if (ChanneledState == 1f) + { + Texture2D tex = GetTexture(Texture); + Vector2 squishyScale = new Vector2(Math.Abs((float)Math.Sin(MathHelper.Pi + MathHelper.TwoPi * projectile.timeLeft / 30f)), 1f); + SpriteEffects flip = (float)Math.Sin(MathHelper.Pi + MathHelper.TwoPi * projectile.timeLeft / 30f) > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + spriteBatch.Draw(tex, projectile.position - Main.screenPosition, null, lightColor * (projectile.timeLeft / 60f), 0, tex.Size() / 2, squishyScale * (2f - (projectile.timeLeft / 60f)), flip, 0); + + return false; + } + + else + return false; } } } diff --git a/Items/Weapons/Melee/TrueBiomeBlade.png b/Items/Weapons/Melee/TrueBiomeBlade.png index 0d870cd122..662f488bd5 100644 Binary files a/Items/Weapons/Melee/TrueBiomeBlade.png and b/Items/Weapons/Melee/TrueBiomeBlade.png differ diff --git a/Particles/BloomLine.png b/Particles/BloomLine.png new file mode 100644 index 0000000000..9a464ad26e Binary files /dev/null and b/Particles/BloomLine.png differ diff --git a/Particles/BloomLineCap.png b/Particles/BloomLineCap.png new file mode 100644 index 0000000000..6767aeec58 Binary files /dev/null and b/Particles/BloomLineCap.png differ diff --git a/Particles/BloomLineVFX.cs b/Particles/BloomLineVFX.cs new file mode 100644 index 0000000000..f563d2d257 --- /dev/null +++ b/Particles/BloomLineVFX.cs @@ -0,0 +1,56 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class BloomLineVFX : Particle + { + public override string Texture => "CalamityMod/Particles/BloomLine"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + public override bool Important => Telegraph; + + public bool Capped; + public float opacity; + public Vector2 LineVector; + public bool Telegraph; //Denotes if the line is used as an enemy telegraph. In that case, it'll be marked as important + + public BloomLineVFX(Vector2 startPoint, Vector2 lineVector, float thickness, Color color, int lifetime, bool capped = false, bool telegraph = false) + { + Position = startPoint; + LineVector = lineVector; + Scale = thickness; + Color = color; + Lifetime = lifetime; + Capped = capped; + Telegraph = telegraph; + Velocity = Vector2.Zero; + Rotation = 0; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D tex = GeneralParticleHandler.GetTexture(Type); + float rot = LineVector.ToRotation() + MathHelper.PiOver2; + Vector2 origin = new Vector2(tex.Width/2f, tex.Height); + Vector2 scale = new Vector2(Scale, LineVector.Length() / tex.Height); + spriteBatch.Draw(tex, Position - Main.screenPosition, null, Color, rot, origin, scale, SpriteEffects.None, 0); + + if (Capped) + { + Texture2D cap = ModContent.GetTexture("CalamityMod/Particles/BloomLineCap"); ; + scale = new Vector2(Scale, Scale); + origin = new Vector2(cap.Width / 2f, cap.Height); + + spriteBatch.Draw(cap, Position - Main.screenPosition, null, Color, rot + MathHelper.Pi, origin, scale, SpriteEffects.None, 0); + spriteBatch.Draw(cap, Position + LineVector - Main.screenPosition, null, Color, rot, origin, scale, SpriteEffects.None, 0); + } + + + } + } +} 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/Particles/CircularSmear.png b/Particles/CircularSmear.png new file mode 100644 index 0000000000..d2b9bdd19c Binary files /dev/null and b/Particles/CircularSmear.png differ diff --git a/Particles/CircularSmearSmokey.png b/Particles/CircularSmearSmokey.png new file mode 100644 index 0000000000..bbd15baf21 Binary files /dev/null and b/Particles/CircularSmearSmokey.png differ diff --git a/Particles/CircularSmearSmokeyVFX .cs b/Particles/CircularSmearSmokeyVFX .cs new file mode 100644 index 0000000000..5855914f2d --- /dev/null +++ b/Particles/CircularSmearSmokeyVFX .cs @@ -0,0 +1,27 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class CircularSmearSmokeyVFX : Particle //Also check out random noise generation! + { + public override string Texture => "CalamityMod/Particles/CircularSmearSmokey"; + public override bool UseAdditiveBlend => true; + + public override bool SetLifetime => true; + public float opacity; + + public CircularSmearSmokeyVFX(Vector2 position, Color color, float rotation, float scale) + { + Position = position; + Velocity = Vector2.Zero; + Color = color; + Scale = scale; + Rotation = rotation; + Lifetime = 2; + } + } +} diff --git a/Particles/CircularSmearVFX.cs b/Particles/CircularSmearVFX.cs new file mode 100644 index 0000000000..28ae240cc5 --- /dev/null +++ b/Particles/CircularSmearVFX.cs @@ -0,0 +1,27 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class CircularSmearVFX : Particle //Also check out Split mod! + { + public override string Texture => "CalamityMod/Particles/CircularSmear"; + public override bool UseAdditiveBlend => true; + + public override bool SetLifetime => true; + public float opacity; + + public CircularSmearVFX(Vector2 position, Color color, float rotation, float scale) + { + Position = position; + Velocity = Vector2.Zero; + Color = color; + Scale = scale; + Rotation = rotation; + Lifetime = 2; + } + } +} diff --git a/Particles/CircularTrail.png b/Particles/CircularTrail.png new file mode 100644 index 0000000000..9105fe87ac Binary files /dev/null and b/Particles/CircularTrail.png differ diff --git a/Particles/ConstellationRing.cs b/Particles/ConstellationRing.cs new file mode 100644 index 0000000000..937ff1bef3 --- /dev/null +++ b/Particles/ConstellationRing.cs @@ -0,0 +1,68 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class ConstellationRingVFX : Particle //Also check out Split mod! + { + public override string Texture => "CalamityMod/Particles/HollowCircleSoftEdge"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + public override bool Important => NeededVisual; + + public Vector2 Squish; + public int StarAmount; + public float StarScale; + public float SpinSpeed; + public bool NeededVisual; + public float Offset; + public float Opacity; + + + public ConstellationRingVFX(Vector2 position, Color color, float rotation, float scale, Vector2 squish, float opacity = 1f, int starAmount = 3, float starScale = 2f, float spinSpeed = 0.05f, bool important = false) + { + Position = position; + Velocity = Vector2.Zero; + Rotation = rotation; + Color = color; + Scale = scale; + Squish = squish; + Opacity = opacity; + StarAmount = starAmount; + StarScale = starScale; + SpinSpeed = spinSpeed; + NeededVisual = important; + Lifetime = 2; + Offset = Main.rand.NextFloat(0f, MathHelper.TwoPi); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D ringTexture = GeneralParticleHandler.GetTexture(Type); + Texture2D starTexture = ModContent.GetTexture("CalamityMod/Particles/Sparkle"); + Texture2D bloomTexture = ModContent.GetTexture("CalamityMod/Particles/BloomCircle"); + + spriteBatch.Draw(ringTexture, Position - Main.screenPosition, null, Color * Opacity, Rotation, ringTexture.Size() / 2f, Squish * Scale, SpriteEffects.None, 0); + + for (int i = 0; i < StarAmount; i++) + { + + float starHeight = (float)Math.Sin(Offset + Main.GlobalTime * SpinSpeed + i * MathHelper.TwoPi / (float)StarAmount); + float starWidth = (float)Math.Cos(Offset + Main.GlobalTime * SpinSpeed + i * MathHelper.TwoPi / (float)StarAmount); + + Vector2 starPos = Position + Rotation.ToRotationVector2() * starWidth * (Squish.X * Scale * ringTexture.Width * 0.45f) + (Rotation + MathHelper.PiOver2).ToRotationVector2() * starHeight * (Squish.Y * Scale * ringTexture.Height * 0.45f); + + //Ajust the bloom's texture to be the same size as the star's + float properBloomSize = (float)starTexture.Height / (float)bloomTexture.Height; + spriteBatch.Draw(bloomTexture, starPos - Main.screenPosition, null, Color * Opacity * 0.5f, 0, bloomTexture.Size() / 2f, Scale * properBloomSize, SpriteEffects.None, 0); + spriteBatch.Draw(starTexture, starPos - Main.screenPosition, null, Color * Opacity * 0.5f, Rotation + MathHelper.PiOver4 + MathHelper.PiOver4 * i, starTexture.Size() / 2f, Scale * 0.75f, SpriteEffects.None, 0); + spriteBatch.Draw(starTexture, starPos - Main.screenPosition, null, Color.White * Opacity, Rotation + MathHelper.PiOver4 * i, starTexture.Size() / 2f, Scale, SpriteEffects.None, 0); + } + + } + } +} diff --git a/Particles/CosmicSmoke.cs b/Particles/CosmicSmoke.cs new file mode 100644 index 0000000000..2151478fd6 --- /dev/null +++ b/Particles/CosmicSmoke.cs @@ -0,0 +1,54 @@ +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + + +namespace CalamityMod.Particles { + public class CosmicSmokeParticle : Particle + { + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + public override string Texture => "CalamityMod/Particles/SmallSmoke"; + + private float Opacity; + private Color BackColor; + private float ColorHueShift; + private float Spin; + + public CosmicSmokeParticle(Vector2 position, Vector2 velocity, Color color, Color backColor, float scale, float opacity, int lifetime, float rotationSpeed = 0f) + { + Position = position; + Velocity = velocity; + Color = color; + BackColor = backColor; + Scale = scale; + Opacity = opacity; + Lifetime = lifetime; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + } + + public override void Update() + { + + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + Velocity *= 0.85f; + + if (Opacity > 90) + { + Lighting.AddLight(Position, Color.ToVector3() * 0.1f); + Scale += 0.01f; + Opacity -= 3; + } + else + { + Scale *= 0.975f; + Opacity -= 2; + } + if (Opacity < 0) + Kill(); + + } + } +} \ No newline at end of file diff --git a/Particles/CritSpark.cs b/Particles/CritSpark.cs new file mode 100644 index 0000000000..e41b8cd284 --- /dev/null +++ b/Particles/CritSpark.cs @@ -0,0 +1,55 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class CritSpark : Particle + { + public override string Texture => "CalamityMod/Particles/ThinSparkle"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + private float Spin; + private float opacity; + private Color Bloom; + private Color LightColor => Bloom * opacity; + private float BloomScale; + + public CritSpark(Vector2 position, Vector2 velocity, Color color, Color bloom, float scale, int lifeTime, float rotationSpeed = 1f, float bloomScale = 1f) + { + Position = position; + Velocity = velocity; + Color = color; + Bloom = bloom; + Scale = scale; + Lifetime = lifeTime; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + BloomScale = bloomScale; + } + + public override void Update() + { + opacity = (float)Math.Sin(MathHelper.PiOver2 + LifetimeCompletion * MathHelper.PiOver2); + Velocity *= 0.80f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f) * (LifetimeCompletion > 0.5 ? 1f : 0.5f); + + Lighting.AddLight(Position, LightColor.R / 255f, LightColor.G / 255f, LightColor.B / 255f); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D sparkTexture = GeneralParticleHandler.GetTexture(Type); + Texture2D bloomTexture = ModContent.GetTexture("CalamityMod/Particles/BloomCircle"); + //Ajust the bloom's texture to be the same size as the star's + float properBloomSize = (float)sparkTexture.Height / (float)bloomTexture.Height; + + spriteBatch.Draw(bloomTexture, Position - Main.screenPosition, null, Bloom * opacity * 0.5f, 0, bloomTexture.Size() / 2f, Scale * BloomScale * properBloomSize, SpriteEffects.None, 0); + spriteBatch.Draw(sparkTexture, Position - Main.screenPosition, null, Color * opacity, Rotation, sparkTexture.Size() / 2f, Scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/CritSpark.png b/Particles/CritSpark.png new file mode 100644 index 0000000000..13ee17462d Binary files /dev/null and b/Particles/CritSpark.png differ diff --git a/Particles/ElectricSpark.cs b/Particles/ElectricSpark.cs new file mode 100644 index 0000000000..ec8c94e9eb --- /dev/null +++ b/Particles/ElectricSpark.cs @@ -0,0 +1,69 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class ElectricSpark : Particle + { + public override string Texture => "CalamityMod/Particles/ElectricSpark"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + public override int FrameVariants => 2; + + private float Spin; + private float opacity; + private Color Bloom; + private Color LightColor => Bloom * opacity; + private float BloomScale; + private float MaxJumpRotation; //Max rotation that the particle can change velocity per "jump" + private float JumpTime; //Time between jumps + private Vector2 OriginalSpeed; + + public ElectricSpark(Vector2 position, Vector2 velocity, Color color, Color bloom, float scale, int lifeTime, float maxJumpRotation = MathHelper.PiOver4, float jumpTime = 10, float rotationSpeed = 1f, float bloomScale = 1f) + { + Position = position; + Velocity = velocity; + OriginalSpeed = velocity; + Color = color; + Bloom = bloom; + Scale = scale; + Lifetime = lifeTime; + MaxJumpRotation = maxJumpRotation; + JumpTime = jumpTime; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + BloomScale = bloomScale; + Variant = Main.rand.Next(2); + } + + public override void Update() + { + opacity -= JumpTime * 0.25f / Lifetime; + if (Time % JumpTime == 0) + { + opacity = 1f; + Velocity = OriginalSpeed.RotatedByRandom(MaxJumpRotation); + } + Velocity *= 0.6f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f) * (LifetimeCompletion > 0.5 ? 1f : 0.5f); + + Lighting.AddLight(Position, LightColor.R / 255f, LightColor.G / 255f, LightColor.B / 255f); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D sparkTexture = GeneralParticleHandler.GetTexture(Type); + Rectangle frame = new Rectangle(0, 6 * Variant, 6, 6); + Texture2D bloomTexture = ModContent.GetTexture("CalamityMod/Particles/BloomCircle"); + //Ajust the bloom's texture to be the same size as the star's + float properBloomSize = (float)frame.Height / (float)bloomTexture.Height; + + spriteBatch.Draw(bloomTexture, Position - Main.screenPosition, null, Bloom * opacity * 0.5f, 0, bloomTexture.Size() / 2f, Scale * BloomScale * properBloomSize, SpriteEffects.None, 0); + spriteBatch.Draw(sparkTexture, Position - Main.screenPosition, frame, Color * opacity, Rotation, frame.Size() / 2f, Scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/ElectricSpark.png b/Particles/ElectricSpark.png new file mode 100644 index 0000000000..39b19d6168 Binary files /dev/null and b/Particles/ElectricSpark.png differ diff --git a/Particles/FakeDust.png b/Particles/FakeDust.png new file mode 100644 index 0000000000..e18edfa242 Binary files /dev/null and b/Particles/FakeDust.png differ diff --git a/Particles/FakeDustBig.png b/Particles/FakeDustBig.png new file mode 100644 index 0000000000..114f49f5b0 Binary files /dev/null and b/Particles/FakeDustBig.png differ diff --git a/Particles/FakeDustParticle.cs b/Particles/FakeDustParticle.cs new file mode 100644 index 0000000000..ead5403161 --- /dev/null +++ b/Particles/FakeDustParticle.cs @@ -0,0 +1,57 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class FakeGlowDust : Particle + { + public override string Texture => "CalamityMod/Particles/FakeDust"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + private float Spin; + private float opacity; + private bool Big; + private bool EmitsLight; + private Vector2 Gravity; + + public FakeGlowDust(Vector2 position, Vector2 velocity, Color color, float scale, int lifeTime, float rotationSpeed = 1f, bool bigSize = false, bool emitsLight = false, Vector2? gravity = null) + { + Position = position; + Velocity = velocity; + Color = color; + Scale = scale; + Lifetime = lifeTime; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + Big = bigSize; + EmitsLight = emitsLight; + Gravity = (Vector2)(gravity == null ? Vector2.Zero : gravity); + Variant = Main.rand.Next(3); + } + + public override void Update() + { + Velocity += Gravity; + opacity = (float)Math.Sin(LifetimeCompletion * MathHelper.Pi); + + if (EmitsLight) + Lighting.AddLight(Position, opacity * Color.R / 255f, opacity * Color.G / 255f, opacity * Color.B / 255f); + + Velocity *= 0.95f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + Scale *= 0.98f; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D dustTexture = Big ? ModContent.GetTexture("CalamityMod/Particles/FakeDustBig") : GeneralParticleHandler.GetTexture(Type); + Rectangle frame = new Rectangle(0, (Big ? 8 : 6) * Variant, (Big ? 8 : 6), (Big ? 8 : 6)); + spriteBatch.Draw(dustTexture, Position - Main.screenPosition, frame, Color * opacity, Rotation, frame.Size() / 2f, Scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/GeneralParticleHandler.cs b/Particles/GeneralParticleHandler.cs index 2be3028795..53be50be67 100644 --- a/Particles/GeneralParticleHandler.cs +++ b/Particles/GeneralParticleHandler.cs @@ -14,23 +14,28 @@ namespace CalamityMod.Particles public static class GeneralParticleHandler { private static List particles; - private static int nextVacantIndex; + //List containing the particles to delete + private static List particlesToKill; //Static list for details concerning every particle type private static Dictionary particleTypes; private static Dictionary particleTextures; private static List particleInstances; //Lists used when drawing particles batched private static List batchedAlphaBlendParticles; + private static List batchedNonPremultipliedParticles; private static List batchedAdditiveBlendParticles; + internal static void Load() { particles = new List(); + particlesToKill = new List(); particleTypes = new Dictionary(); particleTextures = new Dictionary(); particleInstances = new List(); batchedAlphaBlendParticles = new List(); + batchedNonPremultipliedParticles = new List(); batchedAdditiveBlendParticles = new List(); Type baseParticleType = typeof(Particle); @@ -57,10 +62,12 @@ namespace CalamityMod.Particles internal static void Unload() { particles = null; + particlesToKill = null; particleTypes = null; particleTextures = null; particleInstances = null; batchedAlphaBlendParticles = null; + batchedNonPremultipliedParticles = null; batchedAdditiveBlendParticles = null; } @@ -87,12 +94,13 @@ namespace CalamityMod.Particles particle.Update(); } //Clear out particles whose time is up - particles.RemoveAll(particle => particle.Time >= particle.Lifetime && particle.SetLifetime); + particles.RemoveAll(particle => (particle.Time >= particle.Lifetime && particle.SetLifetime) || particlesToKill.Contains(particle)); + particlesToKill.Clear(); } public static void RemoveParticle(Particle particle) { - particles.Remove(particle); + particlesToKill.Add(particle); } public static void DrawAllParticles(SpriteBatch sb) @@ -105,6 +113,8 @@ namespace CalamityMod.Particles if (particle.UseAdditiveBlend) batchedAdditiveBlendParticles.Add(particle); + else if (particle.UseHalfTransparency) + batchedNonPremultipliedParticles.Add(particle); else batchedAlphaBlendParticles.Add(particle); } @@ -120,26 +130,58 @@ namespace CalamityMod.Particles } } - sb.End(); - sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, null, null, Main.GameViewMatrix.ZoomMatrix); - - foreach (Particle particle in batchedAdditiveBlendParticles) + if (batchedNonPremultipliedParticles.Count > 0) { - if (particle.UseCustomDraw) - particle.CustomDraw(sb); - else + sb.End(); + sb.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, null, null, Main.GameViewMatrix.ZoomMatrix); + + foreach (Particle particle in batchedNonPremultipliedParticles) { - Rectangle frame = particleTextures[particle.Type].Frame(1, particle.FrameVariants, 0, particle.Variant); - sb.Draw(particleTextures[particle.Type], particle.Position - Main.screenPosition, frame, particle.Color, particle.Rotation, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f); + if (particle.UseCustomDraw) + particle.CustomDraw(sb); + else + { + Rectangle frame = particleTextures[particle.Type].Frame(1, particle.FrameVariants, 0, particle.Variant); + sb.Draw(particleTextures[particle.Type], particle.Position - Main.screenPosition, frame, particle.Color, particle.Rotation, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f); + } } } - sb.End(); - sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); + if (batchedAdditiveBlendParticles.Count > 0) + { + sb.End(); + sb.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, null, null, Main.GameViewMatrix.ZoomMatrix); + + foreach (Particle particle in batchedAdditiveBlendParticles) + { + if (particle.UseCustomDraw) + particle.CustomDraw(sb); + else + { + Rectangle frame = particleTextures[particle.Type].Frame(1, particle.FrameVariants, 0, particle.Variant); + sb.Draw(particleTextures[particle.Type], particle.Position - Main.screenPosition, frame, particle.Color, particle.Rotation, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f); + } + } + } + + //Return to normal if we swapped the blend state before + if (batchedAdditiveBlendParticles.Count > 0 || batchedNonPremultipliedParticles.Count > 0) + { + sb.End(); + sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); + } batchedAlphaBlendParticles.Clear(); + batchedNonPremultipliedParticles.Clear(); batchedAdditiveBlendParticles.Clear(); } + + /// + /// Gives you the amount of particle slots that are available. Useful when you need multiple particles at once to make an effect and dont want it to be only halfway drawn due to a lack of particle slots + /// + /// + public static int FreeSpacesAvailable() => CalamityConfig.Instance.ParticleLimit - particles.Count(); + /// /// Gives you the texture of the particle type. Useful for custom drawing /// diff --git a/Particles/GenericBloom.cs b/Particles/GenericBloom.cs new file mode 100644 index 0000000000..031a426111 --- /dev/null +++ b/Particles/GenericBloom.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 GenericBloom : Particle + { + public override string Texture => "CalamityMod/Particles/Light"; + public override bool UseAdditiveBlend => true; + public override bool SetLifetime => true; + + private float opacity; + private Color BaseColor; + + public GenericBloom(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(LifetimeCompletion * MathHelper.Pi); + 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/HalfIceStar.png b/Particles/HalfIceStar.png new file mode 100644 index 0000000000..1dae18cc57 Binary files /dev/null and b/Particles/HalfIceStar.png differ diff --git a/Particles/HalfStar.png b/Particles/HalfStar.png new file mode 100644 index 0000000000..758e4e84c6 Binary files /dev/null and b/Particles/HalfStar.png differ diff --git a/Particles/HeavySmoke.cs b/Particles/HeavySmoke.cs new file mode 100644 index 0000000000..acdf9856d9 --- /dev/null +++ b/Particles/HeavySmoke.cs @@ -0,0 +1,74 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class HeavySmokeParticle : Particle + { + public override bool SetLifetime => true; + public override int FrameVariants => 7; + public override bool UseCustomDraw => true; + public override bool Important => StrongVisual; + public override bool UseAdditiveBlend => Glowing; + public override bool UseHalfTransparency => !Glowing; + + public override string Texture => "CalamityMod/Particles/HeavySmoke"; + + private float Opacity; + private float Spin; + private bool StrongVisual; + private bool Glowing; + private float HueShift; + static int FrameAmount = 6; + + public HeavySmokeParticle(Vector2 position, Vector2 velocity, Color color, int lifetime, float scale, float opacity, float rotationSpeed = 0f, bool glowing = false, float hueshift = 0f, bool required = false) + { + Position = position; + Velocity = velocity; + Color = color; + Scale = scale; + Variant = Main.rand.Next(7); + Lifetime = lifetime; + Opacity = opacity; + Spin = rotationSpeed; + StrongVisual = required; + Glowing = glowing; + HueShift = hueshift; + + } + + public override void Update() + { + if (Time / (float)Lifetime < 0.2f) + Scale += 0.01f; + else + Scale *= 0.975f; + + Color = Main.hslToRgb(Main.rgbToHsl(Color).X + HueShift, Main.rgbToHsl(Color).Y, Main.rgbToHsl(Color).Z); + Opacity *= 0.98f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + Velocity *= 0.85f; + + float opacity = Utils.InverseLerp(1f, 0.85f, LifetimeCompletion, true); + Color *= opacity; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D tex = GeneralParticleHandler.GetTexture(Type); + int animationFrame = (int)Math.Floor(Time / ((float)(Lifetime / (float)FrameAmount))); + Rectangle frame = new Rectangle(80 * Variant, 80 * animationFrame, 80, 80); + + + spriteBatch.Draw(tex, Position - Main.screenPosition, frame, Color * Opacity, Rotation, frame.Size() / 2f, Scale, SpriteEffects.None, 0); + } + + } +} diff --git a/Particles/HeavySmoke.png b/Particles/HeavySmoke.png new file mode 100644 index 0000000000..5aa11bd85f Binary files /dev/null and b/Particles/HeavySmoke.png differ diff --git a/Particles/HollowCircleHardEdge.png b/Particles/HollowCircleHardEdge.png new file mode 100644 index 0000000000..1fe5c93429 Binary files /dev/null and b/Particles/HollowCircleHardEdge.png differ diff --git a/Particles/HollowCircleSoftEdge.png b/Particles/HollowCircleSoftEdge.png new file mode 100644 index 0000000000..75bf7ca141 Binary files /dev/null and b/Particles/HollowCircleSoftEdge.png differ diff --git a/Particles/LineVFX.cs b/Particles/LineVFX.cs new file mode 100644 index 0000000000..1aa990202b --- /dev/null +++ b/Particles/LineVFX.cs @@ -0,0 +1,50 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class LineVFX : Particle + { + public override string Texture => "CalamityMod/Particles/ThinEndedLine"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + public override bool Important => Telegraph; + + public float opacity; + public Vector2 LineVector; + public bool Concave; + public bool Telegraph; //Denotes if the line is used as an enemy telegraph. In that case, it'll be marked as important + + public LineVFX(Vector2 startPoint, Vector2 lineVector, float thickness, Color color, bool concave = false, bool telegraph = false) + { + Position = startPoint; + LineVector = lineVector; + Scale = thickness; + Color = color; + Concave = concave; + Telegraph = telegraph; + Velocity = Vector2.Zero; + Rotation = 0; + Lifetime = 2; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D tex; + if (Concave) + tex = ModContent.GetTexture("CalamityMod/Particles/ThickEndedLine"); //THICC :wearty: weary: :weary : oogogg;... ooog... that line be lookin' mighty fine... :hot: + else + tex = GeneralParticleHandler.GetTexture(Type); + + float rot = LineVector.ToRotation() + MathHelper.PiOver2; + Vector2 origin = new Vector2(tex.Width/2f, tex.Height); + Vector2 scale = new Vector2(Scale, LineVector.Length() / tex.Height); + + spriteBatch.Draw(tex, Position - Main.screenPosition, null, Color, rot, origin, scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/MediumMist.png b/Particles/MediumMist.png new file mode 100644 index 0000000000..34dcca01a8 Binary files /dev/null and b/Particles/MediumMist.png differ diff --git a/Particles/MediumMistParticle.cs b/Particles/MediumMistParticle.cs new file mode 100644 index 0000000000..5be71415c8 --- /dev/null +++ b/Particles/MediumMistParticle.cs @@ -0,0 +1,57 @@ +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + + +namespace CalamityMod.Particles { + public class MediumMistParticle : Particle + { + public override string Texture => "CalamityMod/Particles/MediumMist"; + public override int FrameVariants => 3; + public override bool UseAdditiveBlend => true; + + + private float Opacity; + private Color ColorFire; + private Color ColorFade; + private float Spin; + + public MediumMistParticle(Vector2 position, Vector2 velocity, Color colorFire, Color colorFade, float scale, float opacity, float rotationSpeed = 0f) + { + Position = position; + Velocity = velocity; + ColorFire = colorFire; + ColorFade = colorFade; + Scale = scale; + Opacity = opacity; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + Variant = Main.rand.Next(3); + } + + public override void Update() + { + + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + Velocity *= 0.85f; + + if (Opacity > 90) + { + Lighting.AddLight(Position, Color.ToVector3() * 0.1f); + Scale += 0.01f; + Opacity -= 3; + } + else + { + Scale *= 0.975f; + Opacity -= 2; + } + if (Opacity < 0) + Kill(); + + Color = Color.Lerp(ColorFire, ColorFade, MathHelper.Clamp((float)((255 -Opacity) - 100) / 80, 0f, 1f)) * (Opacity / 255f); + + } + } +} \ No newline at end of file diff --git a/Particles/Particle.cs b/Particles/Particle.cs index 74671fda7e..de011d6164 100644 --- a/Particles/Particle.cs +++ b/Particles/Particle.cs @@ -71,6 +71,11 @@ namespace CalamityMod.Particles /// public virtual bool UseAdditiveBlend => false; + /// + /// Set this to true to make your particles work with semi transparent pixels. Is overriden if UseAdditiveBlend is set to true. + /// + public virtual bool UseHalfTransparency => false; + /// /// Removes the particle from the handler /// diff --git a/Particles/SeaFoam.png b/Particles/SeaFoam.png new file mode 100644 index 0000000000..22129adf9c Binary files /dev/null and b/Particles/SeaFoam.png differ diff --git a/Particles/SeaFoamParticle.cs b/Particles/SeaFoamParticle.cs new file mode 100644 index 0000000000..89fb167934 --- /dev/null +++ b/Particles/SeaFoamParticle.cs @@ -0,0 +1,45 @@ +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + + +namespace CalamityMod.Particles { + public class SeaFoamParticle : Particle + { + public override string Texture => "CalamityMod/Particles/SeaFoam"; + public override int FrameVariants => 3; + public override bool UseAdditiveBlend => true; + + + public float Opacity; + private Color ColorStart; + private Color ColorFade; + private float Spin; + private float BaseScale; + + public SeaFoamParticle(Vector2 position, Vector2 velocity, Color colorStart, Color colorFade, float scale, float opacity, float rotationSpeed = 1f) + { + Position = position; + Velocity = velocity; + ColorStart = colorStart; + ColorFade = colorFade; + BaseScale = scale; + Opacity = opacity; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + Variant = Main.rand.Next(3); + } + + public override void Update() + { + Velocity *= 0.85f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + Opacity -= 10; + Scale = BaseScale + Opacity / 255f; + if (Opacity <= 0) + Kill(); + Color = Color.Lerp(ColorStart, ColorFade, MathHelper.Clamp((float)((255 -Opacity) - 100) / 80, 0f, 1f)) * (Opacity / 255f); + } + } +} \ No newline at end of file diff --git a/Particles/SemiCircularSmear.png b/Particles/SemiCircularSmear.png new file mode 100644 index 0000000000..1798a1e3f3 Binary files /dev/null and b/Particles/SemiCircularSmear.png differ diff --git a/Particles/SemiCircularSmearVFX.cs b/Particles/SemiCircularSmearVFX.cs new file mode 100644 index 0000000000..07d47b69c5 --- /dev/null +++ b/Particles/SemiCircularSmearVFX.cs @@ -0,0 +1,35 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class SemiCircularSmearVFX : Particle //Also check out Split mod! + { + public override string Texture => "CalamityMod/Particles/SemiCircularSmear"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + public Vector2 Squish; + + public SemiCircularSmearVFX(Vector2 position, Color color, float rotation, float scale, Vector2 squish) + { + Position = position; + Velocity = Vector2.Zero; + Color = color; + Scale = scale; + Squish = squish; + Rotation = rotation; + Lifetime = 2; + } + + //Use custom draw for the squish + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D tex = GeneralParticleHandler.GetTexture(Type); + spriteBatch.Draw(tex, Position - Main.screenPosition, null, Color, Rotation, tex.Size() / 2f, Squish * Scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/SmallSmokeParticle.cs b/Particles/SmallSmokeParticle.cs new file mode 100644 index 0000000000..08bc36c0a6 --- /dev/null +++ b/Particles/SmallSmokeParticle.cs @@ -0,0 +1,53 @@ +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + + +namespace CalamityMod.Particles { + public class SmallSmokeParticle : Particle + { + public override string Texture => "CalamityMod/Particles/SmallSmoke"; + + private float Opacity; + private Color ColorFire; + private Color ColorFade; + private float Spin; + + public SmallSmokeParticle(Vector2 position, Vector2 velocity, Color colorFire, Color colorFade, float scale, float opacity, float rotationSpeed = 0f) + { + Position = position; + Velocity = velocity; + ColorFire = colorFire; + ColorFade = colorFade; + Scale = scale; + Opacity = opacity; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + } + + public override void Update() + { + + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + Velocity *= 0.85f; + + if (Opacity > 90) + { + Lighting.AddLight(Position, Color.ToVector3() * 0.1f); + Scale += 0.01f; + Opacity -= 3; + } + else + { + Scale *= 0.975f; + Opacity -= 2; + } + if (Opacity < 0) + Kill(); + + Color = Color.Lerp(ColorFire, ColorFade, MathHelper.Clamp((float)((255 -Opacity) - 100) / 80, 0f, 1f)) * (Opacity / 255f); + + } + } +} \ No newline at end of file diff --git a/Particles/SnowflakeSparkle.cs b/Particles/SnowflakeSparkle.cs new file mode 100644 index 0000000000..6e143e6ea6 --- /dev/null +++ b/Particles/SnowflakeSparkle.cs @@ -0,0 +1,61 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class SnowflakeSparkle : Particle + { + public override string Texture => "CalamityMod/Particles/HalfIceStar"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + private float Spin; + private float opacity; + private Color Bloom; + private Color LightColor => Bloom * opacity; + private float BloomScale; + private int Spokes; + + public SnowflakeSparkle(Vector2 position, Vector2 velocity, Color color, Color bloom, float scale, int lifeTime, float rotationSpeed = 1f, float bloomScale = 1f, int spokes = 3) + { + Position = position; + Velocity = velocity; + Color = color; + Bloom = bloom; + Scale = scale; + Lifetime = lifeTime; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + BloomScale = bloomScale; + Spokes = spokes; + } + + public override void Update() + { + opacity = (float)Math.Sin(LifetimeCompletion * MathHelper.Pi); + Lighting.AddLight(Position, LightColor.R / 255f, LightColor.G / 255f, LightColor.B / 255f); + Velocity *= 0.95f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D spokesTexture = GeneralParticleHandler.GetTexture(Type); + Texture2D bloomTexture = ModContent.GetTexture("CalamityMod/Particles/BloomCircle"); + //Ajust the bloom's texture to be the same size as the star's + float properBloomSize = (float)spokesTexture.Height / (float)bloomTexture.Height; + + spriteBatch.Draw(bloomTexture, Position - Main.screenPosition, null, Bloom * opacity * 0.5f, 0, bloomTexture.Size()/2f, Scale * BloomScale * properBloomSize, SpriteEffects.None, 0); + + for (int i = 0; i < Spokes; i++) + { + float rotation = Rotation + MathHelper.Lerp(0f, MathHelper.Pi, i/(float)Spokes); + spriteBatch.Draw(spokesTexture, Position - Main.screenPosition, null, Color * opacity * 0.5f, Rotation + rotation, spokesTexture.Size() / 2f, Scale, SpriteEffects.None, 0); + } + } + } +} diff --git a/Particles/StoneDebris.png b/Particles/StoneDebris.png new file mode 100644 index 0000000000..9dad21abf4 Binary files /dev/null and b/Particles/StoneDebris.png differ diff --git a/Particles/StoneDebrisParticle.cs b/Particles/StoneDebrisParticle.cs new file mode 100644 index 0000000000..129f0ceb2c --- /dev/null +++ b/Particles/StoneDebrisParticle.cs @@ -0,0 +1,40 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class StoneDebrisParticle : Particle + { + public override string Texture => "CalamityMod/Particles/StoneDebris"; + public override bool SetLifetime => true; + public override int FrameVariants => 5; + + private float Spin; + private float opacity; + Color originalColor; + + public StoneDebrisParticle(Vector2 position, Vector2 velocity, Color color, float scale, int lifeTime, float rotationSpeed = 1f) + { + Position = position; + Velocity = velocity; + Color = color; + originalColor = color; + Scale = scale; + Lifetime = lifeTime; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + Variant = Main.rand.Next(3); + } + + public override void Update() + { + opacity = LifetimeCompletion < 0.5f ? 1f : (float)Math.Sin(LifetimeCompletion * MathHelper.Pi); + Color = originalColor * opacity; + Velocity = Velocity * 0.95f + Vector2.UnitY * 0.1f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + } + } +} diff --git a/Particles/StrongBloom.cs b/Particles/StrongBloom.cs new file mode 100644 index 0000000000..8af6bee27c --- /dev/null +++ b/Particles/StrongBloom.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 StrongBloom : Particle + { + public override string Texture => "CalamityMod/Particles/BloomCircle"; + public override bool UseAdditiveBlend => true; + public override bool SetLifetime => true; + + private float opacity; + private Color BaseColor; + + public StrongBloom(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(LifetimeCompletion * MathHelper.Pi); + 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/ThickEndedLine.png b/Particles/ThickEndedLine.png new file mode 100644 index 0000000000..3ed82b1577 Binary files /dev/null and b/Particles/ThickEndedLine.png differ diff --git a/Particles/ThinEndedLine.png b/Particles/ThinEndedLine.png new file mode 100644 index 0000000000..c954f46b96 Binary files /dev/null and b/Particles/ThinEndedLine.png differ diff --git a/Particles/ThinSparkle.png b/Particles/ThinSparkle.png new file mode 100644 index 0000000000..1d698a9c83 Binary files /dev/null and b/Particles/ThinSparkle.png differ diff --git a/Particles/ThunderBolt.png b/Particles/ThunderBolt.png new file mode 100644 index 0000000000..cabdcfc2bc Binary files /dev/null and b/Particles/ThunderBolt.png differ diff --git a/Particles/ThunderBoltVFX.cs b/Particles/ThunderBoltVFX.cs new file mode 100644 index 0000000000..3dd7e10cae --- /dev/null +++ b/Particles/ThunderBoltVFX.cs @@ -0,0 +1,66 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class ThunderBoltVFX : Particle //Also check out Split mod! + { + public override string Texture => "CalamityMod/Particles/ThunderBolt"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + public Vector2 Squish; + public float ShakePower; + public float Opacity; + public Projectile AttachedProjectile; + public float DisplacementFromProjectile; + + public ThunderBoltVFX(Vector2 position, Color color, float rotation, float scale, Vector2 squish, float opacity = 1f, float shakePower = 20f, Projectile projectileToFollow = null, float displacementFromProjectile = 0f) + { + Position = position; + Velocity = Vector2.Zero; + Color = color; + Scale = scale; + Squish = squish; + Rotation = rotation; + Opacity = opacity; + ShakePower = shakePower; + if (projectileToFollow != null) + AttachedProjectile = projectileToFollow; + DisplacementFromProjectile = displacementFromProjectile; + Lifetime = 30; + } + + public override void Update() + { + Lighting.AddLight(Position, Color.ToVector3() * 3f); + float fadeFactor = 1f - 0.05f * MathHelper.Clamp((Time - 10) / 10f, 0f, 1f); + Opacity *= fadeFactor; + Squish.X *= fadeFactor; + + if (AttachedProjectile != null && AttachedProjectile.active) + Position = AttachedProjectile.Center + Vector2.UnitY * DisplacementFromProjectile; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D tex = GeneralParticleHandler.GetTexture(Type); + + Vector2 Shake = Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (1 - (Time / (float)Lifetime)) * ShakePower; + + //The draw happens at the base of the texture + Vector2 Origin = new Vector2(tex.Width / 2f, tex.Height); + + Color drawColor = Color.Lerp(Color.White, Color, (Time / (float)Lifetime)); + + SpriteEffects flip = (Main.GlobalTime % 30 < 15) ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + + spriteBatch.Draw(tex, Position + Shake - Main.screenPosition, null, Color * Opacity * 0.6f, Rotation, Origin, Squish * Scale, flip, 0); + spriteBatch.Draw(tex, Position - Main.screenPosition, null, drawColor * Opacity, Rotation, Origin, Squish * Scale, flip, 0); + } + } +} diff --git a/Particles/WaterGlob.png b/Particles/WaterGlob.png new file mode 100644 index 0000000000..73ba7bee0c Binary files /dev/null and b/Particles/WaterGlob.png differ diff --git a/Particles/WaterGlobParticle.cs b/Particles/WaterGlobParticle.cs new file mode 100644 index 0000000000..d83a8c61f2 --- /dev/null +++ b/Particles/WaterGlobParticle.cs @@ -0,0 +1,39 @@ +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + + +namespace CalamityMod.Particles { + public class WaterGlobParticle : Particle + { + public override string Texture => "CalamityMod/Particles/WaterGlob"; + + public override bool SetLifetime => true; + + public override bool Important => true; + + private float Spin; + + public WaterGlobParticle(Vector2 position, Vector2 velocity, float scale, float rotationSpeed = 0f, int lifeTime = 50) + { + Position = position; + Velocity = velocity; + Color = Color.White * 0.5f; + Scale = scale; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Spin = rotationSpeed; + Lifetime = lifeTime; + } + + public override void Update() + { + + Color *= 0.985f; + Rotation += Spin * ((Velocity.X > 0) ? 1f : -1f); + Velocity *= 0.85f; + Scale *= 0.975f; + + } + } +} \ No newline at end of file diff --git a/Projectiles/Melee/BiomeOrb.cs b/Projectiles/Melee/BiomeOrb.cs deleted file mode 100644 index 1575ade4b2..0000000000 --- a/Projectiles/Melee/BiomeOrb.cs +++ /dev/null @@ -1,211 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.CalPlayer; -using CalamityMod.Dusts; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Projectiles.Melee -{ - public class BiomeOrb : ModProjectile - { - private int dustType = 3; - Color color = default; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Biome Orb"); - ProjectileID.Sets.TrailCacheLength[projectile.type] = 2; - ProjectileID.Sets.TrailingMode[projectile.type] = 0; - } - - public override void SetDefaults() - { - projectile.width = 20; - projectile.height = 20; - projectile.aiStyle = 27; - aiType = ProjectileID.LightBeam; - projectile.friendly = true; - projectile.penetrate = 1; - projectile.timeLeft = 300; - projectile.melee = true; - } - - public override void AI() - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool corrupt = player.ZoneCorrupt; - bool crimson = player.ZoneCrimson; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool sky = player.ZoneSkyHeight; - bool holy = player.ZoneHoly; - if (astral) - { - dustType = ModContent.DustType(); - color = new Color(255, 127, 80, projectile.alpha); - } - else if (jungle) - { - dustType = 39; - color = new Color(128, 255, 128, projectile.alpha); - } - else if (snow) - { - dustType = 51; - color = new Color(128, 255, 255, projectile.alpha); - } - else if (beach) - { - dustType = 33; - color = new Color(0, 0, 128, projectile.alpha); - } - else if (corrupt) - { - dustType = 14; - color = new Color(128, 64, 255, projectile.alpha); - } - else if (crimson) - { - dustType = 5; - color = new Color(128, 0, 0, projectile.alpha); - } - else if (dungeon) - { - dustType = 29; - color = new Color(64, 0, 128, projectile.alpha); - } - else if (desert) - { - dustType = 32; - color = new Color(255, 255, 128, projectile.alpha); - } - else if (glow) - { - dustType = 56; - color = new Color(0, 255, 255, projectile.alpha); - } - else if (hell) - { - dustType = 6; - color = new Color(255, 128, 0, projectile.alpha); - } - else if (sky) - { - dustType = 213; - color = new Color(255, 255, 255, projectile.alpha); - } - else if (holy) - { - dustType = 57; - color = new Color(255, 255, 0, projectile.alpha); - } - else - { - color = new Color(0, 128, 0, projectile.alpha); - } - int num458 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, dustType, 0f, 0f, 100, default, 0.9f); - Main.dust[num458].noGravity = true; - Main.dust[num458].velocity *= 0.5f; - Main.dust[num458].velocity += projectile.velocity * 0.1f; - } - - public override Color? GetAlpha(Color lightColor) - { - return color; - } - - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - if (projectile.timeLeft > 295) - return false; - - CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); - return false; - } - - public override void Kill(int timeLeft) - { - int num3; - for (int num795 = 4; num795 < 31; num795 = num3 + 1) - { - float num796 = projectile.oldVelocity.X * (30f / (float)num795); - float num797 = projectile.oldVelocity.Y * (30f / (float)num795); - int num798 = Dust.NewDust(new Vector2(projectile.oldPosition.X - num796, projectile.oldPosition.Y - num797), 8, 8, dustType, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, default, 1.8f); - Main.dust[num798].noGravity = true; - Dust dust = Main.dust[num798]; - dust.velocity *= 0.5f; - num798 = Dust.NewDust(new Vector2(projectile.oldPosition.X - num796, projectile.oldPosition.Y - num797), 8, 8, dustType, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, default, 1.4f); - dust = Main.dust[num798]; - dust.velocity *= 0.05f; - num3 = num795; - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool holy = player.ZoneHoly; - int debuffTime = 90; - if (astral) - { - target.AddBuff(ModContent.BuffType(), debuffTime); - } - else if (jungle) - { - target.AddBuff(BuffID.Venom, debuffTime); - } - else if (snow) - { - target.AddBuff(ModContent.BuffType(), debuffTime / 3); - } - else if (beach) - { - target.AddBuff(ModContent.BuffType(), debuffTime); - } - else if (dungeon) - { - target.AddBuff(BuffID.Frostburn, debuffTime); - } - else if (desert) - { - target.AddBuff(ModContent.BuffType(), debuffTime); - } - else if (glow) - { - target.AddBuff(ModContent.BuffType(), debuffTime / 3); - } - else if (hell) - { - target.AddBuff(ModContent.BuffType(), debuffTime); - } - else if (holy) - { - target.AddBuff(ModContent.BuffType(), debuffTime); - } - else - { - target.AddBuff(ModContent.BuffType(), debuffTime); - } - } - } -} diff --git a/Projectiles/Melee/BiomeOrb.png b/Projectiles/Melee/BiomeOrb.png deleted file mode 100644 index 9e55e98a87..0000000000 Binary files a/Projectiles/Melee/BiomeOrb.png and /dev/null differ diff --git a/Projectiles/Melee/BrokenBiomeBladeProjectiles.cs b/Projectiles/Melee/BrokenBiomeBladeProjectiles.cs new file mode 100644 index 0000000000..acf4babdb4 --- /dev/null +++ b/Projectiles/Melee/BrokenBiomeBladeProjectiles.cs @@ -0,0 +1,937 @@ +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; + + +namespace CalamityMod.Projectiles.Melee +{ + public class PurityProjection : ModProjectile //The boring plain one + { + public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_PurityProjection"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Purity Projection"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 5; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + } + + 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.melee = true; + projectile.tileCollide = false; + } + + public override void AI() + { + 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 DecaysRetort : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float MaxTime => ref projectile.ai[0]; + public ref float CanLunge => ref projectile.ai[1]; + public float Timer => MaxTime - projectile.timeLeft; + public Player Owner => Main.player[projectile.owner]; + public const float LungeSpeed = 16; + public ref float CanBounce => ref projectile.localAI[0]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Decay's retort"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 84; + projectile.width = projectile.height = 84; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 1; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 120f * projectile.scale; + Vector2 displace = direction * ((float)Math.Sin(Timer / MaxTime * 3.14f) * 60); + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center + displace, Owner.Center + displace + (direction * bladeLenght), 24, ref collisionPoint); + } + + public override void AI() + { + if (!initialized) //Initialization + { + CanBounce = 1f; + projectile.timeLeft = (int)MaxTime; + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + if (CanLunge == 1f) + Lunge(); + Main.PlaySound(SoundID.Item103, projectile.Center); + initialized = true; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + //Manage position and rotation + projectile.scale = 1f + ((float)Math.Sin(Timer / MaxTime * MathHelper.Pi) * 0.6f); //SWAGGER + projectile.Center = Owner.Center + (direction * ((float)Math.Sin(Timer / MaxTime * MathHelper.Pi) * 60)); + + Lighting.AddLight(projectile.Center, new Vector3(0.9f, 0f, 0.35f) * (float)Math.Sin(Timer / MaxTime * MathHelper.Pi)); + + //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); + } + + public void Lunge() + { + if (Main.myPlayer != projectile.owner) + return; + Owner.velocity = direction.SafeNormalize(Vector2.UnitX * Owner.direction) * LungeSpeed; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => OnHitEffects(!target.canGhostHeal || Main.player[projectile.owner].moonLeech); + public override void OnHitPvp(Player target, int damage, bool crit) => OnHitEffects(Main.player[projectile.owner].moonLeech); + + private void OnHitEffects(bool cannotLifesteal) + { + projectile.netUpdate = true; + projectile.netSpam = 0; + + if (!cannotLifesteal) //trolled + { + Owner.statLife += BiomeBlade.EvilAttunement_Lifesteal; + Owner.HealEffect(BiomeBlade.EvilAttunement_Lifesteal); //Idk if its too much or what but at the same time its close range as fuck + } + if (Main.myPlayer != Owner.whoAmI || CanBounce == 0f) + return; + // Bounce off + float bounceStrength = Math.Max((LungeSpeed / 2f), Owner.velocity.Length()); + bounceStrength *= Owner.velocity.Y == 0 ? 0.2f : 1f; //Reduce the bounce if the player is on the ground + Owner.velocity = -direction.SafeNormalize(Vector2.Zero) * MathHelper.Clamp(bounceStrength, 0f, 22f); + CanBounce = 0f; + Owner.GiveIFrames(BiomeBlade.EvilAttunement_BounceIFrames); // i frames for free! + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/BiomeBlade"); + Texture2D tex = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 displace = direction * ((float)Math.Sin(Timer / MaxTime * 3.14f) * 60); + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + direction * 10f - Main.screenPosition; + + spriteBatch.Draw(handle, drawOffset + displace, 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, tex.Height); + drawOffset = Owner.Center + (drawAngle.ToRotationVector2() * 24f * projectile.scale) - Main.screenPosition; + + spriteBatch.Draw(tex, drawOffset + displace, 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 SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + writer.Write(CanBounce); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + CanBounce = reader.ReadSingle(); + } + } + + public class BitingEmbrace : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceSmall"; + + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public float rotation; + public ref float SwingMode => ref projectile.ai[0]; //0 = Up-Down small slash, 1 = Down-Up large slash, 2 = Thrust + public ref float MaxTime => ref projectile.ai[1]; + public float Timer => MaxTime - projectile.timeLeft; + + public int SwingDirection + { + get + { + switch (SwingMode) + { + case 0: + return -1 * Math.Sign(direction.X); + case 1: + return 1 * Math.Sign(direction.X); + default: + return 0; + + } + } + } + public float SwingWidth + { + get + { + switch (SwingMode) + { + case 0: + return 2.3f; + default: + return 1.8f; + } + } + } + + public Player Owner => Main.player[projectile.owner]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Biting Embrace"); + Main.projFrames[projectile.type] = 6; //The true trolling is that we only really use this for the third swing. + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 75; + projectile.width = projectile.height = 75; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 1; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + //The hitbox is simplified into a line collision. + float collisionPoint = 0f; + float bladeLenght = 0f; + Vector2 displace = Vector2.Zero; + switch (SwingMode) + { + case 0: + bladeLenght = 90f * projectile.scale; + break; + case 1: + bladeLenght = 110f * projectile.scale; + break; + case 2: + bladeLenght = projectile.frame <= 2 ? 85f : 150f; //Only use the extended hitbox after the blade actually extends. For realism. + bladeLenght *= projectile.scale; + displace = direction * ThrustDisplaceRatio() * 60f; + break; + + } + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center + displace, Owner.Center + displace + (rotation.ToRotationVector2() * bladeLenght), 24, ref collisionPoint); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + base.OnHitNPC(target, damage, knockback, crit); + if (SwingMode == 2) + target.AddBuff(BuffType(), 20); + } + + public override void AI() + { + if (!initialized) //Initialization + { + projectile.timeLeft = (int)MaxTime; + switch (SwingMode) + { + case 0: + projectile.width = projectile.height = 100; + Main.PlaySound(SoundID.DD2_MonkStaffSwing, projectile.Center); + break; + case 1: + projectile.width = projectile.height = 140; + Main.PlaySound(SoundID.DD2_OgreSpit, projectile.Center); + projectile.damage = (int)(projectile.damage * BiomeBlade.ColdAttunement_SecondSwingBoost); + break; + case 2: + projectile.width = projectile.height = 130; + Main.PlaySound(SoundID.DD2_PhantomPhoenixShot, projectile.Center); + projectile.damage = (int)(projectile.damage * BiomeBlade.ColdAttunement_ThirdSwingBoost); + break; + } + + //Take the direction the sword is swung. FUCK not controlling the swing direction more than just left/right :| + //The direction to mouseworld may need to be turned into the custom synced player mouse variables . not on the branch currently tho + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + + initialized = true; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + //Manage position and rotation + projectile.Center = Owner.Center + (direction * 30); + //rotation = projectile.rotation + MathHelper.SmoothStep(SwingWidth / 2 * SwingDirection, -SwingWidth / 2 * SwingDirection, Timer / MaxTime); + float factor = 1 - (float)Math.Pow((double)-(Timer / MaxTime) + 1, 2d); + rotation = projectile.rotation + MathHelper.Lerp(SwingWidth / 2 * SwingDirection, -SwingWidth / 2 * SwingDirection, factor); + projectile.scale = 1f + ((float)Math.Sin(Timer / MaxTime * MathHelper.Pi) * 0.6f); //SWAGGER + + Lighting.AddLight(Owner.MountedCenter, new Vector3(0.75f, 1f, 1f) * (float)Math.Sin(Timer/MaxTime * MathHelper.Pi)); + + //Add the thrust motion & animation for the third combo state + if (SwingMode == 2) + { + projectile.scale = 1f + (ThrustScaleRatio() * 0.6f); + projectile.Center = Owner.Center + (direction * ThrustDisplaceRatio() * 60); + + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 0 && projectile.frame + 1 < Main.projFrames[projectile.type]) + projectile.frame++; + + if (Main.rand.NextBool()) + { + Particle mist = new MediumMistParticle(Owner.Center + direction * 40 + Main.rand.NextVector2Circular(30f, 30f), Vector2.Zero, new Color(172, 238, 255), new Color(145, 170, 188), Main.rand.NextFloat(0.5f, 1.5f), 245 - Main.rand.Next(50), 0.02f); + mist.Velocity = (mist.Position - Owner.Center) * 0.2f + Owner.velocity; + GeneralParticleHandler.SpawnParticle(mist); + } + + } + + else if (Main.rand.NextFloat(0f, 1f) > 0.75f) + { + Vector2 particlePosition = Owner.Center + (rotation.ToRotationVector2() * 100f * projectile.scale); + Particle snowflake = new SnowflakeSparkle(particlePosition, rotation.ToRotationVector2() * 3f, Color.White, new Color(75, 177, 250), Main.rand.NextFloat(0.3f, 1.5f), 40, 0.5f); + GeneralParticleHandler.SpawnParticle(snowflake); + } + + //Make the owner look like theyre holding the sword bla bla + Owner.heldProj = projectile.whoAmI; + Owner.direction = Math.Sign(rotation.ToRotationVector2().X); + Owner.itemRotation = rotation; + if (Owner.direction != 1) + { + Owner.itemRotation -= 3.14f; + } + Owner.itemRotation = MathHelper.WrapAngle(Owner.itemRotation); + } + + //Animation keys + public CurveSegment anticipation = new CurveSegment(EasingType.SineBump, 0f, 0f, -0.15f); + public CurveSegment thrust = new CurveSegment(EasingType.PolyInOut, 0.2f, 0f, 0.9f, 3); + public CurveSegment hold = new CurveSegment(EasingType.SineBump, 0.35f, 0.9f, 0.1f); + public CurveSegment retract = new CurveSegment(EasingType.PolyInOut, 0.7f, 0.9f, -0.9f, 3); + internal float ThrustDisplaceRatio() => PiecewiseAnimation(Timer / MaxTime, new CurveSegment[] { anticipation, thrust, hold, retract }); + + //Animation keys + public CurveSegment expandSize = new CurveSegment(EasingType.ExpIn, 0f, 0f, 1f); + public CurveSegment holdSize = new CurveSegment(EasingType.Linear, 0.1f, 1f, 0f); + public CurveSegment shrinkSize = new CurveSegment(EasingType.ExpIn, 0.85f, 1f, -1f); + internal float ThrustScaleRatio() => PiecewiseAnimation(Timer / MaxTime, new CurveSegment[] { expandSize, holdSize, shrinkSize }); + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/BiomeBlade"); + + if (SwingMode != 2) + { + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_BitingEmbrace" + (SwingMode == 0 ? "Small" : "Big")); + float drawAngle = rotation; + float drawRotation = rotation + MathHelper.PiOver4; + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + drawAngle.ToRotationVector2() * 10f - 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); + //Update the parameters + drawOrigin = new Vector2(0f, blade.Height); + drawOffset = Owner.Center + (drawAngle.ToRotationVector2() * 28f * projectile.scale) - Main.screenPosition; + spriteBatch.Draw(blade, drawOffset, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f, 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); + } + else + { + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceThrust"); + Vector2 thrustDisplace = direction * (ThrustDisplaceRatio() * 60); + + float drawAngle = rotation; + float drawRotation = rotation + MathHelper.PiOver4; + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + drawAngle.ToRotationVector2() * 10f - Main.screenPosition; + + spriteBatch.Draw(handle, drawOffset + thrustDisplace, 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, 114f); + drawOffset = Owner.Center + (direction * 28f * projectile.scale) - Main.screenPosition; + //Anim stuff + Rectangle frameRectangle = new Rectangle(0, 0 + (116 * projectile.frame), 114, 114); + + spriteBatch.Draw(blade, drawOffset + thrustDisplace, frameRectangle, 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 SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + writer.Write(rotation); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + rotation = reader.ReadSingle(); + } + } + + public class AridGrandeur : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float Shred => ref projectile.ai[0]; //How much the attack is, attacking + public float ShredRatio => MathHelper.Clamp(Shred / (maxShred * 0.5f), 0f, 1f); + public ref float PogoCooldown => ref projectile.ai[1]; //Cooldown for the pogo + public Player Owner => Main.player[projectile.owner]; + public bool CanPogo => Owner.velocity.Y != 0 && PogoCooldown <= 0; //Only pogo when in the air and if the cooldown is zero + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + + public const float pogoStrenght = 16f; //How much the player gets pogoed up + public const float maxShred = 500; //How much shred you get + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Arid Grandeur"); + } + 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 = BiomeBlade.HotAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 84 * projectile.scale; + float bladeWidth = 76 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center, Owner.Center + (direction * bladeLenght), bladeWidth, ref collisionPoint); + } + + public void Pogo() + { + if (CanPogo && Main.myPlayer == Owner.whoAmI) + { + Owner.velocity = -direction.SafeNormalize(Vector2.Zero) * pogoStrenght; //Bounce + Owner.fallStart = (int)(Owner.position.Y / 16f); + PogoCooldown = 30; //Cooldown + Main.PlaySound(SoundID.DD2_MonkStaffGroundImpact, projectile.position); + + Vector2 hitPosition = Owner.Center + (direction * 84 * projectile.scale); + + for (int i = 0; i < 8; i++) + { + Vector2 hitPositionDisplace = direction.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(-10f, 10f); + Vector2 flyDirection = -direction.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)); + Particle smoke = new SmallSmokeParticle(hitPosition + hitPositionDisplace, flyDirection * 9f, Color.OrangeRed, new Color(130, 130, 130), Main.rand.NextFloat(1.8f, 2.6f), 115 - Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(smoke); + + Particle Glow = new StrongBloom(hitPosition - hitPositionDisplace * 3, -direction * 6 * Main.rand.NextFloat(0.5f, 1f), Color.Orange * 0.5f, 0.01f + Main.rand.NextFloat(0f, 0.2f), 20 + Main.rand.Next(40)); + GeneralParticleHandler.SpawnParticle(Glow); + } + for (int i = 0; i < 3; i++) + { + Vector2 hitPositionDisplace = direction.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(-10f, 10f); + Vector2 flyDirection = -direction.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)); + + Particle Rock = new StoneDebrisParticle(hitPosition - hitPositionDisplace * 3, flyDirection * Main.rand.NextFloat(3f, 6f), Color.Beige, 1f + Main.rand.NextFloat(0f, 0.4f), 30 + Main.rand.Next(50), 0.1f); + GeneralParticleHandler.SpawnParticle(Rock); + } + + if (Owner.HeldItem.type == ItemType()) + (Owner.HeldItem.modItem as BiomeBlade).CanLunge = 1; // Reset the lunge counter on pogo. This should make for more interesting and fun synergies + } + } + + public override void AI() + { + if (!initialized) //Initialization. Here its litterally just playing a sound tho lmfao + { + Main.PlaySound(SoundID.Item90, projectile.Center); + initialized = true; + } + + if (!OwnerCanShoot) + { + projectile.Kill(); + return; + } + + if (Shred >= maxShred) + Shred = maxShred; + if (Shred < 0) + Shred = 0; + + Lighting.AddLight(projectile.Center, new Vector3(1f, 0.56f, 0.56f) * ShredRatio); + + //Manage position and rotation + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + projectile.Center = Owner.Center + (direction * 60); + + //Scaling based on shred + projectile.localNPCHitCooldown = BiomeBlade.HotAttunement_LocalIFrames - (int)(MathHelper.Lerp(0, BiomeBlade.HotAttunement_LocalIFrames - BiomeBlade.HotAttunement_LocalIFramesCharged, ShredRatio)); //Increase the hit frequency + projectile.scale = 1f + (ShredRatio * 1f); //SWAGGER + + + if (Collision.SolidCollision(Owner.Center + (direction * 84 * projectile.scale) - Vector2.One * 5f, 10, 10)) + { + Pogo(); + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + //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; + + Shred--; + PogoCooldown--; + projectile.timeLeft = 2; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => ShredTarget(target); + public override void OnHitPvp(Player target, int damage, bool crit) => ShredTarget(target); + + private void ShredTarget(Entity target) + { + if (Main.myPlayer != Owner.whoAmI) + return; + // get lifted up + if (PogoCooldown <= 0) + { + Main.PlaySound(SoundID.NPCHit30, projectile.Center); //Sizzle + Shred += 62; //Augment the shredspeed + if (Owner.velocity.Y > 0) + Owner.velocity.Y = -2f; //Get "stuck" into the enemy partly + Owner.GiveIFrames(BiomeBlade.HotAttunement_ShredIFrames); // i framez. + PogoCooldown = 20; + } + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.NPCHit43, projectile.Center); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/BiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur"); + + int bladeAmount = 4; + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + direction * 10f - 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); + //Update the parameters + drawOrigin = new Vector2(0f, blade.Height); + drawOffset = Owner.Center + (drawAngle.ToRotationVector2() * 32f * projectile.scale) - Main.screenPosition; + + spriteBatch.Draw(blade, drawOffset, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.9f, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + + for (int i = 0; i < bladeAmount; i++) //Draw extra copies + { + blade = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_AridGrandeurExtra"); + + drawAngle = direction.ToRotation(); + + float circleCompletion = (float)Math.Sin(Main.GlobalTime * 5 + i * MathHelper.PiOver2); + drawRotation = drawAngle + MathHelper.PiOver4 + (circleCompletion * MathHelper.Pi / 10f) - (circleCompletion * (MathHelper.Pi / 7f) * ShredRatio); + + drawOrigin = new Vector2(0f, blade.Height); + + + Vector2 drawOffsetStraight = Owner.Center + direction * (float)Math.Sin(Main.GlobalTime * 7) * 10 - Main.screenPosition; //How far from the player + Vector2 drawDisplacementAngle = direction.RotatedBy(MathHelper.PiOver2) * circleCompletion.ToRotationVector2().Y * (20 + 40 * ShredRatio); //How far perpendicularly + + spriteBatch.Draw(blade, drawOffsetStraight + drawDisplacementAngle, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f, 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 SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + } + } + + public class GrovetendersTouch : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchBlade"; + private bool initialized = false; + public Player Owner => Main.player[projectile.owner]; + public float Timer => MaxTime - projectile.timeLeft; + public ref float HasSnapped => ref projectile.ai[0]; + public ref float SnapCoyoteTime => ref projectile.ai[1]; + + const float MaxTime = 90; + const int coyoteTimeFrames = 15; //How many frames does the whip stay extended + const int MaxReach = 400; + const float SnappingPoint = 0.7f; //When does the snap occur. + const float ReelBackStrenght = 14f; + + public BezierCurve curve; + private Vector2 controlPoint1; + private Vector2 controlPoint2; + internal bool ReelingBack => Timer / MaxTime > SnappingPoint; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Grovetender's Touch"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 36; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = BiomeBlade.TropicalAttunement_LocalIFrames; + } + + public override bool? CanCutTiles() => false; //Itd be quite counterproductive to make the whip cut the tiles it just grew + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + BezierCurve curve = new BezierCurve(new Vector2[] { Owner.MountedCenter, controlPoint1, controlPoint2, projectile.Center }); + + int numPoints = 32; + Vector2[] chainPositions = curve.GetPoints(numPoints).ToArray(); + float collisionPoint = 0; + for (int i = 1; i < numPoints; i++) + { + Vector2 position = chainPositions[i]; + Vector2 previousPosition = chainPositions[i - 1]; + if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), position, previousPosition, 6, ref collisionPoint)) + return true; + } + return base.Colliding(projHitbox, targetHitbox); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + base.ModifyHitNPC(target, ref damage, ref knockback, ref crit, ref hitDirection); + Vector2 projectileHalfLenght = (projectile.Size / 2f) * projectile.rotation.ToRotationVector2(); + float collisionPoint = 0; + //If you hit the enemy during the coyote time with the blade of the whip, guarantee a crit + if (Collision.CheckAABBvLineCollision(target.Hitbox.TopLeft(), target.Hitbox.Size(), projectile.Center - projectileHalfLenght, projectile.Center + projectileHalfLenght, 32, ref collisionPoint)) + { + if (SnapCoyoteTime > 0f) + { + crit = true; + for (int i = 0; i < 3; i++) + { + Vector2 sparkSpeed = Owner.DirectionTo(target.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver2, MathHelper.PiOver2)) * 9f; + Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.LimeGreen, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.6f); + GeneralParticleHandler.SpawnParticle(Spark); + } + + } + } + else + damage = (int)(damage * BiomeBlade.TropicalAttunement_ChainDamageReduction); //If the enemy is hit with the chain of the whip, the damage gets reduced + } + + public override void AI() + { + if (!initialized) //Initialization. create control points & shit) + { + projectile.velocity = Owner.DirectionTo(Main.MouseWorld); + Main.PlaySound(SoundID.DD2_OgreSpit, projectile.Center); + controlPoint1 = projectile.Center; + controlPoint2 = projectile.Center; + projectile.timeLeft = (int)MaxTime; + initialized = true; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + if (ReelingBack && HasSnapped == 0f) //Snap & also small coyote time for the hook + { + Main.PlaySound(SoundID.Item41, projectile.Center); //Snap + HasSnapped = 1f; + SnapCoyoteTime = coyoteTimeFrames; + } + + if (SnapCoyoteTime > 0) //keep checking for the tile hook + { + Lighting.AddLight(projectile.Center, 0.8f, 1f, 0.35f); + HookToTile(); + SnapCoyoteTime--; + } + + Owner.direction = Math.Sign(projectile.velocity.X); + projectile.rotation = projectile.AngleFrom(Owner.Center); //Point away from playah + + float ratio = GetSwingRatio(); + projectile.Center = Owner.MountedCenter + SwingPosition(ratio); + projectile.direction = projectile.spriteDirection = -Owner.direction; + + Owner.itemRotation = MathHelper.WrapAngle(Owner.AngleTo(Main.MouseWorld) - (Owner.direction < 0 ? MathHelper.Pi : 0)); + } + public void HookToTile() + { + if (Main.myPlayer == Owner.whoAmI) + { + //Shmoove the player if a tile is hit. This movement always happens if the owner isnt on the ground, but will only happen if the projectile is above the player if they are standing on the ground) + if (Collision.SolidCollision(projectile.position, 32, 32) && (Owner.velocity.Y != 0 || projectile.position.Y < Owner.position.Y)) + { + Owner.velocity = Owner.DirectionTo(projectile.Center) * ReelBackStrenght; + SnapCoyoteTime = 0f; + } + Main.PlaySound(SoundID.Item65, projectile.position); + } + } + + internal float EaseInFunction(float progress) => progress == 0 ? 0f : (float)Math.Pow(2, 10 * progress - 10); //Potion seller i need your strongest easeIns + + private float GetSwingRatio() + { + float ratio = (Timer - SnappingPoint * MaxTime) / (MaxTime * (1 - SnappingPoint)); //The ratio for the last section of the snap is a new curve. + if (!ReelingBack) + ratio = EaseInFunction(Timer / (MaxTime * SnappingPoint)); //Watch this ratio get eased + if (SnapCoyoteTime > 0) + ratio = 0f; + return ratio; + } + + private Vector2 SwingPosition(float progress) + { + //Whip windup and snap part + if (!ReelingBack) + { + float distance = MaxReach * MathHelper.Lerp((float)Math.Sin(progress * MathHelper.PiOver2), 1, 0.04f); //half arc + distance = Math.Max(distance, 65); //Dont be too close to player + + float angleDeviation = MathHelper.Pi / 1.2f; + float angleOffset = Owner.direction * MathHelper.Lerp(-angleDeviation, 0, progress); //Go from very angled to straight at the zenith of the attack + return projectile.velocity.RotatedBy(angleOffset) * distance; + } + else + { + float distance = MathHelper.Lerp(MaxReach, 0f, progress); //Quickly zip back to the player . No angles or minimum distance from player. + return projectile.velocity * distance; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (Timer == 0) + return false; + Texture2D handle = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchGlow"); + + Vector2 projBottom = projectile.Center + new Vector2(-handle.Width / 2, handle.Height / 2).RotatedBy(projectile.rotation + MathHelper.PiOver4) * 0.75f; + DrawChain(spriteBatch, projBottom, out Vector2[] chainPositions); + + float drawRotation = (projBottom - chainPositions[chainPositions.Length - 2]).ToRotation() + MathHelper.PiOver4; //Face away from the last point of the bezier curve + drawRotation += SnapCoyoteTime > 0 ? MathHelper.Pi : 0; //During coyote time the blade flips for some reason. Prevent that from happening + drawRotation += projectile.spriteDirection < 0 ? 0f : 0f; + + Vector2 drawOrigin = new Vector2(0f, handle.Height); + SpriteEffects flip = (projectile.spriteDirection < 0) ? SpriteEffects.None : SpriteEffects.None; + lightColor = Lighting.GetColor((int)(projectile.Center.X / 16f), (int)(projectile.Center.Y / 16f)); + + spriteBatch.Draw(handle, projBottom - Main.screenPosition, null, lightColor, drawRotation, drawOrigin, projectile.scale, flip, 0f); + + //Turn on additive blending + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + //Only update the origin for once + drawOrigin = new Vector2(0f, blade.Height); + spriteBatch.Draw(blade, projBottom - Main.screenPosition, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.9f, drawRotation, drawOrigin, projectile.scale, flip, 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; + } + + private void DrawChain(SpriteBatch spriteBatch, Vector2 projBottom, out Vector2[] chainPositions) + { + Texture2D chainTex = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchChain"); + + float ratio = GetSwingRatio(); + + if (!ReelingBack) //Make the curve be formed from points slightly ahead of the projectile, but clamped to the max rotation (straight line ahead) + { + controlPoint1 = Owner.MountedCenter + SwingPosition(MathHelper.Clamp(ratio + 0.5f, 0f, 1f)) * 0.2f; + controlPoint2 = Owner.MountedCenter + SwingPosition(MathHelper.Clamp(ratio + 0.2f, 0f, 1f)) * 0.5f; + } + else //After the whip snaps, make the curve be a wave + { + Vector2 perpendicular = SwingPosition(ratio).SafeNormalize(Vector2.Zero).RotatedBy(MathHelper.PiOver2); + controlPoint1 = Owner.MountedCenter + SwingPosition(MathHelper.Lerp(ratio, 1f, ratio)) + perpendicular * MathHelper.SmoothStep(0f, 1f, ratio) * -155f; + controlPoint2 = Owner.MountedCenter + SwingPosition(MathHelper.Lerp(ratio, 1f, ratio / 2)) + perpendicular * MathHelper.SmoothStep(0f, 1f, ratio) * 100f; + } + + BezierCurve curve = new BezierCurve(new Vector2[] { Owner.MountedCenter, controlPoint1, controlPoint2, projBottom }); + int numPoints = 30; //"Should make dynamic based on curve length, but I'm not sure how to smoothly do that while using a bezier curve" -Graydee, from the code i referenced. I do agree. + chainPositions = curve.GetPoints(numPoints).ToArray(); + + //Draw each chain segment bar the very first one + for (int i = 1; i < numPoints; i++) + { + Vector2 position = chainPositions[i]; + float rotation = (chainPositions[i] - chainPositions[i - 1]).ToRotation() - MathHelper.PiOver2; //Calculate rotation based on direction from last point + float yScale = Vector2.Distance(chainPositions[i], chainPositions[i - 1]) / chainTex.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)position.X / 16, (int)position.Y / 16); //Lighting of the position of the chain segment + if (ReelingBack) + chainLightColor *= 1 - EaseInFunction(ratio); //Make the chain fade when reeling it back + Vector2 origin = new Vector2(chainTex.Width / 2, chainTex.Height); //Draw from center bottom of texture + spriteBatch.Draw(chainTex, position - Main.screenPosition, null, chainLightColor, rotation, origin, scale, SpriteEffects.None, 0); + } + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + } + } +} diff --git a/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur.png b/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur.png new file mode 100644 index 0000000000..1ae5fb7e62 Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_AridGrandeur.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_AridGrandeurExtra.png b/Projectiles/Melee/BrokenBiomeBlade_AridGrandeurExtra.png new file mode 100644 index 0000000000..bc84b51a7c Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_AridGrandeurExtra.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceBig.png b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceBig.png new file mode 100644 index 0000000000..fd2937b9a0 Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceBig.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceSmall.png b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceSmall.png new file mode 100644 index 0000000000..1d4e5b8db6 Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceSmall.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceThrust.png b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceThrust.png new file mode 100644 index 0000000000..0dc5efed4b Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_BitingEmbraceThrust.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort.png b/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort.png new file mode 100644 index 0000000000..e9ea44de32 Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_DecaysRetort.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchBlade.png b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchBlade.png new file mode 100644 index 0000000000..7d1ab5c71c Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchBlade.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchChain.png b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchChain.png new file mode 100644 index 0000000000..c1d8bd44b9 Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchChain.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchGlow.png b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchGlow.png new file mode 100644 index 0000000000..252f0bd137 Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchGlow.png differ diff --git a/Projectiles/Melee/BrokenBiomeBlade_PurityProjection.png b/Projectiles/Melee/BrokenBiomeBlade_PurityProjection.png new file mode 100644 index 0000000000..3e30b134fc Binary files /dev/null and b/Projectiles/Melee/BrokenBiomeBlade_PurityProjection.png differ diff --git a/Projectiles/Melee/Galaxia.cs b/Projectiles/Melee/Galaxia.cs deleted file mode 100644 index 697fd25eaa..0000000000 --- a/Projectiles/Melee/Galaxia.cs +++ /dev/null @@ -1,279 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.Buffs.Potions; -using CalamityMod.CalPlayer; -using CalamityMod.Projectiles.Typeless; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Melee -{ - public class Galaxia : ModProjectile - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Orb"); - ProjectileID.Sets.TrailCacheLength[projectile.type] = 6; - ProjectileID.Sets.TrailingMode[projectile.type] = 0; - } - - public override void SetDefaults() - { - projectile.width = 24; - projectile.height = 24; - projectile.friendly = true; - projectile.tileCollide = false; - projectile.ignoreWater = true; - projectile.alpha = 50; - projectile.penetrate = 3; - projectile.timeLeft = 240; - projectile.melee = true; - projectile.usesLocalNPCImmunity = true; - projectile.localNPCHitCooldown = 10; - } - - public override void AI() - { - if (projectile.soundDelay == 0) - { - projectile.soundDelay = 20 + Main.rand.Next(40); - if (Main.rand.NextBool(5)) - { - Main.PlaySound(SoundID.Item9, projectile.position); - } - } - projectile.alpha -= 15; - int num58 = 150; - if (projectile.Center.Y >= projectile.ai[1]) - { - num58 = 0; - } - if (projectile.alpha < num58) - { - projectile.alpha = num58; - } - projectile.localAI[0] += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f * (float)projectile.direction; - projectile.rotation += (Math.Abs(projectile.velocity.X) + Math.Abs(projectile.velocity.Y)) * 0.01f * (float)projectile.direction; - if (Main.rand.NextBool(8)) - { - Vector2 value3 = Vector2.UnitX.RotatedByRandom(1.5707963705062866).RotatedBy((double)projectile.velocity.ToRotation(), default); - int num59 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 66, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f, 150, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.2f); - Main.dust[num59].noGravity = true; - Main.dust[num59].velocity = value3 * 0.66f; - Main.dust[num59].position = projectile.Center + value3 * 12f; - } - if (Main.rand.NextBool(24)) - { - int num60 = Gore.NewGore(projectile.Center, new Vector2(projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f), 16, 1f); - Main.gore[num60].velocity *= 0.66f; - Main.gore[num60].velocity += projectile.velocity * 0.3f; - } - if (projectile.ai[1] == 1f) - { - projectile.light = 0.9f; - if (Main.rand.NextBool(5)) - { - int num59 = Dust.NewDust(projectile.position, projectile.width, projectile.height, 66, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f, 150, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 1.2f); - Main.dust[num59].noGravity = true; - } - if (Main.rand.NextBool(10)) - { - Gore.NewGore(projectile.position, new Vector2(projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f), Main.rand.Next(16, 18), 1f); - } - } - - CalamityGlobalProjectile.HomeInOnNPC(projectile, true, 300f, 12f, 20f); - } - - public override Color? GetAlpha(Color lightColor) - { - return new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB, projectile.alpha); - } - - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); - return false; - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool corrupt = player.ZoneCorrupt; - bool crimson = player.ZoneCrimson; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool holy = player.ZoneHoly; - bool nebula = player.ZoneTowerNebula; - bool stardust = player.ZoneTowerStardust; - bool solar = player.ZoneTowerSolar; - bool vortex = player.ZoneTowerVortex; - bool bloodMoon = Main.bloodMoon; - bool snowMoon = Main.snowMoon; - bool pumpkinMoon = Main.pumpkinMoon; - int duration = 180; - if (bloodMoon) - { - player.AddBuff(BuffID.Battle, duration); - } - if (snowMoon) - { - player.AddBuff(BuffID.RapidHealing, duration); - } - if (pumpkinMoon) - { - player.AddBuff(BuffID.WellFed, duration); - } - if (astral) - { - target.AddBuff(ModContent.BuffType(), duration); - player.AddBuff(ModContent.BuffType(), duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - Main.projectile[proj].Calamity().forceMelee = true; - } - else if (jungle) - { - target.AddBuff(ModContent.BuffType(), duration); - player.AddBuff(BuffID.Thorns, duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.Leaf, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - Main.projectile[proj].Calamity().forceMelee = true; - } - else if (snow) - { - target.AddBuff(ModContent.BuffType(), 30); - player.AddBuff(BuffID.Warmth, duration); - Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.IceBolt, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - } - else if (beach) - { - target.AddBuff(ModContent.BuffType(), duration); - player.AddBuff(BuffID.Wet, duration); - int proj = Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, projectile.velocity.X * 0.25f, projectile.velocity.Y * 0.25f, ProjectileID.FlaironBubble, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - Main.projectile[proj].Calamity().forceMelee = true; - } - else if (corrupt) - { - player.AddBuff(BuffID.Wrath, duration); - int ball = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.CursedFlameFriendly, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (ball.WithinBounds(Main.maxProjectiles)) - { - Main.projectile[ball].Calamity().forceMelee = true; - Main.projectile[ball].penetrate = 1; - } - } - else if (crimson) - { - player.AddBuff(BuffID.Rage, duration); - int ball = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.GoldenShowerFriendly, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (ball.WithinBounds(Main.maxProjectiles)) - { - Main.projectile[ball].Calamity().forceMelee = true; - Main.projectile[ball].penetrate = 1; - } - } - else if (dungeon) - { - target.AddBuff(BuffID.Frostburn, duration); - player.AddBuff(BuffID.Dangersense, duration); - int ball = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.WaterBolt, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (ball.WithinBounds(Main.maxProjectiles)) - { - Main.projectile[ball].Calamity().forceMelee = true; - Main.projectile[ball].penetrate = 1; - } - } - else if (desert) - { - target.AddBuff(ModContent.BuffType(), duration); - player.AddBuff(BuffID.Endurance, duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.BlackBolt, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - Main.projectile[proj].Calamity().forceMelee = true; - } - else if (glow) - { - target.AddBuff(ModContent.BuffType(), 30); - player.AddBuff(BuffID.Spelunker, duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.Mushroom, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - Main.projectile[proj].Calamity().forceMelee = true; - } - else if (hell) - { - target.AddBuff(ModContent.BuffType(), duration); - player.AddBuff(BuffID.Inferno, duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.BallofFire, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - Main.projectile[proj].Calamity().forceMelee = true; - } - else if (holy) - { - target.AddBuff(ModContent.BuffType(), duration); - player.AddBuff(BuffID.Heartreach, duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.RainbowCrystalExplosion, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - { - Main.projectile[proj].Calamity().forceMelee = true; - Main.projectile[proj].usesLocalNPCImmunity = true; - Main.projectile[proj].localNPCHitCooldown = -1; - } - } - else if (nebula) - { - player.AddBuff(BuffID.MagicPower, duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.NebulaBlaze1, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - Main.projectile[proj].Calamity().forceMelee = true; - } - else if (stardust) - { - player.AddBuff(BuffID.Summoning, duration); - int ball = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.StardustCellMinionShot, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (ball.WithinBounds(Main.maxProjectiles)) - { - Main.projectile[ball].Calamity().forceMelee = true; - Main.projectile[ball].penetrate = 1; - } - } - else if (solar) - { - player.AddBuff(BuffID.Titan, duration); - Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.SolarWhipSwordExplosion, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0.85f + Main.rand.NextFloat() * 1.15f); - } - else if (vortex) - { - player.AddBuff(BuffID.AmmoReservation, duration); - int proj = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.VortexBeaterRocket, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (proj.WithinBounds(Main.maxProjectiles)) - { - Main.projectile[proj].Calamity().forceMelee = true; - Main.projectile[proj].usesLocalNPCImmunity = true; - Main.projectile[proj].localNPCHitCooldown = -1; - } - } - else - { - target.AddBuff(ModContent.BuffType(), duration); - player.AddBuff(BuffID.DryadsWard, duration); - int ball = Projectile.NewProjectile(projectile.Center, projectile.velocity, ProjectileID.TerrarianBeam, projectile.damage, projectile.knockBack, projectile.owner, 0f, 0f); - if (ball.WithinBounds(Main.maxProjectiles)) - { - Main.projectile[ball].penetrate = 1; - } - } - } - } -} diff --git a/Projectiles/Melee/GalaxiaBolt.png b/Projectiles/Melee/GalaxiaBolt.png new file mode 100644 index 0000000000..bb3cd2af2c Binary files /dev/null and b/Projectiles/Melee/GalaxiaBolt.png differ diff --git a/Projectiles/Melee/GalaxiaCancer.png b/Projectiles/Melee/GalaxiaCancer.png new file mode 100644 index 0000000000..e25a8538f5 Binary files /dev/null and b/Projectiles/Melee/GalaxiaCancer.png differ diff --git a/Projectiles/Melee/GalaxiaCapricorn.png b/Projectiles/Melee/GalaxiaCapricorn.png new file mode 100644 index 0000000000..e353db0053 Binary files /dev/null and b/Projectiles/Melee/GalaxiaCapricorn.png differ diff --git a/Projectiles/Melee/GalaxiaProjectiles.cs b/Projectiles/Melee/GalaxiaProjectiles.cs new file mode 100644 index 0000000000..9bdfc476be --- /dev/null +++ b/Projectiles/Melee/GalaxiaProjectiles.cs @@ -0,0 +1,1850 @@ +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 +{ + + // General cosmic bolt projectile that gets used for a lot of the other ones + + public class GalaxiaBolt : ModProjectile + { + public NPC target; + public Player Owner => Main.player[projectile.owner]; + + public ref float Hue => ref projectile.ai[0]; + public ref float HomingStrenght => ref projectile.ai[1]; + + Particle Head; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Galaxia Bolt"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 2; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 30; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.timeLeft = 80; + projectile.melee = true; + projectile.tileCollide = false; + } + + public override void AI() + { + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + + if (Head == null) + { + Head = new GenericSparkle(projectile.Center, Vector2.Zero, Color.White, Main.hslToRgb(Hue, 100, 50), 1.2f, 2, 0.06f, 3); + GeneralParticleHandler.SpawnParticle(Head); + } + else + { + Head.Position = projectile.Center + projectile.velocity * 0.5f; + Head.Time = 0; + Head.Scale += (float)Math.Sin(Main.GlobalTime * 6) * 0.02f * projectile.scale; + } + + + if (target == null) + target = projectile.Center.ClosestNPCAt(812f, true); + + else if (CalamityUtils.AngleBetween(projectile.velocity, target.Center - projectile.Center) < MathHelper.PiOver2) //Home in + { + float idealDirection = projectile.AngleTo(target.Center); + float updatedDirection = projectile.velocity.ToRotation().AngleTowards(idealDirection, HomingStrenght); + projectile.velocity = updatedDirection.ToRotationVector2() * projectile.velocity.Length() * 0.995f; + } + + + Lighting.AddLight(projectile.Center, 0.75f, 1f, 0.24f); + + if (Main.rand.Next(2) == 0) + { + Particle smoke = new HeavySmokeParticle(projectile.Center, projectile.velocity * 0.5f, Color.Lerp(Color.MidnightBlue, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(0.6f, 1.2f) * projectile.scale, 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center, projectile.velocity * 0.5f, Main.hslToRgb(Hue, 1, 0.7f), 20, Main.rand.NextFloat(0.4f, 0.7f) * projectile.scale, 0.8f, 0, true, 0.005f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); + return false; + } + + public override void Kill(int timeLeft) + { + //Shit out a lot of particles or smth + } + } + + // Passive ring of star + + public class GalaxiaTropicRing : ModProjectile + { + public Player Owner => Main.player[projectile.owner]; + public ref float Mode => ref projectile.ai[0]; + public ref float Fade => ref projectile.ai[1]; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Star Ring"); + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 30; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 300; + projectile.melee = true; + projectile.tileCollide = false; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (Mode == 0f && Main.rand.NextFloat() < FourSeasonsGalaxia.CancerPassiveLifeStealProc) + { + Owner.statLife += FourSeasonsGalaxia.CancerPassiveLifeSteal; + Owner.HealEffect(FourSeasonsGalaxia.CancerPassiveLifeSteal); + } + else + { + target.AddBuff(BuffType(), FourSeasonsGalaxia.CapricornPassiveDebuffTime); + } + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + return Collision.CheckAABBvAABBCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center - Vector2.One * 95 * projectile.scale, Vector2.One * 190 * projectile.scale); + } + + public override void AI() + { + projectile.velocity *= 0.95f; + + if (Mode == 0f) + projectile.Center = Vector2.Lerp(projectile.Center, Owner.Center, 0.4f * MathHelper.Clamp((projectile.timeLeft - 150) / 150f, 0, 1)); + else + projectile.velocity = Utils.SafeNormalize(projectile.Center - Owner.Center, Vector2.Zero) * MathHelper.Clamp((projectile.timeLeft - 150) / 150f, 0, 1) * 3f * (5f - MathHelper.Clamp((projectile.Center - Owner.Center).Length() / 150f, 0, 4f)); + + Fade = projectile.timeLeft > 250 ? (float)Math.Sin((300 - projectile.timeLeft) / 50f * MathHelper.PiOver2) * 0.6f + 0.4f : projectile.timeLeft > 50 ? 1f : (float)Math.Sin((projectile.timeLeft) / 50f * MathHelper.PiOver2); + Lighting.AddLight(projectile.Center, 0.75f, 1f, 0.24f); + + } + + public Vector2 starPosition(int MaxStars, int StarIndex, float diameter) + { + float starHeight = (float)Math.Sin(Main.GlobalTime * 3 + StarIndex * MathHelper.TwoPi / (float)MaxStars); + float starWidth = (float)Math.Cos(Main.GlobalTime * 3 + StarIndex * MathHelper.TwoPi / (float)MaxStars); + + return projectile.Center + projectile.rotation.ToRotationVector2() * starWidth * (projectile.scale * diameter * 0.4f) + (projectile.rotation + MathHelper.PiOver2).ToRotationVector2() * starHeight * (projectile.scale * diameter * 0.4f); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D sigil = GetTexture(Mode == 0 ? "CalamityMod/Projectiles/Melee/GalaxiaCancer" : "CalamityMod/Projectiles/Melee/GalaxiaCapricorn"); //OMG Karkat and Gamzee from homestuck i am a big fan + Texture2D ring = GetTexture("CalamityMod/Particles/BloomRing"); + Texture2D starTexture = GetTexture("CalamityMod/Particles/Sparkle"); + Texture2D lineTexture = GetTexture("CalamityMod/Particles/BloomLine"); + Texture2D bloomTexture = GetTexture("CalamityMod/Particles/BloomCircle"); + + Color ringColor = Mode == 0 ? new Color(255, 0, 0) * Fade : new Color(66, 0, 176) * Fade; + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + spriteBatch.Draw(bloomTexture, projectile.Center - Main.screenPosition, null, ringColor * 0.5f, 0, bloomTexture.Size() / 2f, 2.5f, SpriteEffects.None, 0); + spriteBatch.Draw(ring, projectile.Center - Main.screenPosition, null, ringColor * 0.8f, 0f, ring.Size() / 2f, projectile.scale, 0f, 0f); + + spriteBatch.Draw(sigil, projectile.Center - Main.screenPosition, null, ringColor * MathHelper.Lerp(0.7f, 0f, ((Main.GlobalTime * 5f) % 10) / 10f), 0f, sigil.Size() / 2f, projectile.scale + ((Main.GlobalTime * 5f) % 10) / 10f * 2f, 0f, 0f) ; + spriteBatch.Draw(sigil, projectile.Center - Main.screenPosition, null, Color.White * Fade, 0f, sigil.Size() / 2f, projectile.scale, 0f, 0f); + + for (int i = 0; i < 5; i++) + { + + Vector2 starPos = starPosition(5, i, ring.Width); + + Vector2 LineVector = starPosition(5, i + 1, ring.Width) - starPos; + float rot = LineVector.ToRotation() + MathHelper.PiOver2; + Vector2 origin = new Vector2(lineTexture.Width / 2f, lineTexture.Height); + Vector2 scale = new Vector2(0.3f, LineVector.Length() / lineTexture.Height); + + spriteBatch.Draw(lineTexture, starPos - Main.screenPosition, null, Color.White * Fade * 0.7f, rot, origin, scale, SpriteEffects.None, 0); + + spriteBatch.Draw(bloomTexture, starPos - Main.screenPosition, null, ringColor * 0.5f, 0, bloomTexture.Size() / 2f, 0.1f, SpriteEffects.None, 0); + spriteBatch.Draw(starTexture, starPos - Main.screenPosition, null, ringColor * 0.5f, Main.GlobalTime * 5 + MathHelper.PiOver4 * i, starTexture.Size() / 2f ,1f, SpriteEffects.None, 0); + spriteBatch.Draw(starTexture, starPos - Main.screenPosition, null, Color.White * Fade, Main.GlobalTime * 5, starTexture.Size() / 2f, 1.4f, SpriteEffects.None, 0); + } + + return false; + } + } + + + //Phoenix's pride aka Whirlwind attunement + + public class PhoenixsPride : ModProjectile + { + public override string Texture => "CalamityMod/Items/Weapons/Melee/GalaxiaExtra2"; //The blue one, since this is long range + private bool initialized = false; + Vector2 direction = 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 float OverEmpowerment = 0f; //Used to keep cooldowns working when the spin is full + public ref float hasMadeSound => ref projectile.localAI[0]; + public ref float hasMadeChargeSound => ref projectile.localAI[1]; + + public const float maxEmpowerment = 600f; + public float throwTimer => throwOutTime - projectile.timeLeft; + + + public float AngleReset = 0f; + public bool CanDirectFire = true; + public Particle smear; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Pohenix's Pride"); + 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 = FourSeasonsGalaxia.WhirlwindAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 145 * projectile.scale; + float bladeWidth = 25 * 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(); + 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; + if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < 3) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = 3; + + 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.Coral, Color.Chocolate, 2f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + //Actually do projectiles now + if (Owner.whoAmI == Main.myPlayer) + { + for (int i = 0; i <= 5; i++) + { + float angle = direction.ToRotation() + MathHelper.Lerp(-MathHelper.PiOver4, MathHelper.PiOver4, i / 5f); + Projectile.NewProjectile(Owner.Center, angle.ToRotationVector2() * 30f, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.WhirlwindAttunement_BoltThrowDamageMultiplier), 0f, Owner.whoAmI, 0.1f, MathHelper.Pi * 0.02f); + } + } + } + } + + 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) + { + CanDirectFire = true; + hasMadeSound = 1f; + Main.PlaySound(SoundID.Item71); + } + } + + if (Empowerment / maxEmpowerment >= 0.5) //Double the charge speed when under half speed + { + Empowerment++; + } + + + if (Empowerment / maxEmpowerment >= 0.5) + { + + if (Main.rand.Next(2) == 0) + + { + + float Opacity = MathHelper.Clamp((Empowerment / maxEmpowerment - 0.5f) * 3f, 0, 1) * 0.75f; + float scaleFactor = MathHelper.Clamp((Empowerment / maxEmpowerment - 0.5f) * 3f, 0, 1); + + for (float i = 0f; i <= 1; i += 0.5f) + { + Vector2 smokepos = projectile.Center + (direction * (60 + 40 * i) * projectile.scale) + direction.RotatedBy(-MathHelper.PiOver2) * 30f * scaleFactor * Main.rand.NextFloat(); + + + Particle smoke = new HeavySmokeParticle(smokepos, direction.RotatedBy(-MathHelper.PiOver2) * 20f * scaleFactor + Owner.velocity, Color.Lerp(Color.MidnightBlue, Color.Indigo, i), 10 + Main.rand.Next(5), scaleFactor * Main.rand.NextFloat(2.8f, 3.1f), Opacity + Main.rand.NextFloat(0f, 0.2f), 0f, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(smokepos, direction.RotatedBy(-MathHelper.PiOver2) * 20f * scaleFactor + Owner.velocity, Color.OrangeRed, 7, scaleFactor * Main.rand.NextFloat(2f, 2.4f), Opacity * 2, 0f, true, 0.001f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + } + } + + if ((Empowerment + OverEmpowerment) % 30 == 29 && Owner.whoAmI == Main.myPlayer) + { + Vector2 shotDirection = Main.rand.NextVector2CircularEdge(15f, 15f); + Projectile.NewProjectile(Owner.Center, shotDirection, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.WhirlwindAttunement_BoltDamageReduction), 0f, Owner.whoAmI, 0.1f, MathHelper.Pi * 0.02f); + } + } + + + if (Empowerment / maxEmpowerment >= 0.75) + { + Color currentColor = Color.Chocolate * (((Empowerment / maxEmpowerment) - 0.75f) / 0.25f * 0.8f); + if (smear == null) + { + smear = new CircularSmearSmokeyVFX(Owner.Center, currentColor, 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.9f; + smear.Color = currentColor; + } + + float rotationAdjusted = MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi; + float mouseAngleAdjusted = MathHelper.WrapAngle(Owner.DirectionTo(Main.MouseWorld).ToRotation()) + MathHelper.Pi; + float deltaAngleShoot = Math.Abs(MathHelper.WrapAngle(rotationAdjusted - mouseAngleAdjusted)); + + if (CanDirectFire && deltaAngleShoot < 0.1f) + { + if (Owner.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(Owner.Center, Owner.DirectionTo(Main.MouseWorld) * 15f, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.WhirlwindAttunement_BoltDamageReduction), 0f, Owner.whoAmI, 0.1f, MathHelper.Pi * 0.02f); + } + CanDirectFire = false; + AngleReset = Owner.DirectionTo(Main.MouseWorld).ToRotation(); + } + + + if (Main.rand.NextBool()) + { + float maxDistance = projectile.scale * 1.9f * 78f; + Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); + Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(MathHelper.PiOver2)) * 2f * (1f + distance.Length() / 15f); + Particle glitter = new CritSpark(Owner.Center + distance, Owner.velocity + angularVelocity, Main.rand.Next(3) == 0 ? Color.Turquoise : Color.Coral, currentColor, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); + GeneralParticleHandler.SpawnParticle(glitter); + } + } + + + //Manage position and rotation + projectile.scale = 1 + Empowerment / maxEmpowerment * 1.5f; + + 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; + OverEmpowerment++; + } + } + + 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 * (OmegaBiomeBlade.WhirlwindAttunement_BaseDamageReduction + (OmegaBiomeBlade.WhirlwindAttunement_FullChargeDamageBoost * Empowerment / maxEmpowerment))); + } + + public override void Kill(int timeLeft) + { + if (smear != null) + smear.Kill(); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D sword = GetTexture("CalamityMod/Items/Weapons/Melee/GalaxiaExtra2"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, sword.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(sword, drawOffset, null, color * MathHelper.Lerp(0f, 0.5f, MathHelper.Clamp((Empowerment - maxEmpowerment * 0.4f) / (maxEmpowerment * 0.6f), 0f, 1f)), afterimageRotation, drawOrigin, projectile.scale - 0.2f * ((i / (float)projectile.oldRot.Length)), 0f, 0f); + } + } + + spriteBatch.Draw(sword, 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 + + //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(); + } + + 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(); + } + } + + + //Polaris's gaze aka Super Pogo attunement + + public class PolarissGaze : ModProjectile + { + public override string Texture => "CalamityMod/Items/Weapons/Melee/GalaxiaExtra"; //Red cuz close range yget the deal + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float Shred => ref projectile.ai[0]; //Charge, basically + public ref float HitChargeCooldown => ref projectile.ai[1]; + public float Bounce(float x) => x <= 50 ? x / 50f : x <= 65 ? 1 + 0.15f * (float)Math.Sin((x - 50f) / 15f * MathHelper.Pi) : 1f; + public float ShredRatio => MathHelper.Clamp(Shred / (maxShred * 0.5f), 0f, 1f); + public Player Owner => Main.player[projectile.owner]; + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + + public const float maxShred = 750; //How much shred you get + + public Projectile Wheel; + public bool Dashing; + public Vector2 DashStart; + + public Particle[] Rings = new Particle[3]; + public Particle PolarStar; + + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Polaris's Gaze"); + } + 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 = FourSeasonsGalaxia.SuperPogoAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 145 * projectile.scale; + float bladeWidth = 86 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center, Owner.Center + (direction * bladeLenght), bladeWidth, ref collisionPoint); + } + + public override void AI() + { + if (!initialized) //Initialization. + { + Main.PlaySound(SoundID.Item90, projectile.Center); + initialized = true; + + foreach(Projectile proj in Main.projectile) + { + if (proj.active && proj.type == ProjectileType() && proj.owner == Owner.whoAmI) + { + if (CalamityUtils.AngleBetween(Owner.Center - Main.MouseWorld, Owner.Center - proj.Center) > MathHelper.PiOver4) + { + proj.Kill(); + break; + } + + Wheel = proj; + Dashing = true; + DashStart = Owner.Center; + Wheel.timeLeft = 60; + Owner.GiveIFrames(FourSeasonsGalaxia.SuperPogoAttunement_SlashIFrames); + break; + } + } + } + + if (!OwnerCanShoot) + { + projectile.Kill(); + return; + } + + + #region sparkles and particles + + float bladeLenght = 120 * projectile.scale; + for (int i = 0; i < 3; i ++) + { + if (Rings[i] == null) + { + Rings[i] = new ConstellationRingVFX(Owner.Center + (direction * (25 + bladeLenght * 0.33f * i)), Color.DarkOrchid, direction.ToRotation(), projectile.scale * 0.25f * i, new Vector2(0.5f, 1f), spinSpeed: 7, starAmount: 3 + i, important : true) ; + GeneralParticleHandler.SpawnParticle(Rings[i]); + } + else + { + Rings[i].Time = 0; + Rings[i].Position = Owner.Center + Vector2.Lerp(Vector2.Zero, ((0.9f + 0.1f * (float)Math.Sin(Main.GlobalTime * 10f - i * 0.5f)) * direction * (25 + bladeLenght * 0.33f * (i + 1))), Bounce(MathHelper.Clamp(Shred - 30 * i, 0, maxShred))); + Rings[i].Rotation = direction.ToRotation(); + Rings[i].Scale = projectile.scale * 0.25f * (i + 1); + (Rings[i] as ConstellationRingVFX).Opacity = 0.5f + 0.5f * ShredRatio; + } + } + + if (PolarStar == null) + { + PolarStar = new GenericSparkle(Owner.Center + direction, Vector2.Zero, Color.White, Color.CornflowerBlue, projectile.scale, 2, 0.05f, 5f); + GeneralParticleHandler.SpawnParticle(PolarStar); + } + else + { + PolarStar.Time = 0; + PolarStar.Position = Owner.Center + direction * 46 * projectile.scale; + PolarStar.Rotation += (1 + (float)Math.Sin(Main.GlobalTime * 4f)) * 0.02f; + PolarStar.Scale = projectile.scale * 2f ; + } + + if (Main.rand.NextBool()) + { + Vector2 smokeSpeed = direction.RotatedByRandom(MathHelper.PiOver4 * 0.3f) * Main.rand.NextFloat(10f, 30f) * (ShredRatio * 0.5f + 1f); + Particle smoke = new HeavySmokeParticle(projectile.Center, smokeSpeed + Owner.velocity, Color.Lerp(Color.Purple, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(0.6f, 1.2f) * (ShredRatio * 0.5f + 1f), 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center, smokeSpeed + Owner.velocity, Main.hslToRgb(0.55f, 1, 0.5f + 0.2f * ShredRatio), 20, Main.rand.NextFloat(0.4f, 0.7f) * (ShredRatio * 0.5f + 1f), 0.8f, 0, true, 0.01f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + } + #endregion + + if (Shred >= maxShred) + Shred = maxShred; + if (Shred < 0) + Shred = 0; + + //Manage position and rotation + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + projectile.Center = Owner.Center + (direction * 60); + + //Scaling based on shred + projectile.localNPCHitCooldown = FourSeasonsGalaxia.SuperPogoAttunement_LocalIFrames - (int)(MathHelper.Lerp(0, FourSeasonsGalaxia.SuperPogoAttunement_LocalIFrames - FourSeasonsGalaxia.SuperPogoAttunement_LocalIFramesCharged, ShredRatio)); //Increase the hit frequency + projectile.scale = 1f + (ShredRatio * 1f); //SWAGGER + + + if ((Wheel == null || !Wheel.active) && Dashing) + { + Dashing = false; + Owner.velocity *= 0.1f; //Abrupt stop + Main.PlaySound(mod.GetLegacySoundSlot(Terraria.ModLoader.SoundType.Custom, "Sounds/Custom/MeatySlash"), projectile.Center); + + if (Owner.whoAmI == Main.myPlayer) + { + for (int i = 0; i < 5; i++) + { + Projectile blast = Projectile.NewProjectileDirect(Owner.Center, Main.rand.NextVector2CircularEdge(15, 15), ProjectileType(), (int)(FourSeasonsGalaxia.SuperPogoAttunement_SlashBoltsDamage * Owner.meleeDamage), 0f, Owner.whoAmI, 0.55f, MathHelper.Pi * 0.02f); + { + blast.timeLeft = 100; + } + } + + + Projectile proj = Projectile.NewProjectileDirect(Owner.Center - DashStart / 2f, Vector2.Zero, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.SuperPogoAttunement_SlashDamageBoost), 0, Owner.whoAmI); + if (proj.modProjectile is PolarissGazeDash dash) + { + dash.DashStart = DashStart; + dash.DashEnd = Owner.Center; + } + } + + } + + Owner.Calamity().LungingDown = false; + + if (Dashing) + { + Owner.Calamity().LungingDown = true; + Owner.fallStart = (int)(Owner.position.Y / 16f); + Owner.velocity = Owner.DirectionTo(Wheel.Center) * 60f; + + if (Owner.Distance(Wheel.Center) < 60f) + Wheel.active = false; + } + + //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; + + Shred += 1; + HitChargeCooldown--; + projectile.timeLeft = 2; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => ShredTarget(); + public override void OnHitPvp(Player target, int damage, bool crit) => ShredTarget(); + + private void ShredTarget() + { + if (Main.myPlayer != Owner.whoAmI) + return; + + Owner.fallStart = (int)(Owner.position.Y / 16f); + // get lifted up + if (HitChargeCooldown <= 0) + { + Main.PlaySound(SoundID.NPCHit30, projectile.Center); //Sizzle + Shred += 80; //Augment the shredspeed + if (Owner.velocity.Y > 0) + Owner.velocity.Y = -2f; //Get "stuck" into the enemy partly + Owner.GiveIFrames(FourSeasonsGalaxia.SuperPogoAttunement_ShredIFrames); // i framez. + HitChargeCooldown = 20; + } + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.NPCHit43, projectile.Center); + if (ShredRatio > 0.85 && Owner.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(projectile.Center, direction * 16f, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.SuperPogoAttunement_ShotDamageBoost) , projectile.knockBack, Owner.whoAmI, Shred); + } + Owner.Calamity().LungingDown = false; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D sword = GetTexture("CalamityMod/Items/Weapons/Melee/GalaxiaExtra"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, sword.Height); + Vector2 drawOffset = Owner.Center + direction * 10f - Main.screenPosition; + + spriteBatch.Draw(sword, drawOffset, null, lightColor, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + return false; + } + + 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 PolarissGazeStar : ModProjectile + { + public override string Texture => "CalamityMod/Particles/Sparkle"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float Shred => ref projectile.ai[0]; + public float ShredRatio => MathHelper.Clamp(Shred / (PolarissGaze.maxShred * 0.5f), 0f, 1f); + public Player Owner => Main.player[projectile.owner]; + + public float Timer => MaxTime - projectile.timeLeft; + + public const float MaxTime = 120; + + public Particle PolarStar; //Using a particle ontop of it since the smoke particles would otherwise go over it + + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Northern Star"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 45; + projectile.tileCollide = true; + projectile.ignoreWater = true; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 3; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + projectile.velocity *= 0.95f; + return false; + } + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 84 * projectile.scale; + float bladeWidth = 76 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center - direction * bladeLenght / 2, projectile.Center + direction * bladeLenght / 2, bladeWidth, ref collisionPoint); + } + + public override void AI() + { + if (!initialized) + { + Main.PlaySound(SoundID.Item90, projectile.Center); + initialized = true; + + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + + projectile.timeLeft = (int)MaxTime; + projectile.velocity = direction * 16f; + + projectile.scale = 1f + ShredRatio ; //SWAGGER + projectile.netUpdate = true; + + } + + projectile.velocity *= 0.96f; + projectile.position += projectile.velocity; + + + if (PolarStar == null) + { + PolarStar = new GenericSparkle(projectile.Center, Vector2.Zero, Color.White, Color.CornflowerBlue, projectile.scale * 2f, 2, 0.1f, 5f); + GeneralParticleHandler.SpawnParticle(PolarStar); + } + else + { + PolarStar.Time = 0; + PolarStar.Position = projectile.Center; + PolarStar.Scale = projectile.scale * 2f; + } + + + Vector2 smokeSpeed = Main.rand.NextVector2Circular(10f, 10f); + Particle smoke = new HeavySmokeParticle(projectile.Center, smokeSpeed + projectile.velocity / 2, Color.Lerp(Color.Purple, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(0.6f, 1.2f), 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center, smokeSpeed + projectile.velocity / 2, Main.hslToRgb(0.55f, 1, 0.5f), 20, Main.rand.NextFloat(0.4f, 0.7f), 0.8f, 0, true, 0.01f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + var tex = GetTexture("CalamityMod/Particles/Sparkle"); + float opacityFade = projectile.timeLeft > 15 ? 1 : projectile.timeLeft / 15f; + + spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.5f * opacityFade, Main.GlobalTime * 10f + MathHelper.PiOver4, tex.Size() / 2f, projectile.scale * 1.5f, 0f, 0f); + + spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f * opacityFade, Main.GlobalTime * 10f, tex.Size() / 2f, projectile.scale * 2f, 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) + { + Main.PlaySound(SoundID.Item60, projectile.Center); + 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.CornflowerBlue : Color.MediumSlateBlue, 0.4f + Main.rand.NextFloat(0f, 3.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + + Vector2 smokeSpeed = Main.rand.NextVector2Circular(20f, 20f); + Particle smoke = new HeavySmokeParticle(projectile.Center, smokeSpeed + projectile.velocity / 2, Color.Lerp(Color.DarkRed, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(1.5f, 2.2f), 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center, smokeSpeed + projectile.velocity / 2, Main.hslToRgb(0.55f, 1, 0.5f), 20, Main.rand.NextFloat(1.4f, 1.5f), 0.8f, 0, true, 0.01f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + } + } + + } + + public class PolarissGazeDash : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => 20 - projectile.timeLeft; + + public Vector2 DashStart; + public Vector2 DashEnd; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Shredding Lunge"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 8; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 60; + projectile.timeLeft = 20; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), DashStart, DashEnd); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + crit = true; + + Particle bloom = new StrongBloom(target.Center, target.velocity, Color.Crimson * 0.5f, 1f, 30); + GeneralParticleHandler.SpawnParticle(bloom); + + for (int i = 0; i < 3; i++) + { + Vector2 sparkSpeed = target.DirectionTo(Owner.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)) * 9f; + Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.CornflowerBlue, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.6f); + GeneralParticleHandler.SpawnParticle(Spark); + } + + //Explode into cosmic bolts + for (int i = 0; i < 3; i++) + { + Projectile blast = Projectile.NewProjectileDirect(Owner.Center, Owner.DirectionTo(target.Center).RotatedByRandom(MathHelper.PiOver4) * 30f, ProjectileType(), (int)(FourSeasonsGalaxia.SuperPogoAttunement_SlashBoltsDamage * Owner.meleeDamage), 0f, Owner.whoAmI, 0.55f, MathHelper.Pi * 0.01f); + { + blast.timeLeft = 100; + } + } + } + + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) //OMw to reuse way too much code from the entangling vines + { + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Texture2D lineTex = GetTexture("CalamityMod/Particles/ThinEndedLine"); + + Vector2 Shake = projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - projectile.timeLeft / 5f) * 0.5f; + float bump = (float)Math.Sin(((20f - projectile.timeLeft) / 20f) * MathHelper.Pi); + float raise = (float)Math.Sin(((20f - projectile.timeLeft) / 20f) * MathHelper.PiOver2); + + float rot = (DashEnd - DashStart).ToRotation() + MathHelper.PiOver2; + Vector2 origin = new Vector2(lineTex.Width / 2f, lineTex.Height); + Vector2 scale = new Vector2(0.2f, (DashEnd - DashStart).Length() / lineTex.Height); + + spriteBatch.Draw(lineTex, DashStart - Main.screenPosition + Shake, null, Color.Lerp(Color.White, Color.CornflowerBlue * 0.7f, raise), rot, origin, scale, SpriteEffects.None, 0); + + Texture2D sparkTexture = GetTexture("CalamityMod/Particles/ThinSparkle"); + Texture2D bloomTexture = GetTexture("CalamityMod/Particles/BloomCircle"); + //Ajust the bloom's texture to be the same size as the star's + float properBloomSize = (float)sparkTexture.Width / (float)bloomTexture.Height; + + + Rectangle frame = new Rectangle(0, 0, 14, 14); + + spriteBatch.Draw(bloomTexture, DashEnd - Main.screenPosition, null, Color.CornflowerBlue * bump * 0.5f, 0, bloomTexture.Size() / 2f, bump * 6f * properBloomSize, SpriteEffects.None, 0); + spriteBatch.Draw(sparkTexture, DashEnd - Main.screenPosition, frame, Color.Lerp(Color.White, Color.CornflowerBlue, raise) * bump, raise * MathHelper.TwoPi, frame.Size() / 2f, bump * 3f, SpriteEffects.None, 0); + + //Back to normal + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + return false; + } + } + + //Mercurial tides aka Shockwave attunement + + public class AndromedasStride : ModProjectile + { + public override string Texture => "CalamityMod/Items/Weapons/Melee/GalaxiaExtra"; + 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("Andromeda's Stride"); + } + 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 = 145 * projectile.scale; + float bladeWidth = 25 * 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) && Owner.whoAmI == Main.myPlayer) + { + //WOahhh do a ring of projectiles!! woahhh + for (int i = 0; i < 5; i++) + { + Projectile blast = Projectile.NewProjectileDirect(Owner.Center, (MathHelper.TwoPi * i / 5f).ToRotationVector2() * 10f, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.ShockwaveAttunement_BoltsDamageReduction), 0f, Owner.whoAmI, 0.75f, MathHelper.Pi * 0.02f); + { + blast.timeLeft = 30; + } + } + + Main.PlaySound(SoundID.Item79, projectile.Center); + CurrentIndicator++; + OverCharge = 20f; + } + + if (Charge >= MaxCharge) + { + Charge = MaxCharge; + + if (Main.rand.NextBool()) + { + Vector2 smokeSpeed = direction.RotatedByRandom(MathHelper.PiOver4 * 0.3f) * Main.rand.NextFloat(10f, 30f) * 0.9f; + Particle smoke = new HeavySmokeParticle(projectile.Center + direction * 50f, smokeSpeed + Owner.velocity, Color.Lerp(Color.Purple, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(0.6f, 1.2f), 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center + direction * 50f, smokeSpeed + Owner.velocity, Main.hslToRgb(0.85f, 1, 0.8f), 20, Main.rand.NextFloat(0.4f, 0.7f), 0.8f, 0, true, 0.01f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + } + + + if (Owner.whoAmI == Main.myPlayer && CurrentIndicator < 4f) + { + //Projectiles!!! wah!!! + for (int i = 0; i < 9; i++) + { + Projectile blast = Projectile.NewProjectileDirect(Owner.Center, (MathHelper.TwoPi * i / 9f).ToRotationVector2() * 10f, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.ShockwaveAttunement_BoltsDamageReduction), 0f, Owner.whoAmI, 0.75f, MathHelper.Pi * 0.02f); + { + blast.timeLeft = 50; + } + } + + 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; + Owner.Calamity().LungingDown = false; + 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) + return; + + if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < 15) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = 15; + + Projectile proj = Projectile.NewProjectileDirect(Owner.Center + (direction * 120 * projectile.scale), -direction * 16f, ProjectileType(), projectile.damage, 10f, Owner.whoAmI, 0.75f, MathHelper.Pi / 25f); + proj.scale = 3f; + proj.timeLeft = 50; + + + 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(), (int)(projectile.damage * FourSeasonsGalaxia.ShockwaveAttunement_MonolithDamageBoost), 10f, Owner.whoAmI, Main.rand.Next(4), projSize); + if (proj.modProjectile is AndromedasStrideBoltSpawner spawner) + { + spawner.WaitTimer = (1 - projSize) * 34f; + spawner.OriginDirection = direction; + spawner.Facing = facing; + } + } + + return validPositionFound; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + Owner.GiveIFrames(OmegaBiomeBlade.ShockwaveAttunement_DashHitIFrames); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + damage = (int)(damage * (1f + OmegaBiomeBlade.ShockwaveAttunement_FullChargeBoost * Charge / MaxCharge)); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D sword = GetTexture("CalamityMod/Items/Weapons/Melee/GalaxiaExtra"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, sword.Height); + Vector2 drawOffset = projectile.Center - Main.screenPosition; + + CalamityUtils.EnterShaderRegion(spriteBatch); + + if (OverCharge < 0) + OverCharge = 0f; + //When the blink is + GameShaders.Misc["CalamityMod:BasicTint"].UseOpacity(OverCharge / 20f); + GameShaders.Misc["CalamityMod:BasicTint"].UseColor(new Color(255, 129, 153)); + GameShaders.Misc["CalamityMod:BasicTint"].Apply(); + + spriteBatch.Draw(sword, drawOffset, null, lightColor, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + CalamityUtils.ExitShaderRegion(spriteBatch); + + 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 AndromedasStrideBoltSpawner : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public Player Owner => Main.player[projectile.owner]; + 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 override void SetStaticDefaults() + { + DisplayName.SetDefault("Andromeda Shock"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 70; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = 30; + projectile.hide = true; + } + + public override bool CanDamage() => false; + + public override void AI() + { + if (projectile.velocity != Vector2.Zero) + { + SurfaceUp(); + projectile.rotation = projectile.velocity.ToRotation(); + projectile.velocity = Vector2.Zero; + } + + if (WaitTimer > 0) + { + projectile.timeLeft = 30; + WaitTimer--; + } + + if (projectile.timeLeft == 29) + { + if (Size * 0.8 > 0.4 && Facing != 0) + SideSprouts(Facing, 150f, Size * 0.8f); + } + + if (projectile.timeLeft < 29) + { + if (Main.rand.Next(3) == 0) + { + Vector2 particleDirection = (projectile.rotation - MathHelper.PiOver4).ToRotationVector2(); + Vector2 flyDirection = particleDirection.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4 / 2f, MathHelper.PiOver4 / 2f)) * Main.rand.NextFloat(15f, 35f); + + Particle smoke = new HeavySmokeParticle(projectile.Center, flyDirection, Color.Lerp(Color.MidnightBlue, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(0.4f, 1.3f) * projectile.scale, 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center, flyDirection, Color.Red, 20, Main.rand.NextFloat(0.1f, 0.7f) * projectile.scale, 0.8f, 0, true, 0.01f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + + } + } + + if (projectile.timeLeft == 2) + { + //New bolt + if (Owner.whoAmI == Main.myPlayer) + { + Projectile proj = Projectile.NewProjectileDirect(projectile.position, projectile.rotation.ToRotationVector2() * 18f, ProjectileType(), projectile.damage, 10f, Owner.whoAmI, 0.75f, MathHelper.Pi / 25f); + proj.scale = Size * 3f; + proj.timeLeft = 50; + } + + 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 HeavySmokeParticle(projectile.Center + hitPositionDisplace, flyDirection, Color.Lerp(Color.MidnightBlue, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(1.6f, 2.2f) * projectile.scale, 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center + hitPositionDisplace, flyDirection, Color.Red, 20, Main.rand.NextFloat(1.4f, 1.7f) * projectile.scale, 0.8f, 0, true, 0.005f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + } + } + } + + //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, 10f, Owner.whoAmI, Main.rand.Next(4), projSize); + if (proj.modProjectile is AndromedasStrideBoltSpawner spawner) + { + spawner.WaitTimer = (float)Math.Sqrt(1.0 - Math.Pow(projSize - 1.0, 2)) * 3f; + spawner.OriginDirection = OriginDirection; + spawner.Facing = facing; + } + } + + return validPositionFound; + } + + 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(); + } + } + + //Aries's Wrath aka FlailBlade attunement + + public class AriessWrath : ModProjectile + { + private NPC[] excludedTargets = new NPC[4]; + public override string Texture => "CalamityMod/Items/Weapons/Melee/GalaxiaExtra2"; + public Player Owner => Main.player[projectile.owner]; + public ref float ChainSwapTimer => ref projectile.ai[0]; + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + + const float MaxProjReach = 500f; //How far away do you check for enemies for the extra projs from crits be + + public Particle smear; + public Projectile lastConstellation; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Aries's Wrath"); + + ProjectileID.Sets.TrailCacheLength[projectile.type] = 2; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 80; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = FourSeasonsGalaxia.FlailBladeAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + return Collision.CheckAABBvAABBCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center - Vector2.One * 50 * projectile.scale, Vector2.One * 100 * projectile.scale); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + for (int i = 0; i < 2; i++) + { + Vector2 sparkSpeed = Owner.DirectionTo(target.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver2, MathHelper.PiOver2)) * 9f; + Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.HotPink, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 1f); + GeneralParticleHandler.SpawnParticle(Spark); + } + + Vector2 sliceDirection = Main.rand.NextVector2CircularEdge(50f, 100f); + Particle SliceLine = new LineVFX(target.Center - sliceDirection, sliceDirection * 2f, 0.2f, Color.HotPink * 0.6f) + { + Lifetime = 6 + }; + GeneralParticleHandler.SpawnParticle(SliceLine); + + excludedTargets[0] = target; + for (int i = 0; i < 3; i++) + { + NPC potentialTarget = TargetNext(target.Center, i); + if (potentialTarget == null) + break; + Projectile proj = Projectile.NewProjectileDirect(target.Center, target.DirectionTo(potentialTarget.Center) * 25f, ProjectileType(), (int)(damage * FourSeasonsGalaxia.FlailBladeAttunement_OnHitBoltDamageReduction), 0, Owner.whoAmI, 0.9f, MathHelper.PiOver4 * 0.4f); + proj.scale = 2f; + } + Array.Clear(excludedTargets, 0, 3); + + } + + public NPC TargetNext(Vector2 hitFrom, int index) + { + float longestReach = MaxProjReach; + NPC target = null; + for (int i = 0; i < 200; ++i) + { + NPC npc = Main.npc[i]; + if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC) + { + float distance = Vector2.Distance(hitFrom, npc.Center); + if (distance < longestReach) + { + longestReach = distance; + target = npc; + } + } + } + if (index < 3) + excludedTargets[index + 1] = target; + return target; + } + + //Animation keys + public CurveSegment slowIn = new CurveSegment(EasingType.PolyIn, 0f, 0.2f, 1f, 3); + public CurveSegment bounce = new CurveSegment(EasingType.SineBump, 0.3f, 1f, 0.2f); + public CurveSegment remain = new CurveSegment(EasingType.SineBump, 0.6f, 1f, -0.1f); + internal float ThrowDisplace() => PiecewiseAnimation(MathHelper.Clamp(ChainSwapTimer / 40f, 0, 1), new CurveSegment[] { slowIn, bounce, remain }); + + //Animation keys + public CurveSegment scaleUp = new CurveSegment(EasingType.PolyIn, 0f, 0.2f, 1f, 3); + public CurveSegment scaleDown = new CurveSegment(EasingType.SineBump, 0.3f, 1f, 0.2f); + internal float ScaleEquation() => PiecewiseAnimation(MathHelper.Clamp(ChainSwapTimer / 30f, 0, 1), new CurveSegment[] { scaleUp, scaleDown}); + + + public override void AI() + { + if (!OwnerCanShoot) + { + if ((Owner.Center - projectile.Center).Length() < 30f) + projectile.Kill(); + + else + { + if (projectile.timeLeft <= 2) + { + projectile.velocity *= 10f; + } + if (projectile.velocity.AngleBetween(Owner.Center - projectile.Center) > MathHelper.PiOver4) + projectile.velocity = (projectile.velocity.ToRotation().AngleTowards(projectile.DirectionTo(Owner.Center).ToRotation(), MathHelper.Pi / 20f)).ToRotationVector2() * projectile.velocity.Length() * 0.98f; + else + projectile.velocity = (projectile.velocity.ToRotation().AngleTowards(projectile.DirectionTo(Owner.Center).ToRotation(), MathHelper.Pi)).ToRotationVector2() * projectile.velocity.Length() * 1.05f; + projectile.rotation = Main.GlobalTime * 25f; + projectile.scale = MathHelper.Clamp((Owner.Center - projectile.Center).Length() / (FourSeasonsGalaxia.FlailBladeAttunement_Reach * 0.5f) , 0.3f, 2f); + projectile.timeLeft = 4; + } + return; + } + + if (ChainSwapTimer == 0f) + { + projectile.Center = Owner.Center; + var scream = Main.PlaySound(SoundID.Item120, projectile.Center); + if (scream != null) + scream.Volume *= 0.5f; + + if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < 3) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = 3; + } + + projectile.scale = 1f + ScaleEquation(); + projectile.timeLeft = 2; + + projectile.Center = Vector2.Lerp(projectile.Center, Main.MouseWorld, 0.05f * ThrowDisplace()); + projectile.Center = projectile.Center.MoveTowards(Main.MouseWorld, 40f * ThrowDisplace()); + + if ((projectile.Center - Owner.Center).Length() > FourSeasonsGalaxia.FlailBladeAttunement_Reach) + projectile.Center = Owner.Center + Owner.DirectionTo(projectile.Center) * FourSeasonsGalaxia.FlailBladeAttunement_Reach; + + projectile.rotation = Main.GlobalTime * 25f; + //Make the owner look like theyre "holding" the sword bla bla + Owner.heldProj = projectile.whoAmI; + projectile.velocity = Owner.DirectionTo(projectile.Center); + Owner.direction = Math.Sign(projectile.velocity.X); + Owner.itemRotation = projectile.velocity.ToRotation(); + if (Owner.direction != 1) + { + Owner.itemRotation -= 3.14f; + } + Owner.itemRotation = MathHelper.WrapAngle(Owner.itemRotation); + Owner.itemTime = 2; + Owner.itemAnimation = 2; + + if (smear == null) + { + smear = new CircularSmearSmokeyVFX(projectile.Center, Color.MediumOrchid, projectile.rotation, projectile.scale); + GeneralParticleHandler.SpawnParticle(smear); + } + if (smear != null) + { + smear.Position = projectile.Center; + smear.Rotation = projectile.rotation + MathHelper.PiOver2 + MathHelper.PiOver4; + smear.Time = 0; + smear.Scale = projectile.scale; + smear.Color.A = (byte)(255 * MathHelper.Clamp(ChainSwapTimer / 50f, 0, 1)); + } + + if (Main.rand.NextBool()) + { + float maxDistance = projectile.scale * 82f; + Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); + Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(MathHelper.PiOver2)) * 2f * (1f + distance.Length() / 15f); + Particle glitter = new CritSpark(projectile.Center + distance, angularVelocity, Main.rand.Next(3) == 0 ? Color.HotPink : Color.Plum, Color.DarkOrchid, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); + GeneralParticleHandler.SpawnParticle(glitter); + } + + float smokeDistance = projectile.scale * 62f; + Vector2 smokePos = Main.rand.NextVector2Circular(smokeDistance, smokeDistance); + Vector2 smokeSpeed = Vector2.Normalize(smokePos.RotatedBy(MathHelper.PiOver2)) * 0.1f * (1f + smokePos.Length() / 15f); + Particle smoke = new HeavySmokeParticle(projectile.Center + smokePos, smokeSpeed, Color.Lerp(Color.Navy, Color.Indigo, (float)Math.Sin(Main.GlobalTime * 6f)), 30, Main.rand.NextFloat(0.4f, 1f) * projectile.scale, 0.8f, 0, false, 0, true); + GeneralParticleHandler.SpawnParticle(smoke); + + if (Main.rand.Next(3) == 0) + { + Particle smokeGlow = new HeavySmokeParticle(projectile.Center + smokePos, smokeSpeed, Main.hslToRgb(0.85f, 1, 0.5f), 20, Main.rand.NextFloat(0.4f, 1f) * projectile.scale, 0.8f, 0, true, 0.01f, true); + GeneralParticleHandler.SpawnParticle(smokeGlow); + } + + if (ChainSwapTimer % (20 - Math.Ceiling(14 * MathHelper.Clamp((projectile.position - projectile.oldPosition).Length() / 30f, 0, 1))) == 1 && Owner.whoAmI == Main.myPlayer) + { + if (lastConstellation != null && lastConstellation.active) + lastConstellation.Kill(); + + lastConstellation = Projectile.NewProjectileDirect(Owner.Center, Vector2.Zero, ProjectileType(), (int)(projectile.damage * FourSeasonsGalaxia.FlailBladeAttunement_ChainDamageReduction), 0, Owner.whoAmI); + if (lastConstellation.modProjectile is AriessWrathConstellation constellation) + { + constellation.SizeVector = projectile.Center - Owner.Center; + } + } + + ChainSwapTimer++; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D sword = GetTexture("CalamityMod/Items/Weapons/Melee/GalaxiaExtra2"); + + Vector2 drawPos = projectile.Center; + Vector2 drawOrigin = sword.Size() / 2f; + float drawRotation = projectile.rotation + MathHelper.PiOver4; + + spriteBatch.Draw(sword, drawPos - Main.screenPosition, null, lightColor, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + return false; + } + } + + public class AriessWrathConstellation : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => 20 - projectile.timeLeft; + + public Vector2 SizeVector; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Constellation"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 8; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 30; + projectile.timeLeft = 20; + } + + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center, projectile.Center + SizeVector, 30f, ref collisionPoint); + } + + public override void AI() + { + if (projectile.ai[0] == 0) + { + projectile.ai[0] = 1; + Vector2 previousStar = projectile.Center; + Vector2 offset; + Particle Line; + Particle Star = new GenericSparkle(previousStar, Vector2.Zero, Color.White, Color.Plum, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); + GeneralParticleHandler.SpawnParticle(Star); + + + for (float i = 0 + Main.rand.NextFloat(0.2f, 0.5f); i < 1; i += Main.rand.NextFloat(0.2f, 0.5f)) + { + offset = Main.rand.NextFloat(-50f, 50f) * Vector2.Normalize(SizeVector.RotatedBy(MathHelper.PiOver2)); + Star = new GenericSparkle(projectile.Center + SizeVector * i + offset, Vector2.Zero, Color.White, Color.Plum, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); + GeneralParticleHandler.SpawnParticle(Star); + + Line = new BloomLineVFX(previousStar, projectile.Center + SizeVector * i + offset - previousStar, 0.8f, Color.MediumVioletRed * 0.75f, 20, true, true); + GeneralParticleHandler.SpawnParticle(Line); + + if (Main.rand.Next(3) == 0) + { + offset = Main.rand.NextFloat(-50f, 50f) * Vector2.Normalize(SizeVector.RotatedBy(MathHelper.PiOver2)); + Star = new GenericSparkle(projectile.Center + SizeVector * i + offset, Vector2.Zero, Color.White, Color.Plum, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); + GeneralParticleHandler.SpawnParticle(Star); + + Line = new BloomLineVFX(previousStar, projectile.Center + SizeVector * i + offset - previousStar, 0.8f, Color.MediumVioletRed * 0.75f, 20, true, true); + GeneralParticleHandler.SpawnParticle(Line); + } + + previousStar = projectile.Center + SizeVector * i + offset; + } + + Star = new GenericSparkle(projectile.Center + SizeVector, Vector2.Zero, Color.White, Color.Plum, Main.rand.NextFloat(1f, 1.5f), 20, 0f, 3f); + GeneralParticleHandler.SpawnParticle(Star); + + Line = new BloomLineVFX(previousStar, projectile.Center + SizeVector - previousStar, 0.8f, Color.MediumVioletRed * 0.75f, 20, true); + GeneralParticleHandler.SpawnParticle(Line); + } + } + + + public override void SendExtraAI(BinaryWriter writer) + { + writer.WriteVector2(SizeVector); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + SizeVector = reader.ReadVector2(); + } + + } +} + + diff --git a/Projectiles/Melee/MendedBiomeBlade.png b/Projectiles/Melee/MendedBiomeBlade.png new file mode 100644 index 0000000000..b4d0142515 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade.png differ diff --git a/Projectiles/Melee/MendedBiomeBladeProjectiles.cs b/Projectiles/Melee/MendedBiomeBladeProjectiles.cs new file mode 100644 index 0000000000..1f16cf2fb6 --- /dev/null +++ b/Projectiles/Melee/MendedBiomeBladeProjectiles.cs @@ -0,0 +1,2630 @@ +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 TruePurityProjection : ModProjectile //The boring plain one. With cool homing now + { + 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("Purity 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 PurityProjectionSigil : ModProjectile + { + private NPC target => Main.npc[(int)projectile.ai[0]]; + + public Player Owner => Main.player[projectile.owner]; + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_PurityProjectionSigil"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Purity Sigil"); + ProjectileID.Sets.TrailCacheLength[projectile.type] = 2; + ProjectileID.Sets.TrailingMode[projectile.type] = 0; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 40; + projectile.friendly = false; + projectile.hostile = false; + projectile.penetrate = -1; + projectile.timeLeft = TrueBiomeBlade.DefaultAttunement_SigilTime; + projectile.melee = true; + projectile.tileCollide = false; + } + + public override Color? GetAlpha(Color lightColor) => Color.White; + + public override void AI() + { + + 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; + + if (target.active) + { + projectile.Center = target.Center; + } + else + projectile.active = false; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (Main.myPlayer != projectile.owner) // don't show for other players + return false; + DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); + return false; + } + } + + public class TrueDecaysRetort : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_DecaysRetort"; + private bool initialized = false; + public Vector2 direction = Vector2.Zero; + public ref float MaxTime => ref projectile.ai[0]; + public ref float CanLunge => ref projectile.ai[1]; + public float Timer => MaxTime - projectile.timeLeft; + public bool ChargedUp; + public Player Owner => Main.player[projectile.owner]; + public const float LungeSpeed = 16; + public ref float CanBounce => ref projectile.localAI[0]; + public ref float dashTimer => ref projectile.localAI[1]; + public const float maxDash = 20f; + + private Vector2 PowerLungeStart; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Decay's retort"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 84; + projectile.width = projectile.height = 84; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 1; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 140f * projectile.scale; + Vector2 displace = direction * ((float)Math.Sin(Timer / MaxTime * 3.14f) * 60); + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center + displace, Owner.Center + displace + (direction * bladeLenght), 24, ref collisionPoint); + } + + public override void AI() + { + if (!initialized) //Initialization + { + CanBounce = 1f; + projectile.timeLeft = (int)MaxTime; + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + if (CanLunge == 1f && !ChargedUp) + Lunge(); + Main.PlaySound(SoundID.Item103, projectile.Center); + initialized = true; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + if (ChargedUp && dashTimer == 0f) + PowerLunge(); + + if (dashTimer >= 1f) + { + if (dashTimer < maxDash) + { + Owner.fallStart = (int)(Owner.position.Y / 16f); + Owner.velocity = direction * 60f; + projectile.timeLeft = (int)(MaxTime / 2f); + dashTimer++; + } + + if (dashTimer == maxDash) + { + Owner.velocity *= 0.1f; //Abrupt stop + Owner.Calamity().LungingDown = false; + + Main.PlaySound(mod.GetLegacySoundSlot(Terraria.ModLoader.SoundType.Custom, "Sounds/Custom/SwiftSlice"), Owner.Center); + + if (Owner.whoAmI == Main.myPlayer) + { + Projectile proj = Projectile.NewProjectileDirect(Owner.Center - PowerLungeStart / 2f, Vector2.Zero, ProjectileType(), (int)(projectile.damage * TrueBiomeBlade.EvilAttunement_SlashDamageBoost), 0, Owner.whoAmI); + if (proj.modProjectile is DecaysRetortDash dash) + { + dash.DashStart = PowerLungeStart; + dash.DashEnd = Owner.Center; + } + } + dashTimer = maxDash + 1; + } + } + + //Manage position and rotation + projectile.scale = 1f + ((float)Math.Sin(Timer / MaxTime * MathHelper.Pi) * 0.6f); //SWAGGER + projectile.Center = Owner.Center + (direction * ((float)Math.Sin(Timer / MaxTime * MathHelper.Pi) * 60)); + + Lighting.AddLight(projectile.Center, new Vector3(0.9f, 0f, 0.35f) * (float)Math.Sin(Timer / MaxTime * MathHelper.Pi)); + + //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); + } + + public void Lunge() + { + if (Main.myPlayer != projectile.owner) + return; + Owner.velocity = direction.SafeNormalize(Vector2.UnitX * Owner.direction) * LungeSpeed; + } + + public void PowerLunge() + { + Owner.Calamity().LungingDown = true; + PowerLungeStart = Owner.Center; + dashTimer = 1f; + Owner.GiveIFrames(TrueBiomeBlade.EvilAttunement_SlashIFrames); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => OnHitEffects(!target.canGhostHeal || Main.player[projectile.owner].moonLeech); + public override void OnHitPvp(Player target, int damage, bool crit) => OnHitEffects(Main.player[projectile.owner].moonLeech); + + private void OnHitEffects(bool cannotLifesteal) + { + if (ChargedUp) + return; + + projectile.netUpdate = true; + projectile.netSpam = 0; + + if (!cannotLifesteal) //trolled + { + Owner.statLife += TrueBiomeBlade.EvilAttunement_Lifesteal; + Owner.HealEffect(TrueBiomeBlade.EvilAttunement_Lifesteal); //Idk if its too much or what but at the same time its close range as fuck + } + if (Main.myPlayer != Owner.whoAmI || CanBounce == 0f) + return; + // Bounce off + float bounceStrength = Math.Max((LungeSpeed / 2f), Owner.velocity.Length()); + bounceStrength *= Owner.velocity.Y == 0 ? 0.2f : 1f; //Reduce the bounce if the player is on the ground + Owner.velocity = -direction.SafeNormalize(Vector2.Zero) * MathHelper.Clamp(bounceStrength, 0f, 22f); + CanBounce = 0f; + Owner.GiveIFrames(TrueBiomeBlade.EvilAttunement_BounceIFrames); // i frames for free! + if (Owner.whoAmI == Main.myPlayer) + { + if (Owner.HeldItem.modItem is TrueBiomeBlade sword) + { + sword.PowerLungeCounter++; + if (sword.PowerLungeCounter == 3) + Main.PlaySound(SoundID.Item79); //indicate the charge with a sound effect + } + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade"); + Texture2D tex = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_DecaysRetort"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 displace = direction * ((float)Math.Sin(Timer / MaxTime * 3.14f) * 60); + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + direction * 10f - Main.screenPosition; + + spriteBatch.Draw(handle, drawOffset + displace, 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, tex.Height); + + spriteBatch.Draw(tex, drawOffset + displace, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.9f, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + if (dashTimer > 0f && dashTimer < maxDash) + { + float thrustRatio = (float)Math.Sin(dashTimer / maxDash * MathHelper.Pi); + spriteBatch.Draw(tex, drawOffset + displace, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.9f, drawRotation, drawOrigin, projectile.scale * (1 + thrustRatio * 0.2f), 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 SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + writer.Write(CanBounce); + writer.Write(ChargedUp); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + CanBounce = reader.ReadSingle(); + ChargedUp = reader.ReadBoolean(); + } + } + + public class DecaysRetortDash : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => 20 - projectile.timeLeft; + + public Vector2 DashStart; + public Vector2 DashEnd; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Evisceration Lunge"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 8; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 60; + projectile.timeLeft = 20; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), DashStart, DashEnd); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + for (int i = 0; i < 3; i++) + { + Vector2 sparkSpeed = target.DirectionTo(Owner.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)) * 9f; + Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.Crimson, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.6f); + GeneralParticleHandler.SpawnParticle(Spark); + } + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) //OMw to reuse way too much code from the entangling vines + { + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Texture2D chainTex = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash"); + + Vector2 Shake = projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - projectile.timeLeft / 5f) * 0.5f; + + Vector2 lineDirection = Vector2.Normalize(DashEnd - DashStart); + int dist = (int)Vector2.Distance(DashEnd, DashStart) / 16; + Vector2[] Nodes = new Vector2[dist + 1]; + Nodes[0] = DashStart; + Nodes[dist] = DashEnd; + + + for (int i = 1; i < dist + 1; i++) + { + Vector2 positionAlongLine = Vector2.Lerp(DashStart, DashEnd, i / (float)dist); //Get the position of the segment along the line + + Nodes[i] = positionAlongLine + Shake * (float)Math.Sin(i / (float)dist * MathHelper.PiOver2); + + 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]) / chainTex.Height; //Calculate how much to squash/stretch for smooth chain based on distance between points + float xScale = (i / (float)dist) * 5f; + Vector2 scale = new Vector2(xScale, yScale); + + float opacity = MathHelper.Clamp((float)Math.Sin(i / (float)dist * MathHelper.PiOver2) - (i / (float)dist * ((20f - projectile.timeLeft) / 25f)), 0f, 1f); + + Vector2 origin = new Vector2(chainTex.Width / 2, chainTex.Height); //Draw from center bottom of texture + spriteBatch.Draw(chainTex, Nodes[i] - Main.screenPosition, null, Color.Crimson * opacity, rotation, origin, scale, SpriteEffects.None, 0); + } + + Texture2D sparkTexture = GetTexture("CalamityMod/Particles/CritSpark"); + Texture2D bloomTexture = GetTexture("CalamityMod/Particles/BloomCircle"); + //Ajust the bloom's texture to be the same size as the star's + float properBloomSize = (float)sparkTexture.Width / (float)bloomTexture.Height; + + float bump = (float)Math.Sin(((20f - projectile.timeLeft) / 20f) * MathHelper.Pi); + float raise = (float)Math.Sin(((20f - projectile.timeLeft) / 20f) * MathHelper.PiOver2); + Rectangle frame = new Rectangle(0, 0, 14, 14); + + spriteBatch.Draw(bloomTexture, DashEnd - Main.screenPosition, null, Color.Crimson * bump * 0.5f, 0, bloomTexture.Size() / 2f, bump * 6f * properBloomSize, SpriteEffects.None, 0); + spriteBatch.Draw(sparkTexture, DashEnd - Main.screenPosition, frame, Color.Lerp(Color.White, Color.Crimson, raise) * bump, raise * MathHelper.TwoPi, frame.Size() / 2f, bump * 3f, SpriteEffects.None, 0); + + //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 class TrueBitingEmbrace : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_BitingEmbrace"; + + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public float rotation; + public ref float SwingMode => ref projectile.ai[0]; //0 = Up-Down small slash, 1 = Down-Up large slash, 2 = Thrust + public ref float MaxTime => ref projectile.ai[1]; + public float Timer => MaxTime - projectile.timeLeft; + + public int SwingDirection + { + get + { + switch (SwingMode) + { + case 0: + return -1 * Math.Sign(direction.X); + case 1: + return 1 * Math.Sign(direction.X); + default: + return 0; + + } + } + } + public float SwingWidth + { + get + { + switch (SwingMode) + { + case 0: + return 2.3f; + default: + return 1.8f; + } + } + } + + public Player Owner => Main.player[projectile.owner]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Biting Embrace"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 75; + projectile.width = projectile.height = 75; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 1; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + //The hitbox is simplified into a line collision. + float collisionPoint = 0f; + float bladeLenght = 0f; + Vector2 displace = Vector2.Zero; + switch (SwingMode) + { + case 0: + case 1: + bladeLenght = 150 * projectile.scale; + break; + case 2: + bladeLenght = 225f; //In awe e + bladeLenght *= projectile.scale; + displace = direction * ThrustDisplaceRatio() * 60f; + break; + + } + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center + displace, Owner.Center + displace + (rotation.ToRotationVector2() * bladeLenght), 26, ref collisionPoint); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + base.OnHitNPC(target, damage, knockback, crit); + if (SwingMode == 2) + target.AddBuff(BuffType(), 40); + } + + public override void AI() + { + if (!initialized) //Initialization + { + projectile.timeLeft = (int)MaxTime; + switch (SwingMode) + { + case 0: + projectile.width = projectile.height = 100; + Main.PlaySound(SoundID.DD2_MonkStaffSwing, projectile.Center); + break; + case 1: + projectile.width = projectile.height = 100; + projectile.width = projectile.height = 100; + Main.PlaySound(SoundID.DD2_OgreSpit, projectile.Center); + projectile.damage = (int)(projectile.damage * TrueBiomeBlade.ColdAttunement_SecondSwingBoost); + break; + case 2: + projectile.width = projectile.height = 170; + Main.PlaySound(SoundID.DD2_PhantomPhoenixShot, projectile.Center); + projectile.damage = (int)(projectile.damage * TrueBiomeBlade.ColdAttunement_ThirdSwingBoost); + break; + } + + //Take the direction the sword is swung. FUCK not controlling the swing direction more than just left/right :| + //The direction to mouseworld may need to be turned into the custom synced player mouse variables . not on the branch currently tho + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + + initialized = true; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + //Manage position and rotation + projectile.Center = Owner.Center + (direction * 30); + //rotation = projectile.rotation + MathHelper.SmoothStep(SwingWidth / 2 * SwingDirection, -SwingWidth / 2 * SwingDirection, Timer / MaxTime); + float factor = 1 - (float)Math.Pow((double)-(Timer / MaxTime) + 1, 2d); + rotation = projectile.rotation + MathHelper.Lerp(SwingWidth / 2 * SwingDirection, -SwingWidth / 2 * SwingDirection, factor); + projectile.scale = 1f + ((float)Math.Sin(Timer / MaxTime * MathHelper.Pi) * 0.6f); //SWAGGER + + Lighting.AddLight(Owner.MountedCenter, new Vector3(0.75f, 1f, 1f) * (float)Math.Sin(Timer / MaxTime * MathHelper.Pi)); + + //Add the thrust motion & animation for the third combo state + if (SwingMode == 2) + { + projectile.scale = 1f + (ThrustScaleRatio() * 0.3f); + projectile.Center = Owner.Center + (direction * ThrustDisplaceRatio() * 60); + + projectile.frameCounter++; + if (projectile.frameCounter % 5 == 0 && projectile.frame + 1 < Main.projFrames[projectile.type]) + projectile.frame++; + + if (Main.rand.NextBool() && Owner.whoAmI == Main.myPlayer) + { + Projectile mist = Projectile.NewProjectileDirect(Owner.Center + direction * 40 + Main.rand.NextVector2Circular(30f, 30f), Vector2.Zero, ProjectileType(), (int)(projectile.damage * TrueBiomeBlade.ColdAttunement_MistDamageReduction), 0f, Owner.whoAmI); + mist.velocity = (mist.Center - Owner.Center) * 0.2f + Owner.velocity; + } + + } + + else + { + if (Main.rand.NextFloat(0f, 1f) > 0.75f && Owner.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(Owner.Center + direction * 40, rotation.ToRotationVector2() * 5, ProjectileType(), (int)(projectile.damage * TrueBiomeBlade.ColdAttunement_MistDamageReduction), 0f, Owner.whoAmI); + + Vector2 particlePosition = Owner.Center + (rotation.ToRotationVector2() * 100f * projectile.scale); + Particle snowflake = new SnowflakeSparkle(particlePosition, rotation.ToRotationVector2() * 3f, Color.White, new Color(75, 177, 250), Main.rand.NextFloat(0.3f, 1.5f), 40, 0.5f); + GeneralParticleHandler.SpawnParticle(snowflake); + } + } + + //Make the owner look like theyre holding the sword bla bla + Owner.heldProj = projectile.whoAmI; + Owner.direction = Math.Sign(rotation.ToRotationVector2().X); + Owner.itemRotation = rotation; + if (Owner.direction != 1) + { + Owner.itemRotation -= 3.14f; + } + Owner.itemRotation = MathHelper.WrapAngle(Owner.itemRotation); + } + + //Animation keys + public CurveSegment anticipation = new CurveSegment(EasingType.SineBump, 0f, 0f, -0.15f); + public CurveSegment thrust = new CurveSegment(EasingType.PolyInOut, 0.2f, 0f, 0.9f, 3); + public CurveSegment hold = new CurveSegment(EasingType.SineBump, 0.35f, 0.9f, 0.1f); + public CurveSegment retract = new CurveSegment(EasingType.PolyInOut, 0.7f, 0.9f, -0.9f, 3); + internal float ThrustDisplaceRatio() => PiecewiseAnimation(Timer / MaxTime, new CurveSegment[] { anticipation, thrust, hold, retract }); + + //Animation keys + public CurveSegment expandSize = new CurveSegment(EasingType.ExpIn, 0f, 0f, 1f); + public CurveSegment holdSize = new CurveSegment(EasingType.Linear, 0.1f, 1f, 0f); + public CurveSegment shrinkSize = new CurveSegment(EasingType.ExpIn, 0.85f, 1f, -1f); + internal float ThrustScaleRatio() => PiecewiseAnimation(Timer / MaxTime, new CurveSegment[] { expandSize, holdSize, shrinkSize }); + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade"); + + if (SwingMode != 2) + { + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_BitingEmbrace"); + float drawAngle = rotation; + float drawRotation = rotation + MathHelper.PiOver4; + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + drawAngle.ToRotationVector2() * 10f - 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); + //Update the parameters + drawOrigin = new Vector2(0f, blade.Height); + spriteBatch.Draw(blade, drawOffset, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f, 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); + } + else + { + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_BitingEmbraceThrust"); + Vector2 thrustDisplace = direction * (ThrustDisplaceRatio() * 60); + + float drawAngle = rotation; + float drawRotation = rotation + MathHelper.PiOver4; + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + drawAngle.ToRotationVector2() * 10f - Main.screenPosition; + + spriteBatch.Draw(handle, drawOffset + thrustDisplace, 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); + //Anim stuff + + spriteBatch.Draw(blade, drawOffset + thrustDisplace, 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 SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + writer.Write(rotation); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + rotation = reader.ReadSingle(); + } + } + + public class BitingEmbraceMist : ModProjectile + { + public override string Texture => "CalamityMod/Particles/MediumMist"; + public Player Owner => Main.player[projectile.owner]; + public Color mistColor; + public int variant = -1; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Glacial Mist"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 34; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = 2; + projectile.timeLeft = 300; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + Vector2 size = projectile.Size * projectile.scale; + + return Collision.CheckAABBvAABBCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center - size / 2f, size); + } + + public override void AI() + { + if (variant == -1) + variant = Main.rand.Next(3); + + if (Main.rand.Next(15) == 0 && projectile.alpha <= 140) //only try to spawn your particles if you're not close to dying + { + Vector2 particlePosition = projectile.Center + Main.rand.NextVector2Circular(projectile.width * projectile.scale * 0.5f, projectile.height * projectile.scale * 0.5f); + Particle snowflake = new SnowflakeSparkle(particlePosition, Vector2.Zero, Color.White, new Color(75, 177, 250), Main.rand.NextFloat(0.3f, 1.5f), 40, 0.5f); + GeneralParticleHandler.SpawnParticle(snowflake); + } + + projectile.velocity *= 0.85f; + projectile.position += projectile.velocity; + projectile.rotation += 0.02f * projectile.timeLeft / 300f * ((projectile.velocity.X > 0) ? 1f : -1f); + + if (projectile.alpha < 165) + { + projectile.scale += 0.05f; + projectile.alpha += 2; + } + else + { + projectile.scale *= 0.975f; + projectile.alpha += 1; + } + if (projectile.alpha >= 170) + projectile.Kill(); + + mistColor = Color.Lerp(new Color(172, 238, 255), new Color(145, 170, 188), MathHelper.Clamp((float)(projectile.alpha - 100) / 80, 0f, 1f)) * (255 - projectile.alpha / 255f); + } + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, null, null, Main.GameViewMatrix.ZoomMatrix); + + var tex = GetTexture("CalamityMod/Particles/MediumMist"); + Rectangle frame = tex.Frame(1, 3, 0, variant); + spriteBatch.Draw(tex, projectile.position - Main.screenPosition, frame, mistColor * 0.5f * ((255f - projectile.alpha) / 255f), projectile.rotation, frame.Size() * 0.5f, projectile.scale, SpriteEffects.None, 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 class TrueAridGrandeur : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_AridGrandeur"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float Shred => ref projectile.ai[0]; //How much the attack is, attacking + public float ShredRatio => MathHelper.Clamp(Shred / (maxShred * 0.5f), 0f, 1f); + public ref float PogoCooldown => ref projectile.ai[1]; //Cooldown for the pogo + public ref float BounceTime => ref projectile.localAI[0]; + public Player Owner => Main.player[projectile.owner]; + public bool CanPogo => Owner.velocity.Y != 0 && PogoCooldown <= 0; //Only pogo when in the air and if the cooldown is zero + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + + public const float pogoStrenght = 16f; //How much the player gets pogoed up + public const float maxShred = 500; //How much shred you get + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Arid Grandeur"); + } + 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 = TrueBiomeBlade.HotAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 100 * projectile.scale; + float bladeWidth = 76 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center, Owner.Center + (direction * bladeLenght), bladeWidth, ref collisionPoint); + } + + public void Pogo() + { + if (CanPogo && Main.myPlayer == Owner.whoAmI) + { + Owner.velocity = -direction.SafeNormalize(Vector2.Zero) * pogoStrenght; //Bounce + Owner.fallStart = (int)(Owner.position.Y / 16f); + PogoCooldown = 30; //Cooldown + Main.PlaySound(SoundID.DD2_MonkStaffGroundImpact, projectile.position); + + Vector2 hitPosition = Owner.Center + (direction * 100 * projectile.scale); + BounceTime = 20f; //Used only for animation + + for (int i = 0; i < 8; i++) + { + Vector2 hitPositionDisplace = direction.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(-10f, 10f); + Vector2 flyDirection = -direction.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)); + Particle smoke = new SmallSmokeParticle(hitPosition + hitPositionDisplace, flyDirection * 9f, Color.OrangeRed, new Color(130, 130, 130), Main.rand.NextFloat(1.8f, 2.6f), 115 - Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(smoke); + + Particle Glow = new StrongBloom(hitPosition - hitPositionDisplace * 3, -direction * 6 * Main.rand.NextFloat(0.5f, 1f), Color.Orange * 0.5f, 0.01f + Main.rand.NextFloat(0f, 0.2f), 20 + Main.rand.Next(40)); + GeneralParticleHandler.SpawnParticle(Glow); + } + for (int i = 0; i < 3; i++) + { + Vector2 hitPositionDisplace = direction.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(-10f, 10f); + Vector2 flyDirection = -direction.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)); + + Particle Rock = new StoneDebrisParticle(hitPosition - hitPositionDisplace * 3, flyDirection * Main.rand.NextFloat(3f, 6f), Color.Beige, 1f + Main.rand.NextFloat(0f, 0.4f), 30 + Main.rand.Next(50), 0.1f); + GeneralParticleHandler.SpawnParticle(Rock); + } + + if (Owner.HeldItem.type == ItemType()) + (Owner.HeldItem.modItem as TrueBiomeBlade).StoredLunges = 2; // Reset the lunge counter on pogo. This should make for more interesting and fun synergies + } + } + + public override void AI() + { + if (!initialized) //Initialization. Here its litterally just playing a sound tho lmfao + { + Main.PlaySound(SoundID.Item90, projectile.Center); + initialized = true; + } + + if (!OwnerCanShoot) + { + projectile.Kill(); + return; + } + + if (Shred >= maxShred) + Shred = maxShred; + if (Shred < 0) + Shred = 0; + + Lighting.AddLight(projectile.Center, new Vector3(1f, 0.56f, 0.56f) * ShredRatio); + + //Manage position and rotation + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + projectile.Center = Owner.Center + (direction * 60); + + //Scaling based on shred + projectile.localNPCHitCooldown = TrueBiomeBlade.HotAttunement_LocalIFrames - (int)(MathHelper.Lerp(0, TrueBiomeBlade.HotAttunement_LocalIFrames - TrueBiomeBlade.HotAttunement_LocalIFramesCharged, ShredRatio)); //Increase the hit frequency + projectile.scale = 1f + (ShredRatio * 1f); //SWAGGER + + + if (Collision.SolidCollision(Owner.Center + (direction * 100 * projectile.scale) - Vector2.One * 5f, 10, 10)) + { + Pogo(); + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + //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; + + Shred--; + PogoCooldown--; + BounceTime--; + projectile.timeLeft = 2; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => ShredTarget(); + public override void OnHitPvp(Player target, int damage, bool crit) => ShredTarget(); + + private void ShredTarget() + { + if (Main.myPlayer != Owner.whoAmI) + return; + // get lifted up + if (PogoCooldown <= 0) + { + Main.PlaySound(SoundID.NPCHit30, projectile.Center); //Sizzle + Shred += 62; //Augment the shredspeed + if (Owner.velocity.Y > 0) + Owner.velocity.Y = -2f; //Get "stuck" into the enemy partly + Owner.GiveIFrames(TrueBiomeBlade.HotAttunement_ShredIFrames); // i framez. Do 5 iframes even matter? idk but you get a lot of em so lol... + PogoCooldown = 20; + } + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.NPCHit43, projectile.Center); + if (ShredRatio > 0.5 && Owner.whoAmI == Main.myPlayer) //Keep this for the True biome blade/Repaired biome blade. + { + Projectile.NewProjectile(projectile.Center, direction * 16f, ProjectileType(), (int)(projectile.damage * TrueBiomeBlade.HotAttunement_ShotDamageBoost), projectile.knockBack, Owner.whoAmI, Shred); + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_AridGrandeur"); + + int bladeAmount = 4; + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + direction * 10f - 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); + //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); + + + for (int i = 0; i < bladeAmount; i++) //Draw extra copies + { + blade = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_AridGrandeurExtra"); + + drawAngle = direction.ToRotation(); + + float circleCompletion = (float)Math.Sin(Main.GlobalTime * 5 + i * MathHelper.PiOver2); + drawRotation = drawAngle + MathHelper.PiOver4 + (circleCompletion * MathHelper.Pi / 10f) - (circleCompletion * (MathHelper.Pi / 9f) * ShredRatio); + + drawOrigin = new Vector2(0f, blade.Height); + + Vector2 drawOffsetStraight = Owner.Center + direction * (float)Math.Sin(Main.GlobalTime * 7) * 10 - Main.screenPosition; //How far from the player + Vector2 drawDisplacementAngle = direction.RotatedBy(MathHelper.PiOver2) * circleCompletion.ToRotationVector2().Y * (20 + 40 * ShredRatio); //How far perpendicularly + Vector2 drawOffsetFromBounce = direction * MathHelper.Clamp(BounceTime, 0f, 20f) / 20f * 20f; + + spriteBatch.Draw(blade, drawOffsetStraight + drawDisplacementAngle + drawOffsetFromBounce, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f, 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 SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + } + } + + public class TrueAridGrandeurShot : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_AridGrandeurExtra"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float Shred => ref projectile.ai[0]; + public float ShredRatio => MathHelper.Clamp(Shred / (TrueAridGrandeur.maxShred * 0.5f), 0f, 1f); + public Player Owner => Main.player[projectile.owner]; + + public const float pogoStrenght = 16f; //How much the player gets pogoed up + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Arid Shredder"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 70; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 1; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 84 * projectile.scale; + float bladeWidth = 76 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center - direction * bladeLenght / 2, projectile.Center + direction * bladeLenght / 2, bladeWidth, ref collisionPoint); + } + + public override void AI() + { + if (!initialized) + { + Main.PlaySound(SoundID.Item90, projectile.Center); + projectile.timeLeft = (int)(30f + ShredRatio * 30f); + initialized = true; + + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + + projectile.velocity = direction * 6f; + + projectile.scale = 1f + ShredRatio ; //SWAGGER + projectile.netUpdate = true; + + } + + projectile.position += projectile.velocity; + + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + for (int i = 0; i < 4; i++) //Draw extra copies + { + var tex = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_AridGrandeurExtra"); + + float drawAngle = direction.ToRotation(); + + float circleCompletion = (float)Math.Sin(Main.GlobalTime * 5 + i * MathHelper.PiOver2); + float drawRotation = drawAngle + MathHelper.PiOver4 + (circleCompletion * MathHelper.Pi / 10f) - (circleCompletion * (MathHelper.Pi / 9f) * ShredRatio); + + Vector2 drawOrigin = new Vector2(0f, tex.Height); + + + Vector2 drawOffsetStraight = projectile.Center + direction * (float)Math.Sin(Main.GlobalTime * 7) * 10 - Main.screenPosition; //How far from the player + Vector2 drawDisplacementAngle = direction.RotatedBy(MathHelper.PiOver2) * circleCompletion.ToRotationVector2().Y * (20 + 40 * ShredRatio); //How far perpendicularly + + float opacityFade = projectile.timeLeft > 15 ? 1 : projectile.timeLeft / 15f; + + spriteBatch.Draw(tex, drawOffsetStraight + drawDisplacementAngle, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f * opacityFade, 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) + { + Main.PlaySound(SoundID.Item60, projectile.Center); + for (int i = 0; i < 4; i++) //Particel + { + float drawAngle = direction.ToRotation(); + + float circleCompletion = (float)Math.Sin(Main.GlobalTime * 5 + i * MathHelper.PiOver2); + float drawRotation = drawAngle + MathHelper.PiOver4 + (circleCompletion * MathHelper.Pi / 10f) - (circleCompletion * (MathHelper.Pi / 9f) * ShredRatio); + + + Vector2 drawOffsetStraight = projectile.Center + direction * (float)Math.Sin(Main.GlobalTime * 7) * 10; //How far from the player + Vector2 drawDisplacementAngle = direction.RotatedBy(MathHelper.PiOver2) * circleCompletion.ToRotationVector2().Y * (20 + 40 * ShredRatio); //How far perpendicularly + + for (int j = 0; j < 4; j++) + { + Particle Sparkle = new GenericSparkle(drawOffsetStraight + (drawRotation - MathHelper.PiOver4).ToRotationVector2() * (60 + j * 50f) + drawDisplacementAngle, direction * projectile.velocity.Length() * Main.rand.NextFloat(0.9f, 1.1f), Color.Lerp(Color.Cyan, Color.Orange, (j + 1) / 4f), Color.OrangeRed, 0.5f + Main.rand.NextFloat(-0.2f, 0.2f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + } + + } + + } + + public class TrueGrovetendersTouch : ModProjectile + { + private NPC[] excludedTargets = new NPC[4]; + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchBlade"; + private bool initialized = false; + public Player Owner => Main.player[projectile.owner]; + public float Timer => MaxTime - projectile.timeLeft; + public ref float HasSnapped => ref projectile.ai[0]; + public ref float SnapCoyoteTime => ref projectile.ai[1]; + + public float flipped; + + const float MaxTime = 90; + const int coyoteTimeFrames = 15; //How many frames does the whip stay extended + const int MaxReach = 400; + const float SnappingPoint = 0.55f; //When does the snap occur. + const float ReelBackStrenght = 14f; + + const float MaxTangleReach = 400f; //How long can tangling vines from crits be + + public BezierCurve curve; + private Vector2 controlPoint1; + private Vector2 controlPoint2; + internal bool ReelingBack => Timer / MaxTime > SnappingPoint; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Grovetender's Touch"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 80; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = TrueBiomeBlade.TropicalAttunement_LocalIFrames; + } + + public override bool? CanCutTiles() => false; //Itd be quite counterproductive to make the whip cut the tiles it just grew + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + BezierCurve curve = new BezierCurve(new Vector2[] { Owner.MountedCenter, controlPoint1, controlPoint2, projectile.Center }); + + int numPoints = 32; + Vector2[] chainPositions = curve.GetPoints(numPoints).ToArray(); + float collisionPoint = 0; + for (int i = 1; i < numPoints; i++) + { + Vector2 position = chainPositions[i]; + Vector2 previousPosition = chainPositions[i - 1]; + if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), position, previousPosition, 6, ref collisionPoint)) + return true; + if (i == numPoints - 1) //Extra lenght collision for the blade itself + { + Vector2 projectileHalfLenght = 85 * projectile.rotation.ToRotationVector2(); + return (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center - projectileHalfLenght, projectile.Center + projectileHalfLenght, 32, ref collisionPoint)); + } + + } + + return base.Colliding(projHitbox, targetHitbox); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + Vector2 projectileHalfLenght = 85f * projectile.rotation.ToRotationVector2(); + float collisionPoint = 0; + //If you hit the enemy during the coyote time with the blade of the whip, guarantee a crit + if (Collision.CheckAABBvLineCollision(target.Hitbox.TopLeft(), target.Hitbox.Size(), projectile.Center - projectileHalfLenght, projectile.Center + projectileHalfLenght, 32, ref collisionPoint)) + { + if (SnapCoyoteTime > 0f) + { + crit = true; + for (int i = 0; i < 4; i++) + { + Vector2 sparkSpeed = Owner.DirectionTo(target.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver2, MathHelper.PiOver2)) * 9f; + Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.LimeGreen, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.6f); + GeneralParticleHandler.SpawnParticle(Spark); + } + + } + } + else + damage = (int)(damage * TrueBiomeBlade.TropicalAttunement_ChainDamageReduction); //If the enemy is hit with the chain of the whip, the damage gets reduced + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (crit) + { + bool boing = false; + excludedTargets[0] = target; + for (int i = 0; i < 3; i++) + { + NPC potentialTarget = TargetNext(target.Center, i); + if (potentialTarget == null) + break; + if (!boing) + { + boing = true; + Main.PlaySound(SoundID.Item56); + } + Projectile.NewProjectile(target.Center, Vector2.Zero, ProjectileType(), (int)(damage * TrueBiomeBlade.TropicalAttunement_VineDamageReduction), 0, Owner.whoAmI, target.whoAmI, potentialTarget.whoAmI); + } + Array.Clear(excludedTargets, 0, 3); + } + } + + public NPC TargetNext(Vector2 hitFrom, int index) + { + float longestReach = MaxTangleReach; + NPC target = null; + for (int i = 0; i < 200; ++i) + { + NPC npc = Main.npc[i]; + if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC) + { + float distance = Vector2.Distance(hitFrom, npc.Center); + if (distance < longestReach) + { + longestReach = distance; + target = npc; + } + } + } + if (index < 3) + excludedTargets[index + 1] = target; + return target; + } + + public override void AI() + { + if (!initialized) //Initialization. create control points & shit) + { + projectile.velocity = Owner.DirectionTo(Main.MouseWorld); + Main.PlaySound(SoundID.DD2_OgreSpit, projectile.Center); + controlPoint1 = projectile.Center; + controlPoint2 = projectile.Center; + projectile.timeLeft = (int)MaxTime; + initialized = true; + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + if (ReelingBack && HasSnapped == 0f) //Snap & also small coyote time for the hook + { + Main.PlaySound(SoundID.Item41, projectile.Center); //Snap + HasSnapped = 1f; + SnapCoyoteTime = coyoteTimeFrames; + } + + if (SnapCoyoteTime > 0) //keep checking for the tile hook + { + Lighting.AddLight(projectile.Center, 0.8f, 1f, 0.35f); + HookToTile(); + SnapCoyoteTime--; + } + + Owner.direction = Math.Sign(projectile.velocity.X); + projectile.rotation = projectile.AngleFrom(Owner.Center); //Point away from playah + + float ratio = GetSwingRatio(); + projectile.Center = Owner.MountedCenter + SwingPosition(ratio); + projectile.direction = projectile.spriteDirection = -Owner.direction * (int)flipped; + + //MessWithTiles(); + + Owner.itemRotation = MathHelper.WrapAngle(Owner.AngleTo(Main.MouseWorld) - (Owner.direction < 0 ? MathHelper.Pi : 0)); + } + public void HookToTile() + { + if (Main.myPlayer == Owner.whoAmI) + { + //Shmoove the player if a tile is hit. This movement always happens if the owner isnt on the ground, but will only happen if the projectile is above the player if they are standing on the ground) + if (Collision.SolidCollision(projectile.position, 32, 32) && (Owner.velocity.Y != 0 || projectile.position.Y < Owner.position.Y)) + { + Owner.velocity = Owner.DirectionTo(projectile.Center) * ReelBackStrenght; + SnapCoyoteTime = 0f; + } + Main.PlaySound(SoundID.Item65, projectile.position); + } + } + + internal float EaseInFunction(float progress) => progress == 0 ? 0f : (float)Math.Pow(2, 10 * progress - 10); //Potion seller i need your strongest easeIns + + private float GetSwingRatio() + { + float ratio = (Timer - SnappingPoint * MaxTime) / (MaxTime * (1 - SnappingPoint)); //The ratio for the last section of the snap is a new curve. + if (!ReelingBack) + ratio = EaseInFunction(Timer / (MaxTime * SnappingPoint)); //Watch this ratio get eased + if (SnapCoyoteTime > 0) + ratio = 0f; + return ratio; + } + + private Vector2 SwingPosition(float progress) + { + //Whip windup and snap part + if (!ReelingBack) + { + float distance = MaxReach * MathHelper.Lerp((float)Math.Sin(progress * MathHelper.PiOver2), 1, 0.04f); //half arc + distance = Math.Max(distance, 65); //Dont be too close to player + + float angleDeviation = MathHelper.Pi / 1.2f; + float angleOffset = Owner.direction * flipped * MathHelper.Lerp(-angleDeviation, 0, progress); //Go from very angled to straight at the zenith of the attack + if (flipped == -1) + distance *= MathHelper.Lerp(0.1f, 0.3f, (float)Math.Sin(progress * MathHelper.Pi)); + return projectile.velocity.RotatedBy(angleOffset) * distance; + } + else + { + float distance = MathHelper.Lerp(MaxReach, 0f, progress); //Quickly zip back to the player . No angles or minimum distance from player. + return projectile.velocity * distance; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (Timer == 0) + return false; + Texture2D handle = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchGlow"); + + Vector2 projBottom = projectile.Center + new Vector2(-handle.Width / 2, handle.Height / 2).RotatedBy(projectile.rotation + MathHelper.PiOver4) * 0.75f; + DrawChain(spriteBatch, projBottom, out Vector2[] chainPositions); + + float drawRotation = (projBottom - chainPositions[chainPositions.Length - 2]).ToRotation() + MathHelper.PiOver4; //Face away from the last point of the bezier curve + drawRotation += SnapCoyoteTime > 0 ? MathHelper.Pi : 0; //During coyote time the blade flips for some reason. Prevent that from happening + drawRotation += projectile.spriteDirection < 0 ? 0f : 0f; + + if (ReelingBack) + drawRotation = Utils.AngleLerp(drawRotation, (projectile.Center - Owner.Center).ToRotation(), GetSwingRatio()); + + Vector2 drawOrigin = new Vector2(0f, handle.Height); + SpriteEffects flip = (projectile.spriteDirection < 0) ? SpriteEffects.None : SpriteEffects.None; + lightColor = Lighting.GetColor((int)(projectile.Center.X / 16f), (int)(projectile.Center.Y / 16f)); + + Vector2 nitpickCorrection = (flipped == -1 && (Timer / MaxTime < 0.35f)) ? drawRotation.ToRotationVector2() * 16f + (Owner.direction == -1f ? Vector2.UnitX * -12f : Vector2.Zero) : Vector2.Zero; + + spriteBatch.Draw(handle, projBottom - nitpickCorrection - Main.screenPosition, null, lightColor, drawRotation, drawOrigin, projectile.scale, flip, 0f); + + if ((!ReelingBack || SnapCoyoteTime != 0f) && (Timer / MaxTime > 0.35f)) + { + //Turn on additive blending + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + //Only update the origin for once + drawOrigin = new Vector2(0f, blade.Height); + spriteBatch.Draw(blade, projBottom - nitpickCorrection - Main.screenPosition, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.9f, drawRotation, drawOrigin, projectile.scale, flip, 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; + } + + private void DrawChain(SpriteBatch spriteBatch, Vector2 projBottom, out Vector2[] chainPositions) + { + Texture2D chainTex = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchChain"); + + float ratio = GetSwingRatio(); + + if (!ReelingBack) //Make the curve be formed from points slightly ahead of the projectile, but clamped to the max rotation (straight line ahead) + { + controlPoint1 = Owner.MountedCenter + SwingPosition(MathHelper.Clamp(ratio + 0.5f, 0f, 1f)) * 0.2f; + controlPoint2 = Owner.MountedCenter + SwingPosition(MathHelper.Clamp(ratio + 0.2f, 0f, 1f)) * 0.5f; + } + else //After the whip snaps, make the curve be a wave + { + Vector2 perpendicular = SwingPosition(ratio).SafeNormalize(Vector2.Zero).RotatedBy(MathHelper.PiOver2); + controlPoint1 = Owner.MountedCenter + SwingPosition(MathHelper.Lerp(ratio, 1f, ratio)) + perpendicular * MathHelper.SmoothStep(0f, 1f, ratio) * 155f * Owner.direction; + controlPoint2 = Owner.MountedCenter + SwingPosition(MathHelper.Lerp(ratio, 1f, ratio / 2)) + perpendicular * MathHelper.SmoothStep(0f, 1f, ratio) * -100f * Owner.direction; + } + + BezierCurve curve = new BezierCurve(new Vector2[] { Owner.MountedCenter, controlPoint1, controlPoint2, projBottom }); + int numPoints = 30; + chainPositions = curve.GetPoints(numPoints).ToArray(); + + //Draw each chain segment bar the very first one + for (int i = 1; i < numPoints; i++) + { + Vector2 position = chainPositions[i]; + float rotation = (chainPositions[i] - chainPositions[i - 1]).ToRotation() - MathHelper.PiOver2; //Calculate rotation based on direction from last point + float yScale = Vector2.Distance(chainPositions[i], chainPositions[i - 1]) / chainTex.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)position.X / 16, (int)position.Y / 16); //Lighting of the position of the chain segment + if (ReelingBack) + chainLightColor *= 1 - EaseInFunction(ratio); //Make the chain fade when reeling it back + Vector2 origin = new Vector2(chainTex.Width / 2, chainTex.Height); //Draw from center bottom of texture + spriteBatch.Draw(chainTex, position - Main.screenPosition, null, chainLightColor, rotation, origin, scale, SpriteEffects.None, 0); + } + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + } + } + + public class GrovetendersEntanglingVines : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchChain"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => 20 - projectile.timeLeft; + public NPC NPCfrom + { + get => Main.npc[(int)projectile.ai[0]]; + set => projectile.ai[0] = value.whoAmI; + } + public NPC Target + { + get => Main.npc[(int)projectile.ai[1]]; + set => projectile.ai[1] = value.whoAmI; + } + + const float curvature = 16f; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Entangling Growth"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 8; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 30; + projectile.timeLeft = 20; + } + + public override bool? CanHitNPC(NPC target) => target == Target; + + public override void AI() + { + projectile.Center = Target.Center; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D chainTex = GetTexture("CalamityMod/Projectiles/Melee/BrokenBiomeBlade_GrovetendersTouchChain"); + + float opacity = projectile.timeLeft > 10 ? 1 : projectile.timeLeft / 10f; + Vector2 Shake = projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - projectile.timeLeft / 5f) * 0.5f; + + Vector2 lineDirection = Vector2.Normalize(Target.Center - NPCfrom.Center); + int dist = (int)Vector2.Distance(Target.Center, NPCfrom.Center) / 16; + Vector2[] Nodes = new Vector2[dist + 1]; + Nodes[0] = NPCfrom.Center; + Nodes[dist] = Target.Center; + float pointUp = Target.Center.X > NPCfrom.Center.X ? -MathHelper.PiOver2 : MathHelper.PiOver2; + + for (int i = 1; i < dist + 1; i++) + { + Vector2 positionAlongLine = Vector2.Lerp(NPCfrom.Center, Target.Center, i / (float)dist); //Get the position of the segment along the line, as if it were a flat line + float elevation = (float)Math.Sin(i / (float)dist * MathHelper.Pi) * curvature * dist / 10f; + Nodes[i] = positionAlongLine + lineDirection.RotatedBy(pointUp) * elevation + 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]) / chainTex.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(chainTex.Width / 2, chainTex.Height); //Draw from center bottom of texture + spriteBatch.Draw(chainTex, Nodes[i] - Main.screenPosition, null, chainLightColor * opacity, rotation, origin, scale, SpriteEffects.None, 0); + } + return false; + } + + } + + public class HeavensMight : 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; + 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 = TrueBiomeBlade.HolyAttunement_LocalIFrames; + } + + 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 * (TrueBiomeBlade.HolyAttunement_BaseDamageReduction + (TrueBiomeBlade.HolyAttunement_FullChargeDamageBoost * 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 TheirAbhorrence : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrence"; + 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("Their Abhorrence"); + } + 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)) + { + Main.PlaySound(SoundID.DD2_WitherBeastAuraPulse, projectile.Center); + CurrentIndicator++; + OverCharge = 20f; + } + + if (Charge >= MaxCharge) + { + Charge = MaxCharge; + if (Owner.whoAmI == Main.myPlayer && CurrentIndicator < 4f) + { + 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; + Owner.Calamity().LungingDown = false; + 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; + + //Only create the central monolith if over half charge + if (Charge / MaxCharge < 0.5f) + return; + Projectile.NewProjectile(Owner.Center + (direction * 120 * projectile.scale), -direction, ProjectileType(), (int)(projectile.damage * TrueBiomeBlade.AstralAttunement_MonolithDamageBoost), 10f, Owner.whoAmI, Main.rand.Next(4), 1f); + + //Only create the side monoliths if over 3/4th charge + if (Charge / MaxCharge < 0.75f) + return; + + if (SideSprouts(1, 150f, 0.8f) && Charge >= MaxCharge) + SideSprouts(1, 250f, 0.5f); + + if (SideSprouts(-1, 150f, 0.8f) && Charge >= MaxCharge) + SideSprouts(-1, 250f, 0.5f); + + } + + 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(), (int)(projectile.damage * TrueBiomeBlade.AstralAttunement_MonolithDamageBoost), 10f, Owner.whoAmI, Main.rand.Next(4), projSize); + if (proj.modProjectile is TheirAbhorrenceMonolith monolith) + monolith.WaitTimer = (1 - projSize) * 34f; + } + + return validPositionFound; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + Owner.GiveIFrames(TrueBiomeBlade.AstralAttunement_DashHitIFrames); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + damage = (int)(damage * (1f + TrueBiomeBlade.AstralAttunement_FullChargeBoost * Charge / MaxCharge)); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrence"); + + 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 TheirAbhorrenceMonolith : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith"; + 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 till it appears fr. GOtta remember to sync that one + 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("Their Abhorrence"); + } + 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 (WaitTimer > 0) + { + projectile.timeLeft = 102; + WaitTimer--; + } + + if (projectile.timeLeft == 100) + { + SurfaceUp(); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + projectile.velocity = Vector2.Zero; + + 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 (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 override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (WaitTimer > 0) + return false; + + Texture2D tex = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith"); + + 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, 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); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + WaitTimer = reader.ReadSingle(); + } + + } + + public class GestureForTheDrowned : ModProjectile + { + public override string Texture => "CalamityMod/Items/Weapons/Melee/TrueBiomeBlade"; + Vector2 direction = Vector2.Zero; + public Player Owner => Main.player[projectile.owner]; + public float Timer => 40 - projectile.timeLeft; + public float HalfTimer => (Timer % 20); + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Biome Blade"); //This is litterally just the biome blade without even any extra magic effects so + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 32; + projectile.friendly = true; + projectile.penetrate = 1; + projectile.timeLeft = 40; + projectile.melee = true; + projectile.tileCollide = false; + } + + public override bool CanDamage() => false; + + public override void AI() + { + if (Math.Abs(HalfTimer / 20f) == 0.5f) //Why is this only playing on the first swing + { + var splash = new LegacySoundStyle(SoundID.Splash, 0).WithPitchVariance(Main.rand.NextFloat()); + Main.PlaySound(splash, projectile.Center); + + if (Owner.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(Owner.Center, direction * 0.1f + Owner.velocity, ProjectileType(), projectile.damage, 0, Owner.whoAmI); + } + + Particle Sparkle = new CritSpark(projectile.Center, Main.rand.NextVector2Circular(1f, 1f) * Main.rand.NextFloat(7.5f, 20f), Color.White, Main.rand.NextBool() ? Color.CornflowerBlue : Color.DodgerBlue, 0.1f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + + } + + + direction = Vector2.UnitY.RotatedBy((MathHelper.PiOver4 + Utils.AngleLerp(0f, MathHelper.PiOver4 * 1.5f, HalfTimer / 20f)) * Math.Sign(Timer-1 - 20f)) * (float)Math.Sin(HalfTimer / 20f * MathHelper.Pi) * 30; + Owner.direction = Math.Sign(direction.X); + Owner.itemRotation = direction.ToRotation(); + if (Owner.direction != 1) + { + Owner.itemRotation -= 3.14f; + } + + projectile.Center = Owner.Center + direction; + projectile.rotation = direction.ToRotation() + MathHelper.PiOver2; + projectile.spriteDirection = Math.Sign(Timer - 20f); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D blade = GetTexture("CalamityMod/Items/Weapons/Melee/TrueBiomeBlade"); + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + Vector2 drawOrigin = new Vector2(0f, blade.Height); + Vector2 drawOffset = projectile.Center - Main.screenPosition; + + spriteBatch.Draw(blade, drawOffset, null, lightColor, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + return false; + } + + } + + public class GestureForTheDrownedOrb : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrowned"; + Vector2 direction = Vector2.Zero; + public Player Owner => Main.player[projectile.owner]; + public ref float HasLanded => ref projectile.ai[0]; //Is the orb in the air or is it on the ground? + public ref float TimeSinceLanding => ref projectile.ai[1]; //How long has it been on the ground for + public float Timer => MaxTime - projectile.timeLeft; + public const float MaxTime = 160f; + public float groundOffset; + public bool BounceX => projectile.oldPosition.X == projectile.position.X; + + public bool WaterMode = false; + + public float scaleX => 1 + 0.2f * (1f + -(float)Math.Sin((TimeSinceLanding - 10f) * 0.1f)) * 0.5f; + public float scaleY => (1 + 0.4f * (1f + (float)Math.Sin((TimeSinceLanding - 10f) * 0.1f)) * 0.5f) * MathHelper.Clamp((TimeSinceLanding - 10) / 30f, 0f, 1f) * MathHelper.Clamp(projectile.timeLeft / 30f, 0f, 1f); + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gesture for the Drowned"); + + ProjectileID.Sets.TrailCacheLength[projectile.type] = 5; + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + Main.projFrames[projectile.type] = 3; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 26; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.timeLeft = (int)MaxTime; + projectile.melee = true; + projectile.alpha = 90; + projectile.ignoreWater = true; + projectile.hide = true; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + if (WaterMode) + { + return true; + } + HasLanded = 1f; + projectile.velocity.Y = -4f; + return false; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + if (TimeSinceLanding < 10 && !WaterMode) + return base.Colliding(projHitbox, targetHitbox); + float collisionPoint = 0f; + if (!WaterMode) + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Bottom, projectile.Bottom - (Vector2.UnitY * scaleY * 110), scaleX * 40, ref collisionPoint); + + float halfLenght = 66f * projectile.scale; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center + Vector2.Normalize(projectile.velocity.RotatedBy(MathHelper.PiOver2)) * halfLenght, projectile.Center - Vector2.Normalize(projectile.velocity.RotatedBy(MathHelper.PiOver2)) * halfLenght, 40f, ref collisionPoint); + } + + public override void DrawBehind(int index, List drawCacheProjsBehindNPCsAndTiles, List drawCacheProjsBehindNPCs, List drawCacheProjsBehindProjectiles, List drawCacheProjsOverWiresUI) + { + drawCacheProjsBehindNPCsAndTiles.Add(index); + } + + public override void AI() + { + if (Collision.WetCollision(projectile.position, projectile.width, projectile.height)) + { + WaterMode = true; + projectile.velocity.Y *= 0.33f; + } + else if (WaterMode) + { + projectile.Kill(); + } + + if (WaterMode) + { + projectile.velocity *= 1.02f; + projectile.scale *= 1.01f; + projectile.timeLeft--; + + for (int i = 0; i <= 4; i++) + { + Dust waterTrail = Main.dust[Dust.NewDust(projectile.Center + Main.rand.NextVector2Circular(10f, 10f), 23, 0, DustID.Water, -3.7f * Math.Sign(projectile.velocity.X), -6f, 0, new Color(255, 255, 255), Main.rand.NextFloat(1f, 3f))]; + waterTrail.fadeIn = 3f; + } + + Dust foamDust = Main.dust[Dust.NewDust(projectile.Center + Main.rand.NextVector2Circular(10f, 10f), 9, 0, 16, 2.7f * Math.Sign(projectile.velocity.X), -3f, 0, new Color(255, 255, 255), 1.4f)]; + foamDust.noGravity = true; + + if (Main.rand.NextBool()) + { + float angle = Main.rand.NextFloat(-MathHelper.PiOver2, MathHelper.PiOver2); + float distance = 10f + 50 * Math.Abs(angle) / MathHelper.PiOver2 * projectile.scale; + Vector2 sparkSpeed = -projectile.velocity; + Particle Spark = new CritSpark(projectile.Center + Vector2.Normalize(projectile.velocity.RotatedBy(angle)) * distance, sparkSpeed, Color.SkyBlue, Color.CornflowerBlue, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.6f); + GeneralParticleHandler.SpawnParticle(Spark); + } + return; + } + + if (HasLanded == 1f) + { + TimeSinceLanding++; + + groundOffset = -1; + //Check 7 tiles under the projectile for solid ground + for (float i = 0; i < 7; i += 0.5f) + { + Vector2 positionToCheck = projectile.position; + if (Main.tile[(int)(positionToCheck.X / 16), (int)((positionToCheck.Y / 16) + 1 * i)].IsTileSolidGround() && groundOffset == -1) + { + groundOffset = i * 16; + break; + } + } + //If no ground has been found, go back to the airborne state + if (groundOffset == -1) + { + HasLanded = 0f; + TimeSinceLanding = 0f; + } + + if (TimeSinceLanding > 10) + { + //Trailing water!! Dust spam!!! + Dust waterTrail = Main.dust[Dust.NewDust(projectile.Top + Vector2.UnitY * groundOffset, 23, 0, DustID.Water, -3.7f * Math.Sign(projectile.velocity.X), -6f, 0, new Color(255, 255, 255), Main.rand.NextFloat(1f, 3f))]; + waterTrail.fadeIn = 3f; + waterTrail = Main.dust[Dust.NewDust(projectile.TopRight + Vector2.UnitY * groundOffset + Main.rand.NextVector2Circular(16f, 16f) + Vector2.UnitX * projectile.velocity.X * 4f, 23, 0, DustID.Water, -3.7f * Math.Sign(projectile.velocity.X), -6f, 0, new Color(255, 255, 255), Main.rand.NextFloat(1f, 3f))]; + waterTrail.fadeIn = 3f; + waterTrail = Main.dust[Dust.NewDust(projectile.TopLeft + Vector2.UnitY * groundOffset + Main.rand.NextVector2Circular(16f, 16f) + Vector2.UnitX * projectile.velocity.X * 4f, 23, 0, DustID.Water, -3.7f * Math.Sign(projectile.velocity.X), -6f, 0, new Color(255, 255, 255), Main.rand.NextFloat(1f, 3f))]; + waterTrail.fadeIn = 3f; + + + Dust foamDust = Main.dust[Dust.NewDust(projectile.Top + Vector2.UnitY * groundOffset + Vector2.UnitX * 16 * Math.Sign(projectile.velocity.X), 9, 0, 16, 2.7f * Math.Sign(projectile.velocity.X), -3f, 0, new Color(255, 255, 255), 1.4f)]; + foamDust.noGravity = true; + + //Foam + float height = scaleY * 100f; + Vector2 origin = projectile.Top + Vector2.UnitY * groundOffset + Main.rand.NextVector2Circular(projectile.width / 4f, projectile.height / 4f) - (Vector2.UnitY * height); + Particle foamSmall = new FakeGlowDust(origin, projectile.velocity / 2f, Color.LightSlateGray, Main.rand.NextFloat(1f, 2f), 25, 0.1f, bigSize : true ,gravity: (-projectile.velocity + Vector2.UnitY) * 0.1f); + GeneralParticleHandler.SpawnParticle(foamSmall); + + if (Main.rand.Next(5) == 0) + { + Particle foamLarge = new MediumMistParticle(origin, projectile.velocity / 2f, Color.LightSlateGray, Color.LightBlue, Main.rand.NextFloat(1f, 2f), 245 - Main.rand.Next(50), 0.1f); + GeneralParticleHandler.SpawnParticle(foamLarge); + } + } + } + + else + { + Particle foamSmall = new FakeGlowDust(projectile.Center + Main.rand.NextVector2Circular(projectile.width / 2f, projectile.height / 2f), projectile.velocity / 2f, Color.LightSlateGray, Main.rand.NextFloat(0.2f, 2f), 25, 0.1f, gravity: (-projectile.velocity + Vector2.UnitY) * 0.1f); + GeneralParticleHandler.SpawnParticle(foamSmall); + + if (Main.rand.NextBool()) + { + Particle blob = new WaterGlobParticle(projectile.Center + Main.rand.NextVector2Circular(projectile.width / 2f, projectile.height / 2f), projectile.velocity / 2f, Main.rand.NextFloat(0.2f, 2f), 0.1f); + GeneralParticleHandler.SpawnParticle(blob); + } + + } + + projectile.rotation += 0.1f * ((projectile.velocity.X > 0) ? 1f : -1f); + + + if (projectile.velocity.Y < 15f) + { + projectile.velocity.Y += 0.3f; + } + + if (Math.Abs(projectile.velocity.X) < 8) + { + projectile.velocity.X += 0.3f * ((projectile.velocity.X > 0) ? 1f : -1f); + } + else + { + projectile.velocity.X = Math.Sign(projectile.velocity.X) * 8; + } + + if (BounceX) + { + //Die lmao + projectile.Kill(); + } + + projectile.frameCounter++; + if (projectile.frameCounter % 6 == 0) + projectile.frame = (projectile.frame + 1) % 3; + } + + public override void Kill(int timeLeft) + { + var splash = new LegacySoundStyle(SoundID.Splash, 0).WithPitchVariance(Main.rand.NextFloat()); + Main.PlaySound(splash, projectile.Center); + + for (int i = 0; i < 4; i++) + { + Particle foamLarge = new MediumMistParticle(projectile.Center + Main.rand.NextVector2Circular(projectile.width, projectile.height), projectile.oldVelocity / 2f, Color.LightSlateGray, Color.LightBlue, Main.rand.NextFloat(1f, 2f), 245 - Main.rand.Next(50), 0.1f); + GeneralParticleHandler.SpawnParticle(foamLarge); + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (BounceX) + return false; + + if (WaterMode) + { + Texture2D wave = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedAquaWave"); + float drawRotation = projectile.velocity.ToRotation() + MathHelper.Pi ; + Vector2 drawOrigin = new Vector2(wave.Width/2f, wave.Height / 2f); + Vector2 drawOffset = projectile.Center - Main.screenPosition; + + spriteBatch.Draw(wave, drawOffset - projectile.velocity, null, Color.Lerp(lightColor, Color.White, 0.5f) * 0.2f, drawRotation, drawOrigin, projectile.scale - 0.2f, 0f, 0f); + spriteBatch.Draw(wave, drawOffset, null, Color.Lerp(lightColor, Color.White, 0.5f) * 0.5f, drawRotation, drawOrigin, projectile.scale, 0f, 0f); + return false; + } + + + if (HasLanded == 1f && TimeSinceLanding > 10f) + { + Texture2D wave = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedWave"); + Rectangle frame = new Rectangle(0, 0 + 110 * projectile.frame, 40, 110); + + float drawRotation = 0f; + Vector2 drawOrigin = new Vector2(0f, frame.Height); + + + Vector2 drawOffset; + + //Wobble + Vector2 Scale; + + SpriteEffects flip = projectile.velocity.X > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + + for (int i = 2; i >= 0; i--) + { + drawOffset = projectile.position + Vector2.UnitY * groundOffset + Vector2.UnitY / 2f - Main.screenPosition; + drawOffset -= Vector2.UnitX * 10f * i * Math.Sign(projectile.velocity.X); + float ScaleYAlter = (1 + 0.4f * (1f + (float)Math.Sin((TimeSinceLanding - 10f) * 0.1f + 0.2 * i)) * 0.5f) * MathHelper.Clamp((TimeSinceLanding - 10) / 30f, 0f, 1f) * MathHelper.Clamp(projectile.timeLeft / 30f, 0f, 1f); + Scale = new Vector2(scaleX, ScaleYAlter - 0.05f * i); + float slightfade = 1f - 0.24f * i; + Color darkenedColor = Color.Lerp(lightColor, Color.Black, i * 0.15f); + + spriteBatch.Draw(wave, drawOffset, frame, darkenedColor * MathHelper.Clamp(TimeSinceLanding / 30f, 0f, 1f) * slightfade, drawRotation, drawOrigin, Scale, flip, 0f); + } + + + + return false; + } + + else + { + Texture2D ball = GetTexture("CalamityMod/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrowned"); + float drawRotation = projectile.rotation; + Vector2 drawOrigin = projectile.Size / 2f; + Vector2 drawOffset = projectile.Center - Main.screenPosition; + + spriteBatch.Draw(ball, drawOffset, null, lightColor * MathHelper.Clamp(1 - TimeSinceLanding / 10f, 0f, 1f), drawRotation, drawOrigin, projectile.scale, 0f, 0f); + + return false; + } + + } + + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(WaterMode); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + WaterMode = reader.ReadBoolean(); + } + + } +} + + diff --git a/Projectiles/Melee/MendedBiomeBlade_AridGrandeur.png b/Projectiles/Melee/MendedBiomeBlade_AridGrandeur.png new file mode 100644 index 0000000000..e767d2a2c4 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_AridGrandeur.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_AridGrandeurExtra.png b/Projectiles/Melee/MendedBiomeBlade_AridGrandeurExtra.png new file mode 100644 index 0000000000..5af2eee020 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_AridGrandeurExtra.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_BitingEmbrace.png b/Projectiles/Melee/MendedBiomeBlade_BitingEmbrace.png new file mode 100644 index 0000000000..39a9c7a2ec Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_BitingEmbrace.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_BitingEmbraceThrust.png b/Projectiles/Melee/MendedBiomeBlade_BitingEmbraceThrust.png new file mode 100644 index 0000000000..c1935882e7 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_BitingEmbraceThrust.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_DecaysRetort.png b/Projectiles/Melee/MendedBiomeBlade_DecaysRetort.png new file mode 100644 index 0000000000..6ecc319493 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_DecaysRetort.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash.png b/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash.png new file mode 100644 index 0000000000..5bd65f8816 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_DecaysRetortDash.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrowned.png b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrowned.png new file mode 100644 index 0000000000..0454d6961e Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrowned.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedAquaWave.png b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedAquaWave.png new file mode 100644 index 0000000000..30a5b3e99e Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedAquaWave.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedWave.png b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedWave.png new file mode 100644 index 0000000000..db336bf69b Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_GestureForTheDrownedWave.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchBlade.png b/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchBlade.png new file mode 100644 index 0000000000..55abcc13df Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchBlade.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchGlow.png b/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchGlow.png new file mode 100644 index 0000000000..76fff14456 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_GrovetendersTouchGlow.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_HeavensMight.png b/Projectiles/Melee/MendedBiomeBlade_HeavensMight.png new file mode 100644 index 0000000000..16ff22f0e6 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_HeavensMight.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_HeavensMightChain.png b/Projectiles/Melee/MendedBiomeBlade_HeavensMightChain.png new file mode 100644 index 0000000000..70bee87d0b Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_HeavensMightChain.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_PurityProjectionSigil.png b/Projectiles/Melee/MendedBiomeBlade_PurityProjectionSigil.png new file mode 100644 index 0000000000..28fe39783b Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_PurityProjectionSigil.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrence.png b/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrence.png new file mode 100644 index 0000000000..4ec0fdebc3 Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrence.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith.png b/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith.png new file mode 100644 index 0000000000..4ccb1e449d Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith.png differ diff --git a/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith_Glow.png b/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith_Glow.png new file mode 100644 index 0000000000..ee4d00e3bc Binary files /dev/null and b/Projectiles/Melee/MendedBiomeBlade_TheirAbhorrenceMonolith_Glow.png differ diff --git a/Projectiles/Melee/OmegaBiomeOrb.cs b/Projectiles/Melee/OmegaBiomeOrb.cs deleted file mode 100644 index 375ea0545a..0000000000 --- a/Projectiles/Melee/OmegaBiomeOrb.cs +++ /dev/null @@ -1,253 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.CalPlayer; -using CalamityMod.Dusts; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Projectiles.Melee -{ - public class OmegaBiomeOrb : ModProjectile - { - private int dustType = 3; - Color color = default; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Omega Biome Orb"); - ProjectileID.Sets.TrailCacheLength[projectile.type] = 6; - ProjectileID.Sets.TrailingMode[projectile.type] = 0; - } - - public override void SetDefaults() - { - projectile.width = 20; - projectile.height = 20; - projectile.aiStyle = 27; - aiType = ProjectileID.LightBeam; - projectile.friendly = true; - projectile.penetrate = 1; - projectile.timeLeft = 120; - projectile.melee = true; - } - - public override void AI() - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool corrupt = player.ZoneCorrupt; - bool crimson = player.ZoneCrimson; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool sky = player.ZoneSkyHeight; - bool holy = player.ZoneHoly; - bool nebula = player.ZoneTowerNebula; - bool stardust = player.ZoneTowerStardust; - bool solar = player.ZoneTowerSolar; - bool vortex = player.ZoneTowerVortex; - if (astral) - { - dustType = ModContent.DustType(); - color = new Color(255, 127, 80, projectile.alpha); - } - else if (jungle) - { - dustType = 39; - color = new Color(128, 255, 128, projectile.alpha); - } - else if (snow) - { - dustType = 51; - color = new Color(128, 255, 255, projectile.alpha); - } - else if (beach) - { - dustType = 33; - color = new Color(0, 0, 128, projectile.alpha); - } - else if (corrupt) - { - dustType = 14; - color = new Color(128, 64, 255, projectile.alpha); - } - else if (crimson) - { - dustType = 5; - color = new Color(128, 0, 0, projectile.alpha); - } - else if (dungeon) - { - dustType = 29; - color = new Color(64, 0, 128, projectile.alpha); - } - else if (desert) - { - dustType = 32; - color = new Color(255, 255, 128, projectile.alpha); - } - else if (glow) - { - dustType = 56; - color = new Color(0, 255, 255, projectile.alpha); - } - else if (hell) - { - dustType = 6; - color = new Color(255, 128, 0, projectile.alpha); - } - else if (sky) - { - dustType = 213; - color = new Color(255, 255, 255, projectile.alpha); - } - else if (holy) - { - dustType = 57; - color = new Color(255, 255, 0, projectile.alpha); - } - else if (nebula) - { - dustType = 242; - color = new Color(255, 0, 255, projectile.alpha); - } - else if (stardust) - { - dustType = 206; - color = new Color(0, 255, 255, projectile.alpha); - } - else if (solar) - { - dustType = 244; - color = new Color(255, 128, 0, projectile.alpha); - } - else if (vortex) - { - dustType = 107; - color = new Color(0, 255, 0, projectile.alpha); - } - else - { - color = new Color(0, 128, 0, projectile.alpha); - } - - int num458 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, dustType, 0f, 0f, 100, default, 1.2f); - Main.dust[num458].noGravity = true; - Main.dust[num458].velocity *= 0.5f; - Main.dust[num458].velocity += projectile.velocity * 0.1f; - - CalamityGlobalProjectile.HomeInOnNPC(projectile, !projectile.tileCollide, 200f, 12f, 20f); - } - - public override Color? GetAlpha(Color lightColor) - { - return color; - } - - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - if (projectile.timeLeft > 235) - return false; - - CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); - return false; - } - - public override void Kill(int timeLeft) - { - int num3; - for (int num795 = 4; num795 < 31; num795 = num3 + 1) - { - float num796 = projectile.oldVelocity.X * (30f / (float)num795); - float num797 = projectile.oldVelocity.Y * (30f / (float)num795); - int num798 = Dust.NewDust(new Vector2(projectile.oldPosition.X - num796, projectile.oldPosition.Y - num797), 8, 8, dustType, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, default, 1.8f); - Main.dust[num798].noGravity = true; - Dust dust = Main.dust[num798]; - dust.velocity *= 0.5f; - num798 = Dust.NewDust(new Vector2(projectile.oldPosition.X - num796, projectile.oldPosition.Y - num797), 8, 8, dustType, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, default, 1.4f); - dust = Main.dust[num798]; - dust.velocity *= 0.05f; - num3 = num795; - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool holy = player.ZoneHoly; - bool bloodMoon = Main.bloodMoon; - bool snowMoon = Main.snowMoon; - bool pumpkinMoon = Main.pumpkinMoon; - int duration = 150; - if (bloodMoon) - { - player.AddBuff(BuffID.Battle, duration); - } - if (snowMoon) - { - player.AddBuff(BuffID.RapidHealing, duration); - } - if (pumpkinMoon) - { - player.AddBuff(BuffID.WellFed, duration); - } - if (astral) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (jungle) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (snow) - { - target.AddBuff(ModContent.BuffType(), 30); - } - else if (beach) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (dungeon) - { - target.AddBuff(BuffID.Frostburn, duration); - } - else if (desert) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (glow) - { - target.AddBuff(ModContent.BuffType(), 30); - } - else if (hell) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (holy) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else - { - target.AddBuff(ModContent.BuffType(), duration); - } - } - } -} diff --git a/Projectiles/Melee/OmegaBiomeOrb.png b/Projectiles/Melee/OmegaBiomeOrb.png deleted file mode 100644 index 9e55e98a87..0000000000 Binary files a/Projectiles/Melee/OmegaBiomeOrb.png and /dev/null differ diff --git a/Projectiles/Melee/TrueBiomeBladeProjectiles.cs b/Projectiles/Melee/TrueBiomeBladeProjectiles.cs new file mode 100644 index 0000000000..0e49ef2967 --- /dev/null +++ b/Projectiles/Melee/TrueBiomeBladeProjectiles.cs @@ -0,0 +1,2325 @@ +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 +{ + + //Swordsmith's pride aka Whirlwind attunement + + public class SwordsmithsPride : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride"; + private bool initialized = false; + Vector2 direction = 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 float OverEmpowerment = 0f; //Used to keep cooldowns working when the spin is full + public ref float hasMadeSound => ref projectile.localAI[0]; + public ref float hasMadeChargeSound => ref projectile.localAI[1]; + + public const float maxEmpowerment = 600f; + public float throwTimer => throwOutTime - projectile.timeLeft; + + + public float AngleReset = 0f; + public bool CanDirectFire = true; + public Particle smear; + public Particle sightLine; + public NPC lastTarget; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Swordsmith's Pride"); + 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 = OmegaBiomeBlade.WhirlwindAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 140 * projectile.scale; + float bladeWidth = 25 * 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(); + 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.GreenYellow, 2f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 2f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + } + + if (CurrentState == 0f) + { + + if (hasMadeChargeSound == 0f && Empowerment / maxEmpowerment >= 0.5) + { + hasMadeChargeSound = 1f; + Main.PlaySound(SoundID.Item76, projectile.Center); + } + + 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) + { + CanDirectFire = true; + hasMadeSound = 1f; + Main.PlaySound(SoundID.Item71, projectile.Center); + } + + + if (Empowerment / maxEmpowerment >= 0.5 && (Empowerment + OverEmpowerment) % 30 == 29 && Owner.whoAmI == Main.myPlayer) + { + Vector2 shotDirection = Main.rand.NextVector2CircularEdge(15f, 15f); + if (lastTarget != null && lastTarget.active) //If you've got an actual target, angle your shots towards them + { + shotDirection = (shotDirection.ToRotation().AngleTowards(Owner.AngleTo(lastTarget.Center), MathHelper.PiOver2)).ToRotationVector2() * 15f; + } + Projectile.NewProjectile(Owner.Center, shotDirection, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.WhirlwindAttunement_BeamDamageReduction), 0f, Owner.whoAmI); + + } + + + if (Empowerment / maxEmpowerment >= 0.75) + { + Color currentColor = Color.Lerp(Color.HotPink, Color.GreenYellow, (float)Math.Sin(Main.GlobalTime * 2f)) * (((Empowerment / maxEmpowerment) - 0.75f) / 0.25f * 0.8f); + 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.9f; + smear.Color = currentColor; + } + + if (sightLine == null) + { + sightLine = new LineVFX(Owner.Center, Owner.DirectionTo(Main.MouseWorld), 0.2f, Color.HotPink, false); + GeneralParticleHandler.SpawnParticle(sightLine); + } + else + { + sightLine.Position = Owner.Center + Owner.DirectionTo(Main.MouseWorld) * projectile.scale * 1.88f * 40; + (sightLine as LineVFX).LineVector = Owner.DirectionTo(Main.MouseWorld) * projectile.scale * 1.88f * 38f; + sightLine.Scale = 0.2f; + sightLine.Time = 0; + sightLine.Color = currentColor * 0.7f; + } + + float rotationAdjusted = MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi; + float mouseAngleAdjusted = MathHelper.WrapAngle(Owner.DirectionTo(Main.MouseWorld).ToRotation()) + MathHelper.Pi; + float deltaAngleShoot = Math.Abs(MathHelper.WrapAngle(rotationAdjusted - mouseAngleAdjusted)); + + if (CanDirectFire && deltaAngleShoot < 0.1f) + { + Particle Blink = new GenericSparkle(Owner.Center + Owner.DirectionTo(Main.MouseWorld) * projectile.scale * 1.88f * 78f, Owner.velocity, Color.White, currentColor, 1.5f, 10, 0.1f, 3f); + GeneralParticleHandler.SpawnParticle(Blink); + + if (Owner.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(Owner.Center, Owner.DirectionTo(Main.MouseWorld) * 15f, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.WhirlwindAttunement_BeamDamageReduction), 0f, Owner.whoAmI); + } + CanDirectFire = false; + AngleReset = Owner.DirectionTo(Main.MouseWorld).ToRotation(); + } + + + if (Main.rand.NextBool()) + { + float maxDistance = projectile.scale * 1.9f * 78f; + Vector2 distance = Main.rand.NextVector2Circular(maxDistance, maxDistance); + Vector2 angularVelocity = Vector2.Normalize(distance.RotatedBy(MathHelper.PiOver2)) * 2f * (1f + distance.Length() / 15f); + Particle glitter = new CritSpark(Owner.Center + distance, Owner.velocity + angularVelocity, Color.White, currentColor, 1f + 1 * (distance.Length() / maxDistance), 10, 0.05f, 3f); + GeneralParticleHandler.SpawnParticle(glitter); + } + } + + + //Manage position and rotation + projectile.scale = 1 + Empowerment / maxEmpowerment * 1.5f; + + 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; + OverEmpowerment++; + } + } + + 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 * (OmegaBiomeBlade.WhirlwindAttunement_BaseDamageReduction + (OmegaBiomeBlade.WhirlwindAttunement_FullChargeDamageBoost * Empowerment / maxEmpowerment))); + + if (CurrentState != 1) + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.WhirlwindAttunement_WhirlwindProc) + sword.OnHitProc = true; + return; + } + + if (Owner.HeldItem.modItem is OmegaBiomeBlade blade && Main.rand.NextFloat() <= OmegaBiomeBlade.WhirlwindAttunement_SwordThrowProc) + blade.OnHitProc = true; + + lastTarget = target; + foreach (Projectile proj in Main.projectile) + { + if (proj.active && proj.type == ProjectileType() && proj.owner == Owner.whoAmI) + { + //Reset the timeleft on the sigil & give it its new target (or the same, it doesnt matter really. + proj.ai[0] = target.whoAmI; + proj.timeLeft = OmegaBiomeBlade.WhirlwindAttunement_SigilTime; + return; + } + } + Projectile sigil = Projectile.NewProjectileDirect(target.Center, Vector2.Zero, ProjectileType(), 0, 0, Owner.whoAmI, target.whoAmI); + sigil.timeLeft = OmegaBiomeBlade.WhirlwindAttunement_SigilTime; + } + + public override void Kill(int timeLeft) + { + if (smear != null) + smear.Kill(); + if (sightLine != null) + sightLine.Kill(); + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/OmegaBiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride"); + + 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 + { + public NPC target; + public Player Owner => Main.player[projectile.owner]; + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPrideBeam"; + + 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 = 80; + 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) //Home in + { + projectile.timeLeft = 70; //Remain alive + float angularTurnSpeed = MathHelper.ToRadians(MathHelper.Lerp(15, 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(); + } + + 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 > 75) + return false; + + DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); + + 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); + + Texture2D tex = Main.projectileTexture[projectile.type]; + + spriteBatch.Draw(tex, projectile.Center - Main.screenPosition, null, Color.Lerp(Color.HotPink, Color.GreenYellow, (float)Math.Sin(Main.GlobalTime * 2f)), projectile.rotation, tex.Size() * 0.5f, 1f, 0f, 0f); + + 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) + { + 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 override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.WhirlwindAttunement_SwordBeamProc) + sword.OnHitProc = true; + } + + public override Color? GetAlpha(Color lightColor) => Color.Lerp(Color.HotPink, Color.GreenYellow, (float)Math.Sin(Main.GlobalTime * 2f)); + } + + //Sanguine fury aka Super Pogo attunement + + public class SanguineFury : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_SanguineFury"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float Shred => ref projectile.ai[0]; //How much the attack is, attacking + public float ShredRatio => MathHelper.Clamp(Shred / (maxShred * 0.5f), 0f, 1f); + public ref float PogoCooldown => ref projectile.ai[1]; //Cooldown for the pogo + public ref float BounceTime => ref projectile.localAI[0]; + public Player Owner => Main.player[projectile.owner]; + public bool CanPogo => Owner.velocity.Y != 0 && PogoCooldown <= 0; //Only pogo when in the air and if the cooldown is zero + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + + public const float pogoStrenght = 16f; //How much the player gets pogoed up + public const float maxShred = 500; //How much shred you get + + public Projectile Wheel; + public bool Dashing; + public Vector2 DashStart; + + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sanguine Fury"); + } + 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 = OmegaBiomeBlade.SuperPogoAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 130 * projectile.scale; + float bladeWidth = 86 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center, Owner.Center + (direction * bladeLenght), bladeWidth, ref collisionPoint); + } + + public void Pogo() + { + if (CanPogo && Main.myPlayer == Owner.whoAmI) + { + Owner.velocity = -direction.SafeNormalize(Vector2.Zero) * pogoStrenght; //Bounce + Owner.fallStart = (int)(Owner.position.Y / 16f); + PogoCooldown = 30; //Cooldown + Main.PlaySound(SoundID.DD2_MonkStaffGroundImpact, projectile.position); + + Vector2 hitPosition = Owner.Center + (direction * 100 * projectile.scale); + BounceTime = 20f; //Used only for animation + + for (int i = 0; i < 8; i++) + { + Vector2 hitPositionDisplace = direction.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(-10f, 10f); + Vector2 flyDirection = -direction.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)); + Particle smoke = new SmallSmokeParticle(hitPosition + hitPositionDisplace, flyDirection * 9f, Color.Crimson, new Color(130, 130, 130), Main.rand.NextFloat(1.8f, 2.6f), 155 - Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(smoke); + + Particle Glow = new StrongBloom(hitPosition - hitPositionDisplace * 3, -direction * 6 * Main.rand.NextFloat(0.5f, 1f), Color.Crimson * 0.5f, 0.01f + Main.rand.NextFloat(0f, 0.2f), 20 + Main.rand.Next(40)); + GeneralParticleHandler.SpawnParticle(Glow); + } + for (int i = 0; i < 3; i++) + { + Vector2 hitPositionDisplace = direction.RotatedBy(MathHelper.PiOver2) * Main.rand.NextFloat(-10f, 10f); + Vector2 flyDirection = -direction.RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)); + + Particle Rock = new StoneDebrisParticle(hitPosition - hitPositionDisplace * 3, flyDirection * Main.rand.NextFloat(3f, 6f), Color.Beige, 1f + Main.rand.NextFloat(0f, 0.4f), 30 + Main.rand.Next(50), 0.1f); + GeneralParticleHandler.SpawnParticle(Rock); + } + } + } + + public override void AI() + { + if (!initialized) //Initialization. Here its litterally just playing a sound tho lmfao + { + Main.PlaySound(SoundID.Item90, projectile.Center); + initialized = true; + + foreach(Projectile proj in Main.projectile) + { + if (proj.active && proj.type == ProjectileType() && proj.owner == Owner.whoAmI) + { + if (CalamityUtils.AngleBetween(Owner.Center - Main.MouseWorld, Owner.Center - proj.Center) > MathHelper.PiOver4) + { + proj.Kill(); + break; + } + + Wheel = proj; + Dashing = true; + DashStart = Owner.Center; + Wheel.timeLeft = 60; + Owner.GiveIFrames(OmegaBiomeBlade.SuperPogoAttunement_SlashIFrames); + break; + } + } + } + + if (!OwnerCanShoot) + { + projectile.Kill(); + return; + } + + if (Shred >= maxShred) + Shred = maxShred; + if (Shred < 0) + Shred = 0; + + Lighting.AddLight(projectile.Center, new Vector3(1f, 0.56f, 0.56f) * ShredRatio); + + //Manage position and rotation + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + projectile.Center = Owner.Center + (direction * 60); + + //Scaling based on shred + projectile.localNPCHitCooldown = OmegaBiomeBlade.SuperPogoAttunement_LocalIFrames - (int)(MathHelper.Lerp(0, OmegaBiomeBlade.SuperPogoAttunement_LocalIFrames - OmegaBiomeBlade.SuperPogoAttunement_LocalIFramesCharged, ShredRatio)); //Increase the hit frequency + projectile.scale = 1f + (ShredRatio * 1f); //SWAGGER + + + if ((Wheel == null || !Wheel.active) && Dashing) + { + Dashing = false; + Owner.velocity *= 0.1f; //Abrupt stop + + Main.PlaySound(mod.GetLegacySoundSlot(Terraria.ModLoader.SoundType.Custom, "Sounds/Custom/MeatySlash"), projectile.Center); + if (Owner.whoAmI == Main.myPlayer) + { + Projectile proj = Projectile.NewProjectileDirect(Owner.Center - DashStart / 2f, Vector2.Zero, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.SuperPogoAttunement_SlashDamageBoost), 0, Owner.whoAmI); + if (proj.modProjectile is SanguineFuryDash dash) + { + dash.DashStart = DashStart; + dash.DashEnd = Owner.Center; + } + } + } + + Owner.Calamity().LungingDown = false; + + if (Dashing) + { + Owner.Calamity().LungingDown = true; + Owner.fallStart = (int)(Owner.position.Y / 16f); + Owner.velocity = Owner.DirectionTo(Wheel.Center) * 60f; + + if (Owner.Distance(Wheel.Center) < 60f) + Wheel.active = false; + } + + + if (Collision.SolidCollision(Owner.Center + (direction * 100 * projectile.scale) - Vector2.One * 5f, 10, 10) && !Dashing) + { + Pogo(); + projectile.netUpdate = true; + projectile.netSpam = 0; + } + + //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; + + Shred--; + PogoCooldown--; + BounceTime--; + projectile.timeLeft = 2; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) => ShredTarget(); + public override void OnHitPvp(Player target, int damage, bool crit) => ShredTarget(); + + private void ShredTarget() + { + if (Main.myPlayer != Owner.whoAmI) + return; + + Owner.fallStart = (int)(Owner.position.Y / 16f); + // get lifted up + if (PogoCooldown <= 0) + { + Main.PlaySound(SoundID.NPCHit30, projectile.Center); //Sizzle + Shred += 62; //Augment the shredspeed + if (Owner.velocity.Y > 0) + Owner.velocity.Y = -2f; //Get "stuck" into the enemy partly + Owner.GiveIFrames(OmegaBiomeBlade.SuperPogoAttunement_ShredIFrames); // i framez. + PogoCooldown = 20; + } + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.NPCHit43, projectile.Center); + if (ShredRatio > 0.25 && Owner.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(projectile.Center, direction * 16f, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.SuperPogoAttunement_ShotDamageBoost) , projectile.knockBack, Owner.whoAmI, Shred); + } + Owner.Calamity().LungingDown = false; + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.SuperPogoAttunement_ShredderProc) + sword.OnHitProc = true; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/OmegaBiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_SanguineFury"); + + int bladeAmount = 4; + + float drawAngle = direction.ToRotation(); + float drawRotation = drawAngle + MathHelper.PiOver4; + + Vector2 drawOrigin = new Vector2(0f, handle.Height); + Vector2 drawOffset = Owner.Center + direction * 10f - 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); + + GameShaders.Misc["CalamityMod:BasicTint"].UseOpacity(MathHelper.Clamp(BounceTime, 0f, 20f) / 20f); + GameShaders.Misc["CalamityMod:BasicTint"].UseColor(new Color(207, 248, 255)); + 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); + + + for (int i = 0; i < bladeAmount; i++) //Draw extra copies + { + blade = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_SanguineFuryExtra"); + + drawAngle = direction.ToRotation(); + + float circleCompletion = (float)Math.Sin(Main.GlobalTime * 5 + i * MathHelper.PiOver2); + drawRotation = drawAngle + MathHelper.PiOver4 + (circleCompletion * MathHelper.Pi / 10f) - (circleCompletion * (MathHelper.Pi / 9f) * ShredRatio); + + drawOrigin = new Vector2(0f, blade.Height); + + Vector2 drawOffsetStraight = Owner.Center + direction * (float)Math.Sin(Main.GlobalTime * 7) * 10 - Main.screenPosition; //How far from the player + Vector2 drawDisplacementAngle = direction.RotatedBy(MathHelper.PiOver2) * circleCompletion.ToRotationVector2().Y * (20 + 40 * ShredRatio); //How far perpendicularly + Vector2 drawOffsetFromBounce = direction * MathHelper.Clamp(BounceTime, 0f, 20f) / 20f * 20f; + + spriteBatch.Draw(blade, drawOffsetStraight + drawDisplacementAngle + drawOffsetFromBounce, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f, 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 SendExtraAI(BinaryWriter writer) + { + writer.Write(initialized); + writer.WriteVector2(direction); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + initialized = reader.ReadBoolean(); + direction = reader.ReadVector2(); + } + } + + public class SanguineFuryWheel : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_SanguineFuryExtra"; + private bool initialized = false; + Vector2 direction = Vector2.Zero; + public ref float Shred => ref projectile.ai[0]; + public float ShredRatio => MathHelper.Clamp(Shred / (SanguineFury.maxShred * 0.5f), 0f, 1f); + public Player Owner => Main.player[projectile.owner]; + + public float Timer => MaxTime - projectile.timeLeft; + + public const float MaxTime = 120; + + + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Sanguine Wheel"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 45; + projectile.tileCollide = true; + projectile.ignoreWater = true; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.extraUpdates = 3; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + projectile.velocity *= 0.95f; + return false; + } + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 84 * projectile.scale; + float bladeWidth = 76 * projectile.scale; + + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), projectile.Center - direction * bladeLenght / 2, projectile.Center + direction * bladeLenght / 2, bladeWidth, ref collisionPoint); + } + + public override void AI() + { + if (!initialized) + { + Main.PlaySound(SoundID.Item90, projectile.Center); + initialized = true; + + direction = Owner.DirectionTo(Main.MouseWorld); + direction.Normalize(); + projectile.rotation = direction.ToRotation(); + + projectile.timeLeft = (int)MaxTime; + projectile.velocity = direction * 16f; + + projectile.scale = 1f + ShredRatio ; //SWAGGER + projectile.netUpdate = true; + + } + + projectile.velocity *= 0.96f; + projectile.position += projectile.velocity; + + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.SuperPogoAttunement_WheelProc) + sword.OnHitProc = true; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + for (int i = 0; i < 4; i++) //Draw extra copies + { + var tex = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_SanguineFuryExtra"); + + float transition = MathHelper.Clamp((Timer - 15 - (i * 20)) / (MaxTime * 0.2f), 0f, 1f); + transition = MathHelper.Clamp(Timer / MaxTime, 0f, 1f); + + //float circleCompletion = (float)Math.Sin(Main.GlobalTime * 5 + i * MathHelper.PiOver2); + //float drawAngleShot = MathHelper.WrapAngle(direction.ToRotation() + MathHelper.PiOver4 + (circleCompletion * MathHelper.Pi / 10f) - (circleCompletion * (MathHelper.Pi / 9f) * ShredRatio)); + float drawAngleWheel = MathHelper.WrapAngle(i * MathHelper.PiOver2 + (Main.GlobalTime * 6)); + //Lerp between the position in the shot and the position in the wheel + //float drawAngle = MathHelper.WrapAngle(Utils.AngleLerp(drawAngleShot, drawAngleWheel, transition)); + + Vector2 drawOrigin = new Vector2(0f, tex.Height); + + + //Vector2 drawOffsetStraight = projectile.Center + direction * (float)Math.Sin(Main.GlobalTime * 7) * 10 - Main.screenPosition; //How far from the player + //Vector2 drawDisplacementAngle = direction.RotatedBy(MathHelper.PiOver2) * circleCompletion.ToRotationVector2().Y * (20 + 40 * ShredRatio); //How far perpendicularly + //Vector2 drawPositionShot = drawOffsetStraight + drawDisplacementAngle; + Vector2 drawPositionWheel = projectile.Center - drawAngleWheel.ToRotationVector2() * 20f - Main.screenPosition; + + //Vector2 drawPosition = Vector2.Lerp(drawPositionShot, drawPositionWheel, transition); + + float opacityFade = projectile.timeLeft > 15 ? 1 : projectile.timeLeft / 15f; + + spriteBatch.Draw(tex, drawPositionWheel, null, Color.Lerp(Color.White, lightColor, 0.5f) * 0.8f * opacityFade, drawAngleWheel, drawOrigin, projectile.scale * 0.85f, 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) + { + Main.PlaySound(SoundID.Item60, projectile.Center); + 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.Crimson : Color.DarkRed, 0.4f + Main.rand.NextFloat(0f, 3.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + + } + + public class SanguineFuryDash : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => 20 - projectile.timeLeft; + + public Vector2 DashStart; + public Vector2 DashEnd; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Shredding Lunge"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 8; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 60; + projectile.timeLeft = 20; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), DashStart, DashEnd); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + crit = true; + + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.SuperPogoAttunement_DashProc) + sword.OnHitProc = true; + + Particle bloom = new StrongBloom(target.Center, target.velocity, Color.Crimson * 0.5f, 1f, 30); + GeneralParticleHandler.SpawnParticle(bloom); + + for (int i = 0; i < 3; i++) + { + Vector2 sparkSpeed = target.DirectionTo(Owner.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver4, MathHelper.PiOver4)) * 9f; + Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.Crimson, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.6f); + GeneralParticleHandler.SpawnParticle(Spark); + } + + Owner.statLife += OmegaBiomeBlade.SuperPogoAttunementSlashLifesteal; + Owner.HealEffect(OmegaBiomeBlade.SuperPogoAttunementSlashLifesteal); + } + + + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) //OMw to reuse way too much code from the entangling vines + { + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Texture2D lineTex = GetTexture("CalamityMod/Particles/ThinEndedLine"); + + Vector2 Shake = projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - projectile.timeLeft / 5f) * 0.5f; + float bump = (float)Math.Sin(((20f - projectile.timeLeft) / 20f) * MathHelper.Pi); + float raise = (float)Math.Sin(((20f - projectile.timeLeft) / 20f) * MathHelper.PiOver2); + + float rot = (DashEnd - DashStart).ToRotation() + MathHelper.PiOver2; + Vector2 origin = new Vector2(lineTex.Width / 2f, lineTex.Height); + Vector2 scale = new Vector2(0.2f, (DashEnd - DashStart).Length() / lineTex.Height); + + spriteBatch.Draw(lineTex, DashStart - Main.screenPosition + Shake, null, Color.Lerp(Color.White, Color.Crimson * 0.7f, raise), rot, origin, scale, SpriteEffects.None, 0); + + Texture2D sparkTexture = GetTexture("CalamityMod/Particles/ThinSparkle"); + Texture2D bloomTexture = GetTexture("CalamityMod/Particles/BloomCircle"); + //Ajust the bloom's texture to be the same size as the star's + float properBloomSize = (float)sparkTexture.Width / (float)bloomTexture.Height; + + + Rectangle frame = new Rectangle(0, 0, 14, 14); + + spriteBatch.Draw(bloomTexture, DashEnd - Main.screenPosition, null, Color.Crimson * bump * 0.5f, 0, bloomTexture.Size() / 2f, bump * 6f * properBloomSize, SpriteEffects.None, 0); + spriteBatch.Draw(sparkTexture, DashEnd - Main.screenPosition, frame, Color.Lerp(Color.White, Color.Crimson, raise) * bump, raise * MathHelper.TwoPi, frame.Size() / 2f, bump * 3f, SpriteEffects.None, 0); + + //Back to normal + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + return false; + } + } + + //Mercurial tides aka Shockwave attunement + + 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 = 145 * projectile.scale; + float bladeWidth = 25 * 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) && Owner.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(Owner.Center, Vector2.Zero, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.ShockwaveAttunement_BlastDamageReduction), 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 * OmegaBiomeBlade.ShockwaveAttunement_BlastDamageReduction), 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; + Owner.Calamity().LungingDown = false; + 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 < 15) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = 15; + + Projectile proj = Projectile.NewProjectileDirect(Owner.Center + (direction * 120 * projectile.scale), -direction, ProjectileType(), (int)(projectile.damage * OmegaBiomeBlade.ShockwaveAttunement_MonolithDamageBoost), 10f, Owner.whoAmI, Main.rand.Next(4), 1f); + proj.timeLeft = 81; + + + 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(), (int)(projectile.damage * OmegaBiomeBlade.ShockwaveAttunement_MonolithDamageBoost), 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(OmegaBiomeBlade.ShockwaveAttunement_DashHitIFrames); + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + damage = (int)(damage * (1f + OmegaBiomeBlade.ShockwaveAttunement_FullChargeBoost * Charge / MaxCharge)); + + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.ShockwaveAttunement_SwordProc) + sword.OnHitProc = true; + } + + 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, 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 void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.ShockwaveAttunement_MonolithProc) + sword.OnHitProc = true; + } + + 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 void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.ShockwaveAttunement_BlastProc) + sword.OnHitProc = true; + } + + 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; + } + } + + //Lamentations of the Chained aka FlailBlade attunement + + public class LamentationsOfTheChained : ModProjectile + { + private NPC[] excludedTargets = new NPC[4]; + + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained"; + public Player Owner => Main.player[projectile.owner]; + public ref float ChainSwapTimer => ref projectile.ai[0]; + public ref float SnapCoyoteTime => ref projectile.ai[1]; + private bool OwnerCanShoot => Owner.channel && !Owner.noItems && !Owner.CCed; + + const float MaxTangleReach = 400f; //How long can tangling vines from crits be + + //Doing your mom. Be warned that the X value of these vectors represents the angle of the whip while the Y value represents its RNG seed + public Vector2 whip1; + public Vector2 whip2; + public Vector2 whip3; + + public Particle smear; + public Particle smear2; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Lamentations of the Chained"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 80; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = OmegaBiomeBlade.FlailBladeAttunement_LocalIFrames; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + //Cuz it intializes the hooks as pointing flat to the right of the player and we dont want that. + if (ChainSwapTimer < OmegaBiomeBlade.FlailBladeAttunement_FlailTime) + return false; + + GenerateCurve(whip1.Y, whip1.X.ToRotationVector2(), out Vector2 control10, out Vector2 control11, out Vector2 control12, out Vector2 control13, (ChainSwapTimer % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, 1); + GenerateCurve(whip2.Y, whip2.X.ToRotationVector2(), out Vector2 control20, out Vector2 control21, out Vector2 control22, out Vector2 control23, ((ChainSwapTimer - OmegaBiomeBlade.FlailBladeAttunement_FlailTime / 3f) % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, -1); + GenerateCurve(whip3.Y, whip3.X.ToRotationVector2(), out Vector2 control30, out Vector2 control31, out Vector2 control32, out Vector2 control33, ((ChainSwapTimer - OmegaBiomeBlade.FlailBladeAttunement_FlailTime * 2f / 3f) % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, -1); + + if (Collision.CheckAABBvAABBCollision(targetHitbox.TopLeft(), targetHitbox.Size(), control13 - Vector2.One * 25f, Vector2.One * 50f) || + Collision.CheckAABBvAABBCollision(targetHitbox.TopLeft(), targetHitbox.Size(), control23 - Vector2.One * 25f, Vector2.One * 50f) || + Collision.CheckAABBvAABBCollision(targetHitbox.TopLeft(), targetHitbox.Size(), control33 - Vector2.One * 25f, Vector2.One * 50f) + ) + return true; + + //What you wanted me to calculate all 3 curves? Have straight line collisions instead + float CollisionPoint = 0f; + if (Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.MountedCenter, control13, 20f, ref CollisionPoint) || + Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.MountedCenter, control13, 20f, ref CollisionPoint) || + Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.MountedCenter, control13, 20f, ref CollisionPoint) + ) + return true; + + return false; + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + GenerateCurve(whip1.Y, whip1.X.ToRotationVector2(), out Vector2 control10, out Vector2 control11, out Vector2 control12, out Vector2 control13, (ChainSwapTimer % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, 1); + GenerateCurve(whip2.Y, whip2.X.ToRotationVector2(), out Vector2 control20, out Vector2 control21, out Vector2 control22, out Vector2 control23, ((ChainSwapTimer - OmegaBiomeBlade.FlailBladeAttunement_FlailTime / 3f) % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, -1); + GenerateCurve(whip3.Y, whip3.X.ToRotationVector2(), out Vector2 control30, out Vector2 control31, out Vector2 control32, out Vector2 control33, ((ChainSwapTimer - OmegaBiomeBlade.FlailBladeAttunement_FlailTime * 2f / 3f) % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, -1); + //If you hit the enemy with the blade of the whip, guarantee a crit + if (Collision.CheckAABBvAABBCollision(target.Hitbox.TopLeft(), target.Hitbox.Size(), control13 - Vector2.One * 25f, Vector2.One * 50f) || + Collision.CheckAABBvAABBCollision(target.Hitbox.TopLeft(), target.Hitbox.Size(), control23 - Vector2.One * 25f, Vector2.One * 50f) || + Collision.CheckAABBvAABBCollision(target.Hitbox.TopLeft(), target.Hitbox.Size(), control33 - Vector2.One * 25f, Vector2.One * 50f) + ) + { + + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.FlailBladeAttunement_BladeProc) + sword.OnHitProc = true; + + + crit = true; + for (int i = 0; i < 2; i++) + { + Vector2 sparkSpeed = Owner.DirectionTo(target.Center).RotatedBy(Main.rand.NextFloat(-MathHelper.PiOver2, MathHelper.PiOver2)) * 9f; + Particle Spark = new CritSpark(target.Center, sparkSpeed, Color.White, Color.Turquoise, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 1f); + GeneralParticleHandler.SpawnParticle(Spark); + } + + Vector2 sliceDirection = Main.rand.NextVector2CircularEdge(50f, 100f); + Particle SliceLine = new LineVFX(target.Center - sliceDirection, sliceDirection * 2f, 0.2f, Color.PaleTurquoise * 0.6f) + { + Lifetime = 6 + }; + GeneralParticleHandler.SpawnParticle(SliceLine); + } + + else + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.FlailBladeAttunement_ChainProc) + sword.OnHitProc = true; + + damage = (int)(damage * OmegaBiomeBlade.FlailBladeAttunement_ChainDamageReduction); //If the enemy is hit with the chain of the whip, the damage gets reduced + crit = false; //For once, we also block crits completely from the chain + } + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + if (crit) + { + Main.PlaySound(mod.GetLegacySoundSlot(Terraria.ModLoader.SoundType.Custom, "Sounds/Custom/SwiftSlice"), projectile.Center); + excludedTargets[0] = target; + for (int i = 0; i < 3; i++) + { + NPC potentialTarget = TargetNext(target.Center, i); + if (potentialTarget == null) + break; + Projectile proj = Projectile.NewProjectileDirect(target.Center, Vector2.Zero, ProjectileType(), (int)(damage * OmegaBiomeBlade.FlailBladeAttunement_GhostChainDamageReduction), 0, Owner.whoAmI, target.whoAmI, potentialTarget.whoAmI); + if (proj.modProjectile is GhastlyChain chain) + chain.Gravity = Main.rand.NextFloat(30f, 50f); + } + Array.Clear(excludedTargets, 0, 3); + } + } + + public NPC TargetNext(Vector2 hitFrom, int index) + { + float longestReach = MaxTangleReach; + NPC target = null; + for (int i = 0; i < 200; ++i) + { + NPC npc = Main.npc[i]; + if (!excludedTargets.Contains(npc) && npc.CanBeChasedBy() && !npc.friendly && !npc.townNPC) + { + float distance = Vector2.Distance(hitFrom, npc.Center); + if (distance < longestReach) + { + longestReach = distance; + target = npc; + } + } + } + if (index < 3) + excludedTargets[index + 1] = target; + return target; + } + + public override void AI() + { + if (!OwnerCanShoot) + { + projectile.Kill(); + return; + } + + projectile.velocity = Owner.DirectionTo(Main.MouseWorld); + projectile.velocity.Normalize(); + projectile.rotation = projectile.velocity.ToRotation(); + projectile.Center = Owner.Center + (projectile.velocity * 60); + + //Make the owner look like theyre holding the sword bla bla + Owner.heldProj = projectile.whoAmI; + Owner.direction = Math.Sign(projectile.velocity.X); + Owner.itemRotation = projectile.rotation; + if (Owner.direction != 1) + { + Owner.itemRotation -= 3.14f; + } + Owner.itemRotation = MathHelper.WrapAngle(Owner.itemRotation); + Owner.itemTime = 2; + Owner.itemAnimation = 2; + projectile.timeLeft = 2; + + if (ChainSwapTimer % OmegaBiomeBlade.FlailBladeAttunement_FlailTime == 1) + { + Main.PlaySound(SoundID.DD2_OgreSpit, projectile.Center); + + Vector2 smearPos = Owner.Center + whip1.X.ToRotationVector2() * OmegaBiomeBlade.FlailBladeAttunement_Reach * Main.rand.NextFloat(0.7f, 1.1f); + Vector2 squish = new Vector2( Main.rand.NextFloat(3f, 4f), Main.rand.NextFloat(0.5f, 1f)); + + if (smear == null) + { + smear = new SemiCircularSmearVFX(smearPos, Color.PowderBlue * 0.5f, whip1.X + MathHelper.Pi, projectile.scale * 1.5f, squish); + smear.Lifetime = 2; + GeneralParticleHandler.SpawnParticle(smear); + } + //Update the variables of the smear + else + { + smear.Rotation = whip1.X + MathHelper.Pi; //Add some v ariation? + smear.Position = smearPos; + (smear as SemiCircularSmearVFX).Squish = squish; + } + + smearPos = Owner.Center + whip1.X.ToRotationVector2() * OmegaBiomeBlade.FlailBladeAttunement_Reach * Main.rand.NextFloat(0.8f, 1.3f); + squish = new Vector2(Main.rand.NextFloat(2f, 3f), Main.rand.NextFloat(0.9f, 1.4f)); + + if (smear2 == null) + { + smear2 = new SemiCircularSmearVFX(smearPos, Color.PowderBlue * 0.5f, whip2.X + MathHelper.Pi, projectile.scale * 1.5f, squish); + smear2.Lifetime = 2; + GeneralParticleHandler.SpawnParticle(smear2); + } + //Update the variables of the smear + else + { + smear2.Rotation = whip2.X + MathHelper.Pi; //Add some v ariation? + smear2.Position = smearPos; + (smear2 as SemiCircularSmearVFX).Squish = squish; + } + } + + if (smear != null) + { + smear.Rotation = smear.Rotation.AngleTowards(projectile.velocity.ToRotation(), 0.01f); + smear.Time = 0; + (smear as SemiCircularSmearVFX).Squish.Y *= 0.985f; + (smear as SemiCircularSmearVFX).Squish.X *= 1.01f; + } + if (smear2 != null) + { + smear2.Rotation = smear2.Rotation.AngleTowards(projectile.velocity.ToRotation(), 0.01f); + smear2.Time = 0; + (smear2 as SemiCircularSmearVFX).Squish.Y *= 0.985f; + (smear2 as SemiCircularSmearVFX).Squish.X *= 1.01f; + } + + + //if ((ChainSwapTimer - 12f) % 23 == 0) + //{ + // Main.PlaySound(SoundID.Item41, projectile.Center); + //} + + ChainSwapTimer++; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Items/Weapons/Melee/OmegaBiomeBlade"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained"); + + CalculateChains(spriteBatch, out Vector2[] chainPositions1, out Vector2[] chainPositions2, out Vector2[] chainPositions3); + + //float drawRotation = (projBottom - chainPositions[chainPositions.Length - 2]).ToRotation() + MathHelper.PiOver4; //Face away from the last point of the bezier curve + + Vector2 drawPos = projectile.Center - projectile.velocity * 55f; + Vector2 drawOrigin = new Vector2(0f, handle.Height); + float drawRotation = projectile.rotation + MathHelper.PiOver4; + + //lightColor = Lighting.GetColor((int)(projectile.Center.X / 16f), (int)(projectile.Center.Y / 16f)); + + spriteBatch.Draw(handle, drawPos - Main.screenPosition, 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); + + //Draw the tip of the flails here + Texture2D flailBlade = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedFlail"); + Rectangle bladeFrame = new Rectangle(0, 0, 24, 48); + Vector2 flailOrigin = new Vector2(bladeFrame.Width / 2, bladeFrame.Height); //Draw from center bottom of texture + + float flailRotation = (chainPositions1[chainPositions1.Length - 2] - chainPositions1[chainPositions1.Length - 3]).ToRotation() + MathHelper.PiOver2; + spriteBatch.Draw(flailBlade, chainPositions1[chainPositions1.Length - 2] - Main.screenPosition, bladeFrame, Color.White, flailRotation, flailOrigin, 1, SpriteEffects.None, 0); + + flailRotation = (chainPositions2[chainPositions2.Length - 2] - chainPositions2[chainPositions1.Length - 3]).ToRotation() + MathHelper.PiOver2; + spriteBatch.Draw(flailBlade, chainPositions2[chainPositions2.Length - 2] - Main.screenPosition, bladeFrame, Color.White, flailRotation, flailOrigin, 1, SpriteEffects.None, 0); + + flailRotation = (chainPositions3[chainPositions3.Length - 2] - chainPositions3[chainPositions3.Length - 3]).ToRotation() + MathHelper.PiOver2; + spriteBatch.Draw(flailBlade, chainPositions3[chainPositions3.Length - 2] - Main.screenPosition, bladeFrame, Color.White, flailRotation, flailOrigin, 1, SpriteEffects.None, 0); + + drawOrigin = new Vector2(0f, blade.Height); + spriteBatch.Draw(blade, drawPos - Main.screenPosition, 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; + } + + //TLDR : https://media.discordapp.net/attachments/659100646397575208/933521303443501136/placeholder.gif + private void GenerateCurve(float seed, Vector2 direction, out Vector2 control0, out Vector2 control1, out Vector2 control2, out Vector2 control3, float angleShift = 0f, float necessaryOrientation = 1f) + { + float randomNumber = 0.5f + ((float)Math.Sin(seed * 17.07947) + (float)Math.Sin(seed * 0.2f * 25.13274)) * 0.25f ; //Ty dom for the awesome pseudo rng + //Get new random numbers based on the same seed + float seed1 = 0.5f + ((float)Math.Sin(randomNumber * 100f * 17.07947) + (float)Math.Sin(randomNumber * 100f * 0.2f * 25.13274)) * 0.25f; + float seed2 = 0.5f + ((float)Math.Sin(seed1 * 50f * 17.07947) + (float)Math.Sin(seed1 * 50f * 0.2f * 25.13274)) * 0.25f; + float seed3 = 0.5f + ((float)Math.Sin(seed2 * 17.07947) + (float)Math.Sin(seed2 * 0.2f * 25.13274)) * 0.25f; + + + if ((necessaryOrientation == -1 && randomNumber >= 0.5) || (necessaryOrientation == 1 && randomNumber < 0.5)) + randomNumber = 1 - randomNumber; + + randomNumber += angleShift * 0.1f * necessaryOrientation; + + + float flip = randomNumber >= 0.5 ? 1f : -1f; + + + control0 = Owner.MountedCenter + direction.RotatedBy(MathHelper.ToRadians(MathHelper.Lerp(MathHelper.PiOver4 * 0.3f * flip, MathHelper.PiOver4 * flip, randomNumber))) * MathHelper.Lerp(50f, 130f, (float)Math.Sin(randomNumber * MathHelper.Pi)); + + float easedShift = angleShift == 1 ? 1 : 1 - (float)Math.Pow(2, -10 * angleShift); + float Reach = OmegaBiomeBlade.FlailBladeAttunement_Reach * (0.75f + 0.75f * seed2 - 0.05f * easedShift); + control3 = Owner.MountedCenter + (direction * Reach).RotatedBy(MathHelper.Lerp(-0.01f * flip, 0.01f * flip, easedShift)); // The last point of the curve gets put straight at the front + + //Over the double fucking bezier rainbow + Vector2 point1 = control3 + direction.RotatedBy(MathHelper.PiOver2) * 50; + Vector2 point2 = control3 + direction.RotatedBy(MathHelper.PiOver2) * 50 + direction * 250; + Vector2 point3 = control3 + direction.RotatedBy(-MathHelper.PiOver2) * 50 + direction * 250; + Vector2 point4 = control3 + direction.RotatedBy(-MathHelper.PiOver2) * 50; + BezierCurve curve = new BezierCurve(new Vector2[] { point1, point2, point3, point4 }); + control3 = curve.Evaluate(randomNumber); + + Vector2 directionFromHead = direction.RotatedBy(MathHelper.ToRadians(MathHelper.Lerp(0, 160f * flip, (float)Math.Sin(randomNumber * MathHelper.Pi)))) * MathHelper.Lerp(130f, 200f, MathHelper.Clamp((float)Math.Sin(randomNumber * MathHelper.Pi) - 0.5f, 0f, 1f) * 2f); + control2 = control3 + directionFromHead; + + Vector2 directionFromSecondToLastPoint = Vector2.Normalize(directionFromHead.RotatedBy(MathHelper.Pi - MathHelper.ToRadians(MathHelper.Lerp(80f * flip, 110f * flip, (float)Math.Sin(randomNumber * MathHelper.Pi))))) * MathHelper.Lerp(120f, 280f, (float)Math.Sin(randomNumber * MathHelper.Pi)); + control1 = control2 + directionFromSecondToLastPoint; + + control3 += Vector2.UnitX.RotatedBy(MathHelper.TwoPi * seed1) * seed3 * 30f; + control2 += Vector2.UnitX.RotatedBy(MathHelper.TwoPi * seed2) * seed1 * 30f; + control1 += Vector2.UnitX.RotatedBy(MathHelper.TwoPi * seed3) * seed2 * 30f; + } + + private void CalculateChains(SpriteBatch spriteBatch, out Vector2[] chainPositions1, out Vector2[] chainPositions2, out Vector2[] chainPositions3) + { + + if (ChainSwapTimer % 6 == 0 || whip1.Y == 0) + { + whip1.X = projectile.velocity.RotatedBy(Main.rand.NextFloat(MathHelper.PiOver4 / 16f, -MathHelper.PiOver4 / 16f)).ToRotation(); //X is the orientation + whip1.Y = Main.rand.NextFloat(0.2f, 100f);//Y is the "seed" + + ChainSwapTimer++; + } + + if ((ChainSwapTimer - 2) % 6 == 0 || whip2.Y == 0) + { + whip2.X = projectile.velocity.RotatedBy(Main.rand.NextFloat(MathHelper.Pi / 16f, -MathHelper.Pi / 16f)).ToRotation(); //X is the orientation + whip2.Y = Main.rand.NextFloat(0.2f, 100f);//Y is the "seed" + + ChainSwapTimer++; + } + + if ((ChainSwapTimer - 4) % 6 == 0 || whip3.Y == 0) + { + whip3.X = projectile.velocity.RotatedBy(Main.rand.NextFloat(MathHelper.Pi / 16f, -MathHelper.Pi / 16f)).ToRotation(); //X is the orientation + whip3.Y = Main.rand.NextFloat(0.2f, 100f);//Y is the "seed" + + ChainSwapTimer++; + } + + GenerateCurve(whip1.Y, whip1.X.ToRotationVector2(), out Vector2 control0, out Vector2 control1, out Vector2 control2, out Vector2 control3, (ChainSwapTimer % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, 1); + DrawChain(spriteBatch, out chainPositions1, control0, control1, control2, control3); + + GenerateCurve(whip2.Y, whip2.X.ToRotationVector2(), out control0, out control1, out control2, out control3, ((ChainSwapTimer - OmegaBiomeBlade.FlailBladeAttunement_FlailTime / 3f) % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, -1); + DrawChain(spriteBatch, out chainPositions2, control0, control1, control2, control3); + + GenerateCurve(whip3.Y, whip3.X.ToRotationVector2(), out control0, out control1, out control2, out control3, ((ChainSwapTimer - OmegaBiomeBlade.FlailBladeAttunement_FlailTime * 2f / 3f) % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) / (float)OmegaBiomeBlade.FlailBladeAttunement_FlailTime, -1); + DrawChain(spriteBatch, out chainPositions3, control0, control1, control2, control3); + } + + private void DrawChain(SpriteBatch spriteBatch, out Vector2[] chainPositions, Vector2 control0, Vector2 control1, Vector2 control2, Vector2 control3) + { + + Texture2D tex = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedFlail"); + Rectangle chainFrame = new Rectangle(0, 70, 24, 14); + Rectangle guardFrame = new Rectangle(0, 50, 24, 18); + + //First chain + BezierCurve curve = new BezierCurve(new Vector2[] { Owner.MountedCenter, control0, control1, control2, control3 }); + int numPoints = 40; + chainPositions = curve.GetPoints(numPoints).ToArray(); + + //Draw each chain segment bar the very first one + for (int i = 1; i < numPoints; i++) + { + Vector2 position = chainPositions[i]; + + float rotation = (chainPositions[i] - chainPositions[i - 1]).ToRotation() + MathHelper.PiOver2; //Calculate rotation based on direction from last point + Color chainLightColor = Lighting.GetColor((int)position.X / 16, (int)position.Y / 16); //Lighting of the position of the chain segment + + if (i < numPoints - 1) + { + float yScale = Vector2.Distance(chainPositions[i], chainPositions[i - 1]) / chainFrame.Height; //Calculate how much to squash/stretch for smooth chain based on distance between points + + float segmentProgress = i < 30f ? i / 30f : 1 - (i - 30f) / 10f; + float xScale = 1f + 0.75f * (float)Math.Sin(segmentProgress * MathHelper.PiOver2); + + Vector2 scale = new Vector2(xScale, yScale); //Remember to make it get thicker and thinner based on whatever + Vector2 origin = new Vector2(chainFrame.Width / 2, chainFrame.Height); //Draw from center bottom of texture + + float chainOpacity = MathHelper.Clamp((i / (float)numPoints) * 3f, 0f, 1f); + + spriteBatch.Draw(tex, chainPositions[i] - Main.screenPosition, chainFrame, chainLightColor * chainOpacity, rotation, origin, scale, SpriteEffects.None, 0); + } + else + { + Vector2 origin = new Vector2(guardFrame.Width / 2, guardFrame.Height); //Draw from center bottom of texture + spriteBatch.Draw(tex, chainPositions[i] - Main.screenPosition, guardFrame, chainLightColor, rotation, origin, 1, SpriteEffects.None, 0); + + if ((ChainSwapTimer % OmegaBiomeBlade.FlailBladeAttunement_FlailTime) == 1 && Main.rand.Next(3) == 0f) + { + Particle Flake = new SnowflakeSparkle(chainPositions[i], Vector2.Zero, Color.PaleTurquoise, Color.MediumTurquoise, 1f + Main.rand.NextFloat(0, 1f), 30, 0.4f, 0.2f); + GeneralParticleHandler.SpawnParticle(Flake); + } + } + } + } + + + public override void SendExtraAI(BinaryWriter writer) + { + writer.WriteVector2(whip1); + writer.WriteVector2(whip2); + writer.WriteVector2(whip3); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + whip1 = reader.ReadVector2(); + whip2 = reader.ReadVector2(); + whip3 = reader.ReadVector2(); + } + } + + public class GhastlyChain : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedChain"; + public Player Owner => Main.player[projectile.owner]; + public float Timer => 20 - projectile.timeLeft; + + public float Gravity; + + public NPC NPCfrom + { + get => Main.npc[(int)projectile.ai[0]]; + set => projectile.ai[0] = value.whoAmI; + } + public NPC Target + { + get => Main.npc[(int)projectile.ai[1]]; + set => projectile.ai[1] = value.whoAmI; + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Ghastly Chain"); + } + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 8; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 30; + projectile.timeLeft = 20; + } + + public override bool? CanHitNPC(NPC target) => target == Target; + + public override void AI() + { + projectile.Center = Target.Center; + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + if (Owner.HeldItem.modItem is OmegaBiomeBlade sword && Main.rand.NextFloat() <= OmegaBiomeBlade.FlailBladeAttunement_GhostChainProc) + sword.OnHitProc = true; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D chainTex = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedChain"); + + + //Turn on additive blending + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + float opacity = projectile.timeLeft > 10 ? 1 : projectile.timeLeft / 10f; + Vector2 Shake = projectile.timeLeft < 15 ? Vector2.Zero : Vector2.One.RotatedByRandom(MathHelper.TwoPi) * (15 - projectile.timeLeft / 5f) * 0.5f; + + BezierCurve curve = new BezierCurve(new Vector2[] { Target.Center, Target.Center + Vector2.UnitY * Gravity, NPCfrom.Center + Vector2.UnitY * Gravity, NPCfrom.Center }); + int numPoints = 20; + Vector2[] Nodes = curve.GetPoints(numPoints).ToArray(); + + for (int i = 1; i < numPoints; i++) + { + Vector2 position = Nodes[i] + Shake * (float)Math.Sin(i / (float)numPoints * 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]) / chainTex.Height; //Calculate how much to squash/stretch for smooth chain based on distance between points + Vector2 scale = new Vector2(1, yScale); + + Vector2 origin = new Vector2(chainTex.Width / 2, chainTex.Height); //Draw from center bottom of texture + spriteBatch.Draw(chainTex, position - Main.screenPosition, null, Color.White * opacity, rotation, origin, scale, SpriteEffects.None, 0); + } + + //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 class ChainedMeatHook : ModProjectile + { + public override string Texture => "CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHook"; + public Player Owner => Main.player[projectile.owner]; + + public float Timer => MaxTwirlTime - projectile.timeLeft; + public static float MaxTwirlTime = 30; + public ref float Twirling => ref projectile.ai[0]; + + public bool MayIExist => Owner.active && (Owner.HeldItem.modItem is OmegaBiomeBlade blade) && blade.secondaryAttunement == OmegaBiomeBlade.Attunement.FlailBlade; + + Particle smear; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Enchanted Meat Hook"); + } + + public override void SetDefaults() + { + projectile.melee = true; + projectile.width = projectile.height = 66; + projectile.tileCollide = false; + projectile.friendly = true; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 40; + projectile.timeLeft = 1; + } + + public override bool? CanHitNPC(NPC target) => Twirling == 1f; + + public override void AI() + { + if (!MayIExist) + { + projectile.Kill(); + return; + } + + if (Twirling == 0) + { + projectile.velocity = Vector2.Zero; + projectile.timeLeft = 2; + Vector2 idealPosition = Owner.Center - Owner.direction * Vector2.UnitX * 40f + Vector2.One.RotatedBy(Main.GlobalTime) * 10f; + if ((idealPosition - projectile.Center).Length() > 1500f) + projectile.Center = idealPosition; + projectile.Center = Vector2.Lerp(projectile.Center, idealPosition, 0.05f); + projectile.Center = projectile.Center.MoveTowards(idealPosition, 4f); + + } + + + if (Twirling == 1f) + { + if (projectile.timeLeft == MaxTwirlTime) + { + projectile.velocity = Owner.DirectionTo(Main.MouseWorld); + Main.PlaySound(SoundID.Item71, projectile.Center); + for (int i = 0; i < 4; 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.Cyan : Color.MediumTurquoise, 0.4f + Main.rand.NextFloat(0f, 0.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + + if (smear == null) + { + smear = new CircularSmearVFX(Owner.Center, Color.HotPink, projectile.velocity.ToRotation(), projectile.scale * 1.5f); + GeneralParticleHandler.SpawnParticle(smear); + } + } + + projectile.velocity = projectile.velocity.RotatedBy(MathHelper.TwoPi * -2f * (1 / MaxTwirlTime)); + projectile.velocity.Normalize(); + projectile.rotation = projectile.velocity.ToRotation(); + projectile.Center = Owner.Center + (projectile.velocity * 140 * (1 + 0.3f * (float)Math.Sin(projectile.timeLeft / MaxTwirlTime * MathHelper.Pi))); + + //Update the variables of the smear + if (smear != null) + { + smear.Rotation = projectile.rotation + MathHelper.PiOver2; + smear.Time = 0; + smear.Position = Owner.Center; + smear.Scale = 3.4f; + smear.Color = Color.MediumTurquoise * 0.9f * (float)Math.Sin(projectile.timeLeft / MaxTwirlTime * MathHelper.Pi); + } + + + if (projectile.timeLeft == 1) + { + Main.PlaySound(SoundID.Item101, projectile.Center); + for (int i = 0; i < 4; 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.Cyan : Color.MediumTurquoise, 0.4f + Main.rand.NextFloat(0f, 0.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + Twirling = 0f; + } + } + } + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + int debuffTime = 100; + target.AddBuff(BuffType(), debuffTime); + } + + public override void Kill(int timeLeft) + { + Main.PlaySound(SoundID.Item105, projectile.Center); + 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.Cyan : Color.MediumTurquoise, 0.4f + Main.rand.NextFloat(0f, 1.5f), 20 + Main.rand.Next(30), 1, 3f); + GeneralParticleHandler.SpawnParticle(Sparkle); + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D handle = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHookBody"); + Texture2D blade = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHook"); + + float drawAngle = (projectile.Center - Owner.Center).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); + //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); + + drawChain(spriteBatch); + + //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) + { + Texture2D chainTex = GetTexture("CalamityMod/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedChain"); + + 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; + + 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); + + Vector2 origin = new Vector2(frame.Width / 2, frame.Height); //Draw from center bottom of texture + spriteBatch.Draw(chainTex, Nodes[i] - Main.screenPosition, frame, Color.White * 0.5f, rotation, origin, scale, SpriteEffects.None, 0); + } + } + + } + +} + + diff --git a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.png b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.png new file mode 100644 index 0000000000..ab2f922695 Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChained.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedChain.png b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedChain.png new file mode 100644 index 0000000000..38667e05df Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedChain.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedFlail.png b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedFlail.png new file mode 100644 index 0000000000..9a457c39eb Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedFlail.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHook.png b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHook.png new file mode 100644 index 0000000000..b39836239c Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHook.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHookBody.png b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHookBody.png new file mode 100644 index 0000000000..cd303d2cda Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_LamentationsOfTheChainedHookBody.png differ 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 diff --git a/Projectiles/Melee/TrueBiomeBlade_SanguineFury.png b/Projectiles/Melee/TrueBiomeBlade_SanguineFury.png new file mode 100644 index 0000000000..a0483da6c4 Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_SanguineFury.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_SanguineFuryExtra.png b/Projectiles/Melee/TrueBiomeBlade_SanguineFuryExtra.png new file mode 100644 index 0000000000..a6afbba2ca Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_SanguineFuryExtra.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride.png b/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride.png new file mode 100644 index 0000000000..996e7ea3e2 Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPride.png differ diff --git a/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPrideBeam.png b/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPrideBeam.png new file mode 100644 index 0000000000..325a7ca611 Binary files /dev/null and b/Projectiles/Melee/TrueBiomeBlade_SwordsmithsPrideBeam.png differ diff --git a/Projectiles/Melee/TrueBiomeOrb.cs b/Projectiles/Melee/TrueBiomeOrb.cs deleted file mode 100644 index 6fd9845517..0000000000 --- a/Projectiles/Melee/TrueBiomeOrb.cs +++ /dev/null @@ -1,211 +0,0 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.CalPlayer; -using CalamityMod.Dusts; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Projectiles.Melee -{ - public class TrueBiomeOrb : ModProjectile - { - private int dustType = 3; - Color color = default; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("True Biome Orb"); - ProjectileID.Sets.TrailCacheLength[projectile.type] = 4; - ProjectileID.Sets.TrailingMode[projectile.type] = 0; - } - - public override void SetDefaults() - { - projectile.width = 20; - projectile.height = 20; - projectile.aiStyle = 27; - aiType = ProjectileID.LightBeam; - projectile.friendly = true; - projectile.penetrate = 1; - projectile.timeLeft = 300; - projectile.melee = true; - } - - public override void AI() - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool corrupt = player.ZoneCorrupt; - bool crimson = player.ZoneCrimson; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool sky = player.ZoneSkyHeight; - bool holy = player.ZoneHoly; - if (astral) - { - dustType = ModContent.DustType(); - color = new Color(255, 127, 80, projectile.alpha); - } - else if (jungle) - { - dustType = 39; - color = new Color(128, 255, 128, projectile.alpha); - } - else if (snow) - { - dustType = 51; - color = new Color(128, 255, 255, projectile.alpha); - } - else if (beach) - { - dustType = 33; - color = new Color(0, 0, 128, projectile.alpha); - } - else if (corrupt) - { - dustType = 14; - color = new Color(128, 64, 255, projectile.alpha); - } - else if (crimson) - { - dustType = 5; - color = new Color(128, 0, 0, projectile.alpha); - } - else if (dungeon) - { - dustType = 29; - color = new Color(64, 0, 128, projectile.alpha); - } - else if (desert) - { - dustType = 32; - color = new Color(255, 255, 128, projectile.alpha); - } - else if (glow) - { - dustType = 56; - color = new Color(0, 255, 255, projectile.alpha); - } - else if (hell) - { - dustType = 6; - color = new Color(255, 128, 0, projectile.alpha); - } - else if (sky) - { - dustType = 213; - color = new Color(255, 255, 255, projectile.alpha); - } - else if (holy) - { - dustType = 57; - color = new Color(255, 255, 0, projectile.alpha); - } - else - { - color = new Color(0, 128, 0, projectile.alpha); - } - int num458 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, dustType, 0f, 0f, 100, default, 1.2f); - Main.dust[num458].noGravity = true; - Main.dust[num458].velocity *= 0.5f; - Main.dust[num458].velocity += projectile.velocity * 0.1f; - } - - public override Color? GetAlpha(Color lightColor) - { - return color; - } - - public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) - { - if (projectile.timeLeft > 295) - return false; - - CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor, 1); - return false; - } - - public override void Kill(int timeLeft) - { - int num3; - for (int num795 = 4; num795 < 31; num795 = num3 + 1) - { - float num796 = projectile.oldVelocity.X * (30f / (float)num795); - float num797 = projectile.oldVelocity.Y * (30f / (float)num795); - int num798 = Dust.NewDust(new Vector2(projectile.oldPosition.X - num796, projectile.oldPosition.Y - num797), 8, 8, dustType, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, default, 1.8f); - Main.dust[num798].noGravity = true; - Dust dust = Main.dust[num798]; - dust.velocity *= 0.5f; - num798 = Dust.NewDust(new Vector2(projectile.oldPosition.X - num796, projectile.oldPosition.Y - num797), 8, 8, dustType, projectile.oldVelocity.X, projectile.oldVelocity.Y, 100, default, 1.4f); - dust = Main.dust[num798]; - dust.velocity *= 0.05f; - num3 = num795; - } - } - - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) - { - Player player = Main.player[projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - bool astral = modPlayer.ZoneAstral; - bool jungle = player.ZoneJungle; - bool snow = player.ZoneSnow; - bool beach = player.ZoneBeach; - bool dungeon = player.ZoneDungeon; - bool desert = player.ZoneDesert; - bool glow = player.ZoneGlowshroom; - bool hell = player.ZoneUnderworldHeight; - bool holy = player.ZoneHoly; - int duration = 120; - if (astral) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (jungle) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (snow) - { - target.AddBuff(ModContent.BuffType(), 30); - } - else if (beach) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (dungeon) - { - target.AddBuff(BuffID.Frostburn, duration); - } - else if (desert) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (glow) - { - target.AddBuff(ModContent.BuffType(), 30); - } - else if (hell) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else if (holy) - { - target.AddBuff(ModContent.BuffType(), duration); - } - else - { - target.AddBuff(ModContent.BuffType(), duration); - } - } - } -} diff --git a/Projectiles/Melee/TrueBiomeOrb.png b/Projectiles/Melee/TrueBiomeOrb.png deleted file mode 100644 index 9e55e98a87..0000000000 Binary files a/Projectiles/Melee/TrueBiomeOrb.png and /dev/null differ diff --git a/Projectiles/Ranged/PumplerGrenade.cs b/Projectiles/Ranged/PumplerGrenade.cs index f6578cade1..dcfa1c4db2 100644 --- a/Projectiles/Ranged/PumplerGrenade.cs +++ b/Projectiles/Ranged/PumplerGrenade.cs @@ -4,6 +4,7 @@ using Terraria; using Terraria.ModLoader; using Terraria.ID; using CalamityMod.Dusts; +using CalamityMod.Particles; namespace CalamityMod.Projectiles.Ranged { @@ -35,13 +36,10 @@ namespace CalamityMod.Projectiles.Ranged { for (int i = 0; i < 15; i++) { - Dust dust = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(15f, 15f), ModContent.DustType()); - dust.velocity = (dust.position - projectile.Center) * 0.2f + projectile.velocity; - dust.scale = Main.rand.NextFloat(0.8f, 1.6f); - dust.alpha = Main.rand.Next(30) + 100; - dust.rotation = Main.rand.NextFloat(6.28f); + Particle smoke = new SmallSmokeParticle(projectile.Center + Main.rand.NextVector2Circular(15f, 15f), Vector2.Zero, Color.Orange, new Color(40, 40, 40), Main.rand.NextFloat(0.8f, 1.6f), 145 - Main.rand.Next(30)); + smoke.Velocity = (smoke.Position - projectile.Center) * 0.2f + projectile.velocity; + GeneralParticleHandler.SpawnParticle(smoke); } - //CalamityUtils.ExplosionGores(projectile.Center, 1); } projectile.Kill(); } diff --git a/Projectiles/Ranged/PumplerHoldout.cs b/Projectiles/Ranged/PumplerHoldout.cs index 77730bdfd5..8247a57e1e 100644 --- a/Projectiles/Ranged/PumplerHoldout.cs +++ b/Projectiles/Ranged/PumplerHoldout.cs @@ -10,6 +10,7 @@ using Terraria.Graphics.Effects; using System.Collections.Generic; using Terraria.Graphics.Shaders; using CalamityMod.Dusts; +using CalamityMod.Particles; //TY dom for coding condemnation, great reference, would steal code from again :) @@ -128,11 +129,9 @@ namespace CalamityMod.Projectiles.Ranged for (int i = 0; i < 2 * PumpkinsCharge; i++) { - Dust dust = Dust.NewDustPerfect(tipPosition + Main.rand.NextVector2Circular(10f, 10f), ModContent.DustType()); - dust.velocity = (dust.position - Owner.Center) * 0.3f + Owner.velocity; - dust.scale = Main.rand.NextFloat(0.3f, 0.8f); - dust.alpha = Main.rand.Next(50) + 100; - dust.rotation = Main.rand.NextFloat(6.28f); + Particle smoke = new SmallSmokeParticle(tipPosition + Main.rand.NextVector2Circular(10f, 10f), Vector2.Zero, Color.Orange, new Color(40, 40, 40), Main.rand.NextFloat(0.3f, 0.8f), 145 - Main.rand.Next(50)); + smoke.Velocity = (smoke.Position - Owner.Center) * 0.3f + Owner.velocity; + GeneralParticleHandler.SpawnParticle(smoke); } } diff --git a/Sounds/Custom/MeatySlash.cs b/Sounds/Custom/MeatySlash.cs new file mode 100644 index 0000000000..4033d36113 --- /dev/null +++ b/Sounds/Custom/MeatySlash.cs @@ -0,0 +1,18 @@ +using Microsoft.Xna.Framework.Audio; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Sounds.Custom +{ + public class MeatySlash : ModSound + { + public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type) + { + soundInstance = sound.CreateInstance(); + soundInstance.Volume = volume * 1f; + soundInstance.Pan = pan; + Main.PlaySoundInstance(soundInstance); + return soundInstance; + } + } +} diff --git a/Sounds/Custom/MeatySlash.ogg b/Sounds/Custom/MeatySlash.ogg new file mode 100644 index 0000000000..93c9459ac2 Binary files /dev/null and b/Sounds/Custom/MeatySlash.ogg differ diff --git a/Sounds/Custom/SwiftSlice.cs b/Sounds/Custom/SwiftSlice.cs new file mode 100644 index 0000000000..3f8df43a0b --- /dev/null +++ b/Sounds/Custom/SwiftSlice.cs @@ -0,0 +1,18 @@ +using Microsoft.Xna.Framework.Audio; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Sounds.Custom +{ + public class SwiftSlice : ModSound + { + public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type) + { + soundInstance = sound.CreateInstance(); + soundInstance.Volume = volume * 1f; + soundInstance.Pan = pan; + Main.PlaySoundInstance(soundInstance); + return soundInstance; + } + } +} diff --git a/Sounds/Custom/SwiftSlice.ogg b/Sounds/Custom/SwiftSlice.ogg new file mode 100644 index 0000000000..bc9894c5e6 Binary files /dev/null and b/Sounds/Custom/SwiftSlice.ogg differ diff --git a/Sounds/Custom/ThunderStrike.cs b/Sounds/Custom/ThunderStrike.cs new file mode 100644 index 0000000000..80aec33690 --- /dev/null +++ b/Sounds/Custom/ThunderStrike.cs @@ -0,0 +1,18 @@ +using Microsoft.Xna.Framework.Audio; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Sounds.Custom +{ + public class ThunderStrike : ModSound + { + public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type) + { + soundInstance = sound.CreateInstance(); + soundInstance.Volume = volume * 1f; + soundInstance.Pan = pan; + Main.PlaySoundInstance(soundInstance); + return soundInstance; + } + } +} diff --git a/Sounds/Custom/ThunderStrike.ogg b/Sounds/Custom/ThunderStrike.ogg new file mode 100644 index 0000000000..792f62b553 Binary files /dev/null and b/Sounds/Custom/ThunderStrike.ogg differ diff --git a/Utilities/CalamityRecipes.cs b/Utilities/CalamityRecipes.cs index 38cac5376c..b37ec418a1 100644 --- a/Utilities/CalamityRecipes.cs +++ b/Utilities/CalamityRecipes.cs @@ -1424,6 +1424,18 @@ namespace CalamityMod }); RecipeGroup.RegisterGroup("LunarHamaxe", group); + group = new RecipeGroup(() => "Any Wooden Sword", new int[] + { + ItemID.WoodenSword, + ItemID.BorealWoodSword, + ItemID.RichMahoganySword, + ItemID.PalmWoodSword, + ItemID.EbonwoodSword, + ItemID.ShadewoodSword, + ItemID.PearlwoodSword + }); + RecipeGroup.RegisterGroup("AnyWoodenSword", group); + group = new RecipeGroup(() => "Any Large Gem", new int[] { ItemID.LargeAmber,