From 847c4dc7650485ef6d7fe44b02bc00729412f2d5 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 20 Feb 2021 14:21:46 -0600 Subject: [PATCH] Finished the Photon Ripper Also made some primitive drawing adjustments/fixes --- Effects/CalamityShaders.cs | 3 + Effects/PrismCrystalStreak.fx | 70 +++++++++ Effects/PrismCrystalStreak.xnb | Bin 0 -> 2904 bytes .../Melee/{PrismSaw.cs => PhotonRipper.cs} | 12 +- .../Melee/{PrismSaw.png => PhotonRipper.png} | Bin Projectiles/Boss/InfernadoRevenge.cs | 2 +- .../DraedonsArsenal/PhaseslayerProjectile.cs | 2 +- Projectiles/Magic/FabBolt.cs | 6 +- Projectiles/Magic/FabRay.cs | 6 +- ...wGlowmask.png => PhotonRipperGlowmask.png} | Bin ...rojectile.cs => PhotonRipperProjectile.cs} | 89 +++++++----- ...jectile.png => PhotonRipperProjectile.png} | Bin Projectiles/Melee/PrismTooth.cs | 133 +++++++++++------- Projectiles/Rogue/ScarletDevilProjectile.cs | 2 +- Projectiles/Summon/DaedalusLightning.cs | 2 +- TrailGeneration/PrimitiveTrail.cs | 97 +++++++++---- 16 files changed, 304 insertions(+), 120 deletions(-) create mode 100644 Effects/PrismCrystalStreak.fx create mode 100644 Effects/PrismCrystalStreak.xnb rename Items/Weapons/Melee/{PrismSaw.cs => PhotonRipper.cs} (79%) rename Items/Weapons/Melee/{PrismSaw.png => PhotonRipper.png} (100%) rename Projectiles/Melee/{PrismSawGlowmask.png => PhotonRipperGlowmask.png} (100%) rename Projectiles/Melee/{PrismSawProjectile.cs => PhotonRipperProjectile.cs} (63%) rename Projectiles/Melee/{PrismSawProjectile.png => PhotonRipperProjectile.png} (100%) diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index ffab1270d3..22ef4a17b1 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -16,6 +16,7 @@ namespace CalamityMod.Effects public static Effect FabstaffRayShader; public static Effect ScarletDevilShader; public static Effect BordernadoFireShader; + public static Effect PrismCrystalShader; public static void LoadShaders() { @@ -29,6 +30,7 @@ namespace CalamityMod.Effects FabstaffRayShader = CalamityMod.Instance.GetEffect("Effects/FabstaffStreak"); ScarletDevilShader = CalamityMod.Instance.GetEffect("Effects/ScarletDevilStreak"); BordernadoFireShader = CalamityMod.Instance.GetEffect("Effects/BordernadoFire"); + PrismCrystalShader = CalamityMod.Instance.GetEffect("Effects/PrismCrystalStreak"); Filters.Scene["CalamityMod:Astral"] = new Filter(new AstralScreenShaderData(new Ref(AstralFogShader), "AstralPass").UseColor(0.18f, 0.08f, 0.24f), EffectPriority.VeryHigh); @@ -41,6 +43,7 @@ namespace CalamityMod.Effects GameShaders.Misc["CalamityMod:FabstaffRay"] = new MiscShaderData(new Ref(FabstaffRayShader), "TrailPass"); GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"] = new MiscShaderData(new Ref(ScarletDevilShader), "TrailPass"); GameShaders.Misc["CalamityMod:Bordernado"] = new MiscShaderData(new Ref(BordernadoFireShader), "TrailPass"); + GameShaders.Misc["CalamityMod:PrismCrystal"] = new MiscShaderData(new Ref(PrismCrystalShader), "TrailPass"); } } } diff --git a/Effects/PrismCrystalStreak.fx b/Effects/PrismCrystalStreak.fx new file mode 100644 index 0000000000..8ec86f9cd3 --- /dev/null +++ b/Effects/PrismCrystalStreak.fx @@ -0,0 +1,70 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput)0; + float4 pos = mul(input.Position, uWorldViewProjection); + output.Position = pos; + + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + + return output; +} + +// The X coordinate is the trail completion, the Y coordinate is the same as any other. +// This is simply how the primitive TextCoord is layed out in the C# code. +// Inputted images go into uImage1 sampler, in case you have a noise map or something similar. +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + float areaFadeGlow = lerp(1.2, 17, coords.x); + if (coords.x < 0.25) + areaFadeGlow = lerp(areaFadeGlow, 1.2, 1 - coords.x / 0.25); + float2 mapColor = tex2D(uImage1, float2(frac(coords.x - uTime * 4.2), coords.y)); + float opacity = pow(sin(coords.y * 3.141), areaFadeGlow) + 0.6 * lerp(1.1, 0.3, coords.x) * mapColor.r; + + if (coords.x > 0.66) + opacity = lerp(opacity, 0, (coords.x - 0.66) / 0.3); + + return color * opacity; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/PrismCrystalStreak.xnb b/Effects/PrismCrystalStreak.xnb new file mode 100644 index 0000000000000000000000000000000000000000..43f330f1f69e92c4dc2e3d5ceefdd7a67751cc00 GIT binary patch literal 2904 zcmb_eO=ufe5T2D}SE(HoQVJ~?szM8HF~WB3qENebEXR$h+NhS42wDgmc^z#dYu(ju zY?mC=n+rL(KZiOLs?Z*SbWx#gE+H}WRIq7|f#lGGp*`dfD7|X?&Axr>R}(`?JMw7f zoA=GUd9&|5x%BSLYL8axBho(8-Z9IzRkxO$RH>$?=4^f0Sheg+sf<-~jGB`=wX|fE zodrW*H0+_|VeGeTeWhZS>qE)2hFv$U+T>Vjm_I|wj9YbF+nB5wu4C)fp=8dzP&LbM z8|ww@l2MyXkByd>(ie=8MPqz;eEcDDK2^nz|B}y%cd~qhC+B;4A<`Fjj~l+)a`W< z9F$KFlvtjhmE{Q3J+q>hO=q34H$TQ6 zlQErt9V7M}(+4;>5bh)Ef0bvEK=kmeX{_dK>%*Wke?%{H&v;KBoQG@S-XHYyUMbkR zS6-DN5NNN-%#*2><0>73*H}3Q3-4w z{v66O0bd&Wg@9Cmol|&$n>>gtbC#PJ@w~40B4r9EX9fVzFcCiHFoq;g<7*fi#Yxbp zm(uKoh`VnD@1oxyk$G3@=SR;EQ+R(T2NzyRp3dg8$$W*c_GHFdUNNgMPNYU(Pn{Sa zO^v3<#;EI+D7SDbuSH68UGJr^ruQ)y`@)(uN|xZ`nz#q-=bE@qaeuVivRYXahW;VW z+LP4RkNWcSY9ckiwB?g|UGF$$vh#(w8gz)gyTfv9`jBDdO3+*>o8kN#<(hJP$S23~ zm^@qZ`3RDLcplMvI6@jFn!7t!PF~yEnj&i4zP9!J6#FCa15ZPzzWvjC6RCWE6#n~( zU#9OT=C^luvUhfOuKNBM{6GISI0d~^EEW+b^7p{69liUb-uKhZcI(wQKHb! z?9YbWxA^_SI~98v{X$<8oB00<+eO>voIOgL>h~qwv0{eZY1b$Y6o>TNU J@HV;2e*^A2rUw83 literal 0 HcmV?d00001 diff --git a/Items/Weapons/Melee/PrismSaw.cs b/Items/Weapons/Melee/PhotonRipper.cs similarity index 79% rename from Items/Weapons/Melee/PrismSaw.cs rename to Items/Weapons/Melee/PhotonRipper.cs index e0454cfca1..fad70e541b 100644 --- a/Items/Weapons/Melee/PrismSaw.cs +++ b/Items/Weapons/Melee/PhotonRipper.cs @@ -6,18 +6,22 @@ using Terraria.ModLoader; namespace CalamityMod.Items.Weapons.Melee { - public class PrismSaw : ModItem + public class PhotonRipper : ModItem { public override void SetStaticDefaults() { - DisplayName.SetDefault("Prism Saw"); + DisplayName.SetDefault("Photon Ripper"); + Tooltip.SetDefault("Unleashes a flurry of prismatic crystals at extremely fast speeds\n" + + ""); } public override void SetDefaults() { item.height = 134; item.width = 54; - item.damage = 3781; + item.damage = 2581; + item.axe = 3330; + item.axe /= 5; item.melee = true; item.noMelee = true; item.noUseGraphic = true; @@ -29,7 +33,7 @@ namespace CalamityMod.Items.Weapons.Melee item.autoReuse = false; item.value = CalamityGlobalItem.RarityVioletBuyPrice; item.rare = ItemRarityID.Red; - item.shoot = ModContent.ProjectileType(); + item.shoot = ModContent.ProjectileType(); item.shootSpeed = 1f; item.Calamity().customRarity = CalamityRarity.Violet; } diff --git a/Items/Weapons/Melee/PrismSaw.png b/Items/Weapons/Melee/PhotonRipper.png similarity index 100% rename from Items/Weapons/Melee/PrismSaw.png rename to Items/Weapons/Melee/PhotonRipper.png diff --git a/Projectiles/Boss/InfernadoRevenge.cs b/Projectiles/Boss/InfernadoRevenge.cs index 1f7df09256..a5a0dc225b 100644 --- a/Projectiles/Boss/InfernadoRevenge.cs +++ b/Projectiles/Boss/InfernadoRevenge.cs @@ -71,7 +71,7 @@ namespace CalamityMod.Projectiles.Boss public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { if (TornadoDrawer is null) - TornadoDrawer = new PrimitiveTrail(_ => projectile.width * 0.5f + 16f, ColorFunction, true, GameShaders.Misc["CalamityMod:Bordernado"]); + TornadoDrawer = new PrimitiveTrail(_ => projectile.width * 0.5f + 16f, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:Bordernado"]); GameShaders.Misc["CalamityMod:Bordernado"].SetShaderTexture(ModContent.GetTexture("Terraria/Misc/Perlin")); Vector2[] drawPoints = new Vector2[5]; diff --git a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs index 68c8728504..165fcecad2 100644 --- a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs +++ b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs @@ -308,7 +308,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal Rectangle frame = IsSmall ? bladeTexture.Frame(1, 3, 0, BladeFrameY) : bladeTexture.Frame(3, 7, BladeFrameX, BladeFrameY); if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, true, GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]); + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"]); GameShaders.Misc["CalamityMod:PhaseslayerRipEffect"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/SwordSlashTexture")); diff --git a/Projectiles/Magic/FabBolt.cs b/Projectiles/Magic/FabBolt.cs index cdddbd6508..e61e4f4d51 100644 --- a/Projectiles/Magic/FabBolt.cs +++ b/Projectiles/Magic/FabBolt.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; +using System.Collections.Generic; using System.Linq; using Terraria; using Terraria.Graphics.Shaders; @@ -49,6 +50,7 @@ namespace CalamityMod.Projectiles.Magic } else projectile.velocity *= 1.004f; + projectile.rotation = projectile.velocity.ToRotation(); } internal Color ColorFunction(float completionRatio) @@ -68,10 +70,10 @@ namespace CalamityMod.Projectiles.Magic public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false, GameShaders.Misc["CalamityMod:FabstaffRay"]); + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.SmoothCatmullRomPointRetreivalFunction, GameShaders.Misc["CalamityMod:FabstaffRay"]); GameShaders.Misc["CalamityMod:FabstaffRay"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/FabstaffStreak")); - TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 8); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 0, projectile.oldRot); return false; } diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs index 6f934fab3a..2db4a6c8b8 100644 --- a/Projectiles/Magic/FabRay.cs +++ b/Projectiles/Magic/FabRay.cs @@ -78,10 +78,10 @@ namespace CalamityMod.Projectiles.Magic public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, true, GameShaders.Misc["CalamityMod:FabstaffRay"]); + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:FabstaffRay"]); - GameShaders.Misc["CalamityMod:FabstaffRay"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/FabstaffStreak")); - TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 50); + GameShaders.Misc["CalamityMod:FabstaffRay"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition, 76); return false; } diff --git a/Projectiles/Melee/PrismSawGlowmask.png b/Projectiles/Melee/PhotonRipperGlowmask.png similarity index 100% rename from Projectiles/Melee/PrismSawGlowmask.png rename to Projectiles/Melee/PhotonRipperGlowmask.png diff --git a/Projectiles/Melee/PrismSawProjectile.cs b/Projectiles/Melee/PhotonRipperProjectile.cs similarity index 63% rename from Projectiles/Melee/PrismSawProjectile.cs rename to Projectiles/Melee/PhotonRipperProjectile.cs index f6cc8371a2..679d3fc24f 100644 --- a/Projectiles/Melee/PrismSawProjectile.cs +++ b/Projectiles/Melee/PhotonRipperProjectile.cs @@ -1,5 +1,4 @@ -using CalamityMod.Dusts; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using Terraria; @@ -8,13 +7,15 @@ using Terraria.ModLoader; namespace CalamityMod.Projectiles.Melee { - public class PrismSawProjectile : ModProjectile + public class PhotonRipperProjectile : ModProjectile { public Player Owner => Main.player[projectile.owner]; + public const int CrystalShootRate = 5; + public const int ChargeUpTime = 5; public ref float Time => ref projectile.ai[0]; public ref float OriginalDamage => ref projectile.ai[1]; - public float ChargeUpPower => MathHelper.Clamp((float)Math.Pow(Time / 240f, 1.6D), 0f, 1f); - public override void SetStaticDefaults() => DisplayName.SetDefault("Verrrrrrrry over the top chainsaw thing"); + public float ChargeUpPower => MathHelper.Clamp((float)Math.Pow(Time / ChargeUpTime, 1.6D), 0f, 1f); + public override void SetStaticDefaults() => DisplayName.SetDefault("An extraordinarily cost inefficient chainsaw"); // Seriously though Draedon this seems a bit over the top lmfao. public override void SetDefaults() { @@ -26,17 +27,18 @@ namespace CalamityMod.Projectiles.Melee projectile.melee = true; projectile.ownerHitCheck = true; projectile.usesIDStaticNPCImmunity = true; - projectile.idStaticNPCHitCooldown = 2; + projectile.idStaticNPCHitCooldown = 8; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { Texture2D texture = Main.projectileTexture[projectile.type]; - Texture2D glowmaskTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/PrismSawGlowmask"); + Texture2D glowmaskTexture = ModContent.GetTexture("CalamityMod/Projectiles/Melee/PhotonRipperGlowmask"); Rectangle glowmaskRectangle = glowmaskTexture.Frame(1, 6, 0, projectile.frame); Vector2 origin = texture.Size() * 0.5f; Vector2 drawPosition = projectile.Center - Main.screenPosition; SpriteEffects direction = projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + spriteBatch.Draw(texture, drawPosition, null, projectile.GetAlpha(lightColor), projectile.rotation, origin, projectile.scale, direction, 0f); spriteBatch.Draw(glowmaskTexture, drawPosition, glowmaskRectangle, Color.White, projectile.rotation, origin, projectile.scale, direction, 0f); return false; @@ -47,20 +49,23 @@ namespace CalamityMod.Projectiles.Melee PlayChainsawSounds(); DetermineDamage(); - Vector2 playerRotatedPoint = Owner.RotatedRelativePoint(Owner.MountedCenter); + // Determines the owner's position whilst incorporating their fullRotation field. + // It uses vector transformation on a Z rotation matrix based on said rotation under the hood. + // This is essentially just the pure mathematical definition of the RotatedBy method. + Vector2 playerRotatedPosition = Owner.RotatedRelativePoint(Owner.MountedCenter); if (Main.myPlayer == projectile.owner) { if (Owner.channel && !Owner.noItems && !Owner.CCed) - HandleChannelMovement(playerRotatedPoint); + HandleChannelMovement(playerRotatedPosition); else projectile.Kill(); } - DetermineVisuals(playerRotatedPoint); + DetermineVisuals(playerRotatedPosition); ManipulatePlayerValues(); EmitPrettyDust(); - if (Time > 90f && Time % 36f == 35f) + if (Time % CrystalShootRate == CrystalShootRate - 1f) ReleasePrismTeeth(); // Prevent the projectile from dying normally. However, if anything for whatever reason @@ -74,7 +79,7 @@ namespace CalamityMod.Projectiles.Melee { if (projectile.soundDelay <= 0) { - Main.PlaySound(SoundID.Item22, projectile.position); + Main.PlaySound(SoundID.Item22, projectile.Center); projectile.soundDelay = (int)MathHelper.Lerp(30f, 12f, ChargeUpPower); } } @@ -88,32 +93,38 @@ namespace CalamityMod.Projectiles.Melee projectile.netUpdate = true; } - // And then do time based calculations. This does not execute if the original damage is 0. + // And then do time based damage calculations. This does not execute if the original damage is 0. if (OriginalDamage != 0f) projectile.damage = (int)MathHelper.SmoothStep(OriginalDamage * 0.36f, OriginalDamage, ChargeUpPower); } - public void DetermineVisuals(Vector2 playerRotatedPoint) + public void DetermineVisuals(Vector2 playerRotatedPosition) { - float velocityAngle = projectile.velocity.ToRotation(); - projectile.rotation = velocityAngle; + float directionAngle = projectile.velocity.ToRotation(); + projectile.rotation = directionAngle; int oldDirection = projectile.spriteDirection; if (oldDirection == -1) projectile.rotation += MathHelper.Pi; - projectile.direction = projectile.spriteDirection = (Math.Cos(velocityAngle) > 0).ToDirectionInt(); + projectile.direction = projectile.spriteDirection = (Math.Cos(directionAngle) > 0).ToDirectionInt(); + // If the direction differs from what it originaly was, undo the previous 180 degree turn. + // If this is not done, the chainsaw will have 1 frame of rotational "jitter" when the direction changes based on the + // original angle. This effect looks very strange in-game. if (projectile.spriteDirection != oldDirection) projectile.rotation -= MathHelper.Pi; - // Positioning close to the end of the player's arm. - projectile.position = playerRotatedPoint - projectile.Size * 0.5f + velocityAngle.ToRotationVector2() * 30f; + // Positioning close to the player's arm. + projectile.position = playerRotatedPosition - projectile.Size * 0.5f + directionAngle.ToRotationVector2() * 30f; // Update the position a tiny bit every frame at random to make it look like the saw is vibrating. + // It is reset on the next frame. projectile.position += Main.rand.NextVector2Circular(1.4f, 1.4f); // Update glowmask frames. + // Smoothstep is essentially like a linear interpolation but instead of being a straight line its + // curve is pseudo-logistic, with low increases at the ends of the curve. projectile.frameCounter += (int)MathHelper.SmoothStep(12f, 33f, ChargeUpPower); if (projectile.frameCounter >= 32) { @@ -122,28 +133,23 @@ namespace CalamityMod.Projectiles.Melee } } - public void HandleChannelMovement(Vector2 playerRotatedPoint) + public void HandleChannelMovement(Vector2 playerRotatedPosition) { - float speed = 1f; - if (Owner.ActiveItem().shoot == projectile.type) - speed = Owner.ActiveItem().shootSpeed * projectile.scale; + Vector2 idealAimDirection = (Main.MouseWorld - playerRotatedPosition).SafeNormalize(Vector2.UnitX * Owner.direction); - Vector2 currentAimDirection = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction); - Vector2 idealAimDirection = (Main.MouseWorld - playerRotatedPoint).SafeNormalize(Vector2.UnitX * Owner.direction); - - float angularAimVelocity = 0.16f; + float angularAimVelocity = 0.15f; float directionAngularDisparity = projectile.velocity.AngleBetween(idealAimDirection) / MathHelper.Pi; // Increase the turn speed if close to the ideal direction, since successive linear interpolations // are asymptotic. angularAimVelocity += MathHelper.Lerp(0f, 0.25f, Utils.InverseLerp(0.28f, 0.08f, directionAngularDisparity, true)); - if (directionAngularDisparity < 0.02f) - projectile.velocity = Vector2.Lerp(currentAimDirection, idealAimDirection, angularAimVelocity); + if (directionAngularDisparity > 0.02f) + projectile.velocity = Vector2.Lerp(projectile.velocity, idealAimDirection, angularAimVelocity); else projectile.velocity = idealAimDirection; - projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction) * speed; + projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitX * Owner.direction); } public void ManipulatePlayerValues() @@ -163,6 +169,9 @@ namespace CalamityMod.Projectiles.Melee for (int i = 0; i < 2; i++) { Vector2 spawnPosition = projectile.Center + projectile.velocity * 35f; + + // Spawn the dust a little bit on the chainsaw. X variance is less than Y variance to ensure that dust does not + // spawn too far from the blade. spawnPosition += Main.rand.NextVector2CircularEdge(9f, 35f).RotatedBy(projectile.velocity.ToRotation() + MathHelper.PiOver2); Dust rainbowSpark = Dust.NewDustPerfect(spawnPosition, 261); @@ -175,11 +184,27 @@ namespace CalamityMod.Projectiles.Melee public void ReleasePrismTeeth() { + // Play the sound that the crystal vile shard uses. + // Hopefully this isn't too cancerous to listen to, given the shoot rate of the crystals. + Main.PlaySound(SoundID.Item101, projectile.Center); + if (Main.myPlayer != projectile.owner) return; - float shootReach = MathHelper.SmoothStep(projectile.width * 1.2f, projectile.width * 2.25f + 20f, ChargeUpPower); - Projectile.NewProjectile(Owner.Center, projectile.velocity, ModContent.ProjectileType(), projectile.damage / 2, 0f, projectile.owner, 0f, shootReach); + float shootReach = MathHelper.SmoothStep(projectile.width * 1.8f, projectile.width * 5.3f + 16f, ChargeUpPower); + + // Incorporate item shoot speed into the range of the crystals. + shootReach *= Owner.ActiveItem().shootSpeed; + + float distanceFromMouse = Owner.Distance(Main.MouseWorld); + + // If the distance to the mouse is less than the base reach, reach only to mouse. + // This way the player can more directly control the crystals if they want. + // This comes with a small constant offset to cancel out other factors. + if (distanceFromMouse < shootReach && distanceFromMouse > 40f) + shootReach = distanceFromMouse + 32f; + + Projectile.NewProjectile(Owner.Center, projectile.velocity, ModContent.ProjectileType(), projectile.damage / 2, 0f, projectile.owner, shootReach, projectile.whoAmI); } public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) diff --git a/Projectiles/Melee/PrismSawProjectile.png b/Projectiles/Melee/PhotonRipperProjectile.png similarity index 100% rename from Projectiles/Melee/PrismSawProjectile.png rename to Projectiles/Melee/PhotonRipperProjectile.png diff --git a/Projectiles/Melee/PrismTooth.cs b/Projectiles/Melee/PrismTooth.cs index 60f7eb5841..f916eda231 100644 --- a/Projectiles/Melee/PrismTooth.cs +++ b/Projectiles/Melee/PrismTooth.cs @@ -1,8 +1,8 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; -using System.IO; using Terraria; +using Terraria.GameContent.Achievements; using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -12,86 +12,125 @@ namespace CalamityMod.Projectiles.Melee public class PrismTooth : ModProjectile { internal PrimitiveTrail TrailDrawer; - public const int Lifetime = 30; + public const int Lifetime = 80; public Player Owner => Main.player[projectile.owner]; - public ref float Time => ref projectile.ai[0]; - public ref float ShootReach => ref projectile.ai[1]; + public ref float ShootReach => ref projectile.ai[0]; + public ref float Time => ref projectile.ai[1]; public override void SetStaticDefaults() - { - DisplayName.SetDefault("Prism Tooth"); + { + DisplayName.SetDefault("Prism Tooth"); ProjectileID.Sets.TrailingMode[projectile.type] = 2; ProjectileID.Sets.TrailCacheLength[projectile.type] = 36; } - public override void SetDefaults() - { - projectile.width = projectile.height = 35; + public override void SetDefaults() + { + projectile.scale = 0.6f; + projectile.width = projectile.height = 40; projectile.friendly = true; - projectile.penetrate = 1; - projectile.timeLeft = Lifetime; - projectile.melee = true; - } - - public override void SendExtraAI(BinaryWriter writer) => writer.Write((byte)projectile.direction); - - public override void ReceiveExtraAI(BinaryReader reader) => projectile.direction = reader.ReadByte(); + projectile.tileCollide = false; + projectile.penetrate = -1; + projectile.extraUpdates = 5; + projectile.usesLocalNPCImmunity = true; + projectile.localNPCHitCooldown = 4 * projectile.MaxUpdates; + projectile.timeLeft = Lifetime; + projectile.melee = true; + } public override void AI() { - // Determine the initial direction of the tooth in terms of its orbit. - if (Main.myPlayer == projectile.owner && projectile.spriteDirection == 0) - { - projectile.spriteDirection = Main.rand.NextBool(2).ToDirectionInt(); - projectile.netUpdate = true; - } + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.Pi * Time / Lifetime; - projectile.rotation = MathHelper.Pi * Time / Lifetime; - if (projectile.spriteDirection == -1) - projectile.rotation = MathHelper.Pi - projectile.rotation; - projectile.rotation += projectile.velocity.ToRotation(); + Vector2 baseDirection = (MathHelper.TwoPi * Time / Lifetime - MathHelper.PiOver2).ToRotationVector2(); + baseDirection.X *= 0.25f; + + // Constrain the Y offset into the bounds of 0-1 instead of -1-1. This prevents + // the crystal from flying behind the owner. In this context, the Y offset becomes how far away the + // crystal is from its own in terms of reach. + baseDirection.Y = baseDirection.Y * 0.5f + 0.5f; + Vector2 positionOffset = baseDirection * ShootReach; + + // Don't allow the X offset to go too far. + // This hard limit turns the squashed circle into bending, semi-rectangular shape. + if (Math.Abs(positionOffset.X) > 45f) + positionOffset.X = Math.Sign(baseDirection.X) * 45f; // In this context, the velocity is simply the initial direction as a unit vector- it does not // actually influence movement in any way. - float angle = MathHelper.TwoPi * Time / Lifetime - MathHelper.PiOver2; - if (projectile.spriteDirection == -1) - angle += MathHelper.Pi; + positionOffset = positionOffset.RotatedBy(projectile.velocity.ToRotation() - MathHelper.PiOver2); - Vector2 baseDirection = angle.ToRotationVector2(); - baseDirection.X *= 0.25f; - baseDirection.Y = baseDirection.Y * 0.5f + 0.5f; - baseDirection = baseDirection.RotatedBy(projectile.velocity.ToRotation() - MathHelper.PiOver2); - - projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter) + baseDirection * ShootReach; + projectile.Center = Owner.RotatedRelativePoint(Owner.MountedCenter) + projectile.velocity * 42f + positionOffset; projectile.Opacity = Utils.InverseLerp(0f, 12f, Time, true) * Utils.InverseLerp(Lifetime, Lifetime - 12f, Time, true); + // Destroy trees within the range of the past 20 oldPos positions. + for (int i = 0; i < 20; i++) + { + Point pointToCheck = (projectile.oldPos[i] + projectile.Size * 0.5f).ToTileCoordinates(); + AbsolutelyFuckingAnnihilateTrees(pointToCheck.X, pointToCheck.Y); + } + Time++; } - public override Color? GetAlpha(Color lightColor) + public void AbsolutelyFuckingAnnihilateTrees(int x, int y) { - float hue = (projectile.identity % 9f / 9f + projectile.timeLeft / (float)Lifetime) % 1f; - return Color.Lerp(lightColor, Main.hslToRgb(hue, 0.95f, 0.55f), 0.35f) * projectile.Opacity; + Tile tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y); + + // Ignore tiles that are not active and are not breakable by axes. + if (!tileAtPosition.active() || !Main.tileAxe[tileAtPosition.type]) + return; + + // Don't attempt to mine the tile if for whatever reason it's not supposed to be broken. + if (!WorldGen.CanKillTile(x, y)) + return; + + AchievementsHelper.CurrentlyMining = true; + + WorldGen.KillTile(x, y); + if (Main.netMode == NetmodeID.MultiplayerClient) + NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y); + + AchievementsHelper.CurrentlyMining = false; } - internal float WidthFunction(float completionRatio) => 54f; + public override Color? GetAlpha(Color lightColor) => Color.White; + + internal float WidthFunction(float completionRatio) => projectile.scale * 24f * (1f - Utils.InverseLerp(0.7f, 1f, completionRatio, true)); internal Color ColorFunction(float completionRatio) { - Color color = Color.Lerp(Color.White, Color.Violet, Utils.InverseLerp(0f, 0.7f, completionRatio, true)) * (1f - Utils.InverseLerp(0f, 0.98f, completionRatio, true)); - color.A /= 2; - return color; + float hue = (projectile.identity % 9f / 9f + completionRatio * 0.7f) % 1f; + return Color.Lerp(Color.White, Main.hslToRgb(hue, 0.95f, 0.55f), 0.35f) * projectile.Opacity; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { - if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]); + if (Time <= 5f) + return true; - GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); - TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, 60); + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:PrismCrystal"]); + + // Variable adjustment vector used to prevent the trail for starting somewhat that isn't behind + // the crystal. This may appear in small amounts, with offsets of a few pixels, but at the speed + // these crystals go, it's probably not something to worry too much about. + Vector2 generalOffset = projectile.rotation.ToRotationVector2().RotatedBy(MathHelper.PiOver2) * 15f; + generalOffset += projectile.rotation.ToRotationVector2() * -5f * (float)Math.Sin(projectile.rotation); + + // Mess with the oldPos array so that the trail always points towards the crystal. + Vector2 oldPosition = projectile.oldPos[1]; + projectile.oldPos[1] = projectile.oldPos[0] - projectile.rotation.ToRotationVector2() * Vector2.Distance(projectile.oldPos[0], projectile.oldPos[1]); + + // Revert back if the above calculations caused any NaNs. + if (projectile.oldPos[1].HasNaNs()) + projectile.oldPos[1] = oldPosition; + + GameShaders.Misc["CalamityMod:PrismCrystal"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); + TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f + generalOffset - Main.screenPosition, 65); return true; } + // Prevent the crystals from utilizing velocity. Their movement is entirely dependant on Center setting. public override bool ShouldUpdatePosition() => false; } } diff --git a/Projectiles/Rogue/ScarletDevilProjectile.cs b/Projectiles/Rogue/ScarletDevilProjectile.cs index a6921e3e08..6a438a2b93 100644 --- a/Projectiles/Rogue/ScarletDevilProjectile.cs +++ b/Projectiles/Rogue/ScarletDevilProjectile.cs @@ -176,7 +176,7 @@ namespace CalamityMod.Projectiles.Rogue else { if (TrailDrawer is null) - TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]); + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction, GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"]); GameShaders.Misc["CalamityMod:OverpoweredTouhouSpearShader"].SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/ScarletDevilStreak")); TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity.SafeNormalize(Vector2.Zero) * 86f, 60); diff --git a/Projectiles/Summon/DaedalusLightning.cs b/Projectiles/Summon/DaedalusLightning.cs index e451cc00e3..056a522d17 100644 --- a/Projectiles/Summon/DaedalusLightning.cs +++ b/Projectiles/Summon/DaedalusLightning.cs @@ -140,7 +140,7 @@ namespace CalamityMod.Projectiles.Summon public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { if (LightningDrawer is null) - LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, false); + LightningDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, PrimitiveTrail.RigidPointRetreivalFunction); LightningDrawer.Draw(projectile.oldPos.Where(oldPos => oldPos != Vector2.Zero), projectile.Size * 0.5f - Main.screenPosition, 300); return false; diff --git a/TrailGeneration/PrimitiveTrail.cs b/TrailGeneration/PrimitiveTrail.cs index 9037ad0311..7294706863 100644 --- a/TrailGeneration/PrimitiveTrail.cs +++ b/TrailGeneration/PrimitiveTrail.cs @@ -38,21 +38,24 @@ namespace CalamityMod public VertexWidthFunction WidthFunction; public VertexColorFunction ColorFunction; - // NOTE: Beziers can be laggy when a lot of control points are used, since our implementation - // uses a recursive Lerp that gets more computationally expensive the more original indices. - // n(n - 1)/2 linear interpolations to be precise, where n is the amount of original indices. - public bool UsesSmoothening; public BasicEffect BaseEffect; public MiscShaderData SpecialShader; + public TrailPointRetrievalFunction TrailPointFunction; - public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, bool useSmoothening = true, MiscShaderData specialShader = null) + public delegate List TrailPointRetrievalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null); + + public PrimitiveTrail(VertexWidthFunction widthFunction, VertexColorFunction colorFunction, TrailPointRetrievalFunction pointFunction = null, MiscShaderData specialShader = null) { if (widthFunction is null || colorFunction is null) throw new NullReferenceException($"In order to create a primitive trail, a non-null {(widthFunction is null ? "width" : "color")} function must be specified."); WidthFunction = widthFunction; ColorFunction = colorFunction; - UsesSmoothening = useSmoothening; + // Default to bezier smoothening if nothing else is inputted. + if (pointFunction is null) + pointFunction = SmoothBezierPointRetreivalFunction; + + TrailPointFunction = pointFunction; if (specialShader != null) SpecialShader = specialShader; @@ -90,29 +93,31 @@ namespace CalamityMod BaseEffect.Projection = effectProjection; } - public List GetTrailPoints(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints) + public static List RigidPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) { - // Don't smoothen the points unless explicitly told do so. - if (!UsesSmoothening) - { - List basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList(); - List endPoints = new List(); + List basePoints = originalPositions.Where(originalPosition => originalPosition != Vector2.Zero).ToList(); + List endPoints = new List(); - if (basePoints.Count < 3) - return endPoints; - - // Remap the original positions across a certain length. - for (int i = 0; i < totalTrailPoints; i++) - { - float completionRatio = i / (float)totalTrailPoints; - int currentColorIndex = (int)(completionRatio * (basePoints.Count - 1)); - Vector2 currentColor = basePoints[currentColorIndex]; - Vector2 nextColor = basePoints[(currentColorIndex + 1) % basePoints.Count]; - endPoints.Add(Vector2.Lerp(currentColor, nextColor, completionRatio * (basePoints.Count - 1) % 0.999f) + generalOffset); - } + if (basePoints.Count < 3) return endPoints; - } + // Remap the original positions across a certain length. + for (int i = 0; i < totalTrailPoints; i++) + { + float completionRatio = i / (float)totalTrailPoints; + int currentColorIndex = (int)(completionRatio * (basePoints.Count - 1)); + Vector2 currentColor = basePoints[currentColorIndex]; + Vector2 nextColor = basePoints[(currentColorIndex + 1) % basePoints.Count]; + endPoints.Add(Vector2.Lerp(currentColor, nextColor, completionRatio * (basePoints.Count - 1) % 0.999f) + generalOffset); + } + return endPoints; + } + + // NOTE: Beziers can be laggy when a lot of control points are used, since our implementation + // uses a recursive Lerp that gets more computationally expensive the more original indices. + // n(n + 1)/2 linear interpolations to be precise, where n is the amount of original indices. + public static List SmoothBezierPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) + { List controlPoints = new List(); for (int i = 0; i < originalPositions.Count(); i++) { @@ -126,6 +131,32 @@ namespace CalamityMod return controlPoints.Count <= 1 ? controlPoints : bezierCurve.GetPoints(totalTrailPoints); } + public static List SmoothCatmullRomPointRetreivalFunction(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations) + { + List smoothenedPoints = new List(); + for (int i = 0; i < originalPositions.Count() - 1; i++) + { + if (originalPositions.ElementAt(i) == Vector2.Zero || originalPositions.ElementAt(i + 1) == Vector2.Zero) + continue; + + float currentRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i)); + float aheadRotation = MathHelper.WrapAngle(originalRotations.ElementAt(i + 1)); + int pointsToAdd = (int)(Math.Abs(aheadRotation - currentRotation) * 50f / MathHelper.Pi) + 4; + if (pointsToAdd > 6) + { + int v = 7; + } + + float segmentLength = Vector2.Distance(originalPositions.ElementAt(i), originalPositions.ElementAt(i + 1)); + float increment = 1f / (pointsToAdd + 2); + Vector2 end = originalPositions.ElementAt(i) + currentRotation.ToRotationVector2() * segmentLength; + Vector2 front = originalPositions.ElementAt(i + 1) + aheadRotation.ToRotationVector2() * -segmentLength; + for (float j = increment; j < 1f; j += increment) + smoothenedPoints.Add(Vector2.CatmullRom(end, originalPositions.ElementAt(i), originalPositions.ElementAt(i + 1), front, j) + generalOffset); + } + return smoothenedPoints; + } + public VertexPosition2DColor[] GetVerticesFromTrailPoints(List trailPoints) { List vertices = new List(); @@ -181,19 +212,29 @@ namespace CalamityMod return indices; } - public void Draw(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints) + public void Draw(IEnumerable originalPositions, Vector2 generalOffset, int totalTrailPoints, IEnumerable originalRotations = null) { Main.instance.GraphicsDevice.RasterizerState = RasterizerState.CullNone; - List trailPoints = GetTrailPoints(originalPositions, generalOffset, totalTrailPoints); + List trailPoints = TrailPointFunction(originalPositions, generalOffset, totalTrailPoints, originalRotations); // A trail with only one point or less has nothing to connect to, and therefore, can't make a trail. - if (originalPositions.Count() <= 1 || trailPoints.Count <= 1) + if (originalPositions.Count() <= 2 || trailPoints.Count <= 2) + return; + + // If the trail point has any NaN positions, don't draw anything. + if (trailPoints.Any(point => point.HasNaNs())) return; UpdateBaseEffect(out Matrix projection, out Matrix view); VertexPosition2DColor[] vertices = GetVerticesFromTrailPoints(trailPoints); + short[] triangleIndices = GetIndicesFromTrailPoints(trailPoints.Count); + // Don't draw anything if the indicies/vertices are in any way invalid. + // If they are, the graphics engine, along with the entire game, will crash. + if (triangleIndices.Length % 6 != 0 || vertices.Length % 2 != 0) + return; + if (SpecialShader != null) { SpecialShader.Shader.Parameters["uWorldViewProjection"].SetValue(view * projection);