diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 0a593f6bbc..8d4f7591bc 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -18,6 +18,7 @@ using CalamityMod.Events; using CalamityMod.FluidSimulation; using CalamityMod.Items; using CalamityMod.Items.Accessories; +using CalamityMod.Items.Accessories.Vanity; using CalamityMod.Items.Armor; using CalamityMod.Items.Armor.Bloodflare; using CalamityMod.Items.Armor.Brimflame; @@ -26,6 +27,7 @@ using CalamityMod.Items.Armor.GemTech; using CalamityMod.Items.Armor.OmegaBlue; using CalamityMod.Items.Armor.PlagueReaper; using CalamityMod.Items.Armor.Silva; +using CalamityMod.Items.Armor.Wulfrum; using CalamityMod.Items.Dyes; using CalamityMod.Items.Mounts; using CalamityMod.Items.Mounts.Minecarts; @@ -2548,6 +2550,8 @@ namespace CalamityMod.CalPlayer return new Item(); } + + public override void ProcessTriggers(TriggersSet triggersSet) { if (CalamityKeybinds.NormalityRelocatorHotKey.JustPressed && normalityRelocator && Main.myPlayer == Player.whoAmI) @@ -5849,10 +5853,17 @@ namespace CalamityMod.CalPlayer // The amount of damage that will be dealt is yet to be determined. // + //Todo - At some point it'd be nice to have a "TransformationPlayer" that has all the transformation sfx and visuals so their priorities can be more easily managed. #region Custom Hurt Sounds if (hurtSoundTimer == 0) { - if ((profanedCrystal || profanedCrystalForce) && !profanedCrystalHide) + if (Player.GetModPlayer().ProtectionMatrixDurability > 0) + { + playSound = false; + SoundEngine.PlaySound(RoverDrive.ShieldHurtSound, Player.position); + hurtSoundTimer = 20; + } + else if ((profanedCrystal || profanedCrystalForce) && !profanedCrystalHide) { playSound = false; SoundEngine.PlaySound(Providence.DeathSound, Player.position); @@ -5876,6 +5887,18 @@ namespace CalamityMod.CalPlayer SoundEngine.PlaySound(NPCs.Astral.Atlas.HurtSound, Player.position); hurtSoundTimer = 10; } + else if (Player.GetModPlayer().transformationActive) + { + playSound = false; + SoundEngine.PlaySound(SoundID.NPCHit4, Player.position); + hurtSoundTimer = 10; + } + else if (Player.GetModPlayer().wulfrumSet && (Player.name.ToLower() == "wagstaff" || Player.name.ToLower() == "john wulfrum")) + { + playSound = false; + SoundEngine.PlaySound(SoundID.DSTMaleHurt, Player.position); + hurtSoundTimer = 10; + } } #endregion diff --git a/CalPlayer/CalamityPlayerDrawEffects.cs b/CalPlayer/CalamityPlayerDrawEffects.cs index 5c853f4469..50da4d8ba1 100644 --- a/CalPlayer/CalamityPlayerDrawEffects.cs +++ b/CalPlayer/CalamityPlayerDrawEffects.cs @@ -11,6 +11,8 @@ using Terraria.DataStructures; using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Items.Armor.Wulfrum; namespace CalamityMod.CalPlayer { @@ -37,6 +39,11 @@ namespace CalamityMod.CalPlayer layer.Hide(); } } + + if (Player.HeldItem.ModItem is IHideFrontArm amputator && amputator.ShouldHideArm(Player)) + { + PlayerDrawLayers.ArmOverItem.Hide(); + } } public override void DrawEffects(PlayerDrawSet drawInfo, ref float r, ref float g, ref float b, ref float a, ref bool fullBright) diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 639229b40d..61918acf43 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -58,6 +58,7 @@ using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; using ProvidenceBoss = CalamityMod.NPCs.Providence.Providence; +using CalamityMod.Items.Armor.Wulfrum; namespace CalamityMod.CalPlayer { @@ -207,6 +208,11 @@ namespace CalamityMod.CalPlayer // Apply stealth damage to rogue. Player.GetDamage() += stealthDamage; + + //Slow the player down after any other speed modifiers might have been applied. + //Todo - Move this back to the wulfrum set class whenever statmodifiers are implemented for stats other than damage + if (WulfrumHat.PowerModeEngaged(Player, out _)) + Player.moveSpeed *= 0.8f; } #endregion diff --git a/CalPlayer/DrawLayers/HatExtensionLayer.cs b/CalPlayer/DrawLayers/HatExtensionLayer.cs index 0aa9992ebf..9fc472b4b1 100644 --- a/CalPlayer/DrawLayers/HatExtensionLayer.cs +++ b/CalPlayer/DrawLayers/HatExtensionLayer.cs @@ -15,14 +15,19 @@ namespace CalamityMod.CalPlayer.DrawLayers protected override void Draw(ref PlayerDrawSet drawInfo) { + //Todo : Make this work even for accessories by somehow checking for the players.head equipslot's item instead of the head item. Player drawPlayer = drawInfo.drawPlayer; - int headItemType = drawPlayer.armor[0].type; - if (drawPlayer.armor[10].type > ItemID.None) - headItemType = drawPlayer.armor[10].type; + Item headItem = drawPlayer.armor[0]; - if (ModContent.GetModItem(headItemType) is IExtendedHat extendedHatDrawer) + if (drawPlayer.armor[10].type > ItemID.None) + headItem = drawPlayer.armor[10]; + + if (ModContent.GetModItem(headItem.type) is IExtendedHat extendedHatDrawer) { - if (extendedHatDrawer.PreDrawExtension(drawInfo) && !drawInfo.drawPlayer.dead) + string equipSlotName = extendedHatDrawer.EquipSlotName(drawPlayer) != "" ? extendedHatDrawer.EquipSlotName(drawPlayer) : headItem.Name; + int equipSlot = EquipLoader.GetEquipSlot(Mod, equipSlotName, EquipType.Head); + + if (extendedHatDrawer.PreDrawExtension(drawInfo) && !drawInfo.drawPlayer.dead && equipSlot == drawPlayer.head) { int dyeShader = drawPlayer.dye?[0].dye ?? 0; diff --git a/CalPlayer/DrawLayers/IExtendedHat.cs b/CalPlayer/DrawLayers/IExtendedHat.cs index 40a569380c..499f7415e5 100644 --- a/CalPlayer/DrawLayers/IExtendedHat.cs +++ b/CalPlayer/DrawLayers/IExtendedHat.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Terraria.DataStructures; +using Terraria; public interface IExtendedHat { @@ -15,4 +16,10 @@ public interface IExtendedHat ///Return true to make the extension get drawn automatically from the texture and offsets provided. Return false if you want to draw it yourself /// bool PreDrawExtension(PlayerDrawSet drawInfo) => true; + + /// + /// The name of the equip slot for the item. If left empty, the equip slot that is looked for will use the name of the item. + /// Useful if you have multiple head textures you need to extend. + /// + string EquipSlotName(Player drawPlayer) => ""; } diff --git a/CalPlayer/DrawLayers/IHideFrontArm.cs b/CalPlayer/DrawLayers/IHideFrontArm.cs new file mode 100644 index 0000000000..b91fff9550 --- /dev/null +++ b/CalPlayer/DrawLayers/IHideFrontArm.cs @@ -0,0 +1,15 @@ +using Microsoft.Xna.Framework; +using Terraria.DataStructures; +using Terraria; + +/// +/// Interface that can be used by items that need to hide the players front arm when held. +/// Useful for prosthesis type items. +/// +public interface IHideFrontArm +{ + /// + /// When should the arm be hidden. Defauls to always + /// + bool ShouldHideArm(Player player) => true; +} diff --git a/CalamityMod.cs b/CalamityMod.cs index a65ab5b7de..ef5a470cda 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -1,4 +1,10 @@ -using CalamityMod.Balancing; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Reflection; +using System.Runtime.CompilerServices; +using CalamityMod.Balancing; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.CalPlayer; @@ -55,12 +61,6 @@ using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Runtime.CompilerServices; using Terraria; using Terraria.GameContent; using Terraria.GameContent.Dyes; @@ -75,6 +75,8 @@ namespace CalamityMod { public class CalamityMod : Mod { + public const string CalamityWikiURL = "calamitymod.wiki.gg"; + // TODO -- A huge amount of random floating variables exist here. // These should all be moved to other files, whether that's CalamityLists or brand new ModSystems. // It is best to have a ton of small ModSystems. @@ -133,10 +135,11 @@ namespace CalamityMod internal Mod overhaul = null; internal Mod redemption = null; internal Mod soa = null; + internal Mod subworldLibrary = null; internal Mod summonersAssociation = null; internal Mod thorium = null; internal Mod varia = null; - internal Mod subworldLibrary = null; + internal Mod wikithis = null; #region Load public override void Load() @@ -172,14 +175,16 @@ namespace CalamityMod ModLoader.TryGetMod("Redemption", out redemption); soa = null; ModLoader.TryGetMod("SacredTools", out soa); + subworldLibrary = null; + ModLoader.TryGetMod("SubworldLibrary", out subworldLibrary); summonersAssociation = null; ModLoader.TryGetMod("SummonersAssociation", out summonersAssociation); thorium = null; ModLoader.TryGetMod("ThoriumMod", out thorium); varia = null; ModLoader.TryGetMod("Varia", out varia); - subworldLibrary = null; - ModLoader.TryGetMod("SubworldLibrary", out subworldLibrary); + wikithis = null; + ModLoader.TryGetMod("Wikithis", out wikithis); // Initialize the EnemyStats struct as early as it is safe to do so NPCStats.Load(); @@ -206,6 +211,8 @@ namespace CalamityMod { LoadClient(); GeneralParticleHandler.Load(); + if (wikithis is not null) + wikithis.Call("AddModURL", this, CalamityWikiURL); } CooldownRegistry.Load(); @@ -331,6 +338,7 @@ namespace CalamityMod public override void Unload() { musicMod = null; + ancientsAwakened = null; bossChecklist = null; census = null; @@ -339,9 +347,11 @@ namespace CalamityMod overhaul = null; redemption = null; soa = null; + subworldLibrary = null; summonersAssociation = null; thorium = null; varia = null; + wikithis = null; AstralSky = null; diff --git a/Cooldowns/WulfrumBastion.cs b/Cooldowns/WulfrumBastion.cs new file mode 100644 index 0000000000..69ac6899bf --- /dev/null +++ b/Cooldowns/WulfrumBastion.cs @@ -0,0 +1,73 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.Audio; +using Terraria.Graphics.Shaders; +using static Terraria.ModLoader.ModContent; +using CalamityMod.Items.Armor.Wulfrum; + +namespace CalamityMod.Cooldowns +{ + public class WulfrumBastion : CooldownHandler + { + public bool PowerActive => instance.timeLeft > WulfrumHat.BastionCooldown; + public float DurabilityPercent => (instance.timeLeft - WulfrumHat.BastionCooldown) / (float)WulfrumHat.BastionTime; + + + public static new string ID => "WulfrumBastion"; + public override bool ShouldDisplay => true; + public override string DisplayName => PowerActive ? "Power Armor Durability" : "Wulfrum Bastion Cooldown"; + public override string Texture => PowerActive ? "CalamityMod/Cooldowns/WulfrumBastionActive" : "CalamityMod/Cooldowns/WulfrumBastion"; + public override string OutlineTexture => "CalamityMod/Cooldowns/WulfrumBastionOutline"; + public override string OverlayTexture => "CalamityMod/Cooldowns/WulfrumBastionOverlay"; + public override Color OutlineColor => PowerActive ? new Color(194, 255, 67) : new Color(206, 201, 170); + public override Color CooldownStartColor => PowerActive ? Color.Lerp(new Color(112, 244, 244), new Color(54, 177, 221), DurabilityPercent) : new Color(92, 187, 99); + public override Color CooldownEndColor => PowerActive ? Color.Lerp(new Color(112, 244, 244), new Color(54, 177, 221), DurabilityPercent) : new Color(160, 232, 77); + public override SoundStyle? EndSound => new("CalamityMod/Sounds/Custom/AbilitySounds/WulfrumBastionRecharge"); + //public override bool SavedWithPlayer => false; + + public override void OnCompleted() + { + for (int i = 0; i < 6; i++) + { + Vector2 dustDirection = Main.rand.NextVector2CircularEdge(1f, 1f); + Dust d = Dust.NewDustPerfect(instance.player.Center + dustDirection * Main.rand.NextFloat(0.4f, 10f), 226, dustDirection * Main.rand.NextFloat(1f, 4f), 100, Color.Transparent, Main.rand.NextFloat(0.8f, 1.2f)); + d.noGravity = true; + d.noLight = true; + d.fadeIn = 1f; + } + } + + //Charge down at first, and then charge back up + private float AdjustedCompletion => PowerActive ? (instance.timeLeft - WulfrumHat.BastionCooldown) / (float)WulfrumHat.BastionTime : 1 - (instance.timeLeft / (float)WulfrumHat.BastionCooldown); + + public override void ApplyBarShaders(float opacity) + { + //Use the adjusted completion + GameShaders.Misc["CalamityMod:CircularBarShader"].UseOpacity(opacity); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSaturation(AdjustedCompletion); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseColor(CooldownStartColor); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSecondaryColor(CooldownEndColor); + GameShaders.Misc["CalamityMod:CircularBarShader"].Apply(); + } + + public override void DrawCompact(SpriteBatch spriteBatch, Vector2 position, float opacity, float scale) + { + Texture2D sprite = Request(Texture).Value; + Texture2D outline = Request(OutlineTexture).Value; + Texture2D overlay = Request(OverlayTexture).Value; + + //Draw the outline + spriteBatch.Draw(outline, position, null, OutlineColor * opacity, 0, outline.Size() * 0.5f, scale, SpriteEffects.None, 0f); + + //Draw the icon + spriteBatch.Draw(sprite, position, null, Color.White * opacity, 0, sprite.Size() * 0.5f, scale, SpriteEffects.None, 0f); + + //Draw the small overlay + int lostHeight = (int)Math.Ceiling(overlay.Height * AdjustedCompletion); + Rectangle crop = new Rectangle(0, lostHeight, overlay.Width, overlay.Height - lostHeight); + spriteBatch.Draw(overlay, position + Vector2.UnitY * lostHeight * scale, crop, OutlineColor * opacity * 0.9f, 0, sprite.Size() * 0.5f, scale, SpriteEffects.None, 0f); + } + } +} diff --git a/Cooldowns/WulfrumBastion.png b/Cooldowns/WulfrumBastion.png new file mode 100644 index 0000000000..af341785a7 Binary files /dev/null and b/Cooldowns/WulfrumBastion.png differ diff --git a/Cooldowns/WulfrumBastionActive.png b/Cooldowns/WulfrumBastionActive.png new file mode 100644 index 0000000000..485d708e34 Binary files /dev/null and b/Cooldowns/WulfrumBastionActive.png differ diff --git a/Cooldowns/WulfrumBastionOutline.png b/Cooldowns/WulfrumBastionOutline.png new file mode 100644 index 0000000000..522a00d293 Binary files /dev/null and b/Cooldowns/WulfrumBastionOutline.png differ diff --git a/Cooldowns/WulfrumBastionOverlay.png b/Cooldowns/WulfrumBastionOverlay.png new file mode 100644 index 0000000000..36a775e1c8 Binary files /dev/null and b/Cooldowns/WulfrumBastionOverlay.png differ diff --git a/Cooldowns/WulfrumRoverDrive.cs b/Cooldowns/WulfrumRoverDrive.cs new file mode 100644 index 0000000000..6eb90943ff --- /dev/null +++ b/Cooldowns/WulfrumRoverDrive.cs @@ -0,0 +1,93 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent; +using static CalamityMod.CalamityUtils; +using static Terraria.ModLoader.ModContent; +using CalamityMod.Items.Accessories; +using Terraria.Audio; +using Terraria.Graphics.Shaders; +using System; + +namespace CalamityMod.Cooldowns +{ + public class WulfrumRoverDriveDurability : CooldownHandler + { + private static Color ringColorLerpStart = new Color(49, 220, 221); + private static Color ringColorLerpEnd = new Color(99, 226, 142); + + private float AdjustedCompletion => (instance.timeLeft) / (float)RoverDrive.ProtectionMatrixDurabilityMax; + + public static new string ID => "WulfrumRoverDriveDurability"; + public override bool CanTickDown => !instance.player.GetModPlayer().RoverDriveOn || instance.timeLeft <= 0; + public override bool ShouldDisplay => instance.player.GetModPlayer().RoverDriveOn; + public override string DisplayName => "Protective Matrix Durability"; + public override string Texture => "CalamityMod/Cooldowns/WulfrumRoverDriveActive"; + public override string OutlineTexture => "CalamityMod/Cooldowns/WulfrumRoverDriveOutline"; + public override string OverlayTexture => "CalamityMod/Cooldowns/WulfrumRoverDriveOverlay"; + public override Color OutlineColor => new Color(112, 244, 244); + public override Color CooldownStartColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); + public override Color CooldownEndColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); + public override bool SavedWithPlayer => false; + public override bool PersistsThroughDeath => false; + + + public override void ApplyBarShaders(float opacity) + { + //Use the adjusted completion + GameShaders.Misc["CalamityMod:CircularBarShader"].UseOpacity(opacity); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSaturation(AdjustedCompletion); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseColor(CooldownStartColor); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSecondaryColor(CooldownEndColor); + GameShaders.Misc["CalamityMod:CircularBarShader"].Apply(); + } + + public override void DrawExpanded(SpriteBatch spriteBatch, Vector2 position, float opacity, float scale) + { + base.DrawExpanded(spriteBatch, position, opacity, scale); + + float Xoffset = instance.timeLeft > 9 ? -10f : -5; + DrawBorderStringEightWay(spriteBatch, FontAssets.MouseText.Value, instance.timeLeft.ToString(), position + new Vector2(Xoffset, 4) * scale, Color.Lerp(ringColorLerpStart, Color.OrangeRed, 1 - instance.Completion), Color.Black, scale); + } + + public override void DrawCompact(SpriteBatch spriteBatch, Vector2 position, float opacity, float scale) + { + Texture2D sprite = Request(Texture).Value; + Texture2D outline = Request(OutlineTexture).Value; + Texture2D overlay = Request(OverlayTexture).Value; + + //Draw the outline + spriteBatch.Draw(outline, position, null, OutlineColor * opacity, 0, outline.Size() * 0.5f, scale, SpriteEffects.None, 0f); + + //Draw the icon + spriteBatch.Draw(sprite, position, null, Color.White * opacity, 0, sprite.Size() * 0.5f, scale, SpriteEffects.None, 0f); + + //Draw the small overlay + int lostHeight = (int)Math.Ceiling(overlay.Height * AdjustedCompletion); + Rectangle crop = new Rectangle(0, lostHeight, overlay.Width, overlay.Height - lostHeight); + spriteBatch.Draw(overlay, position + Vector2.UnitY * lostHeight * scale, crop, OutlineColor * opacity * 0.9f, 0, sprite.Size() * 0.5f, scale, SpriteEffects.None, 0f); + + float Xoffset = instance.timeLeft > 9 ? -10f : -5; + DrawBorderStringEightWay(spriteBatch, FontAssets.MouseText.Value, instance.timeLeft.ToString(), position + new Vector2(Xoffset, 4) * scale, Color.Lerp(ringColorLerpStart, Color.OrangeRed, 1 - instance.Completion), Color.Black, scale); + } + } + + public class WulfrumRoverDriveRecharge : CooldownHandler + { + private static Color ringColorLerpStart = new Color(194, 255, 57); + private static Color ringColorLerpEnd = new Color(92, 187, 99); + + public static new string ID => "WulfrumRoverDriveRecharge"; + public override bool ShouldDisplay => true; + public override string DisplayName => "Protective Matrix Recharge"; + public override string Texture => "CalamityMod/Cooldowns/WulfrumRoverDrive"; + public override bool SavedWithPlayer => false; + public override bool PersistsThroughDeath => false; + public override Color OutlineColor => new Color(194, 255, 67); + public override Color CooldownStartColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); + public override Color CooldownEndColor => Color.Lerp(ringColorLerpStart, ringColorLerpEnd, instance.Completion); + + public override void OnCompleted() => instance.player.GetModPlayer().ProtectionMatrixDurability = RoverDrive.ProtectionMatrixDurabilityMax; + public override SoundStyle? EndSound => null; + } +} diff --git a/Cooldowns/WulfrumRoverDrive.png b/Cooldowns/WulfrumRoverDrive.png new file mode 100644 index 0000000000..f1166cb024 Binary files /dev/null and b/Cooldowns/WulfrumRoverDrive.png differ diff --git a/Cooldowns/WulfrumRoverDriveActive.png b/Cooldowns/WulfrumRoverDriveActive.png new file mode 100644 index 0000000000..ba476787c7 Binary files /dev/null and b/Cooldowns/WulfrumRoverDriveActive.png differ diff --git a/Cooldowns/WulfrumRoverDriveOutline.png b/Cooldowns/WulfrumRoverDriveOutline.png new file mode 100644 index 0000000000..0bf2e0315a Binary files /dev/null and b/Cooldowns/WulfrumRoverDriveOutline.png differ diff --git a/Cooldowns/WulfrumRoverDriveOverlay.png b/Cooldowns/WulfrumRoverDriveOverlay.png new file mode 100644 index 0000000000..ff2e2f376b Binary files /dev/null and b/Cooldowns/WulfrumRoverDriveOverlay.png differ diff --git a/DataStructures/VerletSimulatedSegments.cs b/DataStructures/VerletSimulatedSegments.cs new file mode 100644 index 0000000000..8f9a1d031e --- /dev/null +++ b/DataStructures/VerletSimulatedSegments.cs @@ -0,0 +1,59 @@ +using Microsoft.Xna.Framework; +using System.Collections.Generic; + +namespace CalamityMod.DataStructures +{ + public class VerletSimulatedSegment + { + public Vector2 position, oldPosition; + public bool locked; + + public VerletSimulatedSegment(Vector2 _position, bool _locked = false) + { + position = _position; + oldPosition = _position; + locked = _locked; + } + + public static List SimpleSimulation(List segments, float segmentDistance, int loops = 10, float gravity = 0.3f) + { + //https://youtu.be/PGk0rnyTa1U?t=400 verlet integration chains reference here + foreach (VerletSimulatedSegment segment in segments) + { + if (!segment.locked) + { + Vector2 positionBeforeUpdate = segment.position; + + segment.position += (segment.position - segment.oldPosition); // This adds conservation of energy to the segments. This makes it super bouncy and shouldnt be used but it's really funny + segment.position += Vector2.UnitY * gravity; //=> This adds gravity to the segments. + + segment.oldPosition = positionBeforeUpdate; + } + } + + int segmentCount = segments.Count; + + for (int k = 0; k < loops; k++) + { + for (int j = 0; j < segmentCount - 1; j++) + { + VerletSimulatedSegment pointA = segments[j]; + VerletSimulatedSegment pointB = segments[j + 1]; + Vector2 segmentCenter = (pointA.position + pointB.position) / 2f; + Vector2 segmentDirection = Terraria.Utils.SafeNormalize(pointA.position - pointB.position, Vector2.UnitY); + + if (!pointA.locked) + pointA.position = segmentCenter + segmentDirection * segmentDistance / 2f; + + if (!pointB.locked) + pointB.position = segmentCenter - segmentDirection * segmentDistance / 2f; + + segments[j] = pointA; + segments[j + 1] = pointB; + } + } + + return segments; + } + } +} diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index b43eca0ba8..28afaeab49 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -125,6 +125,18 @@ namespace CalamityMod.Effects screenRef = new Ref(CalamityMod.Instance.Assets.Request("Effects/PixelatedSightLine", AssetRequestMode.ImmediateLoad).Value); Filters.Scene["PixelatedSightLine"] = new Filter(new ScreenShaderData(screenRef, "SightLinePass"), EffectPriority.High); Filters.Scene["PixelatedSightLine"].Load(); + + screenRef = new Ref(CalamityMod.Instance.Assets.Request("Effects/WulfrumTilePing", AssetRequestMode.ImmediateLoad).Value); + Filters.Scene["WulfrumTilePing"] = new Filter(new ScreenShaderData(screenRef, "TilePingPass"), EffectPriority.High); + Filters.Scene["WulfrumTilePing"].Load(); + + screenRef = new Ref(CalamityMod.Instance.Assets.Request("Effects/WulfrumScaffoldSelection", AssetRequestMode.ImmediateLoad).Value); + Filters.Scene["WulfrumScaffoldSelection"] = new Filter(new ScreenShaderData(screenRef, "TilePingPass"), EffectPriority.High); + Filters.Scene["WulfrumScaffoldSelection"].Load(); + + screenRef = new Ref(CalamityMod.Instance.Assets.Request("Effects/RoverDriveShield", AssetRequestMode.ImmediateLoad).Value); + Filters.Scene["RoverDriveShield"] = new Filter(new ScreenShaderData(screenRef, "ShieldPass"), EffectPriority.High); + Filters.Scene["RoverDriveShield"].Load(); } } } diff --git a/Effects/RoverDriveShield.fx b/Effects/RoverDriveShield.fx new file mode 100644 index 0000000000..ef427472cf --- /dev/null +++ b/Effects/RoverDriveShield.fx @@ -0,0 +1,53 @@ +float time; +float blowUpPower; //The power the blow up effect is set as. Ideally betwen 0 and 1 +float blowUpSize; //The strenght of the expansion caused by the blow up effect +float3 shieldColor; +float shieldOpacity; +float3 shieldEdgeColor; +float shieldEdgeBlendStrenght; +float noiseScale; +float resolution; + +texture sampleTexture; +sampler2D Texture1Sampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; }; + +float4 main(float2 uv : TEXCOORD) : COLOR +{ + //Pixelate? + //uv.x -= uv.x % (1 / resolution); + //uv.y -= uv.y % (1 / resolution); + + //Crop in a circle + float distanceFromCenter = length(uv - float2(0.5, 0.5)) * 2; + if (distanceFromCenter > 1) + return float4(0, 0, 0, 0); + + //"Blow up" the noise map so it looks circular. + float blownUpUVX = pow((abs(uv.x - 0.5)) * 2, blowUpPower); + float blownUpUVY = pow((abs(uv.y - 0.5)) * 2, blowUpPower); + float2 blownUpUV = float2(-blownUpUVY * blowUpSize * 0.5 + uv.x * (1 + blownUpUVY * blowUpSize), -blownUpUVX * blowUpSize * 0.5 + uv.y * (1 + blownUpUVX * blowUpSize)); + + //Rescale + blownUpUV *= noiseScale; + //Scroll effect + blownUpUV.x = (blownUpUV.x + time) % 1; + + //Get the noise color + float4 noiseColor = tex2D(Texture1Sampler, blownUpUV); + + //Apply a layers of fake fresnel + noiseColor += pow(distanceFromCenter, 6); // + pow(distanceFromCenter, 3) * 0.6; <- Brings us over into ps 3.0 territory if we have pixelation on. + //Fade the edges + if (distanceFromCenter > 0.95) + noiseColor *= (1 - ((distanceFromCenter - 0.95) / 0.05)); + + return noiseColor * float4(lerp(shieldColor, shieldEdgeColor, pow(distanceFromCenter, shieldEdgeBlendStrenght)), shieldOpacity); +} + +technique Technique1 +{ + pass ShieldPass + { + PixelShader = compile ps_2_0 main(); + } +} \ No newline at end of file diff --git a/Effects/RoverDriveShield.xnb b/Effects/RoverDriveShield.xnb new file mode 100644 index 0000000000..f26b005c5d Binary files /dev/null and b/Effects/RoverDriveShield.xnb differ diff --git a/Effects/WulfrumScaffoldSelection.fx b/Effects/WulfrumScaffoldSelection.fx new file mode 100644 index 0000000000..e97f8f85f6 --- /dev/null +++ b/Effects/WulfrumScaffoldSelection.fx @@ -0,0 +1,189 @@ +float Resolution; //Pixel resolution + +float time; +float tileEdgeBlendStrenght; //How hard the border of a tile should get blended away. +float mainOpacity; +float blinkTime; + +float4 baseTintColor; //Color of the tile's overlay +float3 tileEdgeColor; //Color of the tile's edge effects +float4 scanlineColor; //Color of the scanline effects +float4 placementGlowColor; //Color of the tile when first placed + +float4 ScanLines[10]; +int ScanLinesCount; +int verticalScanLinesIndex; + +//Per tile stuff +float2 tilePosition; //The position of the top left of the tile +bool4 cardinalConnections; //Up, Left, Right, Down connections. + + +texture sampleTexture; +sampler2D Texture1Sampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; }; + +bool AND(bool4 value) +{ + return value.x && value.y && value.z && value.w; +} + +int COUNT(bool4 value) +{ + int count = 0; + + if (value.x) + count++; + if (value.y) + count++; + if (value.z) + count++; + if (value.w) + count++; + + return count; +} + +float MOD(float a, float n) +{ + return a - floor(a / n) * n; +} + +float inverselerp(float x, float start, float end) +{ + return clamp((x - start) / (end - start), 0, 1); +} + +//Checks if a corner should be drawn or excluded, based on how many edges the pixel is near to. +bool cornerDrawCheck(float2 position) +{ + float oneEight = 1 / Resolution; + float sevenEights = 7 / Resolution; + + bool4 edgeChecks = bool4(false, false, false, false); + + //top + if (position.y < oneEight && !cardinalConnections.x) + edgeChecks.x = true; + + //bottom + if (position.y >= sevenEights && !cardinalConnections.w) + edgeChecks.w = true; + + //left + if (position.x < oneEight && !cardinalConnections.y) + edgeChecks.y = true; + + //right + if (position.x >= sevenEights && !cardinalConnections.z) + edgeChecks.z = true; + + //if on 2 edges at once, youre on a corner + return COUNT(edgeChecks) < 2; +} + +//Gets the gradient from the tile outline effects +float getOpacityFromEdge(float2 position) +{ + //If fully surrounded, don't draw anything + if (AND(cardinalConnections)) + return 0; + + float oneFourth = 1 / Resolution; + float twoFourths = 3 / Resolution; + float threeFourths = 4 / Resolution; + float one = 7 / Resolution; + + float baseOpacity = 0; + + //up + if (!cardinalConnections.x) + baseOpacity += pow(inverselerp(position.y, twoFourths, 0), tileEdgeBlendStrenght); + + //down + if (!cardinalConnections.w) + baseOpacity += pow(inverselerp(position.y, threeFourths, one), tileEdgeBlendStrenght); + + //left + if (!cardinalConnections.y) + baseOpacity += pow(inverselerp(position.x, twoFourths, 0), tileEdgeBlendStrenght); + + //right + if (!cardinalConnections.z) + baseOpacity += pow(inverselerp(position.x, threeFourths, one), tileEdgeBlendStrenght); + + return baseOpacity; +} + +//Gets the opacity of the scanline on the specific pixel +float getOpacityFromScanLine(float2 position) +{ + float opacity = 0; + float4 scanline; + + //x = offset from origin, y = period, z = speed, w = opacity. + for (int i = 0; i < ScanLinesCount; i++) + { + scanline = ScanLines[i]; + + float pixelPos; + if (i >= verticalScanLinesIndex) + pixelPos = (position.x + tilePosition.x / 16) % scanline.y; + + else + pixelPos = (position.y + tilePosition.y / 16) % scanline.y; + + //Custom mod in case scanline.z is negative, aka the scanline moves in the opposite direction. + float scanlinePos = MOD((scanline.x + time * scanline.z), scanline.y); + + scanlinePos -= scanlinePos % (1 / Resolution); + + pixelPos -= pixelPos % (1 / Resolution); + + if (pixelPos == scanlinePos) + opacity += scanline.w; + } + + + return opacity * (scanlineColor.a - baseTintColor.a); +} + +float4 main(float2 uv : TEXCOORD) : COLOR +{ + //Pixelate + uv.x -= uv.x % (1 / Resolution); + uv.y -= uv.y % (1 / Resolution); + + //Don't draw the corner the case of a missing corner. + if (!cornerDrawCheck(uv)) + return float4(0, 0, 0, 0); + + + float3 ColorTotal = lerp(baseTintColor.rgb, placementGlowColor.rgb, blinkTime); + float OpacityTotal = lerp(baseTintColor.a, placementGlowColor.a, blinkTime); + + //Do the outlines + float tileEdgeBlend = getOpacityFromEdge(uv); + OpacityTotal = lerp(OpacityTotal, 1, tileEdgeBlend); + ColorTotal = lerp(ColorTotal, tileEdgeColor, tileEdgeBlend); + + float scanlineOpacity = getOpacityFromScanLine(uv); + if (scanlineOpacity > 0) + { + OpacityTotal += scanlineOpacity; + ColorTotal = lerp(ColorTotal, scanlineColor.rgb, scanlineOpacity); + } + + //General fade out + OpacityTotal *= mainOpacity; + + ColorTotal = ColorTotal * OpacityTotal; + return float4(ColorTotal, OpacityTotal); +} + +technique Technique1 +{ + pass TileSelectPass + { + PixelShader = compile ps_3_0 main(); + } +} \ No newline at end of file diff --git a/Effects/WulfrumScaffoldSelection.xnb b/Effects/WulfrumScaffoldSelection.xnb new file mode 100644 index 0000000000..61ac0a7311 Binary files /dev/null and b/Effects/WulfrumScaffoldSelection.xnb differ diff --git a/Effects/WulfrumTilePing.fx b/Effects/WulfrumTilePing.fx new file mode 100644 index 0000000000..fc44e3ecc8 --- /dev/null +++ b/Effects/WulfrumTilePing.fx @@ -0,0 +1,212 @@ +float Resolution; //Pixel resolution + +float time; +float2 pingCenter; //The origin of the ping wave. +float pingRadius; //The max radius of the ping. +float pingWaveThickness; //The thickness of the wave before it entirely fades out. +float pingProgress; //How far along the ping progressed +float pingTravelTime; //Percent of the ping's duration during which the ping expands to reach its full radius. +float pingFadePoint; //Percent of the ping's duration at which to start fading away. +float edgeBlendStrength; //How starkly should the ping's edge fade off. +float edgeBlendOutLenght; //Small lenght at the edge of the wave to blend away smoothly. +float tileEdgeBlendStrenght; //How hard the border of a tile should get blended away. + +float4 baseTintColor; //Color of the tile's overlay +float3 tileEdgeColor; //Color of the tile's edge effects +float4 scanlineColor; //Color of the scanline effects +float4 waveColor; //Color of the ping wave + +float4 ScanLines[10]; +int ScanLinesCount; +int verticalScanLinesIndex; + +//Per tile stuff +float2 tilePosition; //The position of the top left of the tile +bool4 cardinalConnections; //Up, Left, Right, Down connections. + + +texture sampleTexture; +sampler2D Texture1Sampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = wrap; AddressV = wrap; }; + +bool AND(bool4 value) +{ + return value.x && value.y && value.z && value.w; +} + +int COUNT(bool4 value) +{ + int count = 0; + + if (value.x) + count++; + if (value.y) + count++; + if (value.z) + count++; + if (value.w) + count++; + + return count; +} + +float MOD(float a, float n) +{ + return a - floor(a / n) * n; +} + +float inverselerp(float x, float start, float end) +{ + return clamp((x - start) / (end - start), 0, 1); +} + +//Checks if a corner should be drawn or excluded, based on how many edges the pixel is near to. +bool cornerDrawCheck(float2 position) +{ + float oneEight = 1 / Resolution; + float sevenEights = 7 / Resolution; + + bool4 edgeChecks = bool4(false, false, false, false); + + //top + if (position.y < oneEight && !cardinalConnections.x) + edgeChecks.x = true; + + //bottom + if (position.y >= sevenEights && !cardinalConnections.w) + edgeChecks.w = true; + + //left + if (position.x < oneEight && !cardinalConnections.y) + edgeChecks.y = true; + + //right + if (position.x >= sevenEights && !cardinalConnections.z) + edgeChecks.z = true; + + //if on 2 edges at once, youre on a corner + return COUNT(edgeChecks) < 2; +} + +//Gets the gradient from the tile outline effects +float getOpacityFromEdge(float2 position) +{ + //If fully surrounded, don't draw anything + if (AND(cardinalConnections)) + return 0; + + float oneFourth = 1 / Resolution; + float twoFourths = 3 / Resolution; + float threeFourths = 4 / Resolution; + float one = 7 / Resolution; + + float baseOpacity = 0; + + //up + if (!cardinalConnections.x) + baseOpacity += pow(inverselerp(position.y, twoFourths, 0), tileEdgeBlendStrenght); + + //down + if (!cardinalConnections.w) + baseOpacity += pow(inverselerp(position.y, threeFourths, one), tileEdgeBlendStrenght); + + //left + if (!cardinalConnections.y) + baseOpacity += pow(inverselerp(position.x, twoFourths, 0), tileEdgeBlendStrenght); + + //right + if (!cardinalConnections.z) + baseOpacity += pow(inverselerp(position.x, threeFourths, one), tileEdgeBlendStrenght); + + return baseOpacity; +} + +//Gets the opacity of the scanline on the specific pixel +float getOpacityFromScanLine(float2 position) +{ + float opacity = 0; + float4 scanline; + + //x = offset from origin, y = period, z = speed, w = opacity. + for (int i = 0; i < ScanLinesCount; i++) + { + scanline = ScanLines[i]; + + float pixelPos; + if (i >= verticalScanLinesIndex) + pixelPos = (position.x + tilePosition.x / 16) % scanline.y; + + else + pixelPos = (position.y + tilePosition.y / 16) % scanline.y; + + //Custom mod in case scanline.z is negative, aka the scanline moves in the opposite direction. + float scanlinePos = MOD((scanline.x + time * scanline.z), scanline.y); + + scanlinePos -= scanlinePos % (1 / Resolution); + + pixelPos -= pixelPos % (1 / Resolution); + + if (pixelPos == scanlinePos) + opacity += scanline.w; + } + + + return opacity * (scanlineColor.a - baseTintColor.a); +} + +float4 main(float2 uv : TEXCOORD) : COLOR +{ + //Pixelate + uv.x -= uv.x % (1 / Resolution); + uv.y -= uv.y % (1 / Resolution); + + //Don't draw the corner the case of a missing corner. + if (!cornerDrawCheck(uv)) + return float4(0, 0, 0, 0); + + float distanceFromPingOrigin = length(pingCenter - (tilePosition + uv * 16)); + float waveExpansionPercent = pingProgress / pingTravelTime; + float currentPingRadius = pingRadius * waveExpansionPercent; + float realWaveExpansionPercent = min(waveExpansionPercent, 1); + float realPingRadius = pingRadius * realWaveExpansionPercent; + + + //Crop the ping wave into a circle + if (distanceFromPingOrigin > realPingRadius) + return float4(0, 0, 0, 0); + + float waveEdgeDistanceFromCenter = max(currentPingRadius - pingWaveThickness, 0); + float edgeBlendFactor = pow(min(max((distanceFromPingOrigin - (waveEdgeDistanceFromCenter)), 0) / (pingWaveThickness - edgeBlendOutLenght), 1), edgeBlendStrength); + + float3 ColorTotal = lerp(baseTintColor.rgb, waveColor.rgb, edgeBlendFactor); + float OpacityTotal = lerp(baseTintColor.a, waveColor.a, edgeBlendFactor); + + //Do the outlines + float tileEdgeBlend = getOpacityFromEdge(uv); + OpacityTotal = lerp(OpacityTotal, 1, tileEdgeBlend); + ColorTotal = lerp(ColorTotal, tileEdgeColor, tileEdgeBlend); + + float scanlineOpacity = getOpacityFromScanLine(uv); + if (scanlineOpacity > 0) + { + OpacityTotal += scanlineOpacity; + ColorTotal = lerp(ColorTotal, scanlineColor.rgb, scanlineOpacity); + } + + //Fade away the border + if (realPingRadius - distanceFromPingOrigin < edgeBlendOutLenght) + OpacityTotal *= (realPingRadius - distanceFromPingOrigin) / edgeBlendOutLenght; + + //General fade out at the end. + OpacityTotal *= 1 - max(pingProgress - pingFadePoint, 0) / (1 - pingFadePoint); + + ColorTotal = ColorTotal * OpacityTotal; + return float4(ColorTotal, OpacityTotal); +} + +technique Technique1 +{ + pass TilePingPass + { + PixelShader = compile ps_3_0 main(); + } +} \ No newline at end of file diff --git a/Effects/WulfrumTilePing.xnb b/Effects/WulfrumTilePing.xnb new file mode 100644 index 0000000000..62b423ebaf Binary files /dev/null and b/Effects/WulfrumTilePing.xnb differ diff --git a/ExtraTextures/BasicTrail.png b/ExtraTextures/BasicTrail.png new file mode 100644 index 0000000000..f2cc0db10f Binary files /dev/null and b/ExtraTextures/BasicTrail.png differ diff --git a/ExtraTextures/DoubleTrail.png b/ExtraTextures/DoubleTrail.png new file mode 100644 index 0000000000..00770c92db Binary files /dev/null and b/ExtraTextures/DoubleTrail.png differ diff --git a/ExtraTextures/MediumLongThrust.png b/ExtraTextures/MediumLongThrust.png new file mode 100644 index 0000000000..ecae43f936 Binary files /dev/null and b/ExtraTextures/MediumLongThrust.png differ diff --git a/ExtraTextures/TechyNoise.png b/ExtraTextures/TechyNoise.png new file mode 100644 index 0000000000..ea7775cb9d Binary files /dev/null and b/ExtraTextures/TechyNoise.png differ diff --git a/ExtraTextures/ZapTrail.png b/ExtraTextures/ZapTrail.png new file mode 100644 index 0000000000..7397f1a4c4 Binary files /dev/null and b/ExtraTextures/ZapTrail.png differ diff --git a/Gores/WulfrumPinger1.png b/Gores/WulfrumPinger1.png new file mode 100644 index 0000000000..07f24ee202 Binary files /dev/null and b/Gores/WulfrumPinger1.png differ diff --git a/Gores/WulfrumPinger2.png b/Gores/WulfrumPinger2.png new file mode 100644 index 0000000000..f28048d437 Binary files /dev/null and b/Gores/WulfrumPinger2.png differ diff --git a/Gores/WulfrumPinger3.png b/Gores/WulfrumPinger3.png new file mode 100644 index 0000000000..c4ad75ae90 Binary files /dev/null and b/Gores/WulfrumPinger3.png differ diff --git a/Gores/WulfrumPinger4.png b/Gores/WulfrumPinger4.png new file mode 100644 index 0000000000..7226f0e705 Binary files /dev/null and b/Gores/WulfrumPinger4.png differ diff --git a/Gores/WulfrumPowerSuit1.png b/Gores/WulfrumPowerSuit1.png new file mode 100644 index 0000000000..dfeccdc09e Binary files /dev/null and b/Gores/WulfrumPowerSuit1.png differ diff --git a/Gores/WulfrumPowerSuit2.png b/Gores/WulfrumPowerSuit2.png new file mode 100644 index 0000000000..1d44fceb23 Binary files /dev/null and b/Gores/WulfrumPowerSuit2.png differ diff --git a/Gores/WulfrumPowerSuit3.png b/Gores/WulfrumPowerSuit3.png new file mode 100644 index 0000000000..cd20ec1934 Binary files /dev/null and b/Gores/WulfrumPowerSuit3.png differ diff --git a/Gores/WulfrumPowerSuit4.png b/Gores/WulfrumPowerSuit4.png new file mode 100644 index 0000000000..2e6319494a Binary files /dev/null and b/Gores/WulfrumPowerSuit4.png differ diff --git a/Gores/WulfrumPowerSuit5.png b/Gores/WulfrumPowerSuit5.png new file mode 100644 index 0000000000..47b6f809f0 Binary files /dev/null and b/Gores/WulfrumPowerSuit5.png differ diff --git a/Gores/WulfrumPowerSuit6.png b/Gores/WulfrumPowerSuit6.png new file mode 100644 index 0000000000..8a0c43f910 Binary files /dev/null and b/Gores/WulfrumPowerSuit6.png differ diff --git a/Gores/WulfrumPowerSuit7.png b/Gores/WulfrumPowerSuit7.png new file mode 100644 index 0000000000..75b19240bf Binary files /dev/null and b/Gores/WulfrumPowerSuit7.png differ diff --git a/Gores/WulfrumPowerSuit8.png b/Gores/WulfrumPowerSuit8.png new file mode 100644 index 0000000000..b272d74cea Binary files /dev/null and b/Gores/WulfrumPowerSuit8.png differ diff --git a/Gores/WulfrumScrewGore.png b/Gores/WulfrumScrewGore.png new file mode 100644 index 0000000000..a5d96ffcff Binary files /dev/null and b/Gores/WulfrumScrewGore.png differ diff --git a/Gores/WulfrumTurtle1.png b/Gores/WulfrumTurtle1.png new file mode 100644 index 0000000000..aa098b46aa Binary files /dev/null and b/Gores/WulfrumTurtle1.png differ diff --git a/Gores/WulfrumTurtle2.png b/Gores/WulfrumTurtle2.png new file mode 100644 index 0000000000..ea5be5e19d Binary files /dev/null and b/Gores/WulfrumTurtle2.png differ diff --git a/Gores/WulfrumTurtle3.png b/Gores/WulfrumTurtle3.png new file mode 100644 index 0000000000..cceeaeeb1b Binary files /dev/null and b/Gores/WulfrumTurtle3.png differ diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index e123db78f5..ad83ffd921 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -51,10 +51,17 @@ namespace CalamityMod.ILEditing IL.Terraria.Player.QuickMana += ConditionallyReplaceManaSickness; IL.Terraria.Player.ItemCheck_Inner += ConditionallyReplaceManaSickness; On.Terraria.Main.SortDrawCacheWorms += DrawFusableParticles; + On.Terraria.Main.DrawInfernoRings += DrawForegroundParticles; On.Terraria.Main.SetDisplayMode += ResetRenderTargetSizes; IL.Terraria.GameContent.Drawing.TileDrawing.DrawPartialLiquid += DrawCustomLava; IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += DrawCustomLava2; IL.Terraria.Main.oldDrawWater += DrawCustomLava3; + On.Terraria.GameContent.Drawing.TileDrawing.Draw += ClearTilePings; + On.Terraria.Player.GrappleMovement += CustomGrappleMovementCheck; + On.Terraria.Player.UpdatePettingAnimal += CustomGrapplePreDefaultMovement; + On.Terraria.Player.PlayerFrame += CustomGrapplePostFrame; + On.Terraria.Player.SlopeDownMovement += CustomGrapplePreStepUp; + // TODO -- Revisit this. It's not an extremely important thing, but it'd be ideal to not just abandon it. // IL.Terraria.WaterfallManager.DrawWaterfall += DrawCustomLavafalls; @@ -96,6 +103,7 @@ namespace CalamityMod.ILEditing IL.Terraria.WorldGen.Chlorophyte += AdjustChlorophyteSpawnLimits; IL.Terraria.GameContent.UI.States.UIWorldCreation.SetDefaultOptions += ChangeDefaultWorldSize; IL.Terraria.GameContent.UI.States.UIWorldCreation.AddWorldSizeOptions += SwapSmallDescriptionKey; + On.Terraria.IO.WorldFile.ClearTempTiles += ClearModdedTempTiles; // Removal of vanilla stupidity IL.Terraria.GameContent.Events.Sandstorm.HasSufficientWind += DecreaseSandstormWindSpeedRequirement; @@ -117,6 +125,13 @@ namespace CalamityMod.ILEditing IL.Terraria.NPC.NPCLoot += FixSplittingWormBannerDrops; On.Terraria.Item.Prefix += LetRogueItemsBeReforgeable; // IL.Terraria.Main.DoUpdate += FixProjectileUpdatePriorityProblems; + + + //Additional detours that are in their own item files given they are only relevant to these specific items: + + //Rover drive detours on Player.DrawInfernoRings to draw its shield + //Wulfrum armor hooks on Player.KeyDoubleTap and DrawPendingMouseText to activate its set bonus and spoof the mouse text to display the stats of the activated weapon if shift is held + //HeldOnlyItem detours Player.dropItemCheck, ItemSlot.Draw (Sb, itemarray, int, int, vector2, color) and ItemSlot.LeftClick_ItemArray to make its stuff work } /// @@ -147,6 +162,7 @@ namespace CalamityMod.ILEditing IL.Terraria.Player.QuickMana -= ConditionallyReplaceManaSickness; IL.Terraria.Player.ItemCheck_Inner -= ConditionallyReplaceManaSickness; On.Terraria.Main.SortDrawCacheWorms -= DrawFusableParticles; + On.Terraria.Main.DrawInfernoRings -= DrawForegroundParticles; On.Terraria.Main.SetDisplayMode -= ResetRenderTargetSizes; IL.Terraria.GameContent.Drawing.TileDrawing.DrawPartialLiquid -= DrawCustomLava; IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw -= DrawCustomLava2; @@ -154,6 +170,11 @@ namespace CalamityMod.ILEditing IL.Terraria.WaterfallManager.DrawWaterfall -= DrawCustomLavafalls; On.Terraria.NPC.Collision_DecideFallThroughPlatforms -= EnableCalamityBossPlatformCollision; IL.Terraria.Wiring.HitWireSingle -= AddTwinklersToStatue; + On.Terraria.GameContent.Drawing.TileDrawing.Draw -= ClearTilePings; + On.Terraria.Player.GrappleMovement -= CustomGrappleMovementCheck; + On.Terraria.Player.UpdatePettingAnimal -= CustomGrapplePreDefaultMovement; + On.Terraria.Player.PlayerFrame -= CustomGrapplePostFrame; + On.Terraria.Player.SlopeDownMovement -= CustomGrapplePreStepUp; // Damage and health balance IL.Terraria.Main.DamageVar -= AdjustDamageVariance; @@ -189,6 +210,7 @@ namespace CalamityMod.ILEditing IL.Terraria.WorldGen.Chlorophyte -= AdjustChlorophyteSpawnLimits; IL.Terraria.GameContent.UI.States.UIWorldCreation.SetDefaultOptions -= ChangeDefaultWorldSize; IL.Terraria.GameContent.UI.States.UIWorldCreation.AddWorldSizeOptions -= SwapSmallDescriptionKey; + On.Terraria.IO.WorldFile.ClearTempTiles -= ClearModdedTempTiles; // Removal of vanilla stupidity IL.Terraria.GameContent.Events.Sandstorm.HasSufficientWind -= DecreaseSandstormWindSpeedRequirement; diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index c796d86704..41ecb25148 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -14,6 +14,8 @@ using CalamityMod.Projectiles; using CalamityMod.Systems; using CalamityMod.Waters; using CalamityMod.World; +using CalamityMod.Projectiles.Typeless; +using CalamityMod.Items.Accessories; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Mono.Cecil.Cil; @@ -33,6 +35,7 @@ using Terraria.ID; using Terraria.ModLoader; using Terraria.UI.Gamepad; using Terraria.Utilities; +using Terraria.Graphics.Light; namespace CalamityMod.ILEditing { @@ -236,7 +239,7 @@ namespace CalamityMod.ILEditing { if (Main.dayTime || BossRushEvent.BossRushActive) return true; - + return orig(); } #endregion Allow Empress to Enrage in Boss Rush @@ -644,7 +647,7 @@ namespace CalamityMod.ILEditing #region General Particle Rendering private static void DrawFusableParticles(On.Terraria.Main.orig_SortDrawCacheWorms orig, Main self) { - GeneralParticleHandler.DrawAllParticles(Main.spriteBatch); + DeathAshParticle.DrawAll(); FusableParticleManager.RenderAllFusableParticles(); @@ -654,6 +657,11 @@ namespace CalamityMod.ILEditing orig(self); } + private static void DrawForegroundParticles(On.Terraria.Main.orig_DrawInfernoRings orig, Main self) + { + GeneralParticleHandler.DrawAllParticles(Main.spriteBatch); + orig(self); + } #endregion General Particle Rendering #region Custom Lava Visuals @@ -903,8 +911,8 @@ namespace CalamityMod.ILEditing c.EmitDelegate>(arr => { // resize the array and add our custom firefly - Array.Resize(ref arr, arr.Length+1); - arr[arr.Length-1] = (short)ModContent.NPCType(); + Array.Resize(ref arr, arr.Length + 1); + arr[arr.Length - 1] = (short)ModContent.NPCType(); return arr; }); @@ -916,5 +924,102 @@ namespace CalamityMod.ILEditing throw new Exception("Hook location not found, switch(*) { case 54: ..."); } #endregion Statue Additions + + #region Tile ping overlay + private static void ClearTilePings(On.Terraria.GameContent.Drawing.TileDrawing.orig_Draw orig, Terraria.GameContent.Drawing.TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets, int waterStyleOverride) + { + //Retro & Trippy light modes are fine. Just reset the cache before every time stuff gets drawn. + if (Lighting.UpdateEveryFrame) + { + //But only if its not on the non solid layer, assumedly because it draws first or something + if (!solidLayer) + TilePingerSystem.ClearTiles(); + } + + else + { + //For the white color mode, we also can simply clear all the cache at once, but this time its only on the solid layers. Don't ask me why i don't know it just works + if (Lighting.Mode == LightMode.White) + { + if (solidLayer) + TilePingerSystem.ClearTiles(); + } + + //In color mode, the tiles get cleared alternating between solid and non solid tiles + else + TilePingerSystem.ClearTiles(solidLayer); + + } + orig(self, solidLayer, forRenderTargets, intoRenderTargets, waterStyleOverride); + } + #endregion + + #region Custom Grappling hooks + + /// + /// Determines if the custom grapple movement should take place or not. Useful for hooks that only do movement tricks in some cases + /// + private static void CustomGrappleMovementCheck(On.Terraria.Player.orig_GrappleMovement orig, Player self) + { + WulfrumPackPlayer mp = self.GetModPlayer(); + + if (mp.GrappleMovementDisabled) + return; + + orig(self); + } + + /// + /// This is called right before the game decides wether or not to update the players velocity based on "real" physics (aka not tongued or hooked or with a pulley) + /// + private static void CustomGrapplePreDefaultMovement(On.Terraria.Player.orig_UpdatePettingAnimal orig, Player self) + { + orig(self); + + WulfrumPackPlayer mp = self.GetModPlayer(); + mp.hookCache = -1; + + //if tongued, dnc. + if (self.tongued) + return; + + //Cache the player's grapple and remove it temporarily (Gets re added in the modplayer's PostUpdateRunSpeeds) + if (self.grappling[0] >= 0 && mp.GrappleMovementDisabled && Main.projectile[self.grappling[0]].type == ModContent.ProjectileType()) + { + mp.hookCache = self.grappling[0]; + self.grappling[0] = -1; + } + } + + /// + /// Used before the player steps up a half tile. If we don't do that, players that are grappled but don't use hook movement won't be able to go over tiles. + /// The hook cache is reset in PreUpdateMovement + /// + private static void CustomGrapplePreStepUp(On.Terraria.Player.orig_SlopeDownMovement orig, Player self) + { + orig(self); + + WulfrumPackPlayer mp = self.GetModPlayer(); + if (self.grappling[0] >= 0 && mp.GrappleMovementDisabled && Main.projectile[self.grappling[0]].type == ModContent.ProjectileType()) + { + mp.hookCache = self.grappling[0]; + self.grappling[0] = -1; + } + } + + /// + /// This is done to put the hook if it was cacehd during the frame instruction. + /// + private static void CustomGrapplePostFrame(On.Terraria.Player.orig_PlayerFrame orig, Player self) + { + orig(self); + WulfrumPackPlayer mp = self.GetModPlayer(); + + if (mp.hookCache > -1) + self.grappling[0] = mp.hookCache; + + mp.hookCache = -1; + } + #endregion } } diff --git a/ILEditing/WorldgenILChanges.cs b/ILEditing/WorldgenILChanges.cs index 1ae35d7587..78678e8139 100644 --- a/ILEditing/WorldgenILChanges.cs +++ b/ILEditing/WorldgenILChanges.cs @@ -7,6 +7,8 @@ using Terraria; using Terraria.GameContent.UI.States; using Terraria.ID; using Terraria.WorldBuilding; +using CalamityMod.Systems; +using System.Linq; namespace CalamityMod.ILEditing { @@ -206,5 +208,21 @@ namespace CalamityMod.ILEditing c.Emit(OpCodes.Ldstr, "Mods.CalamityMod.UI.SmallWorldWarning"); } #endregion + + #region Clear temporary modded tiles + private static void ClearModdedTempTiles(On.Terraria.IO.WorldFile.orig_ClearTempTiles orig) + { + orig(); + + for (int i = 0; i < Main.maxTilesX; i++) + { + for (int j = 0; j < Main.maxTilesY; j++) + { + if (TempTilesManagerSystem.TemporaryTileIDs.Contains(Main.tile[i, j].TileType)) + WorldGen.KillTile(i, j); + } + } + } + #endregion } } diff --git a/Items/Accessories/RoverDrive.cs b/Items/Accessories/RoverDrive.cs index 7672596263..f8c3411b4d 100644 --- a/Items/Accessories/RoverDrive.cs +++ b/Items/Accessories/RoverDrive.cs @@ -2,18 +2,117 @@ using Terraria; using Terraria.ModLoader; using Terraria.ID; +using CalamityMod.Cooldowns; +using CalamityMod.Items.Materials; +using Terraria.Audio; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria.Graphics.Shaders; +using Terraria.Graphics.Effects; +using System; +using CalamityMod.Particles; +using ReLogic.Content; namespace CalamityMod.Items.Accessories { public class RoverDrive : ModItem { + public static readonly SoundStyle ShieldHurtSound = new("CalamityMod/Sounds/Custom/RoverDriveHit") { PitchVariance = 0.6f, Volume = 0.6f, MaxInstances = 0 }; + public static readonly SoundStyle ActivationSound = new("CalamityMod/Sounds/Custom/RoverDriveActivate") { Volume = 0.85f }; + public static readonly SoundStyle BreakSound = new("CalamityMod/Sounds/Custom/RoverDriveBreak") { Volume = 0.75f }; + + public static int ProtectionMatrixDurabilityMax = 50; + public static int ProtectionMatrixRechargeTime = 60 * 10; + public static int ProtectionMatrixDefenseBoost = 10; + + public static Asset NoiseTex; + + + public override void Load() + { + On.Terraria.Main.DrawInfernoRings += DrawRoverDriveShields; + } + public override void Unload() + { + On.Terraria.Main.DrawInfernoRings -= DrawRoverDriveShields; + } + + + private void DrawRoverDriveShields(On.Terraria.Main.orig_DrawInfernoRings orig, Main self) + { + bool playerFound = false; + + for (int i = 0; i < 255; i++) + { + if (!Main.player[i].active || Main.player[i].outOfRange || Main.player[i].dead) + continue; + + if (Main.player[i].GetModPlayer().ProtectionMatrixDurability <= 0) + continue; + + float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + i * 0.2f)); + + if (playerFound == false) + { + float noiseScale = MathHelper.Lerp(0.4f, 0.8f, (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.3f) * 0.5f + 0.5f); + + Effect shieldEffect = Filters.Scene["RoverDriveShield"].GetShader().Shader; + shieldEffect.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly * 0.24f); + shieldEffect.Parameters["blowUpPower"].SetValue(2.5f); + shieldEffect.Parameters["blowUpSize"].SetValue(0.5f); + shieldEffect.Parameters["noiseScale"].SetValue(noiseScale); + //shieldEffect.Parameters["resolution"].SetValue(resolution); + + float baseShieldOpacity = 0.9f + 0.1f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 2f); + shieldEffect.Parameters["shieldOpacity"].SetValue(baseShieldOpacity * (0.5f + 0.5f * (float)Math.Pow(Main.LocalPlayer.GetModPlayer().ProtectionMatrixDurability / (float)ProtectionMatrixDurabilityMax, 0.5f))); + shieldEffect.Parameters["shieldEdgeBlendStrenght"].SetValue(4f); + + Color blueTint = new Color(51, 102, 255); + Color cyanTint = new Color(71, 202, 255); + Color wulfGreen = new Color(194, 255, 67) * 0.8f; + Color edgeColor = CalamityUtils.MulticolorLerp(Main.GlobalTimeWrappedHourly * 0.2f, blueTint, cyanTint, wulfGreen); + shieldEffect.Parameters["shieldColor"].SetValue(blueTint.ToVector3()); + shieldEffect.Parameters["shieldEdgeColor"].SetValue(edgeColor.ToVector3()); + + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, shieldEffect, Main.GameViewMatrix.TransformationMatrix); + + } + + + + playerFound = true; + Player myPlayer = Main.player[i]; + if (NoiseTex == null) + NoiseTex = ModContent.Request("CalamityMod/ExtraTextures/TechyNoise"); + + Texture2D tex = NoiseTex.Value; + Vector2 pos = myPlayer.MountedCenter + myPlayer.gfxOffY * Vector2.UnitY - Main.screenPosition; + + Main.spriteBatch.Draw(tex, pos, null, Color.White, 0, tex.Size() / 2f, scale, 0, 0); + } + + if (playerFound) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.Transform); + } + + orig(self); + } + + public override void SetStaticDefaults() { SacrificeTotal = 1; DisplayName.SetDefault("Rover Drive"); - Tooltip.SetDefault("Activates a protective shield that grants 15 defense for 10 seconds\n" + - //Actually 10.1 seconds at full power with a dissipation across 0.1666 seconds but whatever - "The shield then dissipates and recharges for 20 seconds before being reactivated"); + Tooltip.SetDefault($"Activates a protective matrix that can absorb {ProtectionMatrixDurabilityMax} damage and grants {ProtectionMatrixDefenseBoost} defense\n" + + $"However, the systems are fickle and the shield will need {ProtectionMatrixRechargeTime / 60} seconds to charge up fully\n" + + "Getting hit during the shield recharge period will reset it back to zero\n" + + "Can also be scrapped at an extractinator"); + + ItemID.Sets.ExtractinatorMode[Item.type] = Item.type; } public override void SetDefaults() @@ -23,12 +122,130 @@ namespace CalamityMod.Items.Accessories Item.value = CalamityGlobalItem.Rarity1BuyPrice; Item.rare = ItemRarityID.Blue; Item.accessory = true; + + //Needed for extractination + Item.useStyle = ItemUseStyleID.HiddenAnimation; + Item.useAnimation = 10; + Item.useTime = 2; + Item.consumable = true; } public override void UpdateAccessory(Player player, bool hideVisual) { - CalamityPlayer modPlayer = player.Calamity(); - modPlayer.roverDrive = true; + RoverDrivePlayer modPlayer = player.GetModPlayer(); + //modPlayer.roverDrive = true; + + modPlayer.RoverDriveOn = true; + if (modPlayer.ProtectionMatrixDurability > 0) + player.statDefense += ProtectionMatrixDefenseBoost; + } + + //Scrappable for 3-6 wulfrum scrap or a 20% chance to get an energy core + public override void ExtractinatorUse(ref int resultType, ref int resultStack) + { + resultType = ModContent.ItemType(); + resultStack = Main.rand.Next(3, 6); + + if (Main.rand.NextFloat() > 0.8f) + { + resultStack = 1; + resultType = ModContent.ItemType(); + } + } + } + + public class RoverDrivePlayer : ModPlayer + { + public bool RoverDriveOn; + public int ProtectionMatrixDurability = 0; + public int ProtectionMatrixCharge = 0; + + public override void ResetEffects() + { + //Turn this into armor health when we can + if (RoverDriveOn) + Player.statLifeMax2 += ProtectionMatrixDurability; + + else + ProtectionMatrixDurability = 0; + + RoverDriveOn = false; + } + + public override void PostHurt(bool pvp, bool quiet, double damage, int hitDirection, bool crit) + { + if (RoverDriveOn) + { + if (ProtectionMatrixDurability > 0) + { + ProtectionMatrixDurability -= (int)damage; + if (ProtectionMatrixDurability <= 0) + { + ProtectionMatrixDurability = 0; + SoundEngine.PlaySound(RoverDrive.BreakSound, Player.Center); + Player.Calamity().GeneralScreenShakePower += 2f; + } + + int numParticles = Main.rand.Next(2, 6); + for (int i = 0; i < numParticles; i++) + { + Vector2 velocity = Main.rand.NextVector2CircularEdge(1f, 1f) * Main.rand.NextFloat(3, 14); + velocity.X += 5f * hitDirection; + GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(Player.Center, velocity, Main.rand.NextFloat(2.5f, 3f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25)); + } + } + + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveDurability.ID, out var cdDurability)) + { + cdDurability.timeLeft = ProtectionMatrixDurability; + } + + + //Reset recharge time. + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveRecharge.ID, out var cd)) + { + cd.timeLeft = RoverDrive.ProtectionMatrixRechargeTime; + } + } + } + + public override void UpdateDead() + { + ProtectionMatrixDurability = 0; + } + + + public override void PostUpdateMiscEffects() + { + if (!RoverDriveOn) + { + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveDurability.ID, out var cdDurability) && !RoverDriveOn) + cdDurability.timeLeft = 0; + + if (Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveRecharge.ID, out var cdRecharge) && !RoverDriveOn) + cdRecharge.timeLeft = 0; + } + + else + { + if (ProtectionMatrixDurability == 0 && !Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveRecharge.ID, out var cd)) + { + Player.AddCooldown(WulfrumRoverDriveRecharge.ID, RoverDrive.ProtectionMatrixRechargeTime); + } + + if (ProtectionMatrixDurability > 0 && !Player.Calamity().cooldowns.TryGetValue(WulfrumRoverDriveDurability.ID, out cd)) + { + CooldownInstance durabilityCooldown = Player.AddCooldown(WulfrumRoverDriveDurability.ID, RoverDrive.ProtectionMatrixDurabilityMax); + durabilityCooldown.timeLeft = ProtectionMatrixDurability; + + SoundEngine.PlaySound(RoverDrive.ActivationSound, Player.Center); + } + + if (ProtectionMatrixDurability > 0) + { + Lighting.AddLight(Player.Center, Color.DeepSkyBlue.ToVector3() * 0.2f); + } + } } } } diff --git a/Items/Accessories/Vanity/AbandonedWulfrumHelmet.cs b/Items/Accessories/Vanity/AbandonedWulfrumHelmet.cs new file mode 100644 index 0000000000..535cc44168 --- /dev/null +++ b/Items/Accessories/Vanity/AbandonedWulfrumHelmet.cs @@ -0,0 +1,111 @@ +using CalamityMod.CalPlayer; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.Audio; + +namespace CalamityMod.Items.Accessories.Vanity +{ + [AutoloadEquip(EquipType.Head)] + + //A lot of legacy names that's for sure. A combo of the pre "WulfrumHeadX" names, and the aforementionned "WulfrumHeadX" names. + //This is done so that non summoners don't end up with a helmet they don't really care about anyways, and is a cute reference to the old look. + [LegacyName("WulfrumMask")] + [LegacyName("WulfrumHeadRogue")] + [LegacyName("WulfrumHeadgear")] + [LegacyName("WulfrumHeadRanged")] + [LegacyName("WulfrumHelm")] + [LegacyName("WulfrumHeadMelee")] + [LegacyName("WulfrumHood")] + [LegacyName("WulfrumHeadMagic")] + public class AbandonedWulfrumHelmet : ModItem + { + public override void Load() + { + if (Main.netMode != NetmodeID.Server) + { + EquipLoader.AddEquipTexture(Mod, "CalamityMod/Items/Accessories/Vanity/AbandonedWulfrumHelmet_HeadSet", EquipType.Head, name: "WulfrumOldSetHead"); + EquipLoader.AddEquipTexture(Mod, "CalamityMod/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Body", EquipType.Body, this); + EquipLoader.AddEquipTexture(Mod, "CalamityMod/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Legs", EquipType.Legs, this); + } + } + + public override void SetStaticDefaults() + { + SacrificeTotal = 1; + DisplayName.SetDefault("Abandoned Wulfrum Helmet"); + Tooltip.SetDefault("A worn and rusty helmet ressembling older models of wulfrum armor\n" + + //Could include lore about how X kind of people used to wear it. Like "Streets used to be filled with people of The Resistance wearing this cheap yet effective armor. + "Transforms the holder into a wulfrum robot\n" + + "Can also be worn in the helmet slot as a regular helm"); + + if (Main.netMode == NetmodeID.Server) + return; + + int equipSlotHead = EquipLoader.GetEquipSlot(Mod, "WulfrumOldSetHead", EquipType.Head); + ArmorIDs.Head.Sets.DrawHead[equipSlotHead] = false; + + int equipSlotBody = EquipLoader.GetEquipSlot(Mod, Name, EquipType.Body); + ArmorIDs.Body.Sets.HidesTopSkin[equipSlotBody] = true; + ArmorIDs.Body.Sets.HidesArms[equipSlotBody] = true; + + int equipSlotLegs = EquipLoader.GetEquipSlot(Mod, Name, EquipType.Legs); + ArmorIDs.Legs.Sets.HidesBottomSkin[equipSlotLegs] = true; + } + + public override void SetDefaults() + { + Item.width = 26; + Item.height = 30; + Item.accessory = true; + Item.value = CalamityGlobalItem.Rarity1BuyPrice; + Item.rare = ItemRarityID.Green; + Item.vanity = true; + } + + public override void UpdateVanity(Player player) + { + player.GetModPlayer().transformationActive = true; + player.GetModPlayer().vanityEquipped = true; + } + + public override void UpdateAccessory(Player player, bool hideVisual) + { + if (!hideVisual) + { + player.GetModPlayer().transformationActive = true; + player.GetModPlayer().vanityEquipped = true; + } + } + } + + public class WulfrumTransformationPlayer : ModPlayer + { + public bool vanityEquipped = false; + public bool transformationActive = false; + public bool forceHelmetOn = false; + + public override void ResetEffects() + { + vanityEquipped = false; + transformationActive = false; + forceHelmetOn = false; + } + + public override void FrameEffects() + { + if (forceHelmetOn || transformationActive) + { + Player.head = EquipLoader.GetEquipSlot(Mod, "WulfrumOldSetHead", EquipType.Head); + Player.face = -1; + } + + if (transformationActive) + { + Player.legs = EquipLoader.GetEquipSlot(Mod, "AbandonedWulfrumHelmet", EquipType.Legs); + Player.body = EquipLoader.GetEquipSlot(Mod, "AbandonedWulfrumHelmet", EquipType.Body); + } + } + } +} diff --git a/Items/Accessories/Vanity/AbandonedWulfrumHelmet.png b/Items/Accessories/Vanity/AbandonedWulfrumHelmet.png new file mode 100644 index 0000000000..35e1b18178 Binary files /dev/null and b/Items/Accessories/Vanity/AbandonedWulfrumHelmet.png differ diff --git a/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Body.png b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Body.png new file mode 100644 index 0000000000..a03c783ea9 Binary files /dev/null and b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Body.png differ diff --git a/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Head.png b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Head.png new file mode 100644 index 0000000000..e6ad485960 Binary files /dev/null and b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Head.png differ diff --git a/Items/Accessories/Vanity/AbandonedWulfrumHelmet_HeadSet.png b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_HeadSet.png new file mode 100644 index 0000000000..ecafe90f05 Binary files /dev/null and b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_HeadSet.png differ diff --git a/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Legs.png b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Legs.png new file mode 100644 index 0000000000..8583861f46 Binary files /dev/null and b/Items/Accessories/Vanity/AbandonedWulfrumHelmet_Legs.png differ diff --git a/Items/Accessories/WulfrumAcrobaticsPack.cs b/Items/Accessories/WulfrumAcrobaticsPack.cs new file mode 100644 index 0000000000..db3672c5ad --- /dev/null +++ b/Items/Accessories/WulfrumAcrobaticsPack.cs @@ -0,0 +1,496 @@ +using Terraria; +using Terraria.ModLoader; +using Terraria.ID; +using Terraria.GameInput; +using Terraria.DataStructures; +using CalamityMod.Projectiles.Typeless; +using static Terraria.ModLoader.ModContent; +using System.Linq; +using Microsoft.Xna.Framework; +using CalamityMod.DataStructures; +using System.Collections.Generic; +using System; +using System.Linq; +using CalamityMod.Items.Materials; +using Terraria.Audio; +using CalamityMod.Sounds; + +namespace CalamityMod.Items.Accessories +{ + [AutoloadEquip(EquipType.Back)] + public class WulfrumAcrobaticsPack : ModItem + { + public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Custom/WulfrumHookShoot") { Volume = 0.7f, MaxInstances = 1, SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest}; + public static readonly SoundStyle GrabSound = new("CalamityMod/Sounds/Custom/WulfrumHookGrapple") { Volume = 0.7f, MaxInstances = 1, SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest }; + public static readonly SoundStyle ReleaseSound = new("CalamityMod/Sounds/Custom/WulfrumHookDisengage") { Volume = 0.7f, MaxInstances = 1, SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest }; + + + public override void SetStaticDefaults() + { + SacrificeTotal = 1; + DisplayName.SetDefault("Wulfrum Acrobatics Pack"); + Tooltip.SetDefault("This mess of cogs and wires in a box retools the winch mechanism of hooks to transform them into a wulfrum slingshot\n" + + "The wulfrum slingshot trades the ability to reel you back in for advanced rope physics, letting you swing around the hook as you please\n" + + "Additionally, the pack automatically attempts to grapple to the floor in case it detects imminent fall damage\n" + + "This safety feature won't activate if the down key is being held\n" + + "8% increased movement speed"); + } + + public override void SetDefaults() + { + Item.width = 20; + Item.height = 22; + Item.value = Item.buyPrice(0, 1, 0, 0); + Item.accessory = true; + Item.rare = ItemRarityID.Blue; + } + + public override void UpdateAccessory(Player player, bool hideVisual) + { + player.moveSpeed += 0.08f; + player.GetModPlayer().WulfrumPackEquipped = true; + player.GetModPlayer().PackItem = Item; + + Lighting.AddLight(player.Center, Color.Lerp(Color.DeepSkyBlue,Color.GreenYellow, (float)Math.Sin( Main.GlobalTimeWrappedHourly * 2f) * 0.5f + 0.5f).ToVector3()); + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(ItemID.Chain, 2). + AddIngredient(6). + AddIngredient(1). + AddTile(TileID.Anvils). + Register(); + } + } + + public class WulfrumPackProjectile : GlobalProjectile + { + public override bool? CanUseGrapple(int type, Player player) + { + //Player can shoot up to 2 wulfrum hooks, but only 2 is allowed to stay grappled. + if (player.GetModPlayer().WulfrumPackEquipped) + { + if (Main.projectile.Count(n => n.active && n.owner == player.whoAmI && n.type == ProjectileType()) > 1) + return false; + } + + //This should never happen. This is for the case in which the player shoots a hook without having the wulfrum pack equipped but somehow having a wulfrum hook out. + //Under no real circumstances should this happen, given wulfrum hooks instantly get killed if the player doesn't have the wulfrum pack. + else if (Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ProjectileType())) + return false; + + return base.CanUseGrapple(type, player); + } + + //Prevent players with a wulfrum pack to spawn any non-wulfrum hooks. + public override void OnSpawn(Projectile projectile, IEntitySource source) + { + Player owner = Main.player[projectile.owner]; + if (projectile.aiStyle == 7 && projectile.type != ProjectileType() && owner.GetModPlayer().WulfrumPackEquipped) + { + projectile.active = false; + } + } + } + + public class WulfrumPackPlayer : ModPlayer + { + public bool WulfrumPackEquipped = false; + public Item PackItem = null; + public bool AutoGrappleActivated + { + get + { + if (!WulfrumPackEquipped || Grappled || //Ignore if player isnt wearing the grapple pack, or is already grappled. + Player.noFallDmg || Player.equippedWings != null || //Ignore if player can't take fall damage + Player.controlDown || //Ignore if player disables the auto grapple by holding down + Player.velocity.Y * Player.gravDir < 0 || //Ignore if not falling *down* + (Player.fallStart >= (int)(Player.position.Y / 16f) && Player.gravDir > 0) || (!(Player.fallStart <= (int)(Player.position.Y / 16f)) && Player.gravDir < 0) || //Ignore if the player is not falling below their last fall point + Player.mount.Active || //ignore if player is on a mount + Player.webbed || Player.stoned || Player.frozen || Player.vortexDebuff //Ignore if players movement is compromised + ) + return false; + + return true; + } + } + /// + /// The index of the grapple projectile currently grappled. + /// + public int Grapple = 0; + /// + /// The lenght of the current rope. Determined when the grapple lands. + /// + public float SwingLenght = 0f; + /// + /// Used when we need to store the hook between instructions. + /// + public int hookCache = -1; + /// + /// Is the player grappled? + /// + public bool Grappled => WulfrumPackEquipped && Main.projectile[Grapple].active && Main.projectile[Grapple].ModProjectile is WulfrumHook hook && hook.State == WulfrumHook.HookState.Grappling; + public bool GrappleMovementDisabled + { + get + { + if (!Grappled) + return false; + + if (!PlayerOnGround) + return false; + + if ((Player.Center - Main.projectile[Grapple].Center).Length() > SwingLenght) + return false; + + return true; + } + } + + public Vector2 CurrentPosition; + public Vector2 OldPosition; + public List Segments; + + public static int SimulationResolution = 3; + public static int HookUpdates = 3; + public static float GrappleVelocity = 17f; + public static float ReturnVelocity = 5f; + public static float MaxHopVelocity = 4f; //The maximum velocity at which the player gets any amount of vertical boost from hopping out of the hook + public static int SafetySteps = 3; + public static float SafetyHookAngle = MathHelper.PiOver2 * 1.2f; + public static float SafetyHookAngleResolution = 50f; + + public bool PlayerOnGround => Collision.SolidCollision(Player.position + Vector2.UnitY* 2f * Player.gravDir, Player.width, Player.height, false); + + public override void ResetEffects() + { + WulfrumPackEquipped = false; + PackItem = null; + } + + //Initialize the segments between the player and the hook's end point. + public void SetSegments(Vector2 endPoint) + { + if (Segments == null) + Segments = new List(); + + Segments.Clear(); + + for (int i = 0; i <= SimulationResolution; i++) + { + float progress = i / (float)SimulationResolution; + VerletSimulatedSegment segment = new VerletSimulatedSegment(Vector2.Lerp(endPoint, Player.Center, progress)); + if (i == 0) + segment.locked = true; + + if (i == SimulationResolution) + segment.oldPosition = Player.oldPosition + new Vector2(Player.width, Player.height) * 0.5f; + + Segments.Add(segment); + } + } + + public override void PostUpdateRunSpeeds() + { + if (hookCache != -1) + Player.grappling[0] = hookCache; + + hookCache = -1; + } + + public override void PreUpdateMovement() + { + //If the hook cache was set from -1 in the part before the player stepped up,reset it. + //Should this be detoured before the PlayerLoaders PreUpdateMovement call? In case another mod uses hooks in this call and their modplayer gets called before this one? + if (hookCache > -1) + Player.grappling[0] = hookCache; + hookCache = -1; + + if (Grappled) + { + if ((Main.projectile[Grapple].Center - Player.Center).Length() > SwingLenght + 80f) + { + SoundEngine.PlaySound(WulfrumAcrobaticsPack.ReleaseSound, Main.projectile[Grapple].Center); + Main.projectile[Grapple].Kill(); + } + else + SimulateMovement(Main.projectile[Grapple]); + } + } + + public void SimulateMovement(Projectile grapple) + { + Segments = VerletSimulatedSegment.SimpleSimulation(Segments, SwingLenght / SimulationResolution, 50, 0.3f * Player.gravDir); + + Vector2 CurrentPosition; + + foreach (VerletSimulatedSegment position in Segments) + { + CurrentPosition = position.position; + + //Control point markers + //Dust doost = Dust.NewDustPerfect(CurrentPosition, 1, Vector2.Zero); + //doost.noGravity = true; + } + + + if (!GrappleMovementDisabled) + { + CurrentPosition = Segments[SimulationResolution].position; + Player.velocity = CurrentPosition - Player.Center; + + //let the player swing themselves around if they are under the hook. + if (Player.gravDir * (Player.Center.Y - Segments[0].position.Y) > 0) + { + float swing = 0; + + if (Math.Sign(Player.velocity.X) < 0) + { + if (Player.controlLeft) + swing -= 0.1f; + + else if (Player.controlRight) + swing += 0.1f; + } + + else if (Math.Sign(Player.velocity.X) > 0) + { + if (Player.controlRight) + swing += 0.1f; + + else if (Player.controlLeft) + swing -= 0.1f; + } + + Player.velocity.X += swing; + } + + else if (Math.Abs(Player.Center.X - Segments[0].position.X) < 30f && Math.Abs(Player.velocity.X) < 1) + { + Player.velocity.X = Player.velocity.X == 0 ? 1.5f : 1.5f * Math.Sign(Player.velocity.X); + } + + } + + if (Grappled) + { + for (int i = 1; i < Segments.Count; i++) + { + Lighting.AddLight(Segments[i].position, Color.Lerp(Color.DeepSkyBlue, Color.GreenYellow, i / (float)SimulationResolution).ToVector3()); + } + } + + //Set the old position of the simulation's segments to be the players current center (before the velocity gets applied + //We can't set the new position here by simply adding the velocity to the players current position because it leads to.. funny bugs if you collide with tiles. + Segments[SimulationResolution].oldPosition = Player.Center; + } + + public override void PostUpdate() + { + //After the player's movements are finished being calculated, set the current position of the hook chain to be at their new center. + if (Grappled) + { + Segments[SimulationResolution].position = Player.Center; + + + if (!GrappleMovementDisabled) + { + //Play a swoosh sound if the player changed sides and moved fast + bool playerCrossedSides = Math.Sign(Segments[SimulationResolution].oldPosition.X - Segments[0].position.X) != Math.Sign(Segments[SimulationResolution].position.X - Segments[0].position.X); + float swingSpeed = (Segments[SimulationResolution].oldPosition - Segments[SimulationResolution].position).Length(); + if (swingSpeed > 6f && playerCrossedSides) + SoundEngine.PlaySound(CommonCalamitySounds.LouderSwingWoosh with { Volume = CommonCalamitySounds.LouderSwingWoosh.Volume * (Math.Clamp((swingSpeed - 6f) / 12f, 0, 1)) }, Player.Center); + } + } + + else if (AutoGrappleActivated) + { + Vector2 nextPlayerPosition = Player.position + Player.velocity; + Vector2 checkedPlayerPosition = Player.position; + bool imminentDanger = false; + + for (int i = 0; i < SafetySteps; i++) + { + Vector2 collisionVector = Collision.TileCollision(checkedPlayerPosition, Player.velocity, Player.width, Player.height, gravDir: (int)Player.gravDir); + if (collisionVector.Y < Player.velocity.Y) + { + imminentDanger = true; + checkedPlayerPosition += collisionVector; + break; + } + + checkedPlayerPosition += collisionVector; + } + + if (!imminentDanger) + return; + + int fallDistance = (int)(checkedPlayerPosition.Y / 16f) - Player.fallStart; + int fallDmgThreshold = 25 + Player.extraFall; + + //Technically doesn't ignore clouds but oh well. + if (fallDistance * Player.gravDir > fallDmgThreshold) + { + float halfSpread = SafetyHookAngle / 2f; + Point bestGrapplePos = Point.Zero; + float bestGrappleScore = 0; + + for (float angle = -halfSpread; angle < halfSpread; angle += SafetyHookAngle / SafetyHookAngleResolution) + { + for (int i = 0; i < (int)(WulfrumHook.MaxReach / 16f); i++ ) + { + Vector2 checkSpot = Player.Center + (-Vector2.UnitY * Player.gravDir * i * 16f).RotatedBy(angle); + Point tilePos = checkSpot.ToSafeTileCoordinates(); + Tile tile = Main.tile[tilePos]; + if (tile.HasUnactuatedTile && tile.CanTileBeLatchedOnTo() && !Player.IsBlacklistedForGrappling(tilePos)) + { + if (bestGrappleScore < EvaluatePotentialSafetyHookPos((checkSpot - Player.Center).Length(), angle)) + { + bestGrapplePos = tilePos; + bestGrappleScore = EvaluatePotentialSafetyHookPos((checkSpot - Player.Center).Length(), angle); + } + break; + } + } + } + + if (bestGrapplePos != Point.Zero) + { + //Clear any hooks that might have been flying before then. + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile p = Main.projectile[i]; + if (!p.active || p.owner != Player.whoAmI || p.type != ProjectileType()) + continue; + + if (p.ModProjectile is WulfrumHook claw) + { + SoundEngine.PlaySound(WulfrumAcrobaticsPack.ReleaseSound, p.Center); + p.Kill(); + + } + } + + //Reset the players fall height, because if they take fall dmg in teh frame right after this one it may have a chance of still killing the player due to the + //code where the grapple resets the players fall speed hasnt been called yet + Player.fallStart = (int)(Player.position.Y / 16); + + if (Player.whoAmI == Main.myPlayer) + { + Projectile.NewProjectile(Player.GetSource_ItemUse(PackItem), bestGrapplePos.ToWorldCoordinates(), Vector2.Zero, ProjectileType(), 3, 0, Player.whoAmI); + } + } + } + } + } + + public float EvaluatePotentialSafetyHookPos(float distance, float angle) + { + float score = 0.0001f; + + if (distance < 2 * WulfrumHook.MaxReach / 3f) + score += distance / (2 * WulfrumHook.MaxReach / 3f); + + else + score += 1 - (distance - (2 * WulfrumHook.MaxReach / 3f)) / (WulfrumHook.MaxReach / 3f); + + score += (1 - Math.Abs(angle) / (SafetyHookAngle / 2f)) * 0.5f; + + return score; + } + + public override void ProcessTriggers(TriggersSet triggersSet) + { + if (!WulfrumPackEquipped) + return; + + //Shoot a new hook + if (triggersSet.Grapple && Player.releaseHook) + { + //Clear any previous non-wulfrum hooks / Any hooks that just got shot (should already be handled by the global proj + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile p = Main.projectile[i]; + if (!p.active || p.owner != Player.whoAmI || p.aiStyle != 7 || p.type == ProjectileType()) + continue; + + p.Kill(); + } + + + if (Main.projectile.Count(n => n.active && n.owner == Player.whoAmI && n.type == ProjectileType()) <= 1) + { + SoundEngine.PlaySound(WulfrumAcrobaticsPack.ShootSound, Player.Center); + if (Player.whoAmI == Main.myPlayer) + { + Vector2 velocity = (Main.MouseWorld - Player.Center).SafeNormalize(Vector2.One) * GrappleVelocity; + Projectile.NewProjectile(Player.GetSource_ItemUse(PackItem), Player.Center, velocity, ProjectileType(), 0, 0, Player.whoAmI); + } + } + } + + //Jumping out of the hook + if (triggersSet.Jump && Player.releaseJump) + { + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile p = Main.projectile[i]; + if (!p.active || p.owner != Player.whoAmI || p.type != ProjectileType()) + continue; + + //Only clear hooks that are attached to stuff + if (p.ModProjectile is WulfrumHook claw && claw.State == WulfrumHook.HookState.Grappling) + { + + float angleToUpright = (Player.Center - p.Center).AngleBetween(-Vector2.UnitY); + if (angleToUpright > MathHelper.PiOver4 * 0.45f) // Don't do any jump stuff if the player is jumping from above the hook. + { + Vector2 velocityBoost = Vector2.Zero; + + //Additionally, accelerate the player a lil' if they were holding down the buttons in the direction of their swing. + if ((Math.Sign(Player.velocity.X) < 0 && Player.controlLeft) || (Math.Sign(Player.velocity.X) > 0 && Player.controlRight)) + { + velocityBoost += Player.velocity * 0.15f; + } + //Additionally^2, if the player isnt moving very fast, make them do a straight up hop. + //Don't do the hop if the player isnt moving at all though because thats handled by vanilla. + if (Player.velocity.Length() < MaxHopVelocity && Player.velocity.Length() > 0.0001f || PlayerOnGround) + { + velocityBoost -= Vector2.UnitY * Player.jumpSpeed * (1 - (float)Math.Pow(Player.velocity.Length() / MaxHopVelocity, 5f)); + } + + + Player.velocity += velocityBoost; + Player.jump = Player.jumpHeight / 2; + } + + else + { + //Prevents double jumps from getting activated + Player.releaseJump = false; + } + + SoundEngine.PlaySound(WulfrumAcrobaticsPack.ReleaseSound, p.Center); + p.Kill(); + + } + } + + } + } + + + public override void FrameEffects() + { + //Cache the hook. This is done so that the player may walk around animated if the grapple's movement is disabled. + //The cache is retrieved in the postFrame detour. + if (Player.grappling[0] >= 0 && GrappleMovementDisabled && Main.projectile[Player.grappling[0]].type == ProjectileType()) + { + hookCache = Player.grappling[0]; + Player.grappling[0] = -1; + } + } + } +} diff --git a/Items/Accessories/WulfrumAcrobaticsPack.png b/Items/Accessories/WulfrumAcrobaticsPack.png new file mode 100644 index 0000000000..8d22fe6247 Binary files /dev/null and b/Items/Accessories/WulfrumAcrobaticsPack.png differ diff --git a/Items/Accessories/WulfrumAcrobaticsPack_Back.png b/Items/Accessories/WulfrumAcrobaticsPack_Back.png new file mode 100644 index 0000000000..fb7d7e000b Binary files /dev/null and b/Items/Accessories/WulfrumAcrobaticsPack_Back.png differ diff --git a/Items/Accessories/WulfrumBattery.cs b/Items/Accessories/WulfrumBattery.cs index 565a8e90a6..134b9fb37f 100644 --- a/Items/Accessories/WulfrumBattery.cs +++ b/Items/Accessories/WulfrumBattery.cs @@ -1,16 +1,26 @@ -using Terraria; -using Terraria.ModLoader; +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; using Terraria.ID; +using Terraria.ModLoader; namespace CalamityMod.Items.Accessories { public class WulfrumBattery : ModItem { + public static readonly SoundStyle ExtraDropSound = new("CalamityMod/Sounds/Custom/WulfrumExtraDrop") { PitchVariance = 0.3f }; + public override void SetStaticDefaults() { SacrificeTotal = 1; DisplayName.SetDefault("Wulfrum Battery"); - Tooltip.SetDefault("7% increased summon damage"); + Tooltip.SetDefault( "Empowers your summons with wulfrum energy, letting them emit light around them\n" + + "7% increased summon damage\n" + + "50% chance to get an extra scrap when killing wulfrum robots\n" + + "Can also be scrapped at an extractinator"); + + ItemID.Sets.ExtractinatorMode[Item.type] = Item.type; } public override void SetDefaults() @@ -20,11 +30,63 @@ namespace CalamityMod.Items.Accessories Item.value = Item.buyPrice(0, 1, 0, 0); Item.accessory = true; Item.rare = ItemRarityID.Blue; + + //Needed for extractination + Item.useStyle = ItemUseStyleID.HiddenAnimation; + Item.useAnimation = 10; + Item.useTime = 2; + Item.consumable = true; } public override void UpdateAccessory(Player player, bool hideVisual) { player.GetDamage() += 0.07f; + player.GetModPlayer().battery = true; + } + + //Scrappable for 3-6 wulfrum scrap or a 20% chance to get an energy core + public override void ExtractinatorUse(ref int resultType, ref int resultStack) + { + resultType = ModContent.ItemType(); + resultStack = Main.rand.Next(3, 6); + + if (Main.rand.NextFloat() > 0.8f) + { + resultStack = 1; + resultType = ModContent.ItemType(); + } + } + } + + public class WulfrumBatteryPlayer : ModPlayer + { + public bool battery = false; + public override void ResetEffects() => battery = false; + public override void UpdateDead() => battery = false; + } + + public class WulfrumBatteryGlobalProjectile : GlobalProjectile + { + public override void AI(Projectile projectile) + { + if (!projectile.npcProj && !projectile.trap && projectile.minion && !ProjectileID.Sets.MinionShot[projectile.type] && Main.player[projectile.owner].GetModPlayer().battery) + { + float lightMult = 3f; + if (Lighting.UpdateEveryFrame) //The light loks wayyy too bright in retro/trippy + lightMult = 1.5f; + + Lighting.AddLight(projectile.Center, Color.DeepSkyBlue.ToVector3() * lightMult); + + + + if (Main.rand.NextBool(16)) + { + float size = (projectile.Hitbox.Size() / 2f).Length(); + + Dust zapDust = Dust.NewDustPerfect(projectile.Center + Main.rand.NextVector2Circular(1f, 1f) * size, 226, Main.rand.NextVector2Circular(1f, 1f) * Main.rand.NextFloat(1f, 2.3f)); + zapDust.noGravity = true; + } + } } } } diff --git a/Items/Armor/Wulfrum/WulfrumArmor.cs b/Items/Armor/Wulfrum/WulfrumArmor.cs deleted file mode 100644 index 89a10c8f4e..0000000000 --- a/Items/Armor/Wulfrum/WulfrumArmor.cs +++ /dev/null @@ -1,38 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Armor.Wulfrum -{ - [AutoloadEquip(EquipType.Body)] - public class WulfrumArmor : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Armor"); - Tooltip.SetDefault("3% increased critical strike chance"); - } - - public override void SetDefaults() - { - Item.width = 18; - Item.height = 18; - Item.value = Item.buyPrice(0, 0, 50, 0); - Item.rare = ItemRarityID.Blue; - Item.defense = 2; - } - - public override void UpdateEquip(Player player) => player.GetCritChance() += 3; - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(12). - AddIngredient(). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Armor/Wulfrum/WulfrumArmor.png b/Items/Armor/Wulfrum/WulfrumArmor.png deleted file mode 100644 index f99eacd3b0..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumArmor.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumArmor_Body.png b/Items/Armor/Wulfrum/WulfrumArmor_Body.png deleted file mode 100644 index 2145298e8e..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumArmor_Body.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumFusionCannon.cs b/Items/Armor/Wulfrum/WulfrumFusionCannon.cs new file mode 100644 index 0000000000..e7627b138a --- /dev/null +++ b/Items/Armor/Wulfrum/WulfrumFusionCannon.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using CalamityMod.Cooldowns; +using CalamityMod.Items.BaseItems; +using CalamityMod.Projectiles.Summon; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using static CalamityMod.CalamityUtils; + +namespace CalamityMod.Items.Armor.Wulfrum +{ + public class WulfrumFusionCannon : HeldOnlyItem, IHideFrontArm + { + public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisShoot") { PitchVariance = 0.1f, Volume = 0.4f }; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Experimental Wulfrum Fusion Array"); + Tooltip.SetDefault("Fires quick bursts of medium-range pellets\n" + + "[c/878787:\"Who needs whips when you can simply become the summon yourself?\"]"); + //Imaging hiding actually important/interesting/funny lore in there... :drool: that would be so dark souls + } + public override string Texture => "CalamityMod/Items/Armor/Wulfrum/WulfrumFusionCannon"; + + public bool noAnimation = false; + + public override void SetDefaults() + { + Item.damage = 6; + Item.DamageType = DamageClass.Summon; + Item.width = 34; + Item.height = 42; + Item.useStyle = ItemUseStyleID.Shoot; + Item.noMelee = true; + Item.knockBack = 2; + Item.rare = ItemRarityID.Green; + Item.UseSound = ShootSound; + Item.autoReuse = true; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 18f; + Item.holdStyle = 16; //Custom hold style + + Item.useAnimation = 10; + Item.useTime = 4; + Item.reuseDelay = 17; + + Item.noUseGraphic = false; + } + + public override void ModifyTooltips(List tooltips) + { + var name = tooltips.FirstOrDefault(x => x.Name == "ItemName" && x.Mod == "Terraria"); + name.OverrideColor = Color.Lerp(new Color(194, 255, 67), new Color(112, 244, 244), 0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 3f)); + } + + public override void HoldItem(Player player) + { + player.Calamity().mouseWorldListener = true; + + if (player.whoAmI == Main.myPlayer) + { + if (!WulfrumHat.HasArmorSet(player)) + { + Item.type = 0; + Item.SetDefaults(0); + Item.stack = 0; + + Main.mouseItem = new Item(); + } + } + + Item.noUseGraphic = false; + if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime) + Item.noUseGraphic = true; + + } + + public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) + { + velocity = velocity.RotatedByRandom(MathHelper.PiOver4 * 0.1f); + } + + public override bool CanUseItem(Player player) + { + return player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) && cd.timeLeft < WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime; + } + + public void SetItemInHand(Player player, Rectangle heldItemFrame) + { + //Make the player face where they're aiming. + if (player.Calamity().mouseWorld.X > player.Center.X) + { + player.ChangeDir(1); + } + else + { + player.ChangeDir(-1); + } + + //Hide the cannon till its visible on the player + if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) || cd.timeLeft > WulfrumHat.BastionCooldown + WulfrumHat.BastionTime - WulfrumHat.BastionBuildTime) + return; + + if (player.ItemTimeIsZero) + noAnimation = false; + if (player.itemAnimation > Item.useAnimation) + noAnimation = true; + + float animProgress = 1 - player.itemAnimation / (float)player.itemAnimationMax; + //It beecomes nan if the player loads into a world with the set bonus already active / without shooting any weapons before using it. + //this is because itemAnimationMax isnt set before the item gets used once. + if (noAnimation || animProgress is float.NaN) + animProgress = 1; + + //Default + Vector2 itemPosition = player.MountedCenter + new Vector2(-2f * player.direction, -1f * player.gravDir); + float itemRotation = (player.Calamity().mouseWorld - itemPosition).ToRotation(); + + //Adjust for animation + + if (animProgress < 0.9f) + itemPosition -= itemRotation.ToRotationVector2() * (1 - (float)Math.Pow(1 - (0.9f - animProgress) / 0.9f, 4)) * 3f; + + if (animProgress < 0.6f) + itemRotation += -0.3f * (float)Math.Pow((0.6f - animProgress) / 0.6f, 2) * player.direction * player.gravDir; + + //Shakezzz + itemPosition += Main.rand.NextVector2Circular(2f, 2f) * (1 - animProgress); + + + Vector2 itemSize = new Vector2(38, 18); + Vector2 itemOrigin = new Vector2(-12, 0); + CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin, true); + } + + public override void HoldStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); + public override void UseStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) => false; + } +} diff --git a/Items/Armor/Wulfrum/WulfrumFusionCannon.png b/Items/Armor/Wulfrum/WulfrumFusionCannon.png new file mode 100644 index 0000000000..c1785a678b Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumFusionCannon.png differ diff --git a/Items/Armor/Wulfrum/WulfrumHat.png b/Items/Armor/Wulfrum/WulfrumHat.png new file mode 100644 index 0000000000..0c859a18e4 Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumHat.png differ diff --git a/Items/Armor/Wulfrum/WulfrumHat_FemaleHead.png b/Items/Armor/Wulfrum/WulfrumHat_FemaleHead.png new file mode 100644 index 0000000000..d731696b3e Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumHat_FemaleHead.png differ diff --git a/Items/Armor/Wulfrum/WulfrumHat_Head.png b/Items/Armor/Wulfrum/WulfrumHat_Head.png new file mode 100644 index 0000000000..6d17c44129 Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumHat_Head.png differ diff --git a/Items/Armor/Wulfrum/WulfrumHat_HeadExtension.png b/Items/Armor/Wulfrum/WulfrumHat_HeadExtension.png new file mode 100644 index 0000000000..6c4a0a4755 Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumHat_HeadExtension.png differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadMagic.cs b/Items/Armor/Wulfrum/WulfrumHeadMagic.cs deleted file mode 100644 index 5e92722e98..0000000000 --- a/Items/Armor/Wulfrum/WulfrumHeadMagic.cs +++ /dev/null @@ -1,58 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Armor.Wulfrum -{ - [AutoloadEquip(EquipType.Head)] - [LegacyName("WulfrumHood")] - public class WulfrumHeadMagic : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Visage"); - Tooltip.SetDefault("10% increased magic damage"); - } - - public override void SetDefaults() - { - Item.width = 18; - Item.height = 18; - Item.value = Item.buyPrice(0, 0, 75, 0); - Item.rare = ItemRarityID.Blue; - Item.defense = 1; //6 - } - - public override bool IsArmorSet(Item head, Item body, Item legs) - { - return body.type == ModContent.ItemType() && legs.type == ModContent.ItemType(); - } - - public override void UpdateArmorSet(Player player) - { - player.setBonus = "+3 defense\n" + - "+5 defense when below 50% life"; - player.statDefense += 3; //9 - if (player.statLife <= player.statLifeMax2 * 0.5f) - { - player.statDefense += 5; //14 - } - } - - public override void UpdateEquip(Player player) - { - player.GetDamage() += 0.1f; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(5). - AddIngredient(). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Armor/Wulfrum/WulfrumHeadMagic.png b/Items/Armor/Wulfrum/WulfrumHeadMagic.png deleted file mode 100644 index 82655fd91e..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadMagic.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadMagic_Head.png b/Items/Armor/Wulfrum/WulfrumHeadMagic_Head.png deleted file mode 100644 index 6b273ef5e1..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadMagic_Head.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadMelee.cs b/Items/Armor/Wulfrum/WulfrumHeadMelee.cs deleted file mode 100644 index 4209a2a8f3..0000000000 --- a/Items/Armor/Wulfrum/WulfrumHeadMelee.cs +++ /dev/null @@ -1,60 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Armor.Wulfrum -{ - [AutoloadEquip(EquipType.Head)] - [LegacyName("WulfrumHelm")] - public class WulfrumHeadMelee : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Helm"); - Tooltip.SetDefault("10% increased melee damage"); - } - - public override void SetDefaults() - { - Item.width = 18; - Item.height = 18; - Item.value = Item.buyPrice(0, 0, 75, 0); - Item.rare = ItemRarityID.Blue; - Item.defense = 3; //8 - } - - public override bool IsArmorSet(Item head, Item body, Item legs) - { - return body.type == ModContent.ItemType() && legs.type == ModContent.ItemType(); - } - - public override void UpdateArmorSet(Player player) - { - player.setBonus = "Enemies are more likely to target you\n" + - "+3 defense\n" + - "+5 defense when below 50% life"; - player.statDefense += 3; //11 - if (player.statLife <= (int)(player.statLifeMax2 * 0.5)) - { - player.statDefense += 5; //16 - } - player.aggro += 100; - } - - public override void UpdateEquip(Player player) - { - player.GetDamage() += 0.1f; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(5). - AddIngredient(). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Armor/Wulfrum/WulfrumHeadMelee.png b/Items/Armor/Wulfrum/WulfrumHeadMelee.png deleted file mode 100644 index b2611d63d1..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadMelee.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadMelee_Head.png b/Items/Armor/Wulfrum/WulfrumHeadMelee_Head.png deleted file mode 100644 index 9c56efc53a..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadMelee_Head.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadRanged.cs b/Items/Armor/Wulfrum/WulfrumHeadRanged.cs deleted file mode 100644 index 2b2b43bd70..0000000000 --- a/Items/Armor/Wulfrum/WulfrumHeadRanged.cs +++ /dev/null @@ -1,58 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Armor.Wulfrum -{ - [AutoloadEquip(EquipType.Head)] - [LegacyName("WulfrumHeadgear")] - public class WulfrumHeadRanged : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Headgear"); - Tooltip.SetDefault("10% increased ranged damage"); - } - - public override void SetDefaults() - { - Item.width = 18; - Item.height = 18; - Item.value = Item.buyPrice(0, 0, 75, 0); - Item.rare = ItemRarityID.Blue; - Item.defense = 2; //7 - } - - public override bool IsArmorSet(Item head, Item body, Item legs) - { - return body.type == ModContent.ItemType() && legs.type == ModContent.ItemType(); - } - - public override void UpdateArmorSet(Player player) - { - player.setBonus = "+3 defense\n" + - "+5 defense when below 50% life"; - player.statDefense += 3; //10 - if (player.statLife <= player.statLifeMax2 * 0.5f) - { - player.statDefense += 5; //15 - } - } - - public override void UpdateEquip(Player player) - { - player.GetDamage() += 0.1f; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(5). - AddIngredient(). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Armor/Wulfrum/WulfrumHeadRanged.png b/Items/Armor/Wulfrum/WulfrumHeadRanged.png deleted file mode 100644 index e6d08596e8..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadRanged.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadRanged_Head.png b/Items/Armor/Wulfrum/WulfrumHeadRanged_Head.png deleted file mode 100644 index cf9ef4f3ac..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadRanged_Head.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadRogue.cs b/Items/Armor/Wulfrum/WulfrumHeadRogue.cs deleted file mode 100644 index dbc981bc32..0000000000 --- a/Items/Armor/Wulfrum/WulfrumHeadRogue.cs +++ /dev/null @@ -1,66 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using CalamityMod.CalPlayer; - -namespace CalamityMod.Items.Armor.Wulfrum -{ - [AutoloadEquip(EquipType.Head)] - [LegacyName("WulfrumMask")] - public class WulfrumHeadRogue : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Mask"); - Tooltip.SetDefault("10% increased rogue damage"); - } - - public override void SetDefaults() - { - Item.width = 18; - Item.height = 18; - Item.value = Item.buyPrice(0, 0, 75, 0); - Item.rare = ItemRarityID.Blue; - Item.defense = 1; //6 - } - - public override bool IsArmorSet(Item head, Item body, Item legs) - { - return body.type == ModContent.ItemType() && legs.type == ModContent.ItemType(); - } - - public override void UpdateArmorSet(Player player) - { - var modPlayer = player.Calamity(); - player.setBonus = "+3 defense\n" + - "+5 defense when below 50% life\n" + - "Rogue stealth builds while not attacking and slower while moving, up to a max of 50\n" + - "Once you have built max stealth, you will be able to perform a Stealth Strike\n" + - "Rogue stealth only reduces when you attack, it does not reduce while moving\n" + - "The higher your rogue stealth the higher your rogue damage, crit, and movement speed"; - player.statDefense += 3; //9 - if (player.statLife <= (int)(player.statLifeMax2 * 0.5)) - { - player.statDefense += 5; //14 - } - modPlayer.rogueStealthMax += 0.5f; - modPlayer.wearingRogueArmor = true; - } - - public override void UpdateEquip(Player player) - { - player.GetDamage() += 0.1f; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(5). - AddIngredient(). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Armor/Wulfrum/WulfrumHeadRogue.png b/Items/Armor/Wulfrum/WulfrumHeadRogue.png deleted file mode 100644 index 07edc75dce..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadRogue.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadRogue_Head.png b/Items/Armor/Wulfrum/WulfrumHeadRogue_Head.png deleted file mode 100644 index 56756bdf03..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadRogue_Head.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadSummon.cs b/Items/Armor/Wulfrum/WulfrumHeadSummon.cs deleted file mode 100644 index 4d9e4a1636..0000000000 --- a/Items/Armor/Wulfrum/WulfrumHeadSummon.cs +++ /dev/null @@ -1,58 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Armor.Wulfrum -{ - [AutoloadEquip(EquipType.Head)] - [LegacyName("WulfrumHelmet")] - public class WulfrumHeadSummon : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Helmet"); - Tooltip.SetDefault("10% increased minion damage"); - } - - public override void SetDefaults() - { - Item.width = 18; - Item.height = 18; - Item.value = Item.buyPrice(0, 0, 75, 0); - Item.rare = ItemRarityID.Blue; - } - - public override bool IsArmorSet(Item head, Item body, Item legs) - { - return body.type == ModContent.ItemType() && legs.type == ModContent.ItemType(); - } - - public override void UpdateArmorSet(Player player) - { - player.setBonus = "+3 defense and +1 max minion\n" + - "+5 defense when below 50% life"; - player.statDefense += 3; //8 - player.maxMinions++; - if (player.statLife <= (int)(player.statLifeMax2 * 0.5)) - { - player.statDefense += 5; //13 - } - } - - public override void UpdateEquip(Player player) - { - player.GetDamage() += 0.1f; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(5). - AddIngredient(). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Armor/Wulfrum/WulfrumHeadSummon.png b/Items/Armor/Wulfrum/WulfrumHeadSummon.png deleted file mode 100644 index e549a7c76e..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadSummon.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumHeadSummon_Head.png b/Items/Armor/Wulfrum/WulfrumHeadSummon_Head.png deleted file mode 100644 index 50ce885f3f..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumHeadSummon_Head.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumJacket.png b/Items/Armor/Wulfrum/WulfrumJacket.png new file mode 100644 index 0000000000..edb59f2d4e Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumJacket.png differ diff --git a/Items/Armor/Wulfrum/WulfrumJacket_Body.png b/Items/Armor/Wulfrum/WulfrumJacket_Body.png new file mode 100644 index 0000000000..a1bc3dbe60 Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumJacket_Body.png differ diff --git a/Items/Armor/Wulfrum/WulfrumLeggings.cs b/Items/Armor/Wulfrum/WulfrumLeggings.cs deleted file mode 100644 index 897f279f2b..0000000000 --- a/Items/Armor/Wulfrum/WulfrumLeggings.cs +++ /dev/null @@ -1,41 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Armor.Wulfrum -{ - [AutoloadEquip(EquipType.Legs)] - public class WulfrumLeggings : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Leggings"); - Tooltip.SetDefault("Movement speed increased by 5%"); - } - - public override void SetDefaults() - { - Item.width = 18; - Item.height = 18; - Item.value = Item.buyPrice(0, 0, 25, 0); - Item.rare = ItemRarityID.Blue; - Item.defense = 1; - } - - public override void UpdateEquip(Player player) - { - player.moveSpeed += 0.05f; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(8). - AddIngredient(). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Armor/Wulfrum/WulfrumLeggings.png b/Items/Armor/Wulfrum/WulfrumLeggings.png deleted file mode 100644 index ba9f776ea1..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumLeggings.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumLeggings_Legs.png b/Items/Armor/Wulfrum/WulfrumLeggings_Legs.png deleted file mode 100644 index 9b96d20767..0000000000 Binary files a/Items/Armor/Wulfrum/WulfrumLeggings_Legs.png and /dev/null differ diff --git a/Items/Armor/Wulfrum/WulfrumOveralls.png b/Items/Armor/Wulfrum/WulfrumOveralls.png new file mode 100644 index 0000000000..85d420fe10 Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumOveralls.png differ diff --git a/Items/Armor/Wulfrum/WulfrumOveralls_Legs.png b/Items/Armor/Wulfrum/WulfrumOveralls_Legs.png new file mode 100644 index 0000000000..d3785ea0cc Binary files /dev/null and b/Items/Armor/Wulfrum/WulfrumOveralls_Legs.png differ diff --git a/Items/Armor/Wulfrum/WulfrumSet.cs b/Items/Armor/Wulfrum/WulfrumSet.cs new file mode 100644 index 0000000000..db91b1b8fe --- /dev/null +++ b/Items/Armor/Wulfrum/WulfrumSet.cs @@ -0,0 +1,467 @@ +using CalamityMod.Items.Materials; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using Terraria.DataStructures; +using CalamityMod.Items.Accessories.Vanity; +using CalamityMod.Cooldowns; +using CalamityMod.Projectiles.Magic; +using Terraria.Audio; +using ReLogic.Content; +using Microsoft.Xna.Framework.Graphics; +using System.Linq; +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Magic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using static CalamityMod.CalamityUtils; +using static Terraria.ModLoader.ModContent; +using static Microsoft.Xna.Framework.Input.Keys; +using System; +using CalamityMod.Items.BaseItems; +using System.Collections.Generic; +using CalamityMod.Particles; + +namespace CalamityMod.Items.Armor.Wulfrum +{ + #region Armor pieces + + //Datsuzei / Moonstone armor from starlight river was a nice jumping off point for this kind of set. + + [AutoloadEquip(EquipType.Head)] + [LegacyName("WulfrumHelmet")] + [LegacyName("WulfrumHeadSummon")] + public class WulfrumHat : ModItem, IExtendedHat + { + #region big hat + public string ExtensionTexture => "CalamityMod/Items/Armor/Wulfrum/WulfrumHat_HeadExtension"; + public Vector2 ExtensionSpriteOffset(PlayerDrawSet drawInfo) => -Vector2.UnitY * 2f; + public string EquipSlotName(Player drawPlayer) => drawPlayer.Male ? Name : "WulfrumHatFemale"; + #endregion + + public static readonly SoundStyle SetActivationSound = new("CalamityMod/Sounds/Custom/AbilitySounds/WulfrumBastionActivate"); + public static readonly SoundStyle SetBreakSound = new("CalamityMod/Sounds/Custom/AbilitySounds/WulfrumBastionBreak"); + public static readonly SoundStyle SetBreakSoundSafe = new("CalamityMod/Sounds/Custom/AbilitySounds/WulfrumBastionBreakSafely"); + + public static int BastionBuildTime = (int)(0.55f * 60); + public static int BastionTime = 30 * 60; + public static int TimeLostPerHit = 2 * 60; + public static int BastionCooldown = 20 * 60; + + + internal static Item DummyCannon = new Item(); //Used for the attack swap. Basically we force the player to hold a fake item. + + public static bool PowerModeEngaged(Player player, out CooldownInstance cd) + { + cd = null; + bool hasWulfrumBastionCD = player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out cd); + return (hasWulfrumBastionCD && cd.timeLeft > BastionCooldown); + } + + public override void Load() + { + if (Main.netMode != NetmodeID.Server) + { + EquipLoader.AddEquipTexture(Mod, "CalamityMod/Items/Armor/Wulfrum/WulfrumHat_FemaleHead", EquipType.Head, name : "WulfrumHatFemale"); + } + + On.Terraria.Player.KeyDoubleTap += ActivateSetBonus; + On.Terraria.Main.DrawPendingMouseText += SpoofMouseItem; + } + + public override void Unload() + { + On.Terraria.Player.KeyDoubleTap -= ActivateSetBonus; + On.Terraria.Main.DrawPendingMouseText -= SpoofMouseItem; + + + DummyCannon.TurnToAir(); + DummyCannon = null; + } + + private void ActivateSetBonus(On.Terraria.Player.orig_KeyDoubleTap orig, Player player, int keyDir) + { + if (keyDir == 0 && HasArmorSet(player) && !player.mount.Active) + { + //Only activate if no cooldown & available scrap. + if (!player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out CooldownInstance cd) && player.HasItem(ModContent.ItemType())) + { + player.ConsumeItem(ModContent.ItemType()); + //I Thiiiinnnk there's no need to add mp syncing packets sicne cooldowns get auto synced right. + player.AddCooldown(WulfrumBastion.ID, BastionCooldown + BastionTime); + //Though do i need to sync that or is the player inventory auto synced? + DummyCannon.SetDefaults(ItemType()); + } + } + + orig(player, keyDir); + } + + //Replaces the tooltip of the armor set with the fusion cannon if the player holds shift + private void SpoofMouseItem(On.Terraria.Main.orig_DrawPendingMouseText orig) + { + var player = Main.LocalPlayer; + + if (DummyCannon.IsAir && !Main.gameMenu) + DummyCannon.SetDefaults(ItemType()); + + if (IsPartOfSet(Main.HoverItem) && HasArmorSet(player) && Main.keyState.IsKeyDown(LeftShift)) + { + Main.HoverItem = DummyCannon.Clone(); + Main.hoverItemName = DummyCannon.Name; + } + + orig(); + } + + + public override void SetStaticDefaults() + { + SacrificeTotal = 1; + DisplayName.SetDefault("Wulfrum Hat & Goggles"); + Tooltip.SetDefault("10% increased minion damage\n"+ + "Comes equipped with hair extensions" ); + } + public override void SetDefaults() + { + Item.width = 18; + Item.height = 18; + Item.value = Item.buyPrice(0, 0, 75, 0); + Item.rare = ItemRarityID.Blue; + } + + public override bool IsArmorSet(Item head, Item body, Item legs) => body.type == ItemType() && legs.type == ItemType(); + public static bool HasArmorSet(Player player) => player.armor[0].type == ItemType() && player.armor[1].type == ItemType() && player.armor[2].type == ItemType(); + public bool IsPartOfSet(Item item) => item.type == ItemType() || + item.type == ItemType() || + item.type == ItemType(); + + public override void UpdateArmorSet(Player player) + { + WulfrumArmorPlayer armorPlayer = player.GetModPlayer(); + WulfrumTransformationPlayer transformationPlayer = player.GetModPlayer(); + + armorPlayer.wulfrumSet = true; + + player.setBonus = "+1 max minion"; //The cooler part of the set bonus happens in modifytooltips because i can't recolor it otherwise. Madge + player.maxMinions++; + if (PowerModeEngaged(player, out var cd)) + { + if (cd.timeLeft == BastionCooldown + BastionTime) + { + ActivationEffects(player); + } + + //Can't account for previous fullbody transformations but at this point, whatever. + Item headItem = player.armor[10].type != 0 ? player.armor[10] : player.armor[0]; + bool hatVisible = !transformationPlayer.transformationActive && headItem.type == ItemType(); + + //Spawn the hat + if (cd.timeLeft == BastionCooldown + BastionTime - (int)(BastionBuildTime * 0.9f) && hatVisible) + { + Particle leftoverHat = new WulfrumHatParticle(player, -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(3f, 7f), 25); + GeneralParticleHandler.SpawnParticle(leftoverHat); + } + + if (cd.timeLeft < BastionCooldown + BastionTime - BastionBuildTime) + player.GetModPlayer().transformationActive = true; + else if (cd.timeLeft <= BastionCooldown + BastionTime - (int)(BastionBuildTime * 0.9f)) + player.GetModPlayer().forceHelmetOn = true; + + player.statDefense += 13; + //Drop the player's held item if they were holding something before + if (!(Main.mouseItem.type == DummyCannon.type) && !Main.mouseItem.IsAir) + Main.LocalPlayer.QuickSpawnClonedItem(null, Main.mouseItem, Main.mouseItem.stack); + + //Slot 58 is the "fake" slot thats used for the item the player is holding in their mouse. + Main.mouseItem = DummyCannon; + player.inventory[58] = DummyCannon; + player.selectedItem = 58; + } + + else + { + //Clear the player's hand + if (Main.mouseItem.type == ItemType()) + Main.mouseItem = new Item(); + + DummyCannon.TurnToAir(); + } + } + + public void ActivationEffects(Player player) + { + SoundEngine.PlaySound(SetActivationSound); + + //Do'nt do the effect ifthe player is already using the wulfrum vanity lol. + bool transformedAlready = player.GetModPlayer().transformationActive; + + if (!transformedAlready) + { + for (int i = 0; i < 5; i++) + { + Particle part = new WulfrumBastionPartsParticle(player, i, BastionBuildTime + 2); + GeneralParticleHandler.SpawnParticle(part); + } + } + + //Do spawn the cannon always though + Particle gun = new WulfrumBastionPartsParticle(player, 5, BastionBuildTime + 2); + + if (transformedAlready) + { + (gun as WulfrumBastionPartsParticle).TimeOffset = 0; + (gun as WulfrumBastionPartsParticle).AnimationTime = BastionBuildTime + 2; + } + GeneralParticleHandler.SpawnParticle(gun); + } + + public static void ModifySetTooltips(ModItem item, List tooltips) + { + if (HasArmorSet(Main.LocalPlayer)) + { + int setBonusIndex = tooltips.FindIndex(x => x.Name == "SetBonus" && x.Mod == "Terraria"); + + if (setBonusIndex != -1) + { + TooltipLine setBonus1 = new TooltipLine(item.Mod, "CalamityMod:SetBonus1", "Wulfrum Bastion - Double tap DOWN while dismounted to equip a heavy wulfrum armor"); + setBonus1.OverrideColor = Color.Lerp(new Color(194, 255, 67), new Color(112, 244, 244), 0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 3f)); + tooltips.Insert(setBonusIndex + 1, setBonus1); + + TooltipLine setBonus2 = new TooltipLine(item.Mod, "CalamityMod:SetBonus2", "While the power armor is active, you can only use the integrated fusion cannon, but get increased defensive stats"); + setBonus2.OverrideColor = new Color(110, 192, 93); + tooltips.Insert(setBonusIndex + 2, setBonus2); + + TooltipLine setBonus3 = new TooltipLine(item.Mod, "CalamityMod:SetBonus3", "Calling down the armor consumes one piece of wulfrum scrap, and the armor will lose durability faster when hit"); + setBonus3.OverrideColor = new Color(110, 192, 93); + tooltips.Insert(setBonusIndex + 3, setBonus3); + + if (!Main.keyState.IsKeyDown(LeftShift)) + { + TooltipLine itemDisplay = new TooltipLine(item.Mod, "CalamityMod:ArmorItemDisplay", "Hold SHIFT to see the stats of the fusion cannon"); + itemDisplay.OverrideColor = new Color(190, 190, 190); + tooltips.Add(itemDisplay); + } + } + + } + } + + public override void ModifyTooltips(List tooltips) => ModifySetTooltips(this, tooltips); + + public override void UpdateEquip(Player player) + { + player.GetDamage() += 0.1f; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(5). + AddIngredient(). + AddTile(TileID.Anvils). + Register(); + } + } + + [AutoloadEquip(EquipType.Body)] + [LegacyName("WulfrumArmor")] + public class WulfrumJacket : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 1; + DisplayName.SetDefault("Wulfrum Jacket"); + Tooltip.SetDefault("3% increased critical strike chance"); + + if (Main.netMode != NetmodeID.Server) + { + var equipSlot = EquipLoader.GetEquipSlot(Mod, Name, EquipType.Body); + ArmorIDs.Body.Sets.HidesArms[equipSlot] = true; + ArmorIDs.Body.Sets.HidesTopSkin[equipSlot] = true; + } + } + + public override void SetDefaults() + { + Item.width = 18; + Item.height = 18; + Item.value = Item.buyPrice(0, 0, 50, 0); + Item.rare = ItemRarityID.Blue; + Item.defense = 2; + } + + public override void ModifyTooltips(List tooltips) => WulfrumHat.ModifySetTooltips(this, tooltips); + + public override void UpdateEquip(Player player) => player.GetCritChance() += 3; + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(12). + AddIngredient(). + AddTile(TileID.Anvils). + Register(); + } + } + + [AutoloadEquip(EquipType.Legs)] + [LegacyName("WulfrumLeggings")] + public class WulfrumOveralls : ModItem + { + public override void SetStaticDefaults() + { + SacrificeTotal = 1; + DisplayName.SetDefault("Wulfrum Overalls"); + Tooltip.SetDefault("Movement speed increased by 5%"); + } + + public override void SetDefaults() + { + Item.width = 18; + Item.height = 18; + Item.value = Item.buyPrice(0, 0, 25, 0); + Item.rare = ItemRarityID.Blue; + Item.defense = 1; + + if (Main.netMode != NetmodeID.Server) + { + var equipSlot = EquipLoader.GetEquipSlot(Mod, Name, EquipType.Legs); + ArmorIDs.Legs.Sets.HidesBottomSkin[equipSlot] = true; + } + } + public override void ModifyTooltips(List tooltips) => WulfrumHat.ModifySetTooltips(this, tooltips); + public override void UpdateEquip(Player player) + { + player.moveSpeed += 0.05f; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(8). + AddIngredient(). + AddTile(TileID.Anvils). + Register(); + } + } + #endregion + + public class WulfrumArmorPlayer : ModPlayer + { + public static int BastionShootDamage = 10; + public static float BastionShootSpeed = 18f; + public static int BastionShootTime = 10; + + public bool wulfrumSet = false; + + public override void ResetEffects() + { + wulfrumSet = false; + } + + public override void UpdateDead() + { + wulfrumSet = false; + } + + public override void Kill(double damage, int hitDirection, bool pvp, PlayerDeathReason damageSource) + { + if (WulfrumHat.PowerModeEngaged(Player, out var cd) && Main.netMode != NetmodeID.Server) + { + SetBonusEndEffect(true); + if (!Player.GetModPlayer().vanityEquipped) + Player.GetModPlayer().transformationActive = false; + } + } + + public override void PostUpdate() + { + if (wulfrumSet && Player.Calamity().cooldowns.TryGetValue(WulfrumBastion.ID, out var cd) && cd.timeLeft == WulfrumHat.BastionCooldown) + { + SetBonusEndEffect(false); + } + } + + public override void PostHurt(bool pvp, bool quiet, double damage, int hitDirection, bool crit) + { + if (WulfrumHat.PowerModeEngaged(Player, out var cd)) + { + cd.timeLeft -= WulfrumHat.TimeLostPerHit; + if (cd.timeLeft < WulfrumHat.BastionCooldown) + { + cd.timeLeft = WulfrumHat.BastionCooldown - 1; + if (Main.netMode != NetmodeID.Server) + SetBonusEndEffect(true); + } + } + } + + public void SetBonusEndEffect(bool violent) + { + SoundStyle breakSound = WulfrumHat.SetBreakSoundSafe; + float goreSpeed = 3f; + int goreCount = 4; + int goreIncrement = 2; + + if (violent) + { + breakSound = WulfrumHat.SetBreakSound; + goreSpeed = 9f; + goreCount = 9; + goreIncrement = 1; + } + + SoundEngine.PlaySound(breakSound, Player.Center); + //Only spawn the cannon gore if the player already has the vanity on. + if (Player.GetModPlayer().vanityEquipped) + { + Vector2 shrapnelVelocity = Main.rand.NextVector2Circular(goreSpeed, goreSpeed); + Gore.NewGore(Player.GetSource_Death(), Player.Center, shrapnelVelocity, Mod.Find("WulfrumPowerSuit1").Type); + } + + else + { + int j = 1; + + for (int i = 1; i < goreCount; i++) + { + Vector2 shrapnelVelocity = Main.rand.NextVector2Circular(goreSpeed, goreSpeed); + string goreType = "WulfrumPowerSuit" + j.ToString(); + Gore.NewGore(Player.GetSource_Death(), Player.Center, shrapnelVelocity, Mod.Find(goreType).Type); + + j += Main.rand.Next(1, goreIncrement); + } + } + } + + + public override void PostUpdateMiscEffects() + { + //This is important. Prevents ppl cheat sheeting the item in from softlocking their mouse button lol + if (Main.mouseItem.ModItem is WulfrumFusionCannon && !WulfrumHat.PowerModeEngaged(Player, out _)) + { + Main.mouseItem.TurnToAir(); + } + + //This shouldn't ever be possible since the power mode prevents you from using or moving items around + if (!wulfrumSet && WulfrumHat.PowerModeEngaged(Player, out var cd)) + { + cd.timeLeft = WulfrumHat.BastionCooldown; + } + } + + public override void FrameEffects() + { + //Give the braids variant to w*men + if (!Player.Male && Player.head == EquipLoader.GetEquipSlot(Mod, "WulfrumHat", EquipType.Head)) + Player.head = EquipLoader.GetEquipSlot(Mod, "WulfrumHatFemale", EquipType.Head); + } + } +} diff --git a/Items/BaseItems/HeldOnlyItem.cs b/Items/BaseItems/HeldOnlyItem.cs new file mode 100644 index 0000000000..2c1eb67151 --- /dev/null +++ b/Items/BaseItems/HeldOnlyItem.cs @@ -0,0 +1,67 @@ +using Terraria; +using Terraria.ModLoader; +using Terraria.ID; +using Terraria.DataStructures; +using Terraria.Audio; +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace CalamityMod.Items.BaseItems +{ + /// + /// A item that only exists as a held item. Useful if for example, it is used as a mean to temporarily replace the players attack ability. + /// + public abstract class HeldOnlyItem : ModItem + { + public virtual bool VisibleInUI => false; + + public override void Load() + { + On.Terraria.Player.dropItemCheck += DontDropCoolStuff; + On.Terraria.UI.ItemSlot.LeftClick_ItemArray_int_int += LockMouseToSpecialItem; + On.Terraria.UI.ItemSlot.Draw_SpriteBatch_ItemArray_int_int_Vector2_Color += DrawSpecial; + } + public override void Unload() + { + On.Terraria.Player.dropItemCheck -= DontDropCoolStuff; + On.Terraria.UI.ItemSlot.LeftClick_ItemArray_int_int -= LockMouseToSpecialItem; + On.Terraria.UI.ItemSlot.Draw_SpriteBatch_ItemArray_int_int_Vector2_Color -= DrawSpecial; + } + + private void DrawSpecial(On.Terraria.UI.ItemSlot.orig_Draw_SpriteBatch_ItemArray_int_int_Vector2_Color orig, SpriteBatch sb, Item[] inv, int context, int slot, Vector2 position, Color color) + { + if (inv[slot].ModItem is HeldOnlyItem && !(inv[slot].ModItem as HeldOnlyItem).VisibleInUI) + return; + + else + orig(sb, inv, context, slot, position, color); + } + + public override void PostUpdate() + { + //Die if in the world + Item.type = 0; + Item.stack = 0; + } + + public override bool CanPickup(Player player) => false; + + private void LockMouseToSpecialItem(On.Terraria.UI.ItemSlot.orig_LeftClick_ItemArray_int_int orig, Item[] inv, int context, int slot) + { + if (!(Main.mouseItem.ModItem is HeldOnlyItem)) + orig(inv, context, slot); + } + + //https://media.discordapp.net/attachments/458432092301295618/993675527539916850/unknown.png + private void DontDropCoolStuff(On.Terraria.Player.orig_dropItemCheck orig, Terraria.Player self) + { + if (!(Main.mouseItem.ModItem is HeldOnlyItem)) + orig(self); + } + + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) => false; + + } +} diff --git a/Items/CalamityGlobalItemLoot.cs b/Items/CalamityGlobalItemLoot.cs index 177b0e516e..b600276188 100644 --- a/Items/CalamityGlobalItemLoot.cs +++ b/Items/CalamityGlobalItemLoot.cs @@ -257,13 +257,13 @@ namespace CalamityMod.Items case ItemID.WoodenCrate: case ItemID.WoodenCrateHard: BlockCrateDrops(); - DropHelper.DropItemChance(s, player, ModContent.ItemType(), 0.25f, 3, 5); + DropHelper.DropItemChance(s, player, ModContent.ItemType(), 0.25f, 3, 5); break; case ItemID.IronCrate: case ItemID.IronCrateHard: BlockCrateDrops(); - DropHelper.DropItemChance(s, player, ModContent.ItemType(), 0.25f, 5, 8); + DropHelper.DropItemChance(s, player, ModContent.ItemType(), 0.25f, 5, 8); DropHelper.DropItemChance(s, player, ModContent.ItemType(), 0.25f, 5, 8); break; diff --git a/Items/Fishing/FishingRods/WulfrumRod.cs b/Items/Fishing/FishingRods/WulfrumRod.cs index ed4c1d1979..159dc4111b 100644 --- a/Items/Fishing/FishingRods/WulfrumRod.cs +++ b/Items/Fishing/FishingRods/WulfrumRod.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Items.Fishing.FishingRods { SacrificeTotal = 1; DisplayName.SetDefault("Wulfrum Fishing Pole"); - Tooltip.SetDefault("This barely works, but it's better than nothing."); + Tooltip.SetDefault("This barely works, but it's better than nothing"); } public override void SetDefaults() @@ -33,7 +33,7 @@ namespace CalamityMod.Items.Fishing.FishingRods public override void AddRecipes() { CreateRecipe(). - AddIngredient(9). + AddIngredient(9). AddTile(TileID.Anvils). Register(); } diff --git a/Items/Materials/WulfrumMetalScrap.cs b/Items/Materials/WulfrumMetalScrap.cs index 7567c3dd3d..b4006539c5 100644 --- a/Items/Materials/WulfrumMetalScrap.cs +++ b/Items/Materials/WulfrumMetalScrap.cs @@ -1,10 +1,17 @@ using Terraria; using Terraria.ModLoader; using Terraria.ID; +using Terraria.DataStructures; +using CalamityMod.Items.Accessories; +using CalamityMod.Items.Armor.Wulfrum; +using Terraria.Audio; +using CalamityMod.Cooldowns; +using static CalamityMod.CalamityUtils; namespace CalamityMod.Items.Materials { - public class WulfrumShard : ModItem + [LegacyName("WulfrumShard")] + public class WulfrumMetalScrap : ModItem { public override void SetStaticDefaults() { @@ -20,5 +27,37 @@ namespace CalamityMod.Items.Materials Item.value = Item.sellPrice(copper: 80); Item.rare = ItemRarityID.Blue; } + + public override void OnSpawn(IEntitySource source) + { + if (source is EntitySource_Loot) + { + if (Main.rand.NextBool()) + return; + + bool closePlayer = false; + + for (int i = 0; i < Main.maxPlayers; i++) + { + if ((Main.player[i].Center - Item.Center).Length() < 1200 && Main.player[i].GetModPlayer().battery) + { + closePlayer = true; + break; + } + } + + if (closePlayer) + { + Item.stack++; + SoundEngine.PlaySound(WulfrumBattery.ExtraDropSound, Item.Center); + + int numDust = Main.rand.Next(3, 7); + for (int i = 0; i < numDust; i++) + { + Dust.NewDustDirect(Item.position, Item.width, Item.height, Main.rand.NextBool() ? 246 : 247, 0, -3f, Scale: Main.rand.NextFloat(0.9f, 1f)); + } + } + } + } } } diff --git a/Items/Materials/WulfrumShard.png b/Items/Materials/WulfrumMetalScrap.png similarity index 100% rename from Items/Materials/WulfrumShard.png rename to Items/Materials/WulfrumMetalScrap.png diff --git a/Items/Mounts/OnyxExcavator.cs b/Items/Mounts/OnyxExcavator.cs index 3f03518b0a..df833d2c9b 100644 --- a/Items/Mounts/OnyxExcavator.cs +++ b/Items/Mounts/OnyxExcavator.cs @@ -1,4 +1,4 @@ -using CalamityMod.Buffs.Mounts; +using CalamityMod.Buffs.Mounts; using CalamityMod.Tiles.Abyss; using Microsoft.Xna.Framework; using System; @@ -97,16 +97,7 @@ namespace CalamityMod.Items.Mounts { if (Main.myPlayer == player.whoAmI) { - int highestPickPower = 35; //35% if you have no pickaxes. - for (int item = 0; item < Main.InventorySlotsTotal; item++) - { - if (player.inventory[item].pick <= 0) - continue; - if (player.inventory[item].pick > highestPickPower) - { - highestPickPower = player.inventory[item].pick; - } - } + int highestPickPower = player.GetBestPickPower(); float direction = Math.Sign(player.velocity.X); if (Math.Abs(direction) < 0.1f) @@ -145,60 +136,7 @@ namespace CalamityMod.Items.Mounts float tileDist = tileVec.Length(); Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); - int pickReq = 0; - ModTile moddedTile = TileLoader.GetTile(tile.TileType); - if (moddedTile != null) - { - pickReq = moddedTile.MinPick; - } - else - { - switch (tile.TileType) - { - case TileID.Chlorophyte: - pickReq = 200; - break; - case TileID.Ebonstone: - case TileID.Crimstone: - case TileID.Pearlstone: - case TileID.DesertFossil: - case TileID.Obsidian: - case TileID.Hellstone: - pickReq = 65; - break; - case TileID.Meteorite: - pickReq = 50; - break; - case TileID.Demonite: - case TileID.Crimtane: - if (y > Main.worldSurface) - pickReq = 55; - break; - case TileID.LihzahrdBrick: - case TileID.LihzahrdAltar: - pickReq = 210; - break; - case TileID.Cobalt: - case TileID.Palladium: - pickReq = 100; - break; - case TileID.Mythril: - case TileID.Orichalcum: - pickReq = 110; - break; - case TileID.Adamantite: - case TileID.Titanium: - pickReq = 150; - break; - default: - break; - } - } - if (Main.tileDungeon[tile.TileType]) - { - if (x < Main.maxTilesX * 0.35 || x > Main.maxTilesX * 0.65) - pickReq = 65; - } + int pickReq = tile.GetRequiredPickPower(x, y); if (tileDist < mineHeight) { diff --git a/Items/Placeables/FurnitureCosmilite/CosmiliteBrick.png b/Items/Placeables/FurnitureCosmilite/CosmiliteBrick.png index 65a175e242..e1f2cd166e 100644 Binary files a/Items/Placeables/FurnitureCosmilite/CosmiliteBrick.png and b/Items/Placeables/FurnitureCosmilite/CosmiliteBrick.png differ diff --git a/Items/Tools/WulfrumAxe.cs b/Items/Tools/WulfrumAxe.cs deleted file mode 100644 index 3cb9edc5f9..0000000000 --- a/Items/Tools/WulfrumAxe.cs +++ /dev/null @@ -1,44 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Tools -{ - public class WulfrumAxe : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Axe"); - } - - public override void SetDefaults() - { - Item.damage = 5; - Item.knockBack = 4.5f; - Item.useTime = 15; - Item.useAnimation = 26; - Item.axe = 60 / 5; - Item.tileBoost += 1; - - Item.DamageType = DamageClass.Melee; - Item.width = 30; - Item.height = 38; - Item.useTurn = true; - Item.useStyle = ItemUseStyleID.Swing; - Item.value = Item.buyPrice(0, 1, 0, 0); - Item.rare = ItemRarityID.Blue; - Item.UseSound = SoundID.Item1; - Item.autoReuse = true; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(14). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Tools/WulfrumAxe.png b/Items/Tools/WulfrumAxe.png deleted file mode 100644 index 7bd72fbc30..0000000000 Binary files a/Items/Tools/WulfrumAxe.png and /dev/null differ diff --git a/Items/Tools/WulfrumDiggingTurtle.cs b/Items/Tools/WulfrumDiggingTurtle.cs new file mode 100644 index 0000000000..46bfb38ed5 --- /dev/null +++ b/Items/Tools/WulfrumDiggingTurtle.cs @@ -0,0 +1,84 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Typeless; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.DataStructures; + +namespace CalamityMod.Items.Tools +{ + public class WulfrumDiggingTurtle : ModItem + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Digging Turtle"); + Tooltip.SetDefault("Throws a rickety mining contraption to dig out a small tunnel\n" + + "In case of an emergency, right click to instantly detonate all your digging turtles"); + SacrificeTotal = 10; + } + + public override void SetDefaults() + { + Item.useTime = Item.useAnimation = 8; + Item.maxStack = 999; + Item.consumable = true; + Item.shootSpeed = 20f; + Item.shoot = ModContent.ProjectileType(); + Item.width = 30; + Item.height = 38; + Item.useStyle = ItemUseStyleID.Swing; + Item.noMelee = true; + Item.noUseGraphic = true; + Item.UseSound = SoundID.Item1; + Item.value = Item.buyPrice(0, 0, 10, 0); + Item.rare = ItemRarityID.Blue; + } + + public override bool AltFunctionUse(Player player) => true; + + public override bool ConsumeItem(Player player) + { + return player.altFunctionUse != 2; + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + // Play a sound and detonate all owned turtles. + if (player.altFunctionUse == 2) + { + bool explodedAny = false; + + for (int i = 0; i < Main.maxProjectiles; ++i) + { + Projectile p = Main.projectile[i]; + if (!p.active || p.owner != player.whoAmI || p.type != Item.shoot) + continue; + + p.ai[1] = 1f; + p.timeLeft = 1; + p.netUpdate = true; + p.netSpam = 0; + + explodedAny = true; + } + + if (explodedAny) + SoundEngine.PlaySound(SoundID.Item73, position); + + return false; + } + + return true; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(ItemID.Gel, 5). //Gel is a default combustible item to fuel the motors of the lil guys + AddIngredient(3). + Register(); + } + } +} diff --git a/Items/Tools/WulfrumDiggingTurtle.png b/Items/Tools/WulfrumDiggingTurtle.png new file mode 100644 index 0000000000..7b9d5641ca Binary files /dev/null and b/Items/Tools/WulfrumDiggingTurtle.png differ diff --git a/Items/Tools/WulfrumPickaxe.cs b/Items/Tools/WulfrumDrill.cs similarity index 53% rename from Items/Tools/WulfrumPickaxe.cs rename to Items/Tools/WulfrumDrill.cs index 529aa57d42..c9a662177b 100644 --- a/Items/Tools/WulfrumPickaxe.cs +++ b/Items/Tools/WulfrumDrill.cs @@ -2,41 +2,52 @@ using Terraria; using Terraria.ID; using Terraria.ModLoader; +using CalamityMod.Projectiles.Typeless; namespace CalamityMod.Items.Tools { - public class WulfrumPickaxe : ModItem + [LegacyName("WulfrumPickaxe")] + public class WulfrumDrill : ModItem { public override void SetStaticDefaults() { SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Pickaxe"); + DisplayName.SetDefault("Wulfrum Drill"); } public override void SetDefaults() { Item.damage = 5; - Item.knockBack = 2f; - Item.useTime = 8; + Item.knockBack = 0f; + Item.useTime = 5; Item.useAnimation = 16; - Item.pick = 40; + Item.pick = 35; Item.tileBoost += 1; Item.DamageType = DamageClass.Melee; Item.width = 46; Item.height = 38; - Item.useTurn = true; - Item.useStyle = ItemUseStyleID.Swing; Item.value = Item.buyPrice(0, 1, 0, 0); Item.rare = ItemRarityID.Blue; - Item.UseSound = SoundID.Item1; + Item.UseSound = SoundID.Item23; Item.autoReuse = true; + Item.shoot = ModContent.ProjectileType(); + + Item.channel = true; + Item.noMelee = true; + Item.noUseGraphic = true; + Item.useStyle = ItemUseStyleID.Shoot; + } + + public override void HoldItem(Player player) + { + player.Calamity().mouseWorldListener = true; } public override void AddRecipes() { CreateRecipe(). - AddIngredient(12). + AddIngredient(8). AddTile(TileID.Anvils). Register(); } diff --git a/Items/Tools/WulfrumDrill.png b/Items/Tools/WulfrumDrill.png new file mode 100644 index 0000000000..d1ec38a2df Binary files /dev/null and b/Items/Tools/WulfrumDrill.png differ diff --git a/Items/Tools/WulfrumHammer.cs b/Items/Tools/WulfrumHammer.cs deleted file mode 100644 index 6323e7996a..0000000000 --- a/Items/Tools/WulfrumHammer.cs +++ /dev/null @@ -1,44 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Tools -{ - public class WulfrumHammer : ModItem - { - public override void SetStaticDefaults() - { - SacrificeTotal = 1; - DisplayName.SetDefault("Wulfrum Hammer"); - } - - public override void SetDefaults() - { - Item.damage = 7; - Item.knockBack = 5.5f; - Item.useTime = 11; - Item.useAnimation = 29; - Item.hammer = 45; - Item.tileBoost += 1; - - Item.DamageType = DamageClass.Melee; - Item.width = 28; - Item.height = 38; - Item.useTurn = true; - Item.useStyle = ItemUseStyleID.Swing; - Item.value = Item.buyPrice(0, 1, 0, 0); - Item.rare = ItemRarityID.Blue; - Item.UseSound = SoundID.Item1; - Item.autoReuse = true; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(16). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Tools/WulfrumHammer.png b/Items/Tools/WulfrumHammer.png deleted file mode 100644 index 05741786eb..0000000000 Binary files a/Items/Tools/WulfrumHammer.png and /dev/null differ diff --git a/Items/Tools/WulfrumPickaxe.png b/Items/Tools/WulfrumPickaxe.png deleted file mode 100644 index 2dc3379335..0000000000 Binary files a/Items/Tools/WulfrumPickaxe.png and /dev/null differ diff --git a/Items/Tools/WulfrumScaffoldKit.cs b/Items/Tools/WulfrumScaffoldKit.cs new file mode 100644 index 0000000000..ccf54d517e --- /dev/null +++ b/Items/Tools/WulfrumScaffoldKit.cs @@ -0,0 +1,120 @@ +using System.IO; +using System.Linq; +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Typeless; +using CalamityMod.Tiles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; + +namespace CalamityMod.Items.Tools +{ + public class WulfrumScaffoldKit : ModItem + { + public int storedScrap = 0; + public static int TilesPerScrap = 40; + public static int TileTime = 6 * 60; + public static int TileReach = 40; + public static int PlacedTileType => ModContent.TileType(); + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Scaffold Kit"); + Tooltip.SetDefault("\"For when you need something built fast and don't need it to last.\"\n" + + "Places down temporary metal scaffolding. Uses up one wulfrum metal scrap for " + TilesPerScrap.ToString() + " tiles built\n" + + "Scaffold needs to be adjacent to a solid tile to be placed down" + ); + SacrificeTotal = 1; + } + + public override void SetDefaults() + { + Item.width = 52; + Item.height = 42; + Item.useTime = Item.useAnimation = 25; + Item.autoReuse = false; + Item.noUseGraphic = true; + Item.useStyle = ItemUseStyleID.HiddenAnimation; + Item.UseSound = null; + Item.noMelee = true; + Item.channel = true; + Item.rare = ItemRarityID.Blue; + Item.value = Item.buyPrice(silver: 50); + storedScrap = 0; + Item.shoot = ModContent.ProjectileType(); + TileTime = 6 * 60; + } + + public override void HoldItem(Player player) + { + player.Calamity().mouseWorldListener = true; + } + + public override bool CanUseItem(Player player) + { + return (storedScrap > 0 || player.HasItem(ModContent.ItemType())) && !player.noBuilding + && !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == Item.shoot); + } + + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + float barScale = 1f; + + var barBG = ModContent.Request("CalamityMod/ExtraTextures/GenericBarBack").Value; + var barFG = ModContent.Request("CalamityMod/ExtraTextures/GenericBarFront").Value; + + Vector2 drawPos = position + Vector2.UnitY * (frame.Height - 2) * scale + Vector2.UnitX * (frame.Width - barBG.Width * barScale) * scale * 0.5f; + Rectangle frameCrop = new Rectangle(0, 0, (int)(storedScrap / (float)TilesPerScrap * barFG.Width), barFG.Height); + Color colorBG = Color.RoyalBlue; + Color colorFG = Color.Lerp(Color.Teal, Color.YellowGreen, storedScrap / (float)TilesPerScrap); + + spriteBatch.Draw(barBG, drawPos, null, colorBG, 0f, origin, scale * barScale, 0f, 0f); + spriteBatch.Draw(barFG, drawPos, frameCrop, colorFG * 0.8f, 0f, origin, scale * barScale, 0f, 0f); + } + + + #region saving the durability + public override ModItem Clone(Item item) + { + ModItem clone = base.Clone(item); + if (clone is WulfrumScaffoldKit a && item.ModItem is WulfrumScaffoldKit a2) + { + a.storedScrap = a2.storedScrap; + } + return clone; + } + + public override void SaveData(TagCompound tag) + { + tag["storedScrap"] = storedScrap; + } + + public override void LoadData(TagCompound tag) + { + storedScrap = tag.GetInt("storedScrap"); + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write(storedScrap); + } + + public override void NetReceive(BinaryReader reader) + { + storedScrap = reader.ReadInt32(); + } + #endregion + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(6). + AddIngredient(1). + AddTile(TileID.Anvils). + Register(); + } + } +} diff --git a/Items/Tools/WulfrumScaffoldKit.png b/Items/Tools/WulfrumScaffoldKit.png new file mode 100644 index 0000000000..4d977d3937 Binary files /dev/null and b/Items/Tools/WulfrumScaffoldKit.png differ diff --git a/Items/Tools/WulfrumTreasurePinger.cs b/Items/Tools/WulfrumTreasurePinger.cs new file mode 100644 index 0000000000..4c2afda148 --- /dev/null +++ b/Items/Tools/WulfrumTreasurePinger.cs @@ -0,0 +1,291 @@ +using System; +using System.IO; +using CalamityMod.Items.Materials; +using CalamityMod.Particles; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; + +namespace CalamityMod.Items.Tools +{ + public class WulfrumTreasurePinger : ModItem + { + public static readonly SoundStyle ScanBeepSound = new("CalamityMod/Sounds/Item/WulfrumPing") { PitchVariance = 0.1f }; + public static readonly SoundStyle ScanBeepBreakSound = new("CalamityMod/Sounds/Item/WulfrumPingBreak"); + public static readonly SoundStyle RechargeBeepSound = new("CalamityMod/Sounds/Item/WulfrumPingReady") { PitchVariance = 0.1f }; + + public int usesLeft = maxUses; + public const int maxUses = 20; + public static int breakTime = 90; + public int timeBeforeBlast = 90; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Treasure Pinger"); + Tooltip.SetDefault("Helps you find metal that's hopefully more valuable than wulfrum\n" + + "This contraption seems incredibly shoddy. [c/fc4903: It'll break sooner than later for sure]" + ); + SacrificeTotal = 1; + } + + public override void SetDefaults() + { + Item.width = 52; + Item.height = 42; + Item.useTime = Item.useAnimation = 25; + Item.autoReuse = false; + Item.holdStyle = 16; //Custom hold style + Item.useStyle = ItemUseStyleID.Shoot; + Item.UseSound = null; + Item.noMelee = true; + Item.rare = ItemRarityID.Blue; + Item.value = Item.buyPrice(silver: 50); + usesLeft = maxUses; + timeBeforeBlast = breakTime; + } + + public override void HoldItem(Player player) + { + player.Calamity().mouseWorldListener = true; + + //If the explosion sequence has been initiated. + if (usesLeft <= 0 && timeBeforeBlast < breakTime) + { + timeBeforeBlast--; + player.itemTime = 2; + player.itemAnimation = 2; + + float breakProgress = 1 - timeBeforeBlast / (float)breakTime; + + int smokeLikelyhood = (int)Math.Floor(1 + timeBeforeBlast / (float)breakTime * 4); + if (Main.rand.NextBool(smokeLikelyhood)) + { + Vector2 smokePos = player.GetBackHandPosition(player.compositeBackArm.stretch, player.compositeBackArm.rotation).Floor(); + Vector2 velocity = -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2 * 0.7f) * Main.rand.NextFloat(6f, 9f + 6f * breakProgress); + + Color smokeStart = Main.rand.NextBool() ? Color.GreenYellow : Color.DeepSkyBlue; + Color smokeEnd = Color.Lerp(new Color(110, 110, 110), new Color(60, 60, 60), breakProgress); + + float smokeSize = Main.rand.NextFloat(1.4f, 2.2f) * (0.6f + 0.4f * breakProgress); + + Particle smoke = new SmallSmokeParticle(smokePos, velocity, smokeStart, smokeEnd, smokeSize, 115 - Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(smoke); + } + } + + if (timeBeforeBlast <= 0) + { + DropHelper.DropItem(Item.GetSource_ItemUse(Item), player, ModContent.ItemType(), 0, 3); + + Item.TurnToAir(); + + int smokeCount = Main.rand.Next(5, 10); + int shrapnelCount = Main.rand.Next(3, 5); + int sparkCount = Main.rand.Next(4, 8); + + Vector2 centerPosition = player.GetBackHandPosition(player.compositeBackArm.stretch, player.compositeBackArm.rotation).Floor(); + + for (int i = 0; i < smokeCount; i++) + { + Vector2 velocity = -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2) * Main.rand.NextFloat(12f, 16f); + + Color smokeStart = Main.rand.NextBool() ? Color.GreenYellow : Color.Aqua; + Color smokeEnd = new Color(60, 60, 60); + + float smokeSize = Main.rand.NextFloat(1.4f, 2.2f); + + Particle smoke = new SmallSmokeParticle(centerPosition, velocity, smokeStart, smokeEnd, smokeSize, 135 - Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(smoke); + } + + if (Main.netMode != NetmodeID.Server) + { + for (int i = 0; i < shrapnelCount; i++) + { + Vector2 shrapnelVelocity = Main.rand.NextVector2Circular(9f, 9f); + float shrapnelScale = Main.rand.NextFloat(0.8f, 1f); + + Gore.NewGore(Item.GetSource_ItemUse(Item), centerPosition, shrapnelVelocity, Mod.Find("WulfrumPinger" + Main.rand.Next(1, 5).ToString()).Type, shrapnelScale); + } + } + + for (int i = 0; i < sparkCount; i++) + { + Dust.NewDustPerfect(centerPosition, 226, Main.rand.NextVector2Circular(18f, 18f), Scale: Main.rand.NextFloat(0.4f, 1f)); + } + } + } + + public override bool CanUseItem(Player player) + { + return !(TilePingerSystem.tileEffects["WulfrumPing"].Active); + } + + public override bool? UseItem(Player player) + { + if (TilePingerSystem.AddPing("WulfrumPing", player.Center, player)) + { + if (player.name != "John Wulfrum") + usesLeft--; + + if (usesLeft <= 0) + { + if (player.whoAmI == Main.myPlayer) + SoundEngine.PlaySound(ScanBeepBreakSound); + + //Start the breaking anim. + timeBeforeBlast--; + } + + else if (player.whoAmI == Main.myPlayer) + SoundEngine.PlaySound(ScanBeepSound); + + return true; + } + + return false; + } + + #region drawing stuff + public void SetItemInHand(Player player, Rectangle heldItemFrame) + { + //Make the player face where they're aiming. + if (player.Calamity().mouseWorld.X > player.Center.X) + { + player.ChangeDir(1); + } + else + { + player.ChangeDir(-1); + } + + float itemRotation = player.compositeBackArm.rotation + MathHelper.PiOver2 * player.gravDir; + Vector2 itemPosition = player.GetBackHandPositionImproved(player.compositeBackArm).Floor(); + Vector2 itemSize = new Vector2(52, 42); + Vector2 itemOrigin = new Vector2(-20, -13); + + if (usesLeft == 0) + { + itemPosition += Main.rand.NextVector2CircularEdge(4f, 4f) * (1 - timeBeforeBlast / (float)breakTime); + //We have to lower the timebeforeblast here as well because the item that gets processed here is not actually the same item as the item held in the players hands. + //Basically we are dealing with a clone of the item that the drawn player uses. + //So no, don't worry, the item isn't breaking twice as fast. + timeBeforeBlast--; + } + + CalamityUtils.CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin); + } + + public void SetPlayerArms(Player player) + { + //Calculate the dirction in which the players arms should be pointing at. + Vector2 playerToCursor = (player.Calamity().mouseWorld - player.Center).SafeNormalize(Vector2.UnitX); + float armPointingDirection = (playerToCursor.ToRotation() + MathHelper.PiOver2).Modulo(MathHelper.TwoPi); + + //"crop" the rotation so the player only tilts the fishing rod slightly up and slightly down. + if (armPointingDirection < MathHelper.Pi) + { + armPointingDirection = armPointingDirection / MathHelper.Pi * MathHelper.PiOver4 * 0.5f - MathHelper.PiOver4 * 0.3f; + } + + //It gets a bit harder if its pointing left; ouch + else + { + armPointingDirection -= MathHelper.Pi; + + armPointingDirection = armPointingDirection / MathHelper.Pi * MathHelper.PiOver4 * 0.5f - MathHelper.PiOver4 * 0.3f + MathHelper.Pi; + } + + player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, armPointingDirection * player.gravDir - MathHelper.PiOver2); + player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, armPointingDirection * player.gravDir - MathHelper.PiOver2); + } + + public override void HoldStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); + public override void UseStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); + public override void HoldItemFrame(Player player) => SetPlayerArms(player); + public override void UseItemFrame(Player player) => SetPlayerArms(player); + + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (usesLeft == maxUses || usesLeft == 0) + return; + + float barScale = 1.3f; + + var barBG = ModContent.Request("CalamityMod/ExtraTextures/GenericBarBack").Value; + var barFG = ModContent.Request("CalamityMod/ExtraTextures/GenericBarFront").Value; + + Vector2 drawPos = position + Vector2.UnitY * (frame.Height - 2) * scale + Vector2.UnitX * (frame.Width - barBG.Width * barScale) * scale * 0.5f; + Rectangle frameCrop = new Rectangle(0, 0, (int)(usesLeft / (float)maxUses * barFG.Width), barFG.Height); + Color colorBG = Color.RoyalBlue; + Color colorFG = Color.Lerp(Color.Teal, Color.YellowGreen, usesLeft / (float)maxUses); + + spriteBatch.Draw(barBG, drawPos, null, colorBG, 0f, origin, scale * barScale, 0f, 0f); + spriteBatch.Draw(barFG, drawPos, frameCrop, colorFG * 0.8f, 0f, origin, scale * barScale, 0f, 0f); + } + + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (usesLeft > 0) + return true; + + var tex = ModContent.Request(Texture).Value; + + float blastProgress = (1 - timeBeforeBlast / (float)breakTime); + position += Main.rand.NextVector2CircularEdge(4f, 4f) * blastProgress; + drawColor = Color.Lerp(drawColor, Color.OrangeRed, blastProgress); + + spriteBatch.Draw(tex, position, frame, drawColor, 0f, origin, scale, 0f, 0f); + return false; + } + #endregion + + #region saving the durability + public override ModItem Clone(Item item) + { + ModItem clone = base.Clone(item); + if (clone is WulfrumTreasurePinger a && item.ModItem is WulfrumTreasurePinger a2) + { + a.usesLeft = a2.usesLeft; + a.timeBeforeBlast = a2.timeBeforeBlast; + } + return clone; + } + + public override void SaveData(TagCompound tag) + { + tag["usesLeft"] = usesLeft; + } + + public override void LoadData(TagCompound tag) + { + usesLeft = tag.GetInt("usesLeft"); + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write(usesLeft); + } + + public override void NetReceive(BinaryReader reader) + { + usesLeft = reader.ReadInt32(); + } + #endregion + + public override void AddRecipes() + { + //Intentionally craftable anywhere. + CreateRecipe(). + AddIngredient(6). + Register(); + } + } + + +} diff --git a/Items/Tools/WulfrumTreasurePinger.png b/Items/Tools/WulfrumTreasurePinger.png new file mode 100644 index 0000000000..9a3dec7cbb Binary files /dev/null and b/Items/Tools/WulfrumTreasurePinger.png differ diff --git a/Items/Weapons/Magic/UltraLiquidator.cs b/Items/Weapons/Magic/UltraLiquidator.cs index 86601619f9..8d4c11d40f 100644 --- a/Items/Weapons/Magic/UltraLiquidator.cs +++ b/Items/Weapons/Magic/UltraLiquidator.cs @@ -32,7 +32,7 @@ namespace CalamityMod.Items.Weapons.Magic Item.shootSpeed = 16f; Item.shoot = ModContent.ProjectileType(); - Item.width = Item.height = 16; + Item.width = Item.height = 70; Item.useStyle = ItemUseStyleID.Shoot; Item.noMelee = true; Item.UseSound = SoundID.Item9; @@ -43,8 +43,6 @@ namespace CalamityMod.Items.Weapons.Magic // Terraria seems to really dislike high crit values in SetDefaults public override void ModifyWeaponCrit(Player player, ref float crit) => crit += 30; - public override Vector2? HoldoutOrigin() => new Vector2(15, 15); - public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo projSource, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { Vector2 playerPos = player.RotatedRelativePoint(player.MountedCenter, true); diff --git a/Items/Weapons/Magic/UltraLiquidator.png b/Items/Weapons/Magic/UltraLiquidator.png index ed2a8485cf..c7b0f9b411 100644 Binary files a/Items/Weapons/Magic/UltraLiquidator.png and b/Items/Weapons/Magic/UltraLiquidator.png differ diff --git a/Items/Weapons/Magic/WulfrumProsthesis.cs b/Items/Weapons/Magic/WulfrumProsthesis.cs new file mode 100644 index 0000000000..06020416e4 --- /dev/null +++ b/Items/Weapons/Magic/WulfrumProsthesis.cs @@ -0,0 +1,184 @@ +using System; +using System.Linq; +using CalamityMod.Items.Materials; +using CalamityMod.Projectiles.Magic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using static CalamityMod.CalamityUtils; + +namespace CalamityMod.Items.Weapons.Magic +{ + [LegacyName("WulfrumStaff")] + public class WulfrumProsthesis : ModItem, IHideFrontArm + { + public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisShoot") { PitchVariance = 0.1f, Volume = 0.55f }; + public static readonly SoundStyle HitSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisHit") { PitchVariance = 0.1f, Volume = 0.75f , MaxInstances = 3}; + public static readonly SoundStyle SuckSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisSucc") { Volume = 0.5f }; + public static readonly SoundStyle SuckStopSound = new("CalamityMod/Sounds/Item/WulfrumProsthesisSuccStop") { Volume = 0.5f }; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Prosthesis"); + Tooltip.SetDefault("Casts a wulfrum bolt\n" + + "Right click to drain mana from creatures in front of you"); + //Lore about how magic is not always a given for everyone, and how some unlucky people sometimes resort to voluntarily cutting their limbs to use magic augmented prosthesis + //1 : Informs about magic as a narrative thing, 2 : Informs about wulfrum energy being partly magical. + SacrificeTotal = 1; + } + + internal static Asset RealSprite; + + public override string Texture => "CalamityMod/Items/Weapons/Magic/WulfrumProsthesis_Arm"; + + public override void SetDefaults() + { + Item.damage = 15; + Item.DamageType = DamageClass.Magic; + Item.mana = 2; + Item.width = 34; + Item.height = 42; + Item.useTime = 24; + Item.useAnimation = 24; + Item.useStyle = ItemUseStyleID.Shoot; + Item.noMelee = true; + Item.knockBack = 3; + Item.value = Item.buyPrice(0, 1, 0, 0); + Item.rare = ItemRarityID.Blue; + Item.UseSound = ShootSound; + Item.autoReuse = true; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 18f; + Item.holdStyle = 16; //Custom hold style + } + + public override void HoldItem(Player player) + { + player.Calamity().mouseWorldListener = true; + player.Calamity().rightClickListener = true; + } + + public override bool CanUseItem(Player player) => !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ModContent.ProjectileType()); + + public override bool AltFunctionUse(Player player) => true; + + public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) + { + if (player.altFunctionUse == 2) + type = ModContent.ProjectileType(); + } + + public override void ModifyManaCost(Player player, ref float reduce, ref float mult) + { + if (player.altFunctionUse == 2) + mult = 0f; + } + + public override void UseAnimation(Player player) + { + Item.UseSound = ShootSound; + if (player.altFunctionUse == 2) + Item.UseSound = null; + } + + public void SetItemInHand(Player player, Rectangle heldItemFrame) + { + //Make the player face where they're aiming. + if (player.Calamity().mouseWorld.X > player.Center.X) + { + player.ChangeDir(1); + } + else + { + player.ChangeDir(-1); + } + + float animProgress = 1 - player.itemTime / (float)player.itemTimeMax; + + //Default + Vector2 itemPosition = player.MountedCenter + new Vector2(-2f * player.direction, -1f * player.gravDir); + float itemRotation = (player.Calamity().mouseWorld - itemPosition).ToRotation(); + + //Adjust for animation + + if (animProgress < 0.7f) + itemPosition -= itemRotation.ToRotationVector2() * (1 - (float)Math.Pow(1 - (0.7f - animProgress) / 0.7f, 4)) * 4f; + + if (animProgress < 0.4f) + itemRotation += -0.45f * (float)Math.Pow((0.4f - animProgress) / 0.4f, 2) * player.direction * player.gravDir; + + //Shakezzz + if (player.itemTime == 1 && Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ModContent.ProjectileType())) + { + itemPosition += Main.rand.NextVector2Circular(2f, 2f); + } + + + Vector2 itemSize = new Vector2(28, 14); + Vector2 itemOrigin = new Vector2(-8, 0); + CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin, true); + } + + public override void HoldStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); + public override void UseStyle(Player player, Rectangle heldItemFrame) => SetItemInHand(player, heldItemFrame); + + public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (RealSprite == null) + RealSprite = ModContent.Request("CalamityMod/Items/Weapons/Magic/WulfrumProsthesis"); + + Texture2D properSprite = RealSprite.Value; + + spriteBatch.DrawNewInventorySprite(properSprite, new Vector2(28f, 14f), position, drawColor, origin, scale, new Vector2(0, -6f)); + + return false; + } + + public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) + { + if (RealSprite == null) + RealSprite = ModContent.Request("CalamityMod/Items/Weapons/Magic/WulfrumProsthesis"); + + Texture2D properSprite = RealSprite.Value; + + spriteBatch.Draw(properSprite, Item.position - Main.screenPosition, null, lightColor, rotation, properSprite.Size() / 2f, scale, 0, 0); + + return false; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(10). + AddIngredient(). + AddTile(TileID.Anvils). + Register(); + } + } + + public class WulfrumProsthesisPlayer : ModPlayer + { + public bool ManaDrainActive = false; + + public override void UpdateDead() + { + ManaDrainActive = false; + } + + public override void PostUpdateMiscEffects() + { + if (ManaDrainActive) + { + Player.manaRegenBonus = 35; + Player.manaRegenDelay = 0; + Player.manaRegenBuff = true; + } + + ManaDrainActive = false; + } + } +} diff --git a/Items/Weapons/Magic/WulfrumProsthesis.png b/Items/Weapons/Magic/WulfrumProsthesis.png new file mode 100644 index 0000000000..440925c1b6 Binary files /dev/null and b/Items/Weapons/Magic/WulfrumProsthesis.png differ diff --git a/Items/Weapons/Magic/WulfrumProsthesis_Arm.png b/Items/Weapons/Magic/WulfrumProsthesis_Arm.png new file mode 100644 index 0000000000..600ac1c3c9 Binary files /dev/null and b/Items/Weapons/Magic/WulfrumProsthesis_Arm.png differ diff --git a/Items/Weapons/Magic/WulfrumStaff.cs b/Items/Weapons/Magic/WulfrumStaff.cs deleted file mode 100644 index d88993e314..0000000000 --- a/Items/Weapons/Magic/WulfrumStaff.cs +++ /dev/null @@ -1,52 +0,0 @@ -using CalamityMod.Items.Materials; -using CalamityMod.Projectiles.Magic; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using Microsoft.Xna.Framework; - -namespace CalamityMod.Items.Weapons.Magic -{ - public class WulfrumStaff : ModItem - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Wulfrum Staff"); - Tooltip.SetDefault("Casts a wulfrum bolt"); - //Item.staff[item.type] = true; - SacrificeTotal = 1; - } - - public override void SetDefaults() - { - Item.damage = 13; - Item.DamageType = DamageClass.Magic; - Item.mana = 2; - Item.width = 44; - Item.height = 46; - Item.useTime = 20; - Item.useAnimation = 20; - Item.useStyle = ItemUseStyleID.Shoot; - Item.noMelee = true; - Item.knockBack = 3; - Item.value = Item.buyPrice(0, 1, 0, 0); - Item.rare = ItemRarityID.Blue; - Item.UseSound = SoundID.Item43; - Item.autoReuse = true; - Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 9f; - } - - //public override Vector2? HoldoutOrigin() => new Vector2(8, 15); - - public override Vector2? HoldoutOffset() => new Vector2(-3, 0); - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(12). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Weapons/Magic/WulfrumStaff.png b/Items/Weapons/Magic/WulfrumStaff.png deleted file mode 100644 index bd38ecf2cd..0000000000 Binary files a/Items/Weapons/Magic/WulfrumStaff.png and /dev/null differ diff --git a/Items/Weapons/Melee/Cnidarian.cs b/Items/Weapons/Melee/Cnidarian.cs index 60eeb20d2f..5077cf6fc0 100644 --- a/Items/Weapons/Melee/Cnidarian.cs +++ b/Items/Weapons/Melee/Cnidarian.cs @@ -83,7 +83,7 @@ namespace CalamityMod.Items.Weapons.Melee } - CalamityUtils.CleanHoldStyle(player, player.compositeFrontArm.rotation + MathHelper.PiOver2 * player.gravDir, player.GetFrontHandPositionImproved(player.compositeFrontArm), new Vector2(42, 34), new Vector2(-15, 11)); + CalamityUtils.CleanHoldStyle(player, player.compositeFrontArm.rotation + MathHelper.PiOver2 * player.gravDir, player.GetFrontHandPositionImproved(player.compositeFrontArm), new Vector2(42, 34), new Vector2(-15, 11), true); } @@ -137,12 +137,7 @@ namespace CalamityMod.Items.Weapons.Melee { Texture2D properSprite = ModContent.Request("CalamityMod/Items/Weapons/Melee/Cnidarian").Value; - //Scale the jellyfish sprite properly, since its larger than the fishing rod (Largest dimension of the jellyfish sprite : 52. Largest dimension of the fishing rod : 42) - float scaleRatio = 42 / 52f; - //Offset the jellyfish sprite properly, since the fishing rod is larger than the jellyfish (Jellyfish width : 28px, Fishing rod width : 42) - Vector2 positionOffset = new Vector2(21 - 14, 0) * scale; - - spriteBatch.Draw(properSprite, position + positionOffset, null, drawColor, 0f, origin, scale * scaleRatio, 0, 0); + spriteBatch.DrawNewInventorySprite(properSprite, new Vector2(42f, 34), position, drawColor, origin, scale); return false; } diff --git a/Items/Weapons/Melee/WulfrumBlade.cs b/Items/Weapons/Melee/WulfrumBlade.cs deleted file mode 100644 index b48de10bf2..0000000000 --- a/Items/Weapons/Melee/WulfrumBlade.cs +++ /dev/null @@ -1,47 +0,0 @@ -using CalamityMod.Items.Materials; -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Weapons.Melee -{ - public class WulfrumBlade : ModItem - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Wulfrum Blade"); - SacrificeTotal = 1; - } - - public override void SetDefaults() - { - Item.width = 32; - Item.height = 46; - Item.damage = 12; - Item.DamageType = DamageClass.Melee; - Item.useAnimation = 20; - Item.useStyle = ItemUseStyleID.Swing; - Item.useTime = 20; - Item.useTurn = true; - Item.knockBack = 3.75f; - Item.UseSound = SoundID.Item1; - Item.autoReuse = true; - Item.value = Item.buyPrice(0, 1, 0, 0); - Item.rare = ItemRarityID.Blue; - } - - public override void UseItemHitbox(Player player, ref Rectangle hitbox, ref bool noHitbox) - { - hitbox = CalamityUtils.FixSwingHitbox(39, 39); - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(12). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Weapons/Melee/WulfrumBlade.png b/Items/Weapons/Melee/WulfrumBlade.png deleted file mode 100644 index 121c4cfe6e..0000000000 Binary files a/Items/Weapons/Melee/WulfrumBlade.png and /dev/null differ diff --git a/Items/Weapons/Melee/WulfrumScrewdriver.cs b/Items/Weapons/Melee/WulfrumScrewdriver.cs new file mode 100644 index 0000000000..2abd5b1b3a --- /dev/null +++ b/Items/Weapons/Melee/WulfrumScrewdriver.cs @@ -0,0 +1,215 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using CalamityMod.Projectiles.Melee; +using Terraria.ModLoader; +using Terraria.Audio; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using System; +using static CalamityMod.CalamityUtils; +using Terraria.DataStructures; +using System.Linq; + +namespace CalamityMod.Items.Weapons.Melee +{ + [LegacyName("WulfrumBlade")] + public class WulfrumScrewdriver : ModItem + { + public static int DefaultTime = 10; + public static readonly SoundStyle ThrustSound = new("CalamityMod/Sounds/Item/WulfrumScrewdriverThrust") { PitchVariance = 0.4f }; + public static readonly SoundStyle ThudSound = new("CalamityMod/Sounds/Item/WulfrumScrewdriverThud") { PitchVariance = 0.2f, Volume = 0.7f }; + public static readonly SoundStyle ScrewGetSound = new("CalamityMod/Sounds/Item/WulfrumScrewdriverScrewGet") { PitchVariance = 0.1f}; + public static readonly SoundStyle ScrewHitSound = new("CalamityMod/Sounds/Item/WulfrumScrewdriverScrewHit") { Volume = 0.7f }; + public static readonly SoundStyle FunnyUltrablingSound = new("CalamityMod/Sounds/Custom/UltrablingHit"); + + public static bool ScrewQeuedForStorage = false; + public bool ScrewStored = false; + public bool ScrewAvailable => ScrewStored && ScrewTimer == 0; + public static Vector3 ScrewStart = new Vector3(0); + public static Vector3 ScrewPosition; + public static Vector2 PrevOffset; + public static float ScrewTimer; + public static float ScrewTime = 40; + public static Asset ScrewTex; + public static Asset ScrewOutlineTex; + public static float ScrewBaseDamageMult = 1f; + public static float ScrewBazingaModeDamageMult = 6.5f; + public static float ScrewBazingaAimAssistAngle = 0.52f; //This may look high but remebmer this is the FULL angle, so it actually checks for half that angle deviation + public static float ScrewBazingaAimAssistReach = 600f; + + public override ModItem Clone(Item item) + { + return base.Clone(item); + + ModItem clone = base.Clone(item); + if (clone is WulfrumScrewdriver a && item.ModItem is WulfrumScrewdriver a2 && a2.ScrewStored) + { + a.ScrewStored = a2.ScrewStored; + } + return clone; + } + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Screwdriver"); + Tooltip.SetDefault("Can be used to rapidly and royally screw over any foe, provided they're weak enough\n" + + "Striking an enemy has a chance to give you a wulfrum screw, that you can throw back at them by right clicking\n" + + "Hitting a flung screw with the screwdriver will boost its damage and speed, sending it hurling forwards at high speeds"); + //Lore about it being mostly a novelty item due to its tendency to break instead of properly screwing stuff in. + //Lore about how it came in when wulfrum was brought over from (elsewhere) and a lot of lower class people saw it as a miracle cheap but resilient amterial + SacrificeTotal = 1; + } + + public override float UseSpeedMultiplier(Player player) + { + //Super speedy + if (player.altFunctionUse == 2) + return 2f; + + return base.UseSpeedMultiplier(player); + } + + public override void SetDefaults() + { + Item.width = 14; + Item.height = 50; + Item.damage = 14; + Item.DamageType = DamageClass.Melee; + Item.useAnimation = DefaultTime + WulfrumScrewdriverProj.MaxTime; + Item.useStyle = ItemUseStyleID.Shoot; + Item.useTime = DefaultTime + WulfrumScrewdriverProj.MaxTime; + Item.useTurn = true; + Item.knockBack = 3.75f; + Item.UseSound = ThrustSound; + Item.autoReuse = true; + Item.value = Item.buyPrice(0, 1, 0, 0); + Item.rare = ItemRarityID.Blue; + Item.noMelee = true; + Item.noUseGraphic = true; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 1f; + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(12). + AddIngredient(). + AddTile(TileID.Anvils). + Register(); + } + + public override void Update(ref float gravity, ref float maxFallSpeed) => ScrewStored = false; + public override void UpdateInventory(Player player) + { + if (player.HeldItem != Item) + ScrewStored = false; + } + + public override void HoldItem(Player player) + { + player.Calamity().mouseWorldListener = true; + + if (Main.myPlayer == player.whoAmI) + { + if (ScrewQeuedForStorage) + { + ScrewStored = true; + ScrewQeuedForStorage = false; + } + + if (ScrewTimer > 0) + ScrewTimer--; + + if (ScrewTimer == 1) + { + Vector2 dustPos = new Vector2(ScrewPosition.X, ScrewPosition.Y) + Main.screenPosition; + int numDust = Main.rand.Next(5, 15); + for (int i = 0; i < numDust; i++) + { + Dust.NewDustPerfect(dustPos, Main.rand.NextBool() ? 246 : 247, Main.rand.NextVector2Circular(1f, 1f), Scale: Main.rand.NextFloat(0.9f, 1.4f)); + } + + SoundEngine.PlaySound(ScrewGetSound); + } + } + + base.HoldItem(player); + } + + public override bool AltFunctionUse(Player player) => ScrewAvailable; + public override bool CanUseItem(Player player) => player.altFunctionUse == 2 ? !Main.projectile.Any(n => n.active && n.owner == player.whoAmI && n.type == ModContent.ProjectileType()) : true; + public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) + { + if (player.altFunctionUse == 2) damage = (int)(damage * ScrewBaseDamageMult); + } + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + if (player.altFunctionUse == 2) + { + Vector2 chuckSpeed = new Vector2(Math.Sign(velocity.X) * 0.4f, -1.24f) + player.velocity / 4f; + + //Prevent it from being thrown at any less than -1f + chuckSpeed.Y = Math.Clamp(chuckSpeed.Y, -1f, 3f); + + int p = Projectile.NewProjectile(source, position, chuckSpeed, ModContent.ProjectileType(), damage, knockback, player.whoAmI); + + ScrewStored = false; + return false; + } + + return base.Shoot(player, source, position, velocity, type, damage, knockback); + } + + public CurveSegment InitialAway = new CurveSegment(SineOutEasing, 0f, 0f, -0.2f, 3); + public CurveSegment AccelerateTowards = new CurveSegment(PolyInEasing, 0.3f, -0.2f, 1.2f, 3); + public CurveSegment Bump1Segment = new CurveSegment(SineBumpEasing, 0.5f, 1f, 0.24f); + public CurveSegment Bump2Segment = new CurveSegment(SineBumpEasing, 0.8f, 1f, -0.1f); + internal float ProgressionOfScrew => PiecewiseAnimation(ScrewTimer / ScrewTime, new CurveSegment[] { InitialAway, AccelerateTowards, Bump1Segment, Bump2Segment }); + + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + if (!ScrewStored) + return; + + Player myPlayer = Main.LocalPlayer; + + if (myPlayer.HeldItem != Item || !myPlayer.active || myPlayer.dead) + return; + + spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, Main.GameViewMatrix.TransformationMatrix); + + if (ScrewTex == null) + ScrewTex = ModContent.Request("CalamityMod/Projectiles/Melee/WulfrumScrew"); + if (ScrewOutlineTex == null) + ScrewOutlineTex = ModContent.Request("CalamityMod/Projectiles/Melee/WulfrumScrewOutline"); + + Texture2D screwTex = ScrewTex.Value; + Texture2D screwOutlineTex = ScrewOutlineTex.Value; + + Vector2 realIdealSpot = myPlayer.MountedCenter + myPlayer.gfxOffY * Vector2.UnitY - Main.screenPosition - Vector2.UnitY * 50f - Vector2.Lerp(myPlayer.velocity, PrevOffset, 0.5f); + realIdealSpot.Y += (float)Math.Sin(Main.GlobalTimeWrappedHourly * 3f) * 5f; + realIdealSpot.X += (float)Math.Sin(Main.GlobalTimeWrappedHourly * 1f) * 7.8f; + + ScrewPosition = new Vector3(realIdealSpot, (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f) * MathHelper.PiOver4 * 0.34f); + + position = Vector2.Lerp(new Vector2(ScrewPosition.X, ScrewPosition.Y), new Vector2(ScrewStart.X, ScrewStart.Y), ProgressionOfScrew); + float rotation = ScrewPosition.Z.AngleLerp(ScrewStart.Z, ProgressionOfScrew); + float outlineOpacity = (float)Math.Pow(1 - ScrewTimer / ScrewTime, 2); + scale = 1.05f + 0.05f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f); + + Main.spriteBatch.Draw(screwOutlineTex, position, null, Color.Lerp(Color.GreenYellow, Color.White, (float)Math.Sin(Main.GlobalTimeWrappedHourly) * 0.5f + 0.5f) * outlineOpacity, rotation, screwOutlineTex.Size() / 2f, scale, 0, 0); + Main.spriteBatch.Draw(screwTex, position, null, Color.White, rotation, screwTex.Size() / 2f, scale, 0, 0); + + spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Main.UIScaleMatrix); + + + PrevOffset = myPlayer.velocity; + base.PostDrawInInventory(spriteBatch, position, frame, drawColor, itemColor, origin, scale); + } + } +} diff --git a/Items/Weapons/Melee/WulfrumScrewdriver.png b/Items/Weapons/Melee/WulfrumScrewdriver.png new file mode 100644 index 0000000000..703a796de6 Binary files /dev/null and b/Items/Weapons/Melee/WulfrumScrewdriver.png differ diff --git a/Items/Weapons/Ranged/WulfrumBlunderbuss.cs b/Items/Weapons/Ranged/WulfrumBlunderbuss.cs new file mode 100644 index 0000000000..8d51763f16 --- /dev/null +++ b/Items/Weapons/Ranged/WulfrumBlunderbuss.cs @@ -0,0 +1,231 @@ +using System; +using System.IO; +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; +using static CalamityMod.CalamityUtils; + +namespace CalamityMod.Items.Weapons.Ranged +{ + [LegacyName("WulfrumBow")] + public class WulfrumBlunderbuss : ModItem + { + public static readonly SoundStyle ShootSound = new("CalamityMod/Sounds/Item/WulfrumBlunderbussFire") { PitchVariance = 0.1f }; + public static readonly SoundStyle ShootAndReloadSound = new("CalamityMod/Sounds/Item/WulfrumBlunderbussFireAndReload") { PitchVariance = 0.1f }; + + public static float MinSpreadDistance = 460f; + public static float MaxSpreadDistance = 60f; + public static float MinSpread = 0.2f; + public static float MaxSpread = 0.6f; + public static float MaxDamageFalloff = 0.9f; + public static int BulletCount = 6; + + public static int ShotsPerScrap = 30; + public int storedScrap = 0; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Blunderbuss"); + Tooltip.SetDefault("Consumes wulfrum scrap or silver coins to fire\n" + + "The shot's spread can be diminished by aiming further away, at the cost of less damage"); + //Funny lore quip about how it can perform ecgologically be recyling the scrap parts of the faulty robots youre forced to shoot at as new ammo. + SacrificeTotal = 1; + } + + public override void SetDefaults() + { + Item.damage = 13; + Item.DamageType = DamageClass.Ranged; + Item.width = 23; + Item.height = 8; + Item.useTime = 55; + Item.useAnimation = 55; + Item.useStyle = ItemUseStyleID.Shoot; + Item.noMelee = true; + Item.knockBack = 2.25f; + Item.value = Item.buyPrice(0, 1, 0, 0); + Item.rare = ItemRarityID.Blue; + Item.UseSound = ShootSound; + Item.autoReuse = false; + Item.shoot = ModContent.ProjectileType(); + Item.shootSpeed = 15f; + Item.Calamity().canFirePointBlankShots = true; + } + + public override void HoldItem(Player player) + { + player.Calamity().mouseWorldListener = true; + } + + public override bool CanUseItem(Player player) => storedScrap > 0 || (player.HasItem(ModContent.ItemType()) || player.HasItem(ItemID.SilverCoin)); + + public override void UseAnimation(Player player) + { + Item.UseSound = ShootSound; + if (storedScrap == 1 && (player.HasItem(ModContent.ItemType()) || player.HasItem(ItemID.SilverCoin))) + Item.UseSound = ShootAndReloadSound; + } + + public override bool? UseItem(Player player) + { + storedScrap--; + + if (storedScrap <= 0) + { + bool ammoConsumed = false; + + if (player.HasItem(ModContent.ItemType())) + { + player.ConsumeItem(ModContent.ItemType()); + ammoConsumed = true; + } + + else if (player.HasItem(ItemID.SilverCoin)) + { + player.ConsumeItem(ItemID.SilverCoin); + ammoConsumed = true; + } + + if (ammoConsumed) + storedScrap = ShotsPerScrap; + } + + return base.UseItem(player); + } + + public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) + { + float aimLenght = (Main.MouseWorld - player.MountedCenter).Length(); + float damageMult = MathHelper.Lerp(1f, MaxDamageFalloff, Math.Clamp(aimLenght - MaxSpreadDistance, 0, MinSpreadDistance - MaxSpreadDistance) / (MinSpreadDistance - MaxSpreadDistance)); + damage = (int)(damage * damageMult); + } + + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) + { + if (player.Calamity().GeneralScreenShakePower < 3f) + player.Calamity().GeneralScreenShakePower = 3f; + + float aimLenght = (Main.MouseWorld - player.MountedCenter).Length(); + float spreadDistance = Math.Clamp(aimLenght - MaxSpreadDistance, 0, MinSpreadDistance - MaxSpreadDistance) / (MinSpreadDistance - MaxSpreadDistance); + float spread = MathHelper.Lerp(MaxSpread, MinSpread, spreadDistance); + + Vector2 nuzzleDir = velocity.SafeNormalize(Vector2.Zero); + + + for (int i = 0; i < BulletCount; i++) + { + Vector2 direction = nuzzleDir.RotatedByRandom(spread); + Vector2 nuzzlePos = player.MountedCenter + direction * 15f; + + Projectile.NewProjectile(player.GetSource_ItemUse_WithPotentialAmmo(Item, Item.useAmmo), nuzzlePos, direction * Item.shootSpeed * Main.rand.NextFloat(1.5f, 2f), type, damage, (int)Item.knockBack, player.whoAmI, 0, 0); + } + + return false; + } + + public override void UseStyle(Player player, Rectangle heldItemFrame) + { + player.direction = Math.Sign((player.Calamity().mouseWorld - player.Center).X); + float itemRotation = player.compositeFrontArm.rotation + MathHelper.PiOver2 * player.gravDir; + + Vector2 itemPosition = player.MountedCenter + itemRotation.ToRotationVector2() * 7f; + Vector2 itemSize = new Vector2(46, 16); + Vector2 itemOrigin = new Vector2(-13, 3); + + CalamityUtils.CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin); + + base.UseStyle(player, heldItemFrame); + } + + public override void UseItemFrame(Player player) + { + player.direction = Math.Sign((player.Calamity().mouseWorld - player.Center).X); + + float animProgress = 1 - player.itemTime / (float)player.itemTimeMax; + float rotation = (player.Center - player.Calamity().mouseWorld).ToRotation() * player.gravDir + MathHelper.PiOver2; + if (animProgress < 0.4f) + rotation += -0.45f * (float)Math.Pow((0.4f - animProgress) / 0.4f, 2) * player.direction; + + player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, rotation); + + //Reloads the gun + if (animProgress > 0.5f) + { + float backArmRotation = rotation + 0.52f * player.direction; + + Player.CompositeArmStretchAmount stretch = ((float)Math.Sin(MathHelper.Pi * (animProgress - 0.5f) / 0.36f)).ToStretchAmount(); + player.SetCompositeArmBack(true, stretch, backArmRotation); + } + } + + public override void PostDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) + { + float barScale = 1.2f; + + var barBG = ModContent.Request("CalamityMod/ExtraTextures/GenericBarBack").Value; + var barFG = ModContent.Request("CalamityMod/ExtraTextures/GenericBarFront").Value; + + Vector2 drawPos = position + Vector2.UnitY * (frame.Height - 2 + 6f) * scale + Vector2.UnitX * (frame.Width - barBG.Width * barScale) * scale * 0.5f; + Rectangle frameCrop = new Rectangle(0, 0, (int)(storedScrap / (float)ShotsPerScrap * barFG.Width), barFG.Height); + Color colorBG = Color.RoyalBlue; + Color colorFG = Color.Lerp(Color.Teal, Color.YellowGreen, storedScrap / (float)ShotsPerScrap); + + spriteBatch.Draw(barBG, drawPos, null, colorBG, 0f, origin, scale * barScale, 0f, 0f); + spriteBatch.Draw(barFG, drawPos, frameCrop, colorFG * 0.8f, 0f, origin, scale * barScale, 0f, 0f); + + DrawBorderStringEightWay(spriteBatch, FontAssets.MouseText.Value, storedScrap.ToString(), drawPos + new Vector2(-3, -3) * scale, Color.GreenYellow, Color.Black, scale); + } + + public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(9). + AddTile(TileID.Anvils). + Register(); + } + + public override void OnCraft(Recipe recipe) + { + storedScrap = ShotsPerScrap; + } + + #region saving the durability + public override ModItem Clone(Item item) + { + ModItem clone = base.Clone(item); + if (clone is WulfrumBlunderbuss a && item.ModItem is WulfrumBlunderbuss a2) + { + a.storedScrap = a2.storedScrap; + } + return clone; + } + + public override void SaveData(TagCompound tag) + { + tag["ammoStored"] = storedScrap; + } + + public override void LoadData(TagCompound tag) + { + storedScrap = tag.GetInt("ammoStored"); + } + + public override void NetSend(BinaryWriter writer) + { + writer.Write(storedScrap); + } + + public override void NetReceive(BinaryReader reader) + { + storedScrap = reader.ReadInt32(); + } + #endregion + } +} diff --git a/Items/Weapons/Ranged/WulfrumBlunderbuss.png b/Items/Weapons/Ranged/WulfrumBlunderbuss.png new file mode 100644 index 0000000000..92018ea6fb Binary files /dev/null and b/Items/Weapons/Ranged/WulfrumBlunderbuss.png differ diff --git a/Items/Weapons/Ranged/WulfrumBow.cs b/Items/Weapons/Ranged/WulfrumBow.cs deleted file mode 100644 index 18f96b284e..0000000000 --- a/Items/Weapons/Ranged/WulfrumBow.cs +++ /dev/null @@ -1,45 +0,0 @@ -using CalamityMod.Items.Materials; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Items.Weapons.Ranged -{ - public class WulfrumBow : ModItem - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Wulfrum Bow"); - SacrificeTotal = 1; - } - - public override void SetDefaults() - { - Item.damage = 12; - Item.DamageType = DamageClass.Ranged; - Item.width = 27; - Item.height = 38; - Item.useTime = 25; - Item.useAnimation = 25; - Item.useStyle = ItemUseStyleID.Shoot; - Item.noMelee = true; - Item.knockBack = 2.25f; - Item.value = Item.buyPrice(0, 1, 0, 0); - Item.rare = ItemRarityID.Blue; - Item.UseSound = SoundID.Item5; - Item.autoReuse = true; - Item.shoot = ProjectileID.PurificationPowder; - Item.shootSpeed = 12f; - Item.useAmmo = AmmoID.Arrow; - Item.Calamity().canFirePointBlankShots = true; - } - - public override void AddRecipes() - { - CreateRecipe(). - AddIngredient(10). - AddTile(TileID.Anvils). - Register(); - } - } -} diff --git a/Items/Weapons/Ranged/WulfrumBow.png b/Items/Weapons/Ranged/WulfrumBow.png deleted file mode 100644 index c935117185..0000000000 Binary files a/Items/Weapons/Ranged/WulfrumBow.png and /dev/null differ diff --git a/Items/Weapons/Rogue/WulfrumKnife.cs b/Items/Weapons/Rogue/WulfrumKnife.cs index 221d095dcf..8c015cb8b3 100644 --- a/Items/Weapons/Rogue/WulfrumKnife.cs +++ b/Items/Weapons/Rogue/WulfrumKnife.cs @@ -5,18 +5,30 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using Terraria.Audio; +using CalamityMod.Particles; namespace CalamityMod.Items.Weapons.Rogue { public class WulfrumKnife : ModItem { + public static readonly SoundStyle Throw3Sound = new("CalamityMod/Sounds/Item/WulfrumKnifeThrowFull") { PitchVariance = 0.4f }; + public static readonly SoundStyle Throw2Sound = new("CalamityMod/Sounds/Item/WulfrumKnifeThrowTwo") { PitchVariance = 0.4f }; + public static readonly SoundStyle Throw1Sound = new("CalamityMod/Sounds/Item/WulfrumKnifeThrowSingle") { PitchVariance = 0.4f }; + public static readonly SoundStyle TileHitSound = new("CalamityMod/Sounds/Item/WulfrumKnifeTileHit", 2) { PitchVariance = 0.4f , MaxInstances = 3}; + public override void SetStaticDefaults() { DisplayName.SetDefault("Wulfrum Knife"); - Tooltip.SetDefault("Stealth strikes make the knife fly further and hit several times at once"); + Tooltip.SetDefault("Fires wulfrum knives in bursts of 3\n" + + "Stealth strikes make the knife fly further and hit several times at once\n" + + "Hold right click to magnetize all nearby fallen knives back to you"); SacrificeTotal = 99; } + public int shootCount = 0; + public bool stealthStrikeStarted = false; + public override void SetDefaults() { Item.width = 22; @@ -24,44 +36,125 @@ namespace CalamityMod.Items.Weapons.Rogue Item.noMelee = true; Item.consumable = true; Item.noUseGraphic = true; - Item.useAnimation = 15; Item.useStyle = ItemUseStyleID.Swing; - Item.useTime = 15; + //Clockwork burst + Item.useAnimation = 10; + Item.useTime = 4; + Item.reuseDelay = 24; + Item.knockBack = 1f; - Item.UseSound = SoundID.Item1; + Item.UseSound = Throw3Sound; Item.autoReuse = true; Item.height = 38; Item.maxStack = 999; Item.value = Item.sellPrice(0, 0, 0, 5); Item.rare = ItemRarityID.Blue; Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 12f; + Item.shootSpeed = 4f; Item.DamageType = RogueDamageClass.Instance; } + //Magnetization + public override void HoldItem(Player player) + { + player.Calamity().rightClickListener = true; + + if (player.Calamity().mouseRight && Main.rand.NextBool(7)) + { + Particle streak = new ManaDrainStreak(player, Main.rand.NextFloat(0.2f, 0.5f), Main.rand.NextVector2CircularEdge(1f, 1f) * Main.rand.NextFloat(170f, 670f), Main.rand.NextFloat(30f, 44f), Color.GreenYellow, Color.DeepSkyBlue, Main.rand.Next(15, 30)); + GeneralParticleHandler.SpawnParticle(streak); + } + } + + public override void GrabRange(Player player, ref int grabRange) + { + float rangeMult = 2f; + if (player.Distance(Item.Center) < 670 && player.HeldItem.type == ModContent.ItemType() && player.Calamity().mouseRight) + rangeMult = 20f; + + grabRange = (int)(grabRange * rangeMult); + + if (rangeMult > 2f && player.Distance(Item.Center) > 50f) + { + Item.velocity = (player.DirectionTo(Item.Center) * -20f); + + if (Main.rand.NextBool(3)) + { + Vector2 dustCenter = Item.Center + Main.rand.NextVector2Circular(4f, 4f); + + Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Item.velocity * Main.rand.NextFloat(0.2f, 0.1f), Scale: Main.rand.NextFloat(1.2f, 1.8f)); + chust.noGravity = true; + } + } + } + + + //While this may look stupid, its necessary because ReuseDelay fucks up the consumption of the item otherwise. + public override bool ConsumeItem(Player player) => shootCount < 0; + public override bool? UseItem(Player player) + { + int placeholderStock = shootCount; + shootCount = -1; + + if (ItemLoader.ConsumeItem(Item, player)) + { + Item.stack--; + + if (Item.stack <= 0) + Item.TurnToAir(); + } + + shootCount = placeholderStock; + + shootCount++; + return base.UseItem(player); + } + + //Random spread + public override void UseAnimation(Player player) + { + shootCount = 0; + stealthStrikeStarted = false; + + Item.UseSound = Throw3Sound; + + if (Item.stack == 2) + Item.UseSound = Throw2Sound; + if (Item.stack == 1) + Item.UseSound = Throw1Sound; + } + public override void ModifyShootStats(Player player, ref Vector2 position, ref Vector2 velocity, ref int type, ref int damage, ref float knockback) + { + bool stealthStrike = player.Calamity().StealthStrikeAvailable() || stealthStrikeStarted; + float spread = stealthStrike ? MathHelper.PiOver4 * 0.04f : MathHelper.PiOver4 * 0.1f; + float speedBoost = stealthStrike ? 1.25f : 1f; + + velocity = velocity.RotatedByRandom(shootCount / 2f * spread) * speedBoost; + } + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - if (player.Calamity().StealthStrikeAvailable()) + if (player.Calamity().StealthStrikeAvailable() || stealthStrikeStarted) { + stealthStrikeStarted = true; + int p = Projectile.NewProjectile(source, position, velocity * 1.3f, ModContent.ProjectileType(), damage, knockback, player.whoAmI); Projectile proj = Main.projectile[p]; if (p.WithinBounds(Main.maxProjectiles)) { proj.Calamity().stealthStrike = true; - proj.penetrate = 4; - proj.usesLocalNPCImmunity = true; - proj.localNPCHitCooldown = 1; + proj.penetrate = 2; } return false; } return true; } + public override void AddRecipes() { CreateRecipe(100). - AddIngredient(). - AddTile(TileID.Anvils). + AddIngredient(). Register(); } } diff --git a/Items/Weapons/Rogue/WulfrumKnife.png b/Items/Weapons/Rogue/WulfrumKnife.png index 94ca6dcea6..c09ca757d6 100644 Binary files a/Items/Weapons/Rogue/WulfrumKnife.png and b/Items/Weapons/Rogue/WulfrumKnife.png differ diff --git a/Items/Weapons/Summon/WulfrumController.cs b/Items/Weapons/Summon/WulfrumController.cs index 0467ead024..d68542410d 100644 --- a/Items/Weapons/Summon/WulfrumController.cs +++ b/Items/Weapons/Summon/WulfrumController.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using System; namespace CalamityMod.Items.Weapons.Summon { @@ -13,7 +14,11 @@ namespace CalamityMod.Items.Weapons.Summon public override void SetStaticDefaults() { DisplayName.SetDefault("Wulfrum Controller"); - Tooltip.SetDefault("Summons a wulfrum droid to fight for you"); + Tooltip.SetDefault("Summons a wulfrum droid to fight for you\n" + + "Hold right click while holding the remote to switch all of your drones into supercharge mode\n" + + "Supercharged droids will stop attacking and focus wulfrum energy onto you\n" + + "The beam provides extra regeneration and defense\n" + + "Can also be used to heal other players by keeping your mouse cursor close enough to them"); SacrificeTotal = 1; } @@ -36,6 +41,12 @@ namespace CalamityMod.Items.Weapons.Summon Item.DamageType = DamageClass.Summon; } + public override void HoldItem(Player player) + { + player.Calamity().rightClickListener = true; + player.Calamity().mouseWorldListener = true; + } + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { if (player.altFunctionUse != 2) @@ -53,9 +64,44 @@ namespace CalamityMod.Items.Weapons.Summon public override void AddRecipes() { CreateRecipe(). - AddIngredient(9). + AddIngredient(9). AddTile(TileID.Anvils). Register(); } } + + public class WulfrumControllerPlayer : ModPlayer + { + public int buffingDrones = 0; + + public override void ResetEffects() + { + } + public override void UpdateDead() + { + buffingDrones = 0; + } + + public override void UpdateLifeRegen() + { + if (buffingDrones > 0) + { + Player.lifeRegen += (int)((1 + Math.Log(buffingDrones) * 2) * 3); + + buffingDrones = 0; + } + } + + public override void PostUpdateMiscEffects() + { + if (buffingDrones > 0 && Main.rand.NextBool(3)) + { + Vector2 dustPos = Player.position + (Player.height * Main.rand.NextFloat(0.7f, 1f) + Player.gfxOffY) * Vector2.UnitY + Vector2.UnitX * Main.rand.NextFloat() * Player.width; + + Dust chust = Dust.NewDustPerfect(dustPos, 274, -Vector2.UnitY * Main.rand.NextFloat(1.4f, 7f) + Player.velocity , Alpha: 100, Scale: Main.rand.NextFloat(1.2f, 1.8f)); + chust.noGravity = true; + chust.noLight = true; + } + } + } } diff --git a/Items/Weapons/Summon/WulfrumController.png b/Items/Weapons/Summon/WulfrumController.png index 7222b843e5..fd16ef10c8 100644 Binary files a/Items/Weapons/Summon/WulfrumController.png and b/Items/Weapons/Summon/WulfrumController.png differ diff --git a/NPCs/NormalNPCs/SuperDummyNPC.cs b/NPCs/NormalNPCs/SuperDummyNPC.cs index 416c95dd69..f1b361ed32 100644 --- a/NPCs/NormalNPCs/SuperDummyNPC.cs +++ b/NPCs/NormalNPCs/SuperDummyNPC.cs @@ -1,6 +1,11 @@ using Microsoft.Xna.Framework; using Terraria.ID; using Terraria.ModLoader; +using Terraria.Audio; +using System; +using ReLogic.Utilities; +using Terraria; + namespace CalamityMod.NPCs.NormalNPCs { public class SuperDummyNPC : ModNPC diff --git a/NPCs/NormalNPCs/WulfrumDrone.cs b/NPCs/NormalNPCs/WulfrumDrone.cs index 7a62faaeb8..10b5e8483c 100644 --- a/NPCs/NormalNPCs/WulfrumDrone.cs +++ b/NPCs/NormalNPCs/WulfrumDrone.cs @@ -8,6 +8,7 @@ using Terraria.ModLoader; using Terraria.ModLoader.Utilities; using Microsoft.Xna.Framework; using System.IO; +using CalamityMod.Sounds; namespace CalamityMod.NPCs.NormalNPCs { @@ -72,7 +73,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.noGravity = true; NPC.noTileCollide = true; NPC.HitSound = SoundID.NPCHit4; - NPC.DeathSound = SoundID.NPCDeath14; + NPC.DeathSound = CommonCalamitySounds.WulfrumNPCDeathSound; Banner = NPC.type; BannerItem = ModContent.ItemType(); NPC.Calamity().VulnerableToSickness = false; @@ -221,7 +222,7 @@ namespace CalamityMod.NPCs.NormalNPCs public override void ModifyNPCLoot(NPCLoot npcLoot) { - npcLoot.Add(ModContent.ItemType(), 1, 1, 3); + npcLoot.Add(ModContent.ItemType(), 1, 1, 3); npcLoot.Add(ModContent.ItemType(), new Fraction(7, 100)); npcLoot.AddIf(info => info.npc.ModNPC().Supercharged, ModContent.ItemType()); } diff --git a/NPCs/NormalNPCs/WulfrumGyrator.cs b/NPCs/NormalNPCs/WulfrumGyrator.cs index 321beb7bb4..5b852a1d14 100644 --- a/NPCs/NormalNPCs/WulfrumGyrator.cs +++ b/NPCs/NormalNPCs/WulfrumGyrator.cs @@ -8,6 +8,7 @@ using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Utilities; +using CalamityMod.Sounds; namespace CalamityMod.NPCs.NormalNPCs { @@ -57,7 +58,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.knockBackResist = 0.15f; NPC.value = Item.buyPrice(0, 0, 1, 15); NPC.HitSound = SoundID.NPCHit4; - NPC.DeathSound = SoundID.NPCDeath14; + NPC.DeathSound = CommonCalamitySounds.WulfrumNPCDeathSound; Banner = NPC.type; BannerItem = ModContent.ItemType(); NPC.Calamity().VulnerableToSickness = false; @@ -201,7 +202,7 @@ namespace CalamityMod.NPCs.NormalNPCs public override void ModifyNPCLoot(NPCLoot npcLoot) { - npcLoot.Add(ModContent.ItemType(), 1, 1, 2); + npcLoot.Add(ModContent.ItemType(), 1, 1, 2); npcLoot.Add(ModContent.ItemType(), new Fraction(7, 100)); npcLoot.AddIf(info => info.npc.ModNPC().Supercharged, ModContent.ItemType()); } diff --git a/NPCs/NormalNPCs/WulfrumHovercraft.cs b/NPCs/NormalNPCs/WulfrumHovercraft.cs index 0c3d439589..d3d7958be7 100644 --- a/NPCs/NormalNPCs/WulfrumHovercraft.cs +++ b/NPCs/NormalNPCs/WulfrumHovercraft.cs @@ -9,6 +9,7 @@ using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Utilities; +using CalamityMod.Sounds; namespace CalamityMod.NPCs.NormalNPCs { @@ -77,7 +78,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.lifeMax = 20; NPC.value = Item.buyPrice(0, 0, 1, 50); NPC.HitSound = SoundID.NPCHit4; - NPC.DeathSound = SoundID.NPCDeath14; + NPC.DeathSound = CommonCalamitySounds.WulfrumNPCDeathSound; NPC.noGravity = true; NPC.noTileCollide = true; Banner = NPC.type; @@ -297,7 +298,7 @@ namespace CalamityMod.NPCs.NormalNPCs public override void ModifyNPCLoot(NPCLoot npcLoot) { - npcLoot.Add(ModContent.ItemType(), 1, 2, 3); + npcLoot.Add(ModContent.ItemType(), 1, 2, 3); npcLoot.Add(ModContent.ItemType(), new Fraction(7, 100)); npcLoot.AddIf(info => info.npc.ModNPC().Supercharged, ModContent.ItemType()); } diff --git a/NPCs/NormalNPCs/WulfrumPylon.cs b/NPCs/NormalNPCs/WulfrumPylon.cs index 80ebc2d7cd..68ad483a8b 100644 --- a/NPCs/NormalNPCs/WulfrumPylon.cs +++ b/NPCs/NormalNPCs/WulfrumPylon.cs @@ -1,4 +1,5 @@ using CalamityMod.Items.Accessories; +using CalamityMod.Items.Accessories.Vanity; using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables.Banners; using Terraria; @@ -9,6 +10,7 @@ using Terraria.ModLoader.Utilities; using Microsoft.Xna.Framework; using System.Collections.Generic; using CalamityMod.World; +using CalamityMod.Sounds; namespace CalamityMod.NPCs.NormalNPCs { @@ -57,7 +59,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.noGravity = false; NPC.noTileCollide = false; NPC.HitSound = SoundID.NPCHit4; - NPC.DeathSound = SoundID.NPCDeath14; + NPC.DeathSound = CommonCalamitySounds.WulfrumNPCDeathSound; Banner = NPC.type; BannerItem = ModContent.ItemType(); NPC.Calamity().VulnerableToSickness = false; @@ -199,8 +201,9 @@ namespace CalamityMod.NPCs.NormalNPCs public override void ModifyNPCLoot(NPCLoot npcLoot) { - npcLoot.Add(ModContent.ItemType(), 1, 2, 3); + npcLoot.Add(ModContent.ItemType(), 1, 2, 3); npcLoot.Add(ModContent.ItemType(), new Fraction(7, 100)); + npcLoot.Add(ModContent.ItemType(), new Fraction(5, 100)); npcLoot.Add(ModContent.ItemType()); } } diff --git a/NPCs/NormalNPCs/WulfrumRover.cs b/NPCs/NormalNPCs/WulfrumRover.cs index 8341a45320..95796577c1 100644 --- a/NPCs/NormalNPCs/WulfrumRover.cs +++ b/NPCs/NormalNPCs/WulfrumRover.cs @@ -9,6 +9,8 @@ using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Utilities; +using CalamityMod.Sounds; +using Terraria.Graphics.Effects; namespace CalamityMod.NPCs.NormalNPCs { @@ -56,7 +58,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.knockBackResist = 0.15f; NPC.value = Item.buyPrice(0, 0, 1, 15); NPC.HitSound = SoundID.NPCHit4; - NPC.DeathSound = SoundID.NPCDeath14; + NPC.DeathSound = CommonCalamitySounds.WulfrumNPCDeathSound; Banner = NPC.type; BannerItem = ModContent.ItemType(); NPC.Calamity().VulnerableToSickness = false; @@ -163,6 +165,8 @@ namespace CalamityMod.NPCs.NormalNPCs { if (Supercharged) { + //old + /* Texture2D shieldTexture = ModContent.Request("CalamityMod/NPCs/NormalNPCs/WulfrumRoverShield").Value; Rectangle frame = shieldTexture.Frame(1, 11, 0, (int)(Main.GlobalTimeWrappedHourly * 8) % 11); spriteBatch.Draw(shieldTexture, @@ -174,12 +178,49 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.scale + (float)Math.Cos(Main.GlobalTimeWrappedHourly) * 0.1f, SpriteEffects.None, 0f); + */ + + //0.6 : The noise upscale + //0.15 the scale its drawn at + float scale = 0.15f + 0.03f * (0.5f + 0.5f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 0.5f + NPC.whoAmI * 0.2f)); + float noiseScale = 0.6f; + + Effect shieldEffect = Terraria.Graphics.Effects.Filters.Scene["RoverDriveShield"].GetShader().Shader; + shieldEffect.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly * 0.24f); + shieldEffect.Parameters["blowUpPower"].SetValue(2.5f); + shieldEffect.Parameters["blowUpSize"].SetValue(0.5f); + shieldEffect.Parameters["noiseScale"].SetValue(noiseScale); + + float baseShieldOpacity = 0.9f + 0.1f * (float)Math.Sin(Main.GlobalTimeWrappedHourly * 2f); + shieldEffect.Parameters["shieldOpacity"].SetValue(baseShieldOpacity); + shieldEffect.Parameters["shieldEdgeBlendStrenght"].SetValue(4f); + + Color blueTint = new Color(51, 102, 255); + Color cyanTint = new Color(71, 202, 255); + Color wulfGreen = new Color(194, 255, 67) * 0.8f; + Color edgeColor = CalamityUtils.MulticolorLerp(Main.GlobalTimeWrappedHourly * 0.2f, blueTint, cyanTint, wulfGreen); + shieldEffect.Parameters["shieldColor"].SetValue(blueTint.ToVector3()); + shieldEffect.Parameters["shieldEdgeColor"].SetValue(edgeColor.ToVector3()); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, shieldEffect, Main.GameViewMatrix.TransformationMatrix); + + if (RoverDrive.NoiseTex == null) + RoverDrive.NoiseTex = ModContent.Request("CalamityMod/ExtraTextures/TechyNoise"); + + Texture2D tex = RoverDrive.NoiseTex.Value; + Vector2 pos = NPC.Center + NPC.gfxOffY * Vector2.UnitY - Main.screenPosition; + Main.spriteBatch.Draw(tex, pos, null, Color.White, 0, tex.Size() / 2f, scale, 0, 0); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.Transform); + } } public override void ModifyNPCLoot(NPCLoot npcLoot) { - npcLoot.Add(ModContent.ItemType(), 1, 1, 2); + npcLoot.Add(ModContent.ItemType(), 1, 1, 2); npcLoot.Add(ModContent.ItemType(), 10); npcLoot.Add(ModContent.ItemType(), new Fraction(7, 100)); npcLoot.AddIf(info => info.npc.ModNPC().Supercharged, ModContent.ItemType()); diff --git a/Particles/DrainLine.png b/Particles/DrainLine.png new file mode 100644 index 0000000000..430443c614 Binary files /dev/null and b/Particles/DrainLine.png differ diff --git a/Particles/DrainLineBloom.png b/Particles/DrainLineBloom.png new file mode 100644 index 0000000000..ab1147d488 Binary files /dev/null and b/Particles/DrainLineBloom.png differ diff --git a/Particles/GeneralParticleHandler.cs b/Particles/GeneralParticleHandler.cs index 827da34280..1c8907b360 100644 --- a/Particles/GeneralParticleHandler.cs +++ b/Particles/GeneralParticleHandler.cs @@ -114,6 +114,11 @@ namespace CalamityMod.Particles public static void DrawAllParticles(SpriteBatch sb) { + if (particles.Count == 0) + return; + + sb.End(); + //Batch the particles to avoid constant restarting of the spritebatch foreach (Particle particle in particles) { @@ -183,6 +188,8 @@ namespace CalamityMod.Particles batchedAlphaBlendParticles.Clear(); batchedNonPremultipliedParticles.Clear(); batchedAdditiveBlendParticles.Clear(); + + sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.Transform); } /// diff --git a/Particles/ManaDrainBlobs.cs b/Particles/ManaDrainBlobs.cs new file mode 100644 index 0000000000..92384644fc --- /dev/null +++ b/Particles/ManaDrainBlobs.cs @@ -0,0 +1,69 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using System; + +namespace CalamityMod.Particles +{ + public class ManaDrainBlob : Particle + { + public override bool SetLifetime => false; + public override string Texture => "CalamityMod/Particles/MicroBloom"; + public override bool UseAdditiveBlend => true; + public override int FrameVariants => 2; + + public Player Owner; + + public ManaDrainBlob(Player owner, Vector2 position, Vector2 speed, float scale, Color color) + { + Owner = owner; + Position = position; + Scale = Math.Min(scale, 1f); + Color = color; + Velocity = speed; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Variant = Main.rand.Next(2); + } + + public override void Update() + { + Scale -= 0.02f; + if (Scale < 0.1f) + Kill(); + + Scale += 0.007f; + + if (Owner != null && Owner.active) + { + Vector2 speedDirection = Position - Owner.Center; + float distanceToOwner = speedDirection.Length(); + float distanceToOwnerTwisted = 100f - distanceToOwner; + + if (distanceToOwnerTwisted > 0f) + Scale -= distanceToOwnerTwisted * 0.0015f; + + speedDirection.Normalize(); + + float dustAcceleration = (1f - Scale) * -20f; + speedDirection *= dustAcceleration; + Velocity = (Velocity * 4f + speedDirection) / 5f; + + + if (distanceToOwner > 16) + { + + + if (Main.rand.NextBool(7)) + { + float velocityMultiplier = MathHelper.Lerp(0.05f, 1f, MathHelper.Clamp((distanceToOwner - 10f) / 40f, 0f, 1f)); + Dust chust = Dust.NewDustPerfect(Position, 15, Velocity * Main.rand.NextFloat(0.7f, 1.2f) * velocityMultiplier, Alpha: 100, Scale: Main.rand.NextFloat(1.2f, 1.8f)); + chust.noGravity = true; + chust.noLight = true; + } + } + } + + Rotation += 0.04f * ((Velocity.X > 0) ? 1f : -1f); + } + } +} diff --git a/Particles/ManaDrainStreak.cs b/Particles/ManaDrainStreak.cs new file mode 100644 index 0000000000..e282a0713c --- /dev/null +++ b/Particles/ManaDrainStreak.cs @@ -0,0 +1,62 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; +using System; + +namespace CalamityMod.Particles +{ + public class ManaDrainStreak : Particle + { + public override string Texture => "CalamityMod/Particles/DrainLineBloom"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + public Player Owner; + public float StartDistanceFromPlayer; + public float FinalDistanceFromPlayer; + public Color StartColor; + public Color EndColor; + + public ManaDrainStreak(Player owner, float thickness, Vector2 startVector, float finalDistance, Color colorStart, Color colorEnd, int lifetime) + { + Owner = owner; + Scale = thickness; + Velocity = Vector2.Zero; + Rotation = startVector.ToRotation(); + StartDistanceFromPlayer = startVector.Length(); + FinalDistanceFromPlayer = finalDistance; + StartColor = colorStart; + EndColor = colorEnd; + Color = colorStart; + Lifetime = lifetime; + } + + public override void Update() + { + if (Owner == null || !Owner.active || Owner.dead) + return; + + Position = Owner.MountedCenter + Rotation.ToRotationVector2() * MathHelper.Lerp(StartDistanceFromPlayer, FinalDistanceFromPlayer, (float)Math.Pow(LifetimeCompletion, 2)); + Color = Color.Lerp(StartColor, EndColor, LifetimeCompletion); + Lighting.AddLight(Position, Color.ToVector3() * 0.2f); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D tex = ModContent.Request(Texture).Value; + + float currentDisplace = MathHelper.Lerp(StartDistanceFromPlayer, FinalDistanceFromPlayer, (float)Math.Pow(LifetimeCompletion, 2)); + float earlierDisplace = MathHelper.Lerp(StartDistanceFromPlayer, FinalDistanceFromPlayer, (float)Math.Pow(Math.Clamp(LifetimeCompletion - 0.2f, 0f, 1f), 2)); + + float lenght = (currentDisplace - earlierDisplace) / tex.Height; + Vector2 scale = new Vector2(Scale, lenght); + + Vector2 origin = new Vector2(tex.Width / 2f, tex.Height); + + spriteBatch.Draw(tex, Position - Main.screenPosition, null, Color, Rotation - MathHelper.PiOver2, origin, scale, SpriteEffects.None, 0); + + } + } +} diff --git a/Particles/MicroBloom.png b/Particles/MicroBloom.png new file mode 100644 index 0000000000..d3aff074d0 Binary files /dev/null and b/Particles/MicroBloom.png differ diff --git a/Particles/TechyHolosquare.png b/Particles/TechyHolosquare.png new file mode 100644 index 0000000000..8811f6eb9e Binary files /dev/null and b/Particles/TechyHolosquare.png differ diff --git a/Particles/TechyHolosquareParticle.cs b/Particles/TechyHolosquareParticle.cs new file mode 100644 index 0000000000..6a2562b249 --- /dev/null +++ b/Particles/TechyHolosquareParticle.cs @@ -0,0 +1,75 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using System; +using Microsoft.Xna.Framework.Graphics; + +namespace CalamityMod.Particles +{ + public class TechyHoloysquareParticle : Particle + { + public override bool SetLifetime => true; + public override string Texture => "CalamityMod/Particles/TechyHolosquare"; + public override bool UseAdditiveBlend => true; + public override bool UseCustomDraw => true; + + internal Rectangle Frame; + public float Opacity; + public float OpacityMult; + + public TechyHoloysquareParticle(Vector2 position, Vector2 speed, float scale, Color color, int lifetime, float opacity = 1f) + { + Position = position; + Scale = scale; + Color = color; + Velocity = speed; + Rotation = Main.rand.NextFloat(MathHelper.TwoPi); + Opacity = opacity; + OpacityMult = opacity; + Variant = Main.rand.Next(6); + Lifetime = lifetime; + + switch (Variant) + { + case 0: + Frame = new Rectangle(8, 0, 6, 6); + break; + case 1: + Frame = new Rectangle(6, 8, 10, 6); + break; + case 2: + Frame = new Rectangle(4, 16, 14, 8); + break; + case 3: + Frame = new Rectangle(2, 26, 18, 10); + break; + case 4: + Frame = new Rectangle(2, 38, 18, 8); + break; + case 5: + Frame = new Rectangle(6, 48, 12, 12); + break; + } + } + + public override void Update() + { + Opacity = (float)Math.Pow(LifetimeCompletion, 0.5f) * OpacityMult; + Lighting.AddLight(Position, Color.ToVector3() * Opacity); + Rotation = Velocity.ToRotation(); + + Velocity *= 0.875f; + Scale *= 0.96f; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D baseTex = GeneralParticleHandler.GetTexture(Type); + + CalamityUtils.DrawChromaticAberration(Vector2.UnitX.RotatedBy(Rotation), 1.5f, delegate (Vector2 offset, Color colorMod) + { + spriteBatch.Draw(baseTex, Position + offset - Main.screenPosition, Frame, Color.MultiplyRGB(colorMod) * Opacity, Rotation, Frame.Size() / 2, Scale / 2f, SpriteEffects.None, 0); + }); + } + } +} diff --git a/Particles/WulfrumBastionParts.png b/Particles/WulfrumBastionParts.png new file mode 100644 index 0000000000..1ef46a52d2 Binary files /dev/null and b/Particles/WulfrumBastionParts.png differ diff --git a/Particles/WulfrumBastionPartsParticle.cs b/Particles/WulfrumBastionPartsParticle.cs new file mode 100644 index 0000000000..a96dc95a37 --- /dev/null +++ b/Particles/WulfrumBastionPartsParticle.cs @@ -0,0 +1,126 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using System; +using Microsoft.Xna.Framework.Graphics; + +namespace CalamityMod.Particles +{ + public class WulfrumBastionPartsParticle : Particle + { + public override bool SetLifetime => true; + public override string Texture => "CalamityMod/Particles/WulfrumBastionParts"; + public override bool UseCustomDraw => true; + + internal Rectangle Frame; + internal Vector2 DestinationOffset; + public Vector2 Offset; + public float RotationOffset; + public Player Owner; + public float TimeOffset; + public int AnimationTime; + public float LifetimeCompletionAdjusted => Math.Clamp((Time - Lifetime * TimeOffset) / (float)AnimationTime, 0, 1f); + + public WulfrumBastionPartsParticle(Player owner, int variant, int lifetime) + { + Offset = (-Vector2.UnitY * (40f + Main.rand.NextFloat(34f))).RotatedByRandom(MathHelper.PiOver4 * 0.04f); + Owner = owner; + Position = Owner.Center; + Scale = 1f; + Color = Color.White; + Velocity = Vector2.Zero; + Rotation = 0f; + RotationOffset = Main.rand.NextFloat(MathHelper.PiOver4 * 0f) * (Main.rand.NextBool() ? -1f : 1f); + Lifetime = lifetime; + AnimationTime = (int)(lifetime * 0.44f); + + switch (variant) + { + case 0: //Back leg + Frame = new Rectangle(46, 4, 10, 14); + DestinationOffset = new Vector2(7f, 16f); //1f? + TimeOffset = 0; + break; + case 1: //Front leg + Frame = new Rectangle(30, 4, 12, 14); + DestinationOffset = new Vector2(-4f, 16f); + TimeOffset = 0; + break; + case 2: //Bottom torso + Frame = new Rectangle(4, 30, 22, 12); + DestinationOffset = new Vector2(1f, 5f); + TimeOffset = 0.15f; + break; + case 3: //Torso + Frame = new Rectangle(30, 24, 30, 16); + DestinationOffset = new Vector2(1f, -3f); + TimeOffset = 0.35f; + break; + case 4: //Helmet + Frame = new Rectangle(2, 2, 22, 24); + DestinationOffset = new Vector2(-1f, -15f); + TimeOffset = 0.43f; + break; + case 5: //Fusion Cannon + Frame = new Rectangle(14, 46, 38, 18); + DestinationOffset = new Vector2(-2f, -2f); + TimeOffset = 0.6f; + break; + } + + Origin = Frame.Size() / 2; + + //Fusion Cannon rotates around the shoulder + if (variant == 5) + Origin.X -= 12f; + + } + + public override void Update() + { + Rotation = MathHelper.Lerp(RotationOffset, 0f, (float)Math.Pow(LifetimeCompletionAdjusted, 0.8f)); + + //The gun + if (TimeOffset == 0.6f) + Rotation = (Owner.Calamity().mouseWorld - Owner.Center).ToRotation() + (Owner.direction < 0 ? MathHelper.Pi : 0f); + + + if (Owner.dead || !Owner.active) + Kill(); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + if (Owner.dead || !Owner.active) + return; + + Texture2D baseTex = GeneralParticleHandler.GetTexture(Type); + Vector2 center = new Vector2((int)Owner.MountedCenter.X, (int)(Owner.MountedCenter.Y + Owner.gfxOffY)); + Vector2 currentOffset = Vector2.Lerp(Offset, Vector2.Zero, (float)Math.Pow(LifetimeCompletionAdjusted, 0.8f)); + //Vector2 currentOffset = Vector2.Lerp(Offset, Vector2.Zero, 1f); + Color lightColor = Lighting.GetColor(Owner.Center.ToTileCoordinates()); + + Vector2 realDestinationOffset = new Vector2(DestinationOffset.X * Owner.direction, DestinationOffset.Y * Owner.gravDir); + Vector2 realCurrentOffset = new Vector2(currentOffset.X * Owner.direction, currentOffset.Y * Owner.gravDir); + + + SpriteEffects spriteEffect = SpriteEffects.None; + Vector2 origin = Origin; + + if (Owner.direction < 0) + { + spriteEffect = SpriteEffects.FlipHorizontally; + origin.X = Frame.Width - Origin.X; + } + + + float opacity = Math.Clamp(LifetimeCompletionAdjusted * 4f ,0f, 1f); + + spriteBatch.Draw(baseTex, center + realDestinationOffset + realCurrentOffset - Main.screenPosition, Frame, lightColor * opacity, Rotation, origin, Scale, spriteEffect, 0); + } + } +} + + + + diff --git a/Particles/WulfrumDroidEmote.cs b/Particles/WulfrumDroidEmote.cs new file mode 100644 index 0000000000..e4548ed528 --- /dev/null +++ b/Particles/WulfrumDroidEmote.cs @@ -0,0 +1,50 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class WulfrumDroidEmote : Particle + { + public override string Texture => "CalamityMod/Particles/WulfrumDroidEmotes"; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + public Rectangle Frame; + + public WulfrumDroidEmote(Vector2 position, Vector2 velocity, int lifeTime, float scale = 1f, int variant = -1) + { + Position = position; + Velocity = velocity; + Color = Color.White; + Scale = scale; + Lifetime = lifeTime; + Rotation = velocity.ToRotation() + MathHelper.PiOver2; + + if (variant == -1) + variant = Main.rand.Next(15); + + Frame = new Rectangle(16 * (variant % 8), 16 * (variant / 8), 16, 16); + } + + public override void Update() + { + Velocity *= 0.96f; + Scale *= 0.97f; + + Color lightColor = Frame.Y > 0 ? new Color(112, 244, 244) : new Color(194, 255, 62); + Lighting.AddLight(Position, lightColor.ToVector3()); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D emoteTexture = ModContent.Request(Texture).Value; + Vector2 origin = new Vector2(Frame.Width / 2f, Frame.Height); + float opacity = 1 - (float)Math.Pow(LifetimeCompletion, 4f); + + spriteBatch.Draw(emoteTexture, Position - Main.screenPosition, Frame, Color * opacity, Rotation, origin, Scale, SpriteEffects.None, 0); + } + } +} diff --git a/Particles/WulfrumDroidEmotes.png b/Particles/WulfrumDroidEmotes.png new file mode 100644 index 0000000000..8528061bbb Binary files /dev/null and b/Particles/WulfrumDroidEmotes.png differ diff --git a/Particles/WulfrumDroidSweatEmote.cs b/Particles/WulfrumDroidSweatEmote.cs new file mode 100644 index 0000000000..1b6ecbc941 --- /dev/null +++ b/Particles/WulfrumDroidSweatEmote.cs @@ -0,0 +1,46 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class WulfrumDroidSweatEmote : Particle + { + public override string Texture => "CalamityMod/Particles/WulfrumDroidSweatEmote"; + public override bool UseCustomDraw => true; + public override bool SetLifetime => true; + + public WulfrumDroidSweatEmote(Vector2 position, Vector2 velocity, int lifeTime, float scale = 1f) + { + Position = position; + Velocity = velocity; + Color = Color.White; + Scale = scale; + Lifetime = lifeTime; + Rotation = velocity.ToRotation() + MathHelper.PiOver2; + + } + + public override void Update() + { + Velocity *= 0.96f; + Scale *= 0.97f; + Velocity.Y += 0.06f; + + Lighting.AddLight(Position, new Color(194, 255, 62).ToVector3()); + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D emoteTexture = ModContent.Request(Texture).Value; + Vector2 origin = new Vector2(emoteTexture.Width / 2f, emoteTexture.Height / 2f); + float opacity = 1 - (float)Math.Pow(LifetimeCompletion, 4f); + + SpriteEffects effect = Velocity.X > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; + + spriteBatch.Draw(emoteTexture, Position - Main.screenPosition, null, Color * opacity, Rotation, origin, Scale, effect, 0); + } + } +} diff --git a/Particles/WulfrumDroidSweatEmote.png b/Particles/WulfrumDroidSweatEmote.png new file mode 100644 index 0000000000..8cb5164da2 Binary files /dev/null and b/Particles/WulfrumDroidSweatEmote.png differ diff --git a/Particles/WulfrumHat.png b/Particles/WulfrumHat.png new file mode 100644 index 0000000000..1a11e8e9ef Binary files /dev/null and b/Particles/WulfrumHat.png differ diff --git a/Particles/WulfrumHatParticle.cs b/Particles/WulfrumHatParticle.cs new file mode 100644 index 0000000000..8c18326e97 --- /dev/null +++ b/Particles/WulfrumHatParticle.cs @@ -0,0 +1,55 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using System; +using Microsoft.Xna.Framework.Graphics; + +namespace CalamityMod.Particles +{ + public class WulfrumHatParticle : Particle + { + public override bool SetLifetime => true; + public override string Texture => "CalamityMod/Particles/WulfrumHat"; + public override bool UseCustomDraw => true; + + public int Direction ; + + public WulfrumHatParticle(Player owner, Vector2 velocity, int lifetime) + { + Position = owner.Center - Vector2.UnitY * 20f;; + Direction = owner.direction; + Scale = 1f; + Color = Color.White; + Velocity = velocity; + Rotation = 0f; + Lifetime = lifetime; + } + + public override void Update() + { + Rotation += 0.05f * Math.Sign(Velocity.X); + + Velocity *= 0.95f; + Velocity.Y += 0.22f; + } + + public override void CustomDraw(SpriteBatch spriteBatch) + { + Texture2D baseTex = GeneralParticleHandler.GetTexture(Type); + Color lightColor = Lighting.GetColor(Position.ToTileCoordinates()); + + SpriteEffects spriteEffect = SpriteEffects.None; + if (Direction < 0) + { + spriteEffect = SpriteEffects.FlipHorizontally; + } + + float opacity = Math.Clamp(1 - (float)Math.Pow(LifetimeCompletion , 3f), 0f, 1f); + spriteBatch.Draw(baseTex, Position - Main.screenPosition, null, lightColor * opacity, Rotation, baseTex.Size()/2f, Scale, spriteEffect, 0); + } + } +} + + + + diff --git a/Projectiles/Magic/WulfrumBolt.cs b/Projectiles/Magic/WulfrumBolt.cs index d64fbaf61b..006b461854 100644 --- a/Projectiles/Magic/WulfrumBolt.cs +++ b/Projectiles/Magic/WulfrumBolt.cs @@ -1,16 +1,53 @@ +using System; +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; +using static Terraria.ModLoader.ModContent; +using CalamityMod.Particles; + namespace CalamityMod.Projectiles.Magic { public class WulfrumBolt : ModProjectile { + public ref float OriginalRotation => ref Projectile.ai[0]; + public NPC Target + { + get + { + if (Projectile.ai[1] < 0 || Projectile.ai[1] > Main.maxNPCs) + return null; + + return Main.npc[(int)Projectile.ai[1]]; + } + set + { + if (value == null) + Projectile.ai[1] = -1; + else + Projectile.ai[1] = value.whoAmI; + } + } + + public static float MaxDeviationAngle = MathHelper.PiOver4; + public static float HomingRange = 250; + public static float HomingAngle = MathHelper.PiOver4 * 1.65f; + + internal PrimitiveTrail TrailDrawer; + internal Color PrimColorMult = Color.White; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; public override void SetStaticDefaults() { DisplayName.SetDefault("Bolt"); + + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; } public override void SetDefaults() @@ -19,38 +56,181 @@ namespace CalamityMod.Projectiles.Magic Projectile.height = 8; Projectile.friendly = true; Projectile.ignoreWater = true; - Projectile.penetrate = 2; + Projectile.penetrate = 1; Projectile.DamageType = DamageClass.Magic; + Projectile.timeLeft = 140; + Projectile.extraUpdates = 2; + } + + public NPC FindTarget() + { + float bestScore = 0; + NPC bestTarget = null; + + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC potentialTarget = Main.npc[i]; + + if (!potentialTarget.CanBeChasedBy(null, false)) + continue; + + float distance = potentialTarget.Distance(Projectile.Center); + float angle = Projectile.velocity.AngleBetween((potentialTarget.Center - Projectile.Center)); + + float extraDistance = potentialTarget.width / 2 + potentialTarget.height / 2; + + if (distance - extraDistance < HomingRange && angle < HomingAngle / 2f) + { + if (!Collision.CanHit(Projectile.Center, 1, 1, potentialTarget.Center, 1, 1) && extraDistance < distance) + continue; + + float attemptedScore = EvaluatePotentialTarget(distance - extraDistance, angle / 2f); + if (attemptedScore > bestScore) + { + bestTarget = potentialTarget; + bestScore = attemptedScore; + } + } + } + return bestTarget; + + } + + public float EvaluatePotentialTarget(float distance, float angle) + { + float score = 1 - distance / HomingRange * 0.5f; + + score += (1 - Math.Abs(angle) / (HomingAngle / 2f)) * 0.5f; + + return score; } public override void AI() { - Lighting.AddLight(Projectile.Center, 0f, (255 - Projectile.alpha) * 0.1f / 255f, 0f); - for (int num151 = 0; num151 < 3; num151++) + if (Projectile.timeLeft == 140) { - int num154 = 14; - int num155 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width - num154 * 2, Projectile.height - num154 * 2, 61, 0f, 0f, 100, default, 3f); - Main.dust[num155].noGravity = true; - Main.dust[num155].noLight = true; - Main.dust[num155].velocity *= 0.1f; - Main.dust[num155].velocity += Projectile.velocity * 0.5f; + if (OriginalRotation == 0) + { + OriginalRotation = Projectile.velocity.ToRotation(); + Projectile.rotation = OriginalRotation; + } + Target = null; } - if (Main.rand.NextBool(8)) + else { - int num156 = 16; - int num157 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width - num156 * 2, Projectile.height - num156 * 2, 61, 0f, 0f, 100, default, 2.25f); - Main.dust[num157].velocity *= 0.25f; - Main.dust[num157].noLight = true; - Main.dust[num157].velocity += Projectile.velocity * 0.5f; - return; + Target = FindTarget(); } + + Lighting.AddLight(Projectile.Center, (Color.GreenYellow * 0.8f).ToVector3() * 0.5f); + + if (Target != null) + { + float distanceFromTarget = (Target.Center - Projectile.Center).Length(); + + Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow(( 1 - distanceFromTarget / HomingRange), 2)); + } + + Projectile.velocity *= 0.983f; + Projectile.velocity = Projectile.rotation.ToRotationVector2() * Projectile.velocity.Length(); + + //Blast off. + if (Projectile.timeLeft == 140) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity * 1f; + + for (int i = 0; i < 5; i++) + { + Dust chust = Dust.NewDustPerfect(dustCenter, 15, Projectile.velocity.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(0.2f, 0.5f), Scale: Main.rand.NextFloat(1.2f, 1.8f)); + chust.noGravity = true; + } + } + + if (Projectile.timeLeft <= 137) + { + if (Main.rand.NextBool()) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Projectile.velocity * Main.rand.NextFloat(0.2f, 0.5f), Scale: Main.rand.NextFloat(1.2f, 1.8f)); + chust.noGravity = true; + } + + if (Main.rand.NextBool(4)) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust largeDust = Dust.NewDustPerfect(dustCenter, 257, -Projectile.velocity * Main.rand.NextFloat(0.2f, 0.4f), Scale: Main.rand.NextFloat(0.4f, 1f)); + largeDust.noGravity = true; + largeDust.noLight = true; + } + + if (Main.rand.NextBool(5)) + { + Vector2 center = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(4, 10); + GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(center, velocity, Main.rand.NextFloat(1f, 2f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25)); + + } + } + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = (float)Math.Sqrt(1 - completionRatio); + return Color.DeepSkyBlue.MultiplyRGB(PrimColorMult) * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + return 9.4f; } public override bool PreDraw(ref Color lightColor) { - Texture2D tex = ModContent.Request(Texture).Value; - Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/BasicTrail")); + + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 3.5f, delegate (Vector2 offset, Color colorMod) + { + PrimColorMult = colorMod; + + TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30); + }); + + + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + return false; } + + public override void Kill(int timeLeft) + { + SoundEngine.PlaySound(WulfrumProsthesis.HitSound, Projectile.Center); + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + + return base.OnTileCollide(oldVelocity); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + int numParticles = Main.rand.Next(4, 7); + for (int i = 0; i < numParticles; i++) + { + Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(3, 14); + GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(target.Center, velocity, Main.rand.NextFloat(2.5f, 3f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25)); + } + } } } diff --git a/Projectiles/Magic/WulfrumManaDrain.cs b/Projectiles/Magic/WulfrumManaDrain.cs new file mode 100644 index 0000000000..253f020e3c --- /dev/null +++ b/Projectiles/Magic/WulfrumManaDrain.cs @@ -0,0 +1,159 @@ +using System; +using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using ReLogic.Utilities; +using Terraria; +using Terraria.Audio; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Magic +{ + public class WulfrumManaDrain : ModProjectile + { + private SlotId SuccSoundSlot; + public Player Owner => Main.player[Projectile.owner]; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public ref float Timer => ref Projectile.ai[0]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Mana Drain"); + } + + public override void SetDefaults() + { + Projectile.width = 8; + Projectile.height = 8; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.penetrate = -1; + Projectile.DamageType = DamageClass.Magic; + Projectile.timeLeft = 2; + } + public override bool ShouldUpdatePosition() => false; + public override bool? CanDamage() => false; + + + + public override void AI() + { + Owner.itemTime = 2; + Owner.itemAnimation = 2; + + if (!Owner.Calamity().mouseRight || Owner.dead || Owner.frozen || !Owner.active || Owner.statMana == Owner.statManaMax2) + return; + + //Once again the sound volume scaling does NOT work for whatever reason? Help. + + if (!SoundEngine.TryGetActiveSound(SuccSoundSlot, out var idleSoundOut) || !idleSoundOut.IsPlaying) + { + SuccSoundSlot = SoundEngine.PlaySound(WulfrumProsthesis.SuckSound with { Volume = WulfrumProsthesis.SuckSound.Volume * 0.01f ,IsLooped = true }, Owner.Center); + + } + + else if (idleSoundOut != null) + { + idleSoundOut.Position = Owner.Center; + idleSoundOut.Volume = Math.Clamp((Timer / 30f) + 0.001f, 0f, 1f) * 100f; + } + + + Projectile.timeLeft = 2; + Projectile.Center = Owner.MountedCenter; + Projectile.velocity = (Owner.Calamity().mouseWorld - Owner.MountedCenter).SafeNormalize(Vector2.One); + + if (Main.rand.NextBool(6)) + { + Particle streak = new ManaDrainStreak(Owner, Main.rand.NextFloat(0.2f, 0.5f), Projectile.velocity.RotatedByRandom(MathHelper.PiOver2 * 0.6f) * Main.rand.NextFloat(70f, 150f), Main.rand.NextFloat(30f, 44f), Color.GreenYellow, Color.DeepSkyBlue, Main.rand.Next(13, 20)); + GeneralParticleHandler.SpawnParticle(streak); + } + + NPC target = GetSuccTarget(); + + if (target != null) + { + Owner.GetModPlayer().ManaDrainActive = true; + + if (!Main.rand.NextBool(3)) + { + Vector2 center = target.Center; + center.X += (float)Main.rand.Next(-100, 100) * 0.1f; + center.Y += (float)Main.rand.Next(-100, 100) * 0.1f; + + center += target.velocity; + //Drain ganggg + + Particle bloom = new ManaDrainBlob(Owner, center, Main.rand.NextVector2Circular(4f, 4f), Main.rand.NextFloat(0.7f, 0.9f), Color.DeepSkyBlue); + GeneralParticleHandler.SpawnParticle(bloom); + } + } + + Timer++; + } + + public NPC GetSuccTarget() + { + float collisionPoint = 0f; + + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC struckNPC = Main.npc[i]; + + if (!struckNPC.active || struckNPC.townNPC || struckNPC.friendly) + continue; + + float distance = struckNPC.Distance(Projectile.Center); + float extraDistance = struckNPC.width / 2 + struckNPC.height / 2; + + if (distance - extraDistance < 400f) + { + if (!Collision.CheckAABBvLineCollision(struckNPC.Hitbox.TopLeft(), struckNPC.Hitbox.Size(), Owner.MountedCenter, Owner.MountedCenter + Projectile.velocity * 400f, 110f, ref collisionPoint)) + continue; + + if (!Collision.CanHit(Projectile.Center, 1, 1, struckNPC.Center, 1, 1) && extraDistance < distance) + continue; + + return struckNPC; + } + } + + return null; + } + + public override void Kill(int timeLeft) + { + if (Timer > 2) + { + NPC target = GetSuccTarget(); + + if (target != null) + { + int particlesCount = Main.rand.Next(5, 10); + for (int i = 0; i < particlesCount; i++) + { + Vector2 center = target.Center; + center.X += (float)Main.rand.Next(-100, 100) * 0.1f; + center.Y += (float)Main.rand.Next(-100, 100) * 0.1f; + + center += target.velocity; + //Drain ganggg + + Particle bloom = new ManaDrainBlob(Owner, center, Main.rand.NextVector2Circular(4f, 4f), Main.rand.NextFloat(0.76f, 1f), Color.DeepSkyBlue); + GeneralParticleHandler.SpawnParticle(bloom); + } + } + } + + if (SoundEngine.TryGetActiveSound(SuccSoundSlot, out var soundOut)) + { + soundOut.Stop(); + + SoundEngine.PlaySound(WulfrumProsthesis.SuckStopSound with { Volume = WulfrumProsthesis.SuckStopSound.Volume * Timer / 30f}, Projectile.Center); + + } + } + } +} diff --git a/Projectiles/Melee/CnidarianJellyfishOnTheString.cs b/Projectiles/Melee/CnidarianJellyfishOnTheString.cs index e3178d3559..63f0e509fd 100644 --- a/Projectiles/Melee/CnidarianJellyfishOnTheString.cs +++ b/Projectiles/Melee/CnidarianJellyfishOnTheString.cs @@ -11,21 +11,10 @@ using Terraria.ID; using Terraria.ModLoader; using static CalamityMod.CalamityUtils; using static Terraria.ModLoader.ModContent; +using CalamityMod.DataStructures; namespace CalamityMod.Projectiles.Melee { - public class VerletSimulatedSegment - { - public Vector2 position, oldPosition; - public bool locked; - - public VerletSimulatedSegment(Vector2 _position, bool _locked = false) - { - position = _position; - oldPosition = _position; - locked = _locked; - } - } public class CnidarianJellyfishOnTheString : ModProjectile { @@ -216,39 +205,7 @@ namespace CalamityMod.Projectiles.Melee Segments[0].oldPosition = Segments[0].position; Segments[0].position = Projectile.Center; - //https://youtu.be/PGk0rnyTa1U?t=400 we use verlet integration chains here - foreach (VerletSimulatedSegment segment in Segments) - { - if (!segment.locked) - { - Vector2 positionBeforeUpdate = segment.position; - - segment.position += (segment.position - segment.oldPosition); // This adds conservation of energy to the segments. This makes it super bouncy and shouldnt be used but it's really funny - segment.position += Vector2.UnitY * 0.3f; //=> This adds gravity to the segments. - - segment.oldPosition = positionBeforeUpdate; - } - } - - for (int k = 0; k < 10; k++) - { - for (int j = 0; j < SegmentCount - 1; j++) - { - VerletSimulatedSegment pointA = Segments[j]; - VerletSimulatedSegment pointB = Segments[j + 1]; - Vector2 segmentCenter = (pointA.position + pointB.position) / 2f; - Vector2 segmentDirection = Utils.SafeNormalize(pointA.position - pointB.position, Vector2.UnitY); - - if (!pointA.locked) - pointA.position = segmentCenter + segmentDirection * SegmentDistance / 2f; - - if (!pointB.locked) - pointB.position = segmentCenter - segmentDirection * SegmentDistance / 2f; - - Segments[j] = pointA; - Segments[j + 1] = pointB; - } - } + Segments = VerletSimulatedSegment.SimpleSimulation(Segments, SegmentDistance); Projectile.netUpdate = true; Projectile.netSpam = 0; diff --git a/Projectiles/Melee/WulfrumScrew.cs b/Projectiles/Melee/WulfrumScrew.cs new file mode 100644 index 0000000000..56ee83223f --- /dev/null +++ b/Projectiles/Melee/WulfrumScrew.cs @@ -0,0 +1,253 @@ +using System; +using CalamityMod.Items.Weapons.Melee; +using CalamityMod.Items.Weapons.Rogue; +using CalamityMod.Sounds; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.Audio; +using Terraria.Graphics.Effects; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; +using static Terraria.ModLoader.ModContent; + +namespace CalamityMod.Projectiles.Melee +{ + public class WulfrumScrew : ModProjectile + { + internal PrimitiveTrail TrailDrawer; + internal Color PrimColorMult = Color.White; + + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Screw"); + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 60; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public static int Lifetime = 950; + public float LifetimeCompletion => MathHelper.Clamp((Lifetime - Projectile.timeLeft) / (float)Lifetime, 0f, 1f); + public ref float BazingaTime => ref Projectile.ai[0]; + public ref float AlreadyBazinged => ref Projectile.ai[1]; + public static float BazingaTimeMax = 120f; + public float BazingaTimeCompletion => (BazingaTimeMax - BazingaTime) / BazingaTimeMax; + public float FadePercent => Math.Clamp(Projectile.timeLeft / FadeTime, 0f, 1f); + public static float FadeTime => 30f; + public Player Owner => Main.player[Projectile.owner]; + + public static Asset SheenTex; + + public override void SetDefaults() + { + Projectile.width = 22; + Projectile.height = 22; + Projectile.friendly = true; + Projectile.penetrate = 1; + Projectile.DamageType = DamageClass.Melee; + + Projectile.timeLeft = Lifetime; + Projectile.extraUpdates = 3; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 1; + Projectile.scale = 1.2f; + } + + public override void AI() + { + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; + Projectile.velocity *= 0.998f; + + if (Projectile.timeLeft < Lifetime - 100 && BazingaTime == 0) + Projectile.velocity.Y += 0.01f; + + + if (BazingaTime > 0) + { + BazingaTime--; + + if (BazingaTime == BazingaTimeMax - 2) + Owner.Calamity().GeneralScreenShakePower = 0; + + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Projectile.velocity * Main.rand.NextFloat(0.6f, 1.5f), Scale: Main.rand.NextFloat(1f, 1.4f)); + chust.noGravity = true; + + if (!Main.rand.NextBool(5)) + chust.noLightEmittence = true; + } + + if (Projectile.Center.Distance(Owner.MountedCenter) > 1300 && Projectile.timeLeft > FadeTime) + Projectile.timeLeft = (int)FadeTime; + + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + SoundEngine.PlaySound(WulfrumKnife.TileHitSound, Projectile.Center); + + + bool screwRegained = false; + + //50% chance to gain back the screw on kill. + if (target.life - damage <= 0) + { + if (Main.rand.NextBool() && Main.myPlayer == Owner.whoAmI) + { + if (Owner.HeldItem.ModItem is WulfrumScrewdriver screwdriver && !screwdriver.ScrewStored) + { + WulfrumScrewdriver.ScrewStart = new Vector3(Projectile.Center + Projectile.velocity.SafeNormalize(Vector2.Zero) * 4f * Main.rand.NextFloat() - Main.screenPosition, Projectile.rotation); + WulfrumScrewdriver.ScrewTimer = WulfrumScrewdriver.ScrewTime; + screwdriver.ScrewStored = true; + + SoundEngine.PlaySound(SoundID.Item156); + + screwRegained = true; + } + } + } + + if (!screwRegained && Main.netMode != NetmodeID.Server) + { + Gore screwGore = Gore.NewGorePerfect(Projectile.GetSource_Death(), Projectile.position, -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(4f, 6f) + Projectile.velocity * 0.7f, Mod.Find("WulfrumScrewGore").Type); + screwGore.timeLeft = 20; + } + + //Screenstun + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + + if (BazingaTime > 0) + SoundEngine.PlaySound(CommonCalamitySounds.WulfrumNPCDeathSound, Projectile.Center); + + SoundEngine.PlaySound(WulfrumKnife.TileHitSound, Projectile.Center); + if (Main.netMode != NetmodeID.Server) + { + Gore screwGore = Gore.NewGorePerfect(Projectile.GetSource_Death(), Projectile.position, -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(1f, 3f) + Projectile.velocity * 0.7f, Mod.Find("WulfrumScrewGore").Type); + screwGore.timeLeft = 20; + } + + + + return base.OnTileCollide(oldVelocity); + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = (float)Math.Pow(1 - completionRatio, 2) * (float)Math.Pow(1 - BazingaTimeCompletion, 0.4f); + return Color.GreenYellow.MultiplyRGB(PrimColorMult) * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + return 9.4f; + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D tex = ModContent.Request(Texture).Value; + + float distanceFromAim = Projectile.Center.ShortestDistanceToLine(Owner.MountedCenter, Main.MouseWorld); + float distanceFromPlayerAcrossSightLine = (Owner.MountedCenter - Projectile.Center.ClosestPointOnLine(Owner.MountedCenter, Main.MouseWorld)).Length(); + + float opacity = MathHelper.Clamp(1f - distanceFromAim / 90f, 0f, 1f) * (1f - Math.Clamp((float)Math.Pow(distanceFromPlayerAcrossSightLine / 300f, 9f) , 0f, 1f)); + + //Draw a sightline before the player hits it. + if (Owner.whoAmI == Main.myPlayer && BazingaTime == 0 && opacity > 0) + { + Texture2D empty = Request("CalamityMod/Projectiles/InvisibleProj").Value; + + //Setup the laser sights effect. + Effect laserScopeEffect = Filters.Scene["PixelatedSightLine"].GetShader().Shader; + laserScopeEffect.Parameters["sampleTexture2"].SetValue(ModContent.Request("CalamityMod/ExtraTextures/CertifiedCrustyNoise").Value); + laserScopeEffect.Parameters["noiseOffset"].SetValue(Main.GameUpdateCount * -0.003f); + + laserScopeEffect.Parameters["mainOpacity"].SetValue((float)Math.Pow(opacity , 0.5f)); //Opacity increases as the screw gets close to the cursor + + laserScopeEffect.Parameters["Resolution"].SetValue(new Vector2(700f * 0.2f)); + laserScopeEffect.Parameters["laserAngle"].SetValue((Main.MouseWorld - Owner.MountedCenter).ToRotation() * -1); + + laserScopeEffect.Parameters["laserWidth"].SetValue(0.0025f + (float)Math.Pow(opacity, 5) * ((float)Math.Sin(Main.GlobalTimeWrappedHourly * 3f) * 0.002f + 0.002f)); + laserScopeEffect.Parameters["laserLightStrenght"].SetValue(3f); + + laserScopeEffect.Parameters["color"].SetValue(Color.GreenYellow.ToVector3()); + laserScopeEffect.Parameters["darkerColor"].SetValue(Color.Black.ToVector3()); + laserScopeEffect.Parameters["bloomSize"].SetValue(0.06f + (1 - opacity) * 0.1f); + laserScopeEffect.Parameters["bloomMaxOpacity"].SetValue(0.4f); + laserScopeEffect.Parameters["bloomFadeStrenght"].SetValue(3f); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, laserScopeEffect, Main.GameViewMatrix.TransformationMatrix); + + Main.EntitySpriteDraw(empty, Projectile.Center - Main.screenPosition, null, Color.White, 0, empty.Size() / 2f, 700f, 0, 0); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + } + + + + opacity = BazingaTimeCompletion * FadePercent; + + if (BazingaTime > 0) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + //Draw a trail + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/BasicTrail")); + + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1f, delegate (Vector2 offset, Color colorMod) + { + PrimColorMult = colorMod; + + TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30); + }); + + //Draw the screw with chroma abberation + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 3f, delegate (Vector2 offset, Color colorMod) + { + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition + offset, null, Color.GreenYellow.MultiplyRGB(colorMod) * opacity, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + }); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor) * (1 - opacity), Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + + //Very, very, very, unfortunate spritebatch restart x2, but draw a sheen texture like zenith. + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + + if (SheenTex == null) + SheenTex = ModContent.Request("CalamityMod/Particles/HalfStar"); + Texture2D shineTex = SheenTex.Value; + Vector2 shineScale = new Vector2(1f, 3f - opacity * 2f); + + Main.EntitySpriteDraw(shineTex, Projectile.Center - Main.screenPosition, null, Color.GreenYellow * (1 - opacity) * 0.7f, MathHelper.PiOver2, shineTex.Size() / 2f, shineScale * Projectile.scale, SpriteEffects.None, 0); + + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + } + + else + { + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor) * FadePercent, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + } + return false; + } + + } +} diff --git a/Projectiles/Melee/WulfrumScrew.png b/Projectiles/Melee/WulfrumScrew.png new file mode 100644 index 0000000000..a5d96ffcff Binary files /dev/null and b/Projectiles/Melee/WulfrumScrew.png differ diff --git a/Projectiles/Melee/WulfrumScrewOutline.png b/Projectiles/Melee/WulfrumScrewOutline.png new file mode 100644 index 0000000000..ac652ebe6b Binary files /dev/null and b/Projectiles/Melee/WulfrumScrewOutline.png differ diff --git a/Projectiles/Melee/WulfrumScrewdriverProj.cs b/Projectiles/Melee/WulfrumScrewdriverProj.cs new file mode 100644 index 0000000000..fa322d2306 --- /dev/null +++ b/Projectiles/Melee/WulfrumScrewdriverProj.cs @@ -0,0 +1,237 @@ +using CalamityMod.Particles; +using CalamityMod.Items.Weapons.Melee; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.IO; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using static Terraria.ModLoader.ModContent; +using Terraria.Audio; +using static CalamityMod.CalamityUtils; +using ReLogic.Content; +using Terraria.Graphics.Shaders; +using Terraria.Graphics.Effects; + +namespace CalamityMod.Projectiles.Melee +{ + public class WulfrumScrewdriverProj : ModProjectile + { + public override string Texture => "CalamityMod/Items/Weapons/Melee/WulfrumScrewdriver"; + public float Timer => MaxTime - Projectile.timeLeft; + public float LifetimeCompletion => Timer / (float)MaxTime; + + public static int MaxTime = 14; + public ref float EndLag => ref Projectile.ai[0]; + public ref float TrueDirection => ref Projectile.ai[1]; + public Player Owner => Main.player[Projectile.owner]; + + public static Asset SmearTex; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Screwdriver"); + } + public override void SetDefaults() + { + Projectile.DamageType = DamageClass.Melee; + Projectile.width = 14; + Projectile.height = 50; + Projectile.tileCollide = false; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.ownerHitCheck = true; + } + + public override bool ShouldUpdatePosition() => false; + public CurveSegment ThrustSegment = new CurveSegment(LinearEasing, 0f, 0f, 1f, 3); + public CurveSegment HoldSegment = new CurveSegment(SineBumpEasing, 0.2f, 1f, 0.2f); + public CurveSegment RetractSegment = new CurveSegment(PolyOutEasing, 0.76f, 1f, -0.8f, 3); + public CurveSegment BumpSegment = new CurveSegment(SineBumpEasing, 0.9f, 0.2f, 0.15f); + internal float DistanceFromPlayer => PiecewiseAnimation(LifetimeCompletion, new CurveSegment[] { ThrustSegment, HoldSegment, RetractSegment, BumpSegment }); + public Vector2 OffsetFromPlayer => Projectile.velocity * DistanceFromPlayer * 12f; + + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + //The hitbox is simplified into a line collision. + float collisionPoint = 0f; + float bladeLenght = 78f * Projectile.scale; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Owner.Center + OffsetFromPlayer, Owner.Center + OffsetFromPlayer + (Projectile.velocity * bladeLenght), 24, ref collisionPoint); + } + + public override void AI() + { + if (EndLag == 0) //Initialization + { + EndLag = (float)Math.Max(Owner.ActiveItem().useTime - MaxTime, 1); + Projectile.timeLeft = MaxTime; + TrueDirection = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero).ToRotation(); //Store this for the screw hit + Projectile.velocity = Owner.SafeDirectionTo(Owner.Calamity().mouseWorld, Vector2.Zero).RotatedByRandom(MathHelper.PiOver4 * 0.15f); + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; + } + + //Manage position and rotation + Projectile.Center = Owner.Center + OffsetFromPlayer ; + Projectile.scale = 1f + (float)Math.Sin(LifetimeCompletion * MathHelper.Pi) * 0.2f; //SWAGGER + + //Make the owner look like theyre holding the sword bla bla + Owner.heldProj = Projectile.whoAmI; + Owner.direction = Math.Sign(Projectile.velocity.X); + Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, Projectile.velocity.ToRotation() * Owner.gravDir - MathHelper.PiOver2); + Owner.itemTime = 2; + Owner.itemAnimation = 2; + + + //Check for launchable screws. + for (int i = 0; i < Main.maxProjectiles; i++) + { + Projectile proj = Main.projectile[i]; + if (proj.ModProjectile != null && proj.owner == Projectile.owner && proj.ModProjectile is WulfrumScrew screw && screw.BazingaTime == 0) + { + float collisionPoint = 0f; + float bladeLenght = 86f * Projectile.scale; + if (Collision.CheckAABBvLineCollision(proj.Hitbox.TopLeft(), proj.Hitbox.Size(), Owner.Center + OffsetFromPlayer, Owner.Center + OffsetFromPlayer + (Projectile.velocity * bladeLenght), 34, ref collisionPoint)) + { + Vector2 thudVelocity = TrueDirection.ToRotationVector2() * 6f; + NPC potentialAimAssist = FindTarget(); + if (potentialAimAssist != null) + thudVelocity = (potentialAimAssist.Center - proj.Center).SafeNormalize(Vector2.Zero) * 6f; + + screw.BazingaTime = WulfrumScrew.BazingaTimeMax; + proj.velocity = thudVelocity; + if (screw.AlreadyBazinged == 0) + proj.damage = (int)(proj.damage * WulfrumScrewdriver.ScrewBazingaModeDamageMult); + proj.timeLeft = WulfrumScrew.Lifetime; + proj.knockBack *= 2.5f; + screw.AlreadyBazinged++; + + SoundEngine.PlaySound(WulfrumScrewdriver.ScrewHitSound, Projectile.Center); + + if (screw.AlreadyBazinged > 2) + SoundEngine.PlaySound(WulfrumScrewdriver.FunnyUltrablingSound, Projectile.Center); + + + if (Main.myPlayer == proj.owner) + { + Owner.Calamity().GeneralScreenShakePower = 6f; + } + + return; + } + } + } + } + + public NPC FindTarget() + { + float bestScore = 0; + NPC bestTarget = null; + + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC potentialTarget = Main.npc[i]; + + if (!potentialTarget.CanBeChasedBy(null, false)) + continue; + + float distance = potentialTarget.Distance(Projectile.Center); + float angle = TrueDirection.ToRotationVector2().AngleBetween((potentialTarget.Center - Projectile.Center)); + + float extraDistance = potentialTarget.width / 2 + potentialTarget.height / 2; + + if (distance - extraDistance < WulfrumScrewdriver.ScrewBazingaAimAssistReach && angle < WulfrumScrewdriver.ScrewBazingaAimAssistAngle / 2f) + { + if (!Collision.CanHit(Projectile.Center, 1, 1, potentialTarget.Center, 1, 1) && extraDistance < distance) + continue; + + float attemptedScore = EvaluatePotentialTarget(distance - extraDistance, angle / 2f); + if (attemptedScore > bestScore) + { + bestTarget = potentialTarget; + bestScore = attemptedScore; + } + } + } + return bestTarget; + } + + public float EvaluatePotentialTarget(float distance, float angle) + { + float score = 1 - distance / WulfrumScrewdriver.ScrewBazingaAimAssistReach * 0.2f; + //Prioritize angle over distance + score += (1 - Math.Abs(angle) / (WulfrumScrewdriver.ScrewBazingaAimAssistAngle / 2f)) * 0.8f; + + return score; + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + SoundEngine.PlaySound(WulfrumScrewdriver.ThudSound, target.Center); + Projectile.timeLeft = 0; + + //Chance to gain a screw + if (Main.rand.NextBool(5) && Main.myPlayer == Owner.whoAmI) + { + if (Owner.HeldItem.ModItem is WulfrumScrewdriver screwdriver && !screwdriver.ScrewStored) + { + WulfrumScrewdriver.ScrewStart = new Vector3(target.Center + Projectile.velocity * 14f * Main.rand.NextFloat() - Main.screenPosition, Main.rand.NextFloat(MathHelper.PiOver2 - MathHelper.PiOver4)); + WulfrumScrewdriver.ScrewTimer = WulfrumScrewdriver.ScrewTime; + WulfrumScrewdriver.ScrewQeuedForStorage = true; + + SoundEngine.PlaySound(SoundID.Item156); + } + } + + //Dust + for (int k = 0; k < 4; k++) + { + Dust.NewDustPerfect(Projectile.Center + Projectile.velocity * 70f, 16, Projectile.velocity.RotatedByRandom(0.2f) * Main.rand.NextFloat(6), 0, default, Main.rand.NextFloat(0.7f, 1f)); + } + + + base.OnHitNPC(target, damage, knockback, crit); + } + + public override void Kill(int timeLeft) + { + if (Projectile.numHits == 0) + { + Owner.itemTime = (int)EndLag; + Owner.itemAnimation = (int)EndLag; + } + + //Go into jojo spam mode if you hit an enemy + else + { + Owner.itemTime = 0; + Owner.itemAnimation = 0; + } + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D tex = ModContent.Request(Texture).Value; + + if (SmearTex == null) + SmearTex = ModContent.Request("CalamityMod/ExtraTextures/MediumLongThrust"); + Texture2D smearTex = SmearTex.Value; + + Vector2 drawOrigin = new Vector2(tex.Width / 2f, tex.Height); + Vector2 scale = new Vector2(Math.Abs((float)Math.Sin(LifetimeCompletion * MathHelper.TwoPi * 0.5f)), 1f); + + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, lightColor, Projectile.rotation, drawOrigin, scale * Projectile.scale, 0f, 0); + + if (LifetimeCompletion < 0.6f) + { + int frameCount = (int)Math.Floor((LifetimeCompletion / 0.6f) * 3f); + Rectangle frame = new Rectangle(0, (smearTex.Height / 3) * frameCount, smearTex.Width, smearTex.Height / 3); + float opacity = 1 - (float)Math.Pow(LifetimeCompletion / 0.6f, 0.5f); + + Main.spriteBatch.Draw(smearTex, Projectile.Center + Projectile.velocity * 67f - Main.screenPosition, frame, Color.White * opacity, Projectile.rotation, frame.Size() / 2f, 0.9f, 0, 0); + } + return false; + } + } +} diff --git a/Projectiles/Ranged/WulfrumScrapBullet.cs b/Projectiles/Ranged/WulfrumScrapBullet.cs new file mode 100644 index 0000000000..4b90752c01 --- /dev/null +++ b/Projectiles/Ranged/WulfrumScrapBullet.cs @@ -0,0 +1,72 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; +using static Terraria.ModLoader.ModContent; + +namespace CalamityMod.Projectiles.Ranged +{ + public class WulfrumScrapBullet : ModProjectile + { + internal PrimitiveTrail TrailDrawer; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("High Speed Scrap"); + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetDefaults() + { + Projectile.width = 16; + Projectile.height = 16; + Projectile.DamageType = DamageClass.Ranged; + Projectile.friendly = true; + Projectile.penetrate = 1; + Projectile.timeLeft = 100; + Projectile.extraUpdates = 4; + Projectile.alpha = 255; + } + + public override void AI() + { + Projectile.velocity *= 0.95f; + Lighting.AddLight(Projectile.Center, (Color.PaleGoldenrod * 0.8f).ToVector3() * 0.5f); + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + + return base.OnTileCollide(oldVelocity); + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = (float)Math.Sqrt(Projectile.timeLeft / 100f); + return Color.PaleGoldenrod * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + return (1 - completionRatio) * 6.4f; + } + + public override bool PreDraw(ref Color lightColor) + { + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/BasicTrail")); + TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition, 30); + + return false; + } + } +} diff --git a/Projectiles/Rogue/WulfrumKnifeProj.cs b/Projectiles/Rogue/WulfrumKnifeProj.cs index 5183317fda..1b69740c73 100644 --- a/Projectiles/Rogue/WulfrumKnifeProj.cs +++ b/Projectiles/Rogue/WulfrumKnifeProj.cs @@ -1,37 +1,93 @@ -using CalamityMod.Items.Weapons.Rogue; +using System; +using CalamityMod.Items.Weapons.Rogue; +using CalamityMod.Particles; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; +using static Terraria.ModLoader.ModContent; +using Terraria.Audio; + namespace CalamityMod.Projectiles.Rogue { public class WulfrumKnifeProj : ModProjectile { + internal PrimitiveTrail TrailDrawer; + internal Color PrimColorMult = Color.White; public override string Texture => "CalamityMod/Items/Weapons/Rogue/WulfrumKnife"; public override void SetStaticDefaults() { DisplayName.SetDefault("Knife"); + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; } + public static int Lifetime = 950; + public float LifetimeCompletion => MathHelper.Clamp((Lifetime - Projectile.timeLeft) / (float)Lifetime, 0f, 1f); + public float StealthEffectOpacity => MathHelper.Clamp(1 - LifetimeCompletion, 0f, 1f); + public override void SetDefaults() { Projectile.width = 12; Projectile.height = 12; Projectile.friendly = true; - Projectile.penetrate = 2; - Projectile.aiStyle = 2; - Projectile.timeLeft = 600; - AIType = ProjectileID.ThrowingKnife; + Projectile.penetrate = 1; Projectile.DamageType = RogueDamageClass.Instance; + + Projectile.timeLeft = Lifetime; + Projectile.extraUpdates = 5; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 1; } - public override bool PreDraw(ref Color lightColor) + + public override void AI() { - Texture2D tex = ModContent.Request(Texture).Value; - Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); - return false; + Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2; + Projectile.velocity *= 0.998f; + + if (Projectile.timeLeft < Lifetime - 100) + Projectile.velocity.Y += 0.01f; + + + if (!Projectile.Calamity().stealthStrike) + { + if (Main.rand.NextBool(10)) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Projectile.velocity * Main.rand.NextFloat(0.6f, 1.5f), Scale: Main.rand.NextFloat(1f, 1.4f)); + chust.noGravity = true; + + if (!Main.rand.NextBool(5)) + chust.noLightEmittence = true; + } + } + + else + { + Lighting.AddLight(Projectile.Center, (Main.rand.NextBool() ? Color.GreenYellow : Color.DeepSkyBlue).ToVector3() * StealthEffectOpacity); + + if (Main.rand.NextBool(7)) + { + Vector2 center = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(4, 10); + GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(center, velocity, Main.rand.NextFloat(1f, 2f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25, StealthEffectOpacity)); + + } + + if (Main.rand.NextBool(8)) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Projectile.velocity * Main.rand.NextFloat(0.6f, 1.5f), Scale: Main.rand.NextFloat(1f, 1.4f)); + chust.noGravity = true; + chust.noLightEmittence = true; + } + } } public override void Kill(int timeLeft) @@ -41,5 +97,71 @@ namespace CalamityMod.Projectiles.Rogue Item.NewItem(Projectile.GetSource_DropAsItem(), (int)Projectile.position.X, (int)Projectile.position.Y, Projectile.width, Projectile.height, ModContent.ItemType()); } } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + SoundEngine.PlaySound(WulfrumKnife.TileHitSound, Projectile.Center); + + return base.OnTileCollide(oldVelocity); + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = (float)Math.Pow(1 - completionRatio, 2) * StealthEffectOpacity; + return Color.GreenYellow.MultiplyRGB(PrimColorMult) * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + return 9.4f; + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D tex = ModContent.Request(Texture).Value; + float opacitey = StealthEffectOpacity; + + if (Projectile.Calamity().stealthStrike) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/BasicTrail")); + + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1f, delegate (Vector2 offset, Color colorMod) + { + PrimColorMult = colorMod; + + TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30); + }); + + + + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 3f, delegate (Vector2 offset, Color colorMod) + { + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition + offset, null, Color.GreenYellow.MultiplyRGB(colorMod) * opacitey, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + }); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + + opacitey = MathHelper.Clamp(LifetimeCompletion * 8f, 0f, 1f); + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor) * opacitey, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + } + + else + { + opacitey = MathHelper.Clamp(LifetimeCompletion * 15f, 0f, 1f); + + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor) * opacitey, Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); + } + return false; + } + } } diff --git a/Projectiles/Summon/WulfrumBoltMinion.cs b/Projectiles/Summon/WulfrumBoltMinion.cs deleted file mode 100644 index bf1b684315..0000000000 --- a/Projectiles/Summon/WulfrumBoltMinion.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -namespace CalamityMod.Projectiles.Summon -{ - public class WulfrumBoltMinion : ModProjectile - { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Bolt"); - ProjectileID.Sets.MinionShot[Projectile.type] = true; - } - - public override void SetDefaults() - { - Projectile.width = 8; - Projectile.height = 8; - Projectile.friendly = true; - Projectile.ignoreWater = true; - Projectile.penetrate = 1; - Projectile.extraUpdates = 1; - Projectile.minionSlots = 0f; - Projectile.minion = true; - Projectile.DamageType = DamageClass.Summon; - } - - public override void AI() - { - Lighting.AddLight(Projectile.Center, 0f, (255 - Projectile.alpha) * 0.1f / 255f, 0f); - for (int num151 = 0; num151 < 3; num151++) - { - int num154 = 14; - int num155 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width - num154 * 2, Projectile.height - num154 * 2, 61, 0f, 0f, 100, default, 3f); - Main.dust[num155].noGravity = true; - Main.dust[num155].noLight = true; - Main.dust[num155].velocity *= 0.1f; - Main.dust[num155].velocity += Projectile.velocity * 0.5f; - } - if (Main.rand.NextBool(8)) - { - int num156 = 16; - int num157 = Dust.NewDust(new Vector2(Projectile.position.X, Projectile.position.Y), Projectile.width - num156 * 2, Projectile.height - num156 * 2, 61, 0f, 0f, 100, default, 2.25f); - Main.dust[num157].velocity *= 0.25f; - Main.dust[num157].noLight = true; - Main.dust[num157].velocity += Projectile.velocity * 0.5f; - return; - } - } - - public override bool PreDraw(ref Color lightColor) - { - Texture2D tex = ModContent.Request(Texture).Value; - Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation, tex.Size() / 2f, Projectile.scale, SpriteEffects.None, 0); - return false; - } - } -} diff --git a/Projectiles/Summon/WulfrumDroid.cs b/Projectiles/Summon/WulfrumDroid.cs index 83bedff251..3cd62c32bb 100644 --- a/Projectiles/Summon/WulfrumDroid.cs +++ b/Projectiles/Summon/WulfrumDroid.cs @@ -4,12 +4,94 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using System; +using Terraria.Audio; +using CalamityMod.Particles; +using CalamityMod.Items.Weapons.Summon; +using CalamityMod.Items.Accessories; +using Microsoft.Xna.Framework.Graphics; +using Terraria.Graphics.Shaders; +using Terraria.Graphics.Effects; +using static Terraria.ModLoader.ModContent; +using ReLogic.Content; namespace CalamityMod.Projectiles.Summon { public class WulfrumDroid : ModProjectile { - public float dust = 0f; + public static readonly SoundStyle HelloSound = new("CalamityMod/Sounds/Custom/WulfrumDroidSpawnBeep") { PitchVariance = 0.4f }; + public static readonly SoundStyle PewSound = new("CalamityMod/Sounds/Custom/WulfrumDroidFire") { PitchVariance = 0.4f, Volume = 0.6f, MaxInstances = 0 }; + public static readonly SoundStyle RandomChirpSound = new("CalamityMod/Sounds/Custom/WulfrumDroidChirp", 4) { PitchVariance = 0.3f }; + public static readonly SoundStyle HurrySound = new("CalamityMod/Sounds/Custom/WulfrumDroidHurry", 2) { PitchVariance = 0.3f }; + public static readonly SoundStyle RepairSound = new("CalamityMod/Sounds/Custom/WulfrumDroidRepair") { Volume = 0.8f, PitchVariance = 0.3f, SoundLimitBehavior = SoundLimitBehavior.IgnoreNew }; + public int NewSoundDelay + { + get + { + int minionCount = 1; + for (int i = 0; i < Main.maxProjectiles; i++) + { + Projectile proj = Main.projectile[i]; + if (proj.active && proj.owner == Owner.whoAmI && proj.type == Type && proj.whoAmI != Projectile.whoAmI) + { + minionCount++; + } + } + + return (int)(Main.rand.Next(340, 1460) * minionCount); + } + } + + internal PrimitiveTrail TrailDrawer; + internal Color PrimColorMult; + public Player healedPlayer; + + public float Initialized = 0f; + public static float AggroRange = 450f; + public static float ShootDelay = 110f; //This is the max delay, but it can b e shorter + public enum BehaviorState { Aggressive, Idle }; + public BehaviorState State + { + get => (BehaviorState)(int)Projectile.ai[0]; + + set => Projectile.ai[0] = (float)value; + } + + public ref float ShootTimer => ref Projectile.ai[1]; + + public ref float AyeAyeCaptainCooldown => ref Projectile.localAI[0]; + public ref float NuzzleFlashTime => ref Projectile.localAI[1]; + + public NPC Target + { + get + { + NPC target = null; + + if (Owner.HasMinionAttackTargetNPC) + target = CheckNPCTargetValidity(Main.npc[Owner.MinionAttackTargetNPC]); + + if (target != null) + return target; + + else + { + for (int npcIndex = 0; npcIndex < Main.npc.Length; npcIndex++) + { + target = CheckNPCTargetValidity(Main.npc[npcIndex]); + if (target != null) + return target; + } + } + + return null; + } + } + + public Player Owner => Main.player[Projectile.owner]; + + public static Asset SheenTex; + public override void SetStaticDefaults() { @@ -33,176 +115,386 @@ namespace CalamityMod.Projectiles.Summon Projectile.timeLeft *= 5; Projectile.minion = true; Projectile.DamageType = DamageClass.Summon; + Initialized = 0f; + } + + //Returns the npc if targetable, returns null if not + public NPC CheckNPCTargetValidity(NPC potentialTarget) + { + if (potentialTarget.CanBeChasedBy(this, false)) + { + float targetDist = Vector2.Distance(potentialTarget.Center, Projectile.Center); + + if ((targetDist < AggroRange) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, potentialTarget.position, potentialTarget.width, potentialTarget.height)) + { + return potentialTarget; + } + } + + return null; } public override void AI() { Player player = Main.player[Projectile.owner]; CalamityPlayer modPlayer = player.Calamity(); - if (dust == 0f) + + //Spawn dust + if (Initialized == 0f) { - int dustAmt = 36; + int dustAmt = Main.rand.Next(10, 16); for (int dustIndex = 0; dustIndex < dustAmt; dustIndex++) { - Vector2 source = Vector2.Normalize(Projectile.velocity) * new Vector2((float)Projectile.width / 2f, (float)Projectile.height) * 0.75f; - source = source.RotatedBy((double)((float)(dustIndex - (dustAmt / 2 - 1)) * MathHelper.TwoPi / (float)dustAmt), default) + Projectile.Center; - Vector2 dustVel = source - Projectile.Center; - int green = Dust.NewDust(source + dustVel, 0, 0, 61, dustVel.X * 1.1f, dustVel.Y * 1.1f, 100, default, 1.4f); - Main.dust[green].noGravity = true; - Main.dust[green].noLight = true; - Main.dust[green].velocity = dustVel; + Vector2 direction = Main.rand.NextVector2CircularEdge(1f, 1f); + + Dust wishyDust = Dust.NewDustPerfect(Projectile.Center + direction * Main.rand.NextFloat(1f, 8f), 229, Alpha : 100, Scale: Main.rand.NextFloat(1f, 1.4f)); + wishyDust.noGravity = true; + wishyDust.noLight = true; + wishyDust.velocity = direction * Main.rand.NextFloat(2f, 4); } - dust += 1f; + + SoundEngine.PlaySound(HelloSound, Projectile.Center); + Projectile.soundDelay = NewSoundDelay; + ShootTimer = ShootDelay; + + Initialized ++; } + + bool buffMode = Owner.Calamity().mouseRight && Owner.HeldItem.type == ModContent.ItemType(); + + //Do frame stuff i guess + Projectile.frame = Projectile.frame % (Main.projFrames[Projectile.type] / 2); + Projectile.frameCounter++; if (Projectile.frameCounter > 8) { Projectile.frame++; Projectile.frameCounter = 0; } - if (Projectile.frame >= Main.projFrames[Projectile.type]) + if (Projectile.frame >= Main.projFrames[Projectile.type] / 2) { Projectile.frame = 0; } - bool correctMinion = Projectile.type == ModContent.ProjectileType(); + + if (buffMode) + Projectile.frame += Main.projFrames[Projectile.type] / 2; + + + //Buff stuff player.AddBuff(ModContent.BuffType(), 3600); - if (correctMinion) - { - if (player.dead) - { - modPlayer.wDroid = false; - } - if (modPlayer.wDroid) - { - Projectile.timeLeft = 2; - } - } + if (player.dead) + modPlayer.wDroid = false; + if (modPlayer.wDroid) + Projectile.timeLeft = 2; Projectile.MinionAntiClump(); - Vector2 targetVector = Projectile.position; - float range = 450f; - bool foundTarget = false; - int targetIndex = -1; - if (player.HasMinionAttackTargetNPC) + + + //Lets only recalculate our target once per frame aight + NPC targetCache = buffMode ? null : Target; + float separationAnxietyDist = targetCache != null ? 1000f : 500f; //Have more lenience on how far away from the player should the drone return if theyre attacking an enemy + + if (AyeAyeCaptainCooldown > 0) + AyeAyeCaptainCooldown--; + else if (buffMode) { - NPC npc = Main.npc[player.MinionAttackTargetNPC]; - if (npc.CanBeChasedBy((object) this, false)) - { - float targetDist = Vector2.Distance(npc.Center, Projectile.Center); - if ((!foundTarget && targetDist < range) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height)) - { - range = targetDist; - targetVector = npc.Center; - foundTarget = true; - targetIndex = npc.whoAmI; - } - } - } - if (!foundTarget) - { - for (int npcIndex = 0; npcIndex < Main.npc.Length; ++npcIndex) - { - NPC npc = Main.npc[npcIndex]; - if (npc.CanBeChasedBy((object) this, false)) - { - float targetDist = Vector2.Distance(npc.Center, Projectile.Center); - if ((!foundTarget && targetDist < range) && Collision.CanHitLine(Projectile.position, Projectile.width, Projectile.height, npc.position, npc.width, npc.height)) - { - range = targetDist; - targetVector = npc.Center; - foundTarget = true; - targetIndex = npcIndex; - } - } - } - } - float separationAnxietyDist = 500f; - if (foundTarget) - separationAnxietyDist = 1000f; - if (Vector2.Distance(player.Center, Projectile.Center) > separationAnxietyDist) - { - Projectile.ai[0] = 1f; - Projectile.netUpdate = true; - } - if (Projectile.ai[0] == 1f) - Projectile.tileCollide = false; - if (foundTarget && Projectile.ai[0] == 0f) - { - Vector2 targetPos = targetVector - Projectile.Center; - float targetDist = targetPos.Length(); - targetPos.Normalize(); - if (targetDist > 200f) - { - float speed = 6f; - Vector2 goToTarget = targetPos * speed; - Projectile.velocity.X = (Projectile.velocity.X * 40f + goToTarget.X) / 41f; - Projectile.velocity.Y = (Projectile.velocity.Y * 40f + goToTarget.Y) / 41f; - } - else if (Projectile.velocity.Y > -1f) - Projectile.velocity.Y -= 0.1f; + SoundEngine.PlaySound(RepairSound, Projectile.Center); + AyeAyeCaptainCooldown = 100; } + + if (Projectile.soundDelay > 0) + Projectile.soundDelay--; else { - if (!Collision.CanHitLine(Projectile.Center, 1, 1, player.Center, 1, 1)) - Projectile.ai[0] = 1f; - float returnSpeed = 6f; - if (Projectile.ai[0] == 1f) - returnSpeed = 15f; - Vector2 playerVec = player.Center - Projectile.Center + new Vector2(0f, -60f); + SoundEngine.PlaySound(RandomChirpSound with { Volume = RandomChirpSound.Volume * Main.rand.NextFloat(0.5f, 1f) }, Projectile.Center); + Projectile.soundDelay = NewSoundDelay; + + if (targetCache == null) + { + Vector2 emoteDirection = -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2 * 0.7f); + + Particle emote = new WulfrumDroidEmote(Projectile.Center + emoteDirection * 10f, emoteDirection * Main.rand.NextFloat(3f, 5f), Main.rand.Next(30, 65), Main.rand.NextFloat(1.4f, 2f)); + GeneralParticleHandler.SpawnParticle(emote); + } + } + + + //Return to the player if too far away from them. Hurry up droids! + if (Vector2.Distance(Owner.Center, Projectile.Center) > separationAnxietyDist) + { + State = BehaviorState.Idle; + Projectile.netUpdate = true; + + //play the hurry sound once and never again until it is reset + if (Projectile.soundDelay < 10000) + SoundEngine.PlaySound(HurrySound, Projectile.Center); + + Projectile.soundDelay = 10010; + + if (Main.rand.NextBool(7)) + { + Vector2 emoteDirection = -Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2 * 0.7f); + emoteDirection.X -= Math.Sign(Projectile.velocity.X) * 1f; + + Particle emote = new WulfrumDroidSweatEmote(Projectile.Center + emoteDirection * 10f, emoteDirection * Main.rand.NextFloat(3f, 5f), Main.rand.Next(20, 35), Main.rand.NextFloat(1.4f, 2f)); + GeneralParticleHandler.SpawnParticle(emote); + } + } + //If not hurrying up, reset the sound delay. + else if (Projectile.soundDelay >= 10000) + Projectile.soundDelay = NewSoundDelay; + + + //Target the enemy + if (targetCache != null && State == BehaviorState.Aggressive) + { + Vector2 vectorToTarget = targetCache.Center - Projectile.Center; + float distanceToTarget = vectorToTarget.Length(); + vectorToTarget = vectorToTarget.SafeNormalize(Vector2.Zero); + + //Accelerate towards target if far away + if (distanceToTarget > 200f) + Projectile.velocity = Vector2.Lerp(Projectile.velocity, vectorToTarget * 6f, 1 / 41f); + + //"Float" the minion + else if (Projectile.velocity.Y > -1f) + Projectile.velocity.Y -= 0.1f; + + //Small tweak that makes the minion hop away from the targets center if its too aligned with it vertically + if (Math.Abs(Projectile.Center.X - targetCache.Center.X) < 10f) + Projectile.velocity.X += 4f * Math.Sign(Projectile.Center.X - targetCache.Center.X); + } + + else + { + //Become passive if theres obstruction between it and the player + if (!Collision.CanHitLine(Projectile.Center, 1, 1, Owner.Center, 1, 1)) + State = BehaviorState.Idle; + + float returnSpeed = State == BehaviorState.Idle ? 15f : 6f; + + //Accelerate towards the player if too far & not fast enough + Vector2 playerVec = Owner.Center - Projectile.Center - Vector2.UnitY * 60f; float playerDist = playerVec.Length(); if (playerDist > 200f && returnSpeed < 9f) returnSpeed = 9f; - if (playerDist < 100f && Projectile.ai[0] == 1f && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height)) + + if (playerDist < 100f && State == BehaviorState.Idle && !Collision.SolidCollision(Projectile.position, Projectile.width, Projectile.height)) { - Projectile.ai[0] = 0f; + State = BehaviorState.Aggressive; Projectile.netUpdate = true; } + + //Teleport to player if too far away. if (playerDist > 2000f) { - Projectile.position.X = player.Center.X - (float) (Projectile.width / 2); - Projectile.position.Y = player.Center.Y - (float) (Projectile.width / 2); + Projectile.Center = player.Center; Projectile.netUpdate = true; } - else if (playerDist > 70f) + + else if (buffMode) { - playerVec.Normalize(); - Projectile.velocity = (Projectile.velocity * 20f + playerVec * returnSpeed) / 21f; + AyeAyeCaptainCooldown = 50f; + + Player playerToBuff = Owner; + float mouseDistanceToOwner = (Owner.MountedCenter - Owner.Calamity().mouseWorld).Length(); + + if (Main.netMode == NetmodeID.MultiplayerClient && mouseDistanceToOwner > 120f) + { + for (int i = 0; i < Main.maxPlayers; i++) + { + if (Main.player[i].active && !Main.player[i].dead && (Main.player[i].team == Owner.team || Main.player[i].team == 0)) + { + float mouseDistanceToPotentialTarget = (Main.player[i].MountedCenter - Owner.Calamity().mouseWorld).Length(); + if (mouseDistanceToPotentialTarget < 120f && mouseDistanceToOwner > mouseDistanceToPotentialTarget) + { + playerToBuff = Main.player[i]; + mouseDistanceToOwner = mouseDistanceToPotentialTarget; + } + } + } + + if (playerToBuff != Owner && Main.rand.NextBool(4)) + { + Vector2 direction = Main.rand.NextVector2CircularEdge(1f, 1f); + + Dust wishyDust = Dust.NewDustPerfect(playerToBuff.Center + direction * Main.rand.NextFloat(4f, 9f), 229, Alpha: 100, Scale: Main.rand.NextFloat(1f, 1.4f)); + wishyDust.noGravity = true; + wishyDust.noLight = true; + wishyDust.velocity = direction * Main.rand.NextFloat(2f, 4); + + } + } + + healedPlayer = playerToBuff; + float distanceToHealed = (healedPlayer.Center - Projectile.Center).Length(); + Vector2 aimPosition = playerToBuff.MountedCenter - Vector2.UnitY.RotatedBy((float)Math.Sin(Main.GlobalTimeWrappedHourly + Projectile.whoAmI) * MathHelper.PiOver2 * 0.9f) * 60f - Vector2.UnitY * 20f; + float distanceToAim = (aimPosition - Projectile.Center).Length(); + + if (distanceToAim > 50) + { + float speed = MathHelper.Lerp(10f, 30f, Math.Clamp((distanceToAim - 110f) / 400f, 0f, 1f)); + Projectile.velocity = Vector2.Lerp(Projectile.velocity, (aimPosition - Projectile.Center).SafeNormalize(Vector2.Zero) * speed, 0.05f); + } + + else + { + Projectile.velocity *= 0.98f; + if (Projectile.velocity == Vector2.Zero) + Projectile.velocity = (aimPosition - Projectile.Center).SafeNormalize(Vector2.Zero) * 5f; + } + + if (distanceToHealed < 200f) + { + //Heal player + playerToBuff.GetModPlayer().buffingDrones++; + + ShootTimer--; + if (ShootTimer <= 0) + { + ShootTimer = ShootDelay; + + if (Main.rand.NextBool(3)) + { + RoverDrivePlayer shieldMan = playerToBuff.GetModPlayer(); + if (shieldMan.ProtectionMatrixDurability > 0 && shieldMan.ProtectionMatrixDurability < RoverDrive.ProtectionMatrixDurabilityMax) + { + shieldMan.ProtectionMatrixDurability++; + if (playerToBuff.Calamity().cooldowns.TryGetValue(Cooldowns.WulfrumRoverDriveDurability.ID, out var cd)) + cd.timeLeft = shieldMan.ProtectionMatrixDurability; + } + } + } + } } + else { - if (Projectile.velocity.X == 0f && Projectile.velocity.Y == 0f) + //Aim towards the top of the player + if (playerDist > 70f) + Projectile.velocity = Vector2.Lerp(Projectile.velocity, playerVec.SafeNormalize(Vector2.Zero) * returnSpeed, 1 / 21f); + + else { - Projectile.velocity.X = -0.15f; - Projectile.velocity.Y = -0.05f; + //Get unstuck if your movespeed is zero + if (Projectile.velocity.X == 0f && Projectile.velocity.Y == 0f) + Projectile.velocity = Main.rand.NextVector2CircularEdge(1f, 1f) * -0.15f; + + //Accelerate more + Projectile.velocity *= 1.01f; } - Projectile.velocity *= 1.01f; } } + Projectile.rotation = Projectile.velocity.X * 0.05f; - if (Projectile.velocity.X > 0f) - Projectile.spriteDirection = Projectile.direction = 1; - else if (Projectile.velocity.X < 0f) - Projectile.spriteDirection = Projectile.direction = -1; - if (Projectile.ai[1] > 0f) - Projectile.ai[1] += (float) Main.rand.Next(1, 4); - if (Projectile.ai[1] > 90f) + Projectile.spriteDirection = Projectile.direction = Math.Sign(Projectile.velocity.X); + + if (!buffMode) + ChargeUpAndFire(targetCache); + } + + public void ChargeUpAndFire(NPC targetCache) + { + //Decrease the timer by a random number + ShootTimer -= Main.rand.Next(1, 4); + + + if (ShootTimer <= 0) { - Projectile.ai[1] = 0.0f; + ShootTimer = ShootDelay; Projectile.netUpdate = true; + + //Don't shoot if no target. + if (targetCache == null) + return; + + NuzzleFlashTime = 20f; + SoundEngine.PlaySound(PewSound, Projectile.Center); + //Recoil + Vector2 velocity = targetCache.Center - Projectile.Center; + velocity.Normalize(); + velocity *= 10f; + Projectile.velocity += velocity * -0.3f; + + + if (Main.myPlayer == Projectile.owner) + { + int bolt = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); + Main.projectile[bolt].originalDamage = Projectile.originalDamage; + Main.projectile[bolt].netUpdate = true; + Projectile.netUpdate = true; + } + } + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = 0.4f + 0.4f * ((float)Math.Sin(Main.GlobalTimeWrappedHourly * 6f + completionRatio * -12f) * 0.5f + 0.5f); + + fadeOpacity *= (1 - MathHelper.Clamp(((healedPlayer.Center - Projectile.Center).Length() - 170f) / 70f, 0f, 1f)); + + return Color.CornflowerBlue.MultiplyRGB(PrimColorMult) * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + return (3.4f + 4f * ((float)Math.Sin(Main.GlobalTimeWrappedHourly * 6f + completionRatio * -12f) * 0.5f + 0.5f)) * 2f; + } + + + public override bool PreDraw(ref Color lightColor) + { + if (healedPlayer == null) + healedPlayer = Owner; + + if (Owner.Calamity().mouseRight && Owner.HeldItem.type == ModContent.ItemType() && (healedPlayer.Center - Projectile.Center).Length() < 240f) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/ZapTrail")); + + Vector2[] drawPos = new Vector2[] { Projectile.Center, Projectile.Center, healedPlayer.Center + (Projectile.Center - healedPlayer.Center) * 0.5f + Vector2.UnitY * 40f, healedPlayer.Center, healedPlayer.Center }; + + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1.8f, delegate (Vector2 offset, Color colorMod) + { + PrimColorMult = colorMod; + TrailDrawer.Draw(drawPos, - Main.screenPosition + offset, 30); + }); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + } + return true; + } + + public override void PostDraw(Color lightColor) + { + if (NuzzleFlashTime > 0) + { + NuzzleFlashTime--; + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + float opacity = (float)Math.Pow(NuzzleFlashTime / 20f, 1.7f); + + if (SheenTex == null) + SheenTex = ModContent.Request("CalamityMod/Particles/HalfStar"); + + Texture2D shineTex = SheenTex.Value; + Vector2 shineScale = new Vector2(1.2f, 2f - (opacity) * 1.33f); + //float rotationBoost = opacity * MathHelper.PiOver2; + + Main.EntitySpriteDraw(shineTex, Projectile.Center - Main.screenPosition + Vector2.UnitY * 2f, null, Color.GreenYellow * opacity, MathHelper.PiOver2, shineTex.Size() / 2f, shineScale * Projectile.scale, SpriteEffects.None, 0); + //Main.EntitySpriteDraw(shineTex, Projectile.Center - Main.screenPosition + Vector2.UnitY * 2f, null, Color.GreenYellow * opacity, rotationBoost + 0.3f, shineTex.Size() / 2f, shineScale * Projectile.scale, SpriteEffects.None, 0); + + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); } - if (Projectile.ai[1] != 0f) - return; - ++Projectile.ai[1]; - if (Main.myPlayer != Projectile.owner) - return; - if (!foundTarget) - return; - Vector2 velocity = targetVector - Projectile.Center; - velocity.Normalize(); - velocity *= 10f; - int bolt = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); - Main.projectile[bolt].originalDamage = Projectile.originalDamage; - Main.projectile[bolt].netUpdate = true; - Projectile.netUpdate = true; } public override bool? CanDamage() => false; diff --git a/Projectiles/Summon/WulfrumEnergyBurst.cs b/Projectiles/Summon/WulfrumEnergyBurst.cs new file mode 100644 index 0000000000..a18c0dd266 --- /dev/null +++ b/Projectiles/Summon/WulfrumEnergyBurst.cs @@ -0,0 +1,216 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using System; +using CalamityMod.Particles; +using static CalamityMod.CalamityUtils; +using static Terraria.ModLoader.ModContent; +using Terraria.Graphics.Shaders; +using Terraria.Graphics.Effects; +using ReLogic.Content; + +namespace CalamityMod.Projectiles.Summon +{ + public class WulfrumEnergyBurst : ModProjectile + { + public ref float OriginalRotation => ref Projectile.ai[0]; + public NPC Target + { + get + { + if (Projectile.ai[1] < 0 || Projectile.ai[1] > Main.maxNPCs) + return null; + + return Main.npc[(int)Projectile.ai[1]]; + } + set + { + if (value == null) + Projectile.ai[1] = -1; + else + Projectile.ai[1] = value.whoAmI; + } + } + + public static float MaxDeviationAngle = MathHelper.PiOver4; + public static float HomingRange = 350; + public static float HomingAngle = MathHelper.PiOver4 * 1f; + + internal PrimitiveTrail TrailDrawer; + internal Color PrimColorMult = Color.White; + + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Bolt"); + ProjectileID.Sets.MinionShot[Projectile.type] = true; + + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 8; + Projectile.height = 8; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.penetrate = 1; + Projectile.minionSlots = 0f; + Projectile.minion = true; + Projectile.DamageType = DamageClass.Summon; + + Projectile.timeLeft = 140; + Projectile.extraUpdates = 2; + + + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public NPC FindTarget() + { + float bestScore = 0; + NPC bestTarget = null; + + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC potentialTarget = Main.npc[i]; + + if (!potentialTarget.CanBeChasedBy(null, false)) + continue; + + float distance = potentialTarget.Distance(Projectile.Center); + float angle = Projectile.velocity.AngleBetween((potentialTarget.Center - Projectile.Center)); + + float extraDistance = potentialTarget.width / 2 + potentialTarget.height / 2; + + if (distance - extraDistance < HomingRange && angle < HomingAngle / 2f) + { + if (!Collision.CanHit(Projectile.Center, 1, 1, potentialTarget.Center, 1, 1) && extraDistance < distance) + continue; + + float attemptedScore = EvaluatePotentialTarget(distance - extraDistance, angle / 2f); + if (attemptedScore > bestScore) + { + bestTarget = potentialTarget; + bestScore = attemptedScore; + } + } + } + return bestTarget; + + } + + public float EvaluatePotentialTarget(float distance, float angle) + { + float score = 1 - distance / HomingRange * 0.5f; + + score += (1 - Math.Abs(angle) / (HomingAngle / 2f)) * 0.5f; + + return score; + } + + public override void AI() + { + if (Projectile.timeLeft == 140) + { + if (OriginalRotation == 0) + { + OriginalRotation = Projectile.velocity.ToRotation(); + Projectile.rotation = OriginalRotation; + } + Target = null; + } + else + { + Target = FindTarget(); + } + + Lighting.AddLight(Projectile.Center, (Color.GreenYellow * 0.8f).ToVector3() * 0.5f); + + if (Target != null) + { + float distanceFromTarget = (Target.Center - Projectile.Center).Length(); + + Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow((1 - distanceFromTarget / HomingRange), 2)); + } + + Projectile.velocity *= 1.01f; + Projectile.velocity = Projectile.rotation.ToRotationVector2() * Projectile.velocity.Length(); + + //Blast off. + if (Projectile.timeLeft == 140) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity * 1f; + + for (int i = 0; i < 5; i++) + { + Dust chust = Dust.NewDustPerfect(dustCenter, 178, Projectile.velocity.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(0.2f, 0.5f), Scale: Main.rand.NextFloat(1f, 1.2f)); + chust.noGravity = true; + } + } + + if (Projectile.timeLeft <= 137) + { + if (Main.rand.NextBool(4)) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust chust = Dust.NewDustPerfect(dustCenter, 178, -Projectile.velocity * Main.rand.NextFloat(0.2f, 0.5f), Scale: Main.rand.NextFloat(0.6f, 1.15f)); + chust.noGravity = true; + } + + if (Main.rand.NextBool(4)) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust largeDust = Dust.NewDustPerfect(dustCenter, 178, -Projectile.velocity * Main.rand.NextFloat(0.2f, 0.4f), Scale: Main.rand.NextFloat(0.4f, 1f)); + largeDust.noGravity = true; + largeDust.noLight = true; + } + } + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = (float)Math.Sqrt(1 - completionRatio); + return Color.Chartreuse.MultiplyRGB(PrimColorMult) * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + return 9.4f; + } + + public override bool PreDraw(ref Color lightColor) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/ZapTrail")); + + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 1.5f, delegate (Vector2 offset, Color colorMod) + { + PrimColorMult = colorMod; + + TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30); + }); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + Texture2D tex = ModContent.Request(Texture).Value; + float stretchy = MathHelper.Clamp((Projectile.velocity.Length() - 6f) / 16f, 0f, 1f); + Vector2 scale = new Vector2(1f + stretchy * -0.2f, stretchy * 0.5f + 1f); + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition, null, Projectile.GetAlpha(lightColor), Projectile.rotation + MathHelper.PiOver2, tex.Size() / 2f, Projectile.scale * scale, SpriteEffects.None, 0); + + return false; + } + } +} diff --git a/Projectiles/Summon/WulfrumEnergyBurst.png b/Projectiles/Summon/WulfrumEnergyBurst.png new file mode 100644 index 0000000000..0afbd7a453 Binary files /dev/null and b/Projectiles/Summon/WulfrumEnergyBurst.png differ diff --git a/Projectiles/Summon/WulfrumFusionBolt.cs b/Projectiles/Summon/WulfrumFusionBolt.cs new file mode 100644 index 0000000000..90816ccd9b --- /dev/null +++ b/Projectiles/Summon/WulfrumFusionBolt.cs @@ -0,0 +1,230 @@ +using System; +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; +using static Terraria.ModLoader.ModContent; +using CalamityMod.Particles; + +namespace CalamityMod.Projectiles.Summon +{ + //Mostly a retread of the magic one, with altered visuals + public class WulfrumFusionBolt : ModProjectile + { + public ref float OriginalRotation => ref Projectile.ai[0]; + public NPC Target + { + get + { + if (Projectile.ai[1] < 0 || Projectile.ai[1] > Main.maxNPCs) + return null; + + return Main.npc[(int)Projectile.ai[1]]; + } + set + { + if (value == null) + Projectile.ai[1] = -1; + else + Projectile.ai[1] = value.whoAmI; + } + } + + public static float MaxDeviationAngle = MathHelper.PiOver4; + public static float HomingRange = 250; + public static float HomingAngle = MathHelper.PiOver4 * 1.65f; + + internal PrimitiveTrail TrailDrawer; + internal Color PrimColorMult = Color.White; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Fusion Bolt"); + + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 20; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + + public override void SetDefaults() + { + Projectile.width = 8; + Projectile.height = 8; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.penetrate = 1; + Projectile.DamageType = DamageClass.Summon; + Projectile.timeLeft = 140; + Projectile.extraUpdates = 2; + } + + public NPC FindTarget() + { + float bestScore = 0; + NPC bestTarget = null; + + for (int i = 0; i < Main.maxNPCs; i++) + { + NPC potentialTarget = Main.npc[i]; + + if (!potentialTarget.CanBeChasedBy(null, false)) + continue; + + float distance = potentialTarget.Distance(Projectile.Center); + float angle = Projectile.velocity.AngleBetween((potentialTarget.Center - Projectile.Center)); + + float extraDistance = potentialTarget.width / 2 + potentialTarget.height / 2; + + if (distance - extraDistance < HomingRange && angle < HomingAngle / 2f) + { + if (!Collision.CanHit(Projectile.Center, 1, 1, potentialTarget.Center, 1, 1) && extraDistance < distance) + continue; + + float attemptedScore = EvaluatePotentialTarget(distance - extraDistance, angle / 2f); + if (attemptedScore > bestScore) + { + bestTarget = potentialTarget; + bestScore = attemptedScore; + } + } + } + return bestTarget; + + } + + public float EvaluatePotentialTarget(float distance, float angle) + { + float score = 1 - distance / HomingRange * 0.5f; + + score += (1 - Math.Abs(angle) / (HomingAngle / 2f)) * 0.5f; + + return score; + } + + public override void AI() + { + if (Projectile.timeLeft == 140) + { + Projectile.rotation = Projectile.velocity.ToRotation(); + + Target = null; + } + else + { + Target = FindTarget(); + } + + Lighting.AddLight(Projectile.Center, (Color.DeepSkyBlue).ToVector3() * 0.5f); + + if (Target != null) + { + float distanceFromTarget = (Target.Center - Projectile.Center).Length(); + Projectile.rotation = Projectile.rotation.AngleTowards((Target.Center - Projectile.Center).ToRotation(), 0.07f * (float)Math.Pow(( 1 - distanceFromTarget / HomingRange), 2)); + } + + Projectile.velocity *= 0.983f; + Projectile.velocity = Projectile.rotation.ToRotationVector2() * Projectile.velocity.Length(); + + //Blast off. + if (Projectile.timeLeft == 140) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity * 1f; + + for (int i = 0; i < 5; i++) + { + Dust chust = Dust.NewDustPerfect(dustCenter, 15, Projectile.velocity.RotatedByRandom(MathHelper.PiOver4) * Main.rand.NextFloat(0.2f, 0.5f), Scale: Main.rand.NextFloat(1.2f, 1.8f)); + chust.noGravity = true; + } + } + + if (Projectile.timeLeft <= 137) + { + if (Main.rand.NextBool(5)) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + Dust chust = Dust.NewDustPerfect(dustCenter, 15, -Projectile.velocity * Main.rand.NextFloat(0.2f, 0.5f), Scale: Main.rand.NextFloat(1.2f, 1.8f)); + chust.noGravity = true; + } + + if (Main.rand.NextBool(8)) + { + Vector2 dustCenter = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Dust largeDust = Dust.NewDustPerfect(dustCenter, 257, -Projectile.velocity * Main.rand.NextFloat(0.2f, 0.4f), Scale: Main.rand.NextFloat(0.4f, 1f)); + largeDust.noGravity = true; + largeDust.noLight = true; + } + + if (Main.rand.NextBool(5)) + { + Vector2 center = Projectile.Center + Projectile.velocity.RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero) * Main.rand.NextFloat(-3f, 3f); + + Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(4, 10); + GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(center, velocity, Main.rand.NextFloat(1f, 2f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25)); + + } + } + } + + internal Color ColorFunction(float completionRatio) + { + float fadeOpacity = (float)Math.Sqrt(1 - completionRatio); + return Color.Lerp(Color.DeepSkyBlue, Color.YellowGreen, Projectile.timeLeft / 140f).MultiplyRGB(PrimColorMult) * fadeOpacity; + } + + internal float WidthFunction(float completionRatio) + { + return 6.4f; + } + + public override bool PreDraw(ref Color lightColor) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + if (TrailDrawer is null) + TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction, specialShader: GameShaders.Misc["CalamityMod:TrailStreak"]); + + GameShaders.Misc["CalamityMod:TrailStreak"].SetShaderTexture(Request("CalamityMod/ExtraTextures/BasicTrail")); + CalamityUtils.DrawChromaticAberration(Vector2.UnitX, 0.5f, delegate (Vector2 offset, Color colorMod) + { + PrimColorMult = colorMod; + + TrailDrawer.Draw(Projectile.oldPos, Projectile.Size * 0.5f - Main.screenPosition + offset, 30); + }); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + return false; + } + + public override void Kill(int timeLeft) + { + SoundEngine.PlaySound(WulfrumProsthesis.HitSound with { Volume = WulfrumProsthesis.HitSound.Volume * 0.6f }, Projectile.Center); + } + + public override bool OnTileCollide(Vector2 oldVelocity) + { + Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); + return base.OnTileCollide(oldVelocity); + } + + public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) + { + Main.player[Projectile.owner].MinionAttackTargetNPC = target.whoAmI; //There exists a "whoAmIToTargettingIndex but idk if thats needed question mark + + int numParticles = Main.rand.Next(1, 3); + for (int i = 0; i < numParticles; i++) + { + Vector2 velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedByRandom(MathHelper.Pi / 6f) * Main.rand.NextFloat(3, 14); + GeneralParticleHandler.SpawnParticle(new TechyHoloysquareParticle(target.Center, velocity, Main.rand.NextFloat(2.5f, 3f), Main.rand.NextBool() ? new Color(99, 255, 229) : new Color(25, 132, 247), 25)); + } + } + } +} diff --git a/Projectiles/Typeless/WulfrumDiggingTurtleProjectile.cs b/Projectiles/Typeless/WulfrumDiggingTurtleProjectile.cs new file mode 100644 index 0000000000..6374756e89 --- /dev/null +++ b/Projectiles/Typeless/WulfrumDiggingTurtleProjectile.cs @@ -0,0 +1,248 @@ +using System; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.GameContent; +using CalamityMod.Items.Materials; +using Terraria.DataStructures; +using ReLogic.Utilities; + +namespace CalamityMod.Projectiles.Typeless +{ + public class WulfrumDiggingTurtleProjectile : ModProjectile + { + public static readonly SoundStyle IdleSound = new("CalamityMod/Sounds/Custom/WulfrumSawIdle") { IsLooped = true, Volume = 0.8f, MaxInstances = 0 }; + public static readonly SoundStyle CuttingSound = new("CalamityMod/Sounds/Custom/WulfrumSawCutting") { IsLooped = true, Volume = 0.7f, MaxInstances = 0 }; + public static readonly SoundStyle BreakingSound = new("CalamityMod/Sounds/Custom/WulfrumMachineBreak"); + + private SlotId CuttingSoundSlot; + private SlotId IdlingSoundSlot; + + public Player Owner => Main.player[Projectile.owner]; + public bool Diggging + { + get => Projectile.ai[0] == 1; + set { Projectile.ai[0] = value ? 1f : 0f; } + } + + public bool HasDug + { + get => Projectile.ai[1] == 1; + set { Projectile.ai[1] = value ? 1f : 0f; } + } + + public float CuttingVolume + { + get => Projectile.localAI[0]; + set { Projectile.localAI[0] = Math.Clamp(value, 0f, 1f); } + } + + public override string Texture => "CalamityMod/Items/Tools/WulfrumDiggingTurtle"; + public static Texture2D SmallGearTexture; + public static Texture2D GearTexture; + + public static int Lifetime = 400; + public static int DigTime = 350; + public static float DigSpeed = 1.5f; + public static int MaxPickPower = 160; + public static float ClearSpaceDiagonal = 50; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Digging Turtle"); + } + + public override void SetDefaults() + { + Projectile.width = 20; + Projectile.height = 20; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = Lifetime; + Projectile.netImportant = true; + } + + public override bool? CanDamage() => false; + + public override bool OnTileCollide(Vector2 oldVelocity) + { + if (!HasDug) + { + HasDug = true; + Projectile.timeLeft = DigTime; + } + + Diggging = true; + Projectile.velocity = oldVelocity.SafeNormalize(Vector2.UnitY) * DigSpeed; + + return false; + } + + public override void AI() + { + Lighting.AddLight(Projectile.Center, Color.GreenYellow.ToVector3()); + + //Idle chainsaw sounds + if ((!SoundEngine.TryGetActiveSound(IdlingSoundSlot, out var idleSoundOut))) + IdlingSoundSlot = SoundEngine.PlaySound(IdleSound with { Volume = IdleSound.Volume }, Projectile.Center); + else if (idleSoundOut != null) + { + idleSoundOut.Volume = (1 - CuttingVolume); + idleSoundOut.Position = Projectile.Center; + } + + + //Heavy cutting sound + if ((!SoundEngine.TryGetActiveSound(CuttingSoundSlot, out var cuttingSoundOut))) + CuttingSoundSlot = SoundEngine.PlaySound(CuttingSound with { Volume = CuttingSound.Volume }, Projectile.Center); + else if (cuttingSoundOut != null) + { + cuttingSoundOut.Volume = CuttingVolume; + cuttingSoundOut.Position = Projectile.Center; + } + + + + if (Diggging) + { + CuttingVolume += 0.1f; + for (int i = -1; i <= 1; i++) + { + Point tilePos = (Projectile.Center + (Projectile.rotation + MathHelper.PiOver4 * i).ToRotationVector2() * 16).ToTileCoordinates(); + + DigTile(tilePos.X, tilePos.Y); + } + } + + //the flung state. + else + { + CuttingVolume -= 0.1f; + + float fallSpeed = Projectile.velocity.Y; + + if (Projectile.timeLeft < 345) + Projectile.velocity += Vector2.UnitY * 0.5f * (1 - Math.Clamp((Projectile.timeLeft - 310f) / 35f, 0f, 1f)); + + Projectile.velocity *= 0.98f; + + if (Projectile.velocity.Y > 0) + Projectile.velocity.Y = Math.Clamp(Projectile.velocity.Y, 0, Math.Max(18f, fallSpeed)); + + Projectile.rotation = Projectile.velocity.ToRotation(); + } + + if (!Collision.SolidCollision(Projectile.Center - Vector2.One * ClearSpaceDiagonal * 0.5f, (int)ClearSpaceDiagonal, (int)ClearSpaceDiagonal)) + Diggging = false; + } + + public override void Kill(int timeLeft) + { + if (Main.myPlayer == Owner.whoAmI) + { + if (Main.rand.NextBool() && !Projectile.noDropItem) + Item.NewItem(Projectile.GetSource_DropAsItem(), (int)Projectile.position.X, (int)Projectile.position.Y, Projectile.width, Projectile.height, ModContent.ItemType(), Main.rand.Next(0, 3)); + } + + if (SoundEngine.TryGetActiveSound(CuttingSoundSlot, out var cuttingSoundOut)) + cuttingSoundOut.Stop(); + + if (SoundEngine.TryGetActiveSound(IdlingSoundSlot, out var idleSoundOut)) + idleSoundOut.Stop(); + + SoundEngine.PlaySound(BreakingSound, Projectile.position); + + int smokeCount = Main.rand.Next(5, 10); + int sparkCount = Main.rand.Next(4, 8); + + for (int i = 0; i < smokeCount; i++) + { + Vector2 velocity = Main.rand.NextVector2CircularEdge(1f, 1f) * Main.rand.NextFloat(3f, 12f); + + Color smokeStart = Main.rand.NextBool() ? Color.GreenYellow : Color.Aqua; + Color smokeEnd = new Color(60, 60, 60); + + float smokeSize = Main.rand.NextFloat(1.4f, 2.2f); + + Particle smoke = new SmallSmokeParticle(Projectile.Center, velocity, smokeStart, smokeEnd, smokeSize, 135 - Main.rand.Next(30)); + GeneralParticleHandler.SpawnParticle(smoke); + } + + if (Main.netMode != NetmodeID.Server) + { + for (int i = 0; i < 4; i++) + { + Vector2 shrapnelVelocity = Main.rand.NextVector2Circular(9f, 9f); + float shrapnelScale = Main.rand.NextFloat(0.8f, 1f); + + string goreType = i < 2 ? "WulfrumTurtle1" : i < 3 ? "WulfrumTurtle2" : "WulfrumTurtle3"; + + Gore.NewGore(Projectile.GetSource_Death(), Projectile.Center, shrapnelVelocity, Mod.Find(goreType).Type, shrapnelScale); + } + + + } + + for (int i = 0; i < sparkCount; i++) + { + Dust.NewDustPerfect(Projectile.Center, 226, Main.rand.NextVector2Circular(18f, 18f), Scale: Main.rand.NextFloat(0.4f, 1f)); + } + } + + public void DigTile(int x, int y) + { + Tile tile = Main.tile[x, y]; + if (!tile.HasTile) + return; + + int pickPower = Math.Min( Owner.GetBestPickPower(), MaxPickPower); + int pickaxeRequirement = tile.GetRequiredPickPower(x, y); + + bool true_ = true; + bool false_ = false; + + bool canBreakTileCheck = TileLoader.CanKillTile(x, y, tile.TileType, ref true_) && TileLoader.CanKillTile(x, y, tile.TileType, ref false_); + bool shouldBreakTile = tile.ShouldBeMined(); + + if (!Owner.noBuilding && shouldBreakTile && pickaxeRequirement < pickPower && canBreakTileCheck) + { + WorldGen.KillTile(x, y, false, false, false); + if (!Main.tile[x, y].HasTile && Main.netMode != NetmodeID.SinglePlayer) + { + NetMessage.SendData(MessageID.TileManipulation, -1, -1, null, 0, x, y, 0f, 0, 0, 0); + } + } + } + + public override bool PreDraw(ref Color lightColor) + { + Texture2D texture = TextureAssets.Projectile[Type].Value; + + GearTexture = ModContent.Request("CalamityMod/Projectiles/Typeless/WulfrumDiggingTurtle_Gear").Value; + + SmallGearTexture = ModContent.Request("CalamityMod/Projectiles/Typeless/WulfrumDiggingTurtle_SmallGear").Value; + + + Vector2 position = Projectile.Center - Main.screenPosition; + if (Diggging) + position += Main.rand.NextVector2Circular(2f, 2f); + float drawRotation = Projectile.rotation + MathHelper.PiOver2; + + for (int i = -1; i <= 1; i += 2) + { + Vector2 diggingGearOffset = new Vector2(9 * i, -11).RotatedBy(drawRotation) * Projectile.scale; + Main.EntitySpriteDraw(SmallGearTexture, position + diggingGearOffset, null, lightColor, drawRotation + Main.GlobalTimeWrappedHourly * -10f * i, SmallGearTexture.Size() / 2f, Projectile.scale * 1.2f, 0, 0); + } + + Vector2 largeGearOffset = new Vector2(0f, 3f).RotatedBy(drawRotation) * Projectile.scale; + Main.EntitySpriteDraw(GearTexture, position + largeGearOffset, null, lightColor, Main.GlobalTimeWrappedHourly * 6f, GearTexture.Size() / 2f, Projectile.scale, 0, 0); + + Main.EntitySpriteDraw(texture, position, null, lightColor, drawRotation, texture.Size() / 2f, Projectile.scale, 0, 0); + return false; + } + } +} diff --git a/Projectiles/Typeless/WulfrumDiggingTurtle_Gear.png b/Projectiles/Typeless/WulfrumDiggingTurtle_Gear.png new file mode 100644 index 0000000000..ea5be5e19d Binary files /dev/null and b/Projectiles/Typeless/WulfrumDiggingTurtle_Gear.png differ diff --git a/Projectiles/Typeless/WulfrumDiggingTurtle_SmallGear.png b/Projectiles/Typeless/WulfrumDiggingTurtle_SmallGear.png new file mode 100644 index 0000000000..aa098b46aa Binary files /dev/null and b/Projectiles/Typeless/WulfrumDiggingTurtle_SmallGear.png differ diff --git a/Projectiles/Typeless/WulfrumDrillProj.cs b/Projectiles/Typeless/WulfrumDrillProj.cs new file mode 100644 index 0000000000..466cc9be76 --- /dev/null +++ b/Projectiles/Typeless/WulfrumDrillProj.cs @@ -0,0 +1,104 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class WulfrumDrillProj : ModProjectile + { + public override string Texture => "CalamityMod/Items/Tools/WulfrumDrill"; + + public Player Owner => Main.player[Projectile.owner]; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Drill"); + } + + + public override void SetDefaults() + { + Projectile.width = 22; + Projectile.height = 22; + Projectile.aiStyle = 20; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.tileCollide = false; + Projectile.hide = true; + Projectile.ownerHitCheck = true; + Projectile.DamageType = TrueMeleeNoSpeedDamageClass.Instance; + Projectile.scale = 0.93f; + } + + public override bool ShouldUpdatePosition() => false; + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + float collisionPoint = 0f; + float bladeLenght = 54f * Projectile.scale; + return Collision.CheckAABBvLineCollision(targetHitbox.TopLeft(), targetHitbox.Size(), Projectile.Center, Projectile.Center + (Projectile.velocity * bladeLenght), 24, ref collisionPoint); + } + + public override void AI() + { + if (!Owner.channel) + { + Projectile.Kill(); + Projectile.active = false; + return; + } + + Projectile.timeLeft = 2; + + //Vroom + if (Projectile.soundDelay <= 0) + { + SoundEngine.PlaySound(SoundID.Item22, Owner.Center); + Projectile.soundDelay = 30; + } + + Projectile.velocity = (Owner.Calamity().mouseWorld - Owner.MountedCenter).SafeNormalize(Vector2.One); + //Projectile.spriteDirection = Math.Sign(Projectile.velocity.X); + Owner.heldProj = Projectile.whoAmI; + Owner.ChangeDir(Math.Sign(Projectile.velocity.X)); + Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, Projectile.velocity.ToRotation() * Owner.gravDir - MathHelper.PiOver2); + Owner.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, Projectile.velocity.ToRotation() * Owner.gravDir - MathHelper.PiOver2 - MathHelper.PiOver4 * 0.5f * Owner.direction); + + Owner.SetDummyItemTime(2); + Projectile.rotation = Projectile.velocity.ToRotation(); + Projectile.Center = Owner.MountedCenter + Projectile.velocity * 12f; + + Projectile.velocity.X *= 1f + (float)Main.rand.Next(-3, 4) * 0.01f; + + if (Main.rand.NextBool(6)) + { + Dust whirrDust = Dust.NewDustDirect(Projectile.position + Projectile.velocity * Main.rand.Next(6, 10) * 0.1f, Projectile.width, Projectile.height, 31, 0f, 0f, 80, Scale: 1.4f) ; + whirrDust.position.X -= 4f; + whirrDust.noGravity = true; + whirrDust.velocity *= 0.2f; + whirrDust.velocity.Y = (float)(-Main.rand.Next(7, 13)) * 0.15f; + } + } + + public override bool PreDraw(ref Color lightColor) + { + //Necessary or else itll glitch out for a final frame??? + if (!Projectile.active) + return false; + + Texture2D tex = ModContent.Request(Texture).Value; + Vector2 origin = new Vector2(9f, tex.Height / 2f); + Vector2 shake = Main.rand.NextVector2Circular(1f, 1f) * ((float)Math.Sin(Main.GlobalTimeWrappedHourly ) * 0.25f + 0.75f); + SpriteEffects effect = SpriteEffects.None; + if (Owner.direction * Owner.gravDir < 0) + effect = SpriteEffects.FlipVertically; + + Main.EntitySpriteDraw(tex, Projectile.Center - Main.screenPosition + shake, null, Projectile.GetAlpha(lightColor), Projectile.rotation, origin, Projectile.scale, effect, 0); + return false; + } + } +} diff --git a/Projectiles/Typeless/WulfrumHook.cs b/Projectiles/Typeless/WulfrumHook.cs new file mode 100644 index 0000000000..f877d5fa27 --- /dev/null +++ b/Projectiles/Typeless/WulfrumHook.cs @@ -0,0 +1,253 @@ +using System; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.GameContent; +using CalamityMod.Items.Materials; +using Terraria.DataStructures; +using ReLogic.Utilities; +using CalamityMod.Items.Accessories; +using System.Collections.Generic; +using System.Linq; + +namespace CalamityMod.Projectiles.Typeless +{ + public class WulfrumHook : ModProjectile + { + public Player Owner => Main.player[Projectile.owner]; + internal PrimitiveTrail TrailRenderer; + + public HookState State + { + get => (HookState)(int)Projectile.ai[0]; + set { Projectile.ai[0] = (int)value; } + } + + public ref float Timer => ref Projectile.ai[1]; + + public enum HookState + { + Thrown, + Retracting, + Grappling = 3 //Making this value "3" is important here, as it makes it so that i can put this projectile in the player grapple list while also never having it considered as "grappling" (aka ai[0] = 2) + } + + public static float MaxReach = 600; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Slingshot"); + //Expand the draw distance. Should never happen really , but just in case the player basically walks away from the hook. + ProjectileID.Sets.DrawScreenCheckFluff[Projectile.type] = 3000; + } + + public override void SetDefaults() + { + Projectile.width = 3; + Projectile.height = 3; + Projectile.friendly = true; + Projectile.penetrate = -1; + Projectile.timeLeft = 2; + Projectile.tileCollide = false; + Projectile.extraUpdates = WulfrumPackPlayer.HookUpdates; + Projectile.netImportant = true; + Projectile.aiStyle = 7; //The projectile uses entirely custom AI, but for some reason terraria's only way to distinguish what is and isnt a hook is its ai style. + } + + public override bool? CanDamage() => false; + + public override bool PreAI() => false; + public override void PostAI() + { + Lighting.AddLight(Projectile.Center, Color.DeepSkyBlue.ToVector3()); + Vector2 BetweenOwner = Owner.Center - Projectile.Center; + + if (Owner.dead || Owner.stoned || Owner.webbed || Owner.frozen || BetweenOwner.Length() > 1500) + { + Projectile.Kill(); + return; + } + + Projectile.rotation = BetweenOwner.ToRotation() - MathHelper.PiOver2; + + if (Owner.GetModPlayer().WulfrumPackEquipped) + { + Projectile.timeLeft = 2; + } + + if (State == HookState.Thrown) + { + //Retract if too far. + if (MaxReach < BetweenOwner.Length()) + State = HookState.Retracting; + + float fallSpeed = Projectile.velocity.Y; + + if (Timer > 15 * Projectile.extraUpdates) + Projectile.velocity += Vector2.UnitY * 0.5f * (1 - Math.Clamp((Timer - 15) / 35f, 0f, 1f)) / Projectile.extraUpdates; + + Projectile.velocity *= 0.98f; + + if (Projectile.velocity.Y + 0.001 > 0) + Projectile.velocity.Y = Math.Clamp(Projectile.velocity.Y, 0, Math.Max(18f, fallSpeed)); + + if (Projectile.velocity.Length() < 1f) + State = HookState.Retracting; + + CheckForGrapplableTiles(); + + } + + else if (State == HookState.Retracting) + { + Projectile.velocity = BetweenOwner.SafeNormalize(Vector2.One) * WulfrumPackPlayer.ReturnVelocity; + Projectile.Center += Vector2.UnitY * 0.5f; + + if (BetweenOwner.Length() < 25f) + Projectile.Kill(); + } + + else + { + float lenghtToOwner = BetweenOwner.Length(); + + if (lenghtToOwner > Owner.GetModPlayer().SwingLenght + 60f) + { + State = HookState.Retracting; + } + + Point tilePos = Projectile.Center.ToTileCoordinates(); + Tile tile = Main.tile[tilePos]; + if (!tile.HasUnactuatedTile || !tile.CanTileBeLatchedOnTo() || Owner.IsBlacklistedForGrappling(tilePos)) + State = HookState.Retracting; + + Projectile.velocity = Vector2.Zero; + + if (Owner.grapCount < 10) + { + Owner.grappling[Owner.grapCount] = Projectile.whoAmI; + Owner.grapCount++; + } + } + + Timer++; + } + + public void CheckForGrapplableTiles() + { + Vector2 hitboxStart = Projectile.Center - new Vector2(5f); + Vector2 hitboxEnd = Projectile.Center + new Vector2(5f); + + Point topLeftTile = (hitboxStart - new Vector2(16f)).ToTileCoordinates(); + Point bottomRightTile = (hitboxEnd + new Vector2(32f)).ToTileCoordinates(); + + for (int x = topLeftTile.X; x < bottomRightTile.X; x++) + { + for (int y = topLeftTile.Y; y < bottomRightTile.Y; y++) + { + Vector2 worldPos = new Vector2(x * 16f, y * 16f); + Point tilePos = new Point(x, y); + + //Ignore tiles that arent being collided with + if (!(hitboxStart.X + 10f > worldPos.X) || !(hitboxStart.X < worldPos.X + 16f) || !(hitboxStart.Y + 10f > worldPos.Y) || !(hitboxStart.Y < worldPos.Y + 16f)) + continue; + + Tile tile = Main.tile[tilePos]; + + if (!tile.HasUnactuatedTile || !tile.CanTileBeLatchedOnTo() || Owner.IsBlacklistedForGrappling(tilePos)) + continue; + if (Main.myPlayer != Owner.whoAmI) + continue; + + OnGrapple(worldPos, x, y); + + break; + } + + if (State == HookState.Grappling) + break; + } + } + + public void OnGrapple(Vector2 grapplePos, int x, int y) + { + WulfrumPackPlayer mp = Owner.GetModPlayer(); + //Clear previous grapple + if (Main.projectile[mp.Grapple].active && Main.projectile[mp.Grapple].ModProjectile is WulfrumHook hook && hook.State == WulfrumHook.HookState.Grappling) + Main.projectile[mp.Grapple].Kill(); + + //Hook onto the tile + Projectile.velocity = Vector2.Zero; + State = HookState.Grappling; + Projectile.Center = grapplePos + Vector2.One * 8f; + //effects + WorldGen.KillTile(x, y, fail: true, effectOnly: true); + SoundEngine.PlaySound(SoundID.Dig, grapplePos); + SoundEngine.PlaySound(WulfrumAcrobaticsPack.GrabSound, grapplePos); + + if (Owner.grapCount < 10) + { + Owner.grappling[Owner.grapCount] = Projectile.whoAmI; + Owner.grapCount++; + //Owner.velocity = Vector2.Zero; + } + + mp.SwingLenght = (Owner.Center - Projectile.Center).Length(); + mp.OldPosition = Owner.Center - Owner.velocity; + mp.SetSegments(Projectile.Center); + mp.Grapple = Projectile.whoAmI; + + Rectangle? tileVisualHitbox = WorldGen.GetTileVisualHitbox(x, y); + if (tileVisualHitbox.HasValue) + Projectile.Center = tileVisualHitbox.Value.Center.ToVector2(); + + Projectile.netUpdate = true; + NetMessage.SendData(MessageID.PlayerControls, -1, -1, null, Owner.whoAmI); + } + + + public override void Kill(int timeLeft) + { + if (Owner.grappling[0] == Projectile.whoAmI) + { + Owner.grappling[0] = -1; + Owner.grapCount--; + } + } + + public float PrimWidthFunction(float completionRatio) + { + return 1.6f; + } + + public Color PrimColorFunction(float completionRatio) + { + return Color.Lerp(Color.DeepSkyBlue, Color.GreenYellow, (float)Math.Pow(completionRatio, 1.5D)); + } + + public override bool PreDraw(ref Color lightColor) + { + if (TrailRenderer is null) + TrailRenderer = new PrimitiveTrail(PrimWidthFunction, PrimColorFunction); + + Vector2[] segmentPositions = new Vector2[] {Projectile.Center, Owner.Center }; + + if (State == HookState.Grappling) + segmentPositions = Owner.GetModPlayer().Segments.Select(x => x.position).ToArray(); + + TrailRenderer.Draw(segmentPositions, -Main.screenPosition, 30); + + + Texture2D texture = TextureAssets.Projectile[Type].Value; + + Main.EntitySpriteDraw(texture, Projectile.Center - Main.screenPosition, null, lightColor, Projectile.rotation, texture.Size() / 2f, Projectile.scale, 0, 0); + return false; + } + + public override bool PreDrawExtras() => false; //Prevents vanilla chain drawing from taking place + } +} diff --git a/Projectiles/Typeless/WulfrumHook.png b/Projectiles/Typeless/WulfrumHook.png new file mode 100644 index 0000000000..6f91ff4256 Binary files /dev/null and b/Projectiles/Typeless/WulfrumHook.png differ diff --git a/Projectiles/Typeless/WulfrumScaffoldKitHoldout.cs b/Projectiles/Typeless/WulfrumScaffoldKitHoldout.cs new file mode 100644 index 0000000000..3619d9de6e --- /dev/null +++ b/Projectiles/Typeless/WulfrumScaffoldKitHoldout.cs @@ -0,0 +1,240 @@ +using System; +using System.Collections.Generic; +using CalamityMod.Items.Materials; +using CalamityMod.Items.Tools; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.Graphics.Effects; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Typeless +{ + public class WulfrumScaffoldKitHoldout : ModProjectile + { + public override void Load() + { + PipeCleanupManager = new WulfrumPipeManager(); + } + + public Player Owner => Main.player[Projectile.owner]; + public WulfrumScaffoldKit Kit => Owner.HeldItem.ModItem as WulfrumScaffoldKit; + public bool CanOwnerGoOn => Kit.storedScrap > 0 || Owner.HasItem(ModContent.ItemType()); + + public bool CanSelectTile(Point tilePos) + { + //You only need to check when starting a scaffold + if (SelectedTiles.Count > 0) + return CanSelectMoreTiles(tilePos); + + + for (int i = -1; i < 2; i++) + { + for (int j = -1; j < 2; j++) + { + if (Main.tile[tilePos.X + i, tilePos.Y + j].IsTileFull()) + return true; + } + } + + return false; + } + public bool CanSelectMoreTiles(Point tilePos) + { + for (int i = -2; i < 3; i++) + { + for (int j = -2; j < 3; j++) + { + if (Math.Abs(i) == 2 && Math.Abs(j) == 2) + continue; + + if (Main.tile[tilePos.X + i, tilePos.Y + j].TileType == WulfrumScaffoldKit.PlacedTileType || SelectedTiles.ContainsKey(new Point(tilePos.X + i, tilePos.Y + j))) + return true; + } + } + + return false; + } + + public static TemporaryTileManager PipeCleanupManager; + + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Wulfrum Scaffold Kit"); + } + + public static int tileGlowTime = 10; + + public Dictionary SelectedTiles = new Dictionary(); //Might need some cloning stuff for mp? idk, probably not + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetDefaults() + { + Projectile.width = 1; + Projectile.height = 1; + Projectile.penetrate = -1; + Projectile.netImportant = true; + Projectile.tileCollide = false; + Projectile.ignoreWater = true; + } + + public override bool? CanDamage() => false; + public override bool ShouldUpdatePosition() => false; + + public override void AI() + { + if (Owner.channel && CanOwnerGoOn) + { + //Initialize the position + if (Projectile.timeLeft > 2) + Projectile.position = Owner.Calamity().mouseWorld; + + Owner.itemTime = 2; + Owner.itemAnimation = 2; + + Projectile.position = Projectile.position.MoveTowards(Owner.Calamity().mouseWorld, 16); + //Projectile.position = raytracePosition(); + + if ((Projectile.position - Owner.Center).Length() > WulfrumScaffoldKit.TileReach * 16) + Projectile.position = Owner.Center + Vector2.Normalize(Projectile.position - Owner.Center) * WulfrumScaffoldKit.TileReach * 16; + + if (Owner.whoAmI == Main.myPlayer) + { + Point tilePos = Projectile.position.ToTileCoordinates(); + Tile hoveredTile = Main.tile[tilePos]; + + if (!hoveredTile.HasTile && !SelectedTiles.ContainsKey(tilePos) && CanSelectTile(tilePos)) + { + SelectedTiles.Add(tilePos, tileGlowTime); + + if (Kit.storedScrap > 0) + Kit.storedScrap--; + + else + { + Owner.ConsumeItem(ModContent.ItemType()); + Kit.storedScrap = WulfrumScaffoldKit.TilesPerScrap - 1; + SoundEngine.PlaySound(SoundID.Item65); + if (Main.netMode != NetmodeID.Server) + { + Gore shard = Gore.NewGoreDirect(Projectile.GetSource_ItemUse(Owner.HeldItem), Owner.Center, Main.rand.NextVector2Circular(4f, 4f), Mod.Find("WulfrumPinger2").Type, Main.rand.NextFloat(0.5f, 1f)); + shard.timeLeft = 10; + shard.alpha = 100 - Main.rand.Next(0, 60); + } + } + } + + foreach (Point position in SelectedTiles.Keys) + { + if (SelectedTiles[position] > 0) + SelectedTiles[position]--; + } + } + + Projectile.timeLeft = 2; + } + } + + public override bool PreDraw(ref Color lightColor) + { + if (Main.myPlayer != Owner.whoAmI) + return false; + + Texture2D sprite = ModContent.Request(Texture).Value; + + Effect tileEffect = Filters.Scene["WulfrumScaffoldSelection"].GetShader().Shader; + + tileEffect.Parameters["mainOpacity"].SetValue(1f); + tileEffect.Parameters["tileEdgeBlendStrenght"].SetValue(2f); + tileEffect.Parameters["placementGlowColor"].SetValue(Color.GreenYellow.ToVector4()); + tileEffect.Parameters["baseTintColor"].SetValue(Color.DeepSkyBlue.ToVector4() * 0.5f); + tileEffect.Parameters["scanlineColor"].SetValue(Color.YellowGreen.ToVector4() * 1f); + tileEffect.Parameters["tileEdgeColor"].SetValue(Color.GreenYellow.ToVector3()); + tileEffect.Parameters["Resolution"].SetValue(8f); + + tileEffect.Parameters["time"].SetValue(Main.GameUpdateCount); + Vector4[] scanLines = new Vector4[] + { + new Vector4(0f, 4f, 0.1f, 0.5f), + new Vector4(1f, 4f, 0.1f, 0.5f), + new Vector4(37f, 60f, 0.4f, 1f), + new Vector4(2f, 6f, -0.2f, 0.3f), + new Vector4(0f, 4f, 0.1f, 0.5f), //vertical start + new Vector4(1f, 4f, 0.1f, 0.5f), + new Vector4(2f, 6f, -0.2f, 0.3f) + }; + + tileEffect.Parameters["ScanLines"].SetValue(scanLines); + tileEffect.Parameters["ScanLinesCount"].SetValue(scanLines.Length); + tileEffect.Parameters["verticalScanLinesIndex"].SetValue(4); + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, tileEffect, Main.GameViewMatrix.TransformationMatrix); + + foreach (Point pos in SelectedTiles.Keys) + { + tileEffect.Parameters["blinkTime"].SetValue(SelectedTiles[pos] / (float)tileGlowTime); + tileEffect.Parameters["cardinalConnections"].SetValue(new bool[] { Connected(pos, 0, -1), Connected(pos, -1, 0), Connected(pos, 1, 0), Connected(pos, 0, 1) }); + tileEffect.Parameters["tilePosition"].SetValue(pos.ToVector2() * 16f); + + Main.spriteBatch.Draw(sprite, pos.ToWorldCoordinates() - Main.screenPosition, null, Color.White, 0, new Vector2(sprite.Width / 2f, sprite.Height / 2f), 16f, 0, 0); + } + + CalamityUtils.ExitShaderRegion(Main.spriteBatch); + + return false; + } + + public bool Connected(Point pos, int displaceX, int displaceY) => SelectedTiles.ContainsKey(new Point(pos.X + displaceX, pos.Y + displaceY)); + + + public override void Kill(int timeLeft) + { + if (SelectedTiles.Keys.Count > 0) + SoundEngine.PlaySound(SoundID.Item101 with { Volume = SoundID.Item101.Volume * 0.6f}, Owner.Center); + + if (Main.myPlayer == Owner.whoAmI) + { + foreach (Point pos in SelectedTiles.Keys) + { + if (PipeCleanupManager == null) + PipeCleanupManager = new WulfrumPipeManager(); + + TempTilesManagerSystem.AddTemporaryTile(pos, PipeCleanupManager); + WorldGen.PlaceTile(pos.X, pos.Y, WulfrumScaffoldKit.PlacedTileType) ; + NetMessage.SendTileSquare(-1, pos.X, pos.Y, TileChangeType.None); + } + } + } + } + + + public class WulfrumPipeManager : TemporaryTileManager + { + public override int[] ManagedTypes => new int[] { WulfrumScaffoldKit.PlacedTileType }; + + public override TemporaryTile Setup(Point pos) + { + for (int i = 0; i < 3; i++) + { + Vector2 dustpos = pos.ToWorldCoordinates(); + Dust.NewDustPerfect(dustpos, 83, Main.rand.NextVector2Circular(3f, 3f), Scale: Main.rand.NextFloat(0.4f, 0.7f)); + } + + TemporaryTile tile = new TemporaryTile(pos, this, WulfrumScaffoldKit.TileTime); + return tile; + } + + public override void UpdateEffect(TemporaryTile tile) + { + if (tile.timeleft < WulfrumScaffoldKit.TileTime * 0.1f && Main.rand.NextBool(10)) + { + Vector2 dustpos = tile.position.ToWorldCoordinates(); + Dust.NewDustPerfect(dustpos, 226, Main.rand.NextVector2Circular(4f, 4f), Scale: Main.rand.NextFloat(0.4f, 1f)); + } + } + } +} diff --git a/Sounds/CommonCalamitySounds.cs b/Sounds/CommonCalamitySounds.cs index 2640b25e1c..2547385f6c 100644 --- a/Sounds/CommonCalamitySounds.cs +++ b/Sounds/CommonCalamitySounds.cs @@ -9,6 +9,7 @@ namespace CalamityMod.Sounds public static readonly SoundStyle AstralNPCHitSound = new("CalamityMod/Sounds/NPCHit/AstralEnemyHit", 3); public static readonly SoundStyle AstralNPCDeathSound = new("CalamityMod/Sounds/NPCKilled/AstralEnemyDeath") { Volume = 0.7f }; + public static readonly SoundStyle WulfrumNPCDeathSound = new("CalamityMod/Sounds/NPCKilled/WulfrumDeath"); public static readonly SoundStyle PlagueBoomSound = new("CalamityMod/Sounds/Custom/PlagueSounds/PlagueBoom", 4); @@ -37,5 +38,8 @@ namespace CalamityMod.Sounds public static readonly SoundStyle ScissorGuillotineSnapSound = new("CalamityMod/Sounds/Custom/ScissorGuillotineSnap"); public static readonly SoundStyle LouderPhantomPhoenix = new("CalamityMod/Sounds/Item/LouderPhantomPhoenix", 3); + + public static readonly SoundStyle LouderSwingWoosh = new("CalamityMod/Sounds/Custom/LoudSwingWoosh"); + } } diff --git a/Sounds/Custom/AbilitySounds/WulfrumBastionActivate.ogg b/Sounds/Custom/AbilitySounds/WulfrumBastionActivate.ogg new file mode 100644 index 0000000000..8805e86459 Binary files /dev/null and b/Sounds/Custom/AbilitySounds/WulfrumBastionActivate.ogg differ diff --git a/Sounds/Custom/AbilitySounds/WulfrumBastionBreak.ogg b/Sounds/Custom/AbilitySounds/WulfrumBastionBreak.ogg new file mode 100644 index 0000000000..0838420342 Binary files /dev/null and b/Sounds/Custom/AbilitySounds/WulfrumBastionBreak.ogg differ diff --git a/Sounds/Custom/AbilitySounds/WulfrumBastionBreakSafely.ogg b/Sounds/Custom/AbilitySounds/WulfrumBastionBreakSafely.ogg new file mode 100644 index 0000000000..54ebd12d5c Binary files /dev/null and b/Sounds/Custom/AbilitySounds/WulfrumBastionBreakSafely.ogg differ diff --git a/Sounds/Custom/AbilitySounds/WulfrumBastionRecharge.ogg b/Sounds/Custom/AbilitySounds/WulfrumBastionRecharge.ogg new file mode 100644 index 0000000000..908b505102 Binary files /dev/null and b/Sounds/Custom/AbilitySounds/WulfrumBastionRecharge.ogg differ diff --git a/Sounds/Custom/LoudSwingWoosh.ogg b/Sounds/Custom/LoudSwingWoosh.ogg new file mode 100644 index 0000000000..1717add456 Binary files /dev/null and b/Sounds/Custom/LoudSwingWoosh.ogg differ diff --git a/Sounds/Custom/RoverDriveActivate.ogg b/Sounds/Custom/RoverDriveActivate.ogg new file mode 100644 index 0000000000..127d7e65a3 Binary files /dev/null and b/Sounds/Custom/RoverDriveActivate.ogg differ diff --git a/Sounds/Custom/RoverDriveBreak.ogg b/Sounds/Custom/RoverDriveBreak.ogg new file mode 100644 index 0000000000..c829baf37d Binary files /dev/null and b/Sounds/Custom/RoverDriveBreak.ogg differ diff --git a/Sounds/Custom/RoverDriveHit.ogg b/Sounds/Custom/RoverDriveHit.ogg new file mode 100644 index 0000000000..726ef852e6 Binary files /dev/null and b/Sounds/Custom/RoverDriveHit.ogg differ diff --git a/Sounds/Custom/UltrablingHit.ogg b/Sounds/Custom/UltrablingHit.ogg new file mode 100644 index 0000000000..e0e2baf802 Binary files /dev/null and b/Sounds/Custom/UltrablingHit.ogg differ diff --git a/Sounds/Custom/WulfrumDroidChirp1.ogg b/Sounds/Custom/WulfrumDroidChirp1.ogg new file mode 100644 index 0000000000..874e122f60 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp1.ogg differ diff --git a/Sounds/Custom/WulfrumDroidChirp2.ogg b/Sounds/Custom/WulfrumDroidChirp2.ogg new file mode 100644 index 0000000000..2a7dde01fc Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp2.ogg differ diff --git a/Sounds/Custom/WulfrumDroidChirp3.ogg b/Sounds/Custom/WulfrumDroidChirp3.ogg new file mode 100644 index 0000000000..847313cd6d Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp3.ogg differ diff --git a/Sounds/Custom/WulfrumDroidChirp4.ogg b/Sounds/Custom/WulfrumDroidChirp4.ogg new file mode 100644 index 0000000000..e033b0f0b3 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidChirp4.ogg differ diff --git a/Sounds/Custom/WulfrumDroidFire.ogg b/Sounds/Custom/WulfrumDroidFire.ogg new file mode 100644 index 0000000000..d9f5eaa407 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidFire.ogg differ diff --git a/Sounds/Custom/WulfrumDroidHurry1.ogg b/Sounds/Custom/WulfrumDroidHurry1.ogg new file mode 100644 index 0000000000..c5fa53dc3d Binary files /dev/null and b/Sounds/Custom/WulfrumDroidHurry1.ogg differ diff --git a/Sounds/Custom/WulfrumDroidHurry2.ogg b/Sounds/Custom/WulfrumDroidHurry2.ogg new file mode 100644 index 0000000000..a7a108538f Binary files /dev/null and b/Sounds/Custom/WulfrumDroidHurry2.ogg differ diff --git a/Sounds/Custom/WulfrumDroidRepair.ogg b/Sounds/Custom/WulfrumDroidRepair.ogg new file mode 100644 index 0000000000..c058461278 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidRepair.ogg differ diff --git a/Sounds/Custom/WulfrumDroidSpawnBeep.ogg b/Sounds/Custom/WulfrumDroidSpawnBeep.ogg new file mode 100644 index 0000000000..bc1ba987b1 Binary files /dev/null and b/Sounds/Custom/WulfrumDroidSpawnBeep.ogg differ diff --git a/Sounds/Custom/WulfrumExtraDrop.ogg b/Sounds/Custom/WulfrumExtraDrop.ogg new file mode 100644 index 0000000000..32a86163dd Binary files /dev/null and b/Sounds/Custom/WulfrumExtraDrop.ogg differ diff --git a/Sounds/Custom/WulfrumHookDisengage.ogg b/Sounds/Custom/WulfrumHookDisengage.ogg new file mode 100644 index 0000000000..7963a56faa Binary files /dev/null and b/Sounds/Custom/WulfrumHookDisengage.ogg differ diff --git a/Sounds/Custom/WulfrumHookGrapple.ogg b/Sounds/Custom/WulfrumHookGrapple.ogg new file mode 100644 index 0000000000..02b4739614 Binary files /dev/null and b/Sounds/Custom/WulfrumHookGrapple.ogg differ diff --git a/Sounds/Custom/WulfrumHookShoot.ogg b/Sounds/Custom/WulfrumHookShoot.ogg new file mode 100644 index 0000000000..ea5e4c62d9 Binary files /dev/null and b/Sounds/Custom/WulfrumHookShoot.ogg differ diff --git a/Sounds/Custom/WulfrumMachineBreak.ogg b/Sounds/Custom/WulfrumMachineBreak.ogg new file mode 100644 index 0000000000..0d1280f640 Binary files /dev/null and b/Sounds/Custom/WulfrumMachineBreak.ogg differ diff --git a/Sounds/Custom/WulfrumSawCutting.ogg b/Sounds/Custom/WulfrumSawCutting.ogg new file mode 100644 index 0000000000..c0dcbb75c0 Binary files /dev/null and b/Sounds/Custom/WulfrumSawCutting.ogg differ diff --git a/Sounds/Custom/WulfrumSawIdle.ogg b/Sounds/Custom/WulfrumSawIdle.ogg new file mode 100644 index 0000000000..6ceeb9b0cc Binary files /dev/null and b/Sounds/Custom/WulfrumSawIdle.ogg differ diff --git a/Sounds/Item/WulfrumBlunderbussFire.ogg b/Sounds/Item/WulfrumBlunderbussFire.ogg new file mode 100644 index 0000000000..b2e0e2c4e0 Binary files /dev/null and b/Sounds/Item/WulfrumBlunderbussFire.ogg differ diff --git a/Sounds/Item/WulfrumBlunderbussFireAndReload.ogg b/Sounds/Item/WulfrumBlunderbussFireAndReload.ogg new file mode 100644 index 0000000000..7d829ce601 Binary files /dev/null and b/Sounds/Item/WulfrumBlunderbussFireAndReload.ogg differ diff --git a/Sounds/Item/WulfrumKnifeThrowFull.ogg b/Sounds/Item/WulfrumKnifeThrowFull.ogg new file mode 100644 index 0000000000..77999341ba Binary files /dev/null and b/Sounds/Item/WulfrumKnifeThrowFull.ogg differ diff --git a/Sounds/Item/WulfrumKnifeThrowSingle.ogg b/Sounds/Item/WulfrumKnifeThrowSingle.ogg new file mode 100644 index 0000000000..c858481a92 Binary files /dev/null and b/Sounds/Item/WulfrumKnifeThrowSingle.ogg differ diff --git a/Sounds/Item/WulfrumKnifeThrowTwo.ogg b/Sounds/Item/WulfrumKnifeThrowTwo.ogg new file mode 100644 index 0000000000..d893171d42 Binary files /dev/null and b/Sounds/Item/WulfrumKnifeThrowTwo.ogg differ diff --git a/Sounds/Item/WulfrumKnifeTileHit1.ogg b/Sounds/Item/WulfrumKnifeTileHit1.ogg new file mode 100644 index 0000000000..00b7508be6 Binary files /dev/null and b/Sounds/Item/WulfrumKnifeTileHit1.ogg differ diff --git a/Sounds/Item/WulfrumKnifeTileHit2.ogg b/Sounds/Item/WulfrumKnifeTileHit2.ogg new file mode 100644 index 0000000000..8ba62c1739 Binary files /dev/null and b/Sounds/Item/WulfrumKnifeTileHit2.ogg differ diff --git a/Sounds/Item/WulfrumPing.ogg b/Sounds/Item/WulfrumPing.ogg new file mode 100644 index 0000000000..9fe52766f9 Binary files /dev/null and b/Sounds/Item/WulfrumPing.ogg differ diff --git a/Sounds/Item/WulfrumPingBreak.ogg b/Sounds/Item/WulfrumPingBreak.ogg new file mode 100644 index 0000000000..b598685edc Binary files /dev/null and b/Sounds/Item/WulfrumPingBreak.ogg differ diff --git a/Sounds/Item/WulfrumPingReady.ogg b/Sounds/Item/WulfrumPingReady.ogg new file mode 100644 index 0000000000..8fb52e8c50 Binary files /dev/null and b/Sounds/Item/WulfrumPingReady.ogg differ diff --git a/Sounds/Item/WulfrumProsthesisHit.ogg b/Sounds/Item/WulfrumProsthesisHit.ogg new file mode 100644 index 0000000000..46c85757bc Binary files /dev/null and b/Sounds/Item/WulfrumProsthesisHit.ogg differ diff --git a/Sounds/Item/WulfrumProsthesisShoot.ogg b/Sounds/Item/WulfrumProsthesisShoot.ogg new file mode 100644 index 0000000000..12a62ad09b Binary files /dev/null and b/Sounds/Item/WulfrumProsthesisShoot.ogg differ diff --git a/Sounds/Item/WulfrumProsthesisSucc.ogg b/Sounds/Item/WulfrumProsthesisSucc.ogg new file mode 100644 index 0000000000..36e48a17ea Binary files /dev/null and b/Sounds/Item/WulfrumProsthesisSucc.ogg differ diff --git a/Sounds/Item/WulfrumProsthesisSuccStop.ogg b/Sounds/Item/WulfrumProsthesisSuccStop.ogg new file mode 100644 index 0000000000..7907885f0b Binary files /dev/null and b/Sounds/Item/WulfrumProsthesisSuccStop.ogg differ diff --git a/Sounds/Item/WulfrumScrewdriverScrewGet.ogg b/Sounds/Item/WulfrumScrewdriverScrewGet.ogg new file mode 100644 index 0000000000..281bbf3dbd Binary files /dev/null and b/Sounds/Item/WulfrumScrewdriverScrewGet.ogg differ diff --git a/Sounds/Item/WulfrumScrewdriverScrewHit.ogg b/Sounds/Item/WulfrumScrewdriverScrewHit.ogg new file mode 100644 index 0000000000..b5ad5af9b1 Binary files /dev/null and b/Sounds/Item/WulfrumScrewdriverScrewHit.ogg differ diff --git a/Sounds/Item/WulfrumScrewdriverThrust.ogg b/Sounds/Item/WulfrumScrewdriverThrust.ogg new file mode 100644 index 0000000000..d8de50ab0c Binary files /dev/null and b/Sounds/Item/WulfrumScrewdriverThrust.ogg differ diff --git a/Sounds/Item/WulfrumScrewdriverThud.ogg b/Sounds/Item/WulfrumScrewdriverThud.ogg new file mode 100644 index 0000000000..cbffa078e6 Binary files /dev/null and b/Sounds/Item/WulfrumScrewdriverThud.ogg differ diff --git a/Sounds/NPCKilled/WulfrumDeath.ogg b/Sounds/NPCKilled/WulfrumDeath.ogg new file mode 100644 index 0000000000..f89264d7d7 Binary files /dev/null and b/Sounds/NPCKilled/WulfrumDeath.ogg differ diff --git a/Systems/TempTilesManagerSystem.cs b/Systems/TempTilesManagerSystem.cs new file mode 100644 index 0000000000..fdfa96f88f --- /dev/null +++ b/Systems/TempTilesManagerSystem.cs @@ -0,0 +1,164 @@ +using Microsoft.Xna.Framework; +using Terraria.ModLoader; +using CalamityMod.Items.Tools; +using CalamityMod.Systems; +using Terraria; +using CalamityMod.Items.Materials; +using System.Linq; +using Terraria.ID; +using System.Collections.Generic; +using Microsoft.Xna.Framework.Graphics; +using Terraria.Graphics.Shaders; +using Terraria.Graphics.Effects; +using CalamityMod.Tiles; + +namespace CalamityMod.Systems +{ + /// + /// Useful for temporary tiles that may want to use custom drawing effects with a constant high update rate idependent of the lightning mode + /// + public interface ISpecialTempTileDraw + { + public void CoolDraw(int i, int j, SpriteBatch spriteBatch); + } + + public abstract class TemporaryTileManager + { + /// + /// All the tile types managed by this manager. + /// + public abstract int[] ManagedTypes { get; } + + /// + /// Called every frame. Use this to create special effects or update stuff + /// + /// + public virtual void UpdateEffect(TemporaryTile tile) { } + + /// + /// Creates a temporary tile + /// + /// + public abstract TemporaryTile Setup(Point pos); + + /// + /// Called when a tile runs out of time + /// + public virtual void EndEffect(TemporaryTile tile) { } + } + + public struct TemporaryTile + { + public Point position; + public int timeleft; + public TemporaryTileManager manager; + + public TemporaryTile(Point pos, TemporaryTileManager manager_, int timeLeft = 60) + { + position = pos; + manager = manager_; + timeleft = timeLeft; + } + } + + public class TempTilesManagerSystem : ModSystem + { + public static int[] TemporaryTileIDs; + + public static List ManagedTiles = new List(); + public static List DeletableTiles = new List(); + + public override void Load() + { + ManagedTiles = new List(); + DeletableTiles = new List(); + } + + public override void Unload() + { + ManagedTiles = null; + DeletableTiles = null; + } + public override void PostAddRecipes() + { + TemporaryTileIDs = new int[] { WulfrumScaffoldKit.PlacedTileType }; + } + + /// + /// Adds a temporary tile at the specified position with the specified tile manager + /// The temporary tile manager is used to manage all the effects and placement of the temporary tile. + /// + /// + /// + public static void AddTemporaryTile(Point position, TemporaryTileManager manager) + { + TemporaryTile tile = manager.Setup(position); + ManagedTiles.Add(tile); + } + + /// + /// Requests the time left for a temporary tile at a specified position. + /// + /// The position of the temporary tile + /// + public static int GetTemporaryTileTime(Point position) + { + return ManagedTiles.Find(t => t.position == position).timeleft; + } + + public override void OnWorldUnload() + { + ManagedTiles = new List(); + DeletableTiles = new List(); + } + + public override void PostDrawTiles() + { + if (ManagedTiles.Count <= 0) + return; + + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + foreach (TemporaryTile tile in ManagedTiles) + { + if (TileLoader.GetTile(Main.tile[tile.position].TileType) is ISpecialTempTileDraw coolTile) + coolTile.CoolDraw(tile.position.X, tile.position.Y, Main.spriteBatch); + } + + Main.spriteBatch.End(); + } + + public override void PostUpdateEverything() + { + for (int i = 0; i < ManagedTiles.Count; i++) + { + TemporaryTile tile = ManagedTiles[i]; + TemporaryTileManager manager = tile.manager; + + if (!manager.ManagedTypes.Contains(Main.tile[tile.position].TileType)) + { + DeletableTiles.Add(tile); + continue; + } + + manager.UpdateEffect(tile); + tile.timeleft--; + + if (tile.timeleft < 0) + { + manager.EndEffect(tile); + WorldGen.KillTile(tile.position.X, tile.position.Y); + NetMessage.SendTileSquare(-1, tile.position.X, tile.position.Y, TileChangeType.None); + DeletableTiles.Add(tile); + } + + ManagedTiles[i] = tile; + } + + foreach (TemporaryTile deletableTile in DeletableTiles) + ManagedTiles.Remove(deletableTile); + + DeletableTiles.Clear(); + } + } +} diff --git a/Systems/TilePingerSystem.cs b/Systems/TilePingerSystem.cs new file mode 100644 index 0000000000..5a2449e71c --- /dev/null +++ b/Systems/TilePingerSystem.cs @@ -0,0 +1,354 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.Graphics.Effects; +using Terraria.ID; +using Terraria.Audio; +using Terraria.ModLoader; +using CalamityMod.Items.Tools; +using Terraria.Graphics.Light; + +namespace CalamityMod.Systems +{ + public interface IPingedTileEffect + { + /// + /// The blend state of the tile effect's main shader. + /// + public BlendState BlendState => BlendState.AlphaBlend; + /// + /// Create and set up an effect to be drawn over all the registered tiles for this shader. + /// + /// The configured effect + public Effect SetupEffect(); + /// + /// Modifies the shader for each tile. Use this if your shader is using tile-specific data. + /// + /// The position of the tile + /// The effect being used + public void PerTileSetup(Point pos, ref Effect effect) { } + /// + /// Draws the tile, or an overlay for it. The shader is automatically applied. + /// + /// The position of the tile + public void DrawTile(Point pos); + /// + /// What happens when a ping for this effect gets requested. Return false if the ping couldn't get added. + /// + /// Position of the ping being requested + /// The player that initiated the ping + /// Wether or not the ping's setup was successful + public bool TryAddPing(Vector2 position, Player pinger); + /// + /// Wether or not this effect is active. + /// + public bool Active => true; + /// + /// Check to know if a tile needs to be drawn with this effect. This is only called if the effect is active. + /// + /// + /// + /// Wether or not the tile should be drawn with the effect + public bool ShouldRegisterTile(int x, int y); + /// + /// Called after a tile has been queued to be drawn with this effect. Can be used to edit the draw data of the tile. + /// + /// + /// + /// The tile's draw data + public void EditDrawData(int i, int j, ref TileDrawInfo drawData) { } + /// + /// Update call ran once per frame. + /// + public void UpdateEffect() { } + } + + public class TilePingerSystem : ModSystem + { + internal static Dictionary> pingedTiles; + internal static Dictionary> pingedNonSolidTiles; + internal static Dictionary> drawCache; + + internal static Dictionary tileEffects; + + public override void Load() + { + if (Main.dedServ) + return; + + drawCache = new Dictionary>(); + pingedTiles = new Dictionary>(); + pingedNonSolidTiles = new Dictionary>(); + tileEffects = new Dictionary(); + } + + public override void Unload() + { + drawCache = null; + pingedTiles = null; + pingedNonSolidTiles = null; + tileEffects = null; + } + + public static bool AddPing(string effectName, Vector2 position, Player pinger) => AddPing(tileEffects[effectName], position, pinger); + public static bool AddPing(IPingedTileEffect effect, Vector2 position, Player pinger) => effect.TryAddPing(position, pinger); + + + public static void RegisterTileToDraw(Point tilePos, string effectName, bool solid = true) => RegisterTileToDraw(tilePos, tileEffects[effectName], solid); + public static void RegisterTileToDraw(Point tilePos, IPingedTileEffect effect, bool solid = true) + { + //Unless we are in color light mode, we do not need the distinction between solid and non solid tiles. + if (solid || !(Lighting.Mode == LightMode.Color)) + { + if (!pingedTiles.ContainsKey(effect)) + pingedTiles.Add(effect, new List()); + + if (!pingedTiles[effect].Contains(tilePos)) + pingedTiles[effect].Add(tilePos); + } + + else + { + if (!pingedNonSolidTiles.ContainsKey(effect)) + pingedNonSolidTiles.Add(effect, new List()); + + if (!pingedNonSolidTiles[effect].Contains(tilePos)) + pingedNonSolidTiles[effect].Add(tilePos); + + + } + } + + public override void PostUpdateEverything() + { + foreach (IPingedTileEffect effect in tileEffects.Values) + { + effect.UpdateEffect(); + } + } + + public override void PostDrawTiles() + { + if (pingedTiles.Keys.Count + pingedNonSolidTiles.Count < 1) + return; + + drawCache.Clear(); + + foreach (IPingedTileEffect solidEffect in pingedTiles.Keys) + { + drawCache.Add(solidEffect, pingedTiles[solidEffect].ConvertAll(position => new Point(position.X, position.Y))); + } + + if (Lighting.Mode == LightMode.Color) + { + foreach (IPingedTileEffect nonSolidEffect in pingedNonSolidTiles.Keys) + { + List clonedList = pingedNonSolidTiles[nonSolidEffect].ConvertAll(position => new Point(position.X, position.Y)); + + if (!drawCache.ContainsKey(nonSolidEffect)) + drawCache.Add(nonSolidEffect, clonedList); + + else + { + drawCache[nonSolidEffect].AddRange(clonedList); + } + } + } + + foreach (IPingedTileEffect tileEffect in drawCache.Keys) + //foreach (IPingedTileEffect tileEffect in pingedTiles.Keys) + { + Effect effect = tileEffect.SetupEffect(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, tileEffect.BlendState, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, effect, Main.GameViewMatrix.TransformationMatrix); + + foreach (Point tilePos in drawCache[tileEffect]) + //foreach (Point tilePos in pingedTiles[tileEffect]) + { + tileEffect.PerTileSetup(tilePos, ref effect); + tileEffect.DrawTile(tilePos); + + } + + Main.spriteBatch.End(); + } + } + + public static void ClearTiles() + { + ClearTiles(true); + ClearTiles(false); + } + public static void ClearTiles(bool solid) + { + if (solid) + pingedTiles.Clear(); + + else + pingedNonSolidTiles.Clear(); + } + } + + public class GlobalPingableTile : GlobalTile + { + public override void DrawEffects(int i, int j, int type, SpriteBatch spriteBatch, ref TileDrawInfo drawData) + { + foreach(IPingedTileEffect effect in TilePingerSystem.tileEffects.Values) + { + if (effect.Active && effect.ShouldRegisterTile(i, j)) + { + int tileType = Main.tile[i, j].TileType; + bool solid = true; + + //Necessary separation in the color lighting mode. + if (Lighting.Mode == LightMode.Color) + { + if (TileID.Sets.DrawTileInSolidLayer[tileType].HasValue) + solid = TileID.Sets.DrawTileInSolidLayer[tileType].Value; + else + solid = Main.tileSolid[tileType]; + } + + TilePingerSystem.RegisterTileToDraw(new Point(i, j), effect, solid); + effect.EditDrawData(i, j, ref drawData); + } + } + } + } + + public class WulfrumPingTileEffect : IPingedTileEffect, ILoadable + { + internal static Texture2D emptyFrame; + const int MaxPingLife = 350; + const int MaxPingTravelTime = 60; + const float PingWaveThickness = 50f; + + const float MaxPingRadius = 1700f; + public static Vector2 PingCenter = Vector2.Zero; + public static int PingTimer = 0; + public static float PingProgress => (MaxPingLife - PingTimer) / (float)MaxPingLife; + + public bool Active => PingTimer > 0; + + public BlendState BlendState => BlendState.Additive; + + public bool TryAddPing(Vector2 position, Player pinger) + { + //Only one ping at a time + if (Active) + return false; + + PingCenter = position; + PingTimer = MaxPingLife; + return true; + } + + + public Effect SetupEffect() + { + if (emptyFrame == null) + emptyFrame = ModContent.Request("CalamityMod/Projectiles/InvisibleProj").Value; + + Effect tileEffect = Filters.Scene["WulfrumTilePing"].GetShader().Shader; + tileEffect.Parameters["pingCenter"].SetValue(PingCenter); + tileEffect.Parameters["pingRadius"].SetValue(MaxPingRadius); + tileEffect.Parameters["pingWaveThickness"].SetValue(PingWaveThickness); + tileEffect.Parameters["pingProgress"].SetValue(PingProgress); + tileEffect.Parameters["pingTravelTime"].SetValue(MaxPingTravelTime / (float)MaxPingLife); + tileEffect.Parameters["pingFadePoint"].SetValue(0.9f); + tileEffect.Parameters["edgeBlendStrength"].SetValue(1f); + tileEffect.Parameters["edgeBlendOutLenght"].SetValue(6f); + tileEffect.Parameters["tileEdgeBlendStrenght"].SetValue(2f); + + tileEffect.Parameters["waveColor"].SetValue(Color.GreenYellow.ToVector4()); + tileEffect.Parameters["baseTintColor"].SetValue(Color.DeepSkyBlue.ToVector4() * 0.5f); + tileEffect.Parameters["scanlineColor"].SetValue(Color.YellowGreen.ToVector4() * 1f); + tileEffect.Parameters["tileEdgeColor"].SetValue(Color.GreenYellow.ToVector3()); + tileEffect.Parameters["Resolution"].SetValue(8f); + + tileEffect.Parameters["time"].SetValue(Main.GameUpdateCount); + Vector4[] scanLines = new Vector4[] + { + new Vector4(0f, 4f, 0.1f, 0.5f), + new Vector4(1f, 4f, 0.1f, 0.5f), + new Vector4(37f, 60f, 0.4f, 1f), + new Vector4(2f, 6f, -0.2f, 0.3f), + new Vector4(0f, 4f, 0.1f, 0.5f), //vertical start + new Vector4(1f, 4f, 0.1f, 0.5f), + new Vector4(2f, 6f, -0.2f, 0.3f) + }; + + tileEffect.Parameters["ScanLines"].SetValue(scanLines); + tileEffect.Parameters["ScanLinesCount"].SetValue(scanLines.Length); + tileEffect.Parameters["verticalScanLinesIndex"].SetValue(4); + + return tileEffect; + } + + public void PerTileSetup(Point pos, ref Effect effect) + { + //Up, left, right, down. + effect.Parameters["cardinalConnections"].SetValue(new bool[] { Connected(pos, 0, -1), Connected(pos, -1, 0), Connected(pos, 1, 0), Connected(pos, 0, 1) }); + effect.Parameters["tilePosition"].SetValue(pos.ToVector2() * 16f); + } + + public static bool Connected(Point pos, int displaceX, int displaceY) => Main.IsTileSpelunkable(pos.X + displaceX, pos.Y + displaceY) && Main.tile[pos].TileType == Main.tile[pos.X + displaceX, pos.Y + displaceY].TileType; + + public bool ShouldRegisterTile(int x, int y) + { + return Main.IsTileSpelunkable(x, y); + } + + public void DrawTile(Point pos) + { + Main.spriteBatch.Draw(emptyFrame, pos.ToWorldCoordinates() - Main.screenPosition, null, Color.White, 0, new Vector2(emptyFrame.Width / 2f, emptyFrame.Height / 2f), 16f, 0, 0); + } + + public void EditDrawData(int i, int j, ref TileDrawInfo drawData) + { + float distanceFromCenter = (new Point(i, j).ToWorldCoordinates() - PingCenter).Length(); + float currentExpansion = MathHelper.Clamp(PingProgress * MaxPingLife / (float)MaxPingTravelTime, 0f, 1f) * MaxPingRadius; + + if (distanceFromCenter - 8 > currentExpansion) + return; + + float brightness = 1f; + Tile tile = Framing.GetTileSafely(i, j); + //Counteracts slopes and half tiles being too bright + if (tile.Slope != SlopeType.Solid || tile.IsHalfBlock) + brightness = 0.64f; + + //Fade on the edges + if (distanceFromCenter + 8 > currentExpansion) + brightness *= 1 - (distanceFromCenter - currentExpansion + 8f) / 16f; + + //Fade away with the effect + brightness *= 1 - Math.Max(PingProgress - 0.9f, 0) / (0.1f); + + if (drawData.tileLight.R < 200 * brightness) drawData.tileLight.R = (byte)(200 * brightness); + if (drawData.tileLight.G < 200 * brightness) drawData.tileLight.G = (byte)(200 * brightness); + if (drawData.tileLight.B < 200 * brightness) drawData.tileLight.B = (byte)(200 * brightness); + } + + public void UpdateEffect() + { + if (PingTimer > 0) + { + PingTimer--; + + //if the effect ended (and the player has a treasure pigner in their inventory, of course), play a recharge beep + if (PingTimer == 0 && Main.LocalPlayer.InventoryHas(ModContent.ItemType())) + SoundEngine.PlaySound(WulfrumTreasurePinger.RechargeBeepSound); + } + } + + public void Load(Mod mod) + { + TilePingerSystem.tileEffects.Add("WulfrumPing", this); + } + + public void Unload() { } + } +} diff --git a/Tiles/FurnitureCosmilite/CosmiliteBrick.cs b/Tiles/FurnitureCosmilite/CosmiliteBrick.cs index 18d63459ce..df1a9f3ee1 100644 --- a/Tiles/FurnitureCosmilite/CosmiliteBrick.cs +++ b/Tiles/FurnitureCosmilite/CosmiliteBrick.cs @@ -26,11 +26,6 @@ namespace CalamityMod.Tiles.FurnitureCosmilite return false; } - public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) - { - return TileFraming.BrimstoneFraming(i, j, resetFrame); - } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) { int xPos = Main.tile[i, j].TileFrameX; diff --git a/Tiles/FurnitureCosmilite/CosmiliteBrick.png b/Tiles/FurnitureCosmilite/CosmiliteBrick.png index b2c51767b9..bcb0baf31a 100644 Binary files a/Tiles/FurnitureCosmilite/CosmiliteBrick.png and b/Tiles/FurnitureCosmilite/CosmiliteBrick.png differ diff --git a/Tiles/FurnitureCosmilite/CosmiliteBrickGlow.png b/Tiles/FurnitureCosmilite/CosmiliteBrickGlow.png index fcdac0945d..9aabaa0370 100644 Binary files a/Tiles/FurnitureCosmilite/CosmiliteBrickGlow.png and b/Tiles/FurnitureCosmilite/CosmiliteBrickGlow.png differ diff --git a/Tiles/WulfrumPipes.cs b/Tiles/WulfrumPipes.cs new file mode 100644 index 0000000000..1c7b8f45ed --- /dev/null +++ b/Tiles/WulfrumPipes.cs @@ -0,0 +1,74 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +using Terraria.ID; +using Terraria.Audio; +using Microsoft.Xna.Framework.Graphics; +using Terraria.DataStructures; +using System; +using CalamityMod.Systems; +using CalamityMod.Items.Tools; +using Terraria.GameContent; + +namespace CalamityMod.Tiles +{ + public class WulfrumPipes : ModTile, ISpecialTempTileDraw + { + public static int PlaceTimeMax = 10; + //public float PlaceProgress(Point pos) => Math.Clamp((PlaceTimeStart - Main.GameUpdateCount) / (pos.GetTileRNG() * 5f + 5f), 0, 1); + //public float PlaceProgress(Point pos) => Math.Clamp((PlaceTimeStart - Main.GameUpdateCount) / (pos.GetTileRNG() * 5f + 5f), 0, 1); + + public static Vector2 DisplaceStart(Point pos) => new Vector2(0, -(pos.GetTileRNG() * 10f + 7f)); + public static float RotationStart(Point pos) => - MathHelper.PiOver4 * 0.8f + MathHelper.PiOver4 * 1.6f * pos.GetTileRNG(1); + + + public override void SetStaticDefaults() + { + Main.tileSolid[Type] = true; + Main.tileBlockLight[Type] = true; + + HitSound = SoundID.Item52; + DustType = 83; + AddMapEntry(new Color(128, 90, 77)); + Main.tileLighted[Type] = true; + } + + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + r = 0.00f; + g = 0.6f; + b = 0.3f; + } + + public override void NumDust(int i, int j, bool fail, ref int num) + { + num = Main.rand.NextBool(3) ? 3 : Main.rand.NextBool(3) ? 1 : 2; + } + + public override void PlaceInWorld(int i, int j, Item item) + { + SoundEngine.PlaySound(SoundID.Item52 with { Volume = SoundID.Item52.Volume * 0.75f, Pitch = SoundID.Item52.Pitch - 0.5f }, new Vector2( i * 16, j * 16 )); + } + + public override bool PreDraw(int i, int j, SpriteBatch spriteBatch) + { + return false; + } + + public void CoolDraw(int i, int j, SpriteBatch spriteBatch) + { + Point pos = new Point(i, j); + Tile tile = Main.tile[pos]; + + float timeToGo = pos.GetTileRNG(2) * 22; + float animProgress = (float)Math.Pow(MathHelper.Clamp((TempTilesManagerSystem.GetTemporaryTileTime(pos) - (WulfrumScaffoldKit.TileTime - timeToGo)) / timeToGo, 0, 1), 2); + + Vector2 position = pos.ToWorldCoordinates() + DisplaceStart(pos) * animProgress - Main.screenPosition; + Rectangle frame = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); + + Color tileColor = Lighting.GetColor(pos) * (1 - animProgress); + + Main.spriteBatch.Draw(TextureAssets.Tile[Type].Value, position, frame, tileColor, RotationStart(pos) * animProgress, frame.Size() / 2f, 1f, 0, 0); + } + } +} diff --git a/Tiles/WulfrumPipes.png b/Tiles/WulfrumPipes.png new file mode 100644 index 0000000000..79ab1441f9 Binary files /dev/null and b/Tiles/WulfrumPipes.png differ diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index 5f2a6fd842..b45881e156 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -674,5 +674,75 @@ namespace CalamityMod 1); } } + + /// + /// Draws an item in the inventory with a new texture to replace a previous one. + /// Useful in situations where for example, a different sprite is used for the "real" inventory sprite so it may appear when the player is using it. + /// + /// + /// + /// + /// + /// + /// + /// + public static void DrawNewInventorySprite(this SpriteBatch spriteBatch, Texture2D newTexture, Vector2 originalSize, Vector2 position, Color drawColor, Vector2 origin, float scale, Vector2? offset = null) + { + Vector2 extraOffset; + if (offset == null) + extraOffset = Vector2.Zero; + else + extraOffset = offset.GetValueOrDefault(); + + float largestDimensionOriginal = Math.Max(originalSize.X, originalSize.Y); + float largestDimensionNew = Math.Max(newTexture.Width, newTexture.Height); + + //Scale the sprite so it will account for the dimension of the new sprite if it is larger than the old one (As in, we need to scale down the scale or else it will be too large) + float scaleRatio = Math.Min(largestDimensionOriginal / largestDimensionNew, 1); + + //Offset the jellyfish sprite properly, since the fishing rod is larger than the jellyfish (Jellyfish width : 28px, Fishing rod width : 42) + Vector2 positionOffset = Vector2.Zero; + + if (originalSize.X > newTexture.Width) + positionOffset.X = (originalSize.X - newTexture.Width) / 2f; + + positionOffset *= scale; + + spriteBatch.Draw(newTexture, position + positionOffset + extraOffset, null, drawColor, 0f, origin, scale * scaleRatio, 0, 0); + } + + + public delegate void ChromaAberrationDelegate(Vector2 offset, Color colorMult); + //Thanks spirit <3 + /// + /// Draws a chromatic abberation effect. + /// + /// The direction of the abberation + /// The strenght of the abberation + /// The draw call itself. + public static void DrawChromaticAberration(Vector2 direction, float strength, ChromaAberrationDelegate drawCall) + { + for (int i = -1; i <= 1; i++) + { + Color aberrationColor = Color.White; + switch (i) + { + case -1: + aberrationColor = new Color(255, 0, 0, 0); + break; + case 0: + aberrationColor = new Color(0, 255, 0, 0); + break; + case 1: + aberrationColor = new Color(0, 0, 255, 0); + break; + } + + Vector2 offset = direction.RotatedBy(MathHelper.PiOver2) * i; + offset *= strength; + + drawCall.Invoke(offset, aberrationColor); + } + } } } diff --git a/Utilities/MathematicalUtils.cs b/Utilities/MathematicalUtils.cs index 76999f398f..6b4628e3ad 100644 --- a/Utilities/MathematicalUtils.cs +++ b/Utilities/MathematicalUtils.cs @@ -154,6 +154,50 @@ namespace CalamityMod return fireVelocity; } + /// + /// Calculates the shortest distance between a point and a line that passes through 2 specified points + /// + /// + /// + /// + /// + public static float ShortestDistanceToLine(this Vector2 point, Vector2 lineStart, Vector2 lineEnd) + { + Vector2 lineVector = lineEnd - lineStart; + Vector2 perpendicular = lineVector.RotatedBy(MathHelper.PiOver2); + Vector2 pointToOrigin = point - lineStart; + + return (float)Math.Abs((pointToOrigin.X * perpendicular.X + pointToOrigin.Y * perpendicular.Y)) / perpendicular.Length(); + } + + /// + /// Gets the closest point on a line from a point + /// + /// + /// + /// + /// + public static Vector2 ClosestPointOnLine(this Vector2 point, Vector2 lineStart, Vector2 lineEnd) + { + + Vector2 perpendicular = (lineEnd - lineStart).RotatedBy(MathHelper.PiOver2).SafeNormalize(Vector2.Zero); + float distanceToLine = point.ShortestDistanceToLine(lineStart, lineEnd); + float lineSide = Math.Sign((point.X - lineStart.X) * ( -lineEnd.Y + lineStart.Y) + (point.Y - lineStart.Y) * (lineEnd.X - lineStart.X)); + + return point + distanceToLine * lineSide * perpendicular; + } + + /// + /// Gives the *real* modulo of a divided by a divisor. + /// This method is necessary because the % operator in c# keeps the sign of the dividend, making it Fake as Fuck. + /// + /// + /// + /// + public static float Modulo(this float dividend, float divisor) + { + return dividend - (float)Math.Floor(dividend / divisor) * divisor; + } #region Easings /// diff --git a/Utilities/PlayerUtils.cs b/Utilities/PlayerUtils.cs index 4b175b4424..1174e4e6a2 100644 --- a/Utilities/PlayerUtils.cs +++ b/Utilities/PlayerUtils.cs @@ -159,6 +159,27 @@ namespace CalamityMod light += Main.dayTime || player.lavaWet ? 2 : 1; // not sure how you'd be in lava in the abyss but go ham I guess return light; } + + /// + /// Directly retrieves the best pickaxe power of the player. + /// + /// + /// + public static int GetBestPickPower(this Player player) + { + int highestPickPower = 35; //35% if you have no pickaxes. + for (int item = 0; item < Main.InventorySlotsTotal; item++) + { + if (player.inventory[item].pick <= 0) + continue; + if (player.inventory[item].pick > highestPickPower) + { + highestPickPower = player.inventory[item].pick; + } + } + + return highestPickPower; + } #endregion #region Movement and Controls @@ -489,6 +510,21 @@ namespace CalamityMod #region Arms Control + /// + /// Gets an arm stretch amount from a number ranging from 0 to 1 + /// + public static CompositeArmStretchAmount ToStretchAmount(this float percent) + { + if (percent < 0.25f) + return CompositeArmStretchAmount.None; + if (percent < 0.5f) + return CompositeArmStretchAmount.Quarter; + if (percent < 0.75f) + return CompositeArmStretchAmount.ThreeQuarters; + + return CompositeArmStretchAmount.Full; + } + /// /// The exact same thing as Player.GetFrontHandPosition() except it properly accounts for gravity swaps instead of requiring the coders to do it manually afterwards. /// Additionally, it simply takes in the arm data instead of asking for the rotation and stretch separately. @@ -530,10 +566,14 @@ namespace CalamityMod /// The desired position of the item /// The size of the item sprite (used in calculations) /// The offset from the center of the sprite of the rotation origin + /// Should the swirly effect from the sandstorm jump be disabled /// Should the angle get flipped with the player, or should it be rotated by 180 degrees /// Should the item get displaced with the player's height during the walk anim? - public static void CleanHoldStyle(Player player, float desiredRotation, Vector2 desiredPosition, Vector2 spriteSize, Vector2? rotationOriginFromCenter = null, bool flipAngle = false, bool stepDisplace = true) + public static void CleanHoldStyle(Player player, float desiredRotation, Vector2 desiredPosition, Vector2 spriteSize, Vector2? rotationOriginFromCenter = null, bool noSandstorm = false, bool flipAngle = false, bool stepDisplace = true) { + if (noSandstorm) + player.sandStorm = false; + //Since Vector2.Zero isn't a compile-time constant, we can't use it directly as the default parameter if (rotationOriginFromCenter == null) rotationOriginFromCenter = Vector2.Zero; diff --git a/Utilities/TileUtils.cs b/Utilities/TileUtils.cs index d713d80dc0..c5e7b3b261 100644 --- a/Utilities/TileUtils.cs +++ b/Utilities/TileUtils.cs @@ -20,6 +20,8 @@ using Terraria.ID; using Terraria.ModLoader; using Terraria.ObjectData; using static Terraria.ModLoader.ModContent; +using System.Linq; +using System.Collections.Generic; namespace CalamityMod { @@ -504,5 +506,142 @@ namespace CalamityMod /// /// The tile to check. public static bool IsTileSolid(this Tile tile) => tile != null && tile.HasUnactuatedTile && Main.tileSolid[tile.TileType] && !TileID.Sets.Platforms[tile.TileType]; + + /// + /// Determines if a tile is "full" based on if the tile is solid. This will count platforms and actuated tiles but no other non-solid ground tiles. + /// + /// The tile to check. + public static bool IsTileFull(this Tile tile) => tile != null && tile.HasTile && Main.tileSolid[tile.TileType]; + + /// + /// Returns a random number between 0 and 1 that always remains the same based on the tile's coordinates. + /// + /// The tile position to grab the rng from + /// An extra offset. Useful if you need multiple counts of rng for the same time + public static float GetTileRNG(this Point tilePos, int shift = 0) => (float)(Math.Sin(tilePos.X * 17.07947 + shift * 36) + Math.Sin(tilePos.Y * 25.13274)) * 0.25f + 0.5f; + + /// + /// Grabs the nearest tile point to the origin, in the specified direction + /// + /// + /// + /// + public static Point GetNearestPointInDirection(this Point origin, float direction) + { + return origin + new Point((int)Math.Round(Math.Cos(direction)), (int)Math.Round(Math.Sin(direction))); + } + + /// + /// Just like Vector2.ToTileCoordinates, but also clamps the position to the tile grid. + /// + /// + /// The tile coordinates + public static Point ToSafeTileCoordinates(this Vector2 vec) + { + return new Point((int)MathHelper.Clamp((int)vec.X >> 4, 0, Main.maxTilesX), (int)MathHelper.Clamp((int)vec.Y >> 4, 0, Main.maxTilesY)); + } + + /// + /// Is a tile valid to be grappled onto + /// A straight rip of the private method Projectile.AI_007_GrapplingHooks_CanTileBeLatchedOnTo() + /// + /// + /// Wether or not the tile may be grappled onto + public static bool CanTileBeLatchedOnTo(this Tile theTile, bool grappleOnTrees = false) => Main.tileSolid[theTile.TileType] | (theTile.TileType == 314) | (grappleOnTrees && TileID.Sets.IsATreeTrunk[theTile.TileType]) | (grappleOnTrees && theTile.TileType == 323); + + /// + /// Gets the required pickaxe power of a tile, accounting for both the ModTile and the vanilla tile pick requirements + /// + /// + /// The pickaxe power required to break a tile + public static int GetRequiredPickPower(this Tile tile, int i, int j) + { + int pickReq = 0; + + if (Main.tileNoFail[tile.TileType]) + return pickReq; + + ModTile moddedTile = TileLoader.GetTile(tile.TileType); + + //Getting the pickaxe requirement of a modded tile is shrimple. + if (moddedTile != null) + pickReq = moddedTile.MinPick; + + //Getting the pickaxe requirement of a vanilla tile is quite clamplicated + //This was lifted from code in onyx excavator, which likely was lifted from vanilla. It might need 1.4 updating. + else + { + switch (tile.TileType) + { + case TileID.Chlorophyte: + pickReq = 200; + break; + case TileID.Ebonstone: + case TileID.Crimstone: + case TileID.Pearlstone: + case TileID.DesertFossil: + case TileID.Obsidian: + case TileID.Hellstone: + pickReq = 65; + break; + case TileID.Meteorite: + pickReq = 50; + break; + case TileID.Demonite: + case TileID.Crimtane: + if (j > Main.worldSurface) + pickReq = 55; + break; + case TileID.LihzahrdBrick: + case TileID.LihzahrdAltar: + pickReq = 210; + break; + case TileID.Cobalt: + case TileID.Palladium: + pickReq = 100; + break; + case TileID.Mythril: + case TileID.Orichalcum: + pickReq = 110; + break; + case TileID.Adamantite: + case TileID.Titanium: + pickReq = 150; + break; + default: + break; + } + } + + if (Main.tileDungeon[tile.TileType]) + { + if (i < Main.maxTilesX * 0.35 || i > Main.maxTilesX * 0.65) + pickReq = 65; + } + + return pickReq; + } + + /// + /// Returns if a tile is safe to be mined in terms of it being "important" + /// + /// + /// If voidstone and abyss gravel should be considered unsafe to mine + /// + public static bool ShouldBeMined(this Tile tile, bool ignoreAbyss = true) + { + List tileExcludeList = new List() + { + TileID.DemonAltar, TileID.ElderCrystalStand, TileID.LihzahrdAltar, TileID.Dressers, TileID.Containers + }; + + if (ignoreAbyss) + { + tileExcludeList.Add(ModContent.TileType()); + tileExcludeList.Add(ModContent.TileType()); + } + + return !Main.tileContainer[tile.TileType] && !tileExcludeList.Contains(tile.TileType); + } } } diff --git a/build.txt b/build.txt index 307237585f..0f312564fd 100644 --- a/build.txt +++ b/build.txt @@ -1,5 +1,5 @@ author = Fabsol and the Dev Team -version = 2.0.0.003 +version = 2.0.0.004 displayName = Calamity Mod homepage = https://discord.gg/calamity buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, .git\*, LICENSE, README.md, .editorconfig, .gitignore, .gitattributes