diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 87be21cd53..9325d64cfd 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -19,9 +19,9 @@ namespace CalamityMod.Effects internal static Effect AstralFogShader; // - // All below shaders created by Dominic Karma + // All below shaders created by Lucille Karma // - #region Dominic's Shaders + #region Lucille's Shaders // The Dance of Light's Blinding Light internal static Effect DanceOfLightBlindingShader; @@ -92,7 +92,7 @@ namespace CalamityMod.Effects // Was previously used by Dom's Bladecrest Oathsword. Appears to govern the swing animation. internal static Effect LocalLinearTransformationShader; - // UNUSED -- Probably leftover from Dominic's experiments with applying shaders to primitives (arbitrary GPU-rendered triangles) + // UNUSED -- Probably leftover from Lucille's experiments with applying shaders to primitives (arbitrary GPU-rendered triangles) internal static Effect BasicPrimitiveShader; // Artemis Ohio Beam. Also used by get fixed boi Nuclear Terror's "G-FUEL BEAM" @@ -145,6 +145,12 @@ namespace CalamityMod.Effects // Used to render the results of Navier-Stokes fluid simulations. internal static Effect FluidShaders; + + // Used by projectiles fired by the Sylvestaff. + internal static Effect SylvestaffProjectileShader; + + // Used by the ribbons on the Sylvestaff. + internal static Effect SylvestaffRibbonShader; #endregion // @@ -237,7 +243,7 @@ namespace CalamityMod.Effects var astralPassReg = new AstralScreenShaderData(new Ref(AstralFogShader), "AstralPass").UseColor(0.18f, 0.08f, 0.24f); RegisterSceneFilter(astralPassReg, "Astral", EffectPriority.VeryHigh); - #region Loading Dominic's Shaders + #region Loading Lucille's Shaders DanceOfLightBlindingShader = LoadShader("LightBurstShader"); RegisterScreenShader(DanceOfLightBlindingShader, "BurstPass", "LightBurst"); @@ -360,6 +366,12 @@ namespace CalamityMod.Effects // This shader is not registered with the game but is invoked directly to render the results of fluid simulation. FluidShaders = LoadShader("FluidShaders"); + + SylvestaffProjectileShader = LoadShader("SylvestaffProjectileShader"); + RegisterMiscShader(SylvestaffProjectileShader, "TrailPass", "SylvestaffProjectile"); + + SylvestaffRibbonShader = LoadShader("SylvestaffRibbonShader"); + RegisterMiscShader(SylvestaffRibbonShader, "AutoloadPass", "SylvestaffRibbon"); #endregion #region Loading Iban's Shaders diff --git a/Effects/SylvestaffProjectileShader.fx b/Effects/SylvestaffProjectileShader.fx new file mode 100644 index 0000000000..728a0f6a9a --- /dev/null +++ b/Effects/SylvestaffProjectileShader.fx @@ -0,0 +1,76 @@ +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; +float4 uShaderSpecificData; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float3 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float3 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; +} + +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + // Account for texture distortion artifacts. + coords.y = (coords.y - 0.5) / input.TextureCoordinates.z + 0.5; + + float bump = sin(coords.y * 3.141); + + // Calculate the amount of additive glow for this pixel, using a combination of a scrolling texture and an extreme + // exponential squash of the prior 0-1-0 bump, creating a "center" to the glow and ensuring that the + // ray doesn't look like just a scrolling gradient. + float streakColor = tex2D(uImage1, coords + float2(uTime * -2.75, 0)); + float glow = streakColor.r + pow(bump, 20) * 0.4; + + // Determine opacity based on a weaker exponential squash of the bump in order to create faded horizontal edges. + float opacity = pow(bump, 5); + + // Apply glow. + opacity += glow * opacity; + + return color * opacity; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/SylvestaffProjectileShader.xnb b/Effects/SylvestaffProjectileShader.xnb new file mode 100644 index 0000000000..06bc3ffb44 Binary files /dev/null and b/Effects/SylvestaffProjectileShader.xnb differ diff --git a/Effects/SylvestaffRibbonShader.fx b/Effects/SylvestaffRibbonShader.fx new file mode 100644 index 0000000000..3474df6d49 --- /dev/null +++ b/Effects/SylvestaffRibbonShader.fx @@ -0,0 +1,89 @@ +sampler noiseTextureA : register(s1); + +float pixelationFactor; +float uSaturation; +float4 uShaderSpecificData; +matrix uWorldViewProjection; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float3 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float3 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; +} + +float QuadraticBump(float x) +{ + return x * (4 - x * 4); +} + +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = 1; + float2 coords = input.TextureCoordinates; + coords.y = (coords.y - 0.5) / input.TextureCoordinates.z + 0.5; + + float feelerColorStart = 0.61; + float colorSpacingFactor = 1.9; + float4 outlineColor = float4(91, 114, 119, 255) / 255; + + float erasePixelInterpolant = coords.x - 0.9 - distance(coords.y, 0.5) * 0.1; + + // Band 1: Outline color. + color = lerp(color, outlineColor, coords.x >= feelerColorStart); + + // Band 2: Pink. + float pinkStart = feelerColorStart + colorSpacingFactor * 0.01; + color = lerp(color, float4(221, 150, 179, 255) / 255, coords.x >= pinkStart); + + // Band 3: Outline color. + float outlineAStart = pinkStart + colorSpacingFactor * 0.04; + color = lerp(color, outlineColor, coords.x >= outlineAStart); + + // Band 4: Blue. + float blueStart = outlineAStart + colorSpacingFactor * 0.01; + color = lerp(color, float4(48, 117, 222, 255) / 255, coords.x >= blueStart); + + // Band 5: Baby blue. + float babyBlueStart = blueStart + colorSpacingFactor * 0.04; + color = lerp(color, float4(167, 222, 255, 255) / 255, coords.x >= babyBlueStart); + + // Add an outline to the ends of the feeler. + float horizontalDistanceFromCenter = distance(coords.y, 0.5); + color = lerp(color, outlineColor, horizontalDistanceFromCenter >= 0.3); + color = lerp(color, outlineColor, erasePixelInterpolant >= -0.02); + + float permittedDirection = sign(uSaturation); + float direction = sign(dot(input.Position.xy - uShaderSpecificData.xy, uShaderSpecificData.zw)); + erasePixelInterpolant *= direction == permittedDirection || coords.x < 0.5; + + return color * (erasePixelInterpolant < 0) * input.Color; +} + +technique Technique1 +{ + pass AutoloadPass + { + VertexShader = compile vs_3_0 VertexShaderFunction(); + PixelShader = compile ps_3_0 PixelShaderFunction(); + } +} diff --git a/Effects/SylvestaffRibbonShader.xnb b/Effects/SylvestaffRibbonShader.xnb new file mode 100644 index 0000000000..d6848767d4 Binary files /dev/null and b/Effects/SylvestaffRibbonShader.xnb differ diff --git a/ExtraTextures/BloomCirclePinpoint.png b/ExtraTextures/BloomCirclePinpoint.png new file mode 100644 index 0000000000..49c2dcdb60 Binary files /dev/null and b/ExtraTextures/BloomCirclePinpoint.png differ diff --git a/ExtraTextures/Trails/FabstaffStreak.png b/ExtraTextures/Trails/SylvestaffStreak.png similarity index 100% rename from ExtraTextures/Trails/FabstaffStreak.png rename to ExtraTextures/Trails/SylvestaffStreak.png diff --git a/Graphics/Primitives/IPixelatedPrimitiveRenderer.cs b/Graphics/Primitives/IPixelatedPrimitiveRenderer.cs index 7270d3e93a..14edbcb506 100644 --- a/Graphics/Primitives/IPixelatedPrimitiveRenderer.cs +++ b/Graphics/Primitives/IPixelatedPrimitiveRenderer.cs @@ -15,6 +15,6 @@ namespace CalamityMod.Graphics.Primitives /// /// Render primitives that use pixelation here. /// - void RenderPixelatedPrimitives(SpriteBatch spriteBatch); + void RenderPixelatedPrimitives(SpriteBatch spriteBatch, PixelationPrimitiveLayer layer); } } diff --git a/Graphics/Primitives/PixelationPrimitiveLayer.cs b/Graphics/Primitives/PixelationPrimitiveLayer.cs index 1ed0348bc8..4f05c51ef2 100644 --- a/Graphics/Primitives/PixelationPrimitiveLayer.cs +++ b/Graphics/Primitives/PixelationPrimitiveLayer.cs @@ -1,15 +1,17 @@ -using Microsoft.Xna.Framework.Graphics; +using System; namespace CalamityMod.Graphics.Primitives { /// /// Controls what layer the renders to. /// + [Flags] public enum PixelationPrimitiveLayer { - BeforeNPCs, - AfterNPCs, - BeforeProjectiles, - AfterProjectiles + BeforeNPCs = 1, + AfterNPCs = 2, + BeforeProjectiles = 4, + AfterProjectiles = 8, + AfterPlayers = 16 } } diff --git a/Graphics/Primitives/PrimitivePixelationSystem.cs b/Graphics/Primitives/PrimitivePixelationSystem.cs index 19d5fb1b5c..4d2bc635de 100644 --- a/Graphics/Primitives/PrimitivePixelationSystem.cs +++ b/Graphics/Primitives/PrimitivePixelationSystem.cs @@ -18,6 +18,8 @@ namespace CalamityMod.Graphics.Primitives private static ManagedRenderTarget PixelationTarget_AfterProjectiles; + private static ManagedRenderTarget PixelationTarget_AfterPlayers; + private static RenderTarget2D CreatePixelTarget(int width, int height) => new(Main.instance.GraphicsDevice, width / 2, height / 2); /// @@ -36,11 +38,13 @@ namespace CalamityMod.Graphics.Primitives On_Main.CheckMonoliths += DrawToTargets; On_Main.DoDraw_DrawNPCsOverTiles += DrawTarget_NPCs; On_Main.DrawProjectiles += DrawTarget_Projectiles; + On_Main.DrawPlayers_AfterProjectiles += DrawTarget_Players; PixelationTarget_BeforeNPCs = new(true, CreatePixelTarget); PixelationTarget_AfterNPCs = new(true, CreatePixelTarget); PixelationTarget_BeforeProjectiles = new(true, CreatePixelTarget); PixelationTarget_AfterProjectiles = new(true, CreatePixelTarget); + PixelationTarget_AfterPlayers = new(true, CreatePixelTarget); } public override void Unload() @@ -63,6 +67,7 @@ namespace CalamityMod.Graphics.Primitives var afterNPCs = new List(); var beforeProjectiles = new List(); var afterProjectiles = new List(); + var afterPlayers = new List(); // Check every active projectile. foreach (Projectile projectile in Main.ActiveProjectiles) @@ -70,14 +75,14 @@ namespace CalamityMod.Graphics.Primitives // If the projectile is active, a mod projectile, and uses the interface, add it to the list of primitives to draw this frame. if (projectile.ModProjectile != null && projectile.ModProjectile is IPixelatedPrimitiveRenderer pixelPrimitiveProjectile) { - var listToUse = pixelPrimitiveProjectile.LayerToRenderTo switch - { - PixelationPrimitiveLayer.BeforeNPCs => beforeNPCs, - PixelationPrimitiveLayer.AfterNPCs => afterNPCs, - PixelationPrimitiveLayer.BeforeProjectiles => beforeProjectiles, - _ => afterProjectiles - }; - listToUse.Add(pixelPrimitiveProjectile); + if (pixelPrimitiveProjectile.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.BeforeNPCs)) + beforeNPCs.Add(pixelPrimitiveProjectile); + if (pixelPrimitiveProjectile.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.AfterNPCs)) + afterNPCs.Add(pixelPrimitiveProjectile); + if (pixelPrimitiveProjectile.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.BeforeProjectiles)) + beforeProjectiles.Add(pixelPrimitiveProjectile); + if (pixelPrimitiveProjectile.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.AfterPlayers)) + afterPlayers.Add(pixelPrimitiveProjectile); } } @@ -87,23 +92,24 @@ namespace CalamityMod.Graphics.Primitives // If the NPC is active, a mod NPC, and uses the interface, add it to the list of primitives to draw this frame. if (npc.ModNPC != null && npc.ModNPC is IPixelatedPrimitiveRenderer pixelPrimitiveNPC) { - var listToUse = pixelPrimitiveNPC.LayerToRenderTo switch - { - PixelationPrimitiveLayer.BeforeNPCs => beforeNPCs, - PixelationPrimitiveLayer.AfterNPCs => afterNPCs, - PixelationPrimitiveLayer.BeforeProjectiles => beforeProjectiles, - _ => afterProjectiles - }; - listToUse.Add(pixelPrimitiveNPC); + if (pixelPrimitiveNPC.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.BeforeNPCs)) + beforeNPCs.Add(pixelPrimitiveNPC); + if (pixelPrimitiveNPC.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.AfterNPCs)) + afterNPCs.Add(pixelPrimitiveNPC); + if (pixelPrimitiveNPC.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.BeforeProjectiles)) + beforeProjectiles.Add(pixelPrimitiveNPC); + if (pixelPrimitiveNPC.LayerToRenderTo.HasFlag(PixelationPrimitiveLayer.AfterPlayers)) + afterPlayers.Add(pixelPrimitiveNPC); } } CurrentlyRendering = true; - DrawPrimsToRenderTarget(PixelationTarget_BeforeNPCs, beforeNPCs); - DrawPrimsToRenderTarget(PixelationTarget_AfterNPCs, afterNPCs); - DrawPrimsToRenderTarget(PixelationTarget_BeforeProjectiles, beforeProjectiles); - DrawPrimsToRenderTarget(PixelationTarget_AfterProjectiles, afterProjectiles); + DrawPrimsToRenderTarget(PixelationTarget_BeforeNPCs, PixelationPrimitiveLayer.BeforeNPCs, beforeNPCs); + DrawPrimsToRenderTarget(PixelationTarget_AfterNPCs, PixelationPrimitiveLayer.AfterNPCs, afterNPCs); + DrawPrimsToRenderTarget(PixelationTarget_BeforeProjectiles, PixelationPrimitiveLayer.BeforeProjectiles, beforeProjectiles); + DrawPrimsToRenderTarget(PixelationTarget_AfterProjectiles, PixelationPrimitiveLayer.AfterProjectiles, afterProjectiles); + DrawPrimsToRenderTarget(PixelationTarget_AfterPlayers, PixelationPrimitiveLayer.AfterPlayers, afterPlayers); Main.instance.GraphicsDevice.SetRenderTarget(null); @@ -111,7 +117,7 @@ namespace CalamityMod.Graphics.Primitives orig(); } - private static void DrawPrimsToRenderTarget(RenderTarget2D renderTarget, List pixelPrimitives) + private static void DrawPrimsToRenderTarget(RenderTarget2D renderTarget, PixelationPrimitiveLayer layer, List pixelPrimitives) { // Swap to the target regardless, in order to clear any leftover content from last frame. Not doing this results in the final frame lingering once it stops rendering. renderTarget.SwapTo(); @@ -121,7 +127,7 @@ namespace CalamityMod.Graphics.Primitives Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null); foreach (var pixelPrimitiveDrawer in pixelPrimitives) - pixelPrimitiveDrawer.RenderPixelatedPrimitives(Main.spriteBatch); + pixelPrimitiveDrawer.RenderPixelatedPrimitives(Main.spriteBatch, layer); Main.spriteBatch.End(); } @@ -143,6 +149,12 @@ namespace CalamityMod.Graphics.Primitives DrawTargetScaled(PixelationTarget_AfterProjectiles); } + private void DrawTarget_Players(On_Main.orig_DrawPlayers_AfterProjectiles orig, Main self) + { + orig(self); + DrawTargetScaled(PixelationTarget_AfterPlayers); + } + private static void DrawTargetScaled(ManagedRenderTarget target) { Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); diff --git a/Items/CalamityGlobalItemTooltip.cs b/Items/CalamityGlobalItemTooltip.cs index c848144c6c..d70c85ad00 100644 --- a/Items/CalamityGlobalItemTooltip.cs +++ b/Items/CalamityGlobalItemTooltip.cs @@ -295,8 +295,8 @@ namespace CalamityMod.Items nameLine.OverrideColor = new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB); // Developer items - if (item.type == ModContent.ItemType()) - nameLine.OverrideColor = new Color(Main.DiscoR, 100, 255); + if (item.type == ModContent.ItemType()) + nameLine.OverrideColor = new Color(249, 197, 255); if (item.type == ModContent.ItemType()) nameLine.OverrideColor = new Color(0, 0, 255); if (item.type == ModContent.ItemType()) diff --git a/Items/Weapons/Magic/Fabstaff.cs b/Items/Weapons/Magic/Fabstaff.cs deleted file mode 100644 index cde4852367..0000000000 --- a/Items/Weapons/Magic/Fabstaff.cs +++ /dev/null @@ -1,53 +0,0 @@ -using CalamityMod.Items.Materials; -using CalamityMod.Projectiles.Magic; -using CalamityMod.Rarities; -using CalamityMod.Tiles.Furniture.CraftingStations; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Weapons.Magic -{ - public class Fabstaff : ModItem, ILocalizedModType - { - public new string LocalizationCategory => "Items.Weapons.Magic"; - public override void SetStaticDefaults() - { - Item.staff[Type] = true; - } - - public override void SetDefaults() - { - Item.width = 84; - Item.height = 84; - Item.damage = 140; - Item.DamageType = DamageClass.Magic; - Item.mana = 35; - Item.useAnimation = Item.useTime = 20; - Item.useStyle = ItemUseStyleID.Shoot; - Item.noMelee = true; - Item.knockBack = 5f; - - Item.value = CalamityGlobalItem.RarityHotPinkBuyPrice; - Item.rare = ModContent.RarityType(); - Item.Calamity().devItem = true; - - Item.UseSound = SoundID.Item60; - Item.autoReuse = true; - Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 13.5f; - } - - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(ItemID.RainbowRod). - AddIngredient(5). - AddIngredient(10). - AddTile(). - Register(); - } - } -} diff --git a/Items/Weapons/Magic/Fabstaff.png b/Items/Weapons/Magic/Fabstaff.png deleted file mode 100644 index 6658464065..0000000000 Binary files a/Items/Weapons/Magic/Fabstaff.png and /dev/null differ diff --git a/Items/Weapons/Magic/Sylvestaff.cs b/Items/Weapons/Magic/Sylvestaff.cs new file mode 100644 index 0000000000..f34f2af785 --- /dev/null +++ b/Items/Weapons/Magic/Sylvestaff.cs @@ -0,0 +1,121 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Magic; +using CalamityMod.Rarities; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.Magic +{ + [LegacyName("Fabstaff")] + public class Sylvestaff : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Weapons.Magic"; + + /// + /// The amount by which the staff recoils after firing. + /// + public static float StaffRecoilForce => 0.04f; + + /// + /// The rate at which rays from the staff can release bolts. + /// + public static int RayBoltShootRate => CalamityUtils.SecondsToFrames(0.0667f); + + /// + /// The distance range that targets need to be within relative to a ray's evaluation points in order to shoot bolts. + /// + public static float RayBoltTargetingRange => 272f; + + /// + /// The turn speed interpolant that dictates how fast or slow the staff can move to aim towards the mouse. + /// + public static float TurnSpeedInterpolant => 0.276f; + + /// + /// The sound played when Sylvestaff rays are fired. + /// + public static readonly SoundStyle FireSound = new SoundStyle("CalamityMod/Sounds/Item/SylvestaffFire", 3) with { MaxInstances = 5 }; + + /// + /// The sound played when Sylvestaff rays bounce off of tiles. + /// + public static readonly SoundStyle BounceSound = new SoundStyle("CalamityMod/Sounds/Item/SylvestaffProjectileBounce", 3) with { MaxInstances = 5 }; + + public override string Texture + { + get + { + if (WorldGen.SavedOreTiers.Gold == TileID.Gold || Main.gameMenu) + return "CalamityMod/Items/Weapons/Magic/SylvestaffGold"; + + return "CalamityMod/Items/Weapons/Magic/SylvestaffPlatinum"; + } + } + + public override void SetStaticDefaults() + { + Item.staff[Item.type] = true; + } + + public override void SetDefaults() + { + Item.width = 84; + Item.height = 84; + Item.damage = 125; + Item.DamageType = DamageClass.Magic; + Item.mana = 50; + Item.useTime = 20; + Item.useAnimation = 20; + Item.useStyle = ItemUseStyleID.Shoot; + Item.noMelee = true; + Item.channel = true; + Item.noUseGraphic = true; + Item.knockBack = 5f; + + Item.value = CalamityGlobalItem.RarityHotPinkBuyPrice; + Item.rare = ModContent.RarityType(); + Item.Calamity().devItem = true; + + Item.autoReuse = true; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 13.5f; + } + + public override void ModifyManaCost(Player player, ref float reduce, ref float mult) + { + if (player.ownedProjectileCounts[Item.shoot] <= 0) + mult *= 0; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(ItemID.RainbowRod). + AddIngredient(ItemID.GenderChangePotion). + AddRecipeGroup("AnyGoldBar", 5). + AddIngredient(10). + AddIngredient(5). + AddTile(). + Register(); + } + + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + Texture2D texture = ModContent.Request(Texture).Value; + spriteBatch.Draw(texture, position, frame, drawColor, 0f, origin, scale, SpriteEffects.None, 0); + return false; + } + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) + { + Texture2D texture = ModContent.Request(Texture).Value; + spriteBatch.Draw(texture, Item.position - Main.screenPosition, null, lightColor, 0f, Vector2.Zero, scale, SpriteEffects.None, 0); + return false; + } + } +} diff --git a/Items/Weapons/Magic/SylvestaffGold.png b/Items/Weapons/Magic/SylvestaffGold.png new file mode 100644 index 0000000000..2cd1d31e38 Binary files /dev/null and b/Items/Weapons/Magic/SylvestaffGold.png differ diff --git a/Items/Weapons/Magic/SylvestaffPlatinum.png b/Items/Weapons/Magic/SylvestaffPlatinum.png new file mode 100644 index 0000000000..c611c58ea1 Binary files /dev/null and b/Items/Weapons/Magic/SylvestaffPlatinum.png differ diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Magic.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Magic.hjson index abce23f859..427c9585ef 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Magic.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Magic.hjson @@ -308,11 +308,6 @@ EvergladeSpray: { Tooltip: Fires a stream of burning green ichor } -Fabstaff: { - DisplayName: Fabstaff - Tooltip: Casts a bouncing beam that splits when enemies are near it -} - FaceMelter: { DisplayName: Face Melter Tooltip: @@ -856,6 +851,15 @@ SubsumingVortex: { ''' } +Sylvestaff: { + DisplayName: Sylvestaff + Tooltip: + ''' + Casts a bouncing beam that splits when enemies are near it + 'Also known as the Karma Staff!' + ''' +} + TacticiansTrumpCard: { DisplayName: Tactician's Trump Card Tooltip: diff --git a/Localization/en-US/Mods.CalamityMod.NPCs.hjson b/Localization/en-US/Mods.CalamityMod.NPCs.hjson index a91177866b..ca33d6a044 100644 --- a/Localization/en-US/Mods.CalamityMod.NPCs.hjson +++ b/Localization/en-US/Mods.CalamityMod.NPCs.hjson @@ -466,7 +466,7 @@ BrimstoneWitch: { } EnchantButton: Enchant - DonorButton: Donors + DonorButton: Donors DonorShoutout: Hey {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23} and {24}. You guys are good people. TownNPCMood: { diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Magic.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Magic.hjson index 999a2cae5e..c3c7de4c15 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Magic.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Magic.hjson @@ -66,8 +66,6 @@ EventHorizonStar.DisplayName: Event Horizon Star EvergladeSprayProjectile.DisplayName: Everglade Spray ExoVortex.DisplayName: Subsuming Vortex ExoVortex2.DisplayName: Subsuming Vortex -FabBolt.DisplayName: Fab Bolt -FabRay.DisplayName: Fab Ray FatesRevealFlame.DisplayName: Fate's Reveal FireImplosion.DisplayName: Swirling Backdraft FlareBoltProjectile.DisplayName: Flare Bolt @@ -216,6 +214,8 @@ SpiritDust.DisplayName: Spirit Dust Starblast.DisplayName: Star StardustElementalBeam.DisplayName: Stardust Beam StickyFeather.DisplayName: Feather +SylveBolt.DisplayName: Sylv Bolt +SylveRay.DisplayName: Sylv Ray TacticiansElectricBoom.DisplayName: Electric Explosion TacticiansTrumpCardProj.DisplayName: Trump Beam TearsofHeavenProjectile.DisplayName: Tears of Heaven @@ -261,3 +261,5 @@ WyvernFeatherPurple.DisplayName: Feather WyvernProjectile.DisplayName: Wyvern YharimsCrystalBeam.DisplayName: Yharim's Beam YharimsCrystalPrism.DisplayName: Yermes Christal +SylvBolt.DisplayName: Sylv Bolt +SylvRay.DisplayName: Sylv Ray diff --git a/Physics/Rope.cs b/Physics/Rope.cs new file mode 100644 index 0000000000..746495c53a --- /dev/null +++ b/Physics/Rope.cs @@ -0,0 +1,229 @@ +using System; +using Microsoft.Xna.Framework; +using Terraria; + +namespace CalamityMod.Physics; + +internal class Rope +{ + /// + /// A 0-1 interpolant which dictates a dampning factor for velocity integration increments. + /// + private float MovementSpeedDampingCoefficient + { + get; + set; + } + + /// + /// A timer that increments in respond to wind, assuming wind response is enabled in the . + /// + private float WindTime + { + get; + set; + } + + /// + /// The set of segments that compose this rope. + /// + public RopeSegment[] Segments + { + get; + set; + } + + /// + /// The set of positions that compose this rope. + /// + public Vector2[] SegmentPositions + { + get; + private set; + } + + /// + /// The desired distance between each segment on the rope. + /// + public float DistancePerSegment + { + get; + set; + } + + /// + /// The gravity force to exert on the rope when updating. + /// + public Vector2 Gravity + { + get; + set; + } + + /// + /// The amount of steps to perform when constraining tiles to their desired lengths. Higher values equate to greater accuracy, but reduced performance. + /// + public int ConstraintSteps + { + get; + private set; + } + + /// + /// Sets of settings that dictate how this rope should behave. + /// + public RopeSettings Settings + { + get; + set; + } + + /// + /// Whether this rope should collide with tiles or not. + /// + public bool InteractWithTiles => Settings.TileColliderArea is not null; + + public Rope(Vector2 start, Vector2 end, int segmentCount, float distancePerSegment, Vector2 gravity, RopeSettings settings, int constraintSteps = 10) + { + Segments = new RopeSegment[segmentCount]; + SegmentPositions = new Vector2[segmentCount]; + for (var i = 0; i < segmentCount; i++) + { + var segmentPos = Vector2.Lerp(start, end, i / (segmentCount - 1f)); + Segments[i] = new RopeSegment(segmentPos); + } + + Segments[0].FixedInPlace = settings.StartIsFixed; + Segments[^1].FixedInPlace = settings.EndIsFixed; + RecalculateSegmentPositions(); + + DistancePerSegment = distancePerSegment; + Gravity = gravity; + ConstraintSteps = constraintSteps; + + Settings = settings; + } + + /// + /// Recalculates the cache based on positions. + /// + private void RecalculateSegmentPositions() + { + for (var i = 0; i < Segments.Length; i++) + SegmentPositions[i] = Segments[i].Position; + } + + /// + /// Moves a given position around, obeying tile interaction rules if this rope requires them. + /// + /// The position vector to move. + /// The base velocity to consider. + private void Move(ref Vector2 position, Vector2 baseVelocity) + { + // Apply standard Eulerian integration if tile interactions are not required. + if (!InteractWithTiles || Settings.TileColliderArea is null) + { + position += baseVelocity; + return; + } + + // If tile interactions *are* required, handle them before moving forward. + var width = (int)Settings.TileColliderArea.Value.X; + var height = (int)Settings.TileColliderArea.Value.Y; + var newVelocity = Collision.noSlopeCollision(position, baseVelocity, width, height + 2, true, true); + newVelocity = Collision.noSlopeCollision(position, newVelocity, width, height, true, true); + var finalVelocity = baseVelocity; + if (Math.Abs(baseVelocity.X) > Math.Abs(newVelocity.X)) + finalVelocity.X = 0f; + if (Math.Abs(baseVelocity.Y) > Math.Abs(newVelocity.Y)) + finalVelocity.Y = 0f; + + position += finalVelocity; + } + + /// + /// Updates this rope, making it move around. + /// + public void Update() + { + for (var i = 0; i < Segments.Length; i++) + { + var movementStep = (Segments[i].Position - Segments[i].OldPosition) * (1f - MovementSpeedDampingCoefficient); + if (movementStep.Length() < 0.02f) + movementStep = Vector2.Zero; + + Segments[i].OldPosition = Segments[i].Position; + + if (!Segments[i].FixedInPlace) + Move(ref Segments[i].Position, movementStep + Gravity); + } + + for (var i = 0; i < ConstraintSteps; i++) + Constrain(); + + RecalculateSegmentPositions(); + + if (Settings.RespondToEntityMovement) + HandleEntityMovementResponse(); + if (Settings.RespondToWind) + HandleWindResponse(); + } + + /// + /// Makes this rope respond to the movement of entities. + /// + private void HandleEntityMovementResponse() + { + for (var i = 0; i < Segments.Length; i++) + { + ref RopeSegment ropeSegment = ref Segments[i]; + if (ropeSegment.FixedInPlace) + continue; + + foreach (var player in Main.ActivePlayers) + { + float playerProximityInterpolant = Utils.GetLerpValue(37f, 10f, player.Distance(ropeSegment.Position), true); + ropeSegment.Position += player.velocity * playerProximityInterpolant / Settings.Mass * 0.08f; + } + } + } + + /// + /// Makes this entity respond to wind. + /// + private void HandleWindResponse() + { + WindTime += Main.windSpeedCurrent / 60f; + if (MathF.Abs(WindTime) >= 4000f) + WindTime = 0f; + + var windSpeed = Math.Clamp(Main.WindForVisuals * 2f, -1.3f, 1.3f); + var windWave = MathF.Cos(WindTime * 3.42f + Segments[0].Position.Length() * 0.06f); + var wind = Vector2.UnitX * (windWave + Main.windSpeedCurrent) * -0.2f; + + Segments[^1].Position += wind * Utils.GetLerpValue(0.3f, 0.75f, windSpeed, true) / Settings.Mass; + } + + /// + /// Constrains segments on this rope, conserving their overall length. + /// + public void Constrain() + { + for (var i = 0; i < Segments.Length - 1; i++) + { + // Determine how much each segment has to move in order to return to its desired resting distance. + var segmentLength = Segments[i].Position.Distance(Segments[i + 1].Position); + var distanceFromIdealLength = segmentLength - DistancePerSegment; + Vector2 correctiveForce = (Segments[i].Position - Segments[i + 1].Position).SafeNormalize(Vector2.Zero) * distanceFromIdealLength; + + var pinned = Segments[i].FixedInPlace; + var nextPinned = Segments[i + 1].FixedInPlace; + correctiveForce *= pinned || nextPinned ? 1f : 0.5f; + + if (!pinned) + Move(ref Segments[i].Position, -correctiveForce); + if (!nextPinned) + Move(ref Segments[i + 1].Position, correctiveForce); + } + } +} diff --git a/Physics/RopeHandle.cs b/Physics/RopeHandle.cs new file mode 100644 index 0000000000..4b5c03570f --- /dev/null +++ b/Physics/RopeHandle.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Terraria.ModLoader; + +namespace CalamityMod.Physics; + +// Yes, I was silently reading over the Nightshade dev channels when learning about this. +// So, thanks Tomat and 1-3 for the idea! -Lucille +/// +/// A handle that contains a reference to a given globally managed rope instance. +/// +public readonly struct RopeHandle +{ + /// + /// The value used to identify this handle's associated rope managed by the central system. + /// + private readonly int Identifier; + + /// + /// The rope associated with this handle. + /// + private readonly Rope Rope => ModContent.GetInstance().Ropes[Identifier]!; + + /// + /// The set of all positions maintained by the underlying rope. + /// + public readonly IEnumerable Positions => Rope.SegmentPositions; + + /// + /// The amount of segments this rope has. + /// + public int SegmentCount => Rope.Segments.Length; + + /// + /// The starting position of the underlying rope. + /// + public ref Vector2 Start => ref Rope.Segments[0].Position; + + /// + /// The ending position of the underlying rope. + /// + public ref Vector2 End => ref Rope.Segments[^1].Position; + + /// + /// The gravity associated with the rope. + /// + public Vector2 Gravity + { + get => Rope.Gravity; + set => Rope.Gravity = value; + } + + internal RopeHandle(int identifier) => Identifier = identifier; + + /// + /// Forces this rope to settle by performing a series of constrained updates. + /// + public void Settle() + { + for (var i = 0; i < 20; i++) + Rope.Update(); + } + + /// + /// Indicates that the rope associated with this handle should be returned back to the pool. + /// + public void Dispose() + { + var chunkIndex = Identifier / RopeManagerSystem.BitsPerChunk; + var bitIndex = Identifier % RopeManagerSystem.BitsPerChunk; + ModContent.GetInstance().ToggleActivityIndex(chunkIndex, bitIndex); + } +} diff --git a/Physics/RopeManagerSystem.cs b/Physics/RopeManagerSystem.cs new file mode 100644 index 0000000000..0192cd3c48 --- /dev/null +++ b/Physics/RopeManagerSystem.cs @@ -0,0 +1,132 @@ +using System; +using Microsoft.Xna.Framework; +using Terraria.ModLoader; +using BitOperations = System.Numerics.BitOperations; + +namespace CalamityMod.Physics; + +public sealed class RopeManagerSystem : ModSystem +{ + /// + /// The set of all maintained ropes in the world. + /// + internal readonly Rope[] Ropes = new Rope[MaxRopeCount]; + + /// + /// The internal binary mappings that determine whether ropes are active or not. + /// + internal readonly ulong[] ActivityBitChunks = new ulong[(int)Math.Ceiling((double)MaxRopeCount / BitsPerChunk)]; + + /// + /// The maximum amount of ropes to maintain across the world. + /// + public const int MaxRopeCount = 2048; + + /// + /// The amount of bits contained within each chunk in the array. + /// + public const int BitsPerChunk = sizeof(ulong) * 8; + + public override void ClearWorld() + { + for (var i = 0; i < ActivityBitChunks.Length; i++) + ActivityBitChunks[i] = 0uL; + } + + public override void PostUpdateWorld() + { + for (var i = 0; i < Ropes.Length; i++) + { + var bitIndex = i % BitsPerChunk; + var active = (ActivityBitChunks[i / BitsPerChunk] >> bitIndex & 1) == 1; + if (active) + Ropes[i].Update(); + } + } + + /// + /// Toggles a given activity index. + /// + /// The index of the to toggle. + /// The bit index in the chunk to toggle. + internal void ToggleActivityIndex(int chunkIndex, int bitIndex) => ActivityBitChunks[chunkIndex] ^= 1uL << bitIndex; + + /// + /// Attempts to find and return the first available index for a new rope. + /// + private int? SelectFirstAvailableIndex() + { + for (var i = 0; i < ActivityBitChunks.Length; i++) + { + // This comment can be deleted later if it's deemed a bit too verbose. I'm half doing it for myself to test my understanding, half doing it for any future readers who might + // not immediately understand what the bit operations do here. -Lucille + + // As a simplified example, assume the following for the activity bits, where zero means inactive and one means active: + // 0110 1111 + + // This means the first four indices are occupied, but the fifth index is free. Note that in this case bits are counted from right to left. + // In order to find the first new index, we simply need to count the amount of ones until the first zero. + // Conveniently, BitOperations.TrailingZeroCount exists for this purpose. We just need to invert the binary in order to convert the ones into zeroes. + var offset = BitOperations.TrailingZeroCount(~ActivityBitChunks[i]); + + // Check if the index offset is equal to the amount of bits in the chunk. + // If so, that means that every single bit is a one, and that there's no available index in the chunk to use. + var allBitsAreOccupied = offset == BitsPerChunk; + if (allBitsAreOccupied) + continue; + + return offset + i * BitsPerChunk; + } + + // No valid index found across the activity bit chunks. Return null. + return null; + } + + /// + /// Requests a new rope, returning a handle to it, or null if for some reason the rope couldn't be created. + /// + public RopeHandle? RequestNew(Vector2 start, Vector2 end, int segmentCount, float distancePerSegment, Vector2 gravity, RopeSettings settings, int constraintSteps = 10) + { + var index = SelectFirstAvailableIndex(); + if (index is null) + return null; + + // Mark the newly selected index as active by toggling its activity state on. + ToggleActivityIndex(index.Value / BitsPerChunk, index.Value % BitsPerChunk); + + Ropes[index.Value] = new Rope(start, end, segmentCount, distancePerSegment, gravity, settings, constraintSteps); + + return new RopeHandle(index.Value); + } + + /// + /// Calculates the overall segment length of a rope based on the horizontal span between its two end points and a desired sag distance. + /// + public static float CalculateSegmentLength(float ropeSpan, float sag, int iterations = 12) + { + // A rope at rest is defined via a catenary curve, which exists in the following mathematical form: + // y(x) = a * cosh(x / a) + + // Furthermore, the length of a rope, given the horizontal width w for a rope, is defined as follows: + // L = 2a * sinh(w / 2a) + + // In order to use the above equation, the value of a must be determined for the catenary that this rope will form. + // To do so, a numerical solution will need to be found based on the known width and sag values. + + // Suppose the two supports are at equal height at distances -w/2 and w/2. + // From this, sag (which will be denoted with h) can be defined in the following way: h = y(w/2) - y(0) + // Reducing this results in the following equation: + + // h = a(cosh(w / 2a) - 1) + // a(cosh(w / 2a) - 1) - h = 0 + // This can be used to numerically find a. + var initialGuessA = sag; + var a = (float)CalamityUtils.IterativelySearchForRoot(x => + { + return x * (Math.Cosh(ropeSpan / (x * 2D)) - 1D) - sag; + }, initialGuessA, iterations); + + // Now that a is known, it's just a matter of plugging it back into the original equation to find L. + return MathF.Sinh(ropeSpan / a * 0.5f) * a * 2f; + } +} diff --git a/Physics/RopeSegment.cs b/Physics/RopeSegment.cs new file mode 100644 index 0000000000..81cb8708de --- /dev/null +++ b/Physics/RopeSegment.cs @@ -0,0 +1,30 @@ +using Microsoft.Xna.Framework; + +namespace CalamityMod.Physics; + +/// +/// A representation of a rope segment, containing physical data such as position, velocity, etc., as well as a value which determines whether the rope is fixed in place and not subject to standard physics. +/// +public struct RopeSegment +{ + /// + /// The current position of this segment. + /// + public Vector2 Position; + + /// + /// The previous position of this segment. + /// + public Vector2 OldPosition; + + /// + /// Whether this segment is fixed in place and not subject to standard physics, such as gravity. + /// + public bool FixedInPlace; + + public RopeSegment(Vector2 position) + { + Position = position; + OldPosition = position; + } +} diff --git a/Physics/RopeSettings.cs b/Physics/RopeSettings.cs new file mode 100644 index 0000000000..133e1bc4f0 --- /dev/null +++ b/Physics/RopeSettings.cs @@ -0,0 +1,11 @@ +using Microsoft.Xna.Framework; + +namespace CalamityMod.Physics; + +public readonly record struct RopeSettings(bool StartIsFixed, bool EndIsFixed, bool RespondToEntityMovement, bool RespondToWind, Vector2? TileColliderArea, float Mass = 1f) +{ + public RopeSettings() : this(false, false, false, false, null, 1f) + { + + } +} diff --git a/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs b/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs index 45174b4fd5..8dc8930a27 100644 --- a/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs +++ b/Projectiles/DraedonsArsenal/SnakeEyesProjectile.cs @@ -186,7 +186,7 @@ namespace CalamityMod.Projectiles.DraedonsArsenal Vector2 origin = frame.Size() * 0.5f; Main.EntitySpriteDraw(texture, drawPosition, frame, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, SpriteEffects.None, 0); - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 92); return false; } diff --git a/Projectiles/Enemy/PodobooSpitUltima.cs b/Projectiles/Enemy/PodobooSpitUltima.cs index 7deb4e24c0..f955aef998 100644 --- a/Projectiles/Enemy/PodobooSpitUltima.cs +++ b/Projectiles/Enemy/PodobooSpitUltima.cs @@ -60,7 +60,7 @@ namespace CalamityMod.Projectiles.Enemy public override bool PreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); Vector2 overallOffset = Projectile.Size / 2; int numPoints = 92; PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => overallOffset, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), numPoints); diff --git a/Projectiles/Magic/ArtAttackStar.cs b/Projectiles/Magic/ArtAttackStar.cs index e1da468182..f9c7c7e233 100644 --- a/Projectiles/Magic/ArtAttackStar.cs +++ b/Projectiles/Magic/ArtAttackStar.cs @@ -226,7 +226,7 @@ namespace CalamityMod.Projectiles.Magic Vector2 origin = texture.Size() * 0.5f; Main.spriteBatch.EnterShaderRegion(); - GameShaders.Misc["CalamityMod:ArtAttack"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:ArtAttack"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); GameShaders.Misc["CalamityMod:ArtAttack"].Apply(); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(TrailWidth, TrailColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ArtAttack"]), 180); diff --git a/Projectiles/Magic/FabBolt.cs b/Projectiles/Magic/FabBolt.cs deleted file mode 100644 index 75521fc686..0000000000 --- a/Projectiles/Magic/FabBolt.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using CalamityMod.Graphics.Primitives; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Graphics.Shaders; -using Terraria.ID; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Magic -{ - public class FabBolt : ModProjectile, ILocalizedModType - { - public new string LocalizationCategory => "Projectiles.Magic"; - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public bool FadingOut - { - get => Projectile.ai[0] == 1f; - set => Projectile.ai[0] = value.ToInt(); - } - - public override void SetStaticDefaults() - { - ProjectileID.Sets.CultistIsResistantTo[Type] = true; - ProjectileID.Sets.TrailingMode[Type] = 2; - ProjectileID.Sets.TrailCacheLength[Type] = 23; - } - - public override void SetDefaults() - { - Projectile.width = 4; - Projectile.height = 4; - Projectile.friendly = true; - Projectile.extraUpdates = 2; - Projectile.penetrate = 12; - Projectile.timeLeft = 90 * Projectile.extraUpdates; - Projectile.DamageType = DamageClass.Magic; - Projectile.ignoreWater = true; - Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 0; - } - - public override void AI() - { - if (FadingOut) - { - Projectile.Opacity = MathHelper.Lerp(Projectile.Opacity, 0f, 0.27f); - if (Projectile.Opacity <= 0.05f) - Projectile.Kill(); - } - else - Projectile.velocity *= 1.004f; - Projectile.rotation = Projectile.velocity.ToRotation(); - - // Emit light. - Lighting.AddLight(Projectile.Center, Vector3.One * Projectile.Opacity * 0.45f); - } - - internal Color ColorFunction(float completionRatio) - { - float fadeToEnd = MathHelper.Lerp(0.25f, 0.5f, (float)Math.Cos(-Main.GlobalTimeWrappedHourly * 3f) * 0.5f + 0.5f); - fadeToEnd *= 1f - Utils.GetLerpValue(0.35f, 0f, completionRatio, true); - Color endColor = Color.Lerp(Color.Cyan, Color.HotPink, Projectile.identity % 2); - return Color.Lerp(Color.White, endColor, fadeToEnd) * Projectile.Opacity * 0.7f; - } - - internal float WidthFunction(float completionRatio) - { - float expansionCompletion = 1f - (float)Math.Pow(1f - Utils.GetLerpValue(0f, 0.2f, completionRatio, true), 2D); - return MathHelper.Lerp(0f, 22f, expansionCompletion) * Projectile.Opacity; - } - - public override bool PreDraw(ref Color lightColor) - { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); - PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, smoothen: false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 80); - return false; - } - - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) - { - if (!FadingOut && Projectile.penetrate < 2) - { - FadingOut = true; - Projectile.velocity *= 0.1f; - Projectile.extraUpdates = 0; - Projectile.netUpdate = true; - } - } - - public override bool OnTileCollide(Vector2 oldVelocity) - { - if (!FadingOut) - { - FadingOut = true; - Projectile.velocity *= 0.1f; - Projectile.extraUpdates = 0; - Projectile.netUpdate = true; - } - return false; - } - - public override bool? CanDamage() - { - if (FadingOut) - return false; - return null; - } - } -} diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs deleted file mode 100644 index 4bd1f35a43..0000000000 --- a/Projectiles/Magic/FabRay.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using CalamityMod.Buffs.Alcohol; -using CalamityMod.Graphics.Primitives; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.Graphics.Shaders; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Projectiles.Magic -{ - public class FabRay : ModProjectile, ILocalizedModType - { - public new string LocalizationCategory => "Projectiles.Magic"; - - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - ProjectileID.Sets.TrailCacheLength[Type] = 54; - ProjectileID.Sets.TrailingMode[Type] = 2; - } - - public override void SetDefaults() - { - Projectile.width = 4; - Projectile.height = 4; - Projectile.friendly = true; - Projectile.DamageType = DamageClass.Magic; - Projectile.ignoreWater = true; - Projectile.penetrate = 70; - Projectile.extraUpdates = 3; - Projectile.timeLeft = 60 * Projectile.extraUpdates; - Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 10; - } - - public override void AI() - { - Lighting.AddLight(Projectile.Center, 0.2f, 0.01f, 0.1f); - Projectile.ai[0] += 1f; - Projectile.Opacity = Utils.GetLerpValue(0f, 10f * Projectile.MaxUpdates, Projectile.timeLeft, true); - - int shootRate = Projectile.npcProj ? 40 : 12; - if (Projectile.owner == Main.myPlayer && Projectile.ai[0] % shootRate == 0f) - { - NPC potentialTarget = Projectile.Center.ClosestNPCAt(180f, false); - if (potentialTarget != null) - { - Vector2 shootVelocity = Projectile.SafeDirectionTo(potentialTarget.Center) * 13f; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center - shootVelocity * 2.5f, shootVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); - } - - for (int i = 0; i < Projectile.oldPos.Length / 4; i += 3) - { - potentialTarget = Projectile.oldPos[i].ClosestNPCAt(280f, false); - if (potentialTarget != null) - { - Vector2 shootVelocity = (potentialTarget.Center - Projectile.oldPos[i]).SafeNormalize(Vector2.UnitY) * 13f; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.oldPos[i] - shootVelocity * 2.5f, shootVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); - break; - } - } - } - - // Emit light. - if (!Projectile.hostile) - Lighting.AddLight(Projectile.Center, Vector3.One * Projectile.Opacity * 0.7f); - } - - internal Color ColorFunction(float completionRatio) - { - float fadeToEnd = MathHelper.Lerp(0.65f, 1f, (float)Math.Cos(-Main.GlobalTimeWrappedHourly * 3f) * 0.5f + 0.5f); - float fadeOpacity = Utils.GetLerpValue(1f, 0.64f, completionRatio, true) * Projectile.Opacity; - Color endColor = Color.Lerp(Color.Cyan, Color.HotPink, (float)Math.Sin(completionRatio * MathHelper.Pi * 1.6f - Main.GlobalTimeWrappedHourly * 4f) * 0.5f + 0.5f); - return Color.Lerp(Color.White, endColor, fadeToEnd) * fadeOpacity; - } - - internal float WidthFunction(float completionRatio) - { - float expansionCompletion = 1f - (float)Math.Pow(1f - Utils.GetLerpValue(0f, 0.3f, completionRatio, true), 2D); - return MathHelper.Lerp(0f, 32f * Projectile.Opacity, expansionCompletion); - } - - internal Vector2 OffsetFunction(float completionRatio) => Projectile.Size * 0.5f; - - public override bool PreDraw(ref Color lightColor) - { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak")); - PrimitiveRenderer.RenderTrail(Projectile.oldPos, new PrimitiveSettings(WidthFunction, ColorFunction, OffsetFunction, pixelate: false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 32); - return false; - } - - public override bool OnTileCollide(Vector2 oldVelocity) - { - Projectile.penetrate--; - if (Projectile.penetrate <= 0) - { - Projectile.Kill(); - } - else - { - if (Projectile.velocity.X != oldVelocity.X) - { - Projectile.velocity.X = -oldVelocity.X; - } - if (Projectile.velocity.Y != oldVelocity.Y) - { - Projectile.velocity.Y = -oldVelocity.Y; - } - } - return false; - } - - public override void OnHitPlayer(Player target, Player.HurtInfo info) - { - if (Projectile.hostile) - target.AddBuff(ModContent.BuffType(), 54000); - } - } -} diff --git a/Projectiles/Magic/SHPB.cs b/Projectiles/Magic/SHPB.cs index b05ce18c1f..00e47bcca7 100644 --- a/Projectiles/Magic/SHPB.cs +++ b/Projectiles/Magic/SHPB.cs @@ -378,9 +378,9 @@ namespace CalamityMod.Projectiles.Magic return Color.Lerp(endColor, Color.White, deathInterpolant); } - public void RenderPixelatedPrimitives(SpriteBatch spriteBatch) + public void RenderPixelatedPrimitives(SpriteBatch spriteBatch, PixelationPrimitiveLayer layer) { - GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(PlasmaBallWidthFunction, PlasmaBallColorFunction, (_) => Projectile.Size * 0.5f, true, true, GameShaders.Misc["CalamityMod:ImpFlameTrail"]), Projectile.oldPos.Length * 2); } } diff --git a/Projectiles/Magic/SHPL.cs b/Projectiles/Magic/SHPL.cs index c667a63398..055311f127 100644 --- a/Projectiles/Magic/SHPL.cs +++ b/Projectiles/Magic/SHPL.cs @@ -137,10 +137,10 @@ namespace CalamityMod.Projectiles.Magic return Color.Lerp(startColor, bodyColor, completion); } - public void RenderPixelatedPrimitives(SpriteBatch spriteBatch) + public void RenderPixelatedPrimitives(SpriteBatch spriteBatch, PixelationPrimitiveLayer layer) { // Render the main trail for the body for the laser. - GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(LaserWidthFunction, LaserColorFunction, (_) => Projectile.Size * 0.5f, true, true, GameShaders.Misc["CalamityMod:ImpFlameTrail"]), Projectile.oldPos.Length * 2); // Render a smaller, pure white trail in the same position to represent condensed energy in the core of the laser. diff --git a/Projectiles/Magic/SHPS.cs b/Projectiles/Magic/SHPS.cs index 9ce66fce0c..bd02542b8b 100644 --- a/Projectiles/Magic/SHPS.cs +++ b/Projectiles/Magic/SHPS.cs @@ -234,7 +234,7 @@ namespace CalamityMod.Projectiles.Magic return Color.Lerp(Color.White, tipColor, completion); } - public void RenderPixelatedPrimitives(SpriteBatch spriteBatch) + public void RenderPixelatedPrimitives(SpriteBatch spriteBatch, PixelationPrimitiveLayer layer) { // Render the main trail for the body for the soul. GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak")); @@ -242,7 +242,7 @@ namespace CalamityMod.Projectiles.Magic // Render a smaller, pure white trail in the same position to represent the glowing white core of the soul. Vector2[] soulCoreLength = Projectile.oldPos.Take(8).ToArray(); - GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:ImpFlameTrail"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(soulCoreLength, new(SoulCoreWidthFunction, SoulCoreColorFunction, (_) => Projectile.Size * 0.5f, true, true, GameShaders.Misc["CalamityMod:ImpFlameTrail"]), soulCoreLength.Length * 2); } } diff --git a/Projectiles/Magic/SylvBolt.cs b/Projectiles/Magic/SylvBolt.cs new file mode 100644 index 0000000000..de43d1b0f9 --- /dev/null +++ b/Projectiles/Magic/SylvBolt.cs @@ -0,0 +1,155 @@ +using System; +using CalamityMod.Graphics.Primitives; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Magic +{ + public class SylvBolt : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Magic"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + /// + /// The color hue interpolant for this bolt. + /// + public ref float HueInterpolant => ref Projectile.ai[0]; + + /// + /// How many natural frames have elapsed so far throughout the duration of this bolt's life. Extra updates do not affect this timer. + /// + public int Time + { + get => (int)Projectile.ai[1]; + set => Projectile.ai[1] = value; + } + + /// + /// Whether this bolt is vanishing due to the a collision. + /// + public bool Vanishing + { + get => Projectile.ai[2] == 1f; + set => Projectile.ai[2] = value.ToInt(); + } + + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 23; + } + + public override void SetDefaults() + { + Projectile.width = 4; + Projectile.height = 4; + Projectile.friendly = true; + Projectile.extraUpdates = 2; + Projectile.penetrate = 12; + Projectile.timeLeft = Projectile.extraUpdates * 90; + Projectile.DamageType = DamageClass.Magic; + Projectile.ignoreWater = true; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 0; + } + + public override void AI() + { + Projectile.velocity *= 1.004f; + if (Vanishing) + Vanish(); + + if (Projectile.FinalExtraUpdate()) + Time++; + + Projectile.scale = Utils.GetLerpValue(0f, 7f, Time, true); + + CreateMagicDust(); + + // Emit light. + Lighting.AddLight(Projectile.Center, Vector3.One * Projectile.Opacity * 0.45f); + } + + /// + /// Makes this bolt vanish. + /// + private void Vanish() + { + Projectile.Opacity = MathHelper.Lerp(Projectile.Opacity, 0f, 0.24f); + Projectile.velocity = Vector2.Zero; + Projectile.tileCollide = false; + if (Projectile.Opacity <= 0.1f) + Projectile.Kill(); + } + + /// + /// Idly emits magic dust off this bolt. + /// + private void CreateMagicDust() + { + if (Main.rand.NextBool(4)) + { + Dust magic = Dust.NewDustPerfect(Projectile.Center, 264); + magic.color = ColorFunction(0f); + magic.scale *= 0.56f; + magic.noGravity = true; + } + } + + /// + /// The function responsible for dictating the color of this bolt. + /// + internal Color ColorFunction(float completionRatio) + { + float opacity = (1f - completionRatio) * Projectile.Opacity; + return CalamityUtils.MulticolorLerp(HueInterpolant, new Color(255, 193, 255), Color.White, new Color(127, 242, 255)) * opacity; + } + + /// + /// The function responsible for dictating the width of this bolt. + /// + internal float WidthFunction(float completionRatio) + { + float tip = 1f - MathF.Pow(1f - Utils.GetLerpValue(0.05f, 0.2f, completionRatio * Projectile.Opacity, true), 2f); + return tip * Projectile.Opacity * Projectile.scale * 22f; + } + + public override bool PreDraw(ref Color lightColor) + { + MiscShaderData boltShader = GameShaders.Misc["CalamityMod:SylvestaffProjectile"]; + + boltShader.SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); + PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, smoothen: false, shader: boltShader), 80); + return false; + } + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + if (!Vanishing && Projectile.penetrate < 2) + { + Vanishing = true; + Projectile.velocity *= 0.02f; + Projectile.extraUpdates = 0; + Projectile.netUpdate = true; + } + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + if (!Vanishing) + { + Vanishing = true; + Projectile.velocity = Vector2.Zero; + Projectile.extraUpdates = 0; + Projectile.netUpdate = true; + } + return false; + } + + public override bool? CanDamage() => !Vanishing; + } +} diff --git a/Projectiles/Magic/SylvRay.cs b/Projectiles/Magic/SylvRay.cs new file mode 100644 index 0000000000..84bcfc66b4 --- /dev/null +++ b/Projectiles/Magic/SylvRay.cs @@ -0,0 +1,217 @@ +using System; +using System.IO; +using CalamityMod.Graphics.Primitives; +using CalamityMod.Items.Weapons.Magic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class SylvRay : ModProjectile, ILocalizedModType + { + /// + /// The position from which this ray's glow effect appears. + /// + public Vector2 GlowCenter + { + get; + set; + } + + /// + /// How many natural frames have elapsed so far throughout the duration of this ray's life. Extra updates do not affect this timer. + /// + public int Time + { + get => (int)Projectile.ai[0]; + set => Projectile.ai[0] = value; + } + + public new string LocalizationCategory => "Projectiles.Magic"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 54; + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; + } + + public override void SetDefaults() + { + Projectile.width = 4; + Projectile.height = 4; + Projectile.friendly = true; + Projectile.DamageType = DamageClass.Magic; + Projectile.ignoreWater = true; + Projectile.penetrate = 70; + Projectile.extraUpdates = 3; + Projectile.timeLeft = 60 * Projectile.extraUpdates; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 10; + } + + public override void SendExtraAI(BinaryWriter writer) => writer.WriteVector2(GlowCenter); + + public override void ReceiveExtraAI(BinaryReader reader) => GlowCenter = reader.ReadVector2(); + + public override void AI() + { + if (Projectile.FinalExtraUpdate()) + Time++; + + Projectile.Opacity = Utils.GetLerpValue(0f, Projectile.MaxUpdates * 10f, Projectile.timeLeft, true); + Projectile.scale = Utils.GetLerpValue(1f, 9.5f, Time, true) * Projectile.Opacity; + + if (GlowCenter == Vector2.Zero) + GlowCenter = Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.Zero) * 74f; + + HandleBoltFiring(); + CreateGlowyDust(); + + Lighting.AddLight(Projectile.Center, Vector3.One * Projectile.Opacity * 0.7f); + } + + /// + /// Handles the firing of bolts across this ray. + /// + private void HandleBoltFiring() + { + int shootRate = Sylvestaff.RayBoltShootRate; + if (Time % shootRate == 0 && Projectile.FinalExtraUpdate()) + { + int trailSearchPositions = 13; + for (int i = 0; i < trailSearchPositions; i += 3) + TryToFireBolt(Projectile.oldPos[i] + Projectile.Size * 0.5f, i / (float)trailSearchPositions); + } + } + + /// + /// Attempts to fire a given bolt projectile from a given position at the closest enemy to said position, assuming one exists. + /// + private void TryToFireBolt(Vector2 searchPosition, float hue) + { + NPC potentialTarget = searchPosition.ClosestNPCAt(Sylvestaff.RayBoltTargetingRange, false); + if (potentialTarget is null) + return; + + SoundEngine.PlaySound(Sylvestaff.BounceSound with { MaxInstances = 12, Volume = 0.4f, Pitch = 0.4f }, Projectile.Center); + + float shootSpeed = Projectile.velocity.Length(); + Vector2 shootVelocity = (potentialTarget.Center - searchPosition).SafeNormalize(Vector2.UnitY) * shootSpeed; + if (Projectile.owner == Main.myPlayer) + Projectile.NewProjectile(Projectile.GetSource_FromThis(), searchPosition, shootVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, hue); + + float burstSpeed = Main.rand.NextFloat(1f, 3f); + for (int i = 0; i < 4; i++) + { + Dust magicBurst = Dust.NewDustPerfect(searchPosition, 264); + magicBurst.velocity = Projectile.velocity.RotatedBy(MathHelper.TwoPi * i / 4f + MathHelper.PiOver4).SafeNormalize(Vector2.Zero) * burstSpeed; + magicBurst.color = Color.White; + magicBurst.noLight = true; + magicBurst.noGravity = true; + } + } + + /// + /// Emits dust particles at the glow center of this ray, to help sell the notion that it's appearing from a concentrated ball of queer magic energy. + /// + private void CreateGlowyDust() + { + if (Time <= 9 && Main.rand.NextBool()) + { + Color colorAccent = Main.rand.NextBool() ? Color.HotPink : Color.Aqua; + + Dust transMagic = Dust.NewDustPerfect(GlowCenter, 264); + transMagic.velocity = Main.rand.NextVector2Circular(4.6f, 4.6f) + Projectile.velocity * 0.25f; + transMagic.color = Color.Lerp(Color.White, colorAccent, Main.rand.NextFloat(0.23f)); + transMagic.scale *= 1.1f; + transMagic.fadeIn = 0.75f; + transMagic.noGravity = true; + } + } + + /// + /// The function responsible for dictating the color of this ray. + /// + internal Color ColorFunction(float completionRatio) + { + float opacity = MathF.Pow(Utils.GetLerpValue(1f, 0.64f, completionRatio, true), 3f) * Projectile.Opacity; + float colorInterpolant = MathF.Cos(MathHelper.Pi * completionRatio - Main.GlobalTimeWrappedHourly * 7.2f) * 0.5f + 0.5f; + + Color pink = new Color(255, 147, 255); + Color blue = new Color(109, 224, 255); + Color baseColor = CalamityUtils.MulticolorLerp(colorInterpolant, pink, Color.White, blue, Color.White); + + return baseColor * opacity; + } + + /// + /// The function responsible for dictating the width of this ray. + /// + internal float WidthFunction(float completionRatio) + { + float expansionCompletion = 1f - MathF.Pow(1f - Utils.GetLerpValue(0f, 0.3f, completionRatio, true), 2f); + float undulation = MathF.Cos(MathHelper.Pi * completionRatio * 5f - Main.GlobalTimeWrappedHourly * 23f) * 2.4f; + float maxWidth = undulation + 32f; + + return MathHelper.Lerp(0f, Projectile.scale * maxWidth, expansionCompletion); + } + + /// + /// The function responsible for dictating the render offset of this ray. + /// + internal Vector2 OffsetFunction(float completionRatio) => Projectile.Size * 0.5f; + + /// + /// Renders the front-glow for this ray, to help make it look like it has a defined origin of concentrated magic. + /// + private void RenderFrontGlow() + { + float glowAnimationProgress = Utils.GetLerpValue(0f, 9.5f, Time, true); + float glowBump = CalamityUtils.Convert01To010(glowAnimationProgress); + float glowRotation = Projectile.velocity.ToRotation(); + Vector2 glowScale = new Vector2(1f + glowBump * 0.8f, 1f) * glowBump; + + Vector2 startingPosition = GlowCenter - Main.screenPosition; + Texture2D lightTexture = ModContent.Request("CalamityMod/ExtraTextures/BloomCirclePinpoint").Value; + Main.spriteBatch.Draw(lightTexture, startingPosition, null, ColorFunction(0f) with { A = 0 }, glowRotation, lightTexture.Size() * 0.5f, glowScale, 0, 0f); + Main.spriteBatch.Draw(lightTexture, startingPosition, null, ColorFunction(0f) with { A = 0 }, glowRotation, lightTexture.Size() * 0.5f, glowScale * 0.4f, 0, 0f); + } + + public override bool PreDraw(ref Color lightColor) + { + RenderFrontGlow(); + + MiscShaderData rayShader = GameShaders.Misc["CalamityMod:SylvestaffProjectile"]; + rayShader.SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/ScarletDevilStreak")); + + PrimitiveRenderer.RenderTrail(Projectile.oldPos, new PrimitiveSettings(WidthFunction, ColorFunction, OffsetFunction, pixelate: false, shader: rayShader), 32); + return false; + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Projectile.penetrate--; + if (Projectile.penetrate <= 0) + { + Projectile.Kill(); + } + else + { + SoundEngine.PlaySound(Sylvestaff.BounceSound, Projectile.Center); + + if (Projectile.velocity.X != oldVelocity.X) + Projectile.velocity.X = -oldVelocity.X; + if (Projectile.velocity.Y != oldVelocity.Y) + Projectile.velocity.Y = -oldVelocity.Y; + } + return false; + } + } +} diff --git a/Projectiles/Magic/SylvestaffHoldout.cs b/Projectiles/Magic/SylvestaffHoldout.cs new file mode 100644 index 0000000000..3109ae5bff --- /dev/null +++ b/Projectiles/Magic/SylvestaffHoldout.cs @@ -0,0 +1,262 @@ +using System; +using CalamityMod.Graphics.Primitives; +using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Physics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.Graphics.Shaders; +using Terraria.Localization; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class SylvestaffHoldout : ModProjectile, IPixelatedPrimitiveRenderer + { + public PixelationPrimitiveLayer LayerToRenderTo => PixelationPrimitiveLayer.BeforeProjectiles | PixelationPrimitiveLayer.AfterPlayers; + + public override LocalizedText DisplayName => CalamityUtils.GetItemName(); + + /// + /// The left ribbon on this holdout. + /// + public RopeHandle? LeftRibbon; + + /// + /// The right ribbon on this holdout. + /// + public RopeHandle? RightRibbon; + + /// + /// The player owner of this holdout staff. + /// + public Player Owner => Main.player[Projectile.owner]; + + /// + /// A general purpose, ever-increment timer used by this holdout staff. + /// + public ref float Time => ref Projectile.ai[0]; + + /// + /// The point of attachment for ribbons on this staff. + /// + public Vector2 RibbonAttachPoint => Projectile.Center + Projectile.velocity * Projectile.scale * Projectile.width * 0.34f; + + /// + /// The length of ribbons attached to this staff. + /// + private static float RibbonLength => 70f; + + public override string Texture => ModContent.GetInstance().Texture; + + public override void SetDefaults() + { + Projectile.width = Projectile.height = 94; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.DamageType = DamageClass.Magic; + Projectile.tileCollide = false; + Projectile.ignoreWater = true; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 10; + Projectile.timeLeft = 72000; + } + + public override void AI() + { + if (!Owner.channel) + Projectile.Kill(); + + if (LeftRibbon is null && RightRibbon is null) + InitializeRibbons(); + + AimTowardsMouse(); + HandleHoldoutLogic(); + OrientOwnerArms(); + FireAwesomeMagicRays(); + UpdateRibbon(LeftRibbon, Projectile.velocity.RotatedBy(-MathHelper.PiOver2)); + UpdateRibbon(RightRibbon, Projectile.velocity.RotatedBy(MathHelper.PiOver2)); + + Time++; + } + + /// + /// Initializes the ribbons attached to this staff. + /// + private void InitializeRibbons() + { + int ribbonSegmentCount = 12; + float distancePerSegment = RibbonLength / ribbonSegmentCount; + RopeSettings ribbonSettings = new RopeSettings() + { + StartIsFixed = true, + Mass = 0.72f, + RespondToEntityMovement = true, + RespondToWind = true + }; + LeftRibbon = ModContent.GetInstance().RequestNew(RibbonAttachPoint, Projectile.Center, ribbonSegmentCount, distancePerSegment, Vector2.Zero, ribbonSettings, 25); + RightRibbon = ModContent.GetInstance().RequestNew(RibbonAttachPoint, Projectile.Center, ribbonSegmentCount, distancePerSegment, Vector2.Zero, ribbonSettings, 25); + } + + /// + /// Handles all logic pertaining to making this staff act as a holdout projectile. + /// + private void HandleHoldoutLogic() + { + Vector2 center = Owner.MountedCenter + Vector2.UnitY * 7f + Projectile.velocity * Projectile.width * 0.31f; + + Projectile.rotation = Projectile.velocity.ToRotation(); + Projectile.Center = Owner.RotatedRelativePoint(center) - Vector2.UnitY * Owner.gfxOffY; + Projectile.spriteDirection = (Math.Cos(Projectile.rotation) > 0).ToDirectionInt(); + + // The staff is a holdout projectile; change the player's variables to reflect this. + Owner.ChangeDir(Projectile.spriteDirection); + Owner.SetDummyItemTime(2); + Owner.heldProj = Projectile.whoAmI; + + Projectile.rotation += MathHelper.PiOver4; + if (Projectile.spriteDirection == -1) + Projectile.rotation += MathHelper.PiOver2; + } + + /// + /// Orients the owner player's arm rotation to help make it look like they're actually holding the staff. + /// + private void OrientOwnerArms() + { + float baseRotation = Projectile.velocity.ToRotation() - MathHelper.PiOver2; + float directionVerticality = MathF.Abs(Projectile.velocity.X); + Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, baseRotation + Owner.direction * directionVerticality * MathHelper.PiOver4); + Owner.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, baseRotation + Owner.direction * directionVerticality * 0.33f); + } + + /// + /// Makes this staff aim towards the owner's mouse. + /// + private void AimTowardsMouse() + { + if (Main.myPlayer != Projectile.owner) + return; + + Vector2 idealDirection = Projectile.SafeDirectionTo(Main.MouseWorld); + Vector2 newDirection = Vector2.Lerp(Projectile.velocity, idealDirection, Sylvestaff.TurnSpeedInterpolant).SafeNormalize(Vector2.UnitX * Owner.direction); + if (Projectile.velocity != newDirection) + { + Projectile.velocity = newDirection; + Projectile.netUpdate = true; + Projectile.netSpam = 0; + } + } + + /// + /// Updates a given ribbon. + /// + private void UpdateRibbon(RopeHandle? ribbon, Vector2 gravityDirection) + { + // Ensure that the handle is properly initialized before proceeding any further. + if (ribbon is not RopeHandle rope) + return; + + rope.Start = RibbonAttachPoint; + rope.Gravity = gravityDirection * 0.15f - Projectile.velocity * 0.4f; + } + + /// + /// Handles the firing of magic ray projectiles for this staff. + /// + private void FireAwesomeMagicRays() + { + Item heldItem = Owner.ActiveItem(); + if (heldItem is null) + return; + + if (Time % heldItem.useAnimation == heldItem.useAnimation - 1 && Owner.CheckMana(heldItem.mana, true)) + { + SoundEngine.PlaySound(Sylvestaff.FireSound, Projectile.Center); + if (Main.myPlayer == Projectile.owner) + { + int damage = Owner.GetWeaponDamage(heldItem); + Vector2 shootVelocity = Projectile.velocity * heldItem.shootSpeed; + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, shootVelocity, ModContent.ProjectileType(), damage, heldItem.knockBack, Projectile.owner); + + // Apply a minor amount of recoil. + Projectile.velocity -= Projectile.velocity.RotatedBy(Projectile.spriteDirection * MathHelper.PiOver2) * Sylvestaff.StaffRecoilForce; + } + } + } + + public void RenderPixelatedPrimitives(SpriteBatch spriteBatch, PixelationPrimitiveLayer layer) + { + bool backLayer = layer == PixelationPrimitiveLayer.BeforeProjectiles; + RenderRibbon(LeftRibbon, -1, backLayer); + RenderRibbon(RightRibbon, 1, backLayer); + } + + /// + /// The function responsible for dictating the width of this staff's ribbons. + /// + private float RibbonWidthFunction(float completionRatio) => Projectile.scale * Utils.GetLerpValue(0f, 0.2f, completionRatio, true) * 3.6f; + + /// + /// The function responsible for dictating the color of this staff's ribbons. + /// + private Color RibbonColorFunction(float completionRatio) + { + Color light = Lighting.GetColor(RibbonAttachPoint.ToTileCoordinates()); + return Projectile.GetAlpha(light); + } + + /// + /// Renders one of this staff's ribbons. + /// + private void RenderRibbon(RopeHandle? ribbon, int direction, bool backLayer) + { + // Ensure that the handle is properly initialized before proceeding any further. + if (ribbon is not RopeHandle rope) + return; + + Vector2 forwardDirection = Projectile.velocity; + Vector2 sideDirection = forwardDirection.RotatedBy(MathHelper.PiOver2 * direction); + Vector2 attachmentPoint = RibbonAttachPoint; + Vector2[] ribbonPositions = [.. rope.Positions]; + int positionCount = ribbonPositions.Length; + for (int i = 0; i < ribbonPositions.Length; i++) + { + float completionRatio = i / (float)positionCount; + float wave = MathF.Cos(MathHelper.Pi * completionRatio * 1.5f - MathHelper.TwoPi * Time / 97f) * completionRatio; + + Vector2 backwardsOffset = forwardDirection * i * -RibbonLength / positionCount; + Vector2 sideWavyOffset = sideDirection * wave * RibbonLength * 0.5f; + Vector2 rigidPosition = attachmentPoint + backwardsOffset + sideWavyOffset; + + ribbonPositions[i] = Vector2.Lerp(ribbonPositions[i], rigidPosition, 0.76f); + } + + Vector2 intersectionPosition = Vector2.Transform((Projectile.Center - Main.screenPosition) * 0.5f, Main.GameViewMatrix.TransformationMatrix); + MiscShaderData ribbonShader = GameShaders.Misc["CalamityMod:SylvestaffRibbon"]; + ribbonShader.UseShaderSpecificData(new Vector4(intersectionPosition.X, intersectionPosition.Y, sideDirection.X, sideDirection.Y)); + ribbonShader.UseSaturation(backLayer ? -1f : 1f); + + PrimitiveSettings primitiveSettings = new PrimitiveSettings(RibbonWidthFunction, RibbonColorFunction, pixelate: true, shader: ribbonShader); + PrimitiveRenderer.RenderTrail(ribbonPositions, primitiveSettings, 33); + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = ModContent.Request(Texture).Value; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + SpriteEffects direction = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + Main.spriteBatch.Draw(texture, drawPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, texture.Size() * 0.5f, Projectile.scale, direction, 0f); + return false; + } + + public override void OnKill(int timeLeft) + { + LeftRibbon?.Dispose(); + RightRibbon?.Dispose(); + } + + public override bool? CanDamage() => false; + } +} diff --git a/Projectiles/Melee/GayBeam.cs b/Projectiles/Melee/GayBeam.cs index 5d016effdc..85cb5f4a85 100644 --- a/Projectiles/Melee/GayBeam.cs +++ b/Projectiles/Melee/GayBeam.cs @@ -325,7 +325,7 @@ namespace CalamityMod.Projectiles.Melee Main.spriteBatch.EnterShaderRegion(); - GameShaders.Misc["CalamityMod:ArtAttack"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:ArtAttack"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); GameShaders.Misc["CalamityMod:ArtAttack"].Apply(); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(TrailWidth, TrailColor, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:ArtAttack"]), TrailLength); diff --git a/Projectiles/Melee/UrchinSpikeFugu.cs b/Projectiles/Melee/UrchinSpikeFugu.cs index 3938a7e9cc..249d92ad9a 100644 --- a/Projectiles/Melee/UrchinSpikeFugu.cs +++ b/Projectiles/Melee/UrchinSpikeFugu.cs @@ -63,7 +63,7 @@ namespace CalamityMod.Projectiles.Melee internal Color ColorFunction(float completionRatio) => new Color(91, 62, 153) * Projectile.Opacity; public override bool PreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 8); return true; } diff --git a/Projectiles/Melee/ViolenceThrownProjectile.cs b/Projectiles/Melee/ViolenceThrownProjectile.cs index db26da3a46..667cffc62e 100644 --- a/Projectiles/Melee/ViolenceThrownProjectile.cs +++ b/Projectiles/Melee/ViolenceThrownProjectile.cs @@ -199,7 +199,7 @@ namespace CalamityMod.Projectiles.Melee } public bool JavelinPreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); // Not cloning the points causes the below operations to be applied to the original oldPos value by reference // and thus causes it to be consistently added over and over, which is not intended behavior. @@ -419,7 +419,7 @@ namespace CalamityMod.Projectiles.Melee } public bool YoyoPreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); Texture2D spearProjectile = Terraria.GameContent.TextureAssets.Projectile[Type].Value; diff --git a/Projectiles/Ranged/ElysianArrowRain.cs b/Projectiles/Ranged/ElysianArrowRain.cs index 8e9eefa522..908bf2bfd7 100644 --- a/Projectiles/Ranged/ElysianArrowRain.cs +++ b/Projectiles/Ranged/ElysianArrowRain.cs @@ -110,7 +110,7 @@ namespace CalamityMod.Projectiles.Ranged public override bool PreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); Vector2 overallOffset = Projectile.Size * 0.5f; overallOffset += Projectile.velocity * 1.4f; int numPoints = 46; diff --git a/Projectiles/Ranged/ScorpioLargeRocket.cs b/Projectiles/Ranged/ScorpioLargeRocket.cs index 0e6e837318..33220e38ce 100644 --- a/Projectiles/Ranged/ScorpioLargeRocket.cs +++ b/Projectiles/Ranged/ScorpioLargeRocket.cs @@ -219,7 +219,7 @@ namespace CalamityMod.Projectiles.Ranged Vector2 rotationPoint = frame.Size() * 0.5f; // 29FEB2024: Ozzatron: hopefully ported this correctly to the new prim system by Toasty - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(TrailWidthFunction, TrailColorFunction, (_) => Projectile.Size * 0.5f, smoothen: false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 25); Main.EntitySpriteDraw(texture, drawPosition, frame, drawColor, drawRotation, rotationPoint, Projectile.scale, SpriteEffects.None); diff --git a/Projectiles/Ranged/ScorpioRocket.cs b/Projectiles/Ranged/ScorpioRocket.cs index 94e9965fc4..066adb7379 100644 --- a/Projectiles/Ranged/ScorpioRocket.cs +++ b/Projectiles/Ranged/ScorpioRocket.cs @@ -171,7 +171,7 @@ namespace CalamityMod.Projectiles.Ranged if (Time >= TimeToLaunch) { // 29FEB2024: Ozzatron: hopefully ported this correctly to the new prim system by Toasty - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(TrailWidthFunction, TrailColorFunction, (_) => Projectile.Size * 0.5f, smoothen: false, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 25); } diff --git a/Projectiles/Ranged/SuperradiantBolt.cs b/Projectiles/Ranged/SuperradiantBolt.cs index 2ba1733524..e3eb6e744b 100644 --- a/Projectiles/Ranged/SuperradiantBolt.cs +++ b/Projectiles/Ranged/SuperradiantBolt.cs @@ -75,7 +75,7 @@ namespace CalamityMod.Projectiles.Ranged public override bool PreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 20); Texture2D glow = TextureAssets.Projectile[Type].Value; Main.EntitySpriteDraw(glow, Projectile.Center - Main.screenPosition, null, Color.White, Projectile.rotation, glow.Size() * 0.5f, Projectile.scale, SpriteEffects.None); diff --git a/Projectiles/Ranged/TelluricGlareArrow.cs b/Projectiles/Ranged/TelluricGlareArrow.cs index 5e6bb758a4..d970edad12 100644 --- a/Projectiles/Ranged/TelluricGlareArrow.cs +++ b/Projectiles/Ranged/TelluricGlareArrow.cs @@ -167,7 +167,7 @@ namespace CalamityMod.Projectiles.Ranged public override bool PreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); Vector2 overallOffset = Projectile.Size * 0.5f; overallOffset += Projectile.velocity * 1.4f; int numPoints = 92; diff --git a/Projectiles/Summon/LiliesOfEternityBullet.cs b/Projectiles/Summon/LiliesOfEternityBullet.cs index 5cbe15d4d7..d87e226da0 100644 --- a/Projectiles/Summon/LiliesOfEternityBullet.cs +++ b/Projectiles/Summon/LiliesOfEternityBullet.cs @@ -60,9 +60,9 @@ namespace CalamityMod.Projectiles.Summon private Color PrimitiveColorFunction(float completionRatio) => Color.Lerp(Color.DarkGoldenrod, Color.LightGoldenrodYellow, completionRatio); - public void RenderPixelatedPrimitives(SpriteBatch spriteBatch) + public void RenderPixelatedPrimitives(SpriteBatch spriteBatch, PixelationPrimitiveLayer layer) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, pixelate: true, shader: GameShaders.Misc["CalamityMod:TrailStreak"])); } } diff --git a/Projectiles/Summon/LiliesOfFinalityBullet.cs b/Projectiles/Summon/LiliesOfFinalityBullet.cs index 7dd9798613..19a527e5d2 100644 --- a/Projectiles/Summon/LiliesOfFinalityBullet.cs +++ b/Projectiles/Summon/LiliesOfFinalityBullet.cs @@ -64,9 +64,9 @@ namespace CalamityMod.Projectiles.Summon private Color PrimitiveColorFunction(float completionRatio) => Color.Lerp(Color.DarkGoldenrod, Color.LightGoldenrodYellow, completionRatio); - public void RenderPixelatedPrimitives(SpriteBatch spriteBatch) + public void RenderPixelatedPrimitives(SpriteBatch spriteBatch, PixelationPrimitiveLayer layer) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(PrimitiveWidthFunction, PrimitiveColorFunction, (_) => Projectile.Size * 0.5f, pixelate: true, shader: GameShaders.Misc["CalamityMod:TrailStreak"])); } } diff --git a/Projectiles/Typeless/BlazingStarHeal.cs b/Projectiles/Typeless/BlazingStarHeal.cs index 813cd82252..8b0043879c 100644 --- a/Projectiles/Typeless/BlazingStarHeal.cs +++ b/Projectiles/Typeless/BlazingStarHeal.cs @@ -83,7 +83,7 @@ namespace CalamityMod.Projectiles.Typeless public override bool PreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 25); Main.spriteBatch.EnterShaderRegion(BlendState.Additive); diff --git a/Projectiles/Typeless/BlazingStarThatDoesNotHeal.cs b/Projectiles/Typeless/BlazingStarThatDoesNotHeal.cs index d782b2b97d..c4e2de0393 100644 --- a/Projectiles/Typeless/BlazingStarThatDoesNotHeal.cs +++ b/Projectiles/Typeless/BlazingStarThatDoesNotHeal.cs @@ -60,7 +60,7 @@ namespace CalamityMod.Projectiles.Typeless public override bool PreDraw(ref Color lightColor) { - GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/FabstaffStreak")); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/Trails/SylvestaffStreak")); PrimitiveRenderer.RenderTrail(Projectile.oldPos, new(WidthFunction, ColorFunction, (_) => Projectile.Size * 0.5f, shader: GameShaders.Misc["CalamityMod:TrailStreak"]), 8); Main.spriteBatch.EnterShaderRegion(BlendState.Additive); diff --git a/Sounds/Item/SylvestaffFire1.ogg b/Sounds/Item/SylvestaffFire1.ogg new file mode 100644 index 0000000000..56864c877c Binary files /dev/null and b/Sounds/Item/SylvestaffFire1.ogg differ diff --git a/Sounds/Item/SylvestaffFire2.ogg b/Sounds/Item/SylvestaffFire2.ogg new file mode 100644 index 0000000000..79ca7e1fa9 Binary files /dev/null and b/Sounds/Item/SylvestaffFire2.ogg differ diff --git a/Sounds/Item/SylvestaffFire3.ogg b/Sounds/Item/SylvestaffFire3.ogg new file mode 100644 index 0000000000..6b79439991 Binary files /dev/null and b/Sounds/Item/SylvestaffFire3.ogg differ diff --git a/Sounds/Item/SylvestaffProjectileBounce1.ogg b/Sounds/Item/SylvestaffProjectileBounce1.ogg new file mode 100644 index 0000000000..dbe4a38b8e Binary files /dev/null and b/Sounds/Item/SylvestaffProjectileBounce1.ogg differ diff --git a/Sounds/Item/SylvestaffProjectileBounce2.ogg b/Sounds/Item/SylvestaffProjectileBounce2.ogg new file mode 100644 index 0000000000..81d1d354e4 Binary files /dev/null and b/Sounds/Item/SylvestaffProjectileBounce2.ogg differ diff --git a/Sounds/Item/SylvestaffProjectileBounce3.ogg b/Sounds/Item/SylvestaffProjectileBounce3.ogg new file mode 100644 index 0000000000..4cbae2723f Binary files /dev/null and b/Sounds/Item/SylvestaffProjectileBounce3.ogg differ diff --git a/Utilities/MathematicalUtils.cs b/Utilities/MathematicalUtils.cs index 4c2a9d9c09..8108deec16 100644 --- a/Utilities/MathematicalUtils.cs +++ b/Utilities/MathematicalUtils.cs @@ -225,6 +225,37 @@ namespace CalamityMod /// The input value. public static int DirectionalSign(this float x) => (x > 0f).ToDirectionInt(); + + /// + /// Approximates the derivative of a function at a given point based on a central-difference formula. + /// + /// The function to take the derivative of. + /// The value to evaluate the derivative at. + public static double ApproximateDerivative(this Func fx, double x) + { + double left = fx(x + 1e-7); + double right = fx(x - 1e-7); + return (left - right) * 5e6; + } + + /// + /// Searches for an approximate for a root of a given function. + /// + /// The function to find the root for. + /// The initial guess for what the root could be. + /// The amount of iterations to perform. The higher this is, the more generally accurate the result will be. + public static double IterativelySearchForRoot(Func fx, double initialGuess, int iterations) + { + double result = initialGuess; + for (int i = 0; i < iterations; i++) + { + double derivative = (float)fx.ApproximateDerivative(result); + result -= fx(result) / derivative; + } + + return result; + } + public static List GetIntersectingPointsInLine(Point start, Point end) { List intersectingCells = [];