diff --git a/CalamityMod.cs b/CalamityMod.cs index 9ecaf7bd76..b0a769b5aa 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -89,6 +89,7 @@ using Terraria.UI; using CalamityMod.Schematics; using CalamityMod.Tiles; using CalamityMod.TileEntities; +using CalamityMod.Projectiles.DraedonsArsenal; namespace CalamityMod { @@ -125,6 +126,7 @@ namespace CalamityMod public static Effect CustomShader; public static Effect LightShader; public static Effect TentacleShader; + public static Effect LightDistortionShader; // DR data structure public static SortedDictionary DRValues; @@ -296,6 +298,7 @@ namespace CalamityMod CustomShader = GetEffect("Effects/CustomShader"); LightShader = GetEffect("Effects/LightBurstShader"); TentacleShader = GetEffect("Effects/TentacleShader"); + LightDistortionShader = GetEffect("Effects/DistortionShader"); Filters.Scene["CalamityMod:DevourerofGodsHead"] = new Filter(new DoGScreenShaderData("FilterMiniTower").UseColor(0.4f, 0.1f, 1.0f).UseOpacity(0.5f), EffectPriority.VeryHigh); SkyManager.Instance["CalamityMod:DevourerofGodsHead"] = new DoGSky(); @@ -331,8 +334,9 @@ namespace CalamityMod Filters.Scene["CalamityMod:LightBurst"].Load(); GameShaders.Misc["CalamityMod:SubsumingTentacle"] = new MiscShaderData(new Ref(TentacleShader), "BurstPass"); + GameShaders.Misc["CalamityMod:LightDistortion"] = new MiscShaderData(new Ref(LightDistortionShader), "DistortionPass"); - RipperUI.Reset(); + RipperUI.Reset(); AstralArcanumUI.Load(this); GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(0, 255, 171), ((float)player.Calamity().adrenaline / (float)player.Calamity().adrenalineMax)))); @@ -778,6 +782,7 @@ namespace CalamityMod ModContent.ProjectileType(), ModContent.ProjectileType(), ModContent.ProjectileType(), + ModContent.ProjectileType(), //Some hostile boss projectiles ModContent.ProjectileType(), diff --git a/Effects/DistortionShader.xnb b/Effects/DistortionShader.xnb new file mode 100644 index 0000000000..fc85ee9639 Binary files /dev/null and b/Effects/DistortionShader.xnb differ diff --git a/Items/Weapons/DraedonsArsenal/Phaseslayer.cs b/Items/Weapons/DraedonsArsenal/Phaseslayer.cs new file mode 100644 index 0000000000..a8facdbf6a --- /dev/null +++ b/Items/Weapons/DraedonsArsenal/Phaseslayer.cs @@ -0,0 +1,72 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.DraedonsArsenal; +using CalamityMod.Tiles.Furniture.CraftingStations; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Weapons.DraedonsArsenal +{ + public class Phaseslayer : ModItem + { + public const int MinDamage = 4500; + public const int MaxDamage = 12500; + public const float SmallPhaseDamageMultiplier = 0.66f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Phaseslayer"); + Tooltip.SetDefault("Creates a blade that aims towards the cursor. The faster you swing the blade, the more damage it does.\n" + + "Swinging quickly causes the blade to release energy forward"); + } + public override void SetDefaults() + { + item.damage = MinDamage; + item.melee = true; + item.width = 26; + item.height = 26; + item.useTime = 24; + item.useAnimation = 24; + item.useStyle = ItemUseStyleID.HoldingOut; + item.useTurn = false; + item.knockBack = 7f; + + item.noUseGraphic = true; + + item.value = CalamityGlobalItem.RarityVioletBuyPrice; + item.rare = 10; + item.Calamity().customRarity = CalamityRarity.RareVariant; + + item.UseSound = SoundID.Item1; + item.autoReuse = true; + + item.Calamity().Chargeable = true; + item.Calamity().ChargeMax = 250; + + item.shoot = ModContent.ProjectileType(); + + item.channel = true; + } + + public override bool CanUseItem(Player player) => player.ownedProjectileCounts[item.shoot] <= 0; + + public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) + { + Projectile blade = Projectile.NewProjectileDirect(position, Vector2.Zero, type, damage, knockBack, player.whoAmI); + blade.rotation = blade.AngleTo(Main.MouseWorld); + return false; + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ModContent.ItemType(), 15); + recipe.AddIngredient(ModContent.ItemType(), 15); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddIngredient(ItemID.RedPhasesaber); + recipe.AddTile(ModContent.TileType()); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Weapons/DraedonsArsenal/Phaseslayer.png b/Items/Weapons/DraedonsArsenal/Phaseslayer.png new file mode 100644 index 0000000000..53f9fb432a Binary files /dev/null and b/Items/Weapons/DraedonsArsenal/Phaseslayer.png differ diff --git a/Projectiles/DraedonsArsenal/PhaseslayerBeam.cs b/Projectiles/DraedonsArsenal/PhaseslayerBeam.cs new file mode 100644 index 0000000000..de66606ea8 --- /dev/null +++ b/Projectiles/DraedonsArsenal/PhaseslayerBeam.cs @@ -0,0 +1,67 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.Graphics.Shaders; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.DraedonsArsenal +{ + public class PhaseslayerBeam : ModProjectile + { + public const int Lifetime = 180; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Light Blade"); + Main.projFrames[projectile.type] = 5; + } + + public override void SetDefaults() + { + projectile.width = 64; + projectile.height = 120; + projectile.scale = 0.5f; + projectile.Size *= projectile.scale; + + projectile.friendly = true; + projectile.penetrate = 3; + projectile.melee = true; + projectile.tileCollide = false; + projectile.penetrate = -1; + projectile.usesLocalNPCImmunity = true; + projectile.timeLeft = Lifetime; + projectile.localNPCHitCooldown = 6; + } + + public override void AI() + { + projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; + NPC potentialTarget = projectile.Center.ClosestNPCAt(1000f); + if (potentialTarget != null && projectile.Distance(potentialTarget.Center) > 40f && projectile.timeLeft > Lifetime - 60) + { + projectile.velocity = (projectile.velocity * 7f + projectile.DirectionTo(potentialTarget.Center) * 24f) / 8f; + } + projectile.frameCounter++; + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D bladeTexture = ModContent.GetTexture(Texture); + MiscShaderData distortationShader = GameShaders.Misc["CalamityMod:LightDistortion"]; + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Rectangle frame = bladeTexture.Frame(1, 5, 0, projectile.frameCounter / 4 % 5); + var drawData2 = new DrawData(bladeTexture, projectile.Center - Main.screenPosition, frame, Color.White, projectile.rotation, bladeTexture.Size() * 0.5f, projectile.scale * 1.2f, SpriteEffects.None, 0); + distortationShader.Apply(drawData2); + drawData2.Draw(spriteBatch); + + return false; + } + public override void PostDraw(SpriteBatch spriteBatch, Color drawColor) + { + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + } + } +} diff --git a/Projectiles/DraedonsArsenal/PhaseslayerBeam.png b/Projectiles/DraedonsArsenal/PhaseslayerBeam.png new file mode 100644 index 0000000000..8c9c20d1fe Binary files /dev/null and b/Projectiles/DraedonsArsenal/PhaseslayerBeam.png differ diff --git a/Projectiles/DraedonsArsenal/PhaseslayerBlade.png b/Projectiles/DraedonsArsenal/PhaseslayerBlade.png new file mode 100644 index 0000000000..a7058e9bce Binary files /dev/null and b/Projectiles/DraedonsArsenal/PhaseslayerBlade.png differ diff --git a/Projectiles/DraedonsArsenal/PhaseslayerBladeSmall.png b/Projectiles/DraedonsArsenal/PhaseslayerBladeSmall.png new file mode 100644 index 0000000000..f52f934a8a Binary files /dev/null and b/Projectiles/DraedonsArsenal/PhaseslayerBladeSmall.png differ diff --git a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs new file mode 100644 index 0000000000..b34e8674fb --- /dev/null +++ b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.cs @@ -0,0 +1,227 @@ +using CalamityMod.Dusts; +using CalamityMod.Items.Weapons.DraedonsArsenal; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.DraedonsArsenal +{ + public class PhaseslayerProjectile : ModProjectile + { + public bool IsSmall => Main.player[projectile.owner].ActiveItem().Calamity().CurrentCharge / (float)Main.player[projectile.owner].ActiveItem().Calamity().ChargeMax < 0.5f; + public float AngularSwingMomentum + { + get => projectile.ai[0]; + set => projectile.ai[0] = value; + } + public float FadeoutTime + { + get => projectile.localAI[0]; + set => projectile.localAI[0] = value; + } + public int BladeFrameX => IsSmall ? 1 : projectile.frame / 7; + public int BladeFrameY => IsSmall ? projectile.frame % 3 : projectile.frame % 7; + + // This is rotation EVERY FRAME. Max damage occurs when you can swing it 360 degrees in half a second. + // That speed is 12 degrees per frame, or pi/15 radians per frame. + public const float MaxAngularDamage = MathHelper.Pi / 15f; + public const float DamageUpdateResponsiveness = 0.08f; + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Phaseslayer"); + ProjectileID.Sets.TrailingMode[projectile.type] = 2; + ProjectileID.Sets.TrailCacheLength[projectile.type] = 8; + } + + public override void SetDefaults() + { + projectile.width = 46; // Collision logic is done manually. + projectile.height = 46; + projectile.penetrate = -1; + projectile.tileCollide = false; + projectile.melee = true; + projectile.ignoreWater = true; + projectile.usesLocalNPCImmunity = true; + projectile.friendly = true; + projectile.localNPCHitCooldown = 3; + } + + public override void AI() + { + Player player = Main.player[projectile.owner]; + float rotationAdjusted = MathHelper.WrapAngle(projectile.rotation) + MathHelper.Pi; // Within the bounds of 0 and 2pi instead of -pi and pi for convenience with absolute values. + float oldRotationAdjusted = MathHelper.WrapAngle(projectile.oldRot[1]) + MathHelper.Pi; + float deltaAngle = Math.Abs(rotationAdjusted - oldRotationAdjusted); + + ManipulatePlayer(player); + AdjustDamageBasedOnRotation(player, deltaAngle); + ManipulateFrames(); + PlaySounds(player, deltaAngle); + HandleCooldowns(); + } + + public void AdjustDamageBasedOnRotation(Player player, float deltaAngle) + { + AngularSwingMomentum = MathHelper.Lerp(AngularSwingMomentum, deltaAngle, DamageUpdateResponsiveness); + + float damageInterpolationValue = 0.16f + (float)Math.Log(AngularSwingMomentum / MaxAngularDamage + 1.5f, 3f); + float baseDamageFromSpeed = MathHelper.Lerp(Phaseslayer.MinDamage, Phaseslayer.MaxDamage, damageInterpolationValue); + + float statDamageMultiplier = player.MeleeDamage() * (IsSmall ? Phaseslayer.SmallPhaseDamageMultiplier : 1f); + projectile.damage = (int)(baseDamageFromSpeed * statDamageMultiplier); + } + + public void ManipulatePlayer(Player player) + { + if (Main.myPlayer == player.whoAmI) + { + // Smoothly rotate towards the mouse. This effect is weaker if the mouse is close to the player, to prevent jittery movement. + if (player.channel && !player.noItems && !player.CCed && player.ActiveItem().type == ModContent.ItemType()) + { + float mouseDistance = projectile.Distance(Main.MouseWorld); + + // Ranges from 0 (your mouse is on the player) to 1 (your mouse is at the max range considered, or any further distance). + float distRatio = Utils.InverseLerp(0f, 360f, mouseDistance, true); + + float aimResponsiveness = Utils.InverseLerp(0.035f, 1f, distRatio); + projectile.rotation = projectile.rotation.AngleLerp(player.AngleTo(Main.MouseWorld), aimResponsiveness); + } + else if (FadeoutTime == 0f) + { + if (!player.channel) + FadeoutTime = 10f; // Fade out if the player is no longer charging the weapon. + else projectile.Kill(); // But if something happened to the player, such as death, just kill the projectile immediately. + } + projectile.Center = player.MountedCenter + projectile.rotation.ToRotationVector2() * 36f; + } + projectile.direction = (Math.Cos(projectile.rotation) > 0).ToDirectionInt(); + player.ChangeDir(projectile.direction); + player.heldProj = projectile.whoAmI; + player.itemTime = 2; + player.itemAnimation = 2; + player.itemRotation = projectile.rotation * projectile.direction; + } + + public void ManipulateFrames() + { + projectile.frame = 0; + + if (IsSmall) + { + // Fadeout frames. + if (FadeoutTime > 5) + projectile.frame = 1; + else if (FadeoutTime > 0) + projectile.frame = 2; + } + else + { + projectile.frameCounter++; + int adjustFrameCounter = projectile.frameCounter % 120; + + // Idle lightning frames. + if (adjustFrameCounter >= 50 && adjustFrameCounter <= 78) + projectile.frame = (int)MathHelper.Lerp(1, 9, Utils.InverseLerp(50, 75, adjustFrameCounter, true)); + if (adjustFrameCounter >= 90 && adjustFrameCounter <= 120) + projectile.frame = (int)MathHelper.Lerp(10, 18, Utils.InverseLerp(90, 117, adjustFrameCounter, true)); + + // Fadeout frames. + if (FadeoutTime > 5) + projectile.frame = 19; + else if (FadeoutTime > 0) + projectile.frame = 20; + } + } + + public void PlaySounds(Player player, float deltaAngle) + { + if (projectile.soundDelay <= 0 && deltaAngle >= 0.055f) + { + if (Main.myPlayer == player.whoAmI) + { + Vector2 velocity = projectile.rotation.ToRotationVector2() * 20f; + Projectile.NewProjectile(projectile.Center, velocity, ModContent.ProjectileType(), (int)(projectile.damage * 0.45), 0f, player.whoAmI); + } + bool wasBig = !IsSmall; + if (Main.rand.NextBool(10) && player.ActiveItem().Calamity().CurrentCharge > 0) + { + // This needs to be done manually instead of via ActiveItem. If it isn't, the charge reductions don't work if the item is held via the mouse. + if (Main.myPlayer == projectile.owner) + { + if (Main.mouseItem.active) + Main.mouseItem.Calamity().CurrentCharge--; + else player.HeldItem.Calamity().CurrentCharge--; + } + + // Make some visuals if the sword becomes small as a result of charging. + if (IsSmall && wasBig) + { + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/MechGaussRifle"), projectile.Center); + if (!Main.dedServ) + { + for (int i = 0; i < 60; i++) + { + Dust dust = Dust.NewDustPerfect(projectile.Center, (int)CalamityDusts.Brimstone); + dust.velocity = Main.rand.NextVector2Circular(20f, 20f); + dust.scale = 2.5f; + dust.fadeIn = 1.2f; + dust.noGravity = true; + } + } + } + } + projectile.soundDelay = 15 - (int)MathHelper.Clamp(deltaAngle / MathHelper.ToRadians(36f) * 9f, 0f, 9f); + Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/ELRFire"), projectile.Center); + } + } + + public void HandleCooldowns() + { + if (FadeoutTime > 0) + { + FadeoutTime--; + if (FadeoutTime <= 0f) + projectile.Kill(); + } + } + + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) + { + Texture2D bladeTexture = ModContent.GetTexture("CalamityMod/Projectiles/DraedonsArsenal/PhaseslayerBlade"); + Texture2D hiltTexture = ModContent.GetTexture(Texture); + if (IsSmall) + bladeTexture = ModContent.GetTexture("CalamityMod/Projectiles/DraedonsArsenal/PhaseslayerBladeSmall"); + Vector2 bladeOffset = projectile.rotation.ToRotationVector2() * (IsSmall ? 90f : 132f) * projectile.scale; + Vector2 origin = bladeTexture.Size() * 0.5f; + origin /= IsSmall ? new Vector2(1f, 3f) : new Vector2(3f, 7f); + Rectangle frame = IsSmall ? bladeTexture.Frame(1, 3, 0, BladeFrameY) : bladeTexture.Frame(3, 7, BladeFrameX, BladeFrameY); + + // TODO: Update this afterimage drawcode to be more cool. + for (int i = 1; i < projectile.oldRot.Length; i++) + { + float angleDelta = MathHelper.Clamp(projectile.rotation - projectile.oldRot[i], -0.26f, 0.26f); + float angle = projectile.rotation + angleDelta; + angle += MathHelper.PiOver2; + Color color = Color.White * (float)Math.Pow(1f - i / (float)projectile.oldRot.Length, 3f); + Rectangle afterimageFrame = IsSmall ? bladeTexture.Frame(1, 3, 0, 2) : bladeTexture.Frame(3, 7, 2, 6); + spriteBatch.Draw(bladeTexture, projectile.Center + bladeOffset - Main.screenPosition, afterimageFrame, color, angle, origin, projectile.scale, SpriteEffects.None, 0f); + } + + spriteBatch.Draw(bladeTexture, projectile.Center + bladeOffset - Main.screenPosition, frame, Color.White, projectile.rotation + MathHelper.PiOver2, origin, projectile.scale, SpriteEffects.None, 0f); + spriteBatch.Draw(hiltTexture, projectile.Center - Main.screenPosition, null, lightColor, projectile.rotation + MathHelper.PiOver2, hiltTexture.Size() * 0.5f, projectile.scale, SpriteEffects.None, 0f); + + return false; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float _ = 0f; + Vector2 start = projectile.Center + projectile.rotation.ToRotationVector2() * 28f; + Vector2 end = start + projectile.rotation.ToRotationVector2() * (IsSmall ? 202f : 254f) * projectile.scale; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), start, end, 60f * projectile.scale, ref _); + } + } +} diff --git a/Projectiles/DraedonsArsenal/PhaseslayerProjectile.png b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.png new file mode 100644 index 0000000000..53f9fb432a Binary files /dev/null and b/Projectiles/DraedonsArsenal/PhaseslayerProjectile.png differ