diff --git a/Buffs/Summon/ViridVanguardBuff.cs b/Buffs/Summon/ViridVanguardBuff.cs index a304218317..4c092cb4a4 100644 --- a/Buffs/Summon/ViridVanguardBuff.cs +++ b/Buffs/Summon/ViridVanguardBuff.cs @@ -20,9 +20,9 @@ namespace CalamityMod.Buffs.Summon CalamityPlayer modPlayer = player.Calamity(); if (player.ownedProjectileCounts[ModContent.ProjectileType()] > 0) { - modPlayer.viridVanguard = true; + modPlayer.ViridVanguard = true; } - if (!modPlayer.viridVanguard) + if (!modPlayer.ViridVanguard) { player.DelBuff(buffIndex); buffIndex--; diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index ac9c2aaee9..2855e7fded 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -961,7 +961,7 @@ namespace CalamityMod.CalPlayer public bool deathstareEyeball = false; public bool witherBlossom = false; public bool flowersOfMortality = false; - public bool viridVanguard = false; + public bool ViridVanguard = false; public bool sageSpirit = false; public bool fleshBall = false; public bool eyeOfNight = false; @@ -1997,7 +1997,7 @@ namespace CalamityMod.CalPlayer deathstareEyeball = false; witherBlossom = false; flowersOfMortality = false; - viridVanguard = false; + ViridVanguard = false; sageSpirit = false; fleshBall = false; eyeOfNight = false; diff --git a/Items/CalamityGlobalItem.cs b/Items/CalamityGlobalItem.cs index b27836fd9a..0f24e6513b 100644 --- a/Items/CalamityGlobalItem.cs +++ b/Items/CalamityGlobalItem.cs @@ -637,40 +637,6 @@ namespace CalamityMod.Items } return false; } - if (player.ActiveItem().type == ModContent.ItemType()) - { - int bladeCount = 0; - for (int i = 0; i < Main.maxProjectiles; i++) - { - if (Main.projectile[i].active && - Main.projectile[i].type == ModContent.ProjectileType() && - Main.projectile[i].owner == player.whoAmI && - Main.projectile[i].ModProjectile().FiringTime <= 0f) - { - bladeCount++; - } - } - if (bladeCount > 0) - { - int bladeIndex = 0; - for (int i = 0; i < Main.maxProjectiles; i++) - { - if (Main.projectile[i].ModProjectile is ViridVanguardBlade) - { - if (Main.projectile[i].ModProjectile().FiringTime > 0f) - continue; - } - if (Main.projectile[i].active && Main.projectile[i].type == ModContent.ProjectileType() && Main.projectile[i].owner == player.whoAmI) - { - Main.projectile[i].ModProjectile().FiringTime = 240f; - Main.projectile[i].ModProjectile().RedirectAngle = MathHelper.Lerp(0f, MathHelper.TwoPi, bladeIndex / (float)bladeCount); - Main.projectile[i].netUpdate = true; - bladeIndex++; - } - } - } - return false; - } if (player.ActiveItem().type == ModContent.ItemType()) { bool hasBlades = false; diff --git a/Items/Weapons/Summon/ViridVanguard.cs b/Items/Weapons/Summon/ViridVanguard.cs index 95b8145f50..865fa2f254 100644 --- a/Items/Weapons/Summon/ViridVanguard.cs +++ b/Items/Weapons/Summon/ViridVanguard.cs @@ -10,19 +10,19 @@ namespace CalamityMod.Items.Weapons.Summon { public class ViridVanguard : ModItem { + public const float MaxTargetingDistance = 1550f; + public override void SetStaticDefaults() { DisplayName.SetDefault("Virid Vanguard"); - Tooltip.SetDefault("Summons 2 blades that rotate around you\n" + - "Each pair of blades takes up three minion slots\n" + - "Right clicking prompts all blades to fly upward and redirect towards the mouse"); + Tooltip.SetDefault("Update this"); Item.staff[Item.type] = true; SacrificeTotal = 1; } public override void SetDefaults() { - Item.damage = 280; + Item.damage = 210; Item.DamageType = DamageClass.Summon; Item.mana = 10; Item.width = 26; @@ -32,7 +32,7 @@ namespace CalamityMod.Items.Weapons.Summon Item.noMelee = true; Item.knockBack = 5f; Item.value = CalamityGlobalItem.RarityTurquoiseBuyPrice; - Item.rare = 10; + Item.rare = ItemRarityID.Red; Item.UseSound = SoundID.Item71; Item.autoReuse = true; Item.shoot = ModContent.ProjectileType(); @@ -41,71 +41,31 @@ namespace CalamityMod.Items.Weapons.Summon public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - float totalMinionSlots = 0f; - for (int i = 0; i < Main.maxProjectiles; i++) + if (player.altFunctionUse != 2) { - if (Main.projectile[i].active && Main.projectile[i].minion && Main.projectile[i].owner == player.whoAmI) + int p = Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI, 0f, 1f); + if (Main.projectile.IndexInRange(p)) { - totalMinionSlots += Main.projectile[i].minionSlots; - } - } - if (player.altFunctionUse != 2 && totalMinionSlots + 1.5f < player.maxMinions) - { - position = Main.MouseWorld; - int swordCount = 0; - for (int i = 0; i < Main.projectile.Length; i++) - { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) - { - if ((Main.projectile[i].ModProjectile as ViridVanguardBlade).FiringTime > 0f) - continue; - swordCount++; - for (int j = 0; j < 22; j++) - { - Dust dust = Dust.NewDustDirect(Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height, 2); - dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool(2).ToDirectionInt(); - dust.noGravity = true; - } - } + Main.projectile[p].originalDamage = Item.damage; + Main.projectile[p].ModProjectile().BladeIndex = player.ownedProjectileCounts[type]; } - Projectile newBlade = Projectile.NewProjectileDirect(source, position, Vector2.Zero, type, damage, knockback, player.whoAmI); - (newBlade.ModProjectile as ViridVanguardBlade).AltTexture = swordCount % 2 == 1; - newBlade.originalDamage = Item.damage; - newBlade.netUpdate = true; - swordCount++; - - newBlade = Projectile.NewProjectileDirect(source, position, Vector2.Zero, type, damage, knockback, player.whoAmI); - (newBlade.ModProjectile as ViridVanguardBlade).AltTexture = swordCount % 2 == 1; - newBlade.originalDamage = Item.damage; - newBlade.netUpdate = true; - swordCount++; - - float angleVariance = MathHelper.TwoPi / swordCount; - float angle = 0f; for (int i = 0; i < Main.maxProjectiles; i++) { - if (Main.projectile[i].active && Main.projectile[i].type == type && Main.projectile[i].owner == player.whoAmI) + if (Main.projectile[i].type == type && Main.projectile[i].active && Main.projectile[i].owner == player.whoAmI) { - if ((Main.projectile[i].ModProjectile as ViridVanguardBlade).FiringTime > 0f) - continue; - Main.projectile[i].ai[0] = angle; - Main.projectile[i].localAI[1] = 80f; - angle += angleVariance; - for (int j = 0; j < 22; j++) - { - Dust dust = Dust.NewDustDirect(Main.projectile[i].position, Main.projectile[i].width, Main.projectile[i].height, 6); - dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool(2).ToDirectionInt(); - dust.noGravity = true; - } + Main.projectile[i].ModProjectile().AITimer = 0f; + Main.projectile[i].netUpdate = true; } } } + return false; } public override void AddRecipes() { CreateRecipe(). + AddIngredient(ItemID.EmpressBlade). AddIngredient(). AddIngredient(8). AddTile(TileID.LunarCraftingStation). diff --git a/Projectiles/Summon/ViridVanguardBlade.cs b/Projectiles/Summon/ViridVanguardBlade.cs index 94d0ed9e92..19981b5be5 100644 --- a/Projectiles/Summon/ViridVanguardBlade.cs +++ b/Projectiles/Summon/ViridVanguardBlade.cs @@ -1,10 +1,14 @@ using System; using System.IO; using CalamityMod.Buffs.Summon; -using CalamityMod.CalPlayer; +using CalamityMod.Items.Weapons.Summon; +using CalamityMod.Sounds; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.Audio; +using Terraria.Graphics; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -12,174 +16,385 @@ namespace CalamityMod.Projectiles.Summon { public class ViridVanguardBlade : ModProjectile { - public bool AltTexture = false; - - public int RemainingSlices = 0; - public int PostSliceDeathTimer; - public float RedirectAngle; - public float FiringTime = 0f; - public Vector2 IdealPosition; - public float Angle + public enum ViridVanguardAIState { - get => Projectile.ai[0]; - set => Projectile.ai[0] = value; + CircleOwner, + HorizontalSlashes, + VerticalPierceTeleport, + RegularPierceSlashes, } + + public int BladeIndex; + + public VertexStrip TrailDrawer; + + public Vector2 ChargeStartingPosition; + + public float BladeHoverOffsetAngle + { + get + { + float projectileCounts = Owner.ownedProjectileCounts[Type]; + if (projectileCounts <= 1f) + projectileCounts = 1f; + + return MathHelper.TwoPi * BladeIndex / projectileCounts + AITimer / 27f; + } + } + + public ViridVanguardAIState CurrentState + { + get => (ViridVanguardAIState)Projectile.ai[0]; + set => Projectile.ai[0] = (int)value; + } + + public Player Owner => Main.player[Projectile.owner]; + + public ref float AITimer => ref Projectile.ai[1]; + + public ref float BladeGleamInterpolant => ref Projectile.localAI[0]; + public override void SetStaticDefaults() { DisplayName.SetDefault("Vanguard Blade"); - ProjectileID.Sets.TrailingMode[Projectile.type] = 0; - ProjectileID.Sets.TrailCacheLength[Projectile.type] = 7; + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 45; } public override void SetDefaults() { - Projectile.width = 60; - Projectile.height = 156; + Projectile.width = 84; + Projectile.height = 84; Projectile.netImportant = true; Projectile.friendly = true; Projectile.ignoreWater = true; - Projectile.minionSlots = 1.5f; - Projectile.timeLeft = 18000; + Projectile.timeLeft = 90000; Projectile.penetrate = -1; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 14; Projectile.tileCollide = false; - Projectile.timeLeft *= 5; Projectile.minion = true; Projectile.DamageType = DamageClass.Summon; } + public override void SendExtraAI(BinaryWriter writer) { - writer.Write(RedirectAngle); - writer.Write(FiringTime); - writer.Write(AltTexture); + writer.Write(BladeIndex); + writer.WriteVector2(ChargeStartingPosition); } + public override void ReceiveExtraAI(BinaryReader reader) { - RedirectAngle = reader.ReadSingle(); - FiringTime = reader.ReadSingle(); - AltTexture = reader.ReadBoolean(); + BladeIndex = reader.ReadInt32(); + ChargeStartingPosition = reader.ReadVector2(); } + public override void AI() { - Player player = Main.player[Projectile.owner]; - CalamityPlayer modPlayer = player.Calamity(); - Projectile.spriteDirection = AltTexture.ToDirectionInt(); - bool isProperProjectile = Projectile.type == ModContent.ProjectileType(); - player.AddBuff(ModContent.BuffType(), 3600); - if (isProperProjectile) + // Decide whether the minion should still exist. + HandleMinionBools(); + + // Reset extra updates. + Projectile.MaxUpdates = 1; + + // Have the gleam interpolant dissipate. + BladeGleamInterpolant = MathHelper.Lerp(BladeGleamInterpolant, 0f, 0.1f); + if (BladeGleamInterpolant <= 0.02f) + BladeGleamInterpolant = 0f; + + NPC potentialTarget = Projectile.Center.MinionHoming(ViridVanguard.MaxTargetingDistance, Owner); + switch (CurrentState) { - if (player.dead) - { - modPlayer.viridVanguard = false; - } - if (modPlayer.viridVanguard) - { - Projectile.timeLeft = 2; - } + case ViridVanguardAIState.CircleOwner: + DoBehavior_CircleOwner(potentialTarget); + break; + case ViridVanguardAIState.HorizontalSlashes: + DoBehavior_HorizontalSlashes(potentialTarget); + break; + case ViridVanguardAIState.VerticalPierceTeleport: + DoBehavior_VerticalPierceTeleport(potentialTarget); + break; + case ViridVanguardAIState.RegularPierceSlashes: + DoBehavior_RegularPierceSlashes(potentialTarget); + break; } - if (FiringTime <= 0f) + AITimer++; + } + + public void DoBehavior_CircleOwner(NPC potentialTarget) + { + // Begin attacking if an enemy is nearby. + if (potentialTarget is not null) { - Projectile.ai[1]++; - float outwardPosition = 320f; - outwardPosition += (float)Math.Sin(Angle) * 200f; - Projectile.Center = player.Center + Angle.ToRotationVector2().RotatedBy((float)Math.Cos(Angle) * MathHelper.PiOver4 + AltTexture.ToInt() * MathHelper.Pi) * outwardPosition; - Projectile.rotation = player.AngleTo(Projectile.Center) + MathHelper.PiOver4; - Angle += MathHelper.ToRadians(4f); + CurrentState = ViridVanguardAIState.HorizontalSlashes; + AITimer = 0f; + Projectile.netUpdate = true; + return; } + + Vector2 hoverDestination = Owner.Center + BladeHoverOffsetAngle.ToRotationVector2() * 200f; + Projectile.Center = Vector2.Lerp(Projectile.Center, hoverDestination, 0.04f).MoveTowards(hoverDestination, 16f); + Projectile.velocity *= 0.8f; + + // Teleport to the owner if sufficiently far away. + if (!Projectile.WithinRange(Owner.Center, 2500f)) + { + Projectile.Center = hoverDestination; + Projectile.netUpdate = true; + } + + // Aim away from the target. + Projectile.rotation = Projectile.AngleFrom(Owner.Center) + MathHelper.PiOver2; + } + + public void DoBehavior_HorizontalSlashes(NPC target) + { + int hoverTime = 22; + int chargeTime = 14; + int chargeCount = 7; + float chargeSpeed = 44f; + + // Exit the attack state if the blade no longer has a valid target. + if (target is null) + { + ReturnToIdleState(); + return; + } + + // Use extra updates to make the swords move faster than normal. + Projectile.MaxUpdates = 2; + + // Use a gleam effect right before and during charges. + float wrappedAttackTimer = AITimer % (hoverTime + chargeTime); + float fadeIn = Utils.GetLerpValue(hoverTime - 6f, hoverTime, wrappedAttackTimer, true); + float fadeOut = Utils.GetLerpValue(chargeTime, chargeTime - 6f, wrappedAttackTimer - hoverTime, true); + BladeGleamInterpolant = fadeIn * fadeOut; + + // Hover to the side of the target. + if (wrappedAttackTimer < hoverTime) + { + Vector2 hoverDestination = target.Center + Vector2.UnitX * (target.Center.X < Projectile.Center.X).ToDirectionInt() * 250f; + hoverDestination.Y += (float)Math.Cos(Projectile.identity * 1.7f) * 67f; + + Projectile.Center = Vector2.Lerp(Projectile.Center, hoverDestination, 0.08f).MoveTowards(hoverDestination, 16f); + Projectile.velocity *= 0.5f; + + // Update rotation, to look upward. + Projectile.rotation = Projectile.rotation.AngleLerp(0f, 0.08f); + } + + // Otherwise, if not hovering, update rotation to swing forward somewhat. else + Projectile.rotation += Math.Sign(Projectile.velocity.X) * MathHelper.Pi / chargeTime * 0.36f; + + // Charge VERY quickly at the target once ready. + if (wrappedAttackTimer == hoverTime) { - Projectile.spriteDirection = 1; - if (FiringTime >= 239f) - { - RemainingSlices = Projectile.penetrate = 3; - IdealPosition = player.Center - Vector2.UnitY.RotatedBy(RedirectAngle) * 550f; - } - else if (FiringTime > 120f) - { - Projectile.Center = Vector2.Lerp(Projectile.Center, IdealPosition, 1f / 40f); - Projectile.rotation = Projectile.rotation.AngleLerp(RedirectAngle + MathHelper.ToRadians(82f), 1f / 60f); - } - else if (FiringTime > 80f) - { - Projectile.Center = IdealPosition; - Projectile.rotation = Projectile.rotation.AngleLerp(Projectile.AngleTo(Main.MouseWorld) + MathHelper.ToRadians(82f), 1f / 20f); - } - else if (FiringTime == 80f) - { - PostSliceDeathTimer = 80; - Projectile.velocity = Projectile.SafeDirectionTo(Main.MouseWorld) * 30f; - } - else if (FiringTime == 1f) - { - if (RemainingSlices <= 0) - { - Projectile.Kill(); - } - else if (RemainingSlices <= 2) - { - Projectile.velocity *= -1; - FiringTime = 20f; - } - } - FiringTime--; + SoundEngine.PlaySound(CommonCalamitySounds.MeatySlashSound with { Pitch = 1.6f, Volume = 0.27f }, Projectile.Center); + Projectile.oldPos = new Vector2[Projectile.oldPos.Length]; + Projectile.velocity = Vector2.UnitX * (target.Center.X > Projectile.Center.X).ToDirectionInt() * chargeSpeed; + Projectile.netUpdate = true; } - if (RemainingSlices > 0) - PostSliceDeathTimer--; - if (PostSliceDeathTimer == 1) - Projectile.Kill(); + // Switch to the next attack state once enough charges have happened. + if (AITimer >= (hoverTime + chargeTime) * chargeCount) + { + AITimer = 0f; + CurrentState = ViridVanguardAIState.VerticalPierceTeleport; + Projectile.netUpdate = true; + } + } - if (Projectile.localAI[1] > 0) - { - Projectile.alpha = (int)MathHelper.Lerp(255, 0, 1f - Projectile.localAI[1] / 80f); - Projectile.localAI[1]--; - } - } - public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + public void DoBehavior_VerticalPierceTeleport(NPC target) { - if (RemainingSlices > 0 && FiringTime <= 80f) + int hoverTime = 26; + int chargeTime = 32; + int chargeCount = 7; + float chargeSpeed = 45f; + + // Exit the attack state if the blade no longer has a valid target. + if (target is null) { - FiringTime = 10f; - RemainingSlices--; + ReturnToIdleState(); + return; + } + + // Use extra updates to make the swords move faster than normal. + Projectile.MaxUpdates = 2; + + // Use a gleam effect right before and during charges. + int localAITimer = (int)AITimer + Projectile.identity / 2; + float wrappedAttackTimer = localAITimer % (hoverTime + chargeTime); + float fadeIn = Utils.GetLerpValue(hoverTime - 6f, hoverTime, wrappedAttackTimer, true); + float fadeOut = Utils.GetLerpValue(chargeTime, chargeTime - 6f, wrappedAttackTimer - hoverTime, true); + BladeGleamInterpolant = fadeIn * fadeOut; + + // Hover above the target. + if (wrappedAttackTimer < hoverTime) + { + Vector2 hoverDestination = target.Center - Vector2.UnitY * 500f; + hoverDestination.X += (float)Math.Cos(Projectile.identity * 1.7f) * 50f; + + Projectile.Center = Vector2.Lerp(Projectile.Center, hoverDestination, 0.08f).MoveTowards(hoverDestination, 16f); + Projectile.velocity *= 0.5f; + + // Update rotation, to look at the target. + Projectile.rotation = Projectile.rotation.AngleLerp(Projectile.AngleTo(target.Center) + MathHelper.PiOver2, 0.24f); + } + + // Pierce the target once ready. + if (wrappedAttackTimer == hoverTime) + { + SoundEngine.PlaySound(CommonCalamitySounds.MeatySlashSound with { Pitch = 1.6f, Volume = 0.27f }, Projectile.Center); + Projectile.oldPos = new Vector2[Projectile.oldPos.Length]; + Projectile.velocity = Vector2.UnitY * chargeSpeed; + Projectile.netUpdate = true; + } + + // Teleport above the target once sufficiently far below them. + if (wrappedAttackTimer >= hoverTime + 5f && Projectile.Center.Y > target.Center.Y + 850f) + { + Projectile.oldPos = new Vector2[Projectile.oldPos.Length]; + Projectile.Center = target.Center - Vector2.UnitY * 600f; + Projectile.netUpdate = true; + } + + // Switch to the next attack state once enough charges have happened. + if (AITimer >= (hoverTime + chargeTime) * chargeCount) + { + AITimer = 0f; + CurrentState = ViridVanguardAIState.RegularPierceSlashes; + Projectile.netUpdate = true; } } - public override void Kill(int timeLeft) + + public void DoBehavior_RegularPierceSlashes(NPC target) { - for (int j = 0; j < 40; j++) + int attackCycleTime = 44; + int chargeCount = 8; + float upwardRiseTimeRatio = 0.4f; + float pierceTimeRatio = 0.14f; + + // Exit the attack state if the blade no longer has a valid target. + if (target is null) { - Dust dust = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, 66); - dust.velocity = Vector2.UnitY * Main.rand.NextFloat(3f, 5.5f) * Main.rand.NextBool(2).ToDirectionInt(); - dust.noGravity = true; + ReturnToIdleState(); + ChargeStartingPosition = Vector2.Zero; + return; + } + + // Initialize the starting position on the first frame. + int localAITimer = (int)AITimer + Projectile.identity; + if (localAITimer % attackCycleTime == 1f) + { + ChargeStartingPosition = Projectile.Center + Main.rand.NextVector2Circular(80f, 80f); + Projectile.netUpdate = true; + } + + float attackCompletion = localAITimer / (float)attackCycleTime % 1f; + + // Reset the trail point array if aiming at the target. + if (attackCompletion < upwardRiseTimeRatio) + Projectile.oldPos = new Vector2[Projectile.oldPos.Length]; + + // Use extra updates to make the swords move faster than normal. + Projectile.MaxUpdates = 2; + + // This represents the entire attack cycle in a single interpolant via a bunch of GetLerpValues and vector math. The patterns is as follows: + // 1. Hover very quickly to the starting position. + // 2. Rise upward somewhat. + // 3. Lerp towards the target rapidly. + // 4. Lerp through the target rapidly. + // 5. Repeat. + float offsetDistanceFactor = MathHelper.Lerp(1.61f, 3f, Projectile.identity / 7f % 1f); + Vector2 startingPosition = ChargeStartingPosition + Vector2.UnitY * Utils.GetLerpValue(0f, upwardRiseTimeRatio, attackCompletion, true) * -200f; + Vector2 targetOffset = target.Center - startingPosition; + Vector2 endingPosition = target.Center + targetOffset.SafeNormalize(Vector2.Zero) * MathHelper.Clamp(targetOffset.Length(), 60f, 240f) * offsetDistanceFactor; + float pierceCompletion = Utils.GetLerpValue(upwardRiseTimeRatio, upwardRiseTimeRatio + pierceTimeRatio, attackCompletion, true); + float throughTargetCompletion = Utils.GetLerpValue(upwardRiseTimeRatio + pierceTimeRatio, 1f, attackCompletion, true); + + // Update rotation and interpolate through the necessary positions. + Projectile.rotation = Projectile.rotation.AngleTowards(targetOffset.ToRotation() + MathHelper.PiOver2, MathHelper.Pi / 5f); + Projectile.Center = Vector2.Lerp(Projectile.Center, Vector2.Lerp(startingPosition, target.Center, pierceCompletion), pierceCompletion * 0.5f); + if (throughTargetCompletion > 0f) + Projectile.Center = Vector2.Lerp(target.Center, endingPosition, throughTargetCompletion); + Projectile.velocity = Vector2.Zero; + + // Play a slice sound once ready to charge. + if (localAITimer % attackCycleTime == (int)(attackCycleTime * upwardRiseTimeRatio)) + SoundEngine.PlaySound(CommonCalamitySounds.MeatySlashSound with { Pitch = 1.6f, Volume = 0.27f }, Projectile.Center); + + // Switch to the next attack state once enough charges have happened. + if (localAITimer >= attackCycleTime * chargeCount) + { + AITimer = 0f; + CurrentState = ViridVanguardAIState.HorizontalSlashes; + Projectile.netUpdate = true; } } + + public void ReturnToIdleState() + { + AITimer = 0f; + CurrentState = ViridVanguardAIState.CircleOwner; + Projectile.netUpdate = true; + } + + public void HandleMinionBools() + { + Owner.AddBuff(ModContent.BuffType(), 3600); + if (Projectile.type == ModContent.ProjectileType()) + { + if (Owner.dead) + Owner.Calamity().ViridVanguard = false; + + if (Owner.Calamity().ViridVanguard) + Projectile.timeLeft = 2; + } + } + + public Color TrailColorFunction(float completionRatio) + { + float opacity = (float)Math.Pow(Utils.GetLerpValue(1f, 0.45f, completionRatio, true), 4D) * Projectile.Opacity; + return Color.Lerp(new(115, 196, 127), Color.Yellow, MathHelper.Clamp(completionRatio * 1.4f, 0f, 1f)) * opacity; + } + + public float TrailWidthFunction(float completionRatio) => Projectile.height * (1f - completionRatio) * 0.8f; + public override bool PreDraw(ref Color lightColor) { - Texture2D texture = ModContent.Request("CalamityMod/Projectiles/Summon/ViridVanguardBlade" + (AltTexture ? "" : "Alt")).Value; + Texture2D texture = ModContent.Request(Texture).Value; + Rectangle frame = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame); + Vector2 origin = frame.Size() * 0.5f; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None; - Rectangle rectangle = new Rectangle(0, 0, texture.Width, texture.Height); + TrailDrawer ??= new(); + GameShaders.Misc["EmpressBlade"].UseImage0("Images/Extra_201"); + GameShaders.Misc["EmpressBlade"].UseImage1("Images/Extra_193"); + GameShaders.Misc["EmpressBlade"].UseShaderSpecificData(new Vector4(1f, 0f, 0f, 0.6f)); + GameShaders.Misc["EmpressBlade"].Apply(null); + TrailDrawer.PrepareStrip(Projectile.oldPos, Projectile.oldRot, TrailColorFunction, TrailWidthFunction, Projectile.Size * 0.5f - Main.screenPosition, Projectile.oldPos.Length, true); + TrailDrawer.DrawTrail(); + Main.pixelShader.CurrentTechnique.Passes[0].Apply(); - SpriteEffects spriteEffects = SpriteEffects.None; - if (Projectile.spriteDirection == -1) - spriteEffects = SpriteEffects.FlipHorizontally; + // Draw the blade. + Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation + 0.2f, origin, Projectile.scale, direction, 0); - if (CalamityConfig.Instance.Afterimages && FiringTime > 0f && FiringTime < 80f) - { - for (int i = 0; i < Projectile.oldPos.Length; i++) - { - Vector2 drawPos = Projectile.oldPos[i] + Projectile.Size / 2f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); - Color color = Color.Lerp(Color.White, Color.DarkOliveGreen, i / (float)Projectile.oldPos.Length) * - ((Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); - float scale = MathHelper.Lerp(Projectile.scale * 1f, Projectile.scale * 0.5f, i / (float)Projectile.oldPos.Length); - Main.EntitySpriteDraw(texture, drawPos, new Rectangle?(rectangle), color, - Projectile.rotation, - rectangle.Size() / 2f, scale, SpriteEffects.None, 0); - } - } - Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY), new Rectangle?(rectangle), Color.White, - Projectile.rotation, - rectangle.Size() / 2f, 1f, spriteEffects, 0); + // Draw the gleam. + Texture2D shineTex = ModContent.Request("CalamityMod/Particles/HalfStar").Value; + Vector2 shineScale = new Vector2(1.67f, 3f) * Projectile.scale; + shineScale *= MathHelper.Lerp(0.9f, 1.1f, (float)Math.Cos(Main.GlobalTimeWrappedHourly * 7.4f + Projectile.identity) * 0.5f + 0.5f); + + Vector2 lensFlareWorldPosition = Projectile.Center + (Projectile.rotation - MathHelper.PiOver2).ToRotationVector2() * Projectile.width * Projectile.scale * 0.88f; + Color lensFlareColor = Color.Lerp(Color.LimeGreen, Color.Yellow, 0.23f) with { A = 0 } * BladeGleamInterpolant; + Main.EntitySpriteDraw(shineTex, lensFlareWorldPosition - Main.screenPosition, null, lensFlareColor, 0f, shineTex.Size() * 0.5f, shineScale * 0.6f, 0, 0); + Main.EntitySpriteDraw(shineTex, lensFlareWorldPosition - Main.screenPosition, null, lensFlareColor, MathHelper.PiOver2, shineTex.Size() * 0.5f, shineScale, 0, 0); + + // Reset textures for shaders. + GameShaders.Misc["EmpressBlade"].UseImage0("Images/Extra_209"); + GameShaders.Misc["EmpressBlade"].UseImage1("Images/Extra_210"); return false; } } diff --git a/Projectiles/Summon/ViridVanguardBlade.png b/Projectiles/Summon/ViridVanguardBlade.png index dadc21641b..e2cbaf2040 100644 Binary files a/Projectiles/Summon/ViridVanguardBlade.png and b/Projectiles/Summon/ViridVanguardBlade.png differ diff --git a/Projectiles/Summon/ViridVanguardBladeAlt.png b/Projectiles/Summon/ViridVanguardBladeAlt.png deleted file mode 100644 index 127ec26b1c..0000000000 Binary files a/Projectiles/Summon/ViridVanguardBladeAlt.png and /dev/null differ diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index 0ac1ae059b..094d79ac25 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -615,7 +615,8 @@ namespace CalamityMod } // Cached for efficiency purposes. - internal static readonly FieldInfo UImageFieldMisc = typeof(MiscShaderData).GetField("_uImage1", BindingFlags.NonPublic | BindingFlags.Instance); + internal static readonly FieldInfo UImageFieldMisc0 = typeof(MiscShaderData).GetField("_uImage0", BindingFlags.NonPublic | BindingFlags.Instance); + internal static readonly FieldInfo UImageFieldMisc1 = typeof(MiscShaderData).GetField("_uImage1", BindingFlags.NonPublic | BindingFlags.Instance); internal static readonly FieldInfo UImageFieldArmor = typeof(ArmorShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); /// @@ -623,9 +624,17 @@ namespace CalamityMod /// /// The shader to bind the texture to. /// The texture to bind. - public static MiscShaderData SetShaderTexture(this MiscShaderData shader, Asset texture) + public static MiscShaderData SetShaderTexture(this MiscShaderData shader, Asset texture, int index = 1) { - UImageFieldMisc.SetValue(shader, texture); + switch (index) + { + case 0: + UImageFieldMisc0.SetValue(shader, texture); + break; + case 1: + UImageFieldMisc1.SetValue(shader, texture); + break; + } return shader; }