diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 0e6f433db0..fa805a8d52 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -790,6 +790,18 @@ namespace CalamityMod.CalPlayer public bool daedalusCrystal = false; public bool chaosSpirit = false; public bool redDevil = false; + public bool GemTechSet = false; + private GemTechArmorState gemTechState; + public GemTechArmorState GemTechState + { + get + { + if (gemTechState is null || gemTechState.HasInvalidOwner) + gemTechState = new GemTechArmorState(player.whoAmI); + return gemTechState; + } + set => gemTechState = value; + } #endregion #region Debuff @@ -1551,6 +1563,8 @@ namespace CalamityMod.CalPlayer auricSet = false; auricBoost = false; + GemTechSet = false; + omegaBlueChestplate = false; omegaBlueSet = false; omegaBlueHentai = false; @@ -2393,6 +2407,7 @@ namespace CalamityMod.CalPlayer hasSilvaEffect = false; silvaCountdown = 480; auricSet = false; + GemTechSet = false; omegaBlueChestplate = false; omegaBlueSet = false; omegaBlueCooldown = 0; @@ -2487,6 +2502,7 @@ namespace CalamityMod.CalPlayer elysianFire = false; elysianAegis = false; elysianGuard = false; + GemTechState.OnDeathEffects(); #endregion CurrentlyViewedFactoryID = -1; @@ -3789,6 +3805,9 @@ namespace CalamityMod.CalPlayer { meleeSpeedMult += GetMeleeSpeedBonus(); } + if (GemTechState.IsYellowGemActive) + meleeSpeedMult += GemTechHeadgear.MeleeSpeedBoost; + player.meleeSpeed += meleeSpeedMult; if (player.ActiveItem().type == ModContent.ItemType() || player.ActiveItem().type == ModContent.ItemType() || @@ -4859,6 +4878,9 @@ namespace CalamityMod.CalPlayer if (player.whoAmI != Main.myPlayer) return; + // Handle on-hit melee effects for the gem tech armor set. + GemTechState.MeleeOnHitEffects(target); + if (witheringWeaponEnchant) witheringDamageDone += (int)(damage * (crit ? 2D : 1D)); @@ -4966,6 +4988,10 @@ namespace CalamityMod.CalPlayer if (player.whoAmI != Main.myPlayer) return; + // Handle on-hit melee effects for the gem tech armor set. + if (proj.melee) + GemTechState.MeleeOnHitEffects(target); + if (witheringWeaponEnchant) witheringDamageDone += (int)(damage * (crit ? 2D : 1D)); @@ -5534,7 +5560,7 @@ namespace CalamityMod.CalPlayer // Profaned Soul Crystal encourages use of other weapons, nerfing the damage would not make sense. bool forbidden = player.head == ArmorIDs.Head.AncientBattleArmor && player.body == ArmorIDs.Body.AncientBattleArmor && player.legs == ArmorIDs.Legs.AncientBattleArmor; - bool reducedNerf = fearmongerSet || (forbidden && heldItem.magic); + bool reducedNerf = fearmongerSet || (forbidden && heldItem.magic) || (GemTechSet && GemTechState.IsBlueGemActive); double summonNerfMult = reducedNerf ? 0.75 : 0.5; if (isSummon && !profanedCrystalBuffs) @@ -5578,6 +5604,10 @@ namespace CalamityMod.CalPlayer #endregion + // Handle on-hit ranged effects for the gem tech armor set. + if (proj.ranged) + GemTechState.RangedOnHitEffects(target, damage); + if ((target.damage > 0 || target.boss) && !target.SpawnedFromStatue && CalamityConfig.Instance.Proficiency) { if (gainLevelCooldown <= 0) //max is 12501 to avoid setting off fireworks forever @@ -7576,6 +7606,9 @@ namespace CalamityMod.CalPlayer } } + // Handle hit effects from the gem tech armor set. + player.Calamity().GemTechState.PlayerOnHitEffects((int)damage); + bool hardMode = Main.hardMode; if (player.whoAmI == Main.myPlayer) { @@ -9300,6 +9333,10 @@ namespace CalamityMod.CalPlayer bool hasNonWeaponFunction = isPickaxe || isAxe || isHammer || isPlaced || isChannelable; bool playerUsingWeapon = hasDamage && hasHitboxes && !hasNonWeaponFunction; + // The Gem Tech armor's rogue crystal ensures that stealth is not consumed by non-rogue items. + if ((it.IsAir || !it.Calamity().rogue) && GemTechSet && GemTechState.IsRedGemActive) + playerUsingWeapon = false; + // Animation check depends on whether the item is "clockwork", like Clockwork Assault Rifle. // "Clockwork" weapons can chain-fire multiple stealth strikes (really only 2 max) until you run out of stealth. bool animationCheck = it.useAnimation == it.useTime diff --git a/CalPlayer/CalamityPlayerDrawEffects.cs b/CalPlayer/CalamityPlayerDrawEffects.cs index a2b4753094..aab08b5fc3 100644 --- a/CalPlayer/CalamityPlayerDrawEffects.cs +++ b/CalPlayer/CalamityPlayerDrawEffects.cs @@ -136,6 +136,85 @@ namespace CalamityMod.CalPlayer } }); + public static readonly PlayerLayer GemTechGems = new PlayerLayer("CalamityMod", "GemTechGems", PlayerLayer.Skin, drawInfo => + { + Player drawPlayer = drawInfo.drawPlayer; + CalamityPlayer modPlayer = drawPlayer.Calamity(); + if (drawInfo.shadow != 0f || drawPlayer.dead || !modPlayer.GemTechSet || drawPlayer.Calamity().andromedaState != AndromedaPlayerState.Inactive) + return; + + for (int i = 5; i >= 0; i--) + { + Texture2D gemTexture; + float pulseFactor = 1.8f; + GemTechArmorGemType gemType; + switch (i) + { + case 0: + default: + gemTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/RedGem"); + gemType = GemTechArmorGemType.Rogue; + break; + case 1: + gemTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/YellowGem"); + gemType = GemTechArmorGemType.Melee; + break; + case 2: + gemTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/GreenGem"); + gemType = GemTechArmorGemType.Ranged; + break; + case 3: + gemTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/BlueGem"); + gemType = GemTechArmorGemType.Summoner; + break; + case 4: + gemTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/PurpleGem"); + gemType = GemTechArmorGemType.Magic; + break; + case 5: + gemTexture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/PinkGem"); + gemType = GemTechArmorGemType.Base; + pulseFactor = 2.5f; + break; + } + + // Don't bother doing anything else if the gem is inactive. + if (!modPlayer.GemTechState.GemIsActive(gemType)) + continue; + + float drawOffsetAngle = modPlayer.GemTechState.CalculateGemOffsetAngle(gemType); + float gemOpacity = MathHelper.Lerp(0.85f, 1.05f, (float)Math.Cos(Main.GlobalTime * 2.3f) * 0.5f + 0.5f); + + // Incorporate a sinusoidal pulse into the pulse factor. + pulseFactor *= (float)Math.Cos(Main.GlobalTime * 0.61f + drawOffsetAngle); + + // Somewhat unorthodox way of creating an illusion of gems being drawn behind the player via orbiting. + // Instead of actually messing with a Z position it simply fades away when the sine of the draw + // offset angle is in the low negatives. + gemOpacity *= Utils.InverseLerp(-0.75f, -0.51f, (float)Math.Sin(drawOffsetAngle), true); + + Vector2 baseDrawPosition = modPlayer.GemTechState.CalculateGemPosition(gemType) - Main.screenPosition; + + // Draw back afterimages. + for (int j = 0; j < 5; j++) + { + Color backAfterimageColor = Main.hslToRgb((Main.GlobalTime * 0.47f + j / 5f) % 1f, 1f, 0.67f); + backAfterimageColor = Color.Lerp(backAfterimageColor, Color.White, 0.64f) * gemOpacity * 0.24f; + Vector2 drawPosition = baseDrawPosition + (MathHelper.TwoPi * j / 5f).ToRotationVector2() * pulseFactor; + DrawData gemBackDrawData = new DrawData(gemTexture, drawPosition, null, backAfterimageColor, 0f, gemTexture.Size() * 0.5f, 1f, SpriteEffects.None, 0); + Main.playerDrawData.Add(gemBackDrawData); + } + + // Draw the main gem. + Color baseGemColor = Main.hslToRgb(Main.GlobalTime * 0.51f % 1f, 1f, 0.67f); + baseGemColor = Color.Lerp(baseGemColor, Color.White, 0.56f); + baseGemColor.A = 105; + baseGemColor *= gemOpacity; + DrawData gemDrawData = new DrawData(gemTexture, baseDrawPosition, null, baseGemColor, 0f, gemTexture.Size() * 0.5f, 1f, SpriteEffects.None, 0); + Main.playerDrawData.Add(gemDrawData); + } + }); + public static readonly PlayerLayer MiscEffects = new PlayerLayer("CalamityMod", "MiscEffects", PlayerLayer.MiscEffectsFront, drawInfo => { if (drawInfo.shadow != 0f) @@ -797,6 +876,7 @@ namespace CalamityMod.CalPlayer list.Add(AngelicAllianceAurora); list.Add(IbanDevRobot); list.Add(DyeInvisibilityFix); + list.Add(GemTechGems); } public override void DrawEffects(PlayerDrawInfo drawInfo, ref float r, ref float g, ref float b, ref float a, ref bool fullBright) diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 66c3502a0c..776d59f225 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -131,6 +131,9 @@ namespace CalamityMod.CalPlayer // in the global classes. Attempting to update them there will cause multiple updates to one set for multiple items. CalamityGlobalItem.UpdateAllParticleSets(); + // Update the gem tech armor set. + modPlayer.GemTechState.Update(); + // Regularly sync player stats during multiplayer if (player.whoAmI == Main.myPlayer && Main.netMode == NetmodeID.MultiplayerClient) { @@ -3922,6 +3925,9 @@ namespace CalamityMod.CalPlayer dust.noLight = true; } } + + // Gem Tech stats based on gems. + modPlayer.GemTechState.ProvideGemBoosts(); } #endregion diff --git a/DataStructures/GemTechArmorState.cs b/DataStructures/GemTechArmorState.cs new file mode 100644 index 0000000000..bea1eab94a --- /dev/null +++ b/DataStructures/GemTechArmorState.cs @@ -0,0 +1,403 @@ +using CalamityMod.Items.Armor; +using CalamityMod.Projectiles.Melee; +using CalamityMod.Projectiles.Ranged; +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.DataStructures +{ + public class GemTechArmorState + { + public int OwnerIndex; + public int RedGemRegenerationCountdown; + public int YellowGemRegenerationCountdown; + public int GreenGemRegenerationCountdown; + public int BlueGemRegenerationCountdown; + public int PurpleGemRegenerationCountdown; + public int PinkGemRegenerationCountdown; + public int MeleeCrystalCountdown; + public int LifeRegenBonusCountdown; + public int MultiWeaponLifeRegenBonusCountdown; + public GemTechArmorGemType GemThatShouldBeLost = GemTechArmorGemType.Base; + public GemTechArmorGemType? PreviouslyUsedGem = null; + + public Player Owner => Main.player[OwnerIndex]; + public bool HasInvalidOwner => OwnerIndex < 0 || OwnerIndex >= Main.maxPlayers || !Owner.active; + + public bool IsRedGemActive => RedGemRegenerationCountdown <= 0; + public bool IsYellowGemActive => YellowGemRegenerationCountdown <= 0; + public bool IsGreenGemActive => GreenGemRegenerationCountdown <= 0; + public bool IsBlueGemActive => BlueGemRegenerationCountdown <= 0; + public bool IsPurpleGemActive => PurpleGemRegenerationCountdown <= 0; + public bool IsPinkGemActive => PinkGemRegenerationCountdown <= 0; + public bool AllGemsActive => IsRedGemActive && IsYellowGemActive && IsGreenGemActive && IsBlueGemActive && IsPurpleGemActive && IsPinkGemActive; + + public GemTechArmorState(int ownerIndex) + { + OwnerIndex = ownerIndex; + } + + public bool GemIsActive(GemTechArmorGemType gemType) + { + if (gemType == GemTechArmorGemType.Melee) + return IsYellowGemActive; + if (gemType == GemTechArmorGemType.Ranged) + return IsGreenGemActive; + if (gemType == GemTechArmorGemType.Magic) + return IsPurpleGemActive; + if (gemType == GemTechArmorGemType.Summoner) + return IsBlueGemActive; + if (gemType == GemTechArmorGemType.Rogue) + return IsRedGemActive; + if (gemType == GemTechArmorGemType.Base) + return IsPinkGemActive; + + return false; + } + + public void Update() + { + // Calculate the gem that should be lost. + if (!Owner.ActiveItem().IsAir) + { + if (Owner.ActiveItem().melee) + GemThatShouldBeLost = GemTechArmorGemType.Melee; + if (Owner.ActiveItem().ranged) + GemThatShouldBeLost = GemTechArmorGemType.Ranged; + if (Owner.ActiveItem().magic) + GemThatShouldBeLost = GemTechArmorGemType.Magic; + if (Owner.ActiveItem().summon) + GemThatShouldBeLost = GemTechArmorGemType.Summoner; + if (Owner.ActiveItem().Calamity().rogue) + GemThatShouldBeLost = GemTechArmorGemType.Rogue; + } + + // Mark the base gem for loss if the gem for the previously used item's class is not present. + if (!GemIsActive(GemThatShouldBeLost)) + GemThatShouldBeLost = GemTechArmorGemType.Base; + + // Decrement countdowns. + if (RedGemRegenerationCountdown > 0) + { + RedGemRegenerationCountdown--; + if (RedGemRegenerationCountdown == 0) + CreateRegenerationEffect(GemTechArmorGemType.Rogue); + } + if (YellowGemRegenerationCountdown > 0) + { + YellowGemRegenerationCountdown--; + if (YellowGemRegenerationCountdown == 0) + CreateRegenerationEffect(GemTechArmorGemType.Melee); + } + if (GreenGemRegenerationCountdown > 0) + { + GreenGemRegenerationCountdown--; + if (GreenGemRegenerationCountdown == 0) + CreateRegenerationEffect(GemTechArmorGemType.Ranged); + } + if (BlueGemRegenerationCountdown > 0) + { + BlueGemRegenerationCountdown--; + if (BlueGemRegenerationCountdown == 0) + CreateRegenerationEffect(GemTechArmorGemType.Summoner); + } + if (PurpleGemRegenerationCountdown > 0) + { + PurpleGemRegenerationCountdown--; + if (PurpleGemRegenerationCountdown == 0) + CreateRegenerationEffect(GemTechArmorGemType.Magic); + } + if (PinkGemRegenerationCountdown > 0) + { + PinkGemRegenerationCountdown--; + if (PinkGemRegenerationCountdown == 0) + CreateRegenerationEffect(GemTechArmorGemType.Base); + } + + if (MeleeCrystalCountdown > 0) + { + MeleeCrystalCountdown--; + + // Make the crystal fire countdown go down faster if holding a true melee item. + if (Owner.ActiveItem().melee && (Owner.ActiveItem().shoot == ProjectileID.None || Owner.ActiveItem().Calamity().trueMelee)) + MeleeCrystalCountdown--; + + // Ensure the crystal cooldown does not go below 0 due to the second decrement. + if (MeleeCrystalCountdown < 0) + MeleeCrystalCountdown = 0; + } + + if (LifeRegenBonusCountdown > 0) + LifeRegenBonusCountdown--; + + if (MultiWeaponLifeRegenBonusCountdown > 0) + MultiWeaponLifeRegenBonusCountdown = 0; + } + + public void MeleeOnHitEffects(NPC target) + { + if (!Owner.Calamity().GemTechSet || !IsYellowGemActive || Main.myPlayer != OwnerIndex || MeleeCrystalCountdown > 0) + return; + + int damage = (int)(GemTechHeadgear.MeleeShardBaseDamage * Owner.MeleeDamage()); + for (int i = 0; i < 7; i++) + { + Vector2 shootVelocity = (MathHelper.TwoPi * i / 7f + Main.rand.NextFloatDirection() * 0.23f).ToRotationVector2() * 4.25f; + Projectile.NewProjectile(target.Center, shootVelocity, ModContent.ProjectileType(), damage, 0f, OwnerIndex); + } + + MeleeCrystalCountdown = GemTechHeadgear.MeleeShardDelay; + } + + public void RangedOnHitEffects(NPC target, int hitDamage) + { + bool hasReachedProjCountLimit = Owner.ownedProjectileCounts[ModContent.ProjectileType()] > GemTechHeadgear.MaxFlechettes; + if (!Owner.Calamity().GemTechSet || !IsGreenGemActive || Main.myPlayer != OwnerIndex || hasReachedProjCountLimit) + return; + + int tries = 0; + float spawnOffsetFactor = 150f; + Vector2 flechetteSpawnOffset = Main.rand.NextVector2CircularEdge(spawnOffsetFactor, spawnOffsetFactor); + + // Try to avoid spawning projectiles in tiles. + // If this is not possible, nothing is spawned. + do + { + Vector2 spawnPosition = target.Center + flechetteSpawnOffset; + if (!Collision.SolidCollision(spawnPosition, 1, 1)) + { + int damage = CalamityUtils.DamageSoftCap((int)(hitDamage * 0.32f), 400); + Vector2 shootVelocity = flechetteSpawnOffset.SafeNormalize(Vector2.UnitY) * -20f; + Projectile.NewProjectile(spawnPosition, shootVelocity, ModContent.ProjectileType(), damage, 0f, OwnerIndex); + break; + } + + tries++; + } + while (tries < 50); + } + + public void OnItemUseEffects(Item item) + { + if (item.IsAir || item.damage <= 0) + return; + + LifeRegenBonusCountdown = GemTechHeadgear.AllGemsLifeRegenBoostTime; + GemTechArmorGemType? usedGemType = null; + + if (item.melee) + usedGemType = GemTechArmorGemType.Melee; + if (item.ranged) + usedGemType = GemTechArmorGemType.Ranged; + if (item.magic) + usedGemType = GemTechArmorGemType.Magic; + if (item.summon) + usedGemType = GemTechArmorGemType.Summoner; + if (item.Calamity().rogue) + usedGemType = GemTechArmorGemType.Rogue; + + // The previously used gem has been defined and is different than the currently used one, set the + // extra life regen bonus for using a different class. + if (PreviouslyUsedGem != null && usedGemType != PreviouslyUsedGem) + MultiWeaponLifeRegenBonusCountdown = GemTechHeadgear.AllGemsMultiWeaponLifeRegenBoostTime; + + if (usedGemType.HasValue) + PreviouslyUsedGem = usedGemType; + } + + public void PlayerOnHitEffects(int hitDamage) + { + bool gemWasLost = false; + int gemDamage = 0; + if (hitDamage >= GemTechHeadgear.GemBreakDamageLowerBound) + { + // Destroy the rogue gem. + if (GemIsActive(GemTechArmorGemType.Rogue) && GemThatShouldBeLost == GemTechArmorGemType.Rogue) + { + RedGemRegenerationCountdown = GemTechHeadgear.GemRegenTime; + gemDamage = (int)(GemTechHeadgear.GemDamage * Owner.RogueDamage()); + gemWasLost = true; + } + + // Destroy the melee gem. + if (GemIsActive(GemTechArmorGemType.Melee) && GemThatShouldBeLost == GemTechArmorGemType.Melee) + { + YellowGemRegenerationCountdown = GemTechHeadgear.GemRegenTime; + gemDamage = (int)(GemTechHeadgear.GemDamage * Owner.MeleeDamage()); + gemWasLost = true; + } + + // Destroy the ranged gem. + if (GemIsActive(GemTechArmorGemType.Ranged) && GemThatShouldBeLost == GemTechArmorGemType.Ranged) + { + GreenGemRegenerationCountdown = GemTechHeadgear.GemRegenTime; + gemDamage = (int)(GemTechHeadgear.GemDamage * Owner.RangedDamage()); + gemWasLost = true; + } + + // Destroy the summoner gem. + if (GemIsActive(GemTechArmorGemType.Ranged) && GemThatShouldBeLost == GemTechArmorGemType.Summoner) + { + BlueGemRegenerationCountdown = GemTechHeadgear.GemRegenTime; + gemDamage = (int)(GemTechHeadgear.GemDamage * Owner.MinionDamage()); + gemWasLost = true; + } + + // Destroy the magic gem. + if (GemIsActive(GemTechArmorGemType.Magic) && GemThatShouldBeLost == GemTechArmorGemType.Magic) + { + PurpleGemRegenerationCountdown = GemTechHeadgear.GemRegenTime; + gemDamage = (int)(GemTechHeadgear.GemDamage * Owner.MinionDamage()); + gemWasLost = true; + } + + // Destroy the base gem. + if (GemIsActive(GemTechArmorGemType.Base) && GemThatShouldBeLost == GemTechArmorGemType.Base) + { + PinkGemRegenerationCountdown = GemTechHeadgear.GemRegenTime; + gemDamage = (int)(GemTechHeadgear.GemDamage * Owner.AverageDamage()); + gemWasLost = true; + } + } + + if (gemWasLost) + { + Main.PlaySound(SoundID.DD2_WitherBeastCrystalImpact); + Vector2 gemPosition = CalculateGemPosition(GemThatShouldBeLost); + + // Softcap the damage. This is done primarily to dampen stealth interactions. + gemDamage = CalamityUtils.DamageSoftCap(gemDamage, 100000); + + if (Main.myPlayer == OwnerIndex) + Projectile.NewProjectile(gemPosition, Vector2.Zero, ModContent.ProjectileType(), gemDamage, 0f, OwnerIndex, 0f, (int)GemThatShouldBeLost); + } + } + + public void OnDeathEffects() + { + // Reset countdowns. + RedGemRegenerationCountdown = 0; + YellowGemRegenerationCountdown = 0; + GreenGemRegenerationCountdown = 0; + BlueGemRegenerationCountdown = 0; + PurpleGemRegenerationCountdown = 0; + PinkGemRegenerationCountdown = 0; + } + + public void ProvideGemBoosts() + { + // Don't apply benefits if the armor set isn't being worn. + if (!Owner.Calamity().GemTechSet) + return; + + // The rogue stealth max is present in the Gem Tech Headgear file. + if (IsRedGemActive) + { + Owner.Calamity().throwingCrit += (int)(GemTechHeadgear.RogueCritBoost * 100f); + Owner.Calamity().throwingDamage += GemTechHeadgear.RogueDamageBoost; + } + + // The melee speed boost code is present in the Player Misc Effects file. + if (IsYellowGemActive) + { + Owner.meleeCrit += (int)(GemTechHeadgear.MeleeCritBoost * 100f); + Owner.meleeDamage += GemTechHeadgear.MeleeDamageBoost; + } + + if (IsGreenGemActive) + { + Owner.rangedCrit += (int)(GemTechHeadgear.RangedCritBoost * 100f); + Owner.rangedDamage += GemTechHeadgear.RangedDamageBoost; + } + + if (IsBlueGemActive) + { + Owner.maxMinions += GemTechHeadgear.SummonMinionCountBoost; + Owner.minionDamage += GemTechHeadgear.SummonDamageBoost; + } + + if (IsPurpleGemActive) + { + Owner.statManaMax2 += GemTechHeadgear.MagicManaBoost; + Owner.magicCrit += (int)(GemTechHeadgear.MagicCritBoost * 100f); + Owner.magicDamage += GemTechHeadgear.MagicDamageBoost; + } + + if (IsPinkGemActive) + { + Owner.statDefense += GemTechHeadgear.BaseGemDefenseBoost; + Owner.lifeRegen += GemTechHeadgear.BaseGemLifeRegenBoost; + Owner.moveSpeed += GemTechHeadgear.BaseGemMovementSpeedBoost; + Owner.jumpSpeedBoost += GemTechHeadgear.BaseGemJumpSpeedBoost; + Owner.endurance += GemTechHeadgear.BaseGemDRBoost; + } + + if (LifeRegenBonusCountdown > 0 && AllGemsActive) + { + if (MultiWeaponLifeRegenBonusCountdown > 0) + Owner.lifeRegen += GemTechHeadgear.AllGemsMultiWeaponUseLifeRegenBoost; + else + Owner.lifeRegen += GemTechHeadgear.AllGemsWeaponUseLifeRegenBoost; + } + + if (!Owner.ActiveItem().IsAir && !Owner.ActiveItem().magic) + Owner.manaRegen += GemTechHeadgear.NonMagicItemManaRegenBoost; + } + + public float CalculateGemOffsetAngle(GemTechArmorGemType gemType) + { + return MathHelper.TwoPi * (int)gemType / 6f + Main.GlobalTime * 3.41f; + } + + public Vector2 CalculateGemPosition(GemTechArmorGemType gemType) + { + Vector2 baseDrawOffsetDirection = CalculateGemOffsetAngle(gemType).ToRotationVector2() * new Vector2(1f, 0.2f); + Vector2 gemPosition = Owner.Center + baseDrawOffsetDirection * Owner.width * 1.25f; + gemPosition.Y += Owner.gfxOffY; + if (Owner.mount?.Active ?? false) + gemPosition.Y += Owner.mount.YOffset; + return gemPosition; + } + + public void CreateRegenerationEffect(GemTechArmorGemType gemType) + { + // Create a little visual effect to accompany the return of the gem and play a magic sound. + Main.PlaySound(SoundID.DD2_DarkMageHealImpact, Owner.Center); + + for (int i = 0; i < 12; i++) + { + Dust energyPuff = Dust.NewDustPerfect(CalculateGemPosition(gemType), 267); + energyPuff.velocity = (MathHelper.TwoPi * i / 12f).ToRotationVector2() * 5f; + energyPuff.color = GetColorFromGemType(gemType); + energyPuff.scale = 1.125f; + energyPuff.alpha = 175; + energyPuff.noGravity = true; + } + } + + public static Color GetColorFromGemType(GemTechArmorGemType gemType) + { + switch (gemType) + { + case GemTechArmorGemType.Rogue: + return new Color(224, 24, 0); + case GemTechArmorGemType.Melee: + return new Color(237, 170, 43); + case GemTechArmorGemType.Ranged: + return new Color(37, 188, 108); + case GemTechArmorGemType.Summoner: + return new Color(37, 119, 206); + case GemTechArmorGemType.Magic: + return new Color(200, 58, 209); + case GemTechArmorGemType.Base: + return new Color(255, 115, 206); + } + + // Return a transparent color as a fallback. + return Color.Transparent; + } + } +} diff --git a/Enums/GemTechArmorGemType.cs b/Enums/GemTechArmorGemType.cs new file mode 100644 index 0000000000..e2c5e7217c --- /dev/null +++ b/Enums/GemTechArmorGemType.cs @@ -0,0 +1,12 @@ +namespace CalamityMod +{ + public enum GemTechArmorGemType + { + Melee, + Ranged, + Magic, + Summoner, + Rogue, + Base + } +} diff --git a/ExtraTextures/GemTechArmor/BlueGem.png b/ExtraTextures/GemTechArmor/BlueGem.png new file mode 100644 index 0000000000..25eef1ad4b Binary files /dev/null and b/ExtraTextures/GemTechArmor/BlueGem.png differ diff --git a/ExtraTextures/GemTechArmor/GreenGem.png b/ExtraTextures/GemTechArmor/GreenGem.png new file mode 100644 index 0000000000..6bfe98eb07 Binary files /dev/null and b/ExtraTextures/GemTechArmor/GreenGem.png differ diff --git a/ExtraTextures/GemTechArmor/PinkGem.png b/ExtraTextures/GemTechArmor/PinkGem.png new file mode 100644 index 0000000000..c170b56d73 Binary files /dev/null and b/ExtraTextures/GemTechArmor/PinkGem.png differ diff --git a/ExtraTextures/GemTechArmor/PurpleGem.png b/ExtraTextures/GemTechArmor/PurpleGem.png new file mode 100644 index 0000000000..80dd5f0f6a Binary files /dev/null and b/ExtraTextures/GemTechArmor/PurpleGem.png differ diff --git a/ExtraTextures/GemTechArmor/RedGem.png b/ExtraTextures/GemTechArmor/RedGem.png new file mode 100644 index 0000000000..627f151b0f Binary files /dev/null and b/ExtraTextures/GemTechArmor/RedGem.png differ diff --git a/ExtraTextures/GemTechArmor/YellowGem.png b/ExtraTextures/GemTechArmor/YellowGem.png new file mode 100644 index 0000000000..3ffaf0d250 Binary files /dev/null and b/ExtraTextures/GemTechArmor/YellowGem.png differ diff --git a/Items/Armor/GemTechBodyArmor.cs b/Items/Armor/GemTechBodyArmor.cs new file mode 100644 index 0000000000..75349e89ae --- /dev/null +++ b/Items/Armor/GemTechBodyArmor.cs @@ -0,0 +1,47 @@ +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.CalPlayer; +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.Furniture.CraftingStations; +using CalamityMod.World; +using System.Collections.Generic; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Armor +{ + [AutoloadEquip(EquipType.Body)] + public class GemTechBodyArmor : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gem Tech Body Armor"); + Tooltip.SetDefault("You sunk low enough for me to reach."); + } + + public override void SetDefaults() + { + item.width = 48; + item.height = 32; + item.defense = 31; + item.rare = ItemRarityID.Purple; + + // Exact worth of the armor piece's constituents. + item.value = Item.sellPrice(platinum: 9, gold: 79, silver: 80); + item.Calamity().customRarity = CalamityRarity.Violet; + item.Calamity().donorItem = true; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 16); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Armor/GemTechBodyArmor.png b/Items/Armor/GemTechBodyArmor.png new file mode 100644 index 0000000000..17ddd64a32 Binary files /dev/null and b/Items/Armor/GemTechBodyArmor.png differ diff --git a/Items/Armor/GemTechBodyArmor_Arms.png b/Items/Armor/GemTechBodyArmor_Arms.png new file mode 100644 index 0000000000..c854e89cef Binary files /dev/null and b/Items/Armor/GemTechBodyArmor_Arms.png differ diff --git a/Items/Armor/GemTechBodyArmor_Body.png b/Items/Armor/GemTechBodyArmor_Body.png new file mode 100644 index 0000000000..f1080ed77c Binary files /dev/null and b/Items/Armor/GemTechBodyArmor_Body.png differ diff --git a/Items/Armor/GemTechHeadgear.cs b/Items/Armor/GemTechHeadgear.cs new file mode 100644 index 0000000000..c9a5ffa8ff --- /dev/null +++ b/Items/Armor/GemTechHeadgear.cs @@ -0,0 +1,115 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Microsoft.Xna.Framework; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Armor +{ + [AutoloadEquip(EquipType.Head)] + public class GemTechHeadgear : ModItem + { + public const int GemBreakDamageLowerBound = 100; + public const int GemDamage = 40000; + public const int GemRegenTime = 1800; + + public const int MeleeShardBaseDamage = 825; + public const int MeleeShardDelay = 330; + public const float MeleeDamageBoost = 0.45f; + public const float MeleeCritBoost = 0.12f; + public const float MeleeSpeedBoost = 0.26f; + + public const int MaxFlechettes = 8; + public const float RangedDamageBoost = 0.5f; + public const float RangedCritBoost = 0.16f; + + public const int MagicManaBoost = 100; + public const int NonMagicItemManaRegenBoost = 8; + public const float MagicDamageBoost = 0.5f; + public const float MagicCritBoost = 0.16f; + + public const int SummonMinionCountBoost = 4; + public const float SummonDamageBoost = 0.72f; + + public const int RogueStealthBoost = 130; + public const float RogueDamageBoost = 0.5f; + public const float RogueCritBoost = 0.16f; + + public const int BaseGemDefenseBoost = 75; + public const int BaseGemLifeRegenBoost = 2; + public const float BaseGemDRBoost = 0.12f; + public const float BaseGemMovementSpeedBoost = 0.4f; + public const float BaseGemJumpSpeedBoost = 0.4f; + + public const int AllGemsWeaponUseLifeRegenBoost = 2; + public const int AllGemsMultiWeaponUseLifeRegenBoost = 3; + public const int AllGemsLifeRegenBoostTime = 480; + public const int AllGemsMultiWeaponLifeRegenBoostTime = 150; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gem Tech Headgear"); + Tooltip.SetDefault("The Devil said: Revel in your victory; You've earned your damning. Pack your things and leave."); + } + + public override void SetDefaults() + { + item.width = 40; + item.height = 32; + item.defense = 14; + item.rare = ItemRarityID.Purple; + + // Exact worth of the armor piece's constituents. + item.value = Item.sellPrice(platinum: 6, gold: 14, silver: 88); + item.Calamity().customRarity = CalamityRarity.Violet; + item.Calamity().donorItem = true; + } + + public override bool IsArmorSet(Item head, Item body, Item legs) + { + return body.type == ModContent.ItemType() && legs.type == ModContent.ItemType(); + } + + public override void UpdateArmorSet(Player player) + { + player.Calamity().GemTechSet = true; + player.Calamity().wearingRogueArmor = true; + if (player.Calamity().GemTechState.IsRedGemActive) + player.Calamity().rogueStealthMax += RogueStealthBoost * 0.01f; + + string redGemText = $"The red gem grants {RogueStealthBoost} maximum stealth, increased rogue stats, and makes stealth only consumable by rogue weapons\n"; + string yellowGemText = $"The yellow gem provides increased melee stats and makes melee attacks release shards on hit with a cooldown. This cooldown is shorter for true melee attacks\n"; + string greenGemText = $"The green gem provides increased ranged stats and causes flechettes to fly swiftly towards targets when they are damaged by a ranged projectile\n"; + string blueGemText = $"The blue gem grants {SummonMinionCountBoost} extra maximum minions, increased minion damage, and reduces the penalty for summoner items while holding a non-summoner weapon\n"; + string purpleGemText = $"The violet gem grants {MagicManaBoost} extra maximum mana, increased magic stats, and makes mana rapidly regenerate when holding a non-magic weapon\n"; + string pinkGemText = $"The pink base gem grants {BaseGemDefenseBoost} extra defense, extra damage reduction, increased movement speed, jump speed, and +{BaseGemLifeRegenBoost} life regen\n"; + + player.setBonus = "Six gem fragments idly orbit you; one for each class, and a base gem\n" + + $"A gem is lost when you take more than {GemBreakDamageLowerBound} damage in a single hit. The type of gem lost is the same as the class of the previous when you used\n" + + "If said gem has already been lost, the base gem is lost instead\n" + + $"When a gem is lost, it breaks off and homes towards the nearest enemy or boss, if one is present, dealing a base of {GemDamage} damage\n" + + $"Gems have a {GemRegenTime / 60} second delay before they appear again\n" + + redGemText + + yellowGemText + + greenGemText + + blueGemText + + purpleGemText + + pinkGemText + + $"When all gems exist simultaneously, hitting a target with any weapon grants you +{AllGemsWeaponUseLifeRegenBoost} life regen for {AllGemsLifeRegenBoostTime / 60} seconds\n" + + $"This is increased to +{AllGemsMultiWeaponUseLifeRegenBoost} life regen if a weapon of another class is used during that {AllGemsLifeRegenBoostTime / 60} second period for {AllGemsMultiWeaponLifeRegenBoostTime / 60f} seconds"; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 10); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Armor/GemTechHeadgear.png b/Items/Armor/GemTechHeadgear.png new file mode 100644 index 0000000000..a4fcb0ce81 Binary files /dev/null and b/Items/Armor/GemTechHeadgear.png differ diff --git a/Items/Armor/GemTechHeadgear_Head.png b/Items/Armor/GemTechHeadgear_Head.png new file mode 100644 index 0000000000..dac1356df5 Binary files /dev/null and b/Items/Armor/GemTechHeadgear_Head.png differ diff --git a/Items/Armor/GemTechSchynbaulds.cs b/Items/Armor/GemTechSchynbaulds.cs new file mode 100644 index 0000000000..727d81f4e4 --- /dev/null +++ b/Items/Armor/GemTechSchynbaulds.cs @@ -0,0 +1,42 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Armor +{ + [AutoloadEquip(EquipType.Legs)] + public class GemTechSchynbaulds : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gem Tech Schynbaulds"); + Tooltip.SetDefault("If they hurt you, kick them down."); + } + + public override void SetDefaults() + { + item.width = 28; + item.height = 26; + item.defense = 24; + item.rare = ItemRarityID.Purple; + + // Exact worth of the armor piece's constituents. + item.value = Item.sellPrice(platinum: 7, gold: 35, silver: 84); + item.Calamity().customRarity = CalamityRarity.Violet; + item.Calamity().donorItem = true; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 12); + recipe.AddIngredient(ModContent.ItemType(), 4); + recipe.AddIngredient(ModContent.ItemType(), 3); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Armor/GemTechSchynbaulds.png b/Items/Armor/GemTechSchynbaulds.png new file mode 100644 index 0000000000..81beb64668 Binary files /dev/null and b/Items/Armor/GemTechSchynbaulds.png differ diff --git a/Items/Armor/GemTechSchynbaulds_Legs.png b/Items/Armor/GemTechSchynbaulds_Legs.png new file mode 100644 index 0000000000..7d484a034d Binary files /dev/null and b/Items/Armor/GemTechSchynbaulds_Legs.png differ diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index 2b86fc8adc..04ff890bb2 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -803,7 +803,10 @@ namespace CalamityMod.Items } } - if (item.type == ItemID.MonkStaffT1 || CalamityLists.spearAutoreuseList.Contains(item.type)) + // Handle general use-item effects for the Gem Tech Armor. + player.Calamity().GemTechState.OnItemUseEffects(item); + + if (item.type == ItemID.MonkStaffT1 || CalamityLists.spearAutoreuseList.Contains(item.type)) { return player.ownedProjectileCounts[item.shoot] <= 0; } diff --git a/Projectiles/Melee/GemTechYellowShard.cs b/Projectiles/Melee/GemTechYellowShard.cs new file mode 100644 index 0000000000..1fbe1809bf --- /dev/null +++ b/Projectiles/Melee/GemTechYellowShard.cs @@ -0,0 +1,69 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class GemTechYellowShard : ModProjectile + { + public const int IntangibleFrames = 12; + + public ref float Time => ref projectile.ai[0]; + + public override string Texture => "CalamityMod/ExtraTextures/GemTechArmor/YellowGem"; + + public override void SetStaticDefaults() => DisplayName.SetDefault("Trireme's Yellow Gem"); + + public override void SetDefaults() + { + projectile.width = 12; + projectile.height = 12; + projectile.friendly = true; + projectile.melee = true; + projectile.penetrate = 1; + projectile.MaxUpdates = 2; + projectile.timeLeft = 180; + projectile.ignoreWater = true; + } + + public override void AI() + { + if (projectile.FinalExtraUpdate()) + Time++; + + if (Time >= IntangibleFrames) + { + NPC potentialTarget = projectile.Center.ClosestNPCAt(750f); + + if (potentialTarget != null) + projectile.velocity = (projectile.velocity * 24f + projectile.SafeDirectionTo(potentialTarget.Center) * 9f) / 25f; + } + + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + + public override void Kill(int timeLeft) + { + // Play a shatter sound. + Main.PlaySound(SoundID.Item27, projectile.Center); + + // Create a triangular puff of yellow dust. + Vector2 initialVelocity = Vector2.UnitX * Main.rand.NextFloat(2f, 3.3f); + for (int i = 0; i < 4; i++) + { + Dust crystalShard = Dust.NewDustPerfect(projectile.Center, 267); + crystalShard.velocity = initialVelocity * i / 4f; + crystalShard.scale = 1.225f; + crystalShard.color = Color.Yellow; + crystalShard.noGravity = true; + + Dust.CloneDust(crystalShard).velocity = initialVelocity.RotatedBy(MathHelper.Pi * 0.666f) * i / 4f; + Dust.CloneDust(crystalShard).velocity = initialVelocity.RotatedBy(MathHelper.Pi * -0.666f) * i / 4f; + } + } + + // Cannot deal damage for the first several frames of existence. + public override bool CanDamage() => Time >= IntangibleFrames; + } +} diff --git a/Projectiles/Ranged/GemTechGreenFlechette.cs b/Projectiles/Ranged/GemTechGreenFlechette.cs new file mode 100644 index 0000000000..7c2a920562 --- /dev/null +++ b/Projectiles/Ranged/GemTechGreenFlechette.cs @@ -0,0 +1,76 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class GemTechGreenFlechette : ModProjectile + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Gem Tech Flechette"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 4; + } + + public override void SetDefaults() + { + projectile.width = 12; + projectile.height = 12; + projectile.friendly = true; + projectile.ranged = true; + projectile.ignoreWater = true; + projectile.penetrate = 1; + projectile.timeLeft = 180; + } + + public override void AI() + { + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + projectile.Opacity = Utils.InverseLerp(180f, 174f, projectile.timeLeft, true); + + if (projectile.localAI[0] == 0f) + { + // Create a circular puff of green dust. + float initialSpeed = Main.rand.NextFloat(2.5f, 4.5f); + for (int i = 0; i < 12; i++) + { + Dust crystalShard = Dust.NewDustPerfect(projectile.Center, 267); + crystalShard.velocity = (MathHelper.TwoPi * i / 12f).ToRotationVector2() * initialSpeed * Main.rand.NextFloat(0.6f, 1f); + crystalShard.velocity = crystalShard.velocity.RotatedByRandom(0.37f); + crystalShard.scale = 1.25f; + crystalShard.color = Color.ForestGreen; + crystalShard.noGravity = true; + } + projectile.localAI[0] = 1f; + } + } + + public override void Kill(int timeLeft) + { + // Play a shatter sound. + Main.PlaySound(SoundID.Item27, projectile.Center); + + // Create a circular puff of green dust. + float initialSpeed = Main.rand.NextFloat(2.5f, 4.5f); + for (int i = 0; i < 16; i++) + { + Dust crystalShard = Dust.NewDustPerfect(projectile.Center, 267); + crystalShard.velocity = (MathHelper.TwoPi * i / 16f).ToRotationVector2() * initialSpeed; + crystalShard.scale = 1.25f; + crystalShard.color = Color.ForestGreen; + crystalShard.noGravity = true; + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + lightColor = Color.Lerp(lightColor, Color.White, 0.5f); + lightColor.A = 84; + CalamityUtils.DrawAfterimagesCentered(projectile, ProjectileID.Sets.TrailingMode[projectile.type], lightColor); + return false; + } + } +} diff --git a/Projectiles/Ranged/GemTechGreenFlechette.png b/Projectiles/Ranged/GemTechGreenFlechette.png new file mode 100644 index 0000000000..a98eb6a006 Binary files /dev/null and b/Projectiles/Ranged/GemTechGreenFlechette.png differ diff --git a/Projectiles/Typeless/GemTechArmorGem.cs b/Projectiles/Typeless/GemTechArmorGem.cs new file mode 100644 index 0000000000..bce29d5271 --- /dev/null +++ b/Projectiles/Typeless/GemTechArmorGem.cs @@ -0,0 +1,188 @@ +using CalamityMod.DataStructures; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class GemTechArmorGem : ModProjectile + { + public ref float Time => ref projectile.ai[0]; + public ref float Variant => ref projectile.ai[1]; + public const int UpwardFlyTime = 24; + public const int RedirectTime = 12; + public PrimitiveTrail FlameTrailDrawer = null; + public override string Texture => "CalamityMod/ExtraTextures/GemTechArmor/YellowGem"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Trireme's Gem"); + ProjectileID.Sets.TrailingMode[projectile.type] = 1; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 20; + } + + public override void SetDefaults() + { + projectile.width = projectile.height = 14; + projectile.friendly = true; + projectile.ignoreWater = true; + projectile.tileCollide = false; + projectile.penetrate = 2; + projectile.MaxUpdates = 2; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 13; + projectile.timeLeft = projectile.MaxUpdates * 420; + projectile.Calamity().rogue = true; + } + + public Color GemColor => GemTechArmorState.GetColorFromGemType((GemTechArmorGemType)Variant); + + public override void AI() + { + // Create a puff of energy on the first frame. + if (projectile.localAI[0] == 0f) + { + for (int i = 0; i < 7; i++) + { + Dust energyPuff = Dust.NewDustPerfect(projectile.Center, 267); + energyPuff.velocity = -Vector2.UnitY.RotatedByRandom(0.81f) * Main.rand.NextFloat(1.25f, 4.5f); + energyPuff.color = Color.Lerp(GemColor, Color.White, Main.rand.NextFloat(0.5f)); + energyPuff.scale = 1.1f; + energyPuff.alpha = 185; + energyPuff.noGravity = true; + } + projectile.localAI[0] = 1f; + } + + // This intentionally uses boss priority when homing. + NPC potentialTarget = projectile.Center.ClosestNPCAt(2700f, true, true); + + // Increment the timer on the last extra update. + if (projectile.FinalExtraUpdate()) + Time++; + + // Fly into the air. + if (Time < UpwardFlyTime) + { + projectile.velocity = Vector2.Lerp(projectile.velocity, -Vector2.UnitY * 3f, 0.1f); + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + return; + } + + // Point at nearby targets, if there is one. Also rapidly stop in place. + if (Time < UpwardFlyTime + RedirectTime) + { + if (potentialTarget != null) + { + float angleToTarget = projectile.AngleTo(potentialTarget.Center) + MathHelper.PiOver2; + projectile.rotation = projectile.rotation.AngleLerp(angleToTarget, 0.225f).AngleTowards(angleToTarget, 0.6f); + projectile.velocity = projectile.velocity.MoveTowards(Vector2.Zero, 1.9f) * 0.9f; + } + return; + } + + // Create some visual and acoustic effects right before charging. + if (Time == UpwardFlyTime + RedirectTime && projectile.FinalExtraUpdate()) + { + Main.PlaySound(SoundID.Item72, projectile.Center); + for (int i = 0; i < 12; i++) + { + Dust energyPuff = Dust.NewDustPerfect(projectile.Center, 267); + energyPuff.velocity = (MathHelper.TwoPi * i / 12f).ToRotationVector2() * 5f; + energyPuff.color = GemColor; + energyPuff.scale = 1.125f; + energyPuff.alpha = 175; + energyPuff.noGravity = true; + } + } + + // Rapidly move towards the nearest target. + if (potentialTarget != null && projectile.penetrate >= projectile.maxPenetrate) + { + float distanceFromTarget = projectile.Distance(potentialTarget.Center); + float moveInterpolant = Utils.InverseLerp(0f, 100f, distanceFromTarget, true) * Utils.InverseLerp(600f, 400f, distanceFromTarget, true); + Vector2 targetCenterOffsetVec = potentialTarget.Center - projectile.Center; + float movementSpeed = MathHelper.Min(37.5f, targetCenterOffsetVec.Length()); + Vector2 idealVelocity = targetCenterOffsetVec.SafeNormalize(Vector2.Zero) * movementSpeed; + + // Ensure velocity never has a magnitude less than 4. + if (projectile.velocity.Length() < 4f) + projectile.velocity += projectile.velocity.RotatedBy(MathHelper.PiOver4).SafeNormalize(Vector2.Zero) * 4f; + + // Die if anything goes wrong with the velocity. + if (projectile.velocity.HasNaNs()) + projectile.Kill(); + + // Approach the ideal velocity. + projectile.velocity = Vector2.Lerp(projectile.velocity, idealVelocity, moveInterpolant * 0.08f); + projectile.velocity = projectile.velocity.MoveTowards(idealVelocity, 2f); + } + } + + public override bool CanDamage() => Time > UpwardFlyTime + RedirectTime; + + public Color TrailColor(float completionRatio) + { + float trailOpacity = Utils.InverseLerp(0f, 0.067f, completionRatio, true) * Utils.InverseLerp(0.7f, 0.58f, completionRatio, true); + Color startingColor = Color.Lerp(Color.White, GemColor, 0.47f); + Color middleColor = GemColor; + Color endColor = Color.Transparent; + return CalamityUtils.MulticolorLerp(completionRatio, startingColor, middleColor, endColor) * trailOpacity; + } + + public static float TrailWidth(float completionRatio) => MathHelper.SmoothStep(12f, 4.25f, completionRatio); + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + if (FlameTrailDrawer is null) + FlameTrailDrawer = new PrimitiveTrail(TrailWidth, TrailColor, null, GameShaders.Misc["CalamityMod:ImpFlameTrail"]); + + // Prepare the flame trail shader with its map texture. + GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); + + Texture2D texture; + switch (Variant) + { + case (int)GemTechArmorGemType.Melee: + default: + texture = Main.projectileTexture[projectile.type]; + break; + case (int)GemTechArmorGemType.Ranged: + texture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/GreenGem"); + break; + case (int)GemTechArmorGemType.Magic: + texture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/PurpleGem"); + break; + case (int)GemTechArmorGemType.Summoner: + texture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/BlueGem"); + break; + case (int)GemTechArmorGemType.Rogue: + texture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/RedGem"); + break; + case (int)GemTechArmorGemType.Base: + texture = ModContent.GetTexture("CalamityMod/ExtraTextures/GemTechArmor/PinkGem"); + break; + } + + Vector2 drawPosition = projectile.Center - Main.screenPosition; + Vector2 origin = texture.Size() * 0.5f; + spriteBatch.Draw(texture, drawPosition, null, projectile.GetAlpha(Color.White), projectile.rotation, origin, projectile.scale, SpriteEffects.None, 0f); + + if (projectile.ai[0] > UpwardFlyTime + RedirectTime) + FlameTrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 71); + + return false; + } + + public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) + { + projectile.damage = 0; + projectile.velocity = Vector2.Zero; + projectile.timeLeft = ProjectileID.Sets.TrailCacheLength[projectile.type]; + projectile.netUpdate = true; + } + } +}