From dfbb6f60b22c74673bb90dd313be6d71af86e861 Mon Sep 17 00:00:00 2001 From: IbanPlay <56191483+IbanPlay@users.noreply.github.com> Date: Sat, 8 Jan 2022 01:17:22 +0100 Subject: [PATCH] Base for the mended biome blade --- CalPlayer/CalamityPlayerMiscEffects.cs | 2 + Items/Weapons/Melee/TrueBiomeBlade.cs | 631 ++++++++++++++++++++++++- 2 files changed, 620 insertions(+), 13 deletions(-) diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 5b3dad776b..5741d2c930 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -160,6 +160,8 @@ namespace CalamityMod.CalPlayer // 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(); + // Update the gem tech armor set. GemTechState.Update(); diff --git a/Items/Weapons/Melee/TrueBiomeBlade.cs b/Items/Weapons/Melee/TrueBiomeBlade.cs index d3798af489..bf29b07b69 100644 --- a/Items/Weapons/Melee/TrueBiomeBlade.cs +++ b/Items/Weapons/Melee/TrueBiomeBlade.cs @@ -1,24 +1,161 @@ 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, HolyStar, Marine } + public Attunement? mainAttunement = null; + public Attunement? secondaryAttunement = null; + public int Combo = 0; + public int StoredLunges = 2; + public int PowerLungeCounter = 0; + public override void SetStaticDefaults() { - DisplayName.SetDefault("True Biome Blade"); - Tooltip.SetDefault("Fires different projectiles based on what biome you're in"); + DisplayName.SetDefault("Mended 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_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 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 = ""; //WHAT DO I MAKE IT DO AS AN EXTRA PLLSS IDK ITS SUCH A BORING ATTUNEMENT,,, + 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 do (SOMETHING)"; + 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 charge up a heaven-piercing sword thrust, and release to unleash the devastating blow"; + AttunementInfo.function_extra = "Striking the ground will create an impact so powerful, massive fragments of crystal will rise up from the earth"; + AttunementInfo.color = new Color(220, 143, 255); + break; + case Attunement.HolyStar: + AttunementInfo.name = "Heaven's Abhorrence"; + AttunementInfo.function_description = "Hold LMB to charge up a star-ravaging sword thrust, and release to unleash the devastating blow"; + AttunementInfo.function_extra = "Striking the ground will create an impact so powerful, massive otherwordly monoliths will rise up from the earth"; + AttunementInfo.color = new Color(136, 133, 23); + 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 expand and move much faster"; + 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 +165,501 @@ 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(ItemType()); + recipe.AddIngredient(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(), 10); //Hilarious abyss mats moment. Shall we change that since the abyss gets a attunement anyways + recipe.AddIngredient(ItemType(), 10); + 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, but also set the power lunge counter back to zero + { + StoredLunges = 2; + PowerLungeCounter = 0; } + + //Change the swords function based on its attunement + switch (mainAttunement) + { + case Attunement.Default: + 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.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.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.channel = false; + item.noUseGraphic = true; + item.useStyle = ItemUseStyleID.SwingThrow; + item.shoot = ProjectileType(); + item.shootSpeed = 30; + item.UseSound = null; + item.noMelee = true; + + Combo = 0; + PowerLungeCounter = 0; + break; + case Attunement.Evil: + 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: + case Attunement.HolyStar: + 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.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(); + if (player.whoAmI == Main.myPlayer) + Main.PlaySound(SoundID.DD2_DarkMageHealImpact); + 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())); + } + + 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: + float powerLungeAvailable = 0f; + if (PowerLungeCounter == 3) + { + powerLungeAvailable = 1f; + PowerLungeCounter = 0; + } + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage * 2, knockBack, player.whoAmI, (float)StoredLunges), (float)powerLungeAvailable); + StoredLunges --; + if (StoredLunges < 0) + StoredLunges = 0; + return false; + + case Attunement.Holy: + case Attunement.HolyStar: + float astralVariant = mainAttunement == Attunement.HolyStar ? 1f : 0f; + Projectile.NewProjectile(player.Center, new Vector2(speedX, speedY), ProjectileType(), damage * 2, knockBack, player.whoAmI, astralVariant); + 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.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 = 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; + case Attunement.Holy: + case Attunement.HolyStar: + 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, 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 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) + { + 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, -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 holy = Owner.ZoneHoly; + bool astral = Owner.Calamity().ZoneAstral; + bool marine = Owner.Calamity().ZoneAbyss || Owner.Calamity().ZoneSunkenSea; + + Attunement attunement = Attunement.Default; + + if (jungle) + attunement = Attunement.Tropical; + if (desert || hell) + attunement = Attunement.Hot; + if (snow) + attunement = Attunement.Cold; + if (evil) + attunement = Attunement.Evil; + if (holy) + attunement = Attunement.Holy; + if (astral) + attunement = Attunement.HolyStar; + 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 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; } } }