diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index f7419c2e90..4af5ea84f2 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -186,6 +186,7 @@ namespace CalamityMod.Effects #region Amber's Shaders internal static Effect PrimitiveClearShader; internal static Effect HolyInfernoShader; + internal static Effect DeerclopsShadowShader; #endregion // Shorthand to register a loaded shader in Terraria's graphics engine @@ -392,9 +393,12 @@ namespace CalamityMod.Effects PrimitiveClearShader = LoadShader("PrimitiveClearShader"); RegisterScreenShader(PrimitiveClearShader, "AutoloadPass", "PrimitiveClearShader"); - HolyInfernoShader = LoadShader("HolyInfernoShader"); + HolyInfernoShader = LoadShader("ScreenShaders/HolyInfernoShader"); RegisterMiscShader(HolyInfernoShader, "InfernoPass", "HolyInfernoShader"); + DeerclopsShadowShader = LoadShader("ScreenShaders/DeerclopsShadowShader"); + RegisterMiscShader(DeerclopsShadowShader, "ShadowPass", "DeerclopsShadowShader"); + #endregion } } diff --git a/Effects/ScreenShaders/DeerclopsShadowShader.fx b/Effects/ScreenShaders/DeerclopsShadowShader.fx new file mode 100644 index 0000000000..47273956fe --- /dev/null +++ b/Effects/ScreenShaders/DeerclopsShadowShader.fx @@ -0,0 +1,52 @@ +float minRadius; +float maxRadius; +float maxOpacity; + +float2 screenPosition; +float2 screenSize; +float2 anchorPoint; + +float InverseLerp(float a, float b, float t) +{ + return saturate((t - a) / (b - a)); +} + +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 uv : TEXCOORD0) : COLOR0 +{ + float2 worldUV = screenPosition + screenSize * uv; + float2 deerclopsUV = anchorPoint / screenSize; + float worldDistance = distance(worldUV, anchorPoint); + + // Get the distance to the pixel from Deerclops + float distToDeerclops = distance(anchorPoint, worldUV); + // And get the correct opacity based on it. + float opacity = InverseLerp(0, maxRadius, distToDeerclops); + + // Define the border and mix the shadow and light for a smoother transition + bool border = worldDistance < minRadius && opacity > 0; + float colorMult = 1; + + if (worldDistance > minRadius && worldDistance < maxRadius) + opacity = lerp(opacity, maxOpacity, InverseLerp(minRadius, maxRadius, distToDeerclops)); + + opacity = clamp(opacity, 0, maxOpacity); + + if (border) + { + colorMult = InverseLerp(minRadius * 0.94, minRadius, worldDistance); + } + + // If the color multi has not been changed (not border pixel) and opacity is 0 OR it's within + if (colorMult == 1 && (opacity == 0 || worldDistance < minRadius)) + return sampleColor; + + return float4(0, 0, 0, 1) * colorMult * opacity; +} + +technique Technique1 +{ + pass ShadowPass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/ScreenShaders/DeerclopsShadowShader.xnb b/Effects/ScreenShaders/DeerclopsShadowShader.xnb new file mode 100644 index 0000000000..8703cff449 Binary files /dev/null and b/Effects/ScreenShaders/DeerclopsShadowShader.xnb differ diff --git a/Effects/HolyInfernoShader.fx b/Effects/ScreenShaders/HolyInfernoShader.fx similarity index 100% rename from Effects/HolyInfernoShader.fx rename to Effects/ScreenShaders/HolyInfernoShader.fx diff --git a/Effects/HolyInfernoShader.xnb b/Effects/ScreenShaders/HolyInfernoShader.xnb similarity index 100% rename from Effects/HolyInfernoShader.xnb rename to Effects/ScreenShaders/HolyInfernoShader.xnb diff --git a/Graphics/Drawers/DeerclopsShadowDrawer.cs b/Graphics/Drawers/DeerclopsShadowDrawer.cs new file mode 100644 index 0000000000..88df7065ba --- /dev/null +++ b/Graphics/Drawers/DeerclopsShadowDrawer.cs @@ -0,0 +1,71 @@ +using CalamityMod.NPCs.VanillaNPCOverrides.Bosses; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using Terraria.Graphics.Shaders; +using Terraria.ModLoader; +using Rectangle = Microsoft.Xna.Framework.Rectangle; + +namespace CalamityMod.Graphics.Drawers +{ + public class DeerclopsShadowDrawer : BaseDrawer + { + #region Fields/Properties + + public override DrawerLayer Layer => DrawerLayer.AfterEverything; + + public NPC deerclops => Main.npc[NPC.deerclopsBoss]; + + //Should only draw if not in the main menu, deerclops is active or the border is fading post-death, + //it's rev+ and the boolean for drawing the border is true. + public override bool ShouldDraw => !Main.gameMenu && DeerclopsAI.borderScalar > 0f && DeerclopsAI.shouldDrawEnrageBorder; + #endregion + + #region Methods + public override void DrawToTarget(SpriteBatch spriteBatch) + { + bool shouldDraw; + bool deerclopsInactive = false; + if (NPC.deerclopsBoss >= 0 && NPC.deerclopsBoss.WithinBounds(Main.npc.Length)) + shouldDraw = deerclops.HasValidTarget; + else + { + shouldDraw = DeerclopsAI.borderScalar > 0f; + deerclopsInactive = true; + } + if (shouldDraw) + { + var minRadius = DeerclopsAI.innerBorder; + var maxRadius = DeerclopsAI.outerBorder; + + //Begin drawing the shadow + var blackTile = TextureAssets.MagicPixel; + + var shader = GameShaders.Misc["CalamityMod:DeerclopsShadowShader"].Shader; + shader.Parameters["minRadius"].SetValue(minRadius); + shader.Parameters["maxRadius"].SetValue(maxRadius); + shader.Parameters["anchorPoint"].SetValue(DeerclopsAI.lastDeerclopsPosition); + shader.Parameters["screenPosition"].SetValue(Main.screenPosition); + shader.Parameters["screenSize"].SetValue(Main.ScreenSize.ToVector2()); + shader.Parameters["maxOpacity"].SetValue(DeerclopsAI.borderScalar); + + + spriteBatch.EnterShaderRegion(BlendState.NonPremultiplied, shader); + Rectangle rekt = new(Main.screenWidth / 2, Main.screenHeight / 2, Main.screenWidth, Main.screenHeight); + spriteBatch.Draw(blackTile.Value, rekt, null, default, 0f, blackTile.Value.Size() * 0.5f, 0, 0f); + //Shadow drawing complete + spriteBatch.ExitShaderRegion(); + } + if (deerclopsInactive) + { + //Push the border away and fade out when deerclops is deadge + DeerclopsAI.borderScalar = MathHelper.Clamp(DeerclopsAI.borderScalar - 0.015f, 0f, 1f); + DeerclopsAI.innerBorder += 30f; + DeerclopsAI.outerBorder += 30f; + } + } + #endregion + } +} diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index d848ddaca9..9a9262749c 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -5235,6 +5235,15 @@ namespace CalamityMod.NPCs #region On Spawn public override void OnSpawn(NPC npc, IEntitySource source) { + if (npc.type == NPCID.Deerclops) + { + DeerclopsAI.hasTargetBeenInRange = false; + DeerclopsAI.borderDelay = 7f * 60f; + DeerclopsAI.borderScalar = 0f; + DeerclopsAI.innerBorder = DeerclopsAI.maxDRIncreaseDistance * 5f; + DeerclopsAI.outerBorder = DeerclopsAI.maxDRIncreaseDistance * 5f; + } + if (npc.type != NPCID.VoodooDemon) return; diff --git a/NPCs/VanillaNPCOverrides/Bosses/DeerclopsAI.cs b/NPCs/VanillaNPCOverrides/Bosses/DeerclopsAI.cs index 68384698a0..0060be5143 100644 --- a/NPCs/VanillaNPCOverrides/Bosses/DeerclopsAI.cs +++ b/NPCs/VanillaNPCOverrides/Bosses/DeerclopsAI.cs @@ -1,8 +1,4 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.Events; -using CalamityMod.World; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using System; using Terraria; using Terraria.DataStructures; @@ -11,13 +7,23 @@ using Terraria.Graphics.CameraModifiers; using Terraria.ID; using Terraria.ModLoader; using Terraria.Audio; -using CalamityMod.Projectiles.Boss; -using CalamityMod.NPCs.TownNPCs; +using CalamityMod.World; namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses { public static class DeerclopsAI { + public static bool shouldDrawEnrageBorder = true; + public static bool hasTargetBeenInRange = true; + public const float increaseDRTriggerDistance = 450f; + public const float maxDRIncreaseDistance = 900f; + public static float borderDelay = 10f * 60f; + public static float innerBorder = 450f; + public static float outerBorder = 900f; + public static float borderScalar = 0f; + public static Vector2 lastDeerclopsPosition; + + public static bool BuffedDeerclopsAI(NPC npc, Mod mod) { CalamityGlobalNPC calamityGlobalNPC = npc.Calamity(); @@ -46,14 +52,16 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses bool goHome = false; // Damage resistance based on distance from target - float increaseDRTriggerDistance = 450f; - float maxDRIncreaseDistance = 900f; float distanceFromTarget = npc.Distance(targetData.Center); bool triggerDRIncrease = distanceFromTarget >= increaseDRTriggerDistance; float resistDamageAmount = MathHelper.Clamp((distanceFromTarget - increaseDRTriggerDistance) / (maxDRIncreaseDistance - increaseDRTriggerDistance), 0f, 1f); npc.localAI[3] = MathHelper.Lerp(0f, 30f, resistDamageAmount); float dustAndDRScalar = Utils.Remap(npc.localAI[3], 0f, 30f, 0f, 1f); calamityGlobalNPC.DR = MathHelper.Lerp(0.05f, 0.9f, dustAndDRScalar); + + if (borderDelay > 0f) + borderDelay -= 1f; + if (dustAndDRScalar > 0f) { float invincibleDustAmount = Main.rand.NextFloat() * dustAndDRScalar * 3f; @@ -63,6 +71,33 @@ namespace CalamityMod.NPCs.VanillaNPCOverrides.Bosses Dust.NewDustDirect(npc.position, npc.width, npc.height, 109, 0f, -3f, 0, default(Color), 1.4f).noGravity = true; } } + else if (!hasTargetBeenInRange) + { + //Target entered the border for the first time + hasTargetBeenInRange = true; + if (borderDelay > 120f) + borderDelay = 120f; + } + if (innerBorder != increaseDRTriggerDistance || maxDRIncreaseDistance != outerBorder) + { + //Adjust the border IF the new value is lower (helps prevent jumping if you enter the border early while it's on screen but not finished zooming in) + var LerpValue = Utils.GetLerpValue(hasTargetBeenInRange ? 120f : 180f, 0f, borderDelay, true); + var newInner = MathHelper.Lerp(maxDRIncreaseDistance * 5f, increaseDRTriggerDistance, LerpValue); + if (newInner < innerBorder) + innerBorder = newInner; + var newOuter = MathHelper.Lerp(maxDRIncreaseDistance * 5f, maxDRIncreaseDistance, LerpValue); + if (newOuter < outerBorder) + outerBorder = newOuter; + } + if ((hasTargetBeenInRange && borderScalar < 1f) || borderDelay > 0f) + { + //fade in, with full opacity only available after being inside the border for the first time + borderScalar = MathHelper.Clamp(borderScalar + 0.015f, 0f, hasTargetBeenInRange ? 1f : 0.9f); + } + shouldDrawEnrageBorder = CalamityWorld.revenge || CalamityWorld.death; + + //Set the last deerclops position (used only for post-death border shenanigans) + lastDeerclopsPosition = npc.Center; // Spawn settings if (npc.homeTileX == -1 && npc.homeTileY == -1)