diff --git a/Items/Weapons/Melee/CosmicShiv.cs b/Items/Weapons/Melee/CosmicShiv.cs index e67e36ebfc..518e84bb8c 100644 --- a/Items/Weapons/Melee/CosmicShiv.cs +++ b/Items/Weapons/Melee/CosmicShiv.cs @@ -20,16 +20,16 @@ namespace CalamityMod.Items.Weapons.Melee Item.noUseGraphic = true; Item.autoReuse = true; Item.useStyle = ItemUseStyleID.Rapier; - Item.damage = 98; + Item.damage = 300; Item.DamageType = DamageClass.Melee; - Item.useAnimation = Item.useTime = 18; + Item.useAnimation = Item.useTime = 38; Item.shoot = ModContent.ProjectileType(); Item.shootSpeed = 2.4f; Item.knockBack = 9f; Item.UseSound = SoundID.Item1; Item.value = CalamityGlobalItem.Rarity14BuyPrice; Item.rare = ModContent.RarityType(); - Item.Calamity().donorItem = true; //Yatagarasu#0001 + Item.Calamity().donorItem = true; // revertusernamechange on Discord (Yatagarasu) } public override bool MeleePrefix() => true; @@ -43,4 +43,4 @@ namespace CalamityMod.Items.Weapons.Melee Register(); } } -} +} \ No newline at end of file diff --git a/Projectiles/Melee/CosmicShivAura.cs b/Projectiles/Melee/CosmicShivAura.cs new file mode 100644 index 0000000000..39e903edfb --- /dev/null +++ b/Projectiles/Melee/CosmicShivAura.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Buffs.DamageOverTime; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class CosmicShivAura : ModProjectile + { + public new string LocalizationCategory => "Projectiles.Melee"; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public readonly int SwordsAverageDelay = 40; + public readonly int SwordsRandomOffset = 15; + public int CurrentSwordTimer; + public NPC target; + + public override void SetDefaults() + { + Projectile.width = 2; + Projectile.height = 2; + Projectile.tileCollide = false; + Projectile.ignoreWater = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 300; + } + + public override void OnSpawn(IEntitySource source) + { + if (Main.npc[(int)Projectile.ai[0]] is not null || Main.npc[(int)Projectile.ai[0]].active) + target = Main.npc[(int)Projectile.ai[0]]; // Convert target.whoAmI to object + } + + // ai[0] for ID of target to follow until the end of projectile's lifespan or the target cannot be found + // ai[1] for sword timer + public override void AI() + { + // Unexist with target + if (target is null || !target.active) { + Projectile.Kill(); + } + + Projectile.Center = Main.npc[(int)Projectile.ai[0]].Center; // Stay with target + + if (Projectile.ai[1] == CurrentSwordTimer) + { + Vector2 randomDirection = Main.rand.NextFloat(0, MathHelper.TwoPi).ToRotationVector2(); + randomDirection.Normalize(); + int randomDistance = Main.rand.Next(200, 426); + Vector2 spawnPos = Projectile.Center + (randomDirection * randomDistance); + Vector2 velocity = Vector2.Normalize(Projectile.Center - spawnPos) * Utils.GetLerpValue(-100, 426, randomDistance, clamped: true) * 20f; // Sword moves a bit slower if spawned closer, moves faster if spawned further + Projectile.NewProjectile(Projectile.GetSource_FromThis(), spawnPos.X, spawnPos.Y, velocity.X, velocity.Y, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack * 0.8f, Projectile.owner, randomDistance); + Projectile.ai[1] = 0; // Reset timer + CurrentSwordTimer = Main.rand.Next(SwordsAverageDelay - SwordsRandomOffset, SwordsAverageDelay + SwordsRandomOffset); // Determine when next sword will spawn + } + + Projectile.ai[1]++; + } + + // The aura itself should not do contact damage + public override bool? CanDamage() => false; + } +} diff --git a/Projectiles/Melee/CosmicShivBall.cs b/Projectiles/Melee/CosmicShivBall.cs deleted file mode 100644 index fcbf9b6d7a..0000000000 --- a/Projectiles/Melee/CosmicShivBall.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using CalamityMod.Buffs.DamageOverTime; - -namespace CalamityMod.Projectiles.Melee -{ - public class CosmicShivBall : ModProjectile, ILocalizedModType - { - public new string LocalizationCategory => "Projectiles.Melee"; - // TODO -- Please for the love of god refactor this at some point. It is ancient. - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public NPC target = null; - public const float maxDistanceToTarget = 540f; - public bool initialized = false; - public float startingVelocityY = 0f; - public float randomAngleDelta = 0f; - public const float explosionDamageMultiplier = 1.5f; - public override void SetDefaults() - { - Projectile.width = 12; - Projectile.height = 12; - Projectile.friendly = true; - Projectile.DamageType = DamageClass.Melee; - Projectile.penetrate = 1; - Projectile.tileCollide = false; - Projectile.timeLeft = 220; - } - public override void AI() - { - if (!initialized) - { - target = Projectile.Center.ClosestNPCAt(maxDistanceToTarget); - startingVelocityY = Projectile.velocity.Y; - randomAngleDelta = Main.rand.NextFloat(0f, MathHelper.TwoPi); - initialized = true; - } - Projectile.localAI[0] += 1f; - if (Projectile.localAI[0] > 4f) - { - for (int i = 0; i < 3; i++) - { - int dustID = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, 173, (float)(Projectile.direction * 2), 0f, 115, Color.White, 1.3f); - Main.dust[dustID].noGravity = true; - Main.dust[dustID].velocity *= 0f; - } - } - if (Projectile.localAI[0] % 30 == 0) // every 0.5 seconds - { - target = Projectile.Center.ClosestNPCAt(maxDistanceToTarget); - } - if (target != null) - { - float inertia = 35f; - float homingSpeed = 33.5f; - Vector2 idealVelocity = Projectile.SafeDirectionTo(target.Center, Vector2.UnitX) * homingSpeed; - Projectile.velocity = (Projectile.velocity * (inertia - 1f) + idealVelocity) / inertia; - } - } - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) - { - // for spawning the side beams - for (int i = 0; i < 2; i++) - { - int directionSign = Main.rand.NextBool().ToDirectionInt(); - Vector2 spawnPos = new Vector2(target.Center.X + directionSign * 650, Projectile.Center.Y + Main.rand.Next(-500, 501)); - Vector2 velocity = Vector2.Normalize(target.Center - spawnPos) * 30f; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), spawnPos.X, spawnPos.Y, velocity.X, velocity.Y, ModContent.ProjectileType(), (int)(Projectile.damage * 0.8f), Projectile.knockBack * 0.1f, Projectile.owner); - } - int starMax = Main.rand.Next(6, 11); // 6 to 10 stars - for (int i = -starMax / 2; i < starMax / 2; i++) - { - int ySpawnAdditive = Main.rand.Next(-40, 41); - Vector2 toSpawn = target.Center - new Vector2(0f, 800f + ySpawnAdditive).RotatedBy(MathHelper.ToRadians(i * 11f / starMax)); - Vector2 toTarget = Vector2.Normalize(target.Center - toSpawn) * 35f; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), toSpawn, toTarget, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack * 0.5f, Projectile.owner); - } - target.AddBuff(ModContent.BuffType(), 60); - } - // pretty much entirely from the Oracle circular damage code - - private void CircularDamage(float radius) - { - if (Projectile.owner != Main.myPlayer) - return; - Player owner = Main.player[Projectile.owner]; - - for (int i = 0; i < Main.npc.Length; ++i) - { - NPC target = Main.npc[i]; - if (!target.active || target.dontTakeDamage || target.friendly) - continue; - - // Shock any valid target within range. Check all four corners of their hitbox. - float d1 = Vector2.Distance(Projectile.Center, target.Hitbox.TopLeft()); - float d2 = Vector2.Distance(Projectile.Center, target.Hitbox.TopRight()); - float d3 = Vector2.Distance(Projectile.Center, target.Hitbox.BottomLeft()); - float d4 = Vector2.Distance(Projectile.Center, target.Hitbox.BottomRight()); - float dist = MathHelper.Min(d1, d2); - dist = MathHelper.Min(dist, d3); - dist = MathHelper.Min(dist, d4); - - if (dist <= radius) - { - int damage = (int)(Projectile.damage * explosionDamageMultiplier); - bool crit = Main.rand.Next(100) <= owner.GetCritChance() + 4; - target.StrikeNPC(target.CalculateHitInfo(damage, 0, crit, 0)); - - if (Main.netMode != NetmodeID.SinglePlayer) - NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, i, damage, 0f, 0f, crit ? 1 : 0, 0, 0); - } - } - } - public override void OnKill(int timeLeft) - { - // mostly from AstralCrystal kill code - float rand2PI = Main.rand.NextFloat(MathHelper.TwoPi); - int petalCount = 5; - float speed = 12f; - float scale = Main.rand.NextFloat(1f, 1.35f); - for (float k = 0f; k < MathHelper.TwoPi; k += 0.05f) - { - Vector2 velocity = k.ToRotationVector2() * (2f + (float)(Math.Sin((double)(rand2PI + k * (float)petalCount)) + 1.0) * speed) * Main.rand.NextFloat(0.95f, 1.05f); - Dust dust = Dust.NewDustPerfect(Projectile.Center, 173, new Vector2?(velocity), 0, default, scale); - dust.customData = 0.025f; - } - CircularDamage(80f); - } - } -} diff --git a/Projectiles/Melee/CosmicShivBlade.cs b/Projectiles/Melee/CosmicShivBlade.cs index 092bf4affe..29b208bbbe 100644 --- a/Projectiles/Melee/CosmicShivBlade.cs +++ b/Projectiles/Melee/CosmicShivBlade.cs @@ -4,96 +4,100 @@ using Terraria; using Terraria.ID; using Terraria.ModLoader; using CalamityMod.Buffs.DamageOverTime; +using Microsoft.Xna.Framework.Graphics; +using Terraria.GameContent; +using Terraria.DataStructures; +using Newtonsoft.Json.Linq; +using Terraria.Graphics.Shaders; +using Terraria.Graphics; namespace CalamityMod.Projectiles.Melee { public class CosmicShivBlade : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Melee"; - public const int penetrateMax = 12; - public const float maxScale = 1.8f; - public bool initialized = false; - public float startYVelSign = 0f; + public Vector2 StartPosition = Vector2.Zero; + public int ColorIndex = 0; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 15; + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; + } + public override void SetDefaults() { Projectile.width = 42; Projectile.height = 42; Projectile.friendly = true; - Projectile.penetrate = penetrateMax; + Projectile.penetrate = 5; Projectile.tileCollide = false; - Projectile.timeLeft = 290; + Projectile.timeLeft = 6000; Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 7; + Projectile.localNPCHitCooldown = -1; + Projectile.extraUpdates = 2; + Projectile.alpha = 0; + Projectile.scale = 1.2f; } + + public override void OnSpawn(IEntitySource source) + { + StartPosition = Projectile.position; + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4; + ColorIndex = Main.rand.Next(0, CosmicShivTrail.DustColors.Count); + } + public override void AI() { - if (!initialized) - { - startYVelSign = (float)Math.Sign(Projectile.velocity.Y) * 0.35f; - initialized = true; - } - if (Projectile.penetrate == penetrateMax && Projectile.timeLeft < 245) - { - Projectile.velocity.Y -= startYVelSign; //arc on the X axis (the amount of pressure on this tiny detail made me want to tear my head off) - if (Math.Abs(Projectile.velocity.X) < 30f) - { - Projectile.velocity.X *= 1.04f; - } - } - if (Projectile.velocity.Length() != 0) - { - Projectile.rotation = (float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X) + MathHelper.Pi / 4; - } - else - { - Projectile.rotation += MathHelper.Pi / 6f / (Projectile.scale * 2.5f); - } - Projectile.ai[0]++; - if (Projectile.ai[1] >= 0) - { - Projectile.ai[1]--; - if (Projectile.ai[1] == 0) - { - Projectile.velocity *= -0.9f; - } - } + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver4; + + if (Projectile.Distance(StartPosition) > Projectile.ai[0] * 2) + Projectile.Kill(); + + Lighting.AddLight(Projectile.Center, Projectile.GetAlpha(Color.White).ToVector3() * 0.2f); } + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { - Projectile.scale += (maxScale - 1) / (float)penetrateMax; - Projectile.ai[1] = 5 + Main.rand.Next(-2, 3); target.AddBuff(ModContent.BuffType(), 120); } + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Rectangle sourceRectangle = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame); + Vector2 origin = sourceRectangle.Size() / 2f; + float rotation = Projectile.rotation; + Color randomColor = Projectile.GetAlpha(lightColor); + + float scaleMult = 1.2f; + for (int i = 0; i < Projectile.oldPos.Length; i++) // Afterimages to make the blade look longer + { + Vector2 drawPos = Projectile.oldPos[i] + (Projectile.Size / 2f) - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + Color color = randomColor * ((float)(Projectile.oldPos.Length - i) / (float)Projectile.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color, rotation, origin, Projectile.scale * scaleMult, SpriteEffects.None, 0f); // Smaller, more visible layer + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color * 0.5f, rotation, origin, Projectile.scale * 1.6f * scaleMult, SpriteEffects.None, 0f); // Bigger, less visible layer + scaleMult *= 0.95f; + } + + return false; + } + public override void OnKill(int timeLeft) { - Vector2 randomCirclePointVector = Vector2.One.RotatedByRandom(MathHelper.ToRadians(32f)); - float lerpStart = (float)Main.rand.Next(12, 17); - float lerpEnd = (float)Main.rand.Next(3, 7); - for (float i = 0; i < 9f; ++i) + for (int i = 0; i < 6; i++) { - for (int j = 0; j < 2; ++j) - { - Vector2 randomCirclePointRotated = randomCirclePointVector.RotatedBy((j == 0 ? 1 : -1) * MathHelper.TwoPi / 18); - for (float k = 0f; k < 20f; ++k) - { - Vector2 randomCirclePointLerped = Vector2.Lerp(randomCirclePointVector, randomCirclePointRotated, k / 20f); - float lerpMultiplier = MathHelper.Lerp(lerpStart, lerpEnd, k / 20f) * 4f; - int dustIndex = Dust.NewDust(Projectile.Center, 0, 0, - 173, - 0f, 0f, 100, default, 1.1f); - Main.dust[dustIndex].velocity *= 0.1f; - Main.dust[dustIndex].noGravity = true; - Main.dust[dustIndex].velocity += randomCirclePointLerped * lerpMultiplier; - } - } - - randomCirclePointVector = randomCirclePointVector.RotatedBy(MathHelper.TwoPi / 9); + Dust dust = Dust.NewDustDirect(Projectile.Center, Projectile.width, Projectile.height, DustID.RainbowMk2, 0f, 0f, 0, Projectile.GetAlpha(Color.Purple) * 0.4f, 1.5f); + dust.noGravity = true; } } - public override Color? GetAlpha(Color lightColor) + + public override Color? GetAlpha(Color lightColor) // Probably not the right way to use this function, but it works (hopefully) { - return new Color(124, Main.DiscoG, 255, Projectile.alpha); + Color color = CosmicShivTrail.DustColors[ColorIndex] * Projectile.Opacity; + color = Color.Lerp(color, Color.White, 0.6f); + color.A = 0; + return color; // Take random color from a list and make it more white } } } diff --git a/Projectiles/Melee/CosmicShivTrail.cs b/Projectiles/Melee/CosmicShivTrail.cs new file mode 100644 index 0000000000..01c7d802d6 --- /dev/null +++ b/Projectiles/Melee/CosmicShivTrail.cs @@ -0,0 +1,232 @@ +using System; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using CalamityMod.Buffs.DamageOverTime; +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; +using System.Reflection.Metadata; +using Microsoft.Xna.Framework.Graphics; +using System.Diagnostics.Contracts; +using Terraria.GameContent; +using Terraria.Audio; + +namespace CalamityMod.Projectiles.Melee +{ + public class CosmicShivTrail : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Melee"; + + public NPC target = null; + public const float MaxDistanceToTarget = 540f; + public const float ExplosionDamageMultiplier = 2f; + public const int FadeInTime = 12; + + public static List DustColors = new List + { + new Color(69, 69, 222), + new Color(99, 66, 212), + new Color(130, 64, 214), + new Color(154, 75, 219), + new Color(165, 62, 201) + }; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Type] = 15; + ProjectileID.Sets.TrailingMode[Type] = 2; + } + + public override void SetDefaults() + { + Projectile.width = 24; + Projectile.height = 24; + Projectile.friendly = true; + Projectile.DamageType = DamageClass.Melee; + Projectile.penetrate = 1; + Projectile.tileCollide = false; + Projectile.timeLeft = 220; + Projectile.scale = 0.7f; + Projectile.Opacity = 0f; + Projectile.extraUpdates = 1; + } + + public override void AI() + { + int QuarterSpriteWidth = 48 / 3; + int QuarterSpriteHeight = 48 / 3; + + int QuarterProjWidth = Projectile.width / 3; + int QuarterProjHeight = Projectile.height / 3; + + DrawOriginOffsetX = 0; + DrawOffsetX = -(QuarterSpriteWidth - QuarterProjWidth); + DrawOriginOffsetY = -(QuarterSpriteHeight - QuarterProjHeight); + + + Lighting.AddLight(Projectile.Center, Projectile.GetAlpha(Color.White).ToVector3()); + + Projectile.rotation += Utils.GetLerpValue(-8f, 12f, Projectile.velocity.Length(), clamped: true); + + if (Projectile.ai[0] > 2f) // After two frames + { + Projectile.Opacity = Utils.GetLerpValue(2f, FadeInTime, Projectile.ai[0], clamped: true); // Fade in + + if (Main.rand.Next(0, 2) == 0) // Dust trail + { + float scale = Main.rand.NextFloat(1.6f, 2.1f); + Color randomColor = DustColors[Main.rand.Next(0, DustColors.Count)]; + Dust dust = Dust.NewDustDirect(Projectile.position, 1, 1, DustID.RainbowMk2, 0, 0, 255, randomColor * 0.6f, scale); + dust.noGravity = true; + } + } + + if (Projectile.ai[0] % 30 == 16) // every 0.25 seconds, starting 8 frames later (extraUpdates = 1 so the values are doubled) + { + target = Projectile.Center.ClosestNPCAt(MaxDistanceToTarget); + } + + if (target is not null) + { + Vector2 targetVelocity = (target.Center - Projectile.Center).SafeNormalize(Vector2.Zero); + + float multiplier = Projectile.velocity.Length() < 4f ? Projectile.velocity.Length() + 1f : 1f; // Probably a better way to do this, but just a bandaid fix for if the trail velocity ends up being low + targetVelocity *= Projectile.velocity.Length() + multiplier; + + Projectile.velocity = Vector2.Lerp(Projectile.velocity, targetVelocity, 0.12f); + } + + // lifespan timer + Projectile.ai[0]++; + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + // Summons invisible aura that sticks to enemies, spawning blades + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.position, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, target.whoAmI); + target.AddBuff(ModContent.BuffType(), 60); + } + + // pretty much entirely from the Oracle circular damage code + private void CircularDamage(float radius) + { + if (Projectile.owner != Main.myPlayer) + return; + Player owner = Main.player[Projectile.owner]; + + for (int i = 0; i < Main.npc.Length; ++i) + { + NPC target = Main.npc[i]; + if (!target.active || target.dontTakeDamage || target.friendly) + continue; + + // Shock any valid target within range. Check all four corners of their hitbox. + float d1 = Vector2.Distance(Projectile.Center, target.Hitbox.TopLeft()); + float d2 = Vector2.Distance(Projectile.Center, target.Hitbox.TopRight()); + float d3 = Vector2.Distance(Projectile.Center, target.Hitbox.BottomLeft()); + float d4 = Vector2.Distance(Projectile.Center, target.Hitbox.BottomRight()); + float dist = MathHelper.Min(d1, d2); + dist = MathHelper.Min(dist, d3); + dist = MathHelper.Min(dist, d4); + + if (dist <= radius) + { + int damage = (int)(Projectile.damage * ExplosionDamageMultiplier); + bool crit = Main.rand.Next(100) <= owner.GetCritChance() + 4; + target.StrikeNPC(target.CalculateHitInfo(damage, 0, crit, 0)); + + if (Main.netMode != NetmodeID.SinglePlayer) + NetMessage.SendData(MessageID.DamageNPC, -1, -1, null, i, damage, 0f, 0f, crit ? 1 : 0, 0, 0); + } + } + } + + // Very similar to CosmicShivBlade PreDraw + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + Rectangle sourceRectangle = texture.Frame(1, Main.projFrames[Type], 0, Projectile.frame); + Vector2 origin = sourceRectangle.Size() / 2f; + float rotation = Projectile.rotation; + Color color = Projectile.GetAlpha(Color.White); + float scaleMult = 1f; + + 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 *= ((float)(Projectile.oldPos.Length - (i / 4)) / (float)Projectile.oldPos.Length); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color * 0.4f, rotation * -1f, origin, Projectile.scale * 1.8f * scaleMult, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(sourceRectangle), color, rotation, origin, Projectile.scale * scaleMult, SpriteEffects.None, 0f); + scaleMult *= 0.9f; + } + + return false; + + } + + // Lots of trig here, use desmos to comprehend its full power + public override void OnKill(int timeLeft) + { + float rand2PI = Main.rand.NextFloat(0, MathHelper.TwoPi); // Random rotation offset + int rosePetalCount = Main.rand.Next(5, 8); + int bigWavyPetalCount = Main.rand.Next(7, 11); + int wavyPetalCount = Main.rand.Next(6, 10); + float speed = Main.rand.Next(6, 11); // Size + + int rand = Main.rand.Next(0, 10); // 10% chance rose, 10% chance big wavy shape, and 80% chance small undetail wavy shape + if (rand == 0) { + for (float k = 0f; k < MathHelper.TwoPi; k += 0.03f) + { + float scale = Main.rand.NextFloat(1.1f, 1.4f); + float randomWhitingValue = Main.rand.NextFloat(0.0f, 0.2f); + Color color = Color.Lerp(DustColors[Main.rand.Next(0, DustColors.Count)], Color.White, randomWhitingValue); + + Vector2 velocity = k.ToRotationVector2() * (2f + (float)(Math.Sin((double)(rand2PI + k * (float)rosePetalCount)) + 1.0) * speed) * Main.rand.NextFloat(0.95f, 1.05f); + Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.FireworksRGB, new Vector2?(velocity), 0, color, scale); + dust.noGravity = true; + dust.fadeIn = -1f; + + Dust dust2 = Dust.NewDustPerfect(Projectile.Center, DustID.FireworksRGB, new Vector2?(velocity) * 0.75f, 0, color, scale); + dust2.noGravity = true; + dust2.fadeIn = -1f; + } + } else if (rand == 1) { + for (float k = 0f; k < MathHelper.TwoPi; k += 0.08f) + { + float scale = Main.rand.NextFloat(1.2f, 1.6f); + float randomWhitingValue = Main.rand.NextFloat(0.0f, 0.2f); + Color color = Color.Lerp(DustColors[Main.rand.Next(0, DustColors.Count)], Color.White, randomWhitingValue); + + Vector2 velocity = k.ToRotationVector2() * (float)(Math.Cos((double)(k * (float)bigWavyPetalCount) + rand2PI) + 5.1f) * speed / 4; + Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.FireworksRGB, new Vector2?(velocity), 0, color, scale); + dust.noGravity = true; + dust.fadeIn = -1f; + + Dust dust2 = Dust.NewDustPerfect(Projectile.Center, DustID.FireworksRGB, new Vector2?(velocity) * 0.75f, 0, color, scale); + dust2.noGravity = true; + dust2.fadeIn = -1f; + } + } else { + for (float k = 0f; k < MathHelper.TwoPi; k += 0.2f) + { + float scale = Main.rand.NextFloat(1f, 1.2f); + float randomWhitingValue = Main.rand.NextFloat(0.5f, 0.7f); + Color color = Color.Lerp(DustColors[Main.rand.Next(0, DustColors.Count)], Color.White, randomWhitingValue); + + Vector2 velocity = k.ToRotationVector2() * (0.4f * (float)(Math.Sin((double)(k * (float)wavyPetalCount) + rand2PI) + 2.1f) * (speed / 2)); + Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.FireworksRGB, new Vector2?(velocity), 0, color * 0.3f, scale); + dust.noGravity = true; + dust.fadeIn = -1f; + } + } + + CircularDamage(80f); + } + + public override Color? GetAlpha(Color lightColor) + { + return new Color(238, 171, 255, 25) * Projectile.Opacity; + } + } +} diff --git a/Projectiles/Melee/GalaxyStar.png b/Projectiles/Melee/CosmicShivTrail.png similarity index 100% rename from Projectiles/Melee/GalaxyStar.png rename to Projectiles/Melee/CosmicShivTrail.png diff --git a/Projectiles/Melee/GalaxyStar.cs b/Projectiles/Melee/GalaxyStar.cs deleted file mode 100644 index 6fffa74c23..0000000000 --- a/Projectiles/Melee/GalaxyStar.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using Terraria.Audio; - -namespace CalamityMod.Projectiles.Melee -{ - public class GalaxyStar : ModProjectile, ILocalizedModType - { - public new string LocalizationCategory => "Projectiles.Melee"; - public bool madeCoolMagicSound = false; - public override void SetStaticDefaults() - { - ProjectileID.Sets.TrailCacheLength[Projectile.type] = 4; - ProjectileID.Sets.TrailingMode[Projectile.type] = 0; - } - - public override void SetDefaults() - { - Projectile.width = 42; - Projectile.height = 42; - Projectile.friendly = true; - Projectile.penetrate = 1; - Projectile.tileCollide = false; - Projectile.timeLeft = 160; - Projectile.extraUpdates = 2; - } - public override void AI() - { - Lighting.AddLight(Projectile.Center, 1f, 1f, 1f); - if (!madeCoolMagicSound) - { - SoundEngine.PlaySound(SoundID.Item9, Projectile.position); // Starfury sound - madeCoolMagicSound = true; - } - Projectile.ai[0]++; - if (Projectile.ai[0] % 5 == 0) - { - for (int i = 0; i < Main.rand.Next(2, 4); i++) //2-3 stars - { - Vector2 randVector = Vector2.One.RotatedByRandom(Math.PI * 2.0) * 0.7f; - Dust.NewDust(Projectile.Center, 4, 4, 58, randVector.X, randVector.Y, 0, default, 1f); - } - } - Projectile.rotation += Projectile.velocity.Length() / 19f; - } - - public override bool PreDraw(ref Color lightColor) - { - CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 2); - return false; - } - } -} diff --git a/Projectiles/Melee/Shortswords/CosmicShivProj.cs b/Projectiles/Melee/Shortswords/CosmicShivProj.cs index 6ca1318dc8..a22c6cb94b 100644 --- a/Projectiles/Melee/Shortswords/CosmicShivProj.cs +++ b/Projectiles/Melee/Shortswords/CosmicShivProj.cs @@ -1,9 +1,14 @@ -using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using Terraria; +using Terraria.GameContent; +using Terraria.Graphics; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; @@ -14,6 +19,8 @@ namespace CalamityMod.Projectiles.Melee.Shortswords { public override LocalizedText DisplayName => CalamityUtils.GetItemName(); public override string Texture => "CalamityMod/Items/Weapons/Melee/CosmicShiv"; + public bool MeleeEffect = false; + public int NumHits = 0; public override void SetDefaults() { @@ -29,12 +36,12 @@ namespace CalamityMod.Projectiles.Melee.Shortswords Projectile.hide = true; Projectile.ownerHitCheck = true; Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 8; + Projectile.localNPCHitCooldown = -1; } public override Action EffectBeforePullback => (proj) => { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.velocity * 14f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.velocity * 3f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); }; public override void SetVisualOffsets() @@ -50,31 +57,64 @@ namespace CalamityMod.Projectiles.Melee.Shortswords DrawOriginOffsetY = -(HalfSpriteHeight - HalfProjHeight); } - public override void ExtraBehavior() - { - Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, 173); - } - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { - for (int k = 0; k < 36; k++) - { - int dustID = Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height -16, 173, 0f, 0f, 0, default, 1f); - Main.dust[dustID].velocity *= 3f; - Main.dust[dustID].scale *= 2f; + OnHitEffect(); + + if (NumHits < 3) { // Just to avoid insanity from stacking so many super dummies or hitting many worm segments at once + // 2x bonus for true melee hits (spawns an additional aura plus the one aura from the cosmic shiv ball) + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.position, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, target.whoAmI); + NumHits++; } - target.AddBuff(ModContent.BuffType(), 120); + + target.AddBuff(ModContent.BuffType(), 240); } public override void OnHitPlayer(Player target, Player.HurtInfo info) { - for (int k = 0; k < 36; k++) + OnHitEffect(); + + target.AddBuff(ModContent.BuffType(), 240); + } + + public void OnHitEffect() + { + float rand2PI = Main.rand.NextFloat(MathHelper.TwoPi); // Random rotation offset + int petalCount = Main.rand.Next(5, 8); // Number of star points + float speed = Main.rand.Next(18, 24); // Size of star + + // Bool check so it only performs this effect once per strike, at a 50% chance + if (!MeleeEffect && Main.rand.NextBool()) { - int dustID = Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height - 16, 173, 0f, 0f, 0, default, 1f); - Main.dust[dustID].velocity *= 3f; - Main.dust[dustID].scale *= 2f; + for (float k = 0f; k < MathHelper.TwoPi; k += 0.08f) + { + float scale = Main.rand.NextFloat(1.5f, 1.9f); + float randomWhitingValue = Main.rand.NextFloat(0.0f, 0.2f); + Color color = Color.Lerp(CosmicShivTrail.DustColors[Main.rand.Next(0, CosmicShivTrail.DustColors.Count)], Color.White, randomWhitingValue); // Just for even more variety in colors idk + Vector2 velocity = StarPolarEquation(petalCount, k, rand2PI) * speed * 2; + Dust dust = Dust.NewDustPerfect(Projectile.Center, DustID.FireworksRGB, velocity, 0, color, scale); + dust.noGravity = true; + dust.fadeIn = -1f; // I don't know if this does anything but it looks like the dust fades out faster with this + + Vector2 velocity2 = StarPolarEquation(petalCount, k - 0.04f, rand2PI) * speed * 2 * 0.9f; // Inner star + Dust dust2 = Dust.NewDustPerfect(Projectile.Center, DustID.FireworksRGB, velocity2, 0, color, scale); + dust2.noGravity = true; + dust2.fadeIn = -1f; + } } - target.AddBuff(ModContent.BuffType(), 120); + } + + public Vector2 StarPolarEquation(int pointCount, float angle, float offset) // For OnHitNPC(), Thanks Dominic + { + // There should be a star point that looks directly upward. However, that isn't the case for odd star counts with the equation below. + // To address this, a -90 degree rotation is performed. + // Refer to desmos to view the resulting shape this creates. It's basically a black box of trig otherwise. + float sqrt3 = 1.732051f; + float numerator = MathF.Cos(MathHelper.Pi * (pointCount + 1f) / pointCount); + float starAdjustedAngle = MathF.Asin(MathF.Cos(pointCount * angle + offset)) * 2f; + float denominator = MathF.Cos((starAdjustedAngle + MathHelper.PiOver2 * pointCount) / (pointCount * 2f)); + Vector2 result = angle.ToRotationVector2() * numerator / denominator / sqrt3; + return result; } } }