diff --git a/Backgrounds/AstralDesertSurfaceBGStyle.cs b/Backgrounds/AstralDesertSurfaceBGStyle.cs index 181f0d7222..d5ef0d60c7 100644 --- a/Backgrounds/AstralDesertSurfaceBGStyle.cs +++ b/Backgrounds/AstralDesertSurfaceBGStyle.cs @@ -5,6 +5,7 @@ using Terraria.Graphics.Effects; using Terraria; using Terraria.ModLoader; using Microsoft.Xna.Framework; +using CalamityMod.Skies; namespace CalamityMod.Backgrounds { @@ -80,7 +81,7 @@ namespace CalamityMod.Backgrounds var bgParallax = 0.4; var bgTopY = (int)(backgroundTopMagicNumber * 1800.0 + 1500.0) + (int)scAdj + pushBGTopHack; bgScale *= bgGlobalScaleMultiplier; - var bgWidthScaled = (int)((float)CalamityMod.AstralDesertSurfaceMiddle.Width * bgScale); + var bgWidthScaled = (int)((float)SkyTextureRefs.AstralDesertSurfaceMiddle.Value.Width * bgScale); SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1.2f / (float)bgParallax); var bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); if (Main.gameMenu) @@ -91,7 +92,7 @@ namespace CalamityMod.Backgrounds { for (int i = 0; i < bgLoops; i++) { - Main.spriteBatch.Draw(CalamityMod.AstralDesertSurfaceMiddle, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralDesertSurfaceMiddle.Width, CalamityMod.AstralDesertSurfaceMiddle.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralDesertSurfaceMiddle.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralDesertSurfaceMiddle.Value.Width, SkyTextureRefs.AstralDesertSurfaceMiddle.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } @@ -99,7 +100,7 @@ namespace CalamityMod.Backgrounds bgParallax = 0.43; bgTopY = (int)(backgroundTopMagicNumber * 1950.0 + 1750.0) + (int)scAdj + pushBGTopHack; bgScale *= bgGlobalScaleMultiplier; - bgWidthScaled = (int)((float)CalamityMod.AstralDesertSurfaceClose.Width * bgScale); + bgWidthScaled = (int)((float)SkyTextureRefs.AstralDesertSurfaceClose.Value.Width * bgScale); SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); if (Main.gameMenu) @@ -113,7 +114,7 @@ namespace CalamityMod.Backgrounds { for (int i = 0; i < bgLoops; i++) { - Main.spriteBatch.Draw(CalamityMod.AstralDesertSurfaceClose, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralDesertSurfaceClose.Width, CalamityMod.AstralDesertSurfaceClose.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralDesertSurfaceClose.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralDesertSurfaceClose.Value.Width, SkyTextureRefs.AstralDesertSurfaceClose.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } } diff --git a/Backgrounds/AstralSnowSurfaceBGStyle.cs b/Backgrounds/AstralSnowSurfaceBGStyle.cs index 239fc427b3..7300b8c7e3 100644 --- a/Backgrounds/AstralSnowSurfaceBGStyle.cs +++ b/Backgrounds/AstralSnowSurfaceBGStyle.cs @@ -6,6 +6,7 @@ using Terraria; using Terraria.ModLoader; using Microsoft.Xna.Framework; using Terraria.GameContent.UI.States; +using CalamityMod.Skies; namespace CalamityMod.Backgrounds { @@ -82,7 +83,7 @@ namespace CalamityMod.Backgrounds var bgParallax = 0.4; var bgTopY = (int)(backgroundTopMagicNumber * 1800.0 + 1500.0) + (int)scAdj + pushBGTopHack; bgScale *= bgGlobalScaleMultiplier; - var bgWidthScaled = (int)((float)CalamityMod.AstralSnowSurfaceMiddle.Width * bgScale); + var bgWidthScaled = (int)((float)SkyTextureRefs.AstralSnowSurfaceMiddle.Value.Width * bgScale); SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1.2f / (float)bgParallax); var bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); if (Main.gameMenu) @@ -93,7 +94,7 @@ namespace CalamityMod.Backgrounds { for (int i = 0; i < bgLoops; i++) { - Main.spriteBatch.Draw(CalamityMod.AstralSnowSurfaceMiddle, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSnowSurfaceMiddle.Width, CalamityMod.AstralSnowSurfaceMiddle.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSnowSurfaceMiddle.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSnowSurfaceMiddle.Value.Width, SkyTextureRefs.AstralSnowSurfaceMiddle.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } @@ -101,7 +102,7 @@ namespace CalamityMod.Backgrounds bgParallax = 0.43; bgTopY = (int)(backgroundTopMagicNumber * 1950.0 + 1750.0) + (int)scAdj + pushBGTopHack; bgScale *= bgGlobalScaleMultiplier; - bgWidthScaled = (int)((float)CalamityMod.AstralSurfaceClose.Width * bgScale); + bgWidthScaled = (int)((float)SkyTextureRefs.AstralSurfaceClose.Value.Width * bgScale); SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); if (Main.gameMenu) @@ -115,15 +116,15 @@ namespace CalamityMod.Backgrounds { for (int i = 0; i < bgLoops; i++) { - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceClose, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceClose.Width, CalamityMod.AstralSurfaceClose.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceCloseGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceCloseGlow.Width, CalamityMod.AstralSurfaceCloseGlow.Height), new Color(Color.White.R * 0.7f, Color.White.G * 0.7f, Color.White.B * 0.7f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceClose.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceClose.Value.Width, SkyTextureRefs.AstralSurfaceClose.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceCloseGlow.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceCloseGlow.Value.Width, SkyTextureRefs.AstralSurfaceCloseGlow.Value.Height), new Color(Color.White.R * 0.7f, Color.White.G * 0.7f, Color.White.B * 0.7f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } bgScale = 1.34f; bgParallax = 0.49; bgTopY = (int)(backgroundTopMagicNumber * 2100.0 + 2000.0) + (int)scAdj + pushBGTopHack; bgScale *= bgGlobalScaleMultiplier; - bgWidthScaled = (int)(CalamityMod.AstralSurfaceFront.Width * bgScale); + bgWidthScaled = (int)(SkyTextureRefs.AstralSurfaceFront.Value.Width * bgScale); SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); if (Main.gameMenu) @@ -137,8 +138,8 @@ namespace CalamityMod.Backgrounds { for (int i = 0; i < bgLoops; i++) { - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFront, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFront.Width, CalamityMod.AstralSurfaceFront.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFrontGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFrontGlow.Width, CalamityMod.AstralSurfaceFrontGlow.Height), new Color(Color.White.R * 0.9f, Color.White.G * 0.9f, Color.White.B * 0.9f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceFront.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceFront.Value.Width, SkyTextureRefs.AstralSurfaceFront.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceFrontGlow.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceFrontGlow.Value.Width, SkyTextureRefs.AstralSurfaceFrontGlow.Value.Height), new Color(Color.White.R * 0.9f, Color.White.G * 0.9f, Color.White.B * 0.9f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } } diff --git a/Backgrounds/AstralSurfaceBGStyle.cs b/Backgrounds/AstralSurfaceBGStyle.cs index bc53eed640..c32d475687 100644 --- a/Backgrounds/AstralSurfaceBGStyle.cs +++ b/Backgrounds/AstralSurfaceBGStyle.cs @@ -5,6 +5,7 @@ using System; using Terraria.Graphics.Effects; using Terraria; using Terraria.ModLoader; +using CalamityMod.Skies; namespace CalamityMod.Backgrounds { @@ -86,7 +87,7 @@ namespace CalamityMod.Backgrounds var bgParallax = 0.4; //The parallax of the background layer var bgTopY = (int)(backgroundTopMagicNumber * 1800.0 + 1500.0) + (int)scAdj + pushBGTopHack; //the Y position of the background bgScale *= bgGlobalScaleMultiplier; //Scale of the background - var bgWidthScaled = (int)((float)CalamityMod.AstralSurfaceMiddle.Width * bgScale); //The Width of the bg texture scaled to the correct size + var bgWidthScaled = (int)((float)SkyTextureRefs.AstralSurfaceMiddle.Value.Width * bgScale); //The Width of the bg texture scaled to the correct size SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1.2f / (float)bgParallax); var bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); //The starting position of the background layer if (Main.gameMenu) @@ -98,8 +99,8 @@ namespace CalamityMod.Backgrounds for (int i = 0; i < bgLoops; i++) { //Draw the texture and its glowmask to each loop of the texture - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceMiddle, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceMiddle.Width, CalamityMod.AstralSurfaceMiddle.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceMiddleGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceMiddleGlow.Width, CalamityMod.AstralSurfaceMiddleGlow.Height), new Color(Color.White.R * 0.5f, Color.White.G * 0.5f, Color.White.B * 0.5f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceMiddle.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceMiddle.Value.Width, SkyTextureRefs.AstralSurfaceMiddle.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceMiddleGlow.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + MiddleBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceMiddleGlow.Value.Width, SkyTextureRefs.AstralSurfaceMiddleGlow.Value.Height), new Color(Color.White.R * 0.5f, Color.White.G * 0.5f, Color.White.B * 0.5f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } @@ -109,7 +110,7 @@ namespace CalamityMod.Backgrounds bgParallax = 0.43; bgTopY = (int)(backgroundTopMagicNumber * 1950.0 + 1750.0) + (int)scAdj + pushBGTopHack; bgScale *= bgGlobalScaleMultiplier; - bgWidthScaled = (int)((float)CalamityMod.AstralSurfaceClose.Width * bgScale); + bgWidthScaled = (int)((float)SkyTextureRefs.AstralSurfaceClose.Value.Width * bgScale); SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); if (Main.gameMenu) @@ -123,8 +124,8 @@ namespace CalamityMod.Backgrounds { for (int i = 0; i < bgLoops; i++) { - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceClose, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceClose.Width, CalamityMod.AstralSurfaceClose.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceCloseGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceCloseGlow.Width, CalamityMod.AstralSurfaceCloseGlow.Height), new Color(Color.White.R * 0.7f, Color.White.G * 0.7f, Color.White.B * 0.7f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceClose.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceClose.Value.Width, SkyTextureRefs.AstralSurfaceClose.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceCloseGlow.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + CloseBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceCloseGlow.Value.Width, SkyTextureRefs.AstralSurfaceCloseGlow.Value.Height), new Color(Color.White.R * 0.7f, Color.White.G * 0.7f, Color.White.B * 0.7f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } @@ -134,7 +135,7 @@ namespace CalamityMod.Backgrounds bgParallax = 0.49; bgTopY = (int)(backgroundTopMagicNumber * 2100.0 + 2000.0) + (int)scAdj + pushBGTopHack; bgScale *= bgGlobalScaleMultiplier; - bgWidthScaled = (int)(CalamityMod.AstralSurfaceFront.Width * bgScale); + bgWidthScaled = (int)(SkyTextureRefs.AstralSurfaceFront.Value.Width * bgScale); SkyManager.Instance.DrawToDepth(Main.spriteBatch, 1f / (float)bgParallax); bgStartX = (int)(0.0 - Math.IEEERemainder((double)Main.screenPosition.X * bgParallax, bgWidthScaled) - (double)(bgWidthScaled / 2)); if (Main.gameMenu) @@ -148,8 +149,8 @@ namespace CalamityMod.Backgrounds { for (int i = 0; i < bgLoops; i++) { - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFront, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFront.Width, CalamityMod.AstralSurfaceFront.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); - Main.spriteBatch.Draw(CalamityMod.AstralSurfaceFrontGlow, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, CalamityMod.AstralSurfaceFrontGlow.Width, CalamityMod.AstralSurfaceFrontGlow.Height), new Color(Color.White.R * 0.9f, Color.White.G * 0.9f, Color.White.B * 0.9f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceFront.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceFront.Value.Width, SkyTextureRefs.AstralSurfaceFront.Value.Height), ColorOfSurfaceBackgroundsModified, 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(SkyTextureRefs.AstralSurfaceFrontGlow.Value, new Vector2(bgStartX + bgWidthScaled * i, bgTopY + FrontBGYOffset), new Rectangle(0, 0, SkyTextureRefs.AstralSurfaceFrontGlow.Value.Width, SkyTextureRefs.AstralSurfaceFrontGlow.Value.Height), new Color(Color.White.R * 0.9f, Color.White.G * 0.9f, Color.White.B * 0.9f, COSBMAplha.A), 0f, default(Vector2), bgScale, SpriteEffects.None, 0f); } } } diff --git a/Balancing/BalancingChangesManager.cs b/Balancing/BalancingChangesManager.cs index c616598aca..154c2ec285 100644 --- a/Balancing/BalancingChangesManager.cs +++ b/Balancing/BalancingChangesManager.cs @@ -26,8 +26,7 @@ using static Terraria.ModLoader.ModContent; namespace CalamityMod.Balancing { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class BalancingChangesManager + public sealed class BalancingChangesManager : ModSystem { internal static List UniversalBalancingChanges = null; internal static List NPCSpecificBalancingChanges = null; @@ -36,7 +35,7 @@ namespace CalamityMod.Balancing // For ease of change, changes that are not exclusive to one specific weapon are not bundled into one line if they share the same resistance factor. // To give an example of this, Thanatos having a 50% resist to Chicken Cannon and Prismatic Breaker should be two distinct lines with a 0.5x factor instead of hamfisting them all // into one single resist that may have to be split later. - internal static void Load() + public override void SetStaticDefaults() { // Dirty shorthand for true melee resists, because they're super common and other class resists aren't. IBalancingRule ResistTrueMelee(float f) => new ClassResistBalancingRule(f, TrueMeleeDamageClass.Instance); @@ -522,7 +521,7 @@ namespace CalamityMod.Balancing #endregion } - internal static void Unload() + public override void Unload() { UniversalBalancingChanges = null; NPCSpecificBalancingChanges = null; diff --git a/Buffs/Mounts/AndromedaBuff.cs b/Buffs/Mounts/AndromedaBuff.cs index e352ea4940..34b4fb6ce9 100644 --- a/Buffs/Mounts/AndromedaBuff.cs +++ b/Buffs/Mounts/AndromedaBuff.cs @@ -14,7 +14,7 @@ namespace CalamityMod.Buffs.Mounts public override void Update(Player player, ref int buffIndex) { // Disables crouching with the Crouch, Crawl, and Roll Mod - Mod crouchMod = CalamityMod.Instance.crouchMod; + Mod crouchMod = ExternalMods.crouchMod; if (crouchMod != null) { // Mod Call inputs diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index ff3a3e3c14..855748bb5a 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -1405,7 +1405,7 @@ namespace CalamityMod.CalPlayer boost.AddWithCondition("HasCraftedDraedonsForge", HasCraftedDraedonsForge); // Calculate the new total time of all sessions at the instant of this player save. - TimeSpan newSessionTotal = previousSessionTotal.Add(CalamityMod.SpeedrunTimer.Elapsed); + TimeSpan newSessionTotal = previousSessionTotal.Add(SpeedrunTimerSystem.Elapsed); long totalTicks = newSessionTotal.Ticks; // Save all cooldowns which are marked as persisting through save/load. @@ -4998,10 +4998,10 @@ namespace CalamityMod.CalPlayer // Enabling the config while a player is loaded will show the timer immediately. // But it won't start running until you save and quit and re-enter a world. if (CalamityClientConfig.Instance.SpeedrunTimer) - CalamityMod.SpeedrunTimer.Restart(); + SpeedrunTimerSystem.Restart(); bool showWikiMessage = CalamityClientConfig.Instance.WikiStatusMessage; - bool showVCMMMessage = CalamityClientConfig.Instance.VCMMStatusMessage && !CalamityMod.Instance.VCMMAvailable; + bool showVCMMMessage = CalamityClientConfig.Instance.VCMMStatusMessage && !ExternalMods.VCMMAvailable; bool showStartupMessages = showWikiMessage || showVCMMMessage; // Set a random delay between 12 and 20 seconds. When this delay hits zero, startup messages display diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 858759d482..b17575ad8e 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -13,6 +13,7 @@ using CalamityMod.CustomRecipes; using CalamityMod.DataStructures; using CalamityMod.Dusts; using CalamityMod.Events; +using CalamityMod.ExtraTextures; using CalamityMod.Items; using CalamityMod.Items.Accessories; using CalamityMod.Items.Ammo; @@ -787,8 +788,8 @@ namespace CalamityMod.CalPlayer // Update Carpet textures if (Main.netMode != NetmodeID.Server && Player.whoAmI == Main.myPlayer) { - Asset carpetAuric = ModContent.Request("CalamityMod/ExtraTextures/AuricCarpet"); - Asset carpetOriginal = CalamityMod.carpetOriginal; + Asset carpetAuric = ExtraTextureRefs.FlyingCarpetAuric; + Asset carpetOriginal = ExtraTextureRefs.FlyingCarpetVanilla; TextureAssets.FlyingCarpet = (auricSet ? carpetAuric : carpetOriginal); } @@ -2866,7 +2867,7 @@ namespace CalamityMod.CalPlayer // 50% movement speed bonus so that you don't feel like a snail in the early game // Disabled while Overhaul is enabled, because Overhaul does very similar things to make movement more snappy - if (CalamityMod.Instance.overhaul is null && CalamityServerConfig.Instance.FasterBaseSpeed) + if (ExternalMods.overhaul is null && CalamityServerConfig.Instance.FasterBaseSpeed) Player.moveSpeed += BalancingConstants.DefaultMoveSpeedBoost; // Reduce how slow Chilled makes the player, because it's cancerous right now @@ -4319,7 +4320,7 @@ namespace CalamityMod.CalPlayer CalamityUtils.DisplayLocalizedText("Mods.CalamityMod.Misc.WikiStatus2"); } - if (CalamityClientConfig.Instance.VCMMStatusMessage && !CalamityMod.Instance.VCMMAvailable) + if (CalamityClientConfig.Instance.VCMMStatusMessage && !ExternalMods.VCMMAvailable) { CalamityUtils.DisplayLocalizedText("Mods.CalamityMod.Misc.VCMMStatus"); } diff --git a/CalPlayer/Dashes/PlayerDashManager.cs b/CalPlayer/Dashes/PlayerDashManager.cs index 724292f85f..38fa36d109 100644 --- a/CalPlayer/Dashes/PlayerDashManager.cs +++ b/CalPlayer/Dashes/PlayerDashManager.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using Terraria; +using Terraria.ModLoader; using Terraria.ModLoader.Core; namespace CalamityMod.CalPlayer.Dashes { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class PlayerDashManager + public sealed class PlayerDashManager : ModSystem { internal static Dictionary DashIdentificationTable = new(); @@ -41,28 +41,20 @@ namespace CalamityMod.CalPlayer.Dashes } - internal static void Load() + public override void OnModLoad() { DashIdentificationTable = new(); - Type baseType = typeof(PlayerDashEffect); - Type[] types = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code); - foreach (Type type in types) + ReflectionHelper.IterateCalamityTypes(action: type => { - // Ignore any types which are not dash effects or are abstract. - // This eliminates the PlayerDashEffect template type, which cannot have instances. - if (!type.IsSubclassOf(baseType) || type.IsAbstract) - continue; - - // Use reflection to get the static ID manually. This shouldn't be a performance problem, as this only happens at load-time. string id = (string)type.GetProperty("ID").GetValue(null); PlayerDashEffect dashEffect = (PlayerDashEffect)Activator.CreateInstance(type); DashIdentificationTable[id] = dashEffect; - } + }); } - internal static void Unload() + public override void Unload() { DashIdentificationTable = null; } diff --git a/CalPlayer/DrawLayers/HeldItemGlowMaskLayer.cs b/CalPlayer/DrawLayers/HeldItemGlowMaskLayer.cs index 92ecc32019..184274f3b4 100644 --- a/CalPlayer/DrawLayers/HeldItemGlowMaskLayer.cs +++ b/CalPlayer/DrawLayers/HeldItemGlowMaskLayer.cs @@ -46,6 +46,8 @@ namespace CalamityMod.CalPlayer.DrawLayers glowMask = ModContent.Request("CalamityMod/Items/Weapons/Ranged/AuralisGlow").Value; else if (itemType == ModContent.ItemType()) glowMask = ModContent.Request("CalamityMod/Items/Weapons/Ranged/AuroraBlazerGlow").Value; + else if (itemType == ModContent.ItemType()) + glowMask = ModContent.Request("CalamityMod/Items/Weapons/Ranged/ChromaticEruptionGlow").Value; else if (itemType == ModContent.ItemType()) glowMask = ModContent.Request("CalamityMod/Items/Weapons/Ranged/CleansingBlazeGlow").Value; else if (itemType == ModContent.ItemType()) @@ -66,6 +68,8 @@ namespace CalamityMod.CalPlayer.DrawLayers glowMask = ModContent.Request("CalamityMod/Items/Weapons/Magic/FatesRevealGlow").Value; else if (itemType == ModContent.ItemType()) glowMask = ModContent.Request("CalamityMod/Items/Weapons/Melee/GreatswordofJudgementGlow").Value; + else if (itemType == ModContent.ItemType()) + glowMask = ModContent.Request("CalamityMod/Items/Weapons/Summon/LegionofCelestiaGlow").Value; else if (itemType == ModContent.ItemType()) glowMask = ModContent.Request("CalamityMod/Items/SummonItems/NecroplasmicBeaconGlow").Value; else if (itemType == ModContent.ItemType()) @@ -80,6 +84,8 @@ namespace CalamityMod.CalPlayer.DrawLayers glowMask = ModContent.Request("CalamityMod/Items/Weapons/DraedonsArsenal/PulseRifleGlow").Value; else if (itemType == ModContent.ItemType()) glowMask = ModContent.Request("CalamityMod/Items/Weapons/Magic/SoulPiercerGlow").Value; + else if (itemType == ModContent.ItemType()) + glowMask = ModContent.Request("CalamityMod/Items/Weapons/Melee/StarburstShivGlow").Value; else if (itemType == ModContent.ItemType()) glowMask = ModContent.Request("CalamityMod/Items/Weapons/Magic/SubsumingVortexSmallGlow").Value; else if (itemType == ModContent.ItemType()) diff --git a/CalamityConfig.cs b/CalamityConfig.cs index 00b5eed916..660857cee5 100644 --- a/CalamityConfig.cs +++ b/CalamityConfig.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Reflection; using System.Runtime.Serialization; using CalamityMod.UI; using CalamityMod.UI.DraedonsArsenal; @@ -25,6 +26,24 @@ namespace CalamityMod ParticleLimit = (int)Utils.Clamp(ParticleLimit, MinParticleLimit, MaxParticleLimit); } + internal static void SaveConfig() + { + // There is no current way to manually save a mod configuration file in tModLoader. + // The method which saves mod config files is private in ConfigManager, so reflection is used to invoke it. + try + { + MethodInfo saveMethodInfo = typeof(ConfigManager).GetMethod("Save", BindingFlags.Static | BindingFlags.NonPublic); + if (saveMethodInfo is not null) + saveMethodInfo.Invoke(null, [Instance]); + else + CalamityMod.Instance.Logger.Error("TML ConfigManager.Save reflection failed. Method signature has changed. Notify Calamity Devs if you see this in your log."); + } + catch + { + CalamityMod.Instance.Logger.Error("An error occurred while manually saving Calamity mod configuration. This may be due to a complex mod conflict. It is safe to ignore this error."); + } + } + #region Multi-Threading Settings [Header("Multithreading")] diff --git a/CalamityLists.cs b/CalamityLists.cs index eb6cfff797..a559cbd8d7 100644 --- a/CalamityLists.cs +++ b/CalamityLists.cs @@ -77,8 +77,7 @@ using static Terraria.ModLoader.ModContent; namespace CalamityMod { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public class CalamityLists + public sealed class CalamityLists : ModSystem { public static IList donatorList; public static List projectileDestroyExceptionList; @@ -158,7 +157,7 @@ namespace CalamityMod public static List VeneratedLocketBanlist; //To ban projectiles from locket, mainly spikeballs altho Toasty asked me to add mod calls for adding stuff like Dreamtastic - public static void LoadLists() + public override void OnModLoad() { donatorList = new List() { @@ -390,7 +389,7 @@ namespace CalamityMod "Spider region", "WinterTire", "Nycro", - "Bewearium", + "Vyster", // previously "Bewearium" "William", "HellGoat2", "116taj", @@ -2203,7 +2202,8 @@ namespace CalamityMod ProjectileID.Bee, ProjectileID.GiantBee, ProjectileType(), - ProjectileID.ScarabBomb + ProjectileID.ScarabBomb, + ProjectileID.TNTBarrel }; ZeroContactDamageNPCList = new List @@ -2713,7 +2713,7 @@ namespace CalamityMod }; } - public static void UnloadLists() + public override void Unload() { donatorList = null; projectileDestroyExceptionList = null; diff --git a/CalamityMod.cs b/CalamityMod.cs index aba4ba43e2..04444e41f5 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -1,72 +1,14 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; -using CalamityMod.Balancing; -using CalamityMod.CalPlayer; -using CalamityMod.CalPlayer.Dashes; -using CalamityMod.Cooldowns; -using CalamityMod.DataStructures; -using CalamityMod.Effects; -using CalamityMod.Events; using CalamityMod.FluidSimulation; -using CalamityMod.Graphics.Primitives; using CalamityMod.Items; -using CalamityMod.Items.Dyes.HairDye; -using CalamityMod.Items.VanillaArmorChanges; -using CalamityMod.NPCs.AquaticScourge; -using CalamityMod.NPCs.AstrumAureus; -using CalamityMod.NPCs.AstrumDeus; -using CalamityMod.NPCs.BrimstoneElemental; -using CalamityMod.NPCs.Bumblebirb; -using CalamityMod.NPCs.CalClone; -using CalamityMod.NPCs.CeaselessVoid; -using CalamityMod.NPCs.Crabulon; -using CalamityMod.NPCs.Cryogen; -using CalamityMod.NPCs.DesertScourge; -using CalamityMod.NPCs.DevourerofGods; -using CalamityMod.NPCs.ExoMechs.Apollo; -using CalamityMod.NPCs.ExoMechs.Ares; -using CalamityMod.NPCs.ExoMechs.Artemis; -using CalamityMod.NPCs.ExoMechs.Thanatos; -using CalamityMod.NPCs.HiveMind; -using CalamityMod.NPCs.Leviathan; -using CalamityMod.NPCs.OldDuke; -using CalamityMod.NPCs.Perforator; -using CalamityMod.NPCs.PlaguebringerGoliath; -using CalamityMod.NPCs.Polterghast; -using CalamityMod.NPCs.PrimordialWyrm; -using CalamityMod.NPCs.ProfanedGuardians; -using CalamityMod.NPCs.Providence; -using CalamityMod.NPCs.Ravager; -using CalamityMod.NPCs.Signus; -using CalamityMod.NPCs.SlimeGod; -using CalamityMod.NPCs.StormWeaver; -using CalamityMod.NPCs.SupremeCalamitas; -using CalamityMod.NPCs.Yharon; using CalamityMod.Particles; using CalamityMod.Projectiles; -using CalamityMod.Projectiles.BaseProjectiles; -using CalamityMod.Schematics; -using CalamityMod.Skies; -using CalamityMod.Systems; -using CalamityMod.UI; -using CalamityMod.UI.CalamitasEnchants; -using CalamityMod.UI.DraedonsArsenal; -using CalamityMod.UI.Rippers; -using CalamityMod.Waters; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using ReLogic.Content; using Terraria; -using Terraria.GameContent; -using Terraria.GameContent.Dyes; -using Terraria.GameContent.Liquid; -using Terraria.Graphics.Effects; -using Terraria.Graphics.Shaders; -using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Config; @@ -76,78 +18,6 @@ namespace CalamityMod { public class CalamityMod : Mod { - // 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. - - // Boss Spawners - public static int ghostKillCount = 0; - public static int sharkKillCount = 0; - - // Boss Head Icons - public static int chadPrimeIcon; - - public static Asset carpetOriginal; - - // Astral Sky/BG - public static Texture2D AstralSky; - public static Texture2D AstralSurfaceFront; - public static Texture2D AstralSurfaceFrontGlow; - public static Texture2D AstralSurfaceClose; - public static Texture2D AstralSurfaceCloseGlow; - public static Texture2D AstralSurfaceMiddle; - public static Texture2D AstralSurfaceMiddleGlow; - - // Astral Desert Sky/BG - public static Texture2D AstralDesertSurfaceClose; - public static Texture2D AstralDesertSurfaceMiddle; - - // Astral Snow Sky/BG - public static Texture2D AstralSnowSurfaceMiddle; - - // Sulphur Sea Sky/BG - public static Texture2D SulphurSeaSky; - public static Texture2D SulphurSeaSkyFront; - public static Texture2D SulphurSeaSurface; - - // Destroyer glowmasks - public static Asset[] DestroyerGlowmasks = new Asset[3]; - - // Probe glowmask - public static Asset ProbeGlowmask; - - // Holds the Texture Arrays for all the lava textures. - // These are used for the lava styles. They are seperate from Textureasset.Instance._liquidTexture as they will conflict with ModWaterStyle - // Can hold up to 255 lava styles (more than enough) (excluding the normal lava texture which is liquidTexture 1) - public struct LavaTextures - { - public static Asset[] liquid = new Asset[1]; - public static Asset[] slope = new Asset[1]; - public static Asset[] block = new Asset[1]; - public static Asset[] fall = new Asset[1]; - } - - public static int LavaStyle; - - public static float[] lavaAlpha = new float[1]; - - // Wall of Flesh glowmasks - public static Asset WallOfFleshEyeGlowmask; - public static Asset WallOfFleshDemonSickleTexture; - - // Master Rev+ Skeletron Prime - public static Asset ChadPrime; - public static Asset ChadPrimeEyeGlowmask; - - // DR data structure - public static SortedDictionary DRValues; - - // Boss Kill Time data structure - public static SortedDictionary bossKillTimes; - - // Speedrun timer - internal static Stopwatch SpeedrunTimer = new Stopwatch(); - #region External Flags // External flag to disable non-Revengeance boss AI edits // This can be edited by other mods using reflection to prevent compatibility issues @@ -160,369 +30,41 @@ namespace CalamityMod public static bool ExternalFlag_DisableDefenseDamage = false; #endregion - internal static CalamityMod Instance; - - // TODO -- Mod references should be contained in a ModSystem (example name "ModLoadedChecker") - - // This is Calamity's official music mod, CalamityModMusic. It is now a hard dependency. - internal Mod musicMod = null; - internal bool MusicAvailable => musicMod is not null; - - // This is Vanilla Calamity Mod Music, internally named UnCalamityModMusic. - // VCMM is an official music add-on. Unlike the main music mod, it is not a dependency. - internal Mod vcmm = null; - internal bool VCMMAvailable => vcmm is not null; - - // Please keep this in alphabetical order so it's easy to read - internal Mod ancientsAwakened = null; - internal Mod biomeLava = null; - internal Mod bossChecklist = null; - internal Mod coloredDamageTypes = null; - internal Mod crouchMod = null; - internal Mod dialogueTweak = null; - internal Mod fargos = null; - internal Mod luminance = null; - internal Mod magicStorage = null; - 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 wikithis = null; - - //hell background - //private List loadCache; + internal static CalamityMod Instance => _Instance ??= ModContent.GetInstance(); + private static CalamityMod _Instance; #region Load public override void Load() { - Instance = this; - - carpetOriginal = TextureAssets.FlyingCarpet; - - // If any of these mods aren't loaded, it will simply keep them as null. - musicMod = null; - ModLoader.TryGetMod("CalamityModMusic", out musicMod); - vcmm = null; - ModLoader.TryGetMod("UnCalamityModMusic", out vcmm); - - ancientsAwakened = null; - ModLoader.TryGetMod("AAMod", out ancientsAwakened); - biomeLava = null; - ModLoader.TryGetMod("BiomeLava", out biomeLava); - bossChecklist = null; - ModLoader.TryGetMod("BossChecklist", out bossChecklist); - coloredDamageTypes = null; - ModLoader.TryGetMod("ColoredDamageTypes", out coloredDamageTypes); - crouchMod = null; - ModLoader.TryGetMod("CrouchMod", out crouchMod); - dialogueTweak = null; - ModLoader.TryGetMod("DialogueTweak", out dialogueTweak); - fargos = null; - ModLoader.TryGetMod("Fargowiltas", out fargos); - luminance = null; - ModLoader.TryGetMod("Luminance", out luminance); - magicStorage = null; - ModLoader.TryGetMod("MagicStorage", out magicStorage); - overhaul = null; - ModLoader.TryGetMod("TerrariaOverhaul", out overhaul); - redemption = null; - 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); - wikithis = null; - ModLoader.TryGetMod("Wikithis", out wikithis); - // Initialize the EnemyStats struct as early as it is safe to do so NPCStats.Load(); - // Initialize Calamity Lists so they may be used elsewhere immediately - CalamityLists.LoadLists(); - - // Initialize Calamity Balance, since it is tightly coupled with the remaining lists + // Initialize Calamity Balance, since it is tightly coupled with the remaining systems CalamityGlobalItem.LoadTweaks(); CalamityGlobalProjectile.LoadTweaks(); - // Mount balancing occurs during runtime and is undone when Calamity is unloaded. - Mount.mounts[MountID.Unicorn].dashSpeed *= CalamityPlayer.UnicornSpeedNerfPower; - Mount.mounts[MountID.Unicorn].runSpeed *= CalamityPlayer.UnicornSpeedNerfPower; - - // Buff DCU's pickaxe power to equal PML pickaxe capabilities - Mount.drillPickPower = 225; - - // Make Graveyard biomes require more Gravestones - SceneMetrics.GraveyardTileMax = 60; - SceneMetrics.GraveyardTileMin = 40; - SceneMetrics.GraveyardTileThreshold = 52; - if (!Main.dedServ) { - LoadClient(); - GeneralParticleHandler.Load(); - PrimitiveRenderer.Initialize(); - ForegroundDrawing.ForegroundManager.Load(); - - // Wikithis support - WeakReferenceSupport.WikiThisSupport(); + // This must be done separately from immediate loading, as loading is now multithreaded. + // However, render targets and certain other graphical objects can only be created on the main thread. + Main.QueueMainThreadAction(() => Main.OnPreDraw += PrepareRenderTargets); } - - CooldownRegistry.Load(); - BossRushEvent.Load(); - // TODO -- As ModBossBarStyle is a ModType, its Load function does not need to be called directly here. - BossHealthBarManager.Load(this); - EnchantmentManager.LoadAllEnchantments(); - VanillaArmorChangeManager.Load(); - SetupVanillaDR(); - SetupBossKillTimes(); - SchematicManager.Load(); - - //lava - LavaRendering.instance = new LavaRendering(); - WeakReferenceSupport.LavaStytleToBiomeLava(); - - Attunement.Load(); - BalancingChangesManager.Load(); - BaseIdleHoldoutProjectile.LoadAll(); - PlayerDashManager.Load(); - } - - private void LoadClient() - { - // Astral Sky/BG - AstralSky = ModContent.Request("CalamityMod/Skies/AstralSky", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceFront = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceFront", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceFrontGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceFrontGlow", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceClose = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceClose", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceCloseGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceCloseGlow", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; - AstralSurfaceMiddleGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceMiddleGlow", AssetRequestMode.ImmediateLoad).Value; - - //Astral Desert Sky/BG - AstralDesertSurfaceClose = ModContent.Request("CalamityMod/Backgrounds/AstralDesertSurfaceClose", AssetRequestMode.ImmediateLoad).Value; - AstralDesertSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralDesertSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; - - //Astral Snow Sky/BG - AstralSnowSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralSnowSurfaceMiddle", AssetRequestMode.ImmediateLoad).Value; - - // Sulpher Sea Sky/BG - SulphurSeaSky = ModContent.Request("CalamityMod/Skies/SulphurSeaSky", AssetRequestMode.ImmediateLoad).Value; - SulphurSeaSkyFront = ModContent.Request("CalamityMod/Skies/SulphurSeaSkyFront", AssetRequestMode.ImmediateLoad).Value; - SulphurSeaSurface = ModContent.Request("CalamityMod/Skies/SulphurSeaSurface", AssetRequestMode.ImmediateLoad).Value; - - // Destroyer glowmasks - DestroyerGlowmasks[0] = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerHeadGlow", AssetRequestMode.AsyncLoad); - DestroyerGlowmasks[1] = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerBodyGlow", AssetRequestMode.AsyncLoad); - DestroyerGlowmasks[2] = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerTailGlow", AssetRequestMode.AsyncLoad); - - // Lava Texture - LavaTextures.liquid[0] = LiquidRenderer.Instance._liquidTextures[1]; - LavaTextures.slope[0] = TextureAssets.LiquidSlope[1]; - LavaTextures.block[0] = TextureAssets.Liquid[1]; - var waterfallTexture = (Asset[])typeof(WaterfallManager).GetField("waterfallTexture", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Main.instance.waterfallManager); - LavaTextures.fall[0] = waterfallTexture[1]; - - // Probe glowmask - ProbeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/ProbeGlow", AssetRequestMode.AsyncLoad); - - // Wall of Flesh glowmasks - WallOfFleshEyeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/WallOfFleshEyeTelegraphGlow", AssetRequestMode.AsyncLoad); - WallOfFleshDemonSickleTexture = ModContent.Request("CalamityMod/Projectiles/Melee/ForbiddenOathbladeProjectile", AssetRequestMode.AsyncLoad); - - // Master Rev+ Skeletron Prime textures - ChadPrime = ModContent.Request("CalamityMod/ExtraTextures/ChadPrime", AssetRequestMode.AsyncLoad); - ChadPrimeEyeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/ChadPrimeHeadGlow", AssetRequestMode.AsyncLoad); - - // TODO -- Sky shaders should probably be loaded in a ModSystem - Filters.Scene["CalamityMod:DevourerofGodsHead"] = new Filter(new DoGScreenShaderData("FilterMiniTower").UseColor(0.4f, 0.1f, 1.0f).UseOpacity(0.5f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:DevourerofGodsHead"] = new DoGSky(); - - Filters.Scene["CalamityMod:CalamitasRun3"] = new Filter(new CalScreenShaderData("FilterMiniTower").UseColor(1.1f, 0.3f, 0.3f).UseOpacity(0.6f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:CalamitasRun3"] = new CalSky(); - - Filters.Scene["CalamityMod:PlaguebringerGoliath"] = new Filter(new PbGScreenShaderData("FilterMiniTower").UseColor(0.2f, 0.6f, 0.2f).UseOpacity(0.35f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:PlaguebringerGoliath"] = new PbGSky(); - - Filters.Scene["CalamityMod:Yharon"] = new Filter(new YScreenShaderData("FilterMiniTower").UseColor(1f, 0.4f, 0f).UseOpacity(0.75f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:Yharon"] = new YSky(); - - Filters.Scene["CalamityMod:Leviathan"] = new Filter(new LevScreenShaderData("FilterMiniTower").UseColor(0f, 0f, 0.5f).UseOpacity(0.5f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:Leviathan"] = new LevSky(); - - Filters.Scene["CalamityMod:SupremeCalamitas"] = new Filter(new SCalScreenShaderData("FilterMiniTower").UseColor(Color.Transparent).UseOpacity(0f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:SupremeCalamitas"] = new SCalSky(); - - Filters.Scene["CalamityMod:Signus"] = new Filter(new SignusScreenShaderData("FilterMiniTower").UseColor(0.35f, 0.1f, 0.55f).UseOpacity(0.35f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:Signus"] = new SignusSky(); - - Filters.Scene["CalamityMod:BossRush"] = new Filter(new BossRushScreenShader("FilterMiniTower").UseOpacity(0.75f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:BossRush"] = new BossRushSky(); - - Filters.Scene["CalamityMod:ExoMechs"] = new Filter(new ExoMechsScreenShaderData("FilterMiniTower").UseColor(ExoMechsSky.DrawColor).UseOpacity(0.25f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:ExoMechs"] = new ExoMechsSky(); - - Filters.Scene["CalamityMod:MonolithAccursed"] = new Filter(new MonolithScreenShaderData("FilterMiniTower").UseColor(1.1f, 0.3f, 0.3f).UseOpacity(0.65f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:MonolithAccursed"] = new MonolithSky(); - - // Normal intensity is 4f - Texture2D DistortionTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/BlobbyNoise", AssetRequestMode.ImmediateLoad).Value; - Filters.Scene["CalamityMod:DrunkCrabulon"] = new Filter(new DrunkCrabScreenShaderData("FilterHeatDistortion").UseImage(DistortionTexture, 0, null).UseIntensity(20f), EffectPriority.VeryHigh); - - Filters.Scene["CalamityMod:BrimstoneCrag"] = new Filter(new MonolithScreenShaderData("FilterMiniTower").UseColor(0f, 0f, 0f).UseOpacity(0f), EffectPriority.VeryHigh); - SkyManager.Instance["CalamityMod:BrimstoneCrag"] = new BrimstoneCragSky(); - - SkyManager.Instance["CalamityMod:Astral"] = new AstralSky(); - SkyManager.Instance["CalamityMod:SulphurSea"] = new SulphurSeaSky(); - SkyManager.Instance["CalamityMod:Cryogen"] = new CryogenSky(); - SkyManager.Instance["CalamityMod:StormWeaverFlash"] = new StormWeaverFlashSky(); - - CalamityShaders.LoadShaders(); - - // This must be done separately from immediate loading, as loading is now multithreaded. - // However, render targets and certain other graphical objects can only be created on the main thread. - Main.QueueMainThreadAction(() => - { - Main.OnPreDraw += PrepareRenderTargets; - }); - - RipperUI.Load(); - StealthUI.Load(); - ChargeMeterUI.Load(); - FlightBar.Load(); - - // TODO -- Is this not possible to place in ModNPC.Load or ModNPC.SetStaticDefaults ? - // Centralizing head texture registration like this seems absurdly stiff - Apollo.LoadHeadIcons(); - Artemis.LoadHeadIcons(); - Cryogen.LoadHeadIcons(); - DevourerofGodsHead.LoadHeadIcons(); - DevourerofGodsBody.LoadHeadIcons(); - DevourerofGodsTail.LoadHeadIcons(); - HiveMind.LoadHeadIcons(); - Polterghast.LoadHeadIcons(); - StormWeaverHead.LoadHeadIcons(); - SupremeCalamitas.LoadHeadIcons(); - ThanatosHead.LoadHeadIcons(); - ThanatosBody1.LoadHeadIcons(); - ThanatosBody2.LoadHeadIcons(); - ThanatosTail.LoadHeadIcons(); - - // All the head icon loading shit is done here, so I'm putting this here - string chadPrimeIconPath = "CalamityMod/ExtraTextures/ChadPrime_Head_Boss"; - CalamityMod.Instance.AddBossHeadTexture(chadPrimeIconPath, -1); - chadPrimeIcon = ModContent.GetModBossHeadSlot(chadPrimeIconPath); - - // TODO -- Is this not possible to place in ModItem.Load or ModItem.SetStaticDefaults ? - // Centralizing hair dye shaders like this seems absurdly stiff - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(0, 255, 171), ((float)player.Calamity().adrenaline / (float)player.Calamity().adrenalineMax)))); - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Lerp(player.hairColor, new Color(255, 83, 48), ((float)player.Calamity().rage / (float)player.Calamity().rageMax)))); - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => - { - float flightTimeInterpolant = player.wingTime / player.wingTimeMax; - if (player.mount.Active) - flightTimeInterpolant = 1f; - else if (float.IsInfinity(flightTimeInterpolant) || float.IsNaN(flightTimeInterpolant)) - flightTimeInterpolant = 0f; - - return Color.Lerp(player.hairColor, new Color(139, 205, 255), flightTimeInterpolant); - })); - GameShaders.Hair.BindShader(ModContent.ItemType(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => - { - float stealthInterpolant = player.Calamity().rogueStealth / player.Calamity().rogueStealthMax; - if (float.IsInfinity(stealthInterpolant) || float.IsNaN(stealthInterpolant)) - stealthInterpolant = 0f; - - return Color.Lerp(player.hairColor, new Color(186, 85, 211), stealthInterpolant); - })); - - InvasionProgressUIManager.LoadGUIs(); } #endregion #region Unload public override void Unload() { - musicMod = null; - vcmm = null; - - ancientsAwakened = null; - biomeLava = null; - bossChecklist = null; - coloredDamageTypes = null; - crouchMod = null; - dialogueTweak = null; - fargos = null; - luminance = null; - magicStorage = null; - overhaul = null; - redemption = null; - soa = null; - subworldLibrary = null; - summonersAssociation = null; - thorium = null; - varia = null; - wikithis = null; - - AstralSky = null; - - DRValues?.Clear(); - DRValues = null; - bossKillTimes?.Clear(); - bossKillTimes = null; - - BalancingChangesManager.Unload(); - Attunement.Unload(); - EnchantmentManager.UnloadAllEnchantments(); - VanillaArmorChangeManager.Unload(); - CalamityLists.UnloadLists(); NPCStats.Unload(); CalamityGlobalItem.UnloadTweaks(); CalamityGlobalProjectile.UnloadTweaks(); - PopupGUIManager.UnloadGUIs(); - InvasionProgressUIManager.UnloadGUIs(); - BossRushEvent.Unload(); - SchematicManager.Unload(); - CooldownRegistry.Unload(); - PlayerDashManager.Unload(); - Main.QueueMainThreadAction(() => { Main.OnPreDraw -= PrepareRenderTargets; }); - RipperUI.Unload(); - StealthUI.Unload(); - ChargeMeterUI.Unload(); - FlightBar.Unload(); - - if (!Main.dedServ) - { - TextureAssets.FlyingCarpet = carpetOriginal; - GeneralParticleHandler.Unload(); - } - - Mount.mounts[MountID.Unicorn].dashSpeed /= CalamityPlayer.UnicornSpeedNerfPower; - Mount.mounts[MountID.Unicorn].runSpeed /= CalamityPlayer.UnicornSpeedNerfPower; - - Mount.drillPickPower = 210; - - SceneMetrics.GraveyardTileMax = 36; - SceneMetrics.GraveyardTileMin = 16; - SceneMetrics.GraveyardTileThreshold = 28; - - carpetOriginal = null; - - Instance = null; + _Instance = null; base.Unload(); } #endregion @@ -536,258 +78,18 @@ namespace CalamityMod } #endregion Render Target Management - #region Force ModConfig save (Reflection) - internal static void SaveConfig(CalamityClientConfig cfg) - { - // There is no current way to manually save a mod configuration file in tModLoader. - // The method which saves mod config files is private in ConfigManager, so reflection is used to invoke it. - try - { - MethodInfo saveMethodInfo = typeof(ConfigManager).GetMethod("Save", BindingFlags.Static | BindingFlags.NonPublic); - if (saveMethodInfo is not null) - saveMethodInfo.Invoke(null, new object[] { cfg }); - else - Instance.Logger.Error("TML ConfigManager.Save reflection failed. Method signature has changed. Notify Calamity Devs if you see this in your log."); - } - catch - { - Instance.Logger.Error("An error occurred while manually saving Calamity mod configuration. This may be due to a complex mod conflict. It is safe to ignore this error."); - } - } - #endregion - - #region Vanilla Enemy DR - private void SetupVanillaDR() - { - DRValues = new SortedDictionary { - { NPCID.AngryBonesBig, 0.2f }, - { NPCID.AngryBonesBigHelmet, 0.2f }, - { NPCID.AngryBonesBigMuscle, 0.2f }, - { NPCID.AnomuraFungus, 0.1f }, - { NPCID.Antlion, 0.1f }, - { NPCID.Arapaima, 0.1f }, - { NPCID.ArmoredSkeleton, 0.15f }, - { NPCID.ArmoredViking, 0.1f }, - { NPCID.BigMimicCorruption, 0.3f }, - { NPCID.BigMimicCrimson, 0.3f }, - { NPCID.BigMimicHallow, 0.3f }, - { NPCID.BigMimicJungle, 0.3f }, // unused vanilla enemy - { NPCID.BlueArmoredBones, 0.2f }, - { NPCID.BlueArmoredBonesMace, 0.2f }, - { NPCID.BlueArmoredBonesNoPants, 0.2f }, - { NPCID.BlueArmoredBonesSword, 0.2f }, - { NPCID.BoneLee, 0.2f }, - { NPCID.Crab, 0.05f }, - { NPCID.Crawdad, 0.2f }, - { NPCID.Crawdad2, 0.2f }, - { NPCID.CultistBoss, 0.15f }, - { NPCID.Deerclops, 0.05f }, - { NPCID.DD2Betsy, 0.1f }, - { NPCID.DD2OgreT2, 0.1f }, - { NPCID.DD2OgreT3, 0.15f }, - { NPCID.DeadlySphere, 0.4f }, - { NPCID.DiabolistRed, 0.2f }, - { NPCID.DiabolistWhite, 0.2f }, - { NPCID.DukeFishron, 0.15f }, - { NPCID.DungeonGuardian, 0.9f }, - { NPCID.DungeonSpirit, 0.2f }, - { NPCID.ElfCopter, 0.15f }, - { NPCID.Everscream, 0.1f }, - { NPCID.FlyingAntlion, 0.05f }, - { NPCID.GiantCursedSkull, 0.2f }, - { NPCID.GiantShelly, 0.2f }, - { NPCID.GiantShelly2, 0.2f }, - { NPCID.GiantTortoise, 0.35f }, - { NPCID.Golem, 0.25f }, - { NPCID.GolemFistLeft, 0.25f }, - { NPCID.GolemFistRight, 0.25f }, - { NPCID.GolemHead, 0.25f }, - { NPCID.GolemHeadFree, 0.25f }, - { NPCID.GraniteFlyer, 0.1f }, - { NPCID.GraniteGolem, 0.15f }, - { NPCID.GreekSkeleton, 0.1f }, - { NPCID.HellArmoredBones, 0.2f }, - { NPCID.HellArmoredBonesMace, 0.2f }, - { NPCID.HellArmoredBonesSpikeShield, 0.2f }, - { NPCID.HellArmoredBonesSword, 0.2f }, - { NPCID.IceGolem, 0.1f }, - { NPCID.IceQueen, 0.1f }, - { NPCID.IceTortoise, 0.35f }, - { NPCID.HeadlessHorseman, 0.05f }, - { NPCID.MartianDrone, 0.2f }, - { NPCID.MartianSaucer, 0.2f }, - { NPCID.MartianSaucerCannon, 0.2f }, - { NPCID.MartianSaucerCore, 0.2f }, - { NPCID.MartianSaucerTurret, 0.2f }, - { NPCID.MartianTurret, 0.2f }, - { NPCID.MartianWalker, 0.35f }, - { NPCID.Mimic, 0.3f }, - { NPCID.MoonLordCore, 0.15f }, - { NPCID.MoonLordHand, 0.15f }, - { NPCID.MoonLordHead, 0.15f }, - { NPCID.Mothron, 0.2f }, - { NPCID.MothronEgg, 0.5f }, - { NPCID.MourningWood, 0.1f }, - { NPCID.Necromancer, 0.2f }, - { NPCID.NecromancerArmored, 0.2f }, - { NPCID.Paladin, 0.45f }, - { NPCID.PirateCaptain, 0.05f }, - { NPCID.PirateShipCannon, 0.15f }, - { NPCID.Plantera, 0.15f }, - { NPCID.PlanterasTentacle, 0.1f }, - { NPCID.HallowBoss, 0.15f }, - { NPCID.PossessedArmor, 0.25f }, - { NPCID.PresentMimic, 0.3f }, - { NPCID.PrimeCannon, 0.2f }, - { NPCID.PrimeLaser, 0.2f }, - { NPCID.PrimeSaw, 0.2f }, - { NPCID.PrimeVice, 0.2f }, - { NPCID.Probe, 0.2f }, - { NPCID.Pumpking, 0.1f }, - { NPCID.QueenBee, 0.05f }, - { NPCID.RaggedCaster, 0.2f }, - { NPCID.RaggedCasterOpenCoat, 0.2f }, - { NPCID.Retinazer, 0.2f }, - { NPCID.RustyArmoredBonesAxe, 0.2f }, - { NPCID.RustyArmoredBonesFlail, 0.2f }, - { NPCID.RustyArmoredBonesSword, 0.2f }, - { NPCID.RustyArmoredBonesSwordNoArmor, 0.2f }, - { NPCID.SandElemental, 0.1f }, - { NPCID.SantaNK1, 0.35f }, - { NPCID.SeaSnail, 0.05f }, - { NPCID.SkeletonArcher, 0.1f }, - { NPCID.SkeletonCommando, 0.2f }, - { NPCID.SkeletonSniper, 0.2f }, - { NPCID.SkeletronHand, 0.05f }, - { NPCID.SkeletronHead, 0.05f }, - { NPCID.SkeletronPrime, 0.2f }, - { NPCID.Spazmatism, 0.2f }, - { NPCID.TacticalSkeleton, 0.2f }, - { NPCID.TheDestroyer, 0.1f }, - { NPCID.TheDestroyerBody, 0.2f }, - { NPCID.TheDestroyerTail, 0.35f }, - { NPCID.TheHungry, 0.1f }, - { NPCID.UndeadViking, 0.1f }, - { NPCID.WalkingAntlion, 0.1f }, - { NPCID.WallofFlesh, 0.5f }, - }; - } - #endregion - - #region Boss Kill Times - private void SetupBossKillTimes() - { - // Kill times are measured exactly in frames. - // 60 frames = 1 second - // 3600 frames = 1 minute - bossKillTimes = new SortedDictionary { - // - // VANILLA BOSSES - // - { NPCID.KingSlime, 5400 }, // 1:30 (90 seconds) - { NPCID.EyeofCthulhu, 5400 }, // 1:30 (90 seconds) - { NPCID.EaterofWorldsHead, 7200 }, // 2:00 (120 seconds) - { NPCID.EaterofWorldsBody, 7200 }, - { NPCID.EaterofWorldsTail, 7200 }, - { NPCID.BrainofCthulhu, 7200 }, // 2:00 (120 seconds, total length of fight including Creepers phase) - { NPCID.Creeper, 1800 }, // 0:30 (30 seconds, length of Creepers phase) - { NPCID.Deerclops, 5400 }, // 1:30 (90 seconds) - { NPCID.QueenBee, 7200 }, // 2:00 (120 seconds) - { NPCID.SkeletronHead, 9000 }, // 2:30 (150 seconds) - { NPCID.WallofFlesh, 7200 }, // 2:00 (120 seconds) - { NPCID.WallofFleshEye, 7200 }, - { NPCID.QueenSlimeBoss, 7200 }, // 2:00 (120 seconds) - { NPCID.Spazmatism, 10800 }, // 3:00 (180 seconds) - { NPCID.Retinazer, 10800 }, - { NPCID.TheDestroyer, 10800 }, // 3:00 (180 seconds) - { NPCID.TheDestroyerBody, 10800 }, - { NPCID.TheDestroyerTail, 10800 }, - { NPCID.SkeletronPrime, 10800 }, // 3:00 (180 seconds) - { NPCID.Plantera, 10800 }, // 3:00 (180 seconds) - { NPCID.HallowBoss, 10800 }, // 3:00 (180 seconds) - { NPCID.Golem, 9000 }, // 2:30 (150 seconds) - { NPCID.GolemHead, 3600 }, // 1:00 (60 seconds) - { NPCID.DukeFishron, 9000 }, // 2:30 (150 seconds) - { NPCID.CultistBoss, 9000 }, // 2:30 (150 seconds) - { NPCID.MoonLordCore, 14400 }, // 4:00 (240 seconds) - { NPCID.MoonLordHand, 7200 }, // 2:00 (120 seconds) - { NPCID.MoonLordHead, 7200 }, // 2:00 (120 seconds) - - // - // CALAMITY BOSSES - // - { ModContent.NPCType(), 5400 }, // 1:30 (90 seconds) - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 5400 }, - { ModContent.NPCType(), 5400 }, // 1:30 (90 seconds) - { ModContent.NPCType(), 7200 }, // 2:00 (120 seconds) - { ModContent.NPCType(), 7200 }, // 2:00 (120 seconds) - { ModContent.NPCType(), 9000 }, // 2:30 (150 seconds) -- total length of Slime God fight - { ModContent.NPCType(), 4500 }, // 1:15 (75 seconds) - { ModContent.NPCType(), 4500 }, // 1:15 (75 seconds) - { ModContent.NPCType(), 4500 }, // 1:15 (75 seconds) -- split slimes should spawn at 1:15 and die at around 2:30 - { ModContent.NPCType(), 4500 }, // 1:15 (75 seconds) - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 9000 }, // 2:30 (150 seconds) - { ModContent.NPCType(), 9000 }, - { ModContent.NPCType(), 9000 }, - { ModContent.NPCType(), 9000 }, - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 14400 }, // 4:00 (240 seconds) - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 10800 }, - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 7200 }, // 2:00 (120 seconds) -- first phase is 1:00 - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 7200 }, - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 5400 }, // 1:30 (90 seconds) - { ModContent.NPCType(), 7200 }, // 2:00 (120 seconds) - { ModContent.NPCType(), 14400 }, // 4:00 (240 seconds) - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 1200 }, // 0:20 (20 seconds) - { ModContent.NPCType(), 8100 }, // 2:15 (135 seconds) - { ModContent.NPCType(), 8100 }, - { ModContent.NPCType(), 8100 }, - { ModContent.NPCType(), 7200 }, // 2:00 (120 seconds) - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 10800 }, // 3:00 (180 seconds) - { ModContent.NPCType(), 14400 }, // 4:00 (240 seconds) - { ModContent.NPCType(), 14400 }, // DoG Phase 1 is 1:30, DoG Phase 2 is 2:30 - { ModContent.NPCType(), 14400 }, - { ModContent.NPCType(), 14700 }, // 4:05 (245 seconds) -- he spends 5 seconds invincible where you can't do anything - { ModContent.NPCType(), 21600 }, // 6:00 (360 seconds) - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 21600 }, // 6:00 (360 seconds) - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 21600 }, // 6:00 (360 seconds) - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 21600 }, - { ModContent.NPCType(), 18000 }, // 5:00 (300 seconds) - { ModContent.NPCType(), 18000 } // 5:00 (300 seconds) - }; - } - #endregion - #region Music // This function returns an available Calamity Music Mod track, or null if the Calamity Music Mod is not available. - public int? GetMusicFromMusicMod(string songFilename) => MusicAvailable ? MusicLoader.GetMusicSlot(musicMod, "Sounds/Music/" + songFilename) : null; + public int? GetMusicFromMusicMod(string songFilename) => ExternalMods.MusicAvailable ? MusicLoader.GetMusicSlot(ExternalMods.musicMod, "Sounds/Music/" + songFilename) : null; // This function returns an available VCMM track, or null if VCMM is not available. // Unlike the main Music Mod, VCMM is hierarchical. - public int? GetMusicFromVCMM(string songPath) => VCMMAvailable ? MusicLoader.GetMusicSlot(vcmm, "Assets/" + songPath) : null; + public int? GetMusicFromVCMM(string songPath) => ExternalMods.VCMMAvailable ? MusicLoader.GetMusicSlot(ExternalMods.vcmm, "Assets/" + songPath) : null; #endregion #region Mod Support - public override void PostSetupContent() => WeakReferenceSupport.Setup(); - public override object Call(params object[] args) => ModCalls.Call(args); #endregion @@ -822,16 +124,6 @@ namespace CalamityMod } #endregion - #region Stop Rain - public static void StopRain() - { - if (!Main.raining) - return; - Main.raining = false; - CalamityNetcode.SyncWorld(); - } - #endregion - #region Netcode public override void HandlePacket(BinaryReader reader, int whoAmI) => CalamityNetcode.HandlePacket(this, reader, whoAmI); #endregion diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index 1888f34647..72a8847ebc 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -33,16 +33,12 @@ namespace CalamityMod { _PacketRegistry = new CalamityPacket[256]; // This should allow to use 0-255 range (full byte range) - var types = ModLoader.Mods.SelectMany(mod => AssemblyManager.GetLoadableTypes(mod.Code)); - foreach (var type in types) + ReflectionHelper.IterateEveryModsTypes(action: type => { try { - if (type.IsAbstract || !type.IsSubclassOf(typeof(CalamityPacket))) - continue; - if (Activator.CreateInstance(type) is not CalamityPacket packetHandler) - continue; + return; var msgType = packetHandler.MessageType; var existingHandler = _PacketRegistry[msgType]; @@ -52,7 +48,7 @@ namespace CalamityMod $" [Failed On: '{type.FullName}'" + $" Current Owner: '{existingHandler.GetType().FullName}'," + $" msgTypeToRegister: '{msgType}']"); - continue; + return; } _PacketRegistry[packetHandler.MessageType] = packetHandler; @@ -81,9 +77,9 @@ namespace CalamityMod catch (Exception e) { CalamityMod.Instance.Logger.Error($"Exception was thrown while loading for Packets! {e}"); - continue; + return; } - } + }); } public override void OnModUnload() diff --git a/Cooldowns/CooldownRegistry.cs b/Cooldowns/CooldownRegistry.cs index 53822657c1..d74cf6cd11 100644 --- a/Cooldowns/CooldownRegistry.cs +++ b/Cooldowns/CooldownRegistry.cs @@ -7,7 +7,7 @@ using Terraria.ModLoader.Core; namespace CalamityMod.Cooldowns { // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public class CooldownRegistry + public sealed class CooldownRegistry : ModSystem { // Indexed by ushort netID. Contains every registered cooldown. // Cooldowns are given netIDs when they are registered. @@ -18,7 +18,7 @@ namespace CalamityMod.Cooldowns private static Dictionary nameToNetID = null; - public static void Load() + public override void Load() { registry = new Cooldown[defaultSize]; nameToNetID = new Dictionary(defaultSize); @@ -60,7 +60,7 @@ namespace CalamityMod.Cooldowns #endregion } - public static void RegisterModCooldowns() + public override void OnModLoad() { Type baseHandlerType = typeof(CooldownHandler); foreach (Mod mod in ModLoader.Mods) @@ -87,7 +87,7 @@ namespace CalamityMod.Cooldowns } } - public static void Unload() + public override void Unload() { registry = null; nameToNetID?.Clear(); diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index a8976ede23..2aa2e72970 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -4,11 +4,13 @@ using ReLogic.Content; using Terraria; using Terraria.Graphics.Effects; using Terraria.Graphics.Shaders; +using Terraria.ModLoader; namespace CalamityMod.Effects { // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public class CalamityShaders + [Autoload(Side = ModSide.Client)] + public sealed class CalamityShaders : ModSystem { private const string ShaderPath = "Effects/"; internal const string CalamityShaderPrefix = "CalamityMod:"; @@ -204,38 +206,8 @@ namespace CalamityMod.Effects internal static Effect TeslaTrailShader; #endregion - // Shorthand to register a loaded shader in Terraria's graphics engine - // All shaders registered this way are accessible under GameShaders.Misc - // They will use the prefix described above - private static void RegisterMiscShader(Effect shader, string passName, string registrationName) + public override void PostSetupContent() { - Ref shaderPointer = new(shader); - MiscShaderData passParamRegistration = new(shaderPointer, passName); - GameShaders.Misc[$"{CalamityShaderPrefix}{registrationName}"] = passParamRegistration; - } - - private static void RegisterSceneFilter(ScreenShaderData passReg, string registrationName, EffectPriority priority = EffectPriority.High) - { - string prefixedRegistrationName = $"{CalamityShaderPrefix}{registrationName}"; - Filters.Scene[prefixedRegistrationName] = new Filter(passReg, priority); - Filters.Scene[prefixedRegistrationName].Load(); - } - - // Shorthand to register a loaded shader in Terraria's graphics engine - // All shaders registered this way are accessible under Filters.Scene - // They will use the prefix described above - private static void RegisterScreenShader(Effect shader, string passName, string registrationName, EffectPriority priority = EffectPriority.High) - { - Ref shaderPointer = new(shader); - ScreenShaderData passParamRegistration = new(shaderPointer, passName); - RegisterSceneFilter(passParamRegistration, registrationName, priority); - } - - public static void LoadShaders() - { - if (Main.dedServ) - return; - AssetRepository calAss = CalamityMod.Instance.Assets; // Shorthand to load shaders immediately. @@ -437,5 +409,32 @@ namespace CalamityMod.Effects RegisterMiscShader(TeslaTrailShader, "TrailPass", "TeslaTrail"); #endregion } + + // Shorthand to register a loaded shader in Terraria's graphics engine + // All shaders registered this way are accessible under GameShaders.Misc + // They will use the prefix described above + private static void RegisterMiscShader(Effect shader, string passName, string registrationName) + { + Ref shaderPointer = new(shader); + MiscShaderData passParamRegistration = new(shaderPointer, passName); + GameShaders.Misc[$"{CalamityShaderPrefix}{registrationName}"] = passParamRegistration; + } + + private static void RegisterSceneFilter(ScreenShaderData passReg, string registrationName, EffectPriority priority = EffectPriority.High) + { + string prefixedRegistrationName = $"{CalamityShaderPrefix}{registrationName}"; + Filters.Scene[prefixedRegistrationName] = new Filter(passReg, priority); + Filters.Scene[prefixedRegistrationName].Load(); + } + + // Shorthand to register a loaded shader in Terraria's graphics engine + // All shaders registered this way are accessible under Filters.Scene + // They will use the prefix described above + private static void RegisterScreenShader(Effect shader, string passName, string registrationName, EffectPriority priority = EffectPriority.High) + { + Ref shaderPointer = new(shader); + ScreenShaderData passParamRegistration = new(shaderPointer, passName); + RegisterSceneFilter(passParamRegistration, registrationName, priority); + } } } diff --git a/Events/AcidRainEvent.cs b/Events/AcidRainEvent.cs index 39bb24bb3e..3ca687018d 100644 --- a/Events/AcidRainEvent.cs +++ b/Events/AcidRainEvent.cs @@ -60,7 +60,7 @@ namespace CalamityMod.Events public static Dictionary PossibleMinibossesPolter = new(); - public static List AllMinibosses => PossibleMinibossesAS.Select(miniboss => miniboss.Key).ToList().Concat(PossibleMinibossesPolter.Select(miniboss => miniboss.Key)).Distinct().ToList(); + public static List AllMinibosses => PossibleMinibossesAS.Select(miniboss => miniboss.Key).Concat(PossibleMinibossesPolter.Select(miniboss => miniboss.Key)).Distinct().ToList(); public static bool AnyRainMinibosses { @@ -331,7 +331,7 @@ namespace CalamityMod.Events DownedBossSystem.downedAquaticScourgeAcidRain = DownedBossSystem.downedAquaticScourge; } HasTriedToSummonOldDuke = false; - CalamityMod.StopRain(); + CalamityWorld.StopRain(); } CalamityNetcode.SyncWorld(); diff --git a/Events/BossRushEvent.cs b/Events/BossRushEvent.cs index db51f2cc3a..cc76cb9048 100644 --- a/Events/BossRushEvent.cs +++ b/Events/BossRushEvent.cs @@ -39,6 +39,7 @@ using CalamityMod.Projectiles.Typeless; using CalamityMod.Skies; using CalamityMod.Systems; using CalamityMod.UI.DraedonSummoning; +using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -51,8 +52,7 @@ using ArtemisBoss = CalamityMod.NPCs.ExoMechs.Artemis.Artemis; namespace CalamityMod.Events { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public class BossRushEvent + public sealed class BossRushEvent : ModSystem { public enum TimeChangeContext { @@ -136,7 +136,7 @@ namespace CalamityMod.Events public static readonly SoundStyle VictorySound = new("CalamityMod/Sounds/Custom/BossRush/BossRushVictory"); #region Loading and Unloading - public static void Load() + public override void OnModLoad() { BossIDsAfterDeath = new Dictionary(); @@ -455,7 +455,7 @@ namespace CalamityMod.Events }; } - public static void Unload() + public override void Unload() { Bosses = null; BossIDsAfterDeath = null; @@ -489,7 +489,7 @@ namespace CalamityMod.Events return -1; } int tier = CurrentTier; - if (CalamityMod.Instance.MusicAvailable) + if (ExternalMods.MusicAvailable) { // Boss Rush music for tier 5 doesn't exist if (tier > 4) @@ -590,7 +590,7 @@ namespace CalamityMod.Events // Change time as necessary. if (Bosses[BossRushStage].ToChangeTimeTo != TimeChangeContext.None) - CalamityUtils.ChangeTime(Bosses[BossRushStage].ToChangeTimeTo == TimeChangeContext.Day); + CalamityWorld.ResetTime(Bosses[BossRushStage].ToChangeTimeTo == TimeChangeContext.Day); // Play a special boss roar sound by default. if (!Bosses[BossRushStage].UsesSpecialSound) diff --git a/ExtraTextures/Bestiary/AquaticScourge_Bestiary.png b/ExtraTextures/Bestiary/AquaticScourge_Bestiary.png deleted file mode 100644 index aae7fca94e..0000000000 Binary files a/ExtraTextures/Bestiary/AquaticScourge_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/ArmoredDigger_Bestiary.png b/ExtraTextures/Bestiary/ArmoredDigger_Bestiary.png deleted file mode 100644 index e0fb638d67..0000000000 Binary files a/ExtraTextures/Bestiary/ArmoredDigger_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/AstrumDeus_Bestiary.png b/ExtraTextures/Bestiary/AstrumDeus_Bestiary.png deleted file mode 100644 index 58dd541f69..0000000000 Binary files a/ExtraTextures/Bestiary/AstrumDeus_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/CosmicGuardian_Bestiary.png b/ExtraTextures/Bestiary/CosmicGuardian_Bestiary.png deleted file mode 100644 index 9f46bc2836..0000000000 Binary files a/ExtraTextures/Bestiary/CosmicGuardian_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/DevourerofGods_Bestiary.png b/ExtraTextures/Bestiary/DevourerofGods_Bestiary.png deleted file mode 100644 index abe0519bc4..0000000000 Binary files a/ExtraTextures/Bestiary/DevourerofGods_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/EidolonWyrm_Bestiary.png b/ExtraTextures/Bestiary/EidolonWyrm_Bestiary.png deleted file mode 100644 index fa399c67e7..0000000000 Binary files a/ExtraTextures/Bestiary/EidolonWyrm_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/GulperEel_Bestiary.png b/ExtraTextures/Bestiary/GulperEel_Bestiary.png deleted file mode 100644 index 85eab7d9db..0000000000 Binary files a/ExtraTextures/Bestiary/GulperEel_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/Oarfish_Bestiary.png b/ExtraTextures/Bestiary/Oarfish_Bestiary.png deleted file mode 100644 index acc08a6575..0000000000 Binary files a/ExtraTextures/Bestiary/Oarfish_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/PerforatorLarge_Bestiary.png b/ExtraTextures/Bestiary/PerforatorLarge_Bestiary.png deleted file mode 100644 index 58875863e6..0000000000 Binary files a/ExtraTextures/Bestiary/PerforatorLarge_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/PerforatorMedium_Bestiary.png b/ExtraTextures/Bestiary/PerforatorMedium_Bestiary.png deleted file mode 100644 index 4598f54e7a..0000000000 Binary files a/ExtraTextures/Bestiary/PerforatorMedium_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/PerforatorSmall_Bestiary.png b/ExtraTextures/Bestiary/PerforatorSmall_Bestiary.png deleted file mode 100644 index afbd009ae8..0000000000 Binary files a/ExtraTextures/Bestiary/PerforatorSmall_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/PrimordialWyrm_Bestiary.png b/ExtraTextures/Bestiary/PrimordialWyrm_Bestiary.png deleted file mode 100644 index 4adc7140e5..0000000000 Binary files a/ExtraTextures/Bestiary/PrimordialWyrm_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/SeaSerpent_Bestiary.png b/ExtraTextures/Bestiary/SeaSerpent_Bestiary.png deleted file mode 100644 index 55dd91d297..0000000000 Binary files a/ExtraTextures/Bestiary/SeaSerpent_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/StormWeaver_Bestiary.png b/ExtraTextures/Bestiary/StormWeaver_Bestiary.png deleted file mode 100644 index 05e198b74b..0000000000 Binary files a/ExtraTextures/Bestiary/StormWeaver_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/Bestiary/Thanatos_Bestiary.png b/ExtraTextures/Bestiary/Thanatos_Bestiary.png deleted file mode 100644 index 63f8dc97a9..0000000000 Binary files a/ExtraTextures/Bestiary/Thanatos_Bestiary.png and /dev/null differ diff --git a/ExtraTextures/ExtraTextureRefs.cs b/ExtraTextures/ExtraTextureRefs.cs new file mode 100644 index 0000000000..724db66b6e --- /dev/null +++ b/ExtraTextures/ExtraTextureRefs.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.GameContent; +using Terraria.ModLoader; + +namespace CalamityMod.ExtraTextures +{ + [Autoload(Side = ModSide.Client)] + internal sealed class ExtraTextureRefs : ModSystem + { + // Destroyer glowmasks + public static Asset DestroyerHeadGlowmask; + public static Asset DestroyerBodyGlowmask; + public static Asset DestroyerTailGlowmask; + public static Asset ProbeGlowmask; + + // Master Rev+ Skeletron Prime + public static Asset ChadPrime; + public static Asset ChadPrimeEyeGlowmask; + + // WoF, These are not "exactly" the ExtraTextures. But + public static Asset WallOfFleshEyeGlowmask; + public static Asset WallOfFleshDemonSickleTexture; + + // Flying Carpet Replacements + public static Asset FlyingCarpetVanilla; + public static Asset FlyingCarpetAuric; + + // Boss Heads + // I know it's not exactly a Texture2D but it belongs to ExtraTextures. + public static int BossHeadIndex_ChadPrime; + + public override void Load() + { + string chadPrimeIconPath = "CalamityMod/ExtraTextures/ChadPrime_Head_Boss"; + BossHeadIndex_ChadPrime = CalamityMod.Instance.AddBossHeadTexture(chadPrimeIconPath, -1); + } + + + // TODO: - Every other ExtraTextures Reference could be move in here + public override void OnModLoad() + { + DestroyerHeadGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerHeadGlow", AssetRequestMode.AsyncLoad); + DestroyerBodyGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerBodyGlow", AssetRequestMode.AsyncLoad); + DestroyerTailGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerTailGlow", AssetRequestMode.AsyncLoad); + + ProbeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/ProbeGlow", AssetRequestMode.AsyncLoad); + + ChadPrime = ModContent.Request("CalamityMod/ExtraTextures/ChadPrime", AssetRequestMode.AsyncLoad); + ChadPrimeEyeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/ChadPrimeHeadGlow", AssetRequestMode.AsyncLoad); + + WallOfFleshEyeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/WallOfFleshEyeTelegraphGlow", AssetRequestMode.AsyncLoad); + WallOfFleshDemonSickleTexture = ModContent.Request("CalamityMod/Projectiles/Melee/ForbiddenOathbladeProjectile", AssetRequestMode.AsyncLoad); + + FlyingCarpetVanilla = TextureAssets.FlyingCarpet; + FlyingCarpetAuric = ModContent.Request("CalamityMod/ExtraTextures/AuricCarpet", AssetRequestMode.AsyncLoad); + } + + public override void Unload() + { + if (!Main.dedServ) + { + TextureAssets.FlyingCarpet = FlyingCarpetVanilla; + } + } + } +} diff --git a/ForegroundDrawing/ForegroundManager.cs b/ForegroundDrawing/ForegroundManager.cs deleted file mode 100644 index 88259a63b5..0000000000 --- a/ForegroundDrawing/ForegroundManager.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using ReLogic.Content; -using Terraria; -using Terraria.ModLoader; -using Terraria.ModLoader.Core; - -namespace CalamityMod.ForegroundDrawing -{ - interface IForegroundTile - { - void ForegroundDraw(int x, int y, SpriteBatch spriteBatch); - } - - public static class ForegroundManager - { - private static List _foregroundElements; - private static int _foregroundElementCount; - - internal static void Load() - { - _foregroundElements = new List(1000); - _foregroundElementCount = 0; - } - - public static void AddForegroundDrawingPoint(int x, int y) - { - _foregroundElements.Add(new Point(x, y)); - _foregroundElementCount++; - } - - - public static void DrawTiles() - { - for (int i = 0; i < _foregroundElementCount; i++) - { - ushort type = Main.tile[_foregroundElements[i]].TileType; - if (TileLoader.GetTile(type) is IForegroundTile fgTile) - fgTile.ForegroundDraw(_foregroundElements[i].X, _foregroundElements[i].Y, Main.spriteBatch); - } - } - - public static void ClearTiles() - { - _foregroundElements.Clear(); - _foregroundElementCount = 0; - } - } -} diff --git a/Graphics/Primitives/PrimitiveRenderer.cs b/Graphics/Primitives/PrimitiveRenderer.cs index 928c64bfd4..66fa36a79d 100644 --- a/Graphics/Primitives/PrimitiveRenderer.cs +++ b/Graphics/Primitives/PrimitiveRenderer.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Graphics.Shaders; +using Terraria.ModLoader; namespace CalamityMod.Graphics.Primitives { @@ -19,7 +20,8 @@ namespace CalamityMod.Graphics.Primitives /// If you wish to use pixelation, you MUST make the NPC/Projectile inherit and use instead of predraw..
/// You can also optionally specify a render layer with . It is by default. /// - public static class PrimitiveRenderer + [Autoload(Side = ModSide.Client)] + public sealed class PrimitiveRenderer : ModSystem { #region Static Members private static DynamicVertexBuffer VertexBuffer; @@ -46,7 +48,7 @@ namespace CalamityMod.Graphics.Primitives private static short IndicesIndex; - internal static void Initialize() + public override void OnModLoad() { Main.QueueMainThreadAction(() => { diff --git a/ILEditing/BalancingILChanges.cs b/ILEditing/BalancingILChanges.cs index 50ef9a6f68..3162a2dc91 100644 --- a/ILEditing/BalancingILChanges.cs +++ b/ILEditing/BalancingILChanges.cs @@ -1,6 +1,5 @@ using System; using CalamityMod.Balancing; -using CalamityMod.Items.Accessories; using Mono.Cecil.Cil; using MonoMod.Cil; using Terraria; @@ -16,8 +15,8 @@ namespace CalamityMod.ILEditing private static bool AdjustShimmerRequirements(On_ShimmerTransforms.orig_IsItemTransformLocked orig, int type) { - //Rod of Harmony / psc requires Draedong and SCal dead instead of Moon Lord. - if (type == ItemID.RodofDiscord || type == ModContent.ItemType()) + //Rod of Harmony requires Draedong and SCal dead instead of Moon Lord. + if (type == ItemID.RodofDiscord) { return !DownedBossSystem.downedCalamitas || !DownedBossSystem.downedExoMechs; } @@ -464,6 +463,35 @@ namespace CalamityMod.ILEditing } #endregion + #region Reduce Eater of Worlds Grenade Resist + private static void ReduceEoWGrenadeResist(ILContext il) + { + // Reduce Expert+ Eater of Worlds' resist to explosives from 80% to 60%. + var cursor = new ILCursor(il); + + // Of course, this is 800 lines into Projectile.Damage, so we must do funky things. + for (int f = 0; f < 2; f++) + { + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdcI4(1002))) + { + LogFailure("Reduce EoW Grenade Resist", "Could not move to the resist factor."); + return; + } + } + if (!cursor.TryGotoNext(MoveType.AfterLabel, i => i.MatchDiv())) + { + LogFailure("Reduce EoW Grenade Resist", "Could not move to the resist factor."); + return; + } + + // Remove the division instruction, then pop the 5 off the stack to destroy it. Replace it with loading a 0.4 and then multiplying by it. + cursor.Remove(); + cursor.EmitPop(); + cursor.EmitLdcR4(0.4f); + cursor.EmitMul(); + } + #endregion + #region Terrarian Projectile Limitation for Extra Updates private static void LimitTerrarianProjectiles(ILContext il) { diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 109b245104..9eb8eac935 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -40,11 +40,9 @@ namespace CalamityMod.ILEditing // Graphics IL_Main.DoDraw += AdditiveDrawing; IL_Main.DoDraw += DrawFloralParadiseFog; - On_Main.DrawGore += DrawForegroundStuff; On_Main.DrawCursor += UseCoolFireCursorEffect; On_Main.SortDrawCacheWorms += DrawFusableParticles; On_Main.DrawInfernoRings += DrawForegroundParticles; - On_TileDrawing.PreDrawTiles += ClearForegroundStuff; On_TileDrawing.Draw += ClearTilePings; On_CommonCode.ModifyItemDropFromNPC += ColorBlightedGel; @@ -54,6 +52,11 @@ namespace CalamityMod.ILEditing On_Player.ApplyEquipVanity_Item += DyeableShadersRenderer.CheckVanityDetour; On_Player.UpdateArmorSets += DyeableShadersRenderer.CheckArmorSetsDetour; + // Graphics (ModPlant stuff) + IL_TileDrawing.DrawSingleTile += DisableCullingForTreeAndCactus; + IL_TileDrawing.DrawTrees += DrawTreeGlowMask; + On_TileDrawing.DrawBasicTile += DrawTreeTrunkAndCactusGlowMask; + // NPC behavior IL_Main.UpdateTime += PermitNighttimeTownNPCSpawning; On_Main.UpdateTime_SpawnTownNPCs += AlterTownNPCSpawnRate; @@ -91,7 +94,7 @@ namespace CalamityMod.ILEditing IL_Player.ApplyLifeAndOrMana += ManaSicknessAndChaliceBufferHeal; //LavaStyles - if (CalamityMod.Instance.biomeLava == null) + if (ExternalMods.biomeLava == null) { //Rendering/Drawing IL_Main.DoDraw += DoDrawLavas; @@ -138,6 +141,7 @@ namespace CalamityMod.ILEditing // Damage and health balance On_Main.DamageVar_float_int_float += AdjustDamageVariance; IL_NPC.ScaleStats_ApplyExpertTweaks += RemoveExpertHardmodeScaling; + IL_Projectile.Damage += ReduceEoWGrenadeResist; IL_Projectile.AI_099_2 += LimitTerrarianProjectiles; IL_Player.UpdateBuffs += NerfSharpeningStation; IL_Player.UpdateBuffs += NerfBeetleScaleMail; @@ -178,6 +182,7 @@ namespace CalamityMod.ILEditing On_WorldGen.MakeDungeon += LimitDungeonEntranceXPosition; IL_WorldGen.DungeonHalls += LimitDungeonHallsXPosition; IL_WorldGen.MakeDungeon += ChangeDungeonSpikeQuantities; + Terraria.GameContent.Biomes.On_JunglePass.GenerateFinishingTouches += AddStohne; // Removal of vanilla stupidity IL_Player.UpdateBuffs += RemoveFeralBiteRandomDebuffs; diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 9d02639183..c964b7a2bc 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -9,7 +9,6 @@ using CalamityMod.CalPlayer; using CalamityMod.DataStructures; using CalamityMod.Events; using CalamityMod.FluidSimulation; -using CalamityMod.ForegroundDrawing; using CalamityMod.Items.Accessories; using CalamityMod.Items.Accessories.Vanity; using CalamityMod.Items.Dyes; @@ -41,6 +40,7 @@ using Terraria.Chat; using Terraria.DataStructures; using Terraria.GameContent; using Terraria.GameContent.Achievements; +using Terraria.GameContent.Biomes; using Terraria.GameContent.Drawing; using Terraria.GameContent.Events; using Terraria.GameContent.Liquid; @@ -56,6 +56,7 @@ using Terraria.Localization; using Terraria.ModLoader; using Terraria.ModLoader.IO; using Terraria.UI.Gamepad; +using Terraria.WorldBuilding; using static Terraria.WaterfallManager; namespace CalamityMod.ILEditing @@ -886,7 +887,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLavas(isBackground: true); + LavaRenderingSystem.Instance.DrawLavas(isBackground: true); }); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdsfld
("drawToScreen"), i => i.MatchBrfalse(out _), i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchCall
("DrawWaters"))) { @@ -894,7 +895,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLavas(); + LavaRenderingSystem.Instance.DrawLavas(); }); } @@ -907,7 +908,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLavas(); + LavaRenderingSystem.Instance.DrawLavas(); }); } @@ -920,7 +921,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLavas(isBackground: true); + LavaRenderingSystem.Instance.DrawLavas(isBackground: true); }); } @@ -933,7 +934,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.alphaSave = CalamityMod.lavaAlpha.ToArray(); + LavaRenderingSystem.LavaAlpha.CopyTo(LavaRenderingSystem.AlphaSave, 0); }); if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(0), i => i.MatchStloc(34), i => i.MatchBr(out _), i => i.MatchLdloc(34), i => i.MatchLdcI4(1), i => i.MatchBeq(out _))) { @@ -944,7 +945,7 @@ namespace CalamityMod.ILEditing cursor.EmitDelegate((CaptureBiome biome) => { for (int i = 0; i < 1; i++) { - CalamityMod.lavaAlpha[i] = ((i == CalamityMod.LavaStyle) ? 1f : 0f); + LavaRenderingSystem.LavaAlpha[i] = ((i == LavaRenderingSystem.LavaStyle) ? 1f : 0f); } }); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchLdsfld
("waterStyle"), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) @@ -953,7 +954,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLiquid(bg: true, CalamityMod.LavaStyle); + LavaRenderingSystem.Instance.DrawLiquid(bg: true, LavaRenderingSystem.LavaStyle); }); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchLdsfld
("bloodMoon"), i => i.MatchBrtrue(out _), i => i.MatchLdloc(8), i => i.MatchLdfld("WaterStyle"), i => i.MatchBr(out _), i => i.MatchLdcI4(9), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) { @@ -961,7 +962,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLiquid(bg: true, CalamityMod.LavaStyle); + LavaRenderingSystem.Instance.DrawLiquid(bg: true, LavaRenderingSystem.LavaStyle); }); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchLdsfld
("waterStyle"), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) { @@ -969,7 +970,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLiquid(bg: false, CalamityMod.LavaStyle); + LavaRenderingSystem.Instance.DrawLiquid(bg: false, LavaRenderingSystem.LavaStyle); }); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchLdloc(8), i => i.MatchLdfld("WaterStyle"), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) { @@ -977,7 +978,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - LavaRendering.instance.DrawLiquid(bg: false, CalamityMod.LavaStyle); + LavaRenderingSystem.Instance.DrawLiquid(bg: false, LavaRenderingSystem.LavaStyle); }); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdloc2(), i => i.MatchStsfld
("liquidAlpha"))) { @@ -985,7 +986,7 @@ namespace CalamityMod.ILEditing return; } cursor.EmitDelegate(() => { - CalamityMod.lavaAlpha = LavaRendering.alphaSave; + LavaRenderingSystem.AlphaSave.CopyTo(LavaRenderingSystem.LavaAlpha, 0); }); } @@ -1003,7 +1004,7 @@ namespace CalamityMod.ILEditing cursor.EmitLdloc(13); cursor.EmitLdloc(14); cursor.EmitDelegate((Vector2 unscaledPosition, Vector2 vector, int j, int i, Tile tile) => { - LavaRendering.instance.DrawTile_LiquidBehindTile(solidLayer: false, inFrontOfPlayers: false, -1, unscaledPosition, vector, j, i, tile); + LavaRenderingSystem.Instance.DrawTile_LiquidBehindTile(solidLayer: false, inFrontOfPlayers: false, -1, unscaledPosition, vector, j, i, tile); }); } #endregion @@ -1026,7 +1027,7 @@ namespace CalamityMod.ILEditing cursor.EmitLdarg3(); cursor.EmitLdloc2(); //Initiated Liquid Draw Cache (needed for the Type parameter) cursor.EmitLdfld(typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic).GetRuntimeField("Type")); - cursor.EmitDelegate>((IsVisible, style, type) => IsVisible && ((type == 1 && style >= LavaRendering.instance.WaterStyleMaxCount + 1) || (type != 1 && style <= LavaRendering.instance.WaterStyleMaxCount))); + cursor.EmitDelegate>((IsVisible, style, type) => IsVisible && ((type == 1 && style >= LavaRenderingSystem.Instance.WaterStyleMaxCount + 1) || (type != 1 && style <= LavaRenderingSystem.Instance.WaterStyleMaxCount))); //Lava alpha color, if the liquid drawn is lava, multiply num by the water alpha if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdloc(2), i => i.MatchLdfld(typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic).GetRuntimeField("Type")), i => i.MatchStloc(8))) @@ -1054,7 +1055,11 @@ namespace CalamityMod.ILEditing cursor.EmitLdarg3(); cursor.EmitLdloc2(); //Initiated Liquid Draw Cache (needed for the Type parameter) cursor.EmitLdfld(typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic).GetRuntimeField("Type")); - cursor.EmitDelegate>((initialTexture, style, type) => (style >= LavaRendering.instance.WaterStyleMaxCount + 1 && type == LiquidID.Lava) ? CalamityMod.LavaTextures.liquid[style - LavaRendering.instance.WaterStyleMaxCount - 1].Value : initialTexture); + cursor.EmitDelegate>((initialTexture, style, type) => + (style >= LavaRenderingSystem.Instance.WaterStyleMaxCount + 1 && type == LiquidID.Lava) + ? LavaRenderingSystem.Textures.liquid[style - LavaRenderingSystem.Instance.WaterStyleMaxCount - 1].Value + : initialTexture + ); } private void BlockLavaDrawingForSlopes(On_TileDrawing.orig_DrawTile_LiquidBehindTile orig, TileDrawing self, bool solidLayer, bool inFrontOfPlayers, int waterStyleOverride, Vector2 screenPosition, Vector2 screenOffset, int tileX, int tileY, Tile tileCache) @@ -1136,13 +1141,13 @@ namespace CalamityMod.ILEditing LogFailure("Ambient lava bubble replacer", "Could not locate the bubble newdust parameters"); return; } - cursor.EmitDelegate>(type => LavaRendering.dustLava()); + cursor.EmitDelegate>(type => LavaRenderingSystem.dustLava()); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdcI4(16), i => i.MatchLdcI4(8), i => i.MatchLdcI4(35))) { LogFailure("Ambient lava bubble replacer", "Could not locate the surface bubble newdust parameters"); return; } - cursor.EmitDelegate>(type2 => LavaRendering.dustLava()); + cursor.EmitDelegate>(type2 => LavaRenderingSystem.dustLava()); } private void LavaDropletReplacer(ILContext il) @@ -1153,7 +1158,7 @@ namespace CalamityMod.ILEditing LogFailure("Ambient lava droplet replacer", "Could not locate the lava droplet newgore parameters"); return; } - cursor.EmitDelegate>(type => LavaRendering.goreLava()); + cursor.EmitDelegate>(type => LavaRenderingSystem.goreLava()); } private void SplashEntityLava(ILContext il) @@ -1164,13 +1169,13 @@ namespace CalamityMod.ILEditing LogFailure("Entity Lava Splashing (Item, Projectile, NPC, Player)", "Could not locate the first lava bubble splashing"); return; } - cursor.EmitDelegate>(type => LavaRendering.dustLava()); + cursor.EmitDelegate>(type => LavaRenderingSystem.dustLava()); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdfld("width"), i => i.MatchLdcI4(12), i => i.MatchAdd(), i => i.MatchLdcI4(24), i => i.MatchLdcI4(35))) { LogFailure("Entity Lava Splashing (Item, Projectile, NPC, Player)", "Could not locate the second lava bubble splashing"); return; } - cursor.EmitDelegate>(type2 => LavaRendering.dustLava()); + cursor.EmitDelegate>(type2 => LavaRenderingSystem.dustLava()); } private void PlayerDebuffEdit(ILContext il) @@ -1186,7 +1191,7 @@ namespace CalamityMod.ILEditing cursor.EmitLdloc(161); cursor.EmitDelegate((Player player, int onFiretime) => { - LavaStylesLoader.InflictDebuff(player, CalamityMod.LavaStyle, onFiretime); + LavaStylesLoader.InflictDebuff(player, LavaRenderingSystem.LavaStyle, onFiretime); }); } #endregion @@ -1194,7 +1199,7 @@ namespace CalamityMod.ILEditing #region Other private Color WaterfallGlowmaskEditor(On_WaterfallManager.orig_StylizeColor orig, float alpha, int maxSteps, int waterfallType, int y, int s, Tile tileCache, Color aColor) { - if (CalamityMod.LavaStyle != 0 && !LavaStylesLoader.Get(CalamityMod.LavaStyle).LavafallGlowmask()) + if (LavaRenderingSystem.LavaStyle != 0 && !LavaStylesLoader.Get(LavaRenderingSystem.LavaStyle).LavafallGlowmask()) { return aColor; } @@ -1207,7 +1212,7 @@ namespace CalamityMod.ILEditing private void LavaFallRedrawer(On_WaterfallManager.orig_Draw orig, WaterfallManager self, SpriteBatch spriteBatch) { orig.Invoke(self, spriteBatch); - LavaRendering.instance.InitialDrawLavafall(self); + LavaRenderingSystem.Instance.InitialDrawLavafall(self); } #endregion @@ -1244,32 +1249,32 @@ namespace CalamityMod.ILEditing lightColor.Y = Math.Max(lightColor.Y, G); lightColor.Z = Math.Max(lightColor.Z, B); } - else if (tile.LiquidType == LiquidID.Lava && CalamityMod.Instance.biomeLava == null) + else if (tile.LiquidType == LiquidID.Lava && ExternalMods.biomeLava == null) { Vector3 lavaLight = new Vector3(0.55f, 0.33f, 0.11f); - float R = CalamityMod.LavaStyle == 0 ? lavaLight.X : 0f; - float G = CalamityMod.LavaStyle == 0 ? lavaLight.Y : 0f; - float B = CalamityMod.LavaStyle == 0 ? lavaLight.Z : 0f; - LavaStylesLoader.ModifyLightSetup(x, y, CalamityMod.LavaStyle, ref R, ref G, ref B); + float R = LavaRenderingSystem.LavaStyle == 0 ? lavaLight.X : 0f; + float G = LavaRenderingSystem.LavaStyle == 0 ? lavaLight.Y : 0f; + float B = LavaRenderingSystem.LavaStyle == 0 ? lavaLight.Z : 0f; + LavaStylesLoader.ModifyLightSetup(x, y, LavaRenderingSystem.LavaStyle, ref R, ref G, ref B); for (int styleIndex = 0; styleIndex < LavaStylesLoader.TotalCount; styleIndex++) { - if (CalamityMod.lavaAlpha[styleIndex] > 0f && styleIndex != CalamityMod.LavaStyle) + if (LavaRenderingSystem.LavaAlpha[styleIndex] > 0f && styleIndex != LavaRenderingSystem.LavaStyle) { float r = styleIndex == 0 ? lavaLight.X : 0f; float g = styleIndex == 0 ? lavaLight.Y : 0f; float b = styleIndex == 0 ? lavaLight.Z : 0f; LavaStylesLoader.ModifyLightSetup(x, y, styleIndex, ref r, ref g, ref b); - float r2 = CalamityMod.LavaStyle == 0 ? lavaLight.X : 0f; - float g2 = CalamityMod.LavaStyle == 0 ? lavaLight.Y : 0f; - float b2 = CalamityMod.LavaStyle == 0 ? lavaLight.Z : 0f; - LavaStylesLoader.ModifyLightSetup(x, y, CalamityMod.LavaStyle, ref r2, ref g2, ref b2); + float r2 = LavaRenderingSystem.LavaStyle == 0 ? lavaLight.X : 0f; + float g2 = LavaRenderingSystem.LavaStyle == 0 ? lavaLight.Y : 0f; + float b2 = LavaRenderingSystem.LavaStyle == 0 ? lavaLight.Z : 0f; + LavaStylesLoader.ModifyLightSetup(x, y, LavaRenderingSystem.LavaStyle, ref r2, ref g2, ref b2); - R = float.Lerp(r, r2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); - G = float.Lerp(g, g2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); - B = float.Lerp(b, b2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); + R = float.Lerp(r, r2, LavaRenderingSystem.LavaAlpha[LavaRenderingSystem.LavaStyle]); + G = float.Lerp(g, g2, LavaRenderingSystem.LavaAlpha[LavaRenderingSystem.LavaStyle]); + B = float.Lerp(b, b2, LavaRenderingSystem.LavaAlpha[LavaRenderingSystem.LavaStyle]); } } @@ -1295,7 +1300,7 @@ namespace CalamityMod.ILEditing float r = 0.55f; float g = 0.33f; float b = 0.11f; - LavaStylesLoader.ModifyLightSetup(x, y, CalamityMod.LavaStyle, ref r, ref g, ref b); + LavaStylesLoader.ModifyLightSetup(x, y, LavaRenderingSystem.LavaStyle, ref r, ref g, ref b); if (!(r == 0 && g == 0 && b == 0)) { float r8; @@ -1330,9 +1335,9 @@ namespace CalamityMod.ILEditing { CalamityWaterLoader.DrawColorSetup(x, y, Main.waterStyle, ref initialColor); } - else if (liquidType == LiquidID.Lava && CalamityMod.Instance.biomeLava == null) + else if (liquidType == LiquidID.Lava && ExternalMods.biomeLava == null) { - LavaStylesLoader.DrawColorSetup(x, y, CalamityMod.LavaStyle, ref initialColor); + LavaStylesLoader.DrawColorSetup(x, y, LavaRenderingSystem.LavaStyle, ref initialColor); } }); } @@ -1388,7 +1393,7 @@ namespace CalamityMod.ILEditing // Reason: Flag6 is "IsWater" flag, and since we don't modified that behaviour "yet" it will never be triggered here // Fix this when there will be new lava style with dynamic color changes else if (tileCache.LiquidType == LiquidID.Lava) - LavaStylesLoader.DrawColorSetup(x, y, CalamityMod.LavaStyle, ref initialColor); + LavaStylesLoader.DrawColorSetup(x, y, LavaRenderingSystem.LavaStyle, ref initialColor); }); // And now remaining TotalCount is now could pass to local variable @@ -1515,23 +1520,6 @@ namespace CalamityMod.ILEditing } #endregion - #region Foreground tiles drawing - private static void DrawForegroundStuff(Terraria.On_Main.orig_DrawGore orig, Main self) - { - orig(self); - if (Main.PlayerLoaded && !Main.gameMenu) - ForegroundManager.DrawTiles(); - } - - private static void ClearForegroundStuff(On_TileDrawing.orig_PreDrawTiles orig, TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets) - { - orig(self, solidLayer, forRenderTargets, intoRenderTargets); - - if (!solidLayer && (intoRenderTargets || Lighting.UpdateEveryFrame)) - ForegroundManager.ClearTiles(); - } - #endregion - #region Tile ping overlay private static void ClearTilePings(On_TileDrawing.orig_Draw orig, TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets, int waterStyleOverride) { @@ -1847,8 +1835,8 @@ namespace CalamityMod.ILEditing return; var glowMask = glowMaskTile.GlowMask; - int xPos = drawData.tileFrameX + drawData.addFrX; - int yPos = drawData.tileFrameY + drawData.addFrY; + var xPos = drawData.tileFrameX + drawData.addFrX; + var yPos = drawData.tileFrameY + drawData.addFrY; if (glowMask.HasContentInFramePos(xPos, yPos)) { ref Tile tileCache = ref drawData.tileCache; @@ -1888,12 +1876,398 @@ namespace CalamityMod.ILEditing } else { - Vector2 drawPos = new Vector2(tileX * 16, tileY * 16 + 2) - screenPosition + screenOffset; + Vector2 drawPos = new Vector2(tileX * 16, tileY * 16) - screenPosition + screenOffset; Rectangle drawRect = new Rectangle(xPos, yPos, 16, 16); Main.spriteBatch.Draw(glowMask.Texture, drawPos, drawRect, drawColor, 0.0f, default, 1.0f, drawData.tileSpriteEffect, 0.0f); } } } #endregion + + #region Add Stohne to the Jungle + public static void AddStohne(Terraria.GameContent.Biomes.On_JunglePass.orig_GenerateFinishingTouches orig, JunglePass self, GenerationProgress progress, int oldX, int oldY) + { + int anchorX = oldX; + int anchorY = oldY; + double worldScale = (double)Main.maxTilesX / 4200.0 * 1.5; + // Generate mud + for (int i = 0; (double)i <= 20.0 * worldScale; i++) + { + progress.Set((60.0 + (double)i / worldScale) * 0.01); + anchorX += WorldGen.genRand.Next((int)(-5.0 * worldScale), (int)(6.0 * worldScale)); + anchorY += WorldGen.genRand.Next((int)(-5.0 * worldScale), (int)(6.0 * worldScale)); + WorldGen.TileRunner(anchorX, anchorY, WorldGen.genRand.Next(40, 100), WorldGen.genRand.Next(300, 500), TileID.Mud); + } + for (int j = 0; (double)j <= 10.0 * worldScale; j++) + { + progress.Set((80.0 + (double)j / worldScale * 2.0) * 0.01); + anchorX = oldX + WorldGen.genRand.Next((int)(-600.0 * worldScale), (int)(600.0 * worldScale)); + anchorY = oldY + WorldGen.genRand.Next((int)(-200.0 * worldScale), (int)(200.0 * worldScale)); + while (anchorX < 1 || anchorX >= Main.maxTilesX - 1 || anchorY < 1 || anchorY >= Main.maxTilesY - 1 || Main.tile[anchorX, anchorY].TileType != TileID.Mud) + { + anchorX = oldX + WorldGen.genRand.Next((int)(-600.0 * worldScale), (int)(600.0 * worldScale)); + anchorY = oldY + WorldGen.genRand.Next((int)(-200.0 * worldScale), (int)(200.0 * worldScale)); + } + for (int k = 0; (double)k < 8.0 * worldScale; k++) + { + anchorX += WorldGen.genRand.Next(-30, 31); + anchorY += WorldGen.genRand.Next(-30, 31); + int type = -1; + if (WorldGen.genRand.NextBool(7)) + { + type = -2; + } + WorldGen.TileRunner(anchorX, anchorY, WorldGen.genRand.Next(10, 20), WorldGen.genRand.Next(30, 70), type); + } + } + int stoneType = ModContent.TileType(); + for (int l = 0; (double)l <= 300.0 * worldScale; l++) + { + anchorX = oldX + WorldGen.genRand.Next((int)(-600.0 * worldScale), (int)(600.0 * worldScale)); + anchorY = oldY + WorldGen.genRand.Next((int)(-200.0 * worldScale), (int)(200.0 * worldScale)); + while (anchorX < 1 || anchorX >= Main.maxTilesX - 1 || anchorY < 1 || anchorY >= Main.maxTilesY - 1 || Main.tile[anchorX, anchorY].TileType != 59) + { + anchorX = oldX + WorldGen.genRand.Next((int)(-600.0 * worldScale), (int)(600.0 * worldScale)); + anchorY = oldY + WorldGen.genRand.Next((int)(-200.0 * worldScale), (int)(200.0 * worldScale)); + } + WorldGen.TileRunner(anchorX, anchorY, WorldGen.genRand.Next(4, 10), WorldGen.genRand.Next(5, 30), stoneType); + // Generate Gems + if (WorldGen.genRand.NextBool(4)) + { + int gem = WorldGen.genRand.Next(63, 69); + WorldGen.TileRunner(anchorX + WorldGen.genRand.Next(-1, 2), anchorY + WorldGen.genRand.Next(-1, 2), WorldGen.genRand.Next(3, 7), WorldGen.genRand.Next(4, 8), gem); + } + } + } + #endregion + + #region Hellscape for GlowMask ModPlants + + #region Tree Trunk / Cactus GlowMask + private static void DrawTreeTrunkAndCactusGlowMask(On_TileDrawing.orig_DrawBasicTile orig, TileDrawing self, Vector2 screenPosition, Vector2 screenOffset, int tileX, int tileY, TileDrawInfo drawData, Rectangle normalTileRect, Vector2 normalTilePosition) + { + orig(self, screenPosition, screenOffset, tileX, tileY, drawData, normalTileRect, normalTilePosition); + + var type = drawData.typeCache; + + #region GlowMask Cactus + if (type == TileID.Cactus) + { + var frameX = drawData.tileFrameX; + var frameY = drawData.tileFrameY; + var xPos = drawData.tileFrameX + drawData.addFrX; + var yPos = drawData.tileFrameY + drawData.addFrY; + + WorldGen.GetCactusType(tileX, tileY, frameX, frameY, out var sandType); + if (PlantLoader.Get(TileID.Cactus, sandType) is GlowMaskCactus glowCacti) + { + Vector2 drawPos = new Vector2(tileX * 16, tileY * 16) - screenPosition + screenOffset; + Rectangle drawRect = new Rectangle(xPos, yPos, 16, 16); + + // Fruit Check + var isFruit = drawData.tileFrameX == 204 || drawData.tileFrameY == 202; + var textureToDraw = isFruit ? glowCacti.GetFruitGlowTexture() : glowCacti.GetGlowTexture(); + var texture = textureToDraw?.Value; + if (texture is not null) + Main.spriteBatch.Draw(texture, drawPos, drawRect, glowCacti.GetGlowColor(tileX, tileY), 0.0f, default, 1.0f, drawData.tileSpriteEffect, 0.0f); + } + return; + } + #endregion + + #region GlowMask Tree Trunk + else if (type == TileID.Trees) + { + var xPos = drawData.tileFrameX + drawData.addFrX; + var yPos = drawData.tileFrameY + drawData.addFrY; + + WorldGen.GetTreeBottom(tileX, tileY, out var groundX, out var groundY); + Tile tile = Main.tile[groundX, groundY]; + if (PlantLoader.Get(TileID.Trees, tile.TileType) is GlowMaskTree glowTree) + { + Vector2 drawPos = new Vector2(tileX * 16, tileY * 16) - screenPosition + screenOffset; + Rectangle drawRect = new Rectangle(xPos, yPos, 16, 16); + + var texture = glowTree.GetGlowTexture()?.Value; + if (texture is not null) + Main.spriteBatch.Draw(texture, drawPos, drawRect, glowTree.GetGlowColor(tileX, tileY), 0.0f, default, 1.0f, drawData.tileSpriteEffect, 0.0f); + } + return; + } + #endregion + + #region GlowMask Palm Tree Trunk + else if (type == TileID.PalmTree) + { + var xPos = drawData.tileFrameX + drawData.addFrX; + var yPos = drawData.tileFrameY + drawData.addFrY; + + WorldGen.GetTreeBottom(tileX, tileY, out var groundX, out var groundY); + Tile tile = Main.tile[groundX, groundY]; + if (PlantLoader.Get(TileID.PalmTree, tile.TileType) is GlowMaskPalmTree glowTree) + { + Rectangle drawRect = new Rectangle(xPos, yPos, 16, 16); + + var texture = glowTree.GetGlowTexture()?.Value; + if (texture is not null) + Main.spriteBatch.Draw(texture, normalTilePosition, drawRect, glowTree.GetGlowColor(tileX, tileY), 0.0f, default, 1.0f, drawData.tileSpriteEffect, 0.0f); + } + return; + } + #endregion + } + #endregion + + #region Disable Tree/Cactus Culling + private static void DisableCullingForTreeAndCactus(ILContext il) + { + // Justification: + // Culling for Tree/Cactus should be disabled to simplify the GlowMask rendering on Plants + // Without this We would need to setup more ilchanges to properly gather draw position + // Furthermore we might need to clone the whole vanilla code for tree rendering + // + // And disable culling for pitch black tree/cactus would not affect the performance that much as it's really niche case + + var cursor = new ILCursor(il); + + int visibleFlagIndex = 0; + if (!cursor.TryGotoNext(MoveType.Before, + [ + x => x.MatchLdloc(out visibleFlagIndex), + x => x.MatchLdarg(out _), + x => x.MatchLdfld(out _), + x => x.MatchCallOrCallvirt("IsVisible") + ])) + { + LogFailure("Disable Tree And Cactus Culling", "Unable to Locate IsVisible Call"); + return; + } + + if (!cursor.TryGotoPrev(MoveType.Before, x => x.MatchBrfalse(out _))) + { + LogFailure("Disable Tree And Cactus Culling", "Unable to Locate Brfalse.s"); + return; + } + + cursor.EmitLdarg1(); // TileDrawInfo drawInfo + cursor.EmitDelegate((TileDrawInfo drawInfo) => + { + var type = drawInfo.typeCache; + return type == TileID.Cactus || type == TileID.Trees || type == TileID.PalmTree; + }); + cursor.EmitLdloc(visibleFlagIndex); + cursor.EmitOr(); // visible || isTree || isCactus || isPalmTree + cursor.EmitStloc(visibleFlagIndex); + } + #endregion + + #region Tree Parts GlowMask + private static void DrawTreeGlowMask(ILContext il) + { + var cursor = new ILCursor(il); + + if (!cursor.TryGotoNext(MoveType.After, x => x.MatchLdfld("X"))) + { + LogFailure("GlowMask Tree Rendering", "Unable to Locate Ldfld for Point::X"); + return; + } + + if (!cursor.Next.MatchStloc(out var xLocaIdx)) + { + LogFailure("GlowMask Tree Rendering", "Unable to Locate Stloc Index for Point::X"); + return; + } + + if (!cursor.TryGotoNext(MoveType.After, x => x.MatchLdfld("Y"))) + { + LogFailure("GlowMask Tree Rendering", "Unable to Locate Ldfld for Point::Y"); + return; + } + + if (!cursor.Next.MatchStloc(out var yLocaIdx)) + { + LogFailure("GlowMask Tree Rendering", "Unable to Locate Stloc Index for Point::Y"); + return; + } + + ApplyTreeGlowMaskSubParts(cursor, "GlowMaskTree-Top", "GetTreeTopTexture", xLocaIdx, yLocaIdx, + (glowMaskTree, tileX, tileY) => + { + return new GlowMaskPlantDrawInfo() + { + Texture = glowMaskTree.GetTopGlowTextures().Value, + Color = glowMaskTree.GetGlowColor(tileX, tileY) + }; + }); + + ApplyTreeGlowMaskSubParts(cursor, "GlowMaskTree-R", "GetTreeBranchTexture", xLocaIdx, yLocaIdx, + (glowMaskTree, tileX, tileY) => + { + return new GlowMaskPlantDrawInfo() + { + Texture = glowMaskTree.GetBranchGlowTextures().Value, + Color = glowMaskTree.GetGlowColor(tileX, tileY) + }; + }); + + ApplyTreeGlowMaskSubParts(cursor, "GlowMaskTree-L", "GetTreeBranchTexture", xLocaIdx, yLocaIdx, + (glowMaskTree, tileX, tileY) => + { + return new GlowMaskPlantDrawInfo() + { + Texture = glowMaskTree.GetBranchGlowTextures().Value, + Color = glowMaskTree.GetGlowColor(tileX, tileY) + }; + }); + + ApplyPalmTreeGlowMaskSubParts(cursor, "GlowMaskPalmTree-Top", "GetTreeTopTexture", xLocaIdx, yLocaIdx, + (glowMaskPalmTree, tileX, tileY) => + { + return new GlowMaskPlantDrawInfo() + { + Texture = WorldGen.IsPalmOasisTree(tileX) ? + glowMaskPalmTree.GetOasisTopGlowTextures().Value : + glowMaskPalmTree.GetTopGlowTextures().Value, + + Color = glowMaskPalmTree.GetGlowColor(tileX, tileY) + }; + }); + } + #endregion + + #region GlowMask Patch Tree Sub Parts + private static void ApplyTreeGlowMaskSubParts( + ILCursor cursor, + string debugSubpartName, + string getTextureMethodName, + int xLocaIdx, + int yLocaIdx, + Func onPlantDrawn) where PlantType : IPlant + { + if (!cursor.TryGotoNext(MoveType.Before, x => x.MatchCallOrCallvirt(getTextureMethodName))) + { + LogFailure("GlowMask Tree Rendering", $"Could not locate First {getTextureMethodName} call ({debugSubpartName})"); + return; + } + + if (!cursor.TryGotoPrev([x => x.MatchLdcI4(out var styleEq) && styleEq == 14, x => x.MatchBneUn(out _)])) + { + LogFailure("GlowMask Tree Rendering", $"Could not locate Bne.Un for TreeStyleIndex ({debugSubpartName})"); + return; + } + + if (!cursor.Prev.MatchLdloc(out var treeStyleLocaIdx)) + { + LogFailure("GlowMask Tree Rendering", $"Prev Instruction is not a LdLoc. Cannot locate TreeStyleIndex ({debugSubpartName})"); + return; + } + + if (!cursor.TryGotoNext(MoveType.Before, x => x.MatchCallOrCallvirt("Draw"))) + { + LogFailure("GlowMask Tree Rendering", $"Could not locate DrawCall ({debugSubpartName})"); + return; + } + + cursor.EmitLdloc(treeStyleLocaIdx); // TreeStyle + cursor.EmitLdloc(xLocaIdx); + cursor.EmitLdloc(yLocaIdx); + cursor.EmitDelegate(( + SpriteBatch spriteBatch, + Texture2D texture, + Vector2 position, + Rectangle? sourceRectangle, + Color color, + float rotation, + Vector2 origin, + float scale, + SpriteEffects effects, + float layerDepth, + + int style, + int tileX, + int tileY) => + { + spriteBatch.Draw(texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); + + // Spooky Hardcoded Index: style above 100 is modded tile + if (style < 100) + return; + + int lookup = style - 100; + if (PlantLoader.Get(TileID.Trees, lookup) is not PlantType plant) + return; + + GlowMaskPlantDrawInfo? drawInfo = onPlantDrawn?.Invoke(plant, tileX, tileY) ?? default; + if (drawInfo.HasValue) + { + var info = drawInfo.Value; + spriteBatch.Draw(info.Texture, position, sourceRectangle, info.Color, rotation, origin, scale, effects, layerDepth); + } + }); + cursor.Next.OpCode = OpCodes.Nop; // remove next drawcall + } + #endregion + + #region GlowMask Patch Palm Tree Sub Parts + private static void ApplyPalmTreeGlowMaskSubParts( + ILCursor cursor, + string debugSubpartName, + string getTextureMethodName, + int xLocaIdx, + int yLocaIdx, + Func onPlantDrawn) + { + if (!cursor.TryGotoNext(MoveType.Before, x => x.MatchCallOrCallvirt(getTextureMethodName))) + { + LogFailure("GlowMask Tree Rendering", $"Could not locate First {getTextureMethodName} call ({debugSubpartName})"); + return; + } + + if (!cursor.TryGotoNext(MoveType.Before, x => x.MatchCallOrCallvirt("Draw"))) + { + LogFailure("GlowMask Tree Rendering", $"Could not locate DrawCall ({debugSubpartName})"); + return; + } + + cursor.EmitLdloc(xLocaIdx); + cursor.EmitLdloc(yLocaIdx); + cursor.EmitDelegate(( + SpriteBatch spriteBatch, + Texture2D texture, + Vector2 position, + Rectangle? sourceRectangle, + Color color, + float rotation, + Vector2 origin, + float scale, + SpriteEffects effects, + float layerDepth, + + int tileX, + int tileY) => + { + spriteBatch.Draw(texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); + + // TODO: This can be replace to read style and biome index from ilcode + // ... When we can figure out how to extract info from them + // Check TileDrawing.DrawTrees for context + WorldGen.GetTreeBottom(tileX, tileY, out var sandX, out var sandY); + var sandType = Main.tile[sandX, sandY].TileType; + + if (PlantLoader.Get(TileID.PalmTree, sandType) is not PlantType plant) + return; + + GlowMaskPlantDrawInfo? drawInfo = onPlantDrawn?.Invoke(plant, tileX, tileY) ?? default; + if (drawInfo.HasValue) + { + var info = drawInfo.Value; + spriteBatch.Draw(info.Texture, position, sourceRectangle, info.Color, rotation, origin, scale, effects, layerDepth); + } + }); + cursor.Next.OpCode = OpCodes.Nop; // remove next drawcall + } + #endregion + + #endregion } } diff --git a/ILEditing/VanillaStupidityFixingILChanges.cs b/ILEditing/VanillaStupidityFixingILChanges.cs index 510c5dd121..6085b032f0 100644 --- a/ILEditing/VanillaStupidityFixingILChanges.cs +++ b/ILEditing/VanillaStupidityFixingILChanges.cs @@ -1086,6 +1086,7 @@ namespace CalamityMod.ILEditing // 02JUN2024: Ozzatron: The below code is being kept in its initial state for historic value. #region Store The Stupid Fucking Private Wind Map In Public Property + [/*TotallyNot*/Obsolete("This function serves no purpose and is included in the Calamity source code for historic value.", error: true)] private static void StoreWindGrid(On_TileDrawing.orig_Update orig, TileDrawing self) { orig(self); diff --git a/Items/Accessories/CrownJewel.png b/Items/Accessories/CrownJewel.png index 326c657ab4..76ebab0180 100644 Binary files a/Items/Accessories/CrownJewel.png and b/Items/Accessories/CrownJewel.png differ diff --git a/Items/Accessories/ProfanedSoulCrystal.cs b/Items/Accessories/ProfanedSoulCrystal.cs index 6b1abc7d86..f73429b6d8 100644 --- a/Items/Accessories/ProfanedSoulCrystal.cs +++ b/Items/Accessories/ProfanedSoulCrystal.cs @@ -522,6 +522,7 @@ namespace CalamityMod.Items.Accessories AddIngredient(50). AddIngredient(100). AddTile(). + AddDecraftCondition(CalamityConditions.DownedSupremeCalamitas, CalamityConditions.DownedExoMechs). Register(); } } diff --git a/Items/Accessories/StatisVoidSash.cs b/Items/Accessories/StatisVoidSash.cs index 8760d9bb52..6c22ab7e9b 100644 --- a/Items/Accessories/StatisVoidSash.cs +++ b/Items/Accessories/StatisVoidSash.cs @@ -42,6 +42,7 @@ namespace CalamityMod.Items.Accessories modPlayer.DashID = StatisVoidSashDash.ID; player.dashType = 0; player.spikedBoots = 2; + player.accFlipper = true; } public override void AddRecipes() diff --git a/Items/CalamityGlobalItemTweaks.cs b/Items/CalamityGlobalItemTweaks.cs index bfd3286fe7..bf06608b99 100644 --- a/Items/CalamityGlobalItemTweaks.cs +++ b/Items/CalamityGlobalItemTweaks.cs @@ -15,7 +15,7 @@ namespace CalamityMod.Items public partial class CalamityGlobalItem : GlobalItem { // 02AUG2023: Ozzatron: Having Overhaul enabled turns off all scaling changes, per direct request from Mirsario on 8/2/23. - private static bool DisableScalingForOverhaul => CalamityMod.Instance.overhaul is not null; + private static bool DisableScalingForOverhaul => ExternalMods.overhaul is not null; #region Database and Initialization internal static SortedDictionary currentTweaks = null; @@ -126,7 +126,7 @@ namespace CalamityMod.Items { ItemID.GrenadeLauncher, Do(DamageExact(112)) }, { ItemID.Gungnir, Do(AutoReuse, TrueMelee, UseRatio(0.8f), DamageExact(92), ShootSpeedRatio(1.25f)) }, { ItemID.HallowedRepeater, Do(PointBlank, UseExact(12)) }, - { ItemID.Handgun, Do(PointBlank, UseExact(22)) }, + { ItemID.Handgun, Do(PointBlank, UseExact(20)) }, { ItemID.HellwingBow, Do(PointBlank, DamageExact(16)) }, { ItemID.HighVelocityBullet, Do(DamageExact(13)) }, { ItemID.HiveFive, Do(AutoReuse, DamageExact(27)) }, diff --git a/Items/Critters/ShroombleItem.png b/Items/Critters/ShroombleItem.png index 67a5e736dc..e34c2f2d46 100644 Binary files a/Items/Critters/ShroombleItem.png and b/Items/Critters/ShroombleItem.png differ diff --git a/Items/Dyes/HairDye/AdrenalineHairDye.cs b/Items/Dyes/HairDye/AdrenalineHairDye.cs index f87b4b3831..8b529b6484 100644 --- a/Items/Dyes/HairDye/AdrenalineHairDye.cs +++ b/Items/Dyes/HairDye/AdrenalineHairDye.cs @@ -1,4 +1,7 @@ -using Terraria; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent.Dyes; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -7,6 +10,22 @@ namespace CalamityMod.Items.Dyes.HairDye public class AdrenalineHairDye : ModItem, ILocalizedModType { public new string LocalizationCategory => "Items.Dyes"; + + public override void SetStaticDefaults() + { + if (!Main.dedServ) + { + GameShaders.Hair.BindShader(Type, new LegacyHairShaderData().UseLegacyMethod(UpdateHairDye)); + } + } + + private static Color UpdateHairDye(Player player, Color newColor, ref bool lighting) + { + var calPlayer = player.Calamity(); + var adrenalineP = calPlayer.adrenaline / calPlayer.adrenalineMax; + return Color.Lerp(player.hairColor, new Color(0, 255, 171), adrenalineP); + } + public override void SetDefaults() { Item.width = 20; diff --git a/Items/Dyes/HairDye/RageHairDye.cs b/Items/Dyes/HairDye/RageHairDye.cs index be7670346c..1cba915954 100644 --- a/Items/Dyes/HairDye/RageHairDye.cs +++ b/Items/Dyes/HairDye/RageHairDye.cs @@ -1,4 +1,7 @@ -using Terraria; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent.Dyes; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -7,6 +10,22 @@ namespace CalamityMod.Items.Dyes.HairDye public class RageHairDye : ModItem, ILocalizedModType { public new string LocalizationCategory => "Items.Dyes"; + + public override void SetStaticDefaults() + { + if (!Main.dedServ) + { + GameShaders.Hair.BindShader(Type, new LegacyHairShaderData().UseLegacyMethod(UpdateHairDye)); + } + } + + private static Color UpdateHairDye(Player player, Color newColor, ref bool lighting) + { + var calPlayer = player.Calamity(); + var rageP = calPlayer.rage / calPlayer.rageMax; + return Color.Lerp(player.hairColor, new Color(255, 83, 48), rageP); + } + public override void SetDefaults() { Item.width = 20; diff --git a/Items/Dyes/HairDye/StealthHairDye.cs b/Items/Dyes/HairDye/StealthHairDye.cs index 8f96f7df2b..ecf18ab40a 100644 --- a/Items/Dyes/HairDye/StealthHairDye.cs +++ b/Items/Dyes/HairDye/StealthHairDye.cs @@ -1,4 +1,7 @@ -using Terraria; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent.Dyes; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -7,6 +10,25 @@ namespace CalamityMod.Items.Dyes.HairDye public class StealthHairDye : ModItem, ILocalizedModType { public new string LocalizationCategory => "Items.Dyes"; + + public override void SetStaticDefaults() + { + if (!Main.dedServ) + { + GameShaders.Hair.BindShader(Type, new LegacyHairShaderData().UseLegacyMethod(UpdateHairDye)); + } + } + + private static Color UpdateHairDye(Player player, Color newColor, ref bool lighting) + { + float stealthP = player.Calamity().rogueStealth / player.Calamity().rogueStealthMax; + + if (float.IsInfinity(stealthP) || float.IsNaN(stealthP)) + stealthP = 0f; + + return Color.Lerp(player.hairColor, new Color(186, 85, 211), stealthP); + } + public override void SetDefaults() { Item.width = 20; diff --git a/Items/Dyes/HairDye/WingTimeHairDye.cs b/Items/Dyes/HairDye/WingTimeHairDye.cs index 4083db0f6f..d4de5e8574 100644 --- a/Items/Dyes/HairDye/WingTimeHairDye.cs +++ b/Items/Dyes/HairDye/WingTimeHairDye.cs @@ -1,4 +1,7 @@ -using Terraria; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent.Dyes; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -7,6 +10,25 @@ namespace CalamityMod.Items.Dyes.HairDye public class WingTimeHairDye : ModItem, ILocalizedModType { public new string LocalizationCategory => "Items.Dyes"; + + public override void SetStaticDefaults() + { + if (!Main.dedServ) + { + GameShaders.Hair.BindShader(Type, new LegacyHairShaderData().UseLegacyMethod(UpdateHairDye)); + } + } + + private static Color UpdateHairDye(Player player, Color newColor, ref bool lighting) + { + float wingP = player.wingTime / player.wingTimeMax; + + if (player.mount.Active) wingP = 1f; + else if (float.IsInfinity(wingP) || float.IsNaN(wingP)) wingP = 0f; + + return Color.Lerp(player.hairColor, new Color(139, 205, 255), wingP); + } + public override void SetDefaults() { Item.width = 20; diff --git a/Items/Fishing/GlimmeringGemfish.cs b/Items/Fishing/GlimmeringGemfish.cs index d27cbb552c..9f0e775bf1 100644 --- a/Items/Fishing/GlimmeringGemfish.cs +++ b/Items/Fishing/GlimmeringGemfish.cs @@ -42,7 +42,7 @@ namespace CalamityMod.Items.Fishing itemLoot.Add(ItemID.Amber, 8, gemMin, gemMax); // Add Thorium gems if Thorium is loaded. - Mod thorium = CalamityMod.Instance.thorium; + Mod thorium = ExternalMods.thorium; if (thorium is null) return; diff --git a/Items/Fishing/StuffedFish.cs b/Items/Fishing/StuffedFish.cs index 477c139969..de2ab4cb5e 100644 --- a/Items/Fishing/StuffedFish.cs +++ b/Items/Fishing/StuffedFish.cs @@ -66,7 +66,7 @@ namespace CalamityMod.Items.Fishing itemLoot.AddIf(() => Main.hardMode, ItemID.HallowedSeeds, 20, seedMin, seedMax); // Add Thorium Marine Kelp if Thorium is loaded. - Mod thorium = CalamityMod.Instance.thorium; + Mod thorium = ExternalMods.thorium; if (thorium is null) return; diff --git a/Items/LoreItems/LoreSlimeGod.png b/Items/LoreItems/LoreSlimeGod.png index a8536f1d61..b092509112 100644 Binary files a/Items/LoreItems/LoreSlimeGod.png and b/Items/LoreItems/LoreSlimeGod.png differ diff --git a/Items/Placeables/Furniture/BossRelics/SlimeGodRelic.png b/Items/Placeables/Furniture/BossRelics/SlimeGodRelic.png index fa4f78154d..caf942e9cb 100644 Binary files a/Items/Placeables/Furniture/BossRelics/SlimeGodRelic.png and b/Items/Placeables/Furniture/BossRelics/SlimeGodRelic.png differ diff --git a/Items/Placeables/FurnitureEutrophic/AncientSmoothNavystone.cs b/Items/Placeables/FurnitureEutrophic/AncientSmoothNavystone.cs new file mode 100644 index 0000000000..03e455c165 --- /dev/null +++ b/Items/Placeables/FurnitureEutrophic/AncientSmoothNavystone.cs @@ -0,0 +1,25 @@ +using CalamityMod.Items.Placeables.Walls; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.FurnitureEutrophic +{ + public class AncientSmoothNavystone : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + public override void SetStaticDefaults() + { + Item.ResearchUnlockCount = 100; + } + + public override void SetDefaults() => Item.DefaultToPlaceableTile(ModContent.TileType()); + + /*public override void AddRecipes() + { + CreateRecipe(). + AddIngredient(4). + AddTile(TileID.WorkBenches). + Register(); + }*/ + } +} diff --git a/Items/Placeables/FurnitureEutrophic/AncientSmoothNavystone.png b/Items/Placeables/FurnitureEutrophic/AncientSmoothNavystone.png new file mode 100644 index 0000000000..27551b932a Binary files /dev/null and b/Items/Placeables/FurnitureEutrophic/AncientSmoothNavystone.png differ diff --git a/Items/Placeables/FurnitureEutrophic/SmoothNavystone.cs b/Items/Placeables/FurnitureEutrophic/SmoothNavystone.cs index 4037d5b9b2..6dad3d2cee 100644 --- a/Items/Placeables/FurnitureEutrophic/SmoothNavystone.cs +++ b/Items/Placeables/FurnitureEutrophic/SmoothNavystone.cs @@ -10,6 +10,7 @@ namespace CalamityMod.Items.Placeables.FurnitureEutrophic public override void SetStaticDefaults() { Item.ResearchUnlockCount = 100; + ItemID.Sets.ShimmerTransformToItem[Type] = ModContent.ItemType(); } public override void SetDefaults() => Item.DefaultToPlaceableTile(ModContent.TileType()); diff --git a/Items/Placeables/FurnitureEutrophic/SmoothNavystone.png b/Items/Placeables/FurnitureEutrophic/SmoothNavystone.png index 27551b932a..c1cfbd43f0 100644 Binary files a/Items/Placeables/FurnitureEutrophic/SmoothNavystone.png and b/Items/Placeables/FurnitureEutrophic/SmoothNavystone.png differ diff --git a/Items/Placeables/Stohne.cs b/Items/Placeables/Stohne.cs new file mode 100644 index 0000000000..1e17d1f9ee --- /dev/null +++ b/Items/Placeables/Stohne.cs @@ -0,0 +1,16 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables +{ + public class Stohne : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + public override void SetStaticDefaults() + { + Item.ResearchUnlockCount = 100; + } + + public override void SetDefaults() => Item.DefaultToPlaceableTile(ModContent.TileType()); + } +} diff --git a/Items/Placeables/Stohne.png b/Items/Placeables/Stohne.png new file mode 100644 index 0000000000..60d4e9c891 Binary files /dev/null and b/Items/Placeables/Stohne.png differ diff --git a/Items/Tools/ClimateChange/AridArtifact.cs b/Items/Tools/ClimateChange/AridArtifact.cs index 3e83a71ec6..9949af0295 100644 --- a/Items/Tools/ClimateChange/AridArtifact.cs +++ b/Items/Tools/ClimateChange/AridArtifact.cs @@ -1,4 +1,5 @@ -using Terraria; +using CalamityMod.World; +using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -39,9 +40,9 @@ namespace CalamityMod.Items.Tools.ClimateChange return true; if (SandstormEvent.Happening) - CalamityUtils.StopSandstorm(); + CalamityWorld.StopSandstorm(); else - CalamityUtils.StartSandstorm(); + CalamityWorld.StartSandstorm(); return true; } diff --git a/Items/Tools/ClimateChange/TorrentialTear.cs b/Items/Tools/ClimateChange/TorrentialTear.cs index ed9eb51f0b..ff849c21b1 100644 --- a/Items/Tools/ClimateChange/TorrentialTear.cs +++ b/Items/Tools/ClimateChange/TorrentialTear.cs @@ -1,4 +1,5 @@ -using Terraria; +using CalamityMod.World; +using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -37,11 +38,11 @@ namespace CalamityMod.Items.Tools.ClimateChange if (!Main.raining) { - CalamityUtils.StartRain(torrentialTear: true, worldSync: true); + CalamityWorld.StartRain(adjustSeverity: true, worldSync: true); } else { - CalamityUtils.StopRain(clearWeather: false, worldSync: true); + CalamityWorld.StopRain(clearWeather: false, worldSync: true); } return true; diff --git a/Items/TreasureBags/MiscGrabBags/StarterBag.cs b/Items/TreasureBags/MiscGrabBags/StarterBag.cs index 2972a10c58..dc3ff0f33f 100644 --- a/Items/TreasureBags/MiscGrabBags/StarterBag.cs +++ b/Items/TreasureBags/MiscGrabBags/StarterBag.cs @@ -65,7 +65,7 @@ namespace CalamityMod.Items.TreasureBags.MiscGrabBags itemLoot.Add(ItemID.Chest, 1, 3, 3); // Calamity title theme music box (if music mod is enabled) - Mod musicMod = CalamityMod.Instance.musicMod; + Mod musicMod = ExternalMods.musicMod; if (musicMod is not null) itemLoot.Add(musicMod.Find("CalamityMusicbox").Type); diff --git a/Items/VanillaArmorChanges/VanillaArmorChangeManager.cs b/Items/VanillaArmorChanges/VanillaArmorChangeManager.cs index fd242a29e5..591bb65d2d 100644 --- a/Items/VanillaArmorChanges/VanillaArmorChangeManager.cs +++ b/Items/VanillaArmorChanges/VanillaArmorChangeManager.cs @@ -4,29 +4,28 @@ using System.Linq; using System.Runtime.Serialization; using Terraria; using Terraria.ID; +using Terraria.ModLoader; using Terraria.ModLoader.Core; namespace CalamityMod.Items.VanillaArmorChanges { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class VanillaArmorChangeManager + public class VanillaArmorChangeManager : ModSystem { internal static List ArmorChanges; - internal static void Load() + public override void OnModLoad() { - ArmorChanges = new List(); - Type[] types = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code); - foreach (Type type in types) + ArmorChanges = []; + ReflectionHelper.IterateCalamityTypes(action: type => { - if (!type.IsSubclassOf(typeof(VanillaArmorChange)) || type.IsAbstract) - continue; - - ArmorChanges.Add((VanillaArmorChange)FormatterServices.GetUninitializedObject(type)); - } + ArmorChanges.Add((VanillaArmorChange)Activator.CreateInstance(type)); + }); } - internal static void Unload() => ArmorChanges = null; + public override void Unload() + { + ArmorChanges = null; + } public static void ApplySetBonusTooltipChanges(Item checkItem, ref string setBonusText) { diff --git a/Items/Weapons/Magic/RainbowPartyCannon.cs b/Items/Weapons/Magic/RainbowPartyCannon.cs index caeb8f03cb..e496dd6214 100644 --- a/Items/Weapons/Magic/RainbowPartyCannon.cs +++ b/Items/Weapons/Magic/RainbowPartyCannon.cs @@ -28,7 +28,7 @@ namespace CalamityMod.Items.Weapons.Magic { Item.width = 52; Item.height = 30; - Item.damage = 225; + Item.damage = 175; Item.DamageType = DamageClass.Magic; Item.mana = 25; Item.crit += 4; diff --git a/Items/Weapons/Melee/BrokenBiomeBlade.cs b/Items/Weapons/Melee/BrokenBiomeBlade.cs index eb08776086..895d685c87 100644 --- a/Items/Weapons/Melee/BrokenBiomeBlade.cs +++ b/Items/Weapons/Melee/BrokenBiomeBlade.cs @@ -7,6 +7,7 @@ using CalamityMod.Items.BaseItems; using CalamityMod.Items.Materials; using CalamityMod.Particles; using CalamityMod.Projectiles.Melee; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -160,8 +161,8 @@ namespace CalamityMod.Items.Weapons.Melee int attunement1 = tag.GetInt("mainAttunement"); int attunement2 = tag.GetInt("secondaryAttunement"); - mainAttunement = Attunement.attunementArray[attunement1 != -1 ? attunement1 : Attunement.attunementArray.Length - 1]; - secondaryAttunement = Attunement.attunementArray[attunement2 != -1 ? attunement2 : Attunement.attunementArray.Length - 1]; + mainAttunement = AttunementSystem.FindOrNull(attunement1); + secondaryAttunement = AttunementSystem.FindOrNull(attunement2); if (mainAttunement == secondaryAttunement) secondaryAttunement = null; @@ -171,14 +172,14 @@ namespace CalamityMod.Items.Weapons.Melee public override void NetSend(BinaryWriter writer) { - writer.Write(mainAttunement != null ? (byte)mainAttunement.id : Attunement.attunementArray.Length - 1); - writer.Write(secondaryAttunement != null ? (byte)secondaryAttunement.id : Attunement.attunementArray.Length - 1); + writer.Write(mainAttunement != null ? (byte)mainAttunement.id : AttunementSystem.EmptyID); + writer.Write(secondaryAttunement != null ? (byte)secondaryAttunement.id : AttunementSystem.EmptyID); } public override void NetReceive(BinaryReader reader) { - mainAttunement = Attunement.attunementArray[reader.ReadInt32()]; - secondaryAttunement = Attunement.attunementArray[reader.ReadInt32()]; + mainAttunement = AttunementSystem.FindOrNull(reader.ReadInt32()); + secondaryAttunement = AttunementSystem.FindOrNull(reader.ReadInt32()); } #endregion @@ -190,10 +191,21 @@ namespace CalamityMod.Items.Weapons.Melee public void SafeCheckAttunements() { if (mainAttunement != null) - mainAttunement = Attunement.attunementArray[(int)MathHelper.Clamp((float)mainAttunement.id, (float)AttunementID.Default, (float)AttunementID.Evil)]; + mainAttunement = AttunementSystem.FindOrNull(ClampAttunementRange((int)mainAttunement.id)); if (secondaryAttunement != null) - secondaryAttunement = Attunement.attunementArray[(int)MathHelper.Clamp((float)secondaryAttunement.id, (float)AttunementID.Default, (float)AttunementID.Evil)]; + secondaryAttunement = AttunementSystem.FindOrNull(ClampAttunementRange((int)secondaryAttunement.id)); + } + + private static int ClampAttunementRange(int input) + { + if (input < (int)AttunementID.Default) + return (int)AttunementID.Default; + + if (input > (int)AttunementID.Evil) + return (int)AttunementID.Evil; + + return input; } public override void HoldItem(Player player) diff --git a/Items/Weapons/Melee/DeathsAscension.cs b/Items/Weapons/Melee/DeathsAscension.cs index 9377704d1e..819a5ab932 100644 --- a/Items/Weapons/Melee/DeathsAscension.cs +++ b/Items/Weapons/Melee/DeathsAscension.cs @@ -12,6 +12,18 @@ namespace CalamityMod.Items.Weapons.Melee public class DeathsAscension : ModItem, ILocalizedModType { public new string LocalizationCategory => "Items.Weapons.Melee"; + + public const int RiftLifeTime = 600; + + public const float OrbitalScytheDamageMult = 0.4f; + + public const float RiftScytheDamageMult = 0.125f; + + public const int RiftOrbitalAmount = 4; + + public const int ScytheShotAmount = 4; + + public override void SetStaticDefaults() { ItemID.Sets.ItemsThatAllowRepeatedRightClick[Item.type] = true; @@ -80,12 +92,19 @@ namespace CalamityMod.Items.Weapons.Melee int spreadfactor = 9; if (player.altFunctionUse == 2f) { - for (int index = 0; index < 4; ++index) + for (int index = 0; index < ScytheShotAmount; ++index) { float SpeedX = velocity.X + Main.rand.NextFloat(-spreadfactor, spreadfactor + 1); float SpeedY = velocity.Y + Main.rand.NextFloat(-spreadfactor, spreadfactor + 1); Projectile.NewProjectile(source, position.X, position.Y, SpeedX, SpeedY, type, (int)(damage * 0.125f), knockback, player.whoAmI); } + + // Tell the rift(s) to shoot + foreach (Projectile p in Main.ActiveProjectiles) + { + if (p.type == ModContent.ProjectileType() && p.owner == player.whoAmI && p.ai[0] <= 0) + p.ai[0] = 10f; // Cooldown before scythes can be shot again because right click code is cool and shoots twice without this + } } else { diff --git a/Items/Weapons/Melee/FourSeasonsGalaxia.cs b/Items/Weapons/Melee/FourSeasonsGalaxia.cs index 008bea0bf2..44b836e289 100644 --- a/Items/Weapons/Melee/FourSeasonsGalaxia.cs +++ b/Items/Weapons/Melee/FourSeasonsGalaxia.cs @@ -6,6 +6,7 @@ using CalamityMod.DataStructures; using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Melee; using CalamityMod.Rarities; +using CalamityMod.Systems; using CalamityMod.Tiles.Furniture.CraftingStations; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -153,17 +154,17 @@ namespace CalamityMod.Items.Weapons.Melee { int attunement1 = tag.GetInt("mainAttunement"); - mainAttunement = Attunement.attunementArray[attunement1 != -1 ? attunement1 : Attunement.attunementArray.Length - 1]; + mainAttunement = AttunementSystem.FindOrNull(attunement1); } public override void NetSend(BinaryWriter writer) { - writer.Write(mainAttunement != null ? (byte)mainAttunement.id : Attunement.attunementArray.Length - 1); + writer.Write(mainAttunement != null ? (byte)mainAttunement.id : AttunementSystem.EmptyID); } public override void NetReceive(BinaryReader reader) { - mainAttunement = Attunement.attunementArray[reader.ReadInt32()]; + mainAttunement = AttunementSystem.FindOrNull(reader.ReadInt32()); } #endregion @@ -187,10 +188,21 @@ namespace CalamityMod.Items.Weapons.Melee public void SafeCheckAttunements() { if (mainAttunement == null) - mainAttunement = Attunement.attunementArray[(int)AttunementID.Phoenix]; + mainAttunement = AttunementSystem.FindOrNull(AttunementID.Phoenix); else - mainAttunement = Attunement.attunementArray[(int)MathHelper.Clamp((float)mainAttunement.id, (float)AttunementID.Phoenix, (float)AttunementID.Andromeda)]; + mainAttunement = AttunementSystem.FindOrNull(ClampAttunementRange((int)mainAttunement.id)); + } + + private static int ClampAttunementRange(int input) + { + if (input < (int)AttunementID.Phoenix) + return (int)AttunementID.Phoenix; + + if (input > (int)AttunementID.Andromeda) + return (int)AttunementID.Andromeda; + + return input; } public override void HoldItem(Player player) @@ -240,7 +252,7 @@ namespace CalamityMod.Items.Weapons.Melee public override bool PreDrawInInventory(SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale) { if (mainAttunement == null) - mainAttunement = Attunement.attunementArray[(int)AttunementID.Phoenix]; + mainAttunement = AttunementSystem.FindOrNull(AttunementID.Phoenix); Texture2D itemTexture = Request((mainAttunement.id == AttunementID.Polaris || mainAttunement.id == AttunementID.Andromeda) ? "CalamityMod/Items/Weapons/Melee/GalaxiaDusk" : "CalamityMod/Items/Weapons/Melee/GalaxiaDawn").Value; Texture2D outlineTexture = Request((mainAttunement.id == AttunementID.Polaris || mainAttunement.id == AttunementID.Andromeda) ? "CalamityMod/Items/Weapons/Melee/GalaxiaDuskOutline" : "CalamityMod/Items/Weapons/Melee/GalaxiaDawnOutline").Value; @@ -264,7 +276,7 @@ namespace CalamityMod.Items.Weapons.Melee public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI) { if (mainAttunement == null) - mainAttunement = Attunement.attunementArray[(int)AttunementID.Phoenix]; + mainAttunement = AttunementSystem.FindOrNull(AttunementID.Phoenix); Texture2D itemTexture = Request((mainAttunement.id == AttunementID.Polaris || mainAttunement.id == AttunementID.Andromeda) ? "CalamityMod/Items/Weapons/Melee/GalaxiaDusk" : "CalamityMod/Items/Weapons/Melee/GalaxiaDawn").Value; Texture2D outlineTexture = Request((mainAttunement.id == AttunementID.Polaris || mainAttunement.id == AttunementID.Andromeda) ? "CalamityMod/Items/Weapons/Melee/GalaxiaDuskOutline" : "CalamityMod/Items/Weapons/Melee/GalaxiaDawnOutline").Value; diff --git a/Items/Weapons/Melee/GrandDad.cs b/Items/Weapons/Melee/GrandDad.cs index cc2366d230..fbd699748c 100644 --- a/Items/Weapons/Melee/GrandDad.cs +++ b/Items/Weapons/Melee/GrandDad.cs @@ -22,7 +22,7 @@ namespace CalamityMod.Items.Weapons.Melee { Item.width = 124; Item.height = 124; - Item.damage = 2777; // Feel free to change these 7s as balance requires. The other 7s should stay + Item.damage = 1977; // Feel free to change these 7s as balance requires. The other 7s should stay - Update: no more 2777... :( Item.DamageType = TrueMeleeDamageClass.Instance; Item.useAnimation = 77; Item.useTime = 77; diff --git a/Items/Weapons/Melee/OmegaBiomeBlade.cs b/Items/Weapons/Melee/OmegaBiomeBlade.cs index 20e0ac2121..f38bbd37bf 100644 --- a/Items/Weapons/Melee/OmegaBiomeBlade.cs +++ b/Items/Weapons/Melee/OmegaBiomeBlade.cs @@ -6,6 +6,7 @@ using CalamityMod.DataStructures; using CalamityMod.Items.Materials; using CalamityMod.Particles; using CalamityMod.Projectiles.Melee; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -218,8 +219,8 @@ namespace CalamityMod.Items.Weapons.Melee int attunement1 = tag.GetInt("mainAttunement"); int attunement2 = tag.GetInt("secondaryAttunement"); - mainAttunement = Attunement.attunementArray[attunement1 != -1 ? attunement1 : Attunement.attunementArray.Length - 1]; - secondaryAttunement = Attunement.attunementArray[attunement2 != -1 ? attunement2 : Attunement.attunementArray.Length - 1]; + mainAttunement = AttunementSystem.FindOrNull(attunement1); + secondaryAttunement = AttunementSystem.FindOrNull(attunement2); if (mainAttunement == secondaryAttunement) secondaryAttunement = null; @@ -229,14 +230,14 @@ namespace CalamityMod.Items.Weapons.Melee public override void NetSend(BinaryWriter writer) { - writer.Write(mainAttunement != null ? (byte)mainAttunement.id : Attunement.attunementArray.Length - 1); - writer.Write(secondaryAttunement != null ? (byte)secondaryAttunement.id : Attunement.attunementArray.Length - 1); + writer.Write(mainAttunement != null ? (byte)mainAttunement.id : AttunementSystem.EmptyID); + writer.Write(secondaryAttunement != null ? (byte)secondaryAttunement.id : AttunementSystem.EmptyID); } public override void NetReceive(BinaryReader reader) { - mainAttunement = Attunement.attunementArray[reader.ReadInt32()]; - secondaryAttunement = Attunement.attunementArray[reader.ReadInt32()]; + mainAttunement = AttunementSystem.FindOrNull(reader.ReadInt32()); + secondaryAttunement = AttunementSystem.FindOrNull(reader.ReadInt32()); } #endregion @@ -252,10 +253,21 @@ namespace CalamityMod.Items.Weapons.Melee public void SafeCheckAttunements() { if (mainAttunement != null) - mainAttunement = Attunement.attunementArray[(int)MathHelper.Clamp((float)mainAttunement.id, (float)AttunementID.Whirlwind, (float)AttunementID.Shockwave)]; + mainAttunement = AttunementSystem.FindOrNull(ClampAttunementRange((int)mainAttunement.id)); if (secondaryAttunement != null) - secondaryAttunement = Attunement.attunementArray[(int)MathHelper.Clamp((float)secondaryAttunement.id, (float)AttunementID.Whirlwind, (float)AttunementID.Shockwave)]; + secondaryAttunement = AttunementSystem.FindOrNull(ClampAttunementRange((int)secondaryAttunement.id)); + } + + private static int ClampAttunementRange(int input) + { + if (input < (int)AttunementID.Whirlwind) + return (int)AttunementID.Whirlwind; + + if (input > (int)AttunementID.Shockwave) + return (int)AttunementID.Shockwave; + + return input; } public override void HoldItem(Player player) diff --git a/Items/Weapons/Melee/StarburstShiv.cs b/Items/Weapons/Melee/StarburstShiv.cs index bc484097bc..333f89fb7d 100644 --- a/Items/Weapons/Melee/StarburstShiv.cs +++ b/Items/Weapons/Melee/StarburstShiv.cs @@ -1,5 +1,7 @@ using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Melee.Shortswords; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -13,8 +15,8 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetDefaults() { - Item.width = 44; - Item.height = 44; + Item.width = 74; + Item.height = 94; Item.noMelee = true; Item.noUseGraphic = true; Item.autoReuse = true; @@ -32,6 +34,8 @@ namespace CalamityMod.Items.Weapons.Melee public override bool MeleePrefix() => true; + public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) => Item.DrawItemGlowmaskSingleFrame(spriteBatch, rotation, ModContent.Request("CalamityMod/Items/Weapons/Melee/StarburstShivGlow").Value); + public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Melee/StarburstShiv.png b/Items/Weapons/Melee/StarburstShiv.png index c7c7aa1288..6fc05ab7e6 100644 Binary files a/Items/Weapons/Melee/StarburstShiv.png and b/Items/Weapons/Melee/StarburstShiv.png differ diff --git a/Items/Weapons/Melee/StarburstShivGlow.png b/Items/Weapons/Melee/StarburstShivGlow.png new file mode 100644 index 0000000000..007dc4ba4a Binary files /dev/null and b/Items/Weapons/Melee/StarburstShivGlow.png differ diff --git a/Items/Weapons/Melee/TrueBiomeBlade.cs b/Items/Weapons/Melee/TrueBiomeBlade.cs index 4903f3dba7..3fec69e72c 100644 --- a/Items/Weapons/Melee/TrueBiomeBlade.cs +++ b/Items/Weapons/Melee/TrueBiomeBlade.cs @@ -7,6 +7,7 @@ using CalamityMod.Items.BaseItems; using CalamityMod.Items.Materials; using CalamityMod.Particles; using CalamityMod.Projectiles.Melee; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -179,8 +180,8 @@ namespace CalamityMod.Items.Weapons.Melee int attunement1 = tag.GetInt("mainAttunement"); int attunement2 = tag.GetInt("secondaryAttunement"); - mainAttunement = Attunement.attunementArray[attunement1 != -1 ? attunement1 : Attunement.attunementArray.Length - 1]; - secondaryAttunement = Attunement.attunementArray[attunement2 != -1 ? attunement2 : Attunement.attunementArray.Length - 1]; + mainAttunement = AttunementSystem.FindOrNull(attunement1); + secondaryAttunement = AttunementSystem.FindOrNull(attunement2); if (mainAttunement == secondaryAttunement) secondaryAttunement = null; @@ -190,14 +191,14 @@ namespace CalamityMod.Items.Weapons.Melee public override void NetSend(BinaryWriter writer) { - writer.Write(mainAttunement != null ? (byte)mainAttunement.id : Attunement.attunementArray.Length - 1); - writer.Write(secondaryAttunement != null ? (byte)secondaryAttunement.id : Attunement.attunementArray.Length - 1); + writer.Write(mainAttunement != null ? (byte)mainAttunement.id : AttunementSystem.EmptyID); + writer.Write(secondaryAttunement != null ? (byte)secondaryAttunement.id : AttunementSystem.EmptyID); } public override void NetReceive(BinaryReader reader) { - mainAttunement = Attunement.attunementArray[reader.ReadInt32()]; - secondaryAttunement = Attunement.attunementArray[reader.ReadInt32()]; + mainAttunement = AttunementSystem.FindOrNull(reader.ReadInt32()); + secondaryAttunement = AttunementSystem.FindOrNull(reader.ReadInt32()); } #endregion @@ -213,10 +214,21 @@ namespace CalamityMod.Items.Weapons.Melee public void SafeCheckAttunements() { if (mainAttunement != null) - mainAttunement = Attunement.attunementArray[(int)MathHelper.Clamp((float)mainAttunement.id, (float)AttunementID.TrueDefault, (float)AttunementID.Holy)]; + mainAttunement = AttunementSystem.FindOrNull(ClampAttunementRange((int)mainAttunement.id)); if (secondaryAttunement != null) - secondaryAttunement = Attunement.attunementArray[(int)MathHelper.Clamp((float)secondaryAttunement.id, (float)AttunementID.TrueDefault, (float)AttunementID.Holy)]; + secondaryAttunement = AttunementSystem.FindOrNull(ClampAttunementRange((int)secondaryAttunement.id)); + } + + private static int ClampAttunementRange(int input) + { + if (input < (int)AttunementID.TrueDefault) + return (int)AttunementID.TrueDefault; + + if (input > (int)AttunementID.Marine) + return (int)AttunementID.Marine; + + return input; } public override void HoldItem(Player player) diff --git a/Items/Weapons/Ranged/ChromaticEruption.cs b/Items/Weapons/Ranged/ChromaticEruption.cs index e0184292d8..0e25bea27c 100644 --- a/Items/Weapons/Ranged/ChromaticEruption.cs +++ b/Items/Weapons/Ranged/ChromaticEruption.cs @@ -1,6 +1,7 @@ using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Ranged; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.DataStructures; using Terraria.ID; @@ -19,8 +20,8 @@ namespace CalamityMod.Items.Weapons.Ranged public override void SetDefaults() { - Item.width = 64; - Item.height = 34; + Item.width = 166; + Item.height = 60; Item.damage = 94; Item.DamageType = DamageClass.Ranged; Item.useAnimation = Item.useTime = 6; @@ -54,6 +55,8 @@ namespace CalamityMod.Items.Weapons.Ranged return false; } + public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) => Item.DrawItemGlowmaskSingleFrame(spriteBatch, rotation, ModContent.Request("CalamityMod/Items/Weapons/Ranged/ChromaticEruptionGlow").Value); + public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Ranged/ChromaticEruption.png b/Items/Weapons/Ranged/ChromaticEruption.png index d5748c9943..aba67996a9 100644 Binary files a/Items/Weapons/Ranged/ChromaticEruption.png and b/Items/Weapons/Ranged/ChromaticEruption.png differ diff --git a/Items/Weapons/Ranged/ChromaticEruptionGlow.png b/Items/Weapons/Ranged/ChromaticEruptionGlow.png new file mode 100644 index 0000000000..41eed8a1bb Binary files /dev/null and b/Items/Weapons/Ranged/ChromaticEruptionGlow.png differ diff --git a/Items/Weapons/Ranged/Leviatitan.cs b/Items/Weapons/Ranged/Leviatitan.cs index 2130046725..a640da1b1d 100644 --- a/Items/Weapons/Ranged/Leviatitan.cs +++ b/Items/Weapons/Ranged/Leviatitan.cs @@ -1,6 +1,11 @@ -using CalamityMod.Projectiles.Ranged; +using System; +using System.Diagnostics.Metrics; +using CalamityMod.Particles; +using CalamityMod.Projectiles.Ranged; +using Microsoft.Build.Tasks; using Microsoft.Xna.Framework; using Terraria; +using Terraria.Audio; using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; @@ -10,48 +15,108 @@ namespace CalamityMod.Items.Weapons.Ranged public class Leviatitan : ModItem, ILocalizedModType { public new string LocalizationCategory => "Items.Weapons.Ranged"; + // Every sixth shot fires homing Aberrations, then resets the counter to 2. + // This is intentional so you don't get the Aberrations instantly when you start firing and have to play around it. + private int shotCounter = 1; + public override void SetStaticDefaults() + { + ItemID.Sets.ItemsThatAllowRepeatedRightClick[Item.type] = true; + } + public override void SetDefaults() { Item.width = 82; Item.height = 28; - Item.damage = 77; + Item.damage = 121; Item.DamageType = DamageClass.Ranged; - Item.useTime = 10; - Item.useAnimation = 10; - Item.useStyle = ItemUseStyleID.Shoot; + Item.useTime = Item.useAnimation = 18; //Try not to change this if you can help it. Item.noMelee = true; Item.knockBack = 5f; Item.value = CalamityGlobalItem.RarityLimeBuyPrice; Item.rare = ItemRarityID.Lime; - Item.UseSound = SoundID.Item92; + Item.UseSound = new SoundStyle("CalamityMod/Sounds/Item/FlakKrakenShoot") { Pitch = 0.65f, Volume = 0.4f }; Item.autoReuse = true; Item.shoot = ModContent.ProjectileType(); - Item.shootSpeed = 12f; + Item.shootSpeed = 13f; + Item.useStyle = ItemUseStyleID.Shoot; Item.useAmmo = AmmoID.Bullet; Item.Calamity().canFirePointBlankShots = true; } - public override Vector2? HoldoutOffset() + public override Vector2? HoldoutOffset() => new Vector2(-10, 0); + + public override bool AltFunctionUse(Player player) { - return new Vector2(-15, 0); + return true; } + public override bool CanUseItem(Player player) + { + Item.UseSound = player.altFunctionUse == 2 ? SoundID.NPCHit56 : new SoundStyle("CalamityMod/Sounds/Item/FlakKrakenShoot") { Pitch = 0.65f, Volume = 0.3f }; + return base.CanUseItem(player); + } + public override float UseSpeedMultiplier(Player player) => player.altFunctionUse == 2 ? (1f / 3f) : 1f; public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - float SpeedX = velocity.X + Main.rand.Next(-10, 11) * 0.05f; - float SpeedY = velocity.Y + Main.rand.Next(-10, 11) * 0.05f; + // Reposition to the gun's tip. Calculated seperately due to the two different shot styles. + Vector2 boulderPos = position + new Vector2(74f, player.direction * (Math.Abs(velocity.SafeNormalize(Vector2.Zero).X) < 0.02f ? -2f : -8f)).RotatedBy(velocity.ToRotation()); + Vector2 shotPos = position + new Vector2(74f, player.direction * (Math.Abs(velocity.SafeNormalize(Vector2.Zero).X) < 0.02f ? -6f : 3f)).RotatedBy(velocity.ToRotation()); - if (type == ProjectileID.Bullet) + if (player.altFunctionUse == 2) { - if (Main.rand.NextBool(3)) - Projectile.NewProjectile(source, position.X, position.Y, SpeedX, SpeedY, ModContent.ProjectileType(), (int)(damage * 1.5), knockback, player.whoAmI); - else - Projectile.NewProjectile(source, position.X, position.Y, SpeedX, SpeedY, ModContent.ProjectileType(), damage, knockback, player.whoAmI); + int index = Projectile.NewProjectile(source, boulderPos, velocity * 0.7f, ModContent.ProjectileType(), (int)(damage * 2f), knockback, player.whoAmI); } else - Projectile.NewProjectile(source, position.X, position.Y, SpeedX, SpeedY, type, damage, knockback, player.whoAmI); - + { + Projectile.NewProjectile(source, shotPos, velocity, Item.shoot, damage, knockback, player.whoAmI); + } + if (shotCounter == 7) + { + SoundEngine.PlaySound(SoundID.Zombie38 with { Volume = SoundID.Zombie38.Volume * 0.5f }); + for (int i = 0; i <= 1; i++) + { + float projSpeed = Item.shootSpeed; + Projectile.NewProjectile(source, position + Main.rand.NextVector2Circular(150, 150), velocity * projSpeed, ModContent.ProjectileType(), (int)(damage * 1.3), knockback, player.whoAmI); + } + } + shotCounter++; + if (shotCounter > 7) + shotCounter = 2; return false; } + + //Thanks to Xyk's incredible recoil code, we give both left click and right click different recoils without having to use a holdout. + public override void UseStyle(Player player, Rectangle heldItemFrame) + { + player.ChangeDir(Math.Sign((player.Calamity().mouseWorld - player.Center).X)); + float itemRotation = player.compositeFrontArm.rotation + MathHelper.PiOver2 * player.gravDir; + + float pullback = 7f; + + float animProgress = 0.5f - player.itemTime / (float)player.itemTimeMax; + float rotation = (player.Center - player.Calamity().mouseWorld).ToRotation() * player.gravDir + MathHelper.PiOver2; + if (animProgress < 0.1f) + pullback -= (2.75f) * (float)Math.Pow((0.6f - animProgress) / 0.6f, 2); + + Vector2 itemPosition = player.MountedCenter + itemRotation.ToRotationVector2() * pullback; + Vector2 itemSize = new Vector2(52, 28); + Vector2 itemOrigin = new Vector2(-24, 4); + + CalamityUtils.CleanHoldStyle(player, itemRotation, itemPosition, itemSize, itemOrigin); + + base.UseStyle(player, heldItemFrame); + } + public override void UseItemFrame(Player player) + { + player.ChangeDir(Math.Sign((player.Calamity().mouseWorld - player.Center).X)); + + float animProgress = 0.5f - player.itemTime / (float)player.itemTimeMax; + float rotation = (player.Center - player.Calamity().mouseWorld).ToRotation() * player.gravDir + MathHelper.PiOver2; + if (animProgress < 0.4f) + rotation += (player.altFunctionUse == 2 ? -0.15f : 0) * (float)Math.Pow((0.6f - animProgress) / 0.6f, 2) * player.direction; + + player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, rotation); + } } } + diff --git a/Items/Weapons/Rogue/SamsaraSlicer.cs b/Items/Weapons/Rogue/SamsaraSlicer.cs index 1c35afd3bc..a6cb2e84ef 100644 --- a/Items/Weapons/Rogue/SamsaraSlicer.cs +++ b/Items/Weapons/Rogue/SamsaraSlicer.cs @@ -12,13 +12,13 @@ namespace CalamityMod.Items.Weapons.Rogue [LegacyName("TerraDisk")] public class SamsaraSlicer : RogueWeapon { - public static float Speed = 12f; + public static float Speed = 20f; public override void SetDefaults() { Item.width = 60; Item.height = 64; - Item.damage = 100; + Item.damage = 80; Item.knockBack = 4f; Item.useAnimation = Item.useTime = 30; Item.autoReuse = true; @@ -26,7 +26,7 @@ namespace CalamityMod.Items.Weapons.Rogue Item.noUseGraphic = true; Item.useStyle = ItemUseStyleID.Swing; - Item.UseSound = SoundID.Item1; + Item.UseSound = SoundID.DD2_GoblinBomberThrow; Item.value = CalamityGlobalItem.RarityYellowBuyPrice; Item.rare = ItemRarityID.Yellow; @@ -36,10 +36,12 @@ namespace CalamityMod.Items.Weapons.Rogue Item.shootSpeed = Speed; } - public override float StealthVelocityMultiplier => 0.75f; + public override float StealthVelocityMultiplier => 1.5f; public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { + if (player.ownedProjectileCounts[type] > 4) return false; + int proj = Projectile.NewProjectile(source, position, velocity, type, damage, knockback, player.whoAmI); if (player.Calamity().StealthStrikeAvailable() && proj.WithinBounds(Main.maxProjectiles)) { @@ -48,6 +50,12 @@ namespace CalamityMod.Items.Weapons.Rogue return false; } + public override bool CanUseItem(Player player) + { + if (player.ownedProjectileCounts[Item.shoot] > 4) return false; + return base.CanUseItem(player); + } + public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) { Item.DrawItemGlowmaskSingleFrame(spriteBatch, rotation, ModContent.Request("CalamityMod/Items/Weapons/Rogue/SamsaraSlicerGlow").Value); diff --git a/Items/Weapons/Summon/LegionofCelestia.cs b/Items/Weapons/Summon/LegionofCelestia.cs index 76e3f857a6..d0a6ef0c1e 100644 --- a/Items/Weapons/Summon/LegionofCelestia.cs +++ b/Items/Weapons/Summon/LegionofCelestia.cs @@ -1,6 +1,7 @@ using CalamityMod.Items.Materials; using CalamityMod.Projectiles.Summon; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.DataStructures; using Terraria.ID; @@ -14,8 +15,8 @@ namespace CalamityMod.Items.Weapons.Summon public new string LocalizationCategory => "Items.Weapons.Summon"; public override void SetDefaults() { - Item.width = 36; - Item.height = 36; + Item.width = 100; + Item.height = 128; Item.damage = 57; Item.DamageType = DamageClass.Summon; Item.mana = 10; @@ -31,6 +32,11 @@ namespace CalamityMod.Items.Weapons.Summon Item.shootSpeed = 10f; } + public override void UseStyle(Player player, Rectangle heldItemFrame) + { + player.itemLocation += new Vector2(-20f * player.direction, 34f * player.gravDir).RotatedBy(player.itemRotation); + } + public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { if (player.altFunctionUse != 2) @@ -45,6 +51,8 @@ namespace CalamityMod.Items.Weapons.Summon return false; } + public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) => Item.DrawItemGlowmaskSingleFrame(spriteBatch, rotation, ModContent.Request("CalamityMod/Items/Weapons/Summon/LegionofCelestiaGlow").Value); + public override void AddRecipes() { CreateRecipe(). diff --git a/Items/Weapons/Summon/LegionofCelestia.png b/Items/Weapons/Summon/LegionofCelestia.png index 06ae7fb2e6..db5fd93c4a 100644 Binary files a/Items/Weapons/Summon/LegionofCelestia.png and b/Items/Weapons/Summon/LegionofCelestia.png differ diff --git a/Items/Weapons/Summon/LegionofCelestiaGlow.png b/Items/Weapons/Summon/LegionofCelestiaGlow.png new file mode 100644 index 0000000000..ce16e6cd0b Binary files /dev/null and b/Items/Weapons/Summon/LegionofCelestiaGlow.png differ diff --git a/Localization/en-US/Mods.CalamityMod.Bestiary.Vanilla.hjson b/Localization/en-US/Mods.CalamityMod.Bestiary.Vanilla.hjson new file mode 100644 index 0000000000..48147b2f72 --- /dev/null +++ b/Localization/en-US/Mods.CalamityMod.Bestiary.Vanilla.hjson @@ -0,0 +1,102 @@ +// Put their internal name here +NPCName: { + Dryad: Dryads practice the art of Life Magic, pioneered by Silva. She is connected with nature and can analyze its purity worldwide. She sells seeds, too! + Mechanic: The Mechanic was imprisoned for sticking her nose where she shouldn't. She sells wiring and tools for putting together anything imaginable. + EmpressButterfly: These familiars conjured by the Empress draw power from their surroundings and later bring it to their master. They remind her of a lost loved one, and should one perish in the chaos of night, she shall unleash her full fury upon the attacker. + DemonEye: "{$CommonEntries.DemonEye}" + CataractEye: "{$CommonEntries.DemonEye}" + DialatedEye: "{$CommonEntries.DemonEye}" + SleepyEye: "{$CommonEntries.DemonEye}" + GreenEye: "{$CommonEntries.DemonEye}" + PurpleEye: "{$CommonEntries.DemonEye}" + Wraith: Souls belonging to devotees of gods were once sealed inside the Wall of Flesh. Now, they roam the night in search of vengeance. + BloodNautilus: The intense red glow of the Blood Moon becomes even greater in contact with water, making aquatic creatures affected more strongly than their land counterparts. This enormous shelled water demon directly feeds off that energy, responding brutally to being pestered. + DiggerHead: Exposure to the effects of godly magicks flowing throughout the cracks of the world causes unusual rapid growths in giant worms. + GraniteGolem: These strong magicked constructs were utilized in mines for carrying heavy ores and machinery. They continue to inhabit the mines deep below, even after their abandonment. + GreekSkeleton: Marble caves were used as arenas during the Deific Era. Fighters looking for glory flocked to them, but now only their bodies populate the area. + UndeadViking: After the Crusade left the continent in shambles, many factions attempted to conquer it. These vikings were one such group, but the icy winds of the tundra made short work of them. + IcyMerman: Mermen rarely stray far from the ocean, favoring the vast waters where their revered Elemental now lives in. Those that do can become lost, wander into cold caverns, and become icy undead fish men. + DesertBeast: Minor draconic offshoots who thrive in arid climates, the Basilisk's hardened bodies make them formidable threats. + DuneSplicerHead: The largest worm native to the Desert. Even strengthened by divine magicks, they fall short of the Scourge, and run amok in a hunger-induced frenzy. + SandShark: "{$CommonEntries.SandShark}" + SandsharkCorrupt: "{$CommonEntries.SandShark}" + SandsharkCrimson: "{$CommonEntries.SandShark}" + SandsharkHallow: "{$CommonEntries.SandShark}" + MeteorHead: When meteorites strike the surface, their fragments lay scattered for the taking. Some pieces have a higher mana density, coming to life and attacking anything nearby. + AngryBones: "{$CommonEntries.AngryBones}" + AngryBonesBig: "{$CommonEntries.AngryBones}" + AngryBonesBigMuscle: "{$CommonEntries.AngryBones}" + AngryBonesBigHelmet: "{$CommonEntries.AngryBones}" + BlueArmoredBones: "{$CommonEntries.BlueArmoredBones}" + BlueArmoredBonesMace: "{$CommonEntries.BlueArmoredBones}" + BlueArmoredBonesNoPants: "{$CommonEntries.BlueArmoredBones}" + BlueArmoredBonesSword: "{$CommonEntries.BlueArmoredBones}" + HellArmoredBones: "{$CommonEntries.HellArmoredBones}" + HellArmoredBonesSpikeShield: "{$CommonEntries.HellArmoredBones}" + HellArmoredBonesMace: "{$CommonEntries.HellArmoredBones}" + HellArmoredBonesSword: "{$CommonEntries.HellArmoredBones}" + RustyArmoredBonesAxe: "{$CommonEntries.RustyArmoredBones}" + RustyArmoredBonesFlail: "{$CommonEntries.RustyArmoredBones}" + RustyArmoredBonesSword: "{$CommonEntries.RustyArmoredBones}" + RustyArmoredBonesSwordNoArmor: "{$CommonEntries.RustyArmoredBones}" + SkeletonSniper: Part of Yharim's military force in their past lives, these eagle-eyed sharpshooters let nothing escape their crosshairs, even when their place of operation were these cramped halls. + TacticalSkeleton: Part of Yharim's military force in their past lives, with thick armor and mighty boomsticks, they were the frontline against the invader that massacred the guards in these halls. + SkeletonCommando: Part of Yharim's military force in their past lives, their rocket-powered rage could wipe out entire crowds of escapees had they ever once dared to step out of their cells. + BoneLee: This Onyx Kinsman was apprehended by Yharim's troops, and after countless failed escape attempts, used as an example to other prisoners. + Paladin: Several Godseeker Knights were assigned to guard the Dungeon, yet not even they could fight against, much less see, their killer. Word of the massacre that happened in these halls never got out, the wails of the dead forever silenced. + DiabolistRed: "{$CommonEntries.Diabolist}" + DiabolistWhite: "{$CommonEntries.Diabolist}" + Necromancer: "{$CommonEntries.Necromancer}" + NecromancerArmored: "{$CommonEntries.Necromancer}" + RaggedCaster: "{$CommonEntries.RaggedCaster}" + RaggedCasterOpenCoat: "{$CommonEntries.RaggedCaster}" + DungeonGuardian: The Old Man is cursed to never leave nor enter the Dungeon, much less die. Whoever crosses paths with him and dares to descend into those halls shall not pass! + BoneSerpentHead: Mighty serpents once ruled hell, but long ago shed their obsidian scales and became naught but skeletal husks. Subdued by Demons with stolen Azafurian spells, they now protect the demonic territory fiercely. + Demon: Despite being a primitive civilization, demons populate most of the underworld. Unlike their lesser brothers, they cast shadow magic rather than hell magic. + VoodooDemon: Demons have several religious practices, specially sacrifices. They worship the Wall of Flesh ever since it started roaming the underworld, using offerings to draw it closer. + RedDevil: Conjuring potent spears of dark magic, these elite demons look after the adventurer that destroyed their perceived deity. + WyvernHead: Deeply in tune with the magic of the world, these serpentine dragons guard the skyward ruins of Chrysadia on behalf of the Storm Dragon. Now, their duty calls louder as divine essence surges through the land. + Harpy: Winged, demi-human creatures from distant southward mountains who came to inhabit Chrysadia after its tragic downfall. They defend their new territory fiercely against invaders with their razor-sharp feathers. + MartianProbe: Sensing growing power on the planet, otherworldly beings send space-age technology to scan for valuable resources. + SeekerHead: Godly magicks have unleashed the dark influences that gave birth to the Eater of Worlds, producing smaller, but just as deadly worms. + DesertDjinn: Buried in these caves lie cryptic artifacts older than Ilmeris, their origins swept away by the sands of time. Corrupted by divine magicks, the once friendly djinns within them now reemerge, full of hostility. + ChaosElemental: Manifestations of the unstable Essence of the Hallow, they erratically make chase with an uncontrollable surge of luminous power. + GoblinThief: Thieves forcefully conscripted in the Goblin Army in exchange for freedom, these pesky foes specialize in nimble movement and close-quarters combat. + GoblinSummoner: Goblins that reach such a mastery over the arcane are treated like royalty, prize jewels of their society. Warlocks in particular conjure unfathomable shadowflame ghasts through a powerful hex. + GoblinSorcerer: Goblins struggle to manipulate magic, only scantily capable of conjuring the simplest of spells. Those that can have the potential for manipulating magicked shadow energy through a form of hexing. + PirateCaptain: A pirate captain's love for riches is only rivaled by his desire to explore! Word that the Crusade had seemingly ended spread fast across the world, and abundances to plunder in this continent attracted this sea dweller and his motley crew. + MartianSaucerCore: Following the destruction of their planet by otherworldly creatures, the Martians' military evolved at an unprecedented rate. They were prepared to fight back any future threats, and also pillage any other worlds they could find. + TorchGod: An unknown entity responsible for a torch's eternal flicker, however easily angered by the unsightly, ungrateful abuse of torch placement. + EyeofCthulhu: A gargantuan monster of unknown origins, responsible for plaguing the night with Demon Eyes. It was given the title of "Cthulhu", which means "Great Beast" in the language of dragons. + BrainofCthulhu: The death of a god often birthed great monsters due to the volatile nature of godly essence. The culling of such abominations used to be cause for songs and festivities, but now, they only give birth to disappointments. + SkeletronHead: A demonic construct that bursts out of the Old Man when necessary and the most dangerous part of the curse laid by the Dragon Cult. They hoped to stop all intruders with it, but one was too cunning even for them. + WallofFlesh: Originally created by Azafurian mages as a gambit to seal away godly essence, the towering wall broke free after the city's destruction. Its existence was problematic, but its demise has ushered even greater instability upon the world. + QueenSlimeBoss: After fleeing the initial battle, the Slime God attempted to rebuild its Paladins with the emerged energy of the Hallow. However, it was ensnared by its own creation, unable to control the vast and unstable power of it. + Retinazer: A pair of mechanical eyes built by Draedon for reconnaissance and assassination, Retinazer focuses its energy into firing powerful lasers. + Spazmatism: A pair of mechanical eyes built by Draedon for reconnaissance and assassination, Spazmatism chases at high speed, exhaling cursed flames. + TheDestroyer: Despite being made with repurposed mining equipment, the Destroyer was built for fighting other deities in single combat, decorated in laser-armed probes, which detach from its body when damaged. + SkeletronPrime: Built with the express purpose of inciting fear into the hearts of any god worshiper, this machine has more arms than ever before, and a variety of fierce weapons. + Plantera: A creation of the Vernal Pass meant to replace Braelor in his absence. They harnessed dead animal souls to give it life, but the span of such magic was far larger than anticipated. It didn't take long for the Plantera to grow out of control and slaughter its masters. + HallowBoss: Despite their parentage, children of gods do not inherit a shred of their power. The Empress chose to claim power for herself by siphoning it from other places and beings. She found a perfect candidate in the Hallow due to its unstable nature, and is now transformed into a mighty fae. + Golem: A remarkable display of ingenuity constructed by the Lihzahrd race. Seeking light after they hid away in their temple out of shame for driving their goddess away, they built this construct. Powered by solar energy cells, it is ready to guard the Temple. + DukeFishron: An aquatic-evolved species which lives in isolation in the depths of the ocean. Despite their shortcomings, they still share blood with the dragons of old, claiming near complete dominion over the oceans. Legends claim it only surfaces in search of a rare, savory type of worm. + CultistBoss: The fanatical leader of the Dragon Cult, hell-bent on resurrecting a dragon. He upholds their sacred duty of keeping the cosmic behemoth sealed far away on the moon, an oath he swore to long ago when he pledged himself in their service. + CultistDevote: Utterly devoted, Lunatic Devotees are so paranoid over the prospect of their ritual failing that they stay unflinching even when threatened with death. Fear only makes them work harder. + LunarTowerNebula: The second pillar, created to spawn beings from beyond that filled the Minds of all with gloom. These troops specialized in disabling the enemy's intelligence, ensuring no countermeasures could be planned against the dominator. + LunarTowerSolar: The fourth and last pillar, created as Sunlight bled and marked doom. A miniscule shard of its power was used to make it, and yet its spawns accompanied the dominator directly in his conquest against the dragons. + LunarTowerVortex: The first pillar, created as black Storm clouds on the horizon loomed. While the dominator fought the mightiest of dragons, the spawns of this pillar focused on exterminating any mundane life they could find, appearing in seemingly infinite droves. + LunarTowerStardust: The third Pillar, created as Life rose to fight, but was given no room. Its spawns found particular utility in searching and picking off stronger beings that could pose a threat to the creatures of the Vortex. + MoonLordCore: The cosmic behemoth that brought Terraria to its knees 800 years ago, freed from its lunar prison in a weakened state. It had the power to siphon and dominate souls, including those possessed by dragons, permanently wounding them. It hails from an incomprehensible fissure of broken spacetime which leeches energy from our dimension to sustain itself. +} + +CommonEntries: { + DemonEye: That suspicious feeling of being watched may very well come true in the dark of night, when the Eye of Cthulhu's minions roam the skies. + SandShark: Sand Sharks lived in the shallow waters of Ilmeris, hiding beneath the sand. They were thankfully well equipped to deal with the fallout of the Incineration. + AngryBones: Cursed with undeath, the former prisoners of the Dungeon roam endlessly through its halls, seeking a victim for their unending fury. + BlueArmoredBones: Mercenaries hired by Yharim to guard the Dungeon, the Marching Bones were disciplined and relentless, sundering any escapees that decided to rise against their jailors. + HellArmoredBones: Mercenaries hired by Yharim to guard the Dungeon hailing from Azafure, the fiery glow of the Molten Legion is unmistakable. If anyone ever tried to hide, their red-hot armaments would melt the hideout immediately. + RustyArmoredBones: Mercenaries hired by Yharim to guard the Dungeon hailing from Underground factions, the Rusted Company's weapons are jagged and rough through use and neglect. The brutality they employed on the field was enough to make many prisoners give up on freedom. + Diabolist: Mages of Azafure who bear the Diabolic Sigil, wielding flames as intense as any in the underworld. They were effective at blocking passageways and at making prisoners talk. + Necromancer: These sorcerers were trained in Azafure and bore the Necromantic Sign. Much like they terrorized prisoners with the bodies of their friends, so do they terrorize the Dungeon now. + RaggedCaster: Casters directly from the Dragon Cult, their cursed magic leaves their victims helplessly lost in utter darkness. They perished attempting to contain the onslaught that happened beneath their halls. +} diff --git a/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson b/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson index 099b559c1d..b3fe045eb6 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson @@ -1648,7 +1648,7 @@ StatisVoidSash: { Tooltip: ''' 32% increased jump speed, allows auto-jump, and negates fall damage - Can climb walls, dash, and dodge attacks + Can swim, climb walls, dash, and dodge attacks ''' HoldShiftTooltip: ''' diff --git a/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson b/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson index 6249501795..4e77a31e8b 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson @@ -1691,6 +1691,11 @@ CosmiliteWorkBench: { Tooltip: "" } +AncientSmoothNavystone: { + DisplayName: Ancient Smooth Navystone + Tooltip: "" +} + EutrophicBathtub: { DisplayName: Eutrophic Bathtub Tooltip: "" @@ -3320,6 +3325,11 @@ SpineSapling: { Tooltip: Plants Giant Spine saplings on Brimstone Slag } +Stohne: { + DisplayName: Stohne + Tooltip: "" +} + SulphurousSand: { DisplayName: Sulphurous Sand Tooltip: "" diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Melee.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Melee.hjson index 7982818210..82f66b9f90 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Melee.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Melee.hjson @@ -331,7 +331,9 @@ DeathsAscension: { DisplayName: Death's Ascension Tooltip: ''' + Performs powerful soul-infused swings that creates a rift orbited by scythes on enemy hits Press to launch a barrage of homing scythes + The rift will fire scythes along with you 'It feels just right in your grip... [c/660066:But the hands that wield it are not yours'] ''' diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson index b11bd92b13..5391564821 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Ranged.hjson @@ -682,7 +682,13 @@ Kingsbane: { Leviatitan: { DisplayName: Leviatitan - Tooltip: Converts musket balls into toxic and normal water blasts + Tooltip: + ''' + Fires high velocity aqua blasts + Releases homing aberrations that shred enemy defense every six shots + to vomit a meteor that explodes on hit + 'The L in LMG stands for Leviathan' + ''' } LunarianBow: { diff --git a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson index 39b4651db3..74798b1f01 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Weapons.Rogue.hjson @@ -958,7 +958,7 @@ ScarletDevil: { DisplayName: Scarlet Devil Tooltip: ''' - Throws an ultra high velocity spear, which creates more projectiles that home in + Throws an ultra high velocity spear, which leaves a trail of homing bullets The spear creates a Scarlet Blast upon hitting an enemy Stealth strikes grant you lifesteal and summon a star of projectiles upon hitting an enemy 'Divine Spear "Spear the Gungnir"' diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson index 6a9cfd8994..39ef575b2d 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Melee.hjson @@ -80,6 +80,7 @@ DarklightGreatswordSlashCreator.DisplayName: Darklight Greatsword Slash Creator DarkMasterBeam.DisplayName: Dark Master Beam DarkMasterClone.DisplayName: Dark Terrarian DeathsAscensionProjectile.DisplayName: Ascended Scythe +DeathsAscensionRift.DisplayName: Rift DecaysRetort.DisplayName: Decay's Retort DecaysRetortDash.DisplayName: Evisceration Lunge DemonBlast.DisplayName: Devil Fork @@ -115,6 +116,7 @@ ExobeamSlashCreator.DisplayName: Anime Sword Effect Exoboom.DisplayName: Exoplasma Explosion ExtantAbhorrence.DisplayName: Extant Abhorrence FallenBlast.DisplayName: Fallen Paladin's Wrath +FallenExplosionSmall.DisplayName: Fallen Hammer Blast FallenPaladinsHammerEcho.DisplayName: Fallen Paladin's Hammer Echo FallenPaladinsHammerProj.DisplayName: Fallen Paladin's Hammer Feather.DisplayName: Feather @@ -303,4 +305,3 @@ WulfrumScrew.DisplayName: Wulfrum Screw WulfrumScrewdriverProj.DisplayName: Wulfrum Screwdriver YinYoDark.DisplayName: Dark Shard YinYoLight.DisplayName: Light Shard -FallenExplosionSmall.DisplayName: Fallen Hammer Blast diff --git a/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson b/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson index 11209f6fc1..42979baa91 100644 --- a/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson +++ b/Localization/en-US/Mods.CalamityMod.Projectiles.Ranged.hjson @@ -252,3 +252,6 @@ HellbornProj.DisplayName: Hell-born Gunblast HellbornShell.DisplayName: Hell's Shell RubicoPrimeMag.DisplayName: Rubico Prime Mag MegalodonShot.DisplayName: Megalodon Shot +LeviatitanAberration.DisplayName: Leviatitan Aberration +LeviatitanMeteor.DisplayName: Leviatitan Meteor +LeviatitanExplosion.DisplayName: Leviatitan Explosion diff --git a/Localization/en-US/Mods.CalamityMod.Status.Death.hjson b/Localization/en-US/Mods.CalamityMod.Status.Death.hjson index f6dc2c8748..b8dd397c36 100644 --- a/Localization/en-US/Mods.CalamityMod.Status.Death.hjson +++ b/Localization/en-US/Mods.CalamityMod.Status.Death.hjson @@ -48,7 +48,7 @@ ChaliceOfTheBloodGodUnequip: "{0} violated their pact with the Blood God." ChibiiDoggo: "{0} couldn't stand the sharp objects." CirrusSlap1: "{0} was slapped too hard." CirrusSlap2: "{0} forked around and found out." -CorpusAvertor: "{0} became the blood god's sacrifice." +CorpusAvertor: "{0} became the Blood God's sacrifice." CrushDepth1: "{0} was crushed by the pressure." CrushDepth2: "{0}'s lungs collapsed." CrushDepth3: "{0}'s bones crunched under the deep pressure." diff --git a/ModSupport/ExternalMods.cs b/ModSupport/ExternalMods.cs new file mode 100644 index 0000000000..7518e201c1 --- /dev/null +++ b/ModSupport/ExternalMods.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod +{ + public sealed class ExternalMods : ModSystem + { + // This is Calamity's official music mod, CalamityModMusic. It is now a hard dependency. + internal static Mod musicMod = null; + internal static bool MusicAvailable => musicMod is not null; + + // This is Vanilla Calamity Mod Music, internally named UnCalamityModMusic. + // VCMM is an official music add-on. Unlike the main music mod, it is not a dependency. + internal static Mod vcmm = null; + internal static bool VCMMAvailable => vcmm is not null; + + // Please keep this in alphabetical order so it's easy to read + internal static Mod ancientsAwakened = null; + internal static Mod biomeLava = null; + internal static Mod bossChecklist = null; + internal static Mod coloredDamageTypes = null; + internal static Mod crouchMod = null; + internal static Mod dialogueTweak = null; + internal static Mod fargos = null; + internal static Mod luminance = null; + internal static Mod magicStorage = null; + internal static Mod overhaul = null; + internal static Mod redemption = null; + internal static Mod soa = null; + internal static Mod subworldLibrary = null; + internal static Mod summonersAssociation = null; + internal static Mod thorium = null; + internal static Mod varia = null; + internal static Mod wikithis = null; + + public override void Load() + { + musicMod = null; + ModLoader.TryGetMod("CalamityModMusic", out musicMod); + vcmm = null; + ModLoader.TryGetMod("UnCalamityModMusic", out vcmm); + + ancientsAwakened = null; + ModLoader.TryGetMod("AAMod", out ancientsAwakened); + biomeLava = null; + ModLoader.TryGetMod("BiomeLava", out biomeLava); + bossChecklist = null; + ModLoader.TryGetMod("BossChecklist", out bossChecklist); + coloredDamageTypes = null; + ModLoader.TryGetMod("ColoredDamageTypes", out coloredDamageTypes); + crouchMod = null; + ModLoader.TryGetMod("CrouchMod", out crouchMod); + dialogueTweak = null; + ModLoader.TryGetMod("DialogueTweak", out dialogueTweak); + fargos = null; + ModLoader.TryGetMod("Fargowiltas", out fargos); + luminance = null; + ModLoader.TryGetMod("Luminance", out luminance); + magicStorage = null; + ModLoader.TryGetMod("MagicStorage", out magicStorage); + overhaul = null; + ModLoader.TryGetMod("TerrariaOverhaul", out overhaul); + redemption = null; + 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); + wikithis = null; + ModLoader.TryGetMod("Wikithis", out wikithis); + } + + public override void Unload() + { + musicMod = null; + vcmm = null; + + ancientsAwakened = null; + biomeLava = null; + bossChecklist = null; + coloredDamageTypes = null; + crouchMod = null; + dialogueTweak = null; + fargos = null; + luminance = null; + magicStorage = null; + overhaul = null; + redemption = null; + soa = null; + subworldLibrary = null; + summonersAssociation = null; + thorium = null; + varia = null; + wikithis = null; + } + } +} diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs index 4ced41b143..d154133dee 100644 --- a/ModSupport/ModCalls.cs +++ b/ModSupport/ModCalls.cs @@ -719,9 +719,9 @@ namespace CalamityMod // Sets the damage reduction for an NPC type public static float SetDamageReduction(int npcID, float dr) { - CalamityMod.DRValues.TryGetValue(npcID, out float oldDR); - CalamityMod.DRValues.Remove(npcID); - CalamityMod.DRValues.Add(npcID, dr); + CalamityGlobalNPC.DRValues.TryGetValue(npcID, out float oldDR); + CalamityGlobalNPC.DRValues.Remove(npcID); + CalamityGlobalNPC.DRValues.Add(npcID, dr); return oldDR; } // Sets a specific NPC's damage reduction diff --git a/ModSupport/WeakReferenceSupport.cs b/ModSupport/WeakReferenceSupport.cs index 09ef96dcb9..7d171a83df 100644 --- a/ModSupport/WeakReferenceSupport.cs +++ b/ModSupport/WeakReferenceSupport.cs @@ -118,7 +118,7 @@ namespace CalamityMod public static readonly Func DownedBossRush = () => DownedBossSystem.downedBossRush; } - internal class WeakReferenceSupport + internal class WeakReferenceSupport : ModSystem { public const string CalamityWikiURLOld = "calamitymod.wiki.gg"; public const string CalamityWikiURL = "https://calamitymod.wiki.gg/wiki/{}"; @@ -188,28 +188,27 @@ namespace CalamityMod // { "Xeroc", 26f }, }; - public static void Setup() + public override void PostSetupContent() { + LavaStyleToBiomeLava(); BossChecklistSupport(); FargosSupport(); DialogueTweakSupport(); SummonersAssociationSupport(); ColoredDamageTypesSupport(); LuminanceSupport(); - // done here to assure that all other mods have already loaded so that Calamity can automatically grab any of these types they may have + if (!Main.dedServ) { - GeneralParticleHandler.LoadModParticleInstances(); - CooldownRegistry.RegisterModCooldowns(); - PopupGUIManager.LoadGUIs(); + WikiThisSupport(); } } #region BiomeLava - public static void LavaStytleToBiomeLava() + private static void LavaStyleToBiomeLava() { CalamityMod calamity = GetInstance(); - Mod biomelava = calamity.biomeLava; + Mod biomelava = ExternalMods.biomeLava; if (biomelava == null) return; @@ -255,14 +254,14 @@ namespace CalamityMod #region WikiThis // This is a separate function because it only runs clientside - public static void WikiThisSupport() + private static void WikiThisSupport() { // Wikithis is a clientside mod if (Main.netMode == NetmodeID.Server) return; CalamityMod calamity = GetInstance(); - Mod wiki = calamity.wikithis; + Mod wiki = ExternalMods.wikithis; if (wiki is null) return; @@ -350,15 +349,15 @@ namespace CalamityMod // Wrapper function to detect if a subworld is in use for Subworld Library. internal static bool InAnySubworld() { - if (CalamityMod.Instance.subworldLibrary is null) + if (ExternalMods.subworldLibrary is null) return false; foreach (Mod mod in ModLoader.Mods) { - if (mod.Name.Equals(CalamityMod.Instance.subworldLibrary.Name)) + if (mod.Name.Equals(ExternalMods.subworldLibrary.Name)) continue; - bool anySubworldForMod = (CalamityMod.Instance.subworldLibrary.Call("AnyActive", mod) as bool?) ?? false; + bool anySubworldForMod = (ExternalMods.subworldLibrary.Call("AnyActive", mod) as bool?) ?? false; if (anySubworldForMod) return true; } @@ -386,8 +385,8 @@ namespace CalamityMod private static void BossChecklistSupport() { - CalamityMod calamity = GetInstance(); - Mod bossChecklist = calamity.bossChecklist; + CalamityMod calamity = CalamityMod.Instance; + Mod bossChecklist = ExternalMods.bossChecklist; if (bossChecklist is null) return; @@ -1111,7 +1110,7 @@ namespace CalamityMod #region Fargo's Mutant Mod private static void FargosSupport() { - Mod fargos = GetInstance().fargos; + Mod fargos = ExternalMods.fargos; if (fargos is null) return; @@ -1141,7 +1140,7 @@ namespace CalamityMod #region Dialogue Tweaks private static void DialogueTweakSupport() { - Mod dialogueMod = GetInstance().dialogueTweak; + Mod dialogueMod = ExternalMods.dialogueTweak; if (dialogueMod != null) { dialogueMod.Call("ReplaceShopButtonIcon", NPCType(), "Head"); @@ -1152,7 +1151,7 @@ namespace CalamityMod #region Summoner's Association private static void SummonersAssociationSupport() { - Mod sAssociation = GetInstance().summonersAssociation; + Mod sAssociation = ExternalMods.summonersAssociation; if (sAssociation is null) return; @@ -1292,9 +1291,9 @@ namespace CalamityMod private static Color StealthDamageColor = new(185, 105, 250); private static Color StealthCritColor = new(144, 33, 235); - public static void ColoredDamageTypesSupport() + private static void ColoredDamageTypesSupport() { - Mod coloredDamageTypes = GetInstance().coloredDamageTypes; + Mod coloredDamageTypes = ExternalMods.coloredDamageTypes; if (coloredDamageTypes is null) return; @@ -1319,9 +1318,9 @@ namespace CalamityMod private static void RegisterWorldInfoIcon(Mod luminance, string texturePath, string hoverTextKey, Func shouldAppear, byte priority) => luminance.Call("RegisterWorldInfoIcon", texturePath, hoverTextKey, shouldAppear, priority); - public static void LuminanceSupport() + private static void LuminanceSupport() { - Mod luminance = GetInstance().luminance; + Mod luminance = ExternalMods.luminance; if (luminance is null) return; diff --git a/NPCs/Abyss/EidolonWyrmHead.cs b/NPCs/Abyss/EidolonWyrmHead.cs index 87e85a233e..2f16beb288 100644 --- a/NPCs/Abyss/EidolonWyrmHead.cs +++ b/NPCs/Abyss/EidolonWyrmHead.cs @@ -41,7 +41,6 @@ namespace CalamityMod.NPCs.Abyss { NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/EidolonWyrm_Bestiary", PortraitPositionXOverride = 40 }; value.Position.X += 40; @@ -419,8 +418,19 @@ namespace CalamityMod.NPCs.Abyss return null; } + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + if (NPC.IsABestiaryIconDummy) + { + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 2, 26, 0.6f, new Vector2(70, 30), 2, 20); + } + return true; + } + public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { + if (NPC.IsABestiaryIconDummy) + return; SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) { diff --git a/NPCs/Abyss/GulperEelBody.cs b/NPCs/Abyss/GulperEelBody.cs index 29a0c69184..f5b5530c64 100644 --- a/NPCs/Abyss/GulperEelBody.cs +++ b/NPCs/Abyss/GulperEelBody.cs @@ -133,9 +133,9 @@ namespace CalamityMod.NPCs.Abyss NPC.position.Y = NPC.position.Y + targetYDirection; if (targetXDirection < 0f) - NPC.spriteDirection = 1; - else if (targetXDirection > 0f) NPC.spriteDirection = -1; + else if (targetXDirection > 0f) + NPC.spriteDirection = 1; } } diff --git a/NPCs/Abyss/GulperEelBody.png b/NPCs/Abyss/GulperEelBody.png index fb79dc639f..5d16178519 100644 Binary files a/NPCs/Abyss/GulperEelBody.png and b/NPCs/Abyss/GulperEelBody.png differ diff --git a/NPCs/Abyss/GulperEelBodyAlt.cs b/NPCs/Abyss/GulperEelBodyAlt.cs index db6035b539..83b1c8f2ea 100644 --- a/NPCs/Abyss/GulperEelBodyAlt.cs +++ b/NPCs/Abyss/GulperEelBodyAlt.cs @@ -133,9 +133,9 @@ namespace CalamityMod.NPCs.Abyss NPC.position.Y = NPC.position.Y + targetYDirection; if (targetXDirection < 0f) - NPC.spriteDirection = 1; - else if (targetXDirection > 0f) NPC.spriteDirection = -1; + else if (targetXDirection > 0f) + NPC.spriteDirection = 1; } } diff --git a/NPCs/Abyss/GulperEelBodyAlt.png b/NPCs/Abyss/GulperEelBodyAlt.png index b913ecfe72..f7788755bc 100644 Binary files a/NPCs/Abyss/GulperEelBodyAlt.png and b/NPCs/Abyss/GulperEelBodyAlt.png differ diff --git a/NPCs/Abyss/GulperEelBodyAltGlow.png b/NPCs/Abyss/GulperEelBodyAltGlow.png index 363279be79..f12ca35945 100644 Binary files a/NPCs/Abyss/GulperEelBodyAltGlow.png and b/NPCs/Abyss/GulperEelBodyAltGlow.png differ diff --git a/NPCs/Abyss/GulperEelBodyGlow.png b/NPCs/Abyss/GulperEelBodyGlow.png index bd7324a232..2fb2ddd0c8 100644 Binary files a/NPCs/Abyss/GulperEelBodyGlow.png and b/NPCs/Abyss/GulperEelBodyGlow.png differ diff --git a/NPCs/Abyss/GulperEelHead.cs b/NPCs/Abyss/GulperEelHead.cs index 161506e481..2834778fd2 100644 --- a/NPCs/Abyss/GulperEelHead.cs +++ b/NPCs/Abyss/GulperEelHead.cs @@ -33,7 +33,6 @@ namespace CalamityMod.NPCs.Abyss NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { Scale = 0.75f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/GulperEel_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 20 }; @@ -157,9 +156,9 @@ namespace CalamityMod.NPCs.Abyss } if (NPC.velocity.X < 0f) - NPC.spriteDirection = 1; - else if (NPC.velocity.X > 0f) NPC.spriteDirection = -1; + else if (NPC.velocity.X > 0f) + NPC.spriteDirection = 1; if (Main.player[NPC.target].dead) NPC.TargetClosest(false); @@ -339,8 +338,20 @@ namespace CalamityMod.NPCs.Abyss return null; } + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + if (NPC.IsABestiaryIconDummy) + { + Texture2D mainBody = TextureAssets.Npc[ModContent.NPCType()].Value; + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, [TextureAssets.Npc[ModContent.NPCType()].Value, mainBody, mainBody], 3, 26, 0.3f, new Vector2(0, 20), 3, 10, 0, 0.1f); + } + return true; + } + public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { + if (NPC.IsABestiaryIconDummy) + return; SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) { diff --git a/NPCs/Abyss/GulperEelHead.png b/NPCs/Abyss/GulperEelHead.png index b840a7904d..9b4a5926eb 100644 Binary files a/NPCs/Abyss/GulperEelHead.png and b/NPCs/Abyss/GulperEelHead.png differ diff --git a/NPCs/Abyss/GulperEelHeadGlow.png b/NPCs/Abyss/GulperEelHeadGlow.png index f7d7b57f39..bd708820e2 100644 Binary files a/NPCs/Abyss/GulperEelHeadGlow.png and b/NPCs/Abyss/GulperEelHeadGlow.png differ diff --git a/NPCs/Abyss/GulperEelTail.cs b/NPCs/Abyss/GulperEelTail.cs index e06996e52c..b19d2c37e4 100644 --- a/NPCs/Abyss/GulperEelTail.cs +++ b/NPCs/Abyss/GulperEelTail.cs @@ -133,9 +133,9 @@ namespace CalamityMod.NPCs.Abyss NPC.position.Y = NPC.position.Y + targetYDirection; if (targetXDirection < 0f) - NPC.spriteDirection = 1; - else if (targetXDirection > 0f) NPC.spriteDirection = -1; + else if (targetXDirection > 0f) + NPC.spriteDirection = 1; } } diff --git a/NPCs/Abyss/GulperEelTail.png b/NPCs/Abyss/GulperEelTail.png index acade0c0a0..bda0f5f11c 100644 Binary files a/NPCs/Abyss/GulperEelTail.png and b/NPCs/Abyss/GulperEelTail.png differ diff --git a/NPCs/Abyss/GulperEelTailGlow.png b/NPCs/Abyss/GulperEelTailGlow.png index b07de25a2d..3ef3b136e7 100644 Binary files a/NPCs/Abyss/GulperEelTailGlow.png and b/NPCs/Abyss/GulperEelTailGlow.png differ diff --git a/NPCs/Abyss/OarfishHead.cs b/NPCs/Abyss/OarfishHead.cs index 4dcae8c4f4..20a9467a9b 100644 --- a/NPCs/Abyss/OarfishHead.cs +++ b/NPCs/Abyss/OarfishHead.cs @@ -5,7 +5,9 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables.Banners; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent; using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; @@ -28,7 +30,6 @@ namespace CalamityMod.NPCs.Abyss { NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/Oarfish_Bestiary", PortraitPositionYOverride = 20 }; value.Position.X += 20; @@ -365,5 +366,14 @@ namespace CalamityMod.NPCs.Abyss if (hurtInfo.Damage > 0) target.AddBuff(ModContent.BuffType(), 90); } + + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + if (NPC.IsABestiaryIconDummy) + { + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 11, 10, 0.6f, Vector2.Zero, 3, 10); + } + return true; + } } } diff --git a/NPCs/AquaticScourge/AquaticScourgeHead.cs b/NPCs/AquaticScourge/AquaticScourgeHead.cs index a711c22a36..49ef5b1e5c 100644 --- a/NPCs/AquaticScourge/AquaticScourgeHead.cs +++ b/NPCs/AquaticScourge/AquaticScourgeHead.cs @@ -16,6 +16,7 @@ using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.AcidRain; using CalamityMod.NPCs.CalamityAIs.CalamityBossAIs; using CalamityMod.NPCs.TownNPCs; @@ -42,8 +43,7 @@ namespace CalamityMod.NPCs.AquaticScourge NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { Scale = 0.6f, - PortraitScale = 0.6f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/AquaticScourge_Bestiary" + PortraitScale = 0.6f }; value.Position.X += 40f; value.Position.Y += 20f; @@ -135,6 +135,11 @@ namespace CalamityMod.NPCs.AquaticScourge public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { + if (NPC.IsABestiaryIconDummy) + { + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 10, 12, 0.6f, new Vector2(20, 30), 3, 10); + } + SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) spriteEffects = SpriteEffects.FlipHorizontally; diff --git a/NPCs/AstrumDeus/AstrumDeusHead.cs b/NPCs/AstrumDeus/AstrumDeusHead.cs index c69395c57b..ed832e6006 100644 --- a/NPCs/AstrumDeus/AstrumDeusHead.cs +++ b/NPCs/AstrumDeus/AstrumDeusHead.cs @@ -17,6 +17,7 @@ using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Items.Weapons.Rogue; using CalamityMod.Items.Weapons.Summon; +using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.CalamityAIs.CalamityBossAIs; using CalamityMod.UI.VanillaBossBars; using CalamityMod.World; @@ -57,8 +58,7 @@ namespace CalamityMod.NPCs.AstrumDeus NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { Scale = 0.70f, - PortraitScale = 0.75f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/AstrumDeus_Bestiary" + PortraitScale = 0.75f }; value.Position.X += 55f; value.Position.Y += 23f; @@ -157,7 +157,10 @@ namespace CalamityMod.NPCs.AstrumDeus public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { if (NPC.IsABestiaryIconDummy) + { NPC.Opacity = 1f; + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, AstrumDeusBody.AltTexture.Value, 7, 26, 0.3f, new Vector2(0, 10), 5, 10, 4); + } SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) diff --git a/NPCs/CalamityAIs/CalamityBossAIs/AquaticScourgeAI.cs b/NPCs/CalamityAIs/CalamityBossAIs/AquaticScourgeAI.cs index 2ddd4e677e..b4b7b4b27b 100644 --- a/NPCs/CalamityAIs/CalamityBossAIs/AquaticScourgeAI.cs +++ b/NPCs/CalamityAIs/CalamityBossAIs/AquaticScourgeAI.cs @@ -53,7 +53,7 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs // Kiss my motherfucking ass you piece of shit game npc.timeLeft *= 20; npc.npcSlots = 16f; - CalamityMod.bossKillTimes.TryGetValue(npc.type, out int revKillTime); + CalamityGlobalNPC.BossKillTimes.TryGetValue(npc.type, out int revKillTime); calamityGlobalNPC.KillTime = revKillTime; calamityGlobalNPC.newAI[0] = 1f; nonHostile = false; diff --git a/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs b/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs index a4b0716412..ffc189ab5e 100644 --- a/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs +++ b/NPCs/CalamityAIs/CalamityBossAIs/OldDukeAI.cs @@ -70,9 +70,9 @@ namespace CalamityMod.NPCs.CalamityAIs.CalamityBossAIs Lighting.AddLight((int)((npc.position.X + (npc.width / 2)) / 16f), (int)((npc.position.Y + (npc.height / 2)) / 16f), redLight, greenLight, 0f); if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); else if (!Main.raining && !BossRushEvent.BossRushActive) - CalamityUtils.StartRain(); + CalamityWorld.StartRain(); // Adjust stats int setDamage = npc.defDamage; diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index 69299c1688..a9351018f6 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -45,9 +45,11 @@ using CalamityMod.NPCs.Providence; using CalamityMod.NPCs.Ravager; using CalamityMod.NPCs.SlimeGod; using CalamityMod.NPCs.StormWeaver; +using CalamityMod.NPCs.SunkenSea; using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.NPCs.VanillaNPCAIOverrides.Bosses; using CalamityMod.NPCs.VanillaNPCAIOverrides.RegularEnemies; +using CalamityMod.Packets; using CalamityMod.Particles; using CalamityMod.Projectiles; using CalamityMod.Projectiles.Magic; @@ -83,12 +85,28 @@ using Terraria.Utilities; using static Terraria.ModLoader.ModContent; using CalamityMod.NPCs.SunkenSea; using CalamityMod.Packets; +using CalamityMod.ExtraTextures; +using MonoMod.Utils; namespace CalamityMod.NPCs { public partial class CalamityGlobalNPC : GlobalNPC { #region Variables + + /// + /// Boss Kill Time data structure + /// + public static SortedDictionary BossKillTimes; + + /// + /// Damage Reduction Lookup Table + /// + public static SortedDictionary DRValues { get; set; } + + /// + /// Damage Reduction Value + /// public float DR { get; set; } = 0f; /// @@ -172,6 +190,9 @@ namespace CalamityMod.NPCs // Boss Zen distance private const float BossZenDistance = 6400f; + // Buff most vanilla enemy HP by 25% + private const double EnemyHPMultiplier = 1.25; + // Used to nerf desert prehardmode enemies pre-Desert Scourge private const double DesertEnemyStatMultiplier = 0.75; @@ -392,6 +413,9 @@ namespace CalamityMod.NPCs // Variable for if enemy has been recently hit by an ArcZap public int arcZapCooldown = 0; + + // Animates worms in the bestiary but only when their entry is being looked at + public float bestiaryWormTimer = 0; #endregion #region Instance Per Entity and TML 1.4 Cloning @@ -1201,9 +1225,237 @@ namespace CalamityMod.NPCs } #endregion + #region Load/Unload + public override void Load() + { + #region Setup Vanilla DR Values + DRValues = new SortedDictionary { + { NPCID.AngryBonesBig, 0.2f }, + { NPCID.AngryBonesBigHelmet, 0.2f }, + { NPCID.AngryBonesBigMuscle, 0.2f }, + { NPCID.AnomuraFungus, 0.1f }, + { NPCID.Antlion, 0.1f }, + { NPCID.Arapaima, 0.1f }, + { NPCID.ArmoredSkeleton, 0.15f }, + { NPCID.ArmoredViking, 0.1f }, + { NPCID.BigMimicCorruption, 0.3f }, + { NPCID.BigMimicCrimson, 0.3f }, + { NPCID.BigMimicHallow, 0.3f }, + { NPCID.BigMimicJungle, 0.3f }, // unused vanilla enemy + { NPCID.BlueArmoredBones, 0.2f }, + { NPCID.BlueArmoredBonesMace, 0.2f }, + { NPCID.BlueArmoredBonesNoPants, 0.2f }, + { NPCID.BlueArmoredBonesSword, 0.2f }, + { NPCID.BoneLee, 0.2f }, + { NPCID.Crab, 0.05f }, + { NPCID.Crawdad, 0.2f }, + { NPCID.Crawdad2, 0.2f }, + { NPCID.CultistBoss, 0.15f }, + { NPCID.Deerclops, 0.05f }, + { NPCID.DD2Betsy, 0.1f }, + { NPCID.DD2OgreT2, 0.1f }, + { NPCID.DD2OgreT3, 0.15f }, + { NPCID.DeadlySphere, 0.4f }, + { NPCID.DiabolistRed, 0.2f }, + { NPCID.DiabolistWhite, 0.2f }, + { NPCID.DukeFishron, 0.15f }, + { NPCID.DungeonGuardian, 0.9f }, + { NPCID.DungeonSpirit, 0.2f }, + { NPCID.ElfCopter, 0.15f }, + { NPCID.Everscream, 0.1f }, + { NPCID.FlyingAntlion, 0.05f }, + { NPCID.GiantCursedSkull, 0.2f }, + { NPCID.GiantShelly, 0.2f }, + { NPCID.GiantShelly2, 0.2f }, + { NPCID.GiantTortoise, 0.35f }, + { NPCID.Golem, 0.25f }, + { NPCID.GolemFistLeft, 0.25f }, + { NPCID.GolemFistRight, 0.25f }, + { NPCID.GolemHead, 0.25f }, + { NPCID.GolemHeadFree, 0.25f }, + { NPCID.GraniteFlyer, 0.1f }, + { NPCID.GraniteGolem, 0.15f }, + { NPCID.GreekSkeleton, 0.1f }, + { NPCID.HellArmoredBones, 0.2f }, + { NPCID.HellArmoredBonesMace, 0.2f }, + { NPCID.HellArmoredBonesSpikeShield, 0.2f }, + { NPCID.HellArmoredBonesSword, 0.2f }, + { NPCID.IceGolem, 0.1f }, + { NPCID.IceQueen, 0.1f }, + { NPCID.IceTortoise, 0.35f }, + { NPCID.HeadlessHorseman, 0.05f }, + { NPCID.MartianDrone, 0.2f }, + { NPCID.MartianSaucer, 0.2f }, + { NPCID.MartianSaucerCannon, 0.2f }, + { NPCID.MartianSaucerCore, 0.2f }, + { NPCID.MartianSaucerTurret, 0.2f }, + { NPCID.MartianTurret, 0.2f }, + { NPCID.MartianWalker, 0.35f }, + { NPCID.Mimic, 0.3f }, + { NPCID.MoonLordCore, 0.15f }, + { NPCID.MoonLordHand, 0.15f }, + { NPCID.MoonLordHead, 0.15f }, + { NPCID.Mothron, 0.2f }, + { NPCID.MothronEgg, 0.5f }, + { NPCID.MourningWood, 0.1f }, + { NPCID.Necromancer, 0.2f }, + { NPCID.NecromancerArmored, 0.2f }, + { NPCID.Paladin, 0.45f }, + { NPCID.PirateCaptain, 0.05f }, + { NPCID.PirateShipCannon, 0.15f }, + { NPCID.Plantera, 0.15f }, + { NPCID.PlanterasTentacle, 0.1f }, + { NPCID.HallowBoss, 0.15f }, + { NPCID.PossessedArmor, 0.25f }, + { NPCID.PresentMimic, 0.3f }, + { NPCID.PrimeCannon, 0.2f }, + { NPCID.PrimeLaser, 0.2f }, + { NPCID.PrimeSaw, 0.2f }, + { NPCID.PrimeVice, 0.2f }, + { NPCID.Probe, 0.2f }, + { NPCID.Pumpking, 0.1f }, + { NPCID.QueenBee, 0.05f }, + { NPCID.RaggedCaster, 0.2f }, + { NPCID.RaggedCasterOpenCoat, 0.2f }, + { NPCID.Retinazer, 0.2f }, + { NPCID.RustyArmoredBonesAxe, 0.2f }, + { NPCID.RustyArmoredBonesFlail, 0.2f }, + { NPCID.RustyArmoredBonesSword, 0.2f }, + { NPCID.RustyArmoredBonesSwordNoArmor, 0.2f }, + { NPCID.SandElemental, 0.1f }, + { NPCID.SantaNK1, 0.35f }, + { NPCID.SeaSnail, 0.05f }, + { NPCID.SkeletonArcher, 0.1f }, + { NPCID.SkeletonCommando, 0.2f }, + { NPCID.SkeletonSniper, 0.2f }, + { NPCID.SkeletronHand, 0.05f }, + { NPCID.SkeletronHead, 0.05f }, + { NPCID.SkeletronPrime, 0.2f }, + { NPCID.Spazmatism, 0.2f }, + { NPCID.TacticalSkeleton, 0.2f }, + { NPCID.TheDestroyer, 0.1f }, + { NPCID.TheDestroyerBody, 0.2f }, + { NPCID.TheDestroyerTail, 0.35f }, + { NPCID.TheHungry, 0.1f }, + { NPCID.UndeadViking, 0.1f }, + { NPCID.WalkingAntlion, 0.1f }, + { NPCID.WallofFlesh, 0.5f }, + }; + #endregion + + // Somehow the SetStatic is called few times before SetStaticDefaults + // So We Initialize the Dictionary first. And Push Data later (At SetStaticDefaults) + BossKillTimes = []; + } + + public override void Unload() + { + DRValues?.Clear(); + DRValues = null; + + BossKillTimes?.Clear(); + BossKillTimes = null; + } + #endregion + #region Set Defaults public override void SetStaticDefaults() { + #region Add Entries to BossKillTimes + BossKillTimes.AddRange(new Dictionary(){ + + // + // VANILLA BOSSES + // + { NPCID.KingSlime, 5400 }, // 1:30 (90 seconds) + { NPCID.EyeofCthulhu, 5400 }, // 1:30 (90 seconds) + { NPCID.EaterofWorldsHead, 7200 }, // 2:00 (120 seconds) + { NPCID.EaterofWorldsBody, 7200 }, + { NPCID.EaterofWorldsTail, 7200 }, + { NPCID.BrainofCthulhu, 7200 }, // 2:00 (120 seconds, total length of fight including Creepers phase) + { NPCID.Creeper, 1800 }, // 0:30 (30 seconds, length of Creepers phase) + { NPCID.Deerclops, 5400 }, // 1:30 (90 seconds) + { NPCID.QueenBee, 7200 }, // 2:00 (120 seconds) + { NPCID.SkeletronHead, 9000 }, // 2:30 (150 seconds) + { NPCID.WallofFlesh, 7200 }, // 2:00 (120 seconds) + { NPCID.WallofFleshEye, 7200 }, + { NPCID.QueenSlimeBoss, 7200 }, // 2:00 (120 seconds) + { NPCID.Spazmatism, 10800 }, // 3:00 (180 seconds) + { NPCID.Retinazer, 10800 }, + { NPCID.TheDestroyer, 10800 }, // 3:00 (180 seconds) + { NPCID.TheDestroyerBody, 10800 }, + { NPCID.TheDestroyerTail, 10800 }, + { NPCID.SkeletronPrime, 10800 }, // 3:00 (180 seconds) + { NPCID.Plantera, 10800 }, // 3:00 (180 seconds) + { NPCID.HallowBoss, 10800 }, // 3:00 (180 seconds) + { NPCID.Golem, 9000 }, // 2:30 (150 seconds) + { NPCID.GolemHead, 3600 }, // 1:00 (60 seconds) + { NPCID.DukeFishron, 9000 }, // 2:30 (150 seconds) + { NPCID.CultistBoss, 9000 }, // 2:30 (150 seconds) + { NPCID.MoonLordCore, 14400 }, // 4:00 (240 seconds) + { NPCID.MoonLordHand, 7200 }, // 2:00 (120 seconds) + { NPCID.MoonLordHead, 7200 }, // 2:00 (120 seconds) + + // + // CALAMITY BOSSES + // + { NPCType(), 5400 }, // 1:30 (90 seconds) + { NPCType(), 5400 }, + { NPCType(), 5400 }, + { NPCType(), 5400 }, // 1:30 (90 seconds) + { NPCType(), 7200 }, // 2:00 (120 seconds) + { NPCType(), 7200 }, // 2:00 (120 seconds) + { NPCType(), 9000 }, // 2:30 (150 seconds) -- total length of Slime God fight + { NPCType(), 4500 }, // 1:15 (75 seconds) + { NPCType(), 4500 }, // 1:15 (75 seconds) + { NPCType(), 4500 }, // 1:15 (75 seconds) -- split slimes should spawn at 1:15 and die at around 2:30 + { NPCType(), 4500 }, // 1:15 (75 seconds) + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 9000 }, // 2:30 (150 seconds) + { NPCType(), 9000 }, + { NPCType(), 9000 }, + { NPCType(), 9000 }, + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 14400 }, // 4:00 (240 seconds) + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 10800 }, + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 7200 }, // 2:00 (120 seconds) -- first phase is 1:00 + { NPCType(), 7200 }, + { NPCType(), 7200 }, + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 5400 }, // 1:30 (90 seconds) + { NPCType(), 7200 }, // 2:00 (120 seconds) + { NPCType(), 14400 }, // 4:00 (240 seconds) + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 1200 }, // 0:20 (20 seconds) + { NPCType(), 8100 }, // 2:15 (135 seconds) + { NPCType(), 8100 }, + { NPCType(), 8100 }, + { NPCType(), 7200 }, // 2:00 (120 seconds) + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 10800 }, // 3:00 (180 seconds) + { NPCType(), 14400 }, // 4:00 (240 seconds) + { NPCType(), 14400 }, // DoG Phase 1 is 1:30, DoG Phase 2 is 2:30 + { NPCType(), 14400 }, + { NPCType(), 14700 }, // 4:05 (245 seconds) -- he spends 5 seconds invincible where you can't do anything + { NPCType(), 21600 }, // 6:00 (360 seconds) + { NPCType(), 21600 }, + { NPCType(), 21600 }, // 6:00 (360 seconds) + { NPCType(), 21600 }, + { NPCType(), 21600 }, + { NPCType(), 21600 }, + { NPCType(), 21600 }, + { NPCType(), 21600 }, // 6:00 (360 seconds) + { NPCType(), 21600 }, + { NPCType(), 21600 }, + { NPCType(), 21600 }, + { NPCType(), 18000 }, // 5:00 (300 seconds) + { NPCType(), 18000 } // 5:00 (300 seconds) + }); + #endregion + // Set Plantera to be able to update oldPos[x] // This is only used for her Rev+ AI charge attacks NPCID.Sets.TrailingMode[NPCID.Plantera] = 1; @@ -1225,16 +1477,15 @@ namespace CalamityMod.NPCs // Apply DR to vanilla NPCs. // This also applies DR to other mods' NPCs who have set up their NPCs to have DR. - if (CalamityMod.DRValues.ContainsKey(npc.type)) + if (DRValues.ContainsKey(npc.type)) { - CalamityMod.DRValues.TryGetValue(npc.type, out float newDR); + DRValues.TryGetValue(npc.type, out float newDR); DR = newDR; } // Aquatic Scourge sets kill time in AI, not here. - if (CalamityMod.bossKillTimes.ContainsKey(npc.type) && !CalamityLists.AquaticScourgeIDs.Contains(npc.type)) + if (BossKillTimes.TryGetValue(npc.type, out int revKillTime) && !CalamityLists.AquaticScourgeIDs.Contains(npc.type)) { - CalamityMod.bossKillTimes.TryGetValue(npc.type, out int revKillTime); KillTime = revKillTime; } @@ -2581,550 +2832,559 @@ namespace CalamityMod.NPCs if (Main.expertMode) AdjustExpertModeStatScaling(npc); - // Nerf a shitload of Master Mode enemies - // HP is nerfed by 25% (this nerf is higher due to the player not dealing any more damage in Master) - // Damage is nerfed by 15% (this nerf is lower due to the player having 100% effective defense in Master) - if (Main.masterMode) + // Adjust a ton of enemy stats + switch (npc.type) { - switch (npc.type) - { - case NPCID.AngryBones: - case NPCID.AngryBonesBig: - case NPCID.AngryBonesBigHelmet: - case NPCID.AngryBonesBigMuscle: - case NPCID.BigBoned: - case NPCID.ShortBones: - case NPCID.AnomuraFungus: - case NPCID.Antlion: - case NPCID.WalkingAntlion: - case NPCID.GiantWalkingAntlion: - case NPCID.LarvaeAntlion: - case NPCID.FlyingAntlion: - case NPCID.GiantFlyingAntlion: - case NPCID.BabySlime: - case NPCID.BlackSlime: - case NPCID.BlazingWheel: - case NPCID.BloodCrawler: - case NPCID.BloodCrawlerWall: - case NPCID.BlueJellyfish: - case NPCID.GreenJellyfish: - case NPCID.PinkJellyfish: - case NPCID.BloodJelly: - case NPCID.FungoFish: - case NPCID.BlueSlime: - case NPCID.BoneSerpentBody: - case NPCID.BoneSerpentHead: - case NPCID.BoneSerpentTail: - case NPCID.CaveBat: - case NPCID.CochinealBeetle: - case NPCID.Crab: - case NPCID.Crawdad: - case NPCID.Crawdad2: - case NPCID.Crimera: - case NPCID.BigCrimera: - case NPCID.LittleCrimera: - case NPCID.CursedSkull: - case NPCID.CyanBeetle: - case NPCID.Demon: - case NPCID.DemonEye: - case NPCID.CataractEye: - case NPCID.CataractEye2: - case NPCID.DemonEye2: - case NPCID.DemonEyeOwl: - case NPCID.DemonEyeSpaceship: - case NPCID.DialatedEye: - case NPCID.DialatedEye2: - case NPCID.GreenEye: - case NPCID.GreenEye2: - case NPCID.PurpleEye: - case NPCID.PurpleEye2: - case NPCID.SleepyEye: - case NPCID.SleepyEye2: - case NPCID.DevourerBody: - case NPCID.DevourerHead: - case NPCID.DevourerTail: - case NPCID.DoctorBones: - case NPCID.DungeonSlime: - case NPCID.EaterofSouls: - case NPCID.BigEater: - case NPCID.LittleEater: - case NPCID.FaceMonster: - case NPCID.ArmedZombieEskimo: - case NPCID.ZombieEskimo: - case NPCID.FungiBulb: - case NPCID.Ghost: - case NPCID.GiantShelly: - case NPCID.GiantShelly2: - case NPCID.GiantWormBody: - case NPCID.GiantWormHead: - case NPCID.GiantWormTail: - case NPCID.Gnome: - case NPCID.GoblinScout: - case NPCID.GraniteFlyer: - case NPCID.GraniteGolem: - case NPCID.GreenSlime: - case NPCID.Harpy: - case NPCID.Hellbat: - case NPCID.GreekSkeleton: - case NPCID.Hornet: - case NPCID.HornetFatty: - case NPCID.HornetHoney: - case NPCID.HornetLeafy: - case NPCID.HornetSpikey: - case NPCID.HornetStingy: - case NPCID.BigHornetFatty: - case NPCID.BigHornetHoney: - case NPCID.BigHornetLeafy: - case NPCID.BigHornetSpikey: - case NPCID.BigHornetStingy: - case NPCID.BigMossHornet: - case NPCID.GiantMossHornet: - case NPCID.LittleHornetFatty: - case NPCID.LittleHornetHoney: - case NPCID.LittleHornetLeafy: - case NPCID.LittleHornetSpikey: - case NPCID.LittleHornetStingy: - case NPCID.LittleMossHornet: - case NPCID.MossHornet: - case NPCID.TinyMossHornet: - case NPCID.IceBat: - case NPCID.IceSlime: - case NPCID.JungleBat: - case NPCID.JungleSlime: - case NPCID.LacBeetle: - case NPCID.LavaSlime: - case NPCID.MaggotZombie: - case NPCID.ManEater: - case NPCID.MeteorHead: - case NPCID.MotherSlime: - case NPCID.MushiLadybug: - case NPCID.Nymph: - case NPCID.Pinky: - case NPCID.Piranha: - case NPCID.PurpleSlime: - case NPCID.Raven: - case NPCID.RedSlime: - case NPCID.Salamander: - case NPCID.Salamander2: - case NPCID.Salamander3: - case NPCID.Salamander4: - case NPCID.Salamander5: - case NPCID.Salamander6: - case NPCID.Salamander7: - case NPCID.Salamander8: - case NPCID.Salamander9: - case NPCID.SandSlime: - case NPCID.SeaSnail: - case NPCID.Shark: - case NPCID.ShimmerSlime: - case NPCID.Skeleton: - case NPCID.SkeletonAlien: - case NPCID.SkeletonAstonaut: - case NPCID.SkeletonTopHat: - case NPCID.ArmoredSkeleton: - case NPCID.BigHeadacheSkeleton: - case NPCID.BigMisassembledSkeleton: - case NPCID.BigPantlessSkeleton: - case NPCID.BigSkeleton: - case NPCID.BoneThrowingSkeleton: - case NPCID.BoneThrowingSkeleton2: - case NPCID.BoneThrowingSkeleton3: - case NPCID.BoneThrowingSkeleton4: - case NPCID.HeadacheSkeleton: - case NPCID.HeavySkeleton: - case NPCID.MisassembledSkeleton: - case NPCID.PantlessSkeleton: - case NPCID.SmallMisassembledSkeleton: - case NPCID.SmallHeadacheSkeleton: - case NPCID.SmallSkeleton: - case NPCID.SmallPantlessSkeleton: - case NPCID.SporeSkeleton: - case NPCID.TacticalSkeleton: - case NPCID.SkeletonSniper: - case NPCID.SkeletonCommando: - case NPCID.DarkCaster: - case NPCID.FireImp: - case NPCID.Snatcher: - case NPCID.SnowFlinx: - case NPCID.SpikeBall: - case NPCID.SpikedIceSlime: - case NPCID.SpikedJungleSlime: - case NPCID.SporeBat: - case NPCID.ZombieMushroom: - case NPCID.ZombieMushroomHat: - case NPCID.Squid: - case NPCID.Tim: - case NPCID.TombCrawlerBody: - case NPCID.TombCrawlerHead: - case NPCID.TombCrawlerTail: - case NPCID.UndeadMiner: - case NPCID.UndeadViking: - case NPCID.VoodooDemon: - case NPCID.Vulture: - case NPCID.WallCreeper: - case NPCID.WallCreeperWall: - case NPCID.YellowSlime: - case NPCID.Zombie: - case NPCID.ZombieDoctor: - case NPCID.ZombieElf: - case NPCID.ZombieElfBeard: - case NPCID.ZombieElfGirl: - case NPCID.ZombieMerman: - case NPCID.ZombiePixie: - case NPCID.ZombieRaincoat: - case NPCID.ZombieSuperman: - case NPCID.ZombieSweater: - case NPCID.ZombieXmas: - case NPCID.ArmedTorchZombie: - case NPCID.ArmedZombie: - case NPCID.ArmedZombieCenx: - case NPCID.ArmedZombiePincussion: - case NPCID.ArmedZombieSlimed: - case NPCID.ArmedZombieSwamp: - case NPCID.ArmedZombieTwiggy: - case NPCID.BaldZombie: - case NPCID.BigBaldZombie: - case NPCID.BigFemaleZombie: - case NPCID.BigPincushionZombie: - case NPCID.BigRainZombie: - case NPCID.BigSlimedZombie: - case NPCID.BigSwampZombie: - case NPCID.BigTwiggyZombie: - case NPCID.BigZombie: - case NPCID.BloodZombie: - case NPCID.FemaleZombie: - case NPCID.PincushionZombie: - case NPCID.SlimedZombie: - case NPCID.SmallBaldZombie: - case NPCID.SmallFemaleZombie: - case NPCID.SmallPincushionZombie: - case NPCID.SmallRainZombie: - case NPCID.SmallSlimedZombie: - case NPCID.SmallSwampZombie: - case NPCID.SmallTwiggyZombie: - case NPCID.SmallZombie: - case NPCID.SwampZombie: - case NPCID.TorchZombie: - case NPCID.TwiggyZombie: - case NPCID.AnglerFish: - case NPCID.AngryTrapper: - case NPCID.Arapaima: - case NPCID.ArmoredViking: - case NPCID.DesertBeast: - case NPCID.BlackRecluse: - case NPCID.BlackRecluseWall: - case NPCID.BloodFeeder: - case NPCID.Mummy: - case NPCID.BloodMummy: - case NPCID.DarkMummy: - case NPCID.LightMummy: - case NPCID.BlueArmoredBones: - case NPCID.BlueArmoredBonesMace: - case NPCID.BlueArmoredBonesNoPants: - case NPCID.BlueArmoredBonesSword: - case NPCID.BoneLee: - case NPCID.ChaosElemental: - case NPCID.Clinger: - case NPCID.BigMimicCorruption: - case NPCID.BigMimicCrimson: - case NPCID.BigMimicHallow: - case NPCID.BigMimicJungle: - case NPCID.CorruptSlime: - case NPCID.Corruptor: - case NPCID.Crimslime: - case NPCID.BigCrimslime: - case NPCID.LittleCrimslime: - case NPCID.CrimsonAxe: - case NPCID.CultistArcherBlue: - case NPCID.CultistArcherWhite: - case NPCID.CultistDevote: - case NPCID.CursedHammer: - case NPCID.Derpling: - case NPCID.Herpling: - case NPCID.DesertDjinn: - case NPCID.DiabolistRed: - case NPCID.DiabolistWhite: - case NPCID.DiggerBody: - case NPCID.DiggerHead: - case NPCID.DiggerTail: - case NPCID.DesertGhoul: - case NPCID.DesertGhoulCorruption: - case NPCID.DesertGhoulCrimson: - case NPCID.DesertGhoulHallow: - case NPCID.DuneSplicerBody: - case NPCID.DuneSplicerHead: - case NPCID.DuneSplicerTail: - case NPCID.DungeonSpirit: - case NPCID.EnchantedSword: - case NPCID.FloatyGross: - case NPCID.FlyingSnake: - case NPCID.Gastropod: - case NPCID.GiantBat: - case NPCID.GiantCursedSkull: - case NPCID.GiantFlyingFox: - case NPCID.GiantFungiBulb: - case NPCID.GiantTortoise: - case NPCID.IceTortoise: - case NPCID.HellArmoredBones: - case NPCID.HellArmoredBonesMace: - case NPCID.HellArmoredBonesSpikeShield: - case NPCID.HellArmoredBonesSword: - case NPCID.HoppinJack: - case NPCID.IceElemental: - case NPCID.Mimic: - case NPCID.IceMimic: - case NPCID.PresentMimic: - case NPCID.IchorSticker: - case NPCID.IcyMerman: - case NPCID.IlluminantBat: - case NPCID.IlluminantSlime: - case NPCID.JungleCreeper: - case NPCID.JungleCreeperWall: - case NPCID.DesertLamiaDark: - case NPCID.DesertLamiaLight: - case NPCID.Lavabat: - case NPCID.Lihzahrd: - case NPCID.LihzahrdCrawler: - case NPCID.Medusa: - case NPCID.Moth: - case NPCID.Necromancer: - case NPCID.NecromancerArmored: - case NPCID.Paladin: - case NPCID.PigronCorruption: - case NPCID.PigronCrimson: - case NPCID.PigronHallow: - case NPCID.Pixie: - case NPCID.PossessedArmor: - case NPCID.RaggedCaster: - case NPCID.RaggedCasterOpenCoat: - case NPCID.RedDevil: - case NPCID.RockGolem: - case NPCID.RuneWizard: - case NPCID.RustyArmoredBonesAxe: - case NPCID.RustyArmoredBonesFlail: - case NPCID.RustyArmoredBonesSword: - case NPCID.RustyArmoredBonesSwordNoArmor: - case NPCID.DesertScorpionWalk: - case NPCID.DesertScorpionWall: - case NPCID.SkeletonArcher: - case NPCID.Slimeling: - case NPCID.Slimer: - case NPCID.Slimer2: - case NPCID.ToxicSludge: - case NPCID.Unicorn: - case NPCID.WanderingEye: - case NPCID.Werewolf: - case NPCID.Wolf: - case NPCID.SeekerBody: - case NPCID.SeekerHead: - case NPCID.SeekerTail: - case NPCID.Wraith: - case NPCID.WyvernBody: - case NPCID.WyvernBody2: - case NPCID.WyvernBody3: - case NPCID.WyvernHead: - case NPCID.WyvernLegs: - case NPCID.WyvernTail: - case NPCID.BloodEelBody: - case NPCID.BloodEelHead: - case NPCID.BloodEelTail: - case NPCID.BloodSquid: - case NPCID.ChatteringTeethBomb: - case NPCID.Clown: - case NPCID.CorruptBunny: - case NPCID.CorruptGoldfish: - case NPCID.CorruptPenguin: - case NPCID.Drippler: - case NPCID.GoblinShark: - case NPCID.TheGroom: - case NPCID.TheBride: - case NPCID.CrimsonBunny: - case NPCID.CrimsonGoldfish: - case NPCID.CrimsonPenguin: - case NPCID.EyeballFlyingFish: - case NPCID.Dandelion: - case NPCID.AngryNimbus: - case NPCID.FlyingFish: - case NPCID.IceGolem: - case NPCID.RainbowSlime: - case NPCID.UmbrellaSlime: - case NPCID.Tumbleweed: - case NPCID.SandShark: - case NPCID.SandsharkCorrupt: - case NPCID.SandsharkCrimson: - case NPCID.SandsharkHallow: - case NPCID.SandElemental: - case NPCID.BloodNautilus: - case NPCID.GoblinArcher: - case NPCID.GoblinPeon: - case NPCID.GoblinSorcerer: - case NPCID.GoblinSummoner: - case NPCID.GoblinThief: - case NPCID.GoblinWarrior: - case NPCID.MisterStabby: - case NPCID.SnowBalla: - case NPCID.SnowmanGangsta: - case NPCID.Parrot: - case NPCID.PirateCaptain: - case NPCID.PirateCorsair: - case NPCID.PirateCrossbower: - case NPCID.PirateDeadeye: - case NPCID.PirateDeckhand: - case NPCID.PirateGhost: - case NPCID.PirateShipCannon: - case NPCID.MothronSpawn: - case NPCID.Mothron: - case NPCID.Butcher: - case NPCID.CreatureFromTheDeep: - case NPCID.DeadlySphere: - case NPCID.DrManFly: - case NPCID.Eyezor: - case NPCID.Frankenstein: - case NPCID.Fritz: - case NPCID.Nailhead: - case NPCID.Psycho: - case NPCID.Reaper: - case NPCID.ThePossessed: - case NPCID.SwampThing: - case NPCID.Vampire: - case NPCID.VampireBat: - case NPCID.BrainScrambler: - case NPCID.GigaZapper: - case NPCID.MartianWalker: - case NPCID.GrayGrunt: - case NPCID.MartianDrone: - case NPCID.MartianEngineer: - case NPCID.MartianOfficer: - case NPCID.RayGunner: - case NPCID.Scutlix: - case NPCID.ScutlixRider: - case NPCID.MartianTurret: - case NPCID.HeadlessHorseman: - case NPCID.Hellhound: - case NPCID.Splinterling: - case NPCID.Poltergeist: - case NPCID.Scarecrow1: - case NPCID.Scarecrow2: - case NPCID.Scarecrow3: - case NPCID.Scarecrow4: - case NPCID.Scarecrow5: - case NPCID.Scarecrow6: - case NPCID.Scarecrow7: - case NPCID.Scarecrow8: - case NPCID.Scarecrow9: - case NPCID.Scarecrow10: - case NPCID.ElfArcher: - case NPCID.ElfCopter: - case NPCID.Flocko: - case NPCID.GingerbreadMan: - case NPCID.Krampus: - case NPCID.Nutcracker: - case NPCID.NutcrackerSpinning: - case NPCID.Yeti: - case NPCID.NebulaBeast: - case NPCID.NebulaBrain: - case NPCID.NebulaHeadcrab: - case NPCID.NebulaSoldier: - case NPCID.SolarCorite: - case NPCID.SolarCrawltipedeBody: - case NPCID.SolarCrawltipedeHead: - case NPCID.SolarCrawltipedeTail: - case NPCID.SolarDrakomire: - case NPCID.SolarDrakomireRider: - case NPCID.SolarSolenian: - case NPCID.SolarSpearman: - case NPCID.SolarSroller: - case NPCID.StardustCellBig: - case NPCID.StardustCellSmall: - case NPCID.StardustJellyfishBig: - case NPCID.StardustWormBody: - case NPCID.StardustWormHead: - case NPCID.StardustWormTail: - case NPCID.StardustSoldier: - case NPCID.StardustSpiderBig: - case NPCID.StardustSpiderSmall: - case NPCID.VortexHornet: - case NPCID.VortexHornetQueen: - case NPCID.VortexLarva: - case NPCID.VortexRifleman: - case NPCID.VortexSoldier: - case NPCID.DD2DarkMageT1: - case NPCID.DD2DarkMageT3: - case NPCID.DD2OgreT2: - case NPCID.DD2OgreT3: - case NPCID.MartianSaucerCore: - case NPCID.MartianSaucerCannon: - case NPCID.MartianSaucerTurret: - case NPCID.DD2SkeletonT1: - case NPCID.DD2SkeletonT3: - case NPCID.DD2DrakinT2: - case NPCID.DD2DrakinT3: - case NPCID.DD2GoblinBomberT1: - case NPCID.DD2GoblinBomberT2: - case NPCID.DD2GoblinBomberT3: - case NPCID.DD2GoblinT1: - case NPCID.DD2GoblinT2: - case NPCID.DD2GoblinT3: - case NPCID.DD2JavelinstT1: - case NPCID.DD2JavelinstT2: - case NPCID.DD2JavelinstT3: - case NPCID.DD2KoboldFlyerT2: - case NPCID.DD2KoboldFlyerT3: - case NPCID.DD2KoboldWalkerT2: - case NPCID.DD2KoboldWalkerT3: - case NPCID.DD2LightningBugT3: - case NPCID.DD2WitherBeastT2: - case NPCID.DD2WitherBeastT3: - case NPCID.DD2WyvernT1: - case NPCID.DD2WyvernT2: - case NPCID.DD2WyvernT3: - case NPCID.AncientCultistSquidhead: - case NPCID.SlimeSpiked: + case NPCID.AngryBones: + case NPCID.AngryBonesBig: + case NPCID.AngryBonesBigHelmet: + case NPCID.AngryBonesBigMuscle: + case NPCID.BigBoned: + case NPCID.ShortBones: + case NPCID.AnomuraFungus: + case NPCID.Antlion: + case NPCID.WalkingAntlion: + case NPCID.GiantWalkingAntlion: + case NPCID.LarvaeAntlion: + case NPCID.FlyingAntlion: + case NPCID.GiantFlyingAntlion: + case NPCID.BabySlime: + case NPCID.BlackSlime: + case NPCID.BlazingWheel: + case NPCID.BloodCrawler: + case NPCID.BloodCrawlerWall: + case NPCID.BlueJellyfish: + case NPCID.GreenJellyfish: + case NPCID.PinkJellyfish: + case NPCID.BloodJelly: + case NPCID.FungoFish: + case NPCID.BlueSlime: + case NPCID.BoneSerpentBody: + case NPCID.BoneSerpentHead: + case NPCID.BoneSerpentTail: + case NPCID.CaveBat: + case NPCID.CochinealBeetle: + case NPCID.Crab: + case NPCID.Crawdad: + case NPCID.Crawdad2: + case NPCID.Crimera: + case NPCID.BigCrimera: + case NPCID.LittleCrimera: + case NPCID.CursedSkull: + case NPCID.CyanBeetle: + case NPCID.Demon: + case NPCID.DemonEye: + case NPCID.CataractEye: + case NPCID.CataractEye2: + case NPCID.DemonEye2: + case NPCID.DemonEyeOwl: + case NPCID.DemonEyeSpaceship: + case NPCID.DialatedEye: + case NPCID.DialatedEye2: + case NPCID.GreenEye: + case NPCID.GreenEye2: + case NPCID.PurpleEye: + case NPCID.PurpleEye2: + case NPCID.SleepyEye: + case NPCID.SleepyEye2: + case NPCID.DevourerBody: + case NPCID.DevourerHead: + case NPCID.DevourerTail: + case NPCID.DoctorBones: + case NPCID.DungeonSlime: + case NPCID.EaterofSouls: + case NPCID.BigEater: + case NPCID.LittleEater: + case NPCID.FaceMonster: + case NPCID.ArmedZombieEskimo: + case NPCID.ZombieEskimo: + case NPCID.FungiBulb: + case NPCID.Ghost: + case NPCID.GiantShelly: + case NPCID.GiantShelly2: + case NPCID.GiantWormBody: + case NPCID.GiantWormHead: + case NPCID.GiantWormTail: + case NPCID.Gnome: + case NPCID.GoblinScout: + case NPCID.GraniteFlyer: + case NPCID.GraniteGolem: + case NPCID.GreenSlime: + case NPCID.Harpy: + case NPCID.Hellbat: + case NPCID.GreekSkeleton: + case NPCID.Hornet: + case NPCID.HornetFatty: + case NPCID.HornetHoney: + case NPCID.HornetLeafy: + case NPCID.HornetSpikey: + case NPCID.HornetStingy: + case NPCID.BigHornetFatty: + case NPCID.BigHornetHoney: + case NPCID.BigHornetLeafy: + case NPCID.BigHornetSpikey: + case NPCID.BigHornetStingy: + case NPCID.BigMossHornet: + case NPCID.GiantMossHornet: + case NPCID.LittleHornetFatty: + case NPCID.LittleHornetHoney: + case NPCID.LittleHornetLeafy: + case NPCID.LittleHornetSpikey: + case NPCID.LittleHornetStingy: + case NPCID.LittleMossHornet: + case NPCID.MossHornet: + case NPCID.TinyMossHornet: + case NPCID.IceBat: + case NPCID.IceSlime: + case NPCID.JungleBat: + case NPCID.JungleSlime: + case NPCID.LacBeetle: + case NPCID.LavaSlime: + case NPCID.MaggotZombie: + case NPCID.ManEater: + case NPCID.MeteorHead: + case NPCID.MotherSlime: + case NPCID.MushiLadybug: + case NPCID.Nymph: + case NPCID.Pinky: + case NPCID.Piranha: + case NPCID.PurpleSlime: + case NPCID.Raven: + case NPCID.RedSlime: + case NPCID.Salamander: + case NPCID.Salamander2: + case NPCID.Salamander3: + case NPCID.Salamander4: + case NPCID.Salamander5: + case NPCID.Salamander6: + case NPCID.Salamander7: + case NPCID.Salamander8: + case NPCID.Salamander9: + case NPCID.SandSlime: + case NPCID.SeaSnail: + case NPCID.Shark: + case NPCID.ShimmerSlime: + case NPCID.Skeleton: + case NPCID.SkeletonAlien: + case NPCID.SkeletonAstonaut: + case NPCID.SkeletonTopHat: + case NPCID.ArmoredSkeleton: + case NPCID.BigHeadacheSkeleton: + case NPCID.BigMisassembledSkeleton: + case NPCID.BigPantlessSkeleton: + case NPCID.BigSkeleton: + case NPCID.BoneThrowingSkeleton: + case NPCID.BoneThrowingSkeleton2: + case NPCID.BoneThrowingSkeleton3: + case NPCID.BoneThrowingSkeleton4: + case NPCID.HeadacheSkeleton: + case NPCID.HeavySkeleton: + case NPCID.MisassembledSkeleton: + case NPCID.PantlessSkeleton: + case NPCID.SmallMisassembledSkeleton: + case NPCID.SmallHeadacheSkeleton: + case NPCID.SmallSkeleton: + case NPCID.SmallPantlessSkeleton: + case NPCID.SporeSkeleton: + case NPCID.TacticalSkeleton: + case NPCID.SkeletonSniper: + case NPCID.SkeletonCommando: + case NPCID.DarkCaster: + case NPCID.FireImp: + case NPCID.Snatcher: + case NPCID.SnowFlinx: + case NPCID.SpikeBall: + case NPCID.SpikedIceSlime: + case NPCID.SpikedJungleSlime: + case NPCID.SporeBat: + case NPCID.ZombieMushroom: + case NPCID.ZombieMushroomHat: + case NPCID.Squid: + case NPCID.Tim: + case NPCID.TombCrawlerBody: + case NPCID.TombCrawlerHead: + case NPCID.TombCrawlerTail: + case NPCID.UndeadMiner: + case NPCID.UndeadViking: + case NPCID.VoodooDemon: + case NPCID.Vulture: + case NPCID.WallCreeper: + case NPCID.WallCreeperWall: + case NPCID.YellowSlime: + case NPCID.Zombie: + case NPCID.ZombieDoctor: + case NPCID.ZombieElf: + case NPCID.ZombieElfBeard: + case NPCID.ZombieElfGirl: + case NPCID.ZombieMerman: + case NPCID.ZombiePixie: + case NPCID.ZombieRaincoat: + case NPCID.ZombieSuperman: + case NPCID.ZombieSweater: + case NPCID.ZombieXmas: + case NPCID.ArmedTorchZombie: + case NPCID.ArmedZombie: + case NPCID.ArmedZombieCenx: + case NPCID.ArmedZombiePincussion: + case NPCID.ArmedZombieSlimed: + case NPCID.ArmedZombieSwamp: + case NPCID.ArmedZombieTwiggy: + case NPCID.BaldZombie: + case NPCID.BigBaldZombie: + case NPCID.BigFemaleZombie: + case NPCID.BigPincushionZombie: + case NPCID.BigRainZombie: + case NPCID.BigSlimedZombie: + case NPCID.BigSwampZombie: + case NPCID.BigTwiggyZombie: + case NPCID.BigZombie: + case NPCID.BloodZombie: + case NPCID.FemaleZombie: + case NPCID.PincushionZombie: + case NPCID.SlimedZombie: + case NPCID.SmallBaldZombie: + case NPCID.SmallFemaleZombie: + case NPCID.SmallPincushionZombie: + case NPCID.SmallRainZombie: + case NPCID.SmallSlimedZombie: + case NPCID.SmallSwampZombie: + case NPCID.SmallTwiggyZombie: + case NPCID.SmallZombie: + case NPCID.SwampZombie: + case NPCID.TorchZombie: + case NPCID.TwiggyZombie: + case NPCID.AnglerFish: + case NPCID.AngryTrapper: + case NPCID.Arapaima: + case NPCID.ArmoredViking: + case NPCID.DesertBeast: + case NPCID.BlackRecluse: + case NPCID.BlackRecluseWall: + case NPCID.BloodFeeder: + case NPCID.Mummy: + case NPCID.BloodMummy: + case NPCID.DarkMummy: + case NPCID.LightMummy: + case NPCID.BlueArmoredBones: + case NPCID.BlueArmoredBonesMace: + case NPCID.BlueArmoredBonesNoPants: + case NPCID.BlueArmoredBonesSword: + case NPCID.BoneLee: + case NPCID.ChaosElemental: + case NPCID.Clinger: + case NPCID.BigMimicCorruption: + case NPCID.BigMimicCrimson: + case NPCID.BigMimicHallow: + case NPCID.BigMimicJungle: + case NPCID.CorruptSlime: + case NPCID.Corruptor: + case NPCID.Crimslime: + case NPCID.BigCrimslime: + case NPCID.LittleCrimslime: + case NPCID.CrimsonAxe: + case NPCID.CultistArcherBlue: + case NPCID.CultistArcherWhite: + case NPCID.CultistDevote: + case NPCID.CursedHammer: + case NPCID.Derpling: + case NPCID.Herpling: + case NPCID.DesertDjinn: + case NPCID.DiabolistRed: + case NPCID.DiabolistWhite: + case NPCID.DiggerBody: + case NPCID.DiggerHead: + case NPCID.DiggerTail: + case NPCID.DesertGhoul: + case NPCID.DesertGhoulCorruption: + case NPCID.DesertGhoulCrimson: + case NPCID.DesertGhoulHallow: + case NPCID.DuneSplicerBody: + case NPCID.DuneSplicerHead: + case NPCID.DuneSplicerTail: + case NPCID.DungeonSpirit: + case NPCID.EnchantedSword: + case NPCID.FloatyGross: + case NPCID.FlyingSnake: + case NPCID.Gastropod: + case NPCID.GiantBat: + case NPCID.GiantCursedSkull: + case NPCID.GiantFlyingFox: + case NPCID.GiantFungiBulb: + case NPCID.GiantTortoise: + case NPCID.IceTortoise: + case NPCID.HellArmoredBones: + case NPCID.HellArmoredBonesMace: + case NPCID.HellArmoredBonesSpikeShield: + case NPCID.HellArmoredBonesSword: + case NPCID.HoppinJack: + case NPCID.IceElemental: + case NPCID.Mimic: + case NPCID.IceMimic: + case NPCID.PresentMimic: + case NPCID.IchorSticker: + case NPCID.IcyMerman: + case NPCID.IlluminantBat: + case NPCID.IlluminantSlime: + case NPCID.JungleCreeper: + case NPCID.JungleCreeperWall: + case NPCID.DesertLamiaDark: + case NPCID.DesertLamiaLight: + case NPCID.Lavabat: + case NPCID.Lihzahrd: + case NPCID.LihzahrdCrawler: + case NPCID.Medusa: + case NPCID.Moth: + case NPCID.Necromancer: + case NPCID.NecromancerArmored: + case NPCID.Paladin: + case NPCID.PigronCorruption: + case NPCID.PigronCrimson: + case NPCID.PigronHallow: + case NPCID.Pixie: + case NPCID.PossessedArmor: + case NPCID.RaggedCaster: + case NPCID.RaggedCasterOpenCoat: + case NPCID.RedDevil: + case NPCID.RockGolem: + case NPCID.RuneWizard: + case NPCID.RustyArmoredBonesAxe: + case NPCID.RustyArmoredBonesFlail: + case NPCID.RustyArmoredBonesSword: + case NPCID.RustyArmoredBonesSwordNoArmor: + case NPCID.DesertScorpionWalk: + case NPCID.DesertScorpionWall: + case NPCID.SkeletonArcher: + case NPCID.Slimeling: + case NPCID.Slimer: + case NPCID.Slimer2: + case NPCID.ToxicSludge: + case NPCID.Unicorn: + case NPCID.WanderingEye: + case NPCID.Werewolf: + case NPCID.Wolf: + case NPCID.SeekerBody: + case NPCID.SeekerHead: + case NPCID.SeekerTail: + case NPCID.Wraith: + case NPCID.WyvernBody: + case NPCID.WyvernBody2: + case NPCID.WyvernBody3: + case NPCID.WyvernHead: + case NPCID.WyvernLegs: + case NPCID.WyvernTail: + case NPCID.BloodEelBody: + case NPCID.BloodEelHead: + case NPCID.BloodEelTail: + case NPCID.BloodSquid: + case NPCID.ChatteringTeethBomb: + case NPCID.Clown: + case NPCID.CorruptBunny: + case NPCID.CorruptGoldfish: + case NPCID.CorruptPenguin: + case NPCID.Drippler: + case NPCID.GoblinShark: + case NPCID.TheGroom: + case NPCID.TheBride: + case NPCID.CrimsonBunny: + case NPCID.CrimsonGoldfish: + case NPCID.CrimsonPenguin: + case NPCID.EyeballFlyingFish: + case NPCID.Dandelion: + case NPCID.AngryNimbus: + case NPCID.FlyingFish: + case NPCID.IceGolem: + case NPCID.RainbowSlime: + case NPCID.UmbrellaSlime: + case NPCID.Tumbleweed: + case NPCID.SandShark: + case NPCID.SandsharkCorrupt: + case NPCID.SandsharkCrimson: + case NPCID.SandsharkHallow: + case NPCID.SandElemental: + case NPCID.BloodNautilus: + case NPCID.GoblinArcher: + case NPCID.GoblinPeon: + case NPCID.GoblinSorcerer: + case NPCID.GoblinSummoner: + case NPCID.GoblinThief: + case NPCID.GoblinWarrior: + case NPCID.MisterStabby: + case NPCID.SnowBalla: + case NPCID.SnowmanGangsta: + case NPCID.Parrot: + case NPCID.PirateCaptain: + case NPCID.PirateCorsair: + case NPCID.PirateCrossbower: + case NPCID.PirateDeadeye: + case NPCID.PirateDeckhand: + case NPCID.PirateGhost: + case NPCID.PirateShipCannon: + case NPCID.MothronSpawn: + case NPCID.Mothron: + case NPCID.Butcher: + case NPCID.CreatureFromTheDeep: + case NPCID.DeadlySphere: + case NPCID.DrManFly: + case NPCID.Eyezor: + case NPCID.Frankenstein: + case NPCID.Fritz: + case NPCID.Nailhead: + case NPCID.Psycho: + case NPCID.Reaper: + case NPCID.ThePossessed: + case NPCID.SwampThing: + case NPCID.Vampire: + case NPCID.VampireBat: + case NPCID.BrainScrambler: + case NPCID.GigaZapper: + case NPCID.MartianWalker: + case NPCID.GrayGrunt: + case NPCID.MartianDrone: + case NPCID.MartianEngineer: + case NPCID.MartianOfficer: + case NPCID.RayGunner: + case NPCID.Scutlix: + case NPCID.ScutlixRider: + case NPCID.MartianTurret: + case NPCID.HeadlessHorseman: + case NPCID.Hellhound: + case NPCID.Splinterling: + case NPCID.Poltergeist: + case NPCID.Scarecrow1: + case NPCID.Scarecrow2: + case NPCID.Scarecrow3: + case NPCID.Scarecrow4: + case NPCID.Scarecrow5: + case NPCID.Scarecrow6: + case NPCID.Scarecrow7: + case NPCID.Scarecrow8: + case NPCID.Scarecrow9: + case NPCID.Scarecrow10: + case NPCID.ElfArcher: + case NPCID.ElfCopter: + case NPCID.Flocko: + case NPCID.GingerbreadMan: + case NPCID.Krampus: + case NPCID.Nutcracker: + case NPCID.NutcrackerSpinning: + case NPCID.Yeti: + case NPCID.NebulaBeast: + case NPCID.NebulaBrain: + case NPCID.NebulaHeadcrab: + case NPCID.NebulaSoldier: + case NPCID.SolarCorite: + case NPCID.SolarCrawltipedeBody: + case NPCID.SolarCrawltipedeHead: + case NPCID.SolarCrawltipedeTail: + case NPCID.SolarDrakomire: + case NPCID.SolarDrakomireRider: + case NPCID.SolarSolenian: + case NPCID.SolarSpearman: + case NPCID.SolarSroller: + case NPCID.StardustCellBig: + case NPCID.StardustCellSmall: + case NPCID.StardustJellyfishBig: + case NPCID.StardustWormBody: + case NPCID.StardustWormHead: + case NPCID.StardustWormTail: + case NPCID.StardustSoldier: + case NPCID.StardustSpiderBig: + case NPCID.StardustSpiderSmall: + case NPCID.VortexHornet: + case NPCID.VortexHornetQueen: + case NPCID.VortexLarva: + case NPCID.VortexRifleman: + case NPCID.VortexSoldier: + case NPCID.DD2DarkMageT1: + case NPCID.DD2DarkMageT3: + case NPCID.DD2OgreT2: + case NPCID.DD2OgreT3: + case NPCID.MartianSaucerCore: + case NPCID.MartianSaucerCannon: + case NPCID.MartianSaucerTurret: + case NPCID.DD2SkeletonT1: + case NPCID.DD2SkeletonT3: + case NPCID.DD2DrakinT2: + case NPCID.DD2DrakinT3: + case NPCID.DD2GoblinBomberT1: + case NPCID.DD2GoblinBomberT2: + case NPCID.DD2GoblinBomberT3: + case NPCID.DD2GoblinT1: + case NPCID.DD2GoblinT2: + case NPCID.DD2GoblinT3: + case NPCID.DD2JavelinstT1: + case NPCID.DD2JavelinstT2: + case NPCID.DD2JavelinstT3: + case NPCID.DD2KoboldFlyerT2: + case NPCID.DD2KoboldFlyerT3: + case NPCID.DD2KoboldWalkerT2: + case NPCID.DD2KoboldWalkerT3: + case NPCID.DD2LightningBugT3: + case NPCID.DD2WitherBeastT2: + case NPCID.DD2WitherBeastT3: + case NPCID.DD2WyvernT1: + case NPCID.DD2WyvernT2: + case NPCID.DD2WyvernT3: + case NPCID.AncientCultistSquidhead: + case NPCID.SlimeSpiked: + + // Buff enemy HP by 25% + npc.lifeMax = (int)Math.Round(npc.lifeMax * EnemyHPMultiplier); + + // Nerf a shitload of Master Mode enemies + // HP is nerfed by 25% (this nerf is higher due to the player not dealing any more damage in Master) + // Damage is nerfed by 15% (this nerf is lower due to the player having 100% effective defense in Master) + if (Main.masterMode) + { AdjustMasterModeStatScaling(npc); npc.defDamage = npc.damage; - break; + } - case NPCID.KingSlime: - case NPCID.EyeofCthulhu: - case NPCID.EaterofWorldsHead: - case NPCID.EaterofWorldsBody: - case NPCID.EaterofWorldsTail: - case NPCID.BrainofCthulhu: - case NPCID.Creeper: - case NPCID.QueenBee: - case NPCID.SkeletronHead: - case NPCID.SkeletronHand: - case NPCID.Deerclops: - case NPCID.WallofFlesh: - case NPCID.WallofFleshEye: - case NPCID.QueenSlimeBoss: - case NPCID.Retinazer: - case NPCID.Spazmatism: - case NPCID.TheDestroyer: - case NPCID.TheDestroyerBody: - case NPCID.TheDestroyerTail: - case NPCID.SkeletronPrime: - case NPCID.PrimeCannon: - case NPCID.PrimeLaser: - case NPCID.PrimeSaw: - case NPCID.PrimeVice: - case NPCID.Plantera: - case NPCID.PlanterasTentacle: - case NPCID.Golem: - case NPCID.GolemHead: - case NPCID.GolemHeadFree: - case NPCID.GolemFistLeft: - case NPCID.GolemFistRight: - case NPCID.HallowBoss: - case NPCID.DukeFishron: - case NPCID.CultistBoss: - case NPCID.MoonLordCore: - case NPCID.MoonLordFreeEye: - case NPCID.MoonLordHand: - case NPCID.MoonLordHead: + break; + + case NPCID.KingSlime: + case NPCID.EyeofCthulhu: + case NPCID.EaterofWorldsHead: + case NPCID.EaterofWorldsBody: + case NPCID.EaterofWorldsTail: + case NPCID.BrainofCthulhu: + case NPCID.Creeper: + case NPCID.QueenBee: + case NPCID.SkeletronHead: + case NPCID.SkeletronHand: + case NPCID.Deerclops: + case NPCID.WallofFlesh: + case NPCID.WallofFleshEye: + case NPCID.QueenSlimeBoss: + case NPCID.Retinazer: + case NPCID.Spazmatism: + case NPCID.TheDestroyer: + case NPCID.TheDestroyerBody: + case NPCID.TheDestroyerTail: + case NPCID.SkeletronPrime: + case NPCID.PrimeCannon: + case NPCID.PrimeLaser: + case NPCID.PrimeSaw: + case NPCID.PrimeVice: + case NPCID.Plantera: + case NPCID.PlanterasTentacle: + case NPCID.Golem: + case NPCID.GolemHead: + case NPCID.GolemHeadFree: + case NPCID.GolemFistLeft: + case NPCID.GolemFistRight: + case NPCID.HallowBoss: + case NPCID.DukeFishron: + case NPCID.CultistBoss: + case NPCID.MoonLordCore: + case NPCID.MoonLordFreeEye: + case NPCID.MoonLordHand: + case NPCID.MoonLordHead: + + if (Main.masterMode) AdjustMasterModeStatScaling(npc, true); - break; - } + + break; } } #endregion @@ -3448,7 +3708,7 @@ namespace CalamityMod.NPCs if (CalamityWorld.revenge || BossRushEvent.BossRushActive) { if (npc.type == NPCID.SkeletronPrime && (Main.masterMode || BossRushEvent.BossRushActive)) - index = CalamityMod.chadPrimeIcon; + index = ExtraTextureRefs.BossHeadIndex_ChadPrime; if (npc.type == NPCID.DukeFishron && (CalamityWorld.death || BossRushEvent.BossRushActive)) { @@ -5897,12 +6157,13 @@ namespace CalamityMod.NPCs if (CalamityLists.GrenadeResistIDs.Contains(projectile.type)) { // Eater of Worlds has a vanilla resist in Expert+, this gives it to him in Normal mode + // Note that Calamity reduces the vanilla resist from 80% to 60% bool hasResist = CalamityLists.EaterofWorldsIDs.Contains(npc.type) && !Main.expertMode; // Add a resist for BoC's creepers and Prehardmode worm bosses if (npc.type == NPCID.Creeper || CalamityLists.DesertScourgeIDs.Contains(npc.type) || CalamityLists.PerforatorIDs.Contains(npc.type)) hasResist = true; if (hasResist) - modifiers.SourceDamage *= 0.2f; + modifiers.SourceDamage *= 0.4f; } if (CalamityLists.pierceResistList.Contains(npc.type)) @@ -6629,6 +6890,16 @@ namespace CalamityMod.NPCs if (npc.type == NPCID.SkeletronPrime || npc.type == NPCType()) npc.frameCounter = 0D; } + // Increment the bestiary worm timer when hovering over the NPC or having their entry open. Pauses otherwise + if (npc.IsABestiaryIconDummy) + { + bestiaryWormTimer += 0.02f; + // Resets after an hour. No sane human being is looking at a bestiary entry for an hour straight + if (bestiaryWormTimer > 4320) + { + bestiaryWormTimer = 0; + } + } } // Debuff visuals. Alphabetical order as per usual, please @@ -6951,6 +7222,28 @@ namespace CalamityMod.NPCs public override bool PreDraw(NPC npc, SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { + if (npc.IsABestiaryIconDummy) + { + switch (npc.netID) + { + case NPCID.DiggerHead: + case NPCID.GiantWormHead: + case NPCID.EaterofWorldsHead: + case NPCID.WyvernHead: + case NPCID.StardustWormHead: + case NPCID.SolarCrawltipedeHead: + case NPCID.CultistDragonHead: + case NPCID.TheDestroyer: + case NPCID.LeechHead: + case NPCID.DevourerHead: + case NPCID.TombCrawlerHead: + case NPCID.DuneSplicerHead: + case NPCID.BloodEelHead: + case NPCID.BoneSerpentHead: + case NPCID.SeekerHead: + return DrawVanillaBestiaryWorms(spriteBatch, npc, drawColor); + } + } if (npc.type != NPCID.BrainofCthulhu && (npc.type != NPCID.DukeFishron || npc.ai[0] <= 9f) && npc.active) { if (CalamityClientConfig.Instance.DebuffDisplay && (npc.boss || BossHealthBarManager.MinibossHPBarList.Contains(npc.type) || BossHealthBarManager.OneToMany.ContainsKey(npc.type) || CalamityLists.needsDebuffIconDisplayList.Contains(npc.type))) @@ -7343,7 +7636,7 @@ namespace CalamityMod.NPCs } // Destroyer drawing and laser telegraphs - else if (CalamityLists.DestroyerIDs.Contains(npc.type)) + else if (CalamityLists.DestroyerIDs.Contains(npc.type) && !npc.IsABestiaryIconDummy) { Texture2D npcTexture = TextureAssets.Npc[npc.type].Value; int frameHeight = npcTexture.Height / Main.npcFrameCount[npc.type]; @@ -7469,7 +7762,7 @@ namespace CalamityMod.NPCs } } - Texture2D glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? CalamityMod.DestroyerGlowmasks[0].Value : TextureAssets.Dest[0].Value; + Texture2D glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? ExtraTextureRefs.DestroyerHeadGlowmask.Value : TextureAssets.Dest[0].Value; switch (npc.type) { default: @@ -7477,11 +7770,11 @@ namespace CalamityMod.NPCs break; case NPCID.TheDestroyerBody: - glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? CalamityMod.DestroyerGlowmasks[1].Value : TextureAssets.Dest[1].Value; + glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? ExtraTextureRefs.DestroyerBodyGlowmask.Value : TextureAssets.Dest[1].Value; break; case NPCID.TheDestroyerTail: - glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? CalamityMod.DestroyerGlowmasks[2].Value : TextureAssets.Dest[2].Value; + glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? ExtraTextureRefs.DestroyerTailGlowmask.Value : TextureAssets.Dest[2].Value; break; } @@ -7494,7 +7787,7 @@ namespace CalamityMod.NPCs else if (npc.type == NPCID.Probe && CalamityClientConfig.Instance.NewVanillaTextures) { float eyeTelegraphGateValue = (NPC.IsMechQueenUp ? DestroyerAI.ProbeLaserGateValue_Mechdusa : BossRushEvent.BossRushActive ? DestroyerAI.ProbeLaserGateValue_BossRush : revenge ? DestroyerAI.ProbeLaserGateValue_Rev : DestroyerAI.ProbeLaserGateValue) - DestroyerAI.ProbeLaserTelegraphTime; - Texture2D glowTexture = CalamityMod.ProbeGlowmask.Value; + Texture2D glowTexture = ExtraTextureRefs.ProbeGlowmask.Value; Vector2 halfSize = npc.frame.Size() / 2; SpriteEffects spriteEffects = SpriteEffects.None; if (npc.spriteDirection == -1) @@ -7805,7 +8098,7 @@ namespace CalamityMod.NPCs float eyeTelegraphGateValue = WallOfFleshAI.LaserShootGateValue - WallOfFleshAI.LaserShootTelegraphTime; if (npc.localAI[1] > eyeTelegraphGateValue || npc.localAI[2] > 0f || enraged) { - Texture2D glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? CalamityMod.WallOfFleshEyeGlowmask.Value : TextureAssets.Npc[npc.type].Value; + Texture2D glowTexture = CalamityClientConfig.Instance.NewVanillaTextures ? ExtraTextureRefs.WallOfFleshEyeGlowmask.Value : TextureAssets.Npc[npc.type].Value; Vector2 halfSize = npc.frame.Size() / 2; SpriteEffects spriteEffects = SpriteEffects.None; if (npc.spriteDirection == 1) @@ -7827,7 +8120,7 @@ namespace CalamityMod.NPCs // His afterimages I can't get to work, so fuck it else if (npc.type == NPCID.SkeletronPrime || npc.type == NPCType()) { - Texture2D npcTexture = (masterMode && revenge && npc.type == NPCID.SkeletronPrime) ? CalamityMod.ChadPrime.Value : TextureAssets.Npc[npc.type].Value; + Texture2D npcTexture = (masterMode && revenge && npc.type == NPCID.SkeletronPrime) ? ExtraTextureRefs.ChadPrime.Value : TextureAssets.Npc[npc.type].Value; int frameHeight = npcTexture.Height / Main.npcFrameCount[npc.type]; npc.frame.Y = (int)newAI[3]; @@ -7894,7 +8187,7 @@ namespace CalamityMod.NPCs { int alpha = 192; eyesColor = npc.type == NPCType() ? new Color(150, 100, 255, alpha) : new Color(255, 255, 0, alpha); - Texture2D glowTexture = npc.type == NPCID.SkeletronPrime ? CalamityMod.ChadPrimeEyeGlowmask.Value : SkeletronPrime2.EyeTexture.Value; + Texture2D glowTexture = npc.type == NPCID.SkeletronPrime ? ExtraTextureRefs.ChadPrimeEyeGlowmask.Value : SkeletronPrime2.EyeTexture.Value; spriteBatch.Draw(glowTexture, npc.Center - screenPos + new Vector2(0, npc.gfxOffY), npc.frame, eyesColor, npc.rotation, npc.frame.Size() / 2, npc.scale, spriteEffects, 0f); } else @@ -8024,6 +8317,92 @@ namespace CalamityMod.NPCs newColor.A = (byte)((float)newColor.A * A); return newColor; } + + public static bool DrawVanillaBestiaryWorms(SpriteBatch spriteBatch, NPC npc, Color drawColor) + { + npc.Opacity = 1; + int segments = 6; + int spacing = 20; + int bashLength = 0; + float bashSpeed = 0f; + int speed = 3; + float rotation = 0.6f; + Texture2D wyvernArm = TextureAssets.Npc[NPCID.WyvernLegs].Value; + Texture2D wyvernBody = TextureAssets.Npc[NPCID.WyvernBody].Value; + switch (npc.netID) + { + case NPCID.DiggerHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, segments, 24, 0.4f, Vector2.Zero, speed, 10, 10, 0.2f); + case NPCID.GiantWormHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, 8, 14, 0.6f, new Vector2(20, 0), 4, 10, 6, 0.18f); + case NPCID.EaterofWorldsHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, segments, 34, 0.2f, new Vector2(30, 0), speed, 10, 16, 0.24f); + case NPCID.WyvernHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, [wyvernArm, wyvernBody, wyvernBody, wyvernBody], 4, 28, 0.1f, new Vector2(36, 0), speed, 6, 50, 0.3f, true); + case NPCID.StardustWormHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, 8, 14, rotation, new Vector2(0, 10), 4, 10, 6, 0.18f); + case NPCID.SolarCrawltipedeHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, segments, spacing, rotation, Vector2.Zero, 6, 10, 16, 0.22f); + case NPCID.CultistDragonHead: + return DrawSpecialBestiaryWorm(spriteBatch, npc, drawColor); + case NPCID.TheDestroyer: + return DrawSpecialBestiaryWorm(spriteBatch, npc, drawColor); + case NPCID.LeechHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, 8, 14, 0.6f, new Vector2(20, 0), 4, 10, 6, 0.18f); + case NPCID.DevourerHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, segments, spacing, rotation, Vector2.Zero, speed, 20, 10, 0.2f); + case NPCID.TombCrawlerHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, 9, 14, rotation, Vector2.Zero, speed, 20, 6, 0.14f); + case NPCID.DuneSplicerHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, segments, 28, 0.4f, Vector2.Zero, speed, 10, bashLength, bashSpeed); + case NPCID.BloodEelHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, 6, 22, 0.1f, Vector2.Zero, speed, 6, 20, 0.2f, true); + case NPCID.BoneSerpentHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, 9, 16, rotation, Vector2.Zero, speed, 10, 30, 0.4f); + case NPCID.SeekerHead: + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, TextureAssets.Npc[npc.type].Value, TextureAssets.Npc[npc.type + 1].Value, segments, spacing, rotation, Vector2.Zero, speed, 20, 10, 0.2f); + } + return true; + } + + public static bool DrawSpecialBestiaryWorm(SpriteBatch spriteBatch, NPC npc, Color drawColor) + { + // This is solely for The Destroyer and the Phantasm Dragon due to having more than 1 frame each but only for specific segments + bool dragon = npc.type == NPCID.CultistDragonHead; + Texture2D headTexture = TextureAssets.Npc[npc.type].Value; + float wormTimer = npc.Calamity().bestiaryWormTimer; + // Dragon head has 3 frames, Destroyer has 1 + int frameAmt = dragon ? 3 : 1; + npc.frame = TextureAssets.Npc[npc.type].Frame(1, frameAmt, 0, 0); + Vector2 baseOffset = new Vector2(dragon ? 0 : 20, dragon ? 0 : 20); + // Buffers the segment position and rotations + float offset = -0.2f; + float startX = baseOffset.X; + float startY = baseOffset.Y; + int segmentSpacing = dragon ? 32 : 38; + int animationSpeed = 3; + int range = 10; + int headOffset = dragon ? 40 : 20; + float headSpeedOffset = dragon ? 0.2f : 0.16f; + float rotationStrength = 0.2f; + // Draw the body segments + for (int i = 4; i > 0; i--) + { + // The first segment is slightly closer to keep up with the head + float bodyOffset = i == 1 ? i * segmentSpacing * 0.4f : i * segmentSpacing - segmentSpacing * 0.5f; + + // Second dragon segment uses the arm, rest use the normal body + Texture2D toUse = i == 2 ? TextureAssets.Npc[NPCID.CultistDragonBody1].Value : TextureAssets.Npc[NPCID.CultistDragonBody2].Value; + // If it's The Destroyer instead use his texture and increase the frame count to two + if (!dragon) + toUse = TextureAssets.Npc[NPCID.TheDestroyerBody].Value; + int bodyFrameAmt = dragon ? 1 : 2; + spriteBatch.Draw(toUse, npc.position + new Vector2(startX + bodyOffset, MathF.Sin((wormTimer + offset * i) * animationSpeed) * range + startY), toUse.Frame(1, bodyFrameAmt, 0, 0), npc.GetAlpha(drawColor), npc.rotation - MathHelper.PiOver2 - MathF.Cos((wormTimer + offset * i) * animationSpeed) * MathHelper.PiOver4 * rotationStrength, new Vector2(toUse.Width * 0.5f, toUse.Height * 0.5f / bodyFrameAmt), npc.scale, SpriteEffects.FlipHorizontally, 0f); + } + // Draw the head + spriteBatch.Draw(headTexture, npc.position + new Vector2(startX + headOffset, MathF.Sin((wormTimer - headSpeedOffset) * animationSpeed) * range + startY), npc.frame, npc.GetAlpha(drawColor), npc.rotation - MathHelper.PiOver2 - MathF.Cos((wormTimer - headSpeedOffset) * animationSpeed) * MathHelper.PiOver4 * rotationStrength, new Vector2(headTexture.Width * 0.5f, headTexture.Height / (float)frameAmt), npc.scale, SpriteEffects.FlipHorizontally, 0f); + return false; + } #endregion #region Any Events @@ -8241,7 +8620,7 @@ namespace CalamityMod.NPCs CalamityPlayer mp = player.Calamity(); mp.lastSplitType = newBossTypeJustDowned; - mp.lastSplit = mp.previousSessionTotal.Add(CalamityMod.SpeedrunTimer.Elapsed); + mp.lastSplit = mp.previousSessionTotal.Add(SpeedrunTimerSystem.Elapsed); } } } @@ -8943,17 +9322,117 @@ namespace CalamityMod.NPCs #endregion #region Bestiary - public override void SetBestiary(NPC npc, Terraria.GameContent.Bestiary.BestiaryDatabase database, Terraria.GameContent.Bestiary.BestiaryEntry bestiaryEntry) + public override void SetBestiary(NPC npc, BestiaryDatabase database, BestiaryEntry bestiaryEntry) { - // Create a string array containing all an NPC's debuff resistances - string[] elements = new string[5] + // Replace vanilla bestiary flavor text for certain NPCs + // These are ordered by their order in the bestiary, if you're wondering why it seems so arbitrary lmao + switch (npc.netID) { + case NPCID.Dryad: + case NPCID.Mechanic: + case NPCID.EmpressButterfly: + case NPCID.DemonEye: + case NPCID.CataractEye: + case NPCID.DialatedEye: + case NPCID.SleepyEye: + case NPCID.GreenEye: + case NPCID.PurpleEye: + case NPCID.Wraith: + case NPCID.BloodNautilus: + case NPCID.DiggerHead: + case NPCID.GraniteGolem: + case NPCID.GreekSkeleton: + case NPCID.UndeadViking: + case NPCID.IcyMerman: + case NPCID.DesertBeast: + case NPCID.DuneSplicerHead: + case NPCID.SandShark: + case NPCID.SandsharkCorrupt: + case NPCID.SandsharkCrimson: + case NPCID.SandsharkHallow: + case NPCID.MeteorHead: + case NPCID.AngryBones: + case NPCID.AngryBonesBig: + case NPCID.AngryBonesBigMuscle: + case NPCID.AngryBonesBigHelmet: + case NPCID.BlueArmoredBones: + case NPCID.BlueArmoredBonesMace: + case NPCID.BlueArmoredBonesNoPants: + case NPCID.BlueArmoredBonesSword: + case NPCID.HellArmoredBones: + case NPCID.HellArmoredBonesSpikeShield: + case NPCID.HellArmoredBonesMace: + case NPCID.HellArmoredBonesSword: + case NPCID.RustyArmoredBonesAxe: + case NPCID.RustyArmoredBonesFlail: + case NPCID.RustyArmoredBonesSword: + case NPCID.RustyArmoredBonesSwordNoArmor: + case NPCID.SkeletonSniper: + case NPCID.TacticalSkeleton: + case NPCID.SkeletonCommando: + case NPCID.BoneLee: + case NPCID.Paladin: + case NPCID.DiabolistRed: + case NPCID.DiabolistWhite: + case NPCID.Necromancer: + case NPCID.NecromancerArmored: + case NPCID.RaggedCaster: + case NPCID.RaggedCasterOpenCoat: + case NPCID.DungeonGuardian: + case NPCID.BoneSerpentHead: + case NPCID.Demon: + case NPCID.VoodooDemon: + case NPCID.RedDevil: + case NPCID.WyvernHead: + case NPCID.Harpy: + case NPCID.MartianProbe: + case NPCID.SeekerHead: + case NPCID.DesertDjinn: + case NPCID.ChaosElemental: + case NPCID.GoblinThief: + case NPCID.GoblinSummoner: + case NPCID.GoblinSorcerer: + case NPCID.PirateCaptain: + case NPCID.MartianSaucerCore: + case NPCID.TorchGod: + case NPCID.EyeofCthulhu: + case NPCID.BrainofCthulhu: + case NPCID.SkeletronHead: + case NPCID.WallofFlesh: + case NPCID.QueenSlimeBoss: + case NPCID.Retinazer: + case NPCID.Spazmatism: + case NPCID.TheDestroyer: + case NPCID.SkeletronPrime: + case NPCID.Plantera: + case NPCID.HallowBoss: + case NPCID.Golem: + case NPCID.DukeFishron: + case NPCID.CultistBoss: + case NPCID.CultistDevote: + case NPCID.LunarTowerNebula: + case NPCID.LunarTowerSolar: + case NPCID.LunarTowerVortex: + case NPCID.LunarTowerStardust: + case NPCID.MoonLordCore: + FlavorTextBestiaryInfoElement f = new("Hi CS0120"); + bestiaryEntry.Info.RemoveAll(i => i.GetType() == f.GetType()); + bestiaryEntry.Info.Add(new FlavorTextBestiaryInfoElement(CalamityUtils.GetTextValue($"Bestiary.Vanilla.{Lang.GetNPCName(npc.netID).Key}"))); + break; + default: + break; + + } + + // Create a string array containing all an NPC's debuff resistances + string[] elements = + [ NPCDebuffResistText(npc.Calamity().VulnerableToHeat, CalamityUtils.GetTextValue("UI.DebuffSystem.Heat")), NPCDebuffResistText(npc.Calamity().VulnerableToSickness, CalamityUtils.GetTextValue("UI.DebuffSystem.Sickness")), NPCDebuffResistText(npc.Calamity().VulnerableToCold, CalamityUtils.GetTextValue("UI.DebuffSystem.Cold")), NPCDebuffResistText(npc.Calamity().VulnerableToElectricity, CalamityUtils.GetTextValue("UI.DebuffSystem.Electricity")), NPCDebuffResistText(npc.Calamity().VulnerableToWater, CalamityUtils.GetTextValue("UI.DebuffSystem.Water")) - }; + ]; // Insert the debuff info into the NPC's bestiary entry bestiaryEntry.Info.Insert(0, new BestiaryDebuffInfo(elements)); @@ -8969,6 +9448,28 @@ namespace CalamityMod.NPCs { bestiaryEntry.AddTags(BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.SurfaceMushroom); } + + // Remove the static portraits from vanilla worms so that Calamity's worm movement can be added in PreDraw + switch (npc.netID) + { + case NPCID.DiggerHead: + case NPCID.GiantWormHead: + case NPCID.EaterofWorldsHead: + case NPCID.WyvernHead: + case NPCID.StardustWormHead: + case NPCID.SolarCrawltipedeHead: + case NPCID.CultistDragonHead: + case NPCID.TheDestroyer: + case NPCID.LeechHead: + case NPCID.DevourerHead: + case NPCID.TombCrawlerHead: + case NPCID.DuneSplicerHead: + case NPCID.BloodEelHead: + case NPCID.BoneSerpentHead: + case NPCID.SeekerHead: + NPCID.Sets.NPCBestiaryDrawOffset[npc.type] = NPCID.Sets.NPCBestiaryDrawOffset[npc.type] with { CustomTexturePath = null }; + break; + } } public static string NPCDebuffResistText(bool? effectiveness, string name) diff --git a/NPCs/CalamityGlobalNPCLoot.cs b/NPCs/CalamityGlobalNPCLoot.cs index 3b1fd71f2d..639b336815 100644 --- a/NPCs/CalamityGlobalNPCLoot.cs +++ b/NPCs/CalamityGlobalNPCLoot.cs @@ -1767,9 +1767,6 @@ DukeEditFailed: if (npc.AnyInteractions()) SplittingWormBestiaryUpdate(npc); - // Check whether bosses should be spawned naturally as a result of this NPC's death. - CheckBossSpawn(npc); - // Determine whether this NPC is the second Twin killed in a fight, regardless of which Twin it is. bool lastTwinStanding = false; if (npc.type == NPCID.Retinazer) @@ -2138,88 +2135,5 @@ DukeEditFailed: return true; } #endregion - - #region Check Boss Spawn - // TODO -- not loot code, should be moved eventually - private void CheckBossSpawn(NPC npc) - { - if ((npc.type == ModContent.NPCType() || npc.type == ModContent.NPCType() || npc.type == ModContent.NPCType() || - npc.type == ModContent.NPCType()) && !NPC.AnyNPCs(ModContent.NPCType()) && !DownedBossSystem.downedPolterghast) - { - CalamityMod.ghostKillCount++; - if (CalamityMod.ghostKillCount == 10) - { - string key = "Mods.CalamityMod.Status.Boss.GhostBossText2"; - Color messageColor = Color.Cyan; - - CalamityUtils.DisplayLocalizedText(key, messageColor); - } - else if (CalamityMod.ghostKillCount == 20) - { - string key = "Mods.CalamityMod.Status.Boss.GhostBossText3"; - Color messageColor = Color.Cyan; - - CalamityUtils.DisplayLocalizedText(key, messageColor); - } - - if (CalamityMod.ghostKillCount >= 30 && Main.netMode != NetmodeID.MultiplayerClient) - { - int lastPlayer = npc.lastInteraction; - - if (!Main.player[lastPlayer].active || Main.player[lastPlayer].dead) - { - lastPlayer = npc.FindClosestPlayer(); - } - - if (lastPlayer >= 0) - { - SoundEngine.PlaySound(Polterghast.Polterghast.SpawnSound, Main.player[lastPlayer].Center); - NPC.SpawnOnPlayer(lastPlayer, ModContent.NPCType()); - CalamityMod.ghostKillCount = 0; - } - } - } - - bool normalShark = npc.type == NPCID.SandShark || npc.type == NPCID.SandsharkHallow || npc.type == NPCID.SandsharkCorrupt || npc.type == NPCID.SandsharkCrimson; - if (NPC.downedPlantBoss && (normalShark || (npc.type == ModContent.NPCType() && Main.zenithWorld)) && !NPC.AnyNPCs(ModContent.NPCType())) - { - CalamityMod.sharkKillCount++; - if (CalamityMod.sharkKillCount == 4) - { - string key = "Mods.CalamityMod.Status.Boss.SandSharkText"; - Color messageColor = Color.Goldenrod; - - CalamityUtils.DisplayLocalizedText(key, messageColor); - } - else if (CalamityMod.sharkKillCount == 8) - { - string key = "Mods.CalamityMod.Status.Boss.SandSharkText2"; - Color messageColor = Color.Goldenrod; - - CalamityUtils.DisplayLocalizedText(key, messageColor); - } - if (CalamityMod.sharkKillCount >= 10 && Main.netMode != NetmodeID.MultiplayerClient) - { - if (!Main.player[Main.myPlayer].dead && Main.player[Main.myPlayer].active) - { - SoundEngine.PlaySound(Mauler.RoarSound, Main.player[Main.myPlayer].Center); - } - - int lastPlayer = npc.lastInteraction; - - if (!Main.player[lastPlayer].active || Main.player[lastPlayer].dead) - { - lastPlayer = npc.FindClosestPlayer(); - } - - if (lastPlayer >= 0) - { - NPC.SpawnOnPlayer(lastPlayer, ModContent.NPCType()); - CalamityMod.sharkKillCount = -5; - } - } - } - } - #endregion } } diff --git a/NPCs/CalamityGlobalTownNPC.cs b/NPCs/CalamityGlobalTownNPC.cs index 391fc74071..581fae52d5 100644 --- a/NPCs/CalamityGlobalTownNPC.cs +++ b/NPCs/CalamityGlobalTownNPC.cs @@ -244,7 +244,7 @@ namespace CalamityMod.NPCs "Merasmus", // <@!288066987819663360> (spiderprovidence) "Habolo", // <@!163028025494077441> (hellgoat2) "Ortho", // <@!264984390910738432> (worcuus) - "Chris Tallballs", // <@!770211589076418571> (bewearium) + "Chris Tallballs", // <@!770211589076418571> (vysterx) (previously: bewearium) "Syethas", // <@!325413275066171393> (cosmicstariight) "Nextdoor Psycho", // <@!173261518572486656> (nextdoorpsycho) }; @@ -1164,8 +1164,8 @@ namespace CalamityMod.NPCs .AddWithCustomValue(ItemID.NaturesGift, Item.buyPrice(gold: 10)) .Add(ItemType()) .AddWithCustomValue(ItemID.Grapes, Item.buyPrice(gold: 2, silver: 50), Condition.HappyEnough, Condition.DownedSkeletron) - .Add(ItemID.CorruptSeeds, Condition.CrimsonWorld, Condition.InGraveyard) - .Add(ItemID.CrimsonSeeds, Condition.CorruptWorld, Condition.InGraveyard); + .Add(ItemID.CorruptSeeds, Condition.CrimsonWorld, Condition.InGraveyard, Condition.PreHardmode) + .Add(ItemID.CrimsonSeeds, Condition.CorruptWorld, Condition.InGraveyard, Condition.PreHardmode); // Vanilla sells these in Hardmode, we just make them available at all times } if (type == NPCID.GoblinTinkerer) diff --git a/NPCs/CalamityNaturalSpawnBossNPC.cs b/NPCs/CalamityNaturalSpawnBossNPC.cs new file mode 100644 index 0000000000..7d49b2e894 --- /dev/null +++ b/NPCs/CalamityNaturalSpawnBossNPC.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.NPCs.AcidRain; +using CalamityMod.NPCs.Astral; +using CalamityMod.NPCs.NormalNPCs; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.NPCs +{ + public sealed class CalamityNaturalSpawnBossNPC : GlobalNPC + { + public override bool InstancePerEntity => false; + + public static int ghostKillCount = 0; + public static int sharkKillCount = 0; + + private static int[] _PolterghastTriggerNPCS; + private static int[] _GreatSharkTriggerNPCS; + + public override void SetStaticDefaults() + { + ghostKillCount = 0; + sharkKillCount = 0; + + _PolterghastTriggerNPCS = [ + ModContent.NPCType(), + ModContent.NPCType(), + ModContent.NPCType(), + ModContent.NPCType() + ]; + + _GreatSharkTriggerNPCS = [ + NPCID.SandShark, + NPCID.SandsharkHallow, + NPCID.SandsharkCorrupt, + NPCID.SandsharkCrimson + ]; + } + + public override void Unload() + { + _PolterghastTriggerNPCS = null; + _GreatSharkTriggerNPCS = null; + } + + public override void OnKill(NPC npc) + { + CheckPolterghastCondition(npc); + CheckGreatSandSharkCondition(npc); + } + + private static void CheckPolterghastCondition(NPC slainedNPC) + { + if (DownedBossSystem.downedPolterghast) + return; + + if (NPC.AnyNPCs(ModContent.NPCType())) + return; + + if (!_PolterghastTriggerNPCS.Contains(slainedNPC.type)) + return; + + ghostKillCount++; + if (ghostKillCount == 10) + { + string key = "Mods.CalamityMod.Status.Boss.GhostBossText2"; + Color messageColor = Color.Cyan; + + CalamityUtils.DisplayLocalizedText(key, messageColor); + } + else if (ghostKillCount == 20) + { + string key = "Mods.CalamityMod.Status.Boss.GhostBossText3"; + Color messageColor = Color.Cyan; + + CalamityUtils.DisplayLocalizedText(key, messageColor); + } + + if (ghostKillCount >= 30 && Main.netMode != NetmodeID.MultiplayerClient) + { + int lastPlayer = slainedNPC.lastInteraction; + + if (!Main.player[lastPlayer].active || Main.player[lastPlayer].dead) + { + lastPlayer = slainedNPC.FindClosestPlayer(); + } + + if (lastPlayer >= 0) + { + SoundEngine.PlaySound(Polterghast.Polterghast.SpawnSound, Main.player[lastPlayer].Center); + NPC.SpawnOnPlayer(lastPlayer, ModContent.NPCType()); + ghostKillCount = 0; + } + } + } + + private static void CheckGreatSandSharkCondition(NPC slainedNPC) + { + if (!NPC.downedPlantBoss) + return; + + if (NPC.AnyNPCs(ModContent.NPCType())) + return; + + var fusionFeeder = slainedNPC.type == ModContent.NPCType() && Main.zenithWorld; + if (!_GreatSharkTriggerNPCS.Contains(slainedNPC.type) && !fusionFeeder) + return; + + sharkKillCount++; + if (sharkKillCount == 4) + { + string key = "Mods.CalamityMod.Status.Boss.SandSharkText"; + Color messageColor = Color.Goldenrod; + + CalamityUtils.DisplayLocalizedText(key, messageColor); + } + else if (sharkKillCount == 8) + { + string key = "Mods.CalamityMod.Status.Boss.SandSharkText2"; + Color messageColor = Color.Goldenrod; + + CalamityUtils.DisplayLocalizedText(key, messageColor); + } + if (sharkKillCount >= 10 && Main.netMode != NetmodeID.MultiplayerClient) + { + if (!Main.player[Main.myPlayer].dead && Main.player[Main.myPlayer].active) + { + SoundEngine.PlaySound(Mauler.RoarSound, Main.player[Main.myPlayer].Center); + } + + int lastPlayer = slainedNPC.lastInteraction; + + if (!Main.player[lastPlayer].active || Main.player[lastPlayer].dead) + { + lastPlayer = slainedNPC.FindClosestPlayer(); + } + + if (lastPlayer >= 0) + { + NPC.SpawnOnPlayer(lastPlayer, ModContent.NPCType()); + sharkKillCount = -5; + } + } + } + } +} diff --git a/NPCs/Cryogen/Cryogen.cs b/NPCs/Cryogen/Cryogen.cs index e3d1a476fd..ff3fb30f3c 100644 --- a/NPCs/Cryogen/Cryogen.cs +++ b/NPCs/Cryogen/Cryogen.cs @@ -38,7 +38,6 @@ using Terraria.ModLoader; namespace CalamityMod.NPCs.Cryogen { - [AutoloadBossHead] [LongDistanceNetSync] // Cryogen follows you forever like Queen Bee in vanilla, So we need this to sync it's position on minimap public class Cryogen : ModNPC { @@ -66,16 +65,13 @@ namespace CalamityMod.NPCs.Cryogen public static int cryoIconIndex; public static int pyroIconIndex; - internal static void LoadHeadIcons() + public override void Load() { string cryoIconPath = "CalamityMod/NPCs/Cryogen/Cryogen_Phase1_Head_Boss"; string pyroIconPath = "CalamityMod/NPCs/Cryogen/Pyrogen_Head_Boss"; - - CalamityMod.Instance.AddBossHeadTexture(cryoIconPath, -1); - cryoIconIndex = ModContent.GetModBossHeadSlot(cryoIconPath); - - CalamityMod.Instance.AddBossHeadTexture(pyroIconPath, -1); - pyroIconIndex = ModContent.GetModBossHeadSlot(pyroIconPath); + + cryoIconIndex = CalamityMod.Instance.AddBossHeadTexture(cryoIconPath, -1); + pyroIconIndex = CalamityMod.Instance.AddBossHeadTexture(pyroIconPath, -1); } public override void SetStaticDefaults() @@ -265,9 +261,9 @@ namespace CalamityMod.NPCs.Cryogen } if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); else if (!Main.raining && !BossRushEvent.BossRushActive) - CalamityUtils.StartRain(); + CalamityWorld.StartRain(); if (!player.active || player.dead) { diff --git a/NPCs/DesertScourge/DesertScourgeHead.cs b/NPCs/DesertScourge/DesertScourgeHead.cs index faf604d439..36b16e13de 100644 --- a/NPCs/DesertScourge/DesertScourgeHead.cs +++ b/NPCs/DesertScourge/DesertScourgeHead.cs @@ -943,7 +943,7 @@ namespace CalamityMod.NPCs.DesertScourge CalamityUtils.DisplayLocalizedText(key2, messageColor2); if (!Terraria.GameContent.Events.Sandstorm.Happening) - CalamityUtils.StartSandstorm(); + CalamityWorld.StartSandstorm(); } // Mark Desert Scourge as dead. diff --git a/NPCs/DevourerofGods/CosmicGuardianHead.cs b/NPCs/DevourerofGods/CosmicGuardianHead.cs index 661f9761eb..bc2501a11f 100644 --- a/NPCs/DevourerofGods/CosmicGuardianHead.cs +++ b/NPCs/DevourerofGods/CosmicGuardianHead.cs @@ -33,7 +33,6 @@ namespace CalamityMod.NPCs.DevourerofGods { Scale = 0.75f, PortraitScale = 0.75f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/CosmicGuardian_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 40 }; @@ -365,6 +364,12 @@ namespace CalamityMod.NPCs.DevourerofGods Texture2D texture2D15 = TextureAssets.Npc[NPC.type].Value; Vector2 halfSizeTexture = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / 2)); + + if (NPC.IsABestiaryIconDummy) + { + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, texture2D15, TextureAssets.Npc[ModContent.NPCType()].Value, 8, 26, 0.2f, new Vector2(-10, 0), 4, 5); + } + Vector2 distFromHead3 = NPC.Center - screenPos; distFromHead3 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height)) * NPC.scale / 2f; distFromHead3 += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY); diff --git a/NPCs/DevourerofGods/DevourerofGodsBody.cs b/NPCs/DevourerofGods/DevourerofGodsBody.cs index 3bdcc568fc..b78344a2d5 100644 --- a/NPCs/DevourerofGods/DevourerofGodsBody.cs +++ b/NPCs/DevourerofGods/DevourerofGodsBody.cs @@ -25,12 +25,10 @@ namespace CalamityMod.NPCs.DevourerofGods { public static int phase2IconIndex; - internal static void LoadHeadIcons() + public override void Load() { string phase2IconPath = "CalamityMod/NPCs/DevourerofGods/DevourerofGodsBodyS_Head_Boss"; - - CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); - phase2IconIndex = ModContent.GetModBossHeadSlot(phase2IconPath); + phase2IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); } private const float LaserVelocityMultiplierMin = 0.5f; diff --git a/NPCs/DevourerofGods/DevourerofGodsHead.cs b/NPCs/DevourerofGods/DevourerofGodsHead.cs index e6028ace8f..3532c04d4d 100644 --- a/NPCs/DevourerofGods/DevourerofGodsHead.cs +++ b/NPCs/DevourerofGods/DevourerofGodsHead.cs @@ -56,16 +56,13 @@ namespace CalamityMod.NPCs.DevourerofGods public static Asset Phase2Texture_Glow; public static Asset Phase2Texture_Glow2; - internal static void LoadHeadIcons() + public override void Load() { string phase1IconPath = "CalamityMod/NPCs/DevourerofGods/DevourerofGodsHead_Head_Boss"; string phase2IconPath = "CalamityMod/NPCs/DevourerofGods/DevourerofGodsHeadS_Head_Boss"; - - CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); - phase1IconIndex = ModContent.GetModBossHeadSlot(phase1IconPath); - - CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); - phase2IconIndex = ModContent.GetModBossHeadSlot(phase2IconPath); + + phase1IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); + phase2IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); } // Laser velocity @@ -168,7 +165,6 @@ namespace CalamityMod.NPCs.DevourerofGods { Scale = 0.6f, PortraitScale = 0.6f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/DevourerofGods_Bestiary", PortraitPositionXOverride = 60, PortraitPositionYOverride = 40 }; @@ -355,7 +351,7 @@ namespace CalamityMod.NPCs.DevourerofGods // Stop rain if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); // Get a target (time is checked in the second check to ensure a new target isn't being set constantly) if (NPC.target < 0 || NPC.target == Main.maxPlayers || Main.player[NPC.target].dead || !Main.player[NPC.target].active) @@ -2633,7 +2629,9 @@ namespace CalamityMod.NPCs.DevourerofGods Texture2D texture2D15 = useOtherTextures ? Phase2Texture.Value : TextureAssets.Npc[NPC.type].Value; Vector2 halfSizeTexture = new Vector2(texture2D15.Width / 2, texture2D15.Height / 2); if (NPC.IsABestiaryIconDummy) - NPC.frame = texture2D15.Frame(); + { + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, texture2D15, DevourerofGodsBody.Phase2Texture.Value, 4, 26, 0.5f, new Vector2(30, 10), 2, 20); + } Vector2 drawLocation = NPC.Center - screenPos; drawLocation -= new Vector2(texture2D15.Width, texture2D15.Height) * NPC.scale / 2f; diff --git a/NPCs/DevourerofGods/DevourerofGodsTail.cs b/NPCs/DevourerofGods/DevourerofGodsTail.cs index 895ded17e2..fe52904f8a 100644 --- a/NPCs/DevourerofGods/DevourerofGodsTail.cs +++ b/NPCs/DevourerofGods/DevourerofGodsTail.cs @@ -31,16 +31,13 @@ namespace CalamityMod.NPCs.DevourerofGods public static Asset Phase2Texture_Glow; public static Asset Phase2Texture_Glow2; - internal static void LoadHeadIcons() + public override void Load() { string phase1IconPath = "CalamityMod/NPCs/DevourerofGods/DevourerofGodsTail_Head_Boss"; string phase2IconPath = "CalamityMod/NPCs/DevourerofGods/DevourerofGodsTailS_Head_Boss"; - - CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); - phase1IconIndex = ModContent.GetModBossHeadSlot(phase1IconPath); - - CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); - phase2IconIndex = ModContent.GetModBossHeadSlot(phase2IconPath); + + phase1IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); + phase2IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); } private int invinceTime = 720; diff --git a/NPCs/ExoMechs/Apollo/Apollo.cs b/NPCs/ExoMechs/Apollo/Apollo.cs index 67238d32a2..fa2a0044dc 100644 --- a/NPCs/ExoMechs/Apollo/Apollo.cs +++ b/NPCs/ExoMechs/Apollo/Apollo.cs @@ -32,16 +32,13 @@ namespace CalamityMod.NPCs.ExoMechs.Apollo public static Asset GlowTexture; - internal static void LoadHeadIcons() + public override void Load() { string phase1IconPath = "CalamityMod/NPCs/ExoMechs/Apollo/ApolloHead"; string phase2IconPath = "CalamityMod/NPCs/ExoMechs/Apollo/ApolloPhase2Head"; - - CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); - phase1IconIndex = ModContent.GetModBossHeadSlot(phase1IconPath); - - CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); - phase2IconIndex = ModContent.GetModBossHeadSlot(phase2IconPath); + + phase1IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); + phase2IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); } public enum Phase diff --git a/NPCs/ExoMechs/Artemis/Artemis.cs b/NPCs/ExoMechs/Artemis/Artemis.cs index 70737fc4e4..cbd0ba8e18 100644 --- a/NPCs/ExoMechs/Artemis/Artemis.cs +++ b/NPCs/ExoMechs/Artemis/Artemis.cs @@ -44,16 +44,13 @@ namespace CalamityMod.NPCs.ExoMechs.Artemis public static Asset GlowTexture; - internal static void LoadHeadIcons() + public override void Load() { string phase1IconPath = "CalamityMod/NPCs/ExoMechs/Artemis/ArtemisHead"; string phase2IconPath = "CalamityMod/NPCs/ExoMechs/Artemis/ArtemisPhase2Head"; - - CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); - phase1IconIndex = ModContent.GetModBossHeadSlot(phase1IconPath); - - CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); - phase2IconIndex = ModContent.GetModBossHeadSlot(phase2IconPath); + + phase1IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); + phase2IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); } public enum Phase diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs index 889dec6b6d..acf7edb991 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs @@ -23,16 +23,13 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos public static int normalIconIndex; public static int vulnerableIconIndex; - internal static void LoadHeadIcons() + public override void Load() { string normalIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosNormalBody"; string vulnerableIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosVulnerableBody"; - - CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); - normalIconIndex = ModContent.GetModBossHeadSlot(normalIconPath); - - CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); - vulnerableIconIndex = ModContent.GetModBossHeadSlot(vulnerableIconPath); + + normalIconIndex = CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); + vulnerableIconIndex = CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); } // Whether the body is venting heat or not, it is vulnerable to damage during venting diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs index d657a52918..60dfba869b 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs @@ -23,16 +23,13 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos public static int normalIconIndex; public static int vulnerableIconIndex; - internal static void LoadHeadIcons() + public override void Load() { string normalIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosNormalBody2"; string vulnerableIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosVulnerableBody2"; - - CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); - normalIconIndex = ModContent.GetModBossHeadSlot(normalIconPath); - - CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); - vulnerableIconIndex = ModContent.GetModBossHeadSlot(vulnerableIconPath); + + normalIconIndex = CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); + vulnerableIconIndex = CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); } // Whether the body is venting heat or not, it is vulnerable to damage during venting diff --git a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs index ef027b0b35..41787b1f86 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs @@ -47,16 +47,13 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos public static Asset ReticleTopTexture; public static Asset ReticleBottomTexture; - internal static void LoadHeadIcons() + public override void Load() { string normalIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosNormalHead"; string vulnerableIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosVulnerableHead"; - - CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); - normalIconIndex = ModContent.GetModBossHeadSlot(normalIconPath); - - CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); - vulnerableIconIndex = ModContent.GetModBossHeadSlot(vulnerableIconPath); + + normalIconIndex = CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); + vulnerableIconIndex = CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); } public enum Phase @@ -144,7 +141,6 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { Scale = 0.65f, PortraitScale = 0.6f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/Thanatos_Bestiary", PortraitPositionXOverride = 40 }; value.Position.X += 52f; @@ -1116,6 +1112,32 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Texture2D texture = TextureAssets.Npc[NPC.type].Value; Vector2 vector = new Vector2(TextureAssets.Npc[NPC.type].Value.Width / 2, TextureAssets.Npc[NPC.type].Value.Height / Main.npcFrameCount[NPC.type] / 2); + // Reimplementation of CalamityUtils.DrawAnimatedBestiaryWorm but tweaked due to Thanatos' animations + if (NPC.IsABestiaryIconDummy) + { + NPC.frame = texture.Frame(); + // Buffers the segment position and rotations + float offset = -0.2f; + float startX = 60; + float startY = 70; + int segmentSpacing = 40; + int animationSpeed = 5; + float wormTimer = NPC.Calamity().bestiaryWormTimer; + // Draw the body segments + for (int i = 3; i > 0; i--) + { + // The first segment is slightly closer to keep up with the head + float bodyOffset = i == 1 ? i * segmentSpacing * 0.4f : i * segmentSpacing - segmentSpacing * 0.5f; + + Texture2D toUse = i % 2 == 1 ? TextureAssets.Npc[ModContent.NPCType()].Value : TextureAssets.Npc[ModContent.NPCType()].Value; + spriteBatch.Draw(toUse, NPC.position + new Vector2(startX + bodyOffset, MathF.Sin((wormTimer + offset * i) * animationSpeed) * 2 + startY), toUse.Frame(1, 5, 0, 0), NPC.GetAlpha(drawColor), NPC.rotation - MathHelper.PiOver2 - MathF.Cos((wormTimer + offset * i) * animationSpeed) * MathHelper.PiOver4 * 0.075f, new Vector2(toUse.Width / 2, toUse.Width / 10), NPC.scale, SpriteEffects.None, 0f); + } + // Draw the head + spriteBatch.Draw(texture, NPC.position + new Vector2(startX + 24, MathF.Sin(wormTimer * animationSpeed) * 2 + startY), texture.Frame(1, 5, 0, 0), NPC.GetAlpha(drawColor), NPC.rotation - MathHelper.PiOver2 - MathF.Cos(wormTimer * animationSpeed) * MathHelper.PiOver4 * 0.075f, new Vector2(texture.Width * 0.5f, texture.Height / 5), NPC.scale, SpriteEffects.None, 0f); + + return false; + } + Vector2 center = NPC.Center - screenPos; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[NPC.type]) * NPC.scale / 2f; center += vector * NPC.scale + new Vector2(0f, NPC.gfxOffY); diff --git a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs index 004df1e829..05054f02de 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs @@ -23,16 +23,13 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos public static int normalIconIndex; public static int vulnerableIconIndex; - internal static void LoadHeadIcons() + public override void Load() { string normalIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosNormalTail"; string vulnerableIconPath = "CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosVulnerableTail"; - - CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); - normalIconIndex = ModContent.GetModBossHeadSlot(normalIconPath); - - CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); - vulnerableIconIndex = ModContent.GetModBossHeadSlot(vulnerableIconPath); + + normalIconIndex = CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); + vulnerableIconIndex = CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); } // Whether the tail is venting heat or not, it is vulnerable to damage during venting diff --git a/NPCs/GreatSandShark/GreatSandShark.cs b/NPCs/GreatSandShark/GreatSandShark.cs index c0d7469cc5..05e4e6f881 100644 --- a/NPCs/GreatSandShark/GreatSandShark.cs +++ b/NPCs/GreatSandShark/GreatSandShark.cs @@ -118,7 +118,7 @@ namespace CalamityMod.NPCs.GreatSandShark if (!Terraria.GameContent.Events.Sandstorm.Happening) { - CalamityUtils.StartSandstorm(); + CalamityWorld.StartSandstorm(); CalamityNetcode.SyncWorld(); } diff --git a/NPCs/HiveMind/HiveMind.cs b/NPCs/HiveMind/HiveMind.cs index bd6e05f57b..5d863f1b6d 100644 --- a/NPCs/HiveMind/HiveMind.cs +++ b/NPCs/HiveMind/HiveMind.cs @@ -44,16 +44,13 @@ namespace CalamityMod.NPCs.HiveMind public static int normalIconIndex; public static int phase2IconIndex; - internal static void LoadHeadIcons() + public override void Load() { string normalIconPath = "CalamityMod/NPCs/HiveMind/HiveMind_Head_Boss"; string phase2IconPath = "CalamityMod/NPCs/HiveMind/HiveMindP2_Head_Boss"; - - CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); - normalIconIndex = ModContent.GetModBossHeadSlot(normalIconPath); - - CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); - phase2IconIndex = ModContent.GetModBossHeadSlot(phase2IconPath); + + normalIconIndex = CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); + phase2IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); } // This block of values can be modified in SetDefaults() based on difficulty mode or something diff --git a/NPCs/NormalNPCs/ArmoredDiggerHead.cs b/NPCs/NormalNPCs/ArmoredDiggerHead.cs index d25ec0ad3b..33ee0968e7 100644 --- a/NPCs/NormalNPCs/ArmoredDiggerHead.cs +++ b/NPCs/NormalNPCs/ArmoredDiggerHead.cs @@ -5,10 +5,11 @@ using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Weapons.Summon; using CalamityMod.World; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; +using Terraria.GameContent; using Terraria.GameContent.Bestiary; -using Terraria.GameContent.ItemDropRules; using Terraria.ID; using Terraria.ModLoader; @@ -23,7 +24,6 @@ namespace CalamityMod.NPCs.NormalNPCs { NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/ArmoredDigger_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 40 }; @@ -490,8 +490,8 @@ namespace CalamityMod.NPCs.NormalNPCs { npcLoot.Add(ModContent.ItemType(), 1, 4, 8); npcLoot.Add(ModContent.ItemType(), 1, 4, 8); - npcLoot.AddIf(() => Main.zenithWorld, ModContent.ItemType(), 1, 3, 6); - npcLoot.AddIf(() => Main.zenithWorld, ModContent.ItemType(), 10); + npcLoot.AddIf(() => Main.zenithWorld, ModContent.ItemType(), 1, 3, 6, ui: false); + npcLoot.AddIf(() => Main.zenithWorld, ModContent.ItemType(), 10, ui: false); } public override void ModifyTypeName(ref string typeName) @@ -511,5 +511,13 @@ namespace CalamityMod.NPCs.NormalNPCs } else return null; } + public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) + { + if (NPC.IsABestiaryIconDummy) + { + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 4, 26, 0.6f, new Vector2(10, -10), 4, 16); + } + return true; + } } } diff --git a/NPCs/NormalNPCs/Bohldohr.cs b/NPCs/NormalNPCs/Bohldohr.cs index 222b7849e5..b48e26de4c 100644 --- a/NPCs/NormalNPCs/Bohldohr.cs +++ b/NPCs/NormalNPCs/Bohldohr.cs @@ -1,4 +1,5 @@ -using CalamityMod.Items.Placeables.Banners; +using CalamityMod.Items.Placeables; +using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.SummonItems; using CalamityMod.NPCs.CalamityAIs.CalamityRegularEnemyAIs; using CalamityMod.NPCs.Other; @@ -99,6 +100,7 @@ namespace CalamityMod.NPCs.NormalNPCs public override void ModifyNPCLoot(NPCLoot npcLoot) { npcLoot.Add(ItemID.LihzahrdBrick, 1, 10, 26); + npcLoot.Add(ModContent.ItemType(), 1, 10, 26); npcLoot.Add(ItemID.LunarTabletFragment, 7, 10, 26); npcLoot.Add(ItemID.LihzahrdPowerCell, 50); npcLoot.AddIf(() => DownedBossSystem.downedCalamitas && DownedBossSystem.downedExoMechs && Main.zenithWorld, ModContent.ItemType(), 2, ui: false); diff --git a/NPCs/NormalNPCs/CladCrab.cs b/NPCs/NormalNPCs/CladCrab.cs index 580344f3a3..9a644b624a 100644 --- a/NPCs/NormalNPCs/CladCrab.cs +++ b/NPCs/NormalNPCs/CladCrab.cs @@ -17,7 +17,7 @@ namespace CalamityMod.NPCs.NormalNPCs { public override void SetStaticDefaults() { - Main.npcFrameCount[NPC.type] = 7; + Main.npcFrameCount[NPC.type] = 8; NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { SpriteDirection = 1 @@ -250,7 +250,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (NPC.velocity.X == 0f) { - NPC.frame.Y = frameHeight * 1; + NPC.frame.Y = 0; NPC.frameCounter = 0.0; return; } diff --git a/NPCs/NormalNPCs/CladCrab.png b/NPCs/NormalNPCs/CladCrab.png index 53d950960b..87d6986193 100644 Binary files a/NPCs/NormalNPCs/CladCrab.png and b/NPCs/NormalNPCs/CladCrab.png differ diff --git a/NPCs/NormalNPCs/Foveanator.cs b/NPCs/NormalNPCs/Foveanator.cs index 801be02d26..99a94b5677 100644 --- a/NPCs/NormalNPCs/Foveanator.cs +++ b/NPCs/NormalNPCs/Foveanator.cs @@ -22,7 +22,6 @@ using Terraria.ModLoader; namespace CalamityMod.NPCs.NormalNPCs { - [AutoloadBossHead] public class Foveanator : ModNPC { public static int phase1IconIndex; @@ -30,16 +29,13 @@ namespace CalamityMod.NPCs.NormalNPCs public static Asset GlowTexture; - internal static void LoadHeadIcons() + public override void Load() { string phase1IconPath = "CalamityMod/NPCs/NormalNPCs/Foveanator_Head_Boss"; string phase2IconPath = "CalamityMod/NPCs/NormalNPCs/Foveanator_Phase2_Head_Boss"; - - CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); - phase1IconIndex = ModContent.GetModBossHeadSlot(phase1IconPath); - - CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); - phase2IconIndex = ModContent.GetModBossHeadSlot(phase2IconPath); + + phase1IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); + phase2IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase2IconPath, -1); } public override void SetStaticDefaults() diff --git a/NPCs/NormalNPCs/Shroomble.cs b/NPCs/NormalNPCs/Shroomble.cs index 45548a73dc..5527aa4cfc 100644 --- a/NPCs/NormalNPCs/Shroomble.cs +++ b/NPCs/NormalNPCs/Shroomble.cs @@ -16,7 +16,7 @@ namespace CalamityMod.NPCs.NormalNPCs { public override void SetStaticDefaults() { - Main.npcFrameCount[NPC.type] = 7; + Main.npcFrameCount[NPC.type] = 8; Main.npcCatchable[NPC.type] = true; NPCID.Sets.CountsAsCritter[NPC.type] = true; NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() @@ -130,7 +130,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (NPC.velocity.X == 0f) { - NPC.frame.Y = frameHeight * 1; + NPC.frame.Y = 0; NPC.frameCounter = 0.0; return; } diff --git a/NPCs/NormalNPCs/Shroomble.png b/NPCs/NormalNPCs/Shroomble.png index 5388a66e89..d459a2529a 100644 Binary files a/NPCs/NormalNPCs/Shroomble.png and b/NPCs/NormalNPCs/Shroomble.png differ diff --git a/NPCs/Perforator/PerforatorHeadLarge.cs b/NPCs/Perforator/PerforatorHeadLarge.cs index 28d91fd296..44935f2b57 100644 --- a/NPCs/Perforator/PerforatorHeadLarge.cs +++ b/NPCs/Perforator/PerforatorHeadLarge.cs @@ -35,7 +35,6 @@ namespace CalamityMod.NPCs.Perforator { Scale = 0.75f, PortraitScale = 0.75f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/PerforatorLarge_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 40 }; @@ -533,7 +532,10 @@ namespace CalamityMod.NPCs.Perforator public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { if (NPC.IsABestiaryIconDummy) + { NPC.Opacity = 1f; + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, PerforatorBodyLarge.AltTexture.Value, 3, 40, 0.3f, Vector2.Zero, 3, 10); + } SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) diff --git a/NPCs/Perforator/PerforatorHeadMedium.cs b/NPCs/Perforator/PerforatorHeadMedium.cs index c6814bab0f..4f5ffd2b01 100644 --- a/NPCs/Perforator/PerforatorHeadMedium.cs +++ b/NPCs/Perforator/PerforatorHeadMedium.cs @@ -31,7 +31,6 @@ namespace CalamityMod.NPCs.Perforator { Scale = 0.7f, PortraitScale = 0.7f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/PerforatorMedium_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 40 }; @@ -458,7 +457,10 @@ namespace CalamityMod.NPCs.Perforator public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { if (NPC.IsABestiaryIconDummy) + { NPC.Opacity = 1f; + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 5, 34, 0.3f, Vector2.Zero, 5, 6); + } SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) diff --git a/NPCs/Perforator/PerforatorHeadSmall.cs b/NPCs/Perforator/PerforatorHeadSmall.cs index b8fd5aa87e..ceda2e5f25 100644 --- a/NPCs/Perforator/PerforatorHeadSmall.cs +++ b/NPCs/Perforator/PerforatorHeadSmall.cs @@ -2,6 +2,7 @@ using System.IO; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Events; +using CalamityMod.NPCs.Abyss; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -35,7 +36,6 @@ namespace CalamityMod.NPCs.Perforator { Scale = 0.8f, PortraitScale = 0.8f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/PerforatorSmall_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 60 }; @@ -491,7 +491,10 @@ namespace CalamityMod.NPCs.Perforator public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { if (NPC.IsABestiaryIconDummy) + { NPC.Opacity = 1f; + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 5, 22, 0.6f, new Vector2(-20, -20), 4, 10); + } SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) diff --git a/NPCs/Polterghast/Polterghast.cs b/NPCs/Polterghast/Polterghast.cs index 20138b1ba8..8ed15fa562 100644 --- a/NPCs/Polterghast/Polterghast.cs +++ b/NPCs/Polterghast/Polterghast.cs @@ -39,17 +39,14 @@ namespace CalamityMod.NPCs.Polterghast { public static int phase1IconIndex; public static int phase3IconIndex; - - internal static void LoadHeadIcons() + + public override void Load() { string phase1IconPath = "CalamityMod/NPCs/Polterghast/Polterghast_Head_Boss"; string phase3IconPath = "CalamityMod/NPCs/Polterghast/Necroplasm_Head_Boss"; - CalamityMod.Instance.AddBossHeadTexture(phase1IconPath, -1); - phase1IconIndex = ModContent.GetModBossHeadSlot(phase1IconPath); - - CalamityMod.Instance.AddBossHeadTexture(phase3IconPath, -1); - phase3IconIndex = ModContent.GetModBossHeadSlot(phase3IconPath); + phase1IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase1IconPath); + phase3IconIndex = CalamityMod.Instance.AddBossHeadTexture(phase3IconPath); } private const int DespawnTimerMax = 900; @@ -308,7 +305,7 @@ namespace CalamityMod.NPCs.Polterghast // Stop rain if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); // Set time left if (NPC.timeLeft < 1800) diff --git a/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs b/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs index 4480a90eec..36b5028b83 100644 --- a/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs +++ b/NPCs/PrimordialWyrm/PrimordialWyrmHead.cs @@ -13,6 +13,7 @@ using CalamityMod.Items.Weapons.Melee; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.NormalNPCs; +using CalamityMod.NPCs.Perforator; using CalamityMod.Sounds; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -93,7 +94,6 @@ namespace CalamityMod.NPCs.PrimordialWyrm Scale = 0.50f, PortraitScale = 0.6f, PortraitPositionXOverride = 40, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/PrimordialWyrm_Bestiary" }; value.Position.X += 55; value.Position.Y += 5; @@ -1426,7 +1426,10 @@ namespace CalamityMod.NPCs.PrimordialWyrm public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { if (NPC.IsABestiaryIconDummy) + { NPC.Opacity = 1f; + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 3, 18, 0.4f, new Vector2(130, 60), 3, 10); + } SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 432b21f36e..5d7518325b 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -634,7 +634,7 @@ namespace CalamityMod.NPCs.Providence // Prevent lag by stopping rain if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); // Set target biome type if (biomeType == 0) diff --git a/NPCs/StormWeaver/StormWeaverHead.cs b/NPCs/StormWeaver/StormWeaverHead.cs index 6a639fc6a6..af485f9299 100644 --- a/NPCs/StormWeaver/StormWeaverHead.cs +++ b/NPCs/StormWeaver/StormWeaverHead.cs @@ -14,6 +14,7 @@ using CalamityMod.Items.Potions; using CalamityMod.Items.TreasureBags; using CalamityMod.Items.Weapons.Magic; using CalamityMod.Items.Weapons.Ranged; +using CalamityMod.NPCs.Perforator; using CalamityMod.Projectiles.Boss; using CalamityMod.Projectiles.Enemy; using CalamityMod.Sounds; @@ -37,16 +38,13 @@ namespace CalamityMod.NPCs.StormWeaver public static int normalIconIndex; public static int vulnerableIconIndex; - internal static void LoadHeadIcons() + public override void Load() { string normalIconPath = "CalamityMod/NPCs/StormWeaver/StormWeaverHead_Head_Boss"; string vulnerableIconPath = "CalamityMod/NPCs/StormWeaver/StormWeaverHeadNaked_Head_Boss"; - - CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); - normalIconIndex = ModContent.GetModBossHeadSlot(normalIconPath); - - CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); - vulnerableIconIndex = ModContent.GetModBossHeadSlot(vulnerableIconPath); + + normalIconIndex = CalamityMod.Instance.AddBossHeadTexture(normalIconPath, -1); + vulnerableIconIndex = CalamityMod.Instance.AddBossHeadTexture(vulnerableIconPath, -1); } private const float BoltAngleSpread = 280; @@ -70,7 +68,6 @@ namespace CalamityMod.NPCs.StormWeaver { Scale = 0.85f, PortraitScale = 0.75f, - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/StormWeaver_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 40 }; @@ -178,9 +175,9 @@ namespace CalamityMod.NPCs.StormWeaver bool expertMode = Main.expertMode || bossRush; if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); else if (!Main.raining && !bossRush) - CalamityUtils.StartRain(); + CalamityWorld.StartRain(); float lifeRatio = NPC.life / (float)NPC.lifeMax; @@ -817,7 +814,7 @@ namespace CalamityMod.NPCs.StormWeaver if (Main.netMode == NetmodeID.MultiplayerClient || (Main.netMode == NetmodeID.SinglePlayer && Main.gameMenu) || calamityGlobalNPC.newAI[1] > 0f || bossRush) return; - CalamityUtils.StartRain(true, true); + CalamityWorld.StartRain(true, true); calamityGlobalNPC.newAI[1] = 1f; } } @@ -825,7 +822,10 @@ namespace CalamityMod.NPCs.StormWeaver public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { if (NPC.IsABestiaryIconDummy) + { NPC.Opacity = 1f; + return CalamityUtils.DrawAnimatedBestiaryWorm(spriteBatch, NPC, drawColor, TextureAssets.Npc[Type].Value, TextureAssets.Npc[ModContent.NPCType()].Value, 6, 24, 0.8f, Vector2.Zero, 3, 26, 10, 0.15f); + } SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) diff --git a/NPCs/SunkenSea/SandProwler.cs b/NPCs/SunkenSea/SandProwler.cs index 57a4fb4d21..46ec02e744 100644 --- a/NPCs/SunkenSea/SandProwler.cs +++ b/NPCs/SunkenSea/SandProwler.cs @@ -52,7 +52,6 @@ namespace CalamityMod.NPCs.SunkenSea { NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { - CustomTexturePath = "CalamityMod/ExtraTextures/Bestiary/SeaSerpent_Bestiary", PortraitPositionXOverride = 40, PortraitPositionYOverride = 20 }; @@ -583,6 +582,30 @@ namespace CalamityMod.NPCs.SunkenSea public override bool PreDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) { Texture2D segmentSprite = TextureAssets.Npc[Type].Value; + if (NPC.IsABestiaryIconDummy) + { + NPC.frame = segmentSprite.Frame(); + // Buffers the segment position and rotations + float offset = -0.2f; + float startX = 0; + float startY = 0; + int segmentSpacing = 16; + int animationSpeed = 5; + float wormTimer = NPC.Calamity().bestiaryWormTimer; + // Draw the body segments + for (int i = 7; i > 0; i--) + { + // The first segment is slightly closer to keep up with the head + float bodyOffset = i == 1 ? i * segmentSpacing * 0.4f : i * segmentSpacing - segmentSpacing * 0.5f; + + Texture2D toUse = i == 1 ? BodySprite1.Value : i == 2 ? BodySprite2.Value : i % 2 == 0 ? BodySprite3.Value : BodySprite4.Value; + spriteBatch.Draw(toUse, NPC.position + new Vector2(startX + bodyOffset, MathF.Sin((wormTimer + offset * i) * animationSpeed) * 2 + startY), toUse.Frame(1, 1, 0, 0), NPC.GetAlpha(drawColor), NPC.rotation - MathHelper.PiOver2 - MathF.Cos((wormTimer + offset * i) * animationSpeed) * MathHelper.PiOver4 * 0.075f, new Vector2(toUse.Width / 2, toUse.Width / 2), NPC.scale, SpriteEffects.None, 0f); + } + // Draw the head + spriteBatch.Draw(segmentSprite, NPC.position + new Vector2(startX, MathF.Sin(wormTimer * animationSpeed) * 2 + startY), segmentSprite.Frame(1, 11, 0, 0), NPC.GetAlpha(drawColor), NPC.rotation - MathHelper.PiOver2 - MathF.Cos(wormTimer * animationSpeed) * MathHelper.PiOver4 * 0.075f, new Vector2(segmentSprite.Width * 0.5f, segmentSprite.Height / 11), NPC.scale, SpriteEffects.None, 0f); + + return false; + } switch (NPC.ai[3]) { case 0: diff --git a/NPCs/SupremeCalamitas/SupremeCalamitas.cs b/NPCs/SupremeCalamitas/SupremeCalamitas.cs index 36ee5887fd..4b8ab51bea 100644 --- a/NPCs/SupremeCalamitas/SupremeCalamitas.cs +++ b/NPCs/SupremeCalamitas/SupremeCalamitas.cs @@ -226,24 +226,17 @@ namespace CalamityMod.NPCs.SupremeCalamitas public static Asset ForcefieldTexture; // TODO -- This is cumbersome. Change it to be better in 1.4. - internal static void LoadHeadIcons() + public override void Load() { string hoodedIconPath = "CalamityMod/NPCs/SupremeCalamitas/HoodedHeadIcon"; string hoodlessIconPath = "CalamityMod/NPCs/SupremeCalamitas/HoodlessHeadIcon"; string cirrusIconPath = "CalamityMod/NPCs/SupremeCalamitas/CirrusHeadIcon"; string cirrusIconP2Path = "CalamityMod/NPCs/SupremeCalamitas/CirrusHeadIcon2"; - - CalamityMod.Instance.AddBossHeadTexture(hoodedIconPath, -1); - hoodedHeadIconIndex = ModContent.GetModBossHeadSlot(hoodedIconPath); - - CalamityMod.Instance.AddBossHeadTexture(hoodlessIconPath, -1); - hoodlessHeadIconIndex = ModContent.GetModBossHeadSlot(hoodlessIconPath); - - CalamityMod.Instance.AddBossHeadTexture(cirrusIconPath, -1); - cirrusHeadIconIndex = ModContent.GetModBossHeadSlot(cirrusIconPath); - - CalamityMod.Instance.AddBossHeadTexture(cirrusIconP2Path, -1); - cirrusHeadIconP2Index = ModContent.GetModBossHeadSlot(cirrusIconP2Path); + + hoodedHeadIconIndex = CalamityMod.Instance.AddBossHeadTexture(hoodedIconPath, -1); + hoodlessHeadIconIndex = CalamityMod.Instance.AddBossHeadTexture(hoodlessIconPath, -1); + cirrusHeadIconIndex = CalamityMod.Instance.AddBossHeadTexture(cirrusIconPath, -1); + cirrusHeadIconP2Index = CalamityMod.Instance.AddBossHeadTexture(cirrusIconP2Path, -1); } public override void SetStaticDefaults() @@ -457,7 +450,7 @@ namespace CalamityMod.NPCs.SupremeCalamitas } if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); bool bossRush = BossRushEvent.BossRushActive; bool expertMode = Main.expertMode || bossRush; diff --git a/NPCs/TownNPCs/FAP.cs b/NPCs/TownNPCs/FAP.cs index a8a071f222..de0920664a 100644 --- a/NPCs/TownNPCs/FAP.cs +++ b/NPCs/TownNPCs/FAP.cs @@ -873,7 +873,7 @@ namespace CalamityMod.NPCs.TownNPCs public override void AddShops() { - Mod musicMod = CalamityMod.Instance.musicMod; + Mod musicMod = ExternalMods.musicMod; musicMod.TryFind("Interlude1MusicBox", out ModItem interlude1Box); musicMod.TryFind("Interlude2MusicBox", out ModItem interlude2Box); musicMod.TryFind("Interlude3MusicBox", out ModItem interlude3Box); diff --git a/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs b/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs index b983ecd7e8..7ec2bdf1e9 100644 --- a/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs +++ b/NPCs/VanillaNPCAIOverrides/RegularEnemies/RevengeanceAndDeathAI.cs @@ -6162,16 +6162,17 @@ PrepareToShoot: if (Main.netMode != NetmodeID.MultiplayerClient) { - if (npc.justHit || !Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) - npc.ai[0] = 0f; - if (npc.type == NPCID.Harpy) { + float featherShootCutOffValue = CalamityWorld.revenge ? 90f : 60f; + if (npc.justHit || !Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + npc.ai[0] = featherShootCutOffValue + 1f; + if (npc.ai[0] >= HarpyFeatherGateValue) { npc.ai[0] = 0f; } - else if (npc.ai[0] % 30f == 0f && npc.ai[0] <= (CalamityWorld.revenge ? 90f : 60f)) + else if (npc.ai[0] % 30f == 0f && npc.ai[0] <= featherShootCutOffValue) { npc.ai[0] += 1f; if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) @@ -6195,11 +6196,15 @@ PrepareToShoot: if (npc.type == NPCID.Demon || npc.type == NPCID.VoodooDemon) { + float scytheShootCutOffValue = CalamityWorld.revenge ? 80f : 60f; + if (npc.justHit || !Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + npc.ai[0] = scytheShootCutOffValue + 1f; + if (npc.ai[0] >= DemonScytheGateValue) { npc.ai[0] = 0f; } - else if (npc.ai[0] % 20f == 0f && npc.ai[0] <= (CalamityWorld.revenge ? 80f : 60f)) + else if (npc.ai[0] % 20f == 0f && npc.ai[0] <= scytheShootCutOffValue) { npc.ai[0] += 1f; if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) @@ -6223,11 +6228,15 @@ PrepareToShoot: if (npc.type == NPCID.RedDevil) { + float tridentShootCutOffValue = 80f; + if (npc.justHit || !Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) + npc.ai[0] = tridentShootCutOffValue + 1f; + if (npc.ai[0] >= RedDevilTridentGateValue) { npc.ai[0] = 0f; } - else if (npc.ai[0] % 20f == 0f && npc.ai[0] <= 80f) + else if (npc.ai[0] % 20f == 0f && npc.ai[0] <= tridentShootCutOffValue) { npc.ai[0] += 1f; if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) diff --git a/NPCs/Yharon/Yharon.cs b/NPCs/Yharon/Yharon.cs index ce447fe3be..5165eb775f 100644 --- a/NPCs/Yharon/Yharon.cs +++ b/NPCs/Yharon/Yharon.cs @@ -198,7 +198,7 @@ namespace CalamityMod.NPCs.Yharon // Stop rain if (CalamityServerConfig.Instance.BossesStopWeather) - CalamityMod.StopRain(); + CalamityWorld.StopRain(); // Variables bool bossRush = BossRushEvent.BossRushActive; diff --git a/Particles/GeneralParticleHandler.cs b/Particles/GeneralParticleHandler.cs index 3fb0a7190c..d37925abd5 100644 --- a/Particles/GeneralParticleHandler.cs +++ b/Particles/GeneralParticleHandler.cs @@ -9,11 +9,12 @@ using Terraria; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Core; +using Terraria.ModLoader.IO; namespace CalamityMod.Particles { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class GeneralParticleHandler + [Autoload(Side = ModSide.Client)] + public sealed class GeneralParticleHandler : ModSystem { private static List particles; private static Queue particlesToSpawnNextFrame; @@ -22,58 +23,54 @@ namespace CalamityMod.Particles //Static list for details concerning every particle type internal static Dictionary particleTypes; internal static Dictionary particleTextures; - private static List particleInstances; //Lists used when drawing particles batched private static List batchedAlphaBlendParticles; private static List batchedNonPremultipliedParticles; private static List batchedAdditiveBlendParticles; - public static void LoadModParticleInstances() + public override void PostSetupContent() { Type baseParticleType = typeof(Particle); - foreach (Mod mod in ModLoader.Mods) + ReflectionHelper.IterateEveryModsTypes(action: type => { - foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code)) - { - if (type.IsSubclassOf(baseParticleType) && !type.IsAbstract && type != baseParticleType) - { - int ID = particleTypes.Count; //Get the ID of the particle - particleTypes[type] = ID; + int ID = particleTypes.Count; //Get the ID of the particle + particleTypes[type] = ID; - Particle instance = (Particle)FormatterServices.GetUninitializedObject(type); - particleInstances.Add(instance); + // Flow: 2024/09/17 + // 'UnintializedObject' is allowed to use here as it's only read for Texture string Property + // But do NOT EVER use it's instance as they are literally Uninitialized. + // It might cause unintended behaviour if we do that. +#pragma warning disable SYSLIB0050 + Particle instance = (Particle)FormatterServices.GetUninitializedObject(type); +#pragma warning restore SYSLIB0050 - string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name; - if (instance.Texture != "") - texturePath = instance.Texture; - particleTextures[ID] = ModContent.Request(texturePath, AssetRequestMode.ImmediateLoad).Value; - } - } - } + string texturePath = type.Namespace.Replace('.', '/') + "/" + type.Name; + if (instance.Texture != "") + texturePath = instance.Texture; + particleTextures[ID] = ModContent.Request(texturePath, AssetRequestMode.ImmediateLoad).Value; + }); } - internal static void Load() + public override void Load() { - particles = new List(); - particlesToSpawnNextFrame = new Queue(); - particlesToKill = new List(); - particleTypes = new Dictionary(); - particleTextures = new Dictionary(); - particleInstances = new List(); + particles = []; + particlesToSpawnNextFrame = []; + particlesToKill = []; + particleTypes = []; + particleTextures = []; - batchedAlphaBlendParticles = new List(); - batchedNonPremultipliedParticles = new List(); - batchedAdditiveBlendParticles = new List(); + batchedAlphaBlendParticles = []; + batchedNonPremultipliedParticles = []; + batchedAdditiveBlendParticles = []; } - internal static void Unload() + public override void Unload() { particles = null; particlesToSpawnNextFrame = null; particlesToKill = null; particleTypes = null; particleTextures = null; - particleInstances = null; batchedAlphaBlendParticles = null; batchedNonPremultipliedParticles = null; diff --git a/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs b/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs index 34d117b2e6..a8658220ca 100644 --- a/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs +++ b/Projectiles/BaseProjectiles/BaseIdleHoldoutProjectile.cs @@ -16,29 +16,17 @@ namespace CalamityMod.Projectiles.BaseProjectiles // The projectile type cannot be directly discerned at load time (Using Activator.CreateInstance will create an associated projectile with an ID of 0) and as // such this property exists as a direct means of retrieving it. Not ideal, but it works. public abstract int IntendedProjectileType { get; } - public static Dictionary ItemProjectileRelationship = new(); + public static Dictionary ItemProjectileRelationship = []; - // TODO -- There is no reason this load hook should need to be called from CalamityMod. - // All subclasses of this should be ILoadable and should load themselves. - public static void LoadAll() + public override void SetStaticDefaults() { - ItemProjectileRelationship = new Dictionary(); + ItemProjectileRelationship[AssociatedItemID] = IntendedProjectileType; + } - // Look through every type in the mod, and check if it's derived from BaseIdleHoldoutProjectile. - // If it is, cache it into the item/projectile relationship cache. - Type[] types = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code); - foreach (Type type in types) - { - // Don't load abstract classes; they cannot have instances. - if (type.IsAbstract) - continue; - - if (type.IsSubclassOf(typeof(BaseIdleHoldoutProjectile))) - { - BaseIdleHoldoutProjectile instance = Activator.CreateInstance(type) as BaseIdleHoldoutProjectile; - ItemProjectileRelationship[instance.AssociatedItemID] = instance.IntendedProjectileType; - } - } + public override void Unload() + { + ItemProjectileRelationship?.Clear(); + ItemProjectileRelationship = null; } public static void CheckForEveryHoldout(Player player) diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 30ed8405b5..d2d63771fe 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -8,6 +8,7 @@ using CalamityMod.CalPlayer; using CalamityMod.Dusts; using CalamityMod.EntitySources; using CalamityMod.Events; +using CalamityMod.ExtraTextures; using CalamityMod.Items.Accessories; using CalamityMod.Items.Potions.Alcohol; using CalamityMod.NPCs; @@ -4570,7 +4571,7 @@ namespace CalamityMod.Projectiles if (Main.wofNPCIndex < 0 || !Main.npc[Main.wofNPCIndex].active || Main.npc[Main.wofNPCIndex].life <= 0 || projectile.tileCollide) return true; - Texture2D texture = CalamityMod.WallOfFleshDemonSickleTexture.Value; + Texture2D texture = ExtraTextureRefs.WallOfFleshDemonSickleTexture.Value; int frameHeight = texture.Height / Main.projFrames[projectile.type]; int frameY = frameHeight * projectile.frame; Rectangle rectangle = new Rectangle(0, frameY, texture.Width, frameHeight); diff --git a/Projectiles/Magic/ForbiddenSunProjectile.cs b/Projectiles/Magic/ForbiddenSunProjectile.cs index 5fb8696413..6aaf251d2a 100644 --- a/Projectiles/Magic/ForbiddenSunProjectile.cs +++ b/Projectiles/Magic/ForbiddenSunProjectile.cs @@ -1,4 +1,5 @@ -using Terraria; +using Microsoft.Xna.Framework; +using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; @@ -28,15 +29,9 @@ namespace CalamityMod.Projectiles.Magic public override void AI() { Projectile.rotation = Projectile.velocity.ToRotation(); - if (Projectile.frameCounter++ % 4 == 0) - { - Projectile.frame++; - } - if (Projectile.frame >= Main.projFrames[Projectile.type]) - { - Projectile.frame = 0; - } - Lighting.AddLight(Projectile.Center, (255 - Projectile.alpha) * 0.25f / 255f, (255 - Projectile.alpha) * 0.2f / 255f, (255 - Projectile.alpha) * 0.01f / 255f); + Projectile.frameCounter++; + Projectile.frame = Projectile.frameCounter / 4 % Main.projFrames[Projectile.type]; + Lighting.AddLight(Projectile.Center, 0.25f, 0.2f, 0.01f); if (Projectile.wet && !Projectile.lavaWet) { Projectile.Kill(); @@ -48,17 +43,18 @@ namespace CalamityMod.Projectiles.Magic } if (Main.rand.NextBool(4)) { - int forbid = Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, Main.rand.NextBool(3) ? 16 : 174, 0f, 0f); - Main.dust[forbid].noGravity = true; - Main.dust[forbid].velocity *= 0f; + Dust fire = Dust.NewDustDirect(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, Main.rand.NextBool(3) ? 16 : 174); + fire.noGravity = true; + fire.velocity *= 0f; } } public override void OnKill(int timeLeft) { + SoundEngine.PlaySound(SoundID.Item20, Projectile.Center); if (Projectile.owner == Main.myPlayer) { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner); } } diff --git a/Projectiles/Magic/ForbiddenSunburst.cs b/Projectiles/Magic/ForbiddenSunburst.cs index 03785ec273..a14becc6ca 100644 --- a/Projectiles/Magic/ForbiddenSunburst.cs +++ b/Projectiles/Magic/ForbiddenSunburst.cs @@ -1,7 +1,5 @@ -using System; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Terraria; -using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; @@ -35,11 +33,6 @@ namespace CalamityMod.Projectiles.Magic { Projectile.Kill(); } - if (Projectile.localAI[0] == 0f) - { - SoundEngine.PlaySound(SoundID.Item20, Projectile.Center); - Projectile.localAI[0] += 1f; - } float projTimer = 25f; if (Projectile.ai[0] > 180f) { @@ -52,31 +45,24 @@ namespace CalamityMod.Projectiles.Magic } projTimer *= 0.7f; Projectile.ai[0] += 4f; - int timerCounter = 0; - while ((float)timerCounter < projTimer) + float timerCounter = 0; + while (timerCounter < projTimer) { - float rando1 = (float)Main.rand.Next(-25, 26); - float rando2 = (float)Main.rand.Next(-25, 26); - float rando3 = (float)Main.rand.Next(9, 24); - float randoAdjuster = (float)Math.Sqrt((double)(rando1 * rando1 + rando2 * rando2)); - randoAdjuster = rando3 / randoAdjuster; - rando1 *= randoAdjuster; - rando2 *= randoAdjuster; - int orngDust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Pixie, 0f, 0f, 100, default, 2.5f); - Dust dust = Main.dust[orngDust]; + Dust dust = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, DustID.Pixie, Alpha: 100, Scale: 2.5f); dust.noGravity = true; - dust.position.X = Projectile.Center.X; - dust.position.Y = Projectile.Center.Y; - dust.position.X += (float)Main.rand.Next(-10, 11); - dust.position.Y += (float)Main.rand.Next(-10, 11); - dust.velocity.X = rando1; - dust.velocity.Y = rando2; + dust.position = Projectile.Center + Main.rand.NextVector2Circular(10f, 10f); + dust.velocity = Main.rand.NextVector2Circular(25f, 25f); timerCounter++; } } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) => target.AddBuff(BuffID.OnFire3, 300); + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + modifiers.HitDirectionOverride = (Projectile.Center.X < target.Center.X).ToDirectionInt(); + } + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, ExplosionRadius, targetHitbox); } } diff --git a/Projectiles/Melee/BasherHoldout.cs b/Projectiles/Melee/BasherHoldout.cs index ba66ea6ada..6f40f5d2d1 100644 --- a/Projectiles/Melee/BasherHoldout.cs +++ b/Projectiles/Melee/BasherHoldout.cs @@ -60,6 +60,7 @@ namespace CalamityMod.Projectiles.Melee public override void UseStyle() { + AnimationProgress = Animation % useAnim; DrawUnconditionally = false; if (CanHit || postSwing) diff --git a/Projectiles/Melee/BiomeBladeHoldout.cs b/Projectiles/Melee/BiomeBladeHoldout.cs index 9b1bc95342..5babf42730 100644 --- a/Projectiles/Melee/BiomeBladeHoldout.cs +++ b/Projectiles/Melee/BiomeBladeHoldout.cs @@ -2,6 +2,7 @@ using CalamityMod.DataStructures; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Particles; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -123,7 +124,7 @@ namespace CalamityMod.Projectiles.Melee bool hotAttune = Owner.ZoneDesert || Owner.ZoneUnderworldHeight; bool heavenlyAttune = Owner.ZoneHallow || Owner.Calamity().ZoneAstral; - Attunement attunement = Attunement.attunementArray[(int)AttunementID.TrueDefault]; + Attunement attunement = AttunementSystem.FindOrNull(AttunementID.TrueDefault); if (hotAttune) attunement = Attunement.attunementArray[(int)AttunementID.TrueHot]; diff --git a/Projectiles/Melee/BladecrestOathswordProj.cs b/Projectiles/Melee/BladecrestOathswordProj.cs index b962bf36c3..4b0fdfee15 100644 --- a/Projectiles/Melee/BladecrestOathswordProj.cs +++ b/Projectiles/Melee/BladecrestOathswordProj.cs @@ -36,6 +36,8 @@ namespace CalamityMod.Projectiles.Melee public override void SetStaticDefaults() { + base.SetStaticDefaults(); // DO NOT REMOVE THIS + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; ProjectileID.Sets.TrailCacheLength[Projectile.type] = 3; } diff --git a/Projectiles/Melee/BrokenBiomeBladeHoldout.cs b/Projectiles/Melee/BrokenBiomeBladeHoldout.cs index 1cf5493bf4..5b8413e628 100644 --- a/Projectiles/Melee/BrokenBiomeBladeHoldout.cs +++ b/Projectiles/Melee/BrokenBiomeBladeHoldout.cs @@ -2,6 +2,7 @@ using CalamityMod.DataStructures; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Particles; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -123,19 +124,19 @@ namespace CalamityMod.Projectiles.Melee bool evilAttune = Owner.ZoneCorrupt || Owner.ZoneCrimson; bool hotAttune = Owner.ZoneDesert || Owner.ZoneUnderworldHeight; - Attunement attunement = Attunement.attunementArray[(int)AttunementID.Default]; + Attunement attunement = AttunementSystem.FindOrNull(AttunementID.Default); if (hotAttune) { - attunement = Attunement.attunementArray[(int)AttunementID.Hot]; + attunement = AttunementSystem.FindOrNull(AttunementID.Hot); } if (coldAttune) { - attunement = Attunement.attunementArray[(int)AttunementID.Cold]; + attunement = AttunementSystem.FindOrNull(AttunementID.Cold); } if (evilAttune) { - attunement = Attunement.attunementArray[(int)AttunementID.Evil]; + attunement = AttunementSystem.FindOrNull(AttunementID.Evil); } //If the owner already had the attunement , break out of it (And unswap) diff --git a/Projectiles/Melee/CometQuasherHoldout.cs b/Projectiles/Melee/CometQuasherHoldout.cs index 6565539d1e..0c77a63ce3 100644 --- a/Projectiles/Melee/CometQuasherHoldout.cs +++ b/Projectiles/Melee/CometQuasherHoldout.cs @@ -59,6 +59,7 @@ namespace CalamityMod.Projectiles.Melee public override void UseStyle() { + AnimationProgress = Animation % useAnim; DrawUnconditionally = false; if (CanHit || postSwing) diff --git a/Projectiles/Melee/DeathsAscensionProjectile.cs b/Projectiles/Melee/DeathsAscensionProjectile.cs index e5aea1d2fb..52e243df5b 100644 --- a/Projectiles/Melee/DeathsAscensionProjectile.cs +++ b/Projectiles/Melee/DeathsAscensionProjectile.cs @@ -1,10 +1,9 @@ -using CalamityMod.Buffs.DamageOverTime; -using CalamityMod.Projectiles.Healing; +using CalamityMod.Items.Weapons.Melee; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ID; using Terraria.ModLoader; + namespace CalamityMod.Projectiles.Melee { public class DeathsAscensionProjectile : ModProjectile, ILocalizedModType @@ -21,7 +20,7 @@ namespace CalamityMod.Projectiles.Melee { Projectile.width = 102; Projectile.height = 82; - Projectile.aiStyle = ProjAIStyleID.Sickle; + Projectile.aiStyle = -1; Projectile.friendly = true; Projectile.DamageType = DamageClass.Melee; Projectile.tileCollide = false; @@ -31,7 +30,6 @@ namespace CalamityMod.Projectiles.Melee Projectile.ignoreWater = true; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 30; - AIType = ProjectileID.DeathSickle; } public override void AI() @@ -43,18 +41,41 @@ namespace CalamityMod.Projectiles.Melee Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.ShadowbeamStaff, Projectile.velocity.X * 0.5f, Projectile.velocity.Y * 0.5f); } - CalamityUtils.HomeInOnNPC(Projectile, true, 900f, 18f, 20f); + int startLife = Projectile.ai[2] > 0 ? DeathsAscension.RiftLifeTime : 180; + // Player scythes just home + if (Projectile.ai[2] <= 0) + { + CalamityUtils.HomeInOnNPC(Projectile, true, 900f, 18f, 20f); + Projectile.velocity *= 0.96f; + } + // Rift scythes have orbital motion + else + { + Projectile.velocity = Projectile.velocity.SafeNormalize(Vector2.UnitY).RotatedBy(0.1f) * 20; + } + // Smoothly disappear + if (Projectile.timeLeft < 60) + { + Projectile.alpha += 3; + } + // Rotation direction stuff from the vanilla Death Sickle + if (Projectile.velocity.X < 0f) + { + Projectile.spriteDirection = -1; + } + Projectile.rotation += (float)Projectile.direction * 0.05f; + Projectile.rotation += (float)Projectile.direction * 0.5f * ((float)Projectile.timeLeft / startLife); } public override bool PreDraw(ref Color lightColor) { - CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 2); + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor * Projectile.Opacity, 2); return false; } public override Color? GetAlpha(Color lightColor) { - return new Color(150, 0, 200, 0); + return new Color(150, 0, 200, 0) * Projectile.Opacity; } } } diff --git a/Projectiles/Melee/DeathsAscensionRift.cs b/Projectiles/Melee/DeathsAscensionRift.cs new file mode 100644 index 0000000000..b844b8ba93 --- /dev/null +++ b/Projectiles/Melee/DeathsAscensionRift.cs @@ -0,0 +1,104 @@ +using CalamityMod.Graphics.Metaballs; +using CalamityMod.Items.Weapons.Melee; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Melee +{ + public class DeathsAscensionRift : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Melee"; + + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + + public override void SetDefaults() + { + Projectile.width = 50; + Projectile.height = 50; + Projectile.friendly = true; + Projectile.ignoreWater = true; + Projectile.timeLeft = DeathsAscension.RiftLifeTime; + Projectile.penetrate = -1; + Projectile.tileCollide = false; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 30; + } + + public override void AI() + { + // Metaball visuals + int ballAmt = 20; + for (int i = 0; i < ballAmt; i++) + { + // How far balls are between each other + float offset = i * 5; + // Allows the rift to be rotated + Vector2 rotationOffset = Vector2.UnitY.RotatedBy(Projectile.rotation) * i; + // How random the sizing can get. Randomness is decreased as the balls get smaller + float sizeRandomness = MathHelper.Lerp(10, 0, (float)(i / (float)ballAmt)); + // How random the positioning can get + float positionRandomness = 20; + // Size decreases with each iteration as the balls are spawned further out. They also have some slight bubbly randomness and will scale in while the rift is spawning + float scale = (MathHelper.Lerp(90, 10, (float)(i / (float)ballAmt)) + Main.rand.NextFloat(-sizeRandomness, sizeRandomness)) * Utils.GetLerpValue(DeathsAscension.RiftLifeTime, DeathsAscension.RiftLifeTime - 10, Projectile.timeLeft, true); + // Spawn the metaballs. The first moves downwards while the other moves upwards + StreamGougeMetaball.SpawnParticle(Projectile.Center + Vector2.UnitY * (offset + Main.rand.NextFloat(-positionRandomness, positionRandomness)) + rotationOffset , Vector2.Zero, scale); + StreamGougeMetaball.SpawnParticle(Projectile.Center + Vector2.UnitY * -(offset + Main.rand.NextFloat(-positionRandomness, positionRandomness)) - rotationOffset, Vector2.Zero, scale); + } + + // Spawn orbital scythes on spawn. These last until the rift dies. + if (Projectile.ai[2] == 0) + { + int scytheAmt = DeathsAscension.RiftOrbitalAmount; + float speed = 30; + for (int i = 0; i < scytheAmt; i++) + { + Vector2 scytheVelocity = Vector2.UnitY.RotatedBy(MathHelper.Lerp(0, 3 * MathHelper.PiOver2, (float)(i / (float)(scytheAmt - 1))) + Projectile.ai[1]) * speed; + if (Projectile.owner == Main.myPlayer) + { + int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, scytheVelocity, ModContent.ProjectileType(), (int)(Projectile.damage * DeathsAscension.OrbitalScytheDamageMult), Projectile.knockBack, Projectile.owner, ai2: 1); + + Main.projectile[p].penetrate = -1; + Main.projectile[p].timeLeft = DeathsAscension.RiftLifeTime; + } + } + Projectile.ai[2] = 1; + } + + // When the weapon is swung fire scythes from the rift + if (Projectile.ai[0] == 10) + { + SoundEngine.PlaySound(SoundID.Item104 with { Pitch = 0.4f }, Projectile.Center); + SoundEngine.PlaySound(SoundID.Item71 with { Pitch = -0.4f }, Projectile.Center); + + Vector2 direction = Projectile.Center.DirectionTo(Main.MouseWorld) * 12; + int spreadfactor = 9; + for (int index = 0; index < DeathsAscension.ScytheShotAmount; ++index) + { + float SpeedX = direction.X + Main.rand.NextFloat(-spreadfactor, spreadfactor + 1); + float SpeedY = direction.Y + Main.rand.NextFloat(-spreadfactor, spreadfactor + 1); + if (Projectile.owner == Main.myPlayer) + { + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, SpeedX, SpeedY, ModContent.ProjectileType(), (int)(Projectile.damage * DeathsAscension.RiftScytheDamageMult), Projectile.knockBack, Projectile.owner); + } + } + } + + // Controls the rotational offset of orbital scythes + Projectile.ai[1] += 0.1f; + + // Decrement scythe cooldown timer + if (Projectile.ai[0] > 0) + { + Projectile.ai[0]--; + } + } + + public override void OnKill(int timeLeft) + { + SoundEngine.PlaySound(CalPlayer.CalamityPlayer.DrownSound, Projectile.Center); + } + } +} diff --git a/Projectiles/Melee/DeathsAscensionSwing.cs b/Projectiles/Melee/DeathsAscensionSwing.cs index 40c38d118f..379f042834 100644 --- a/Projectiles/Melee/DeathsAscensionSwing.cs +++ b/Projectiles/Melee/DeathsAscensionSwing.cs @@ -47,8 +47,8 @@ namespace CalamityMod.Projectiles.Melee Projectile.tileCollide = false; Projectile.DamageType = TrueMeleeNoSpeedDamageClass.Instance; Projectile.ownerHitCheck = true; - Projectile.usesIDStaticNPCImmunity = true; - Projectile.idStaticNPCHitCooldown = 8; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 8; Projectile.frameCounter = 0; } @@ -112,6 +112,8 @@ namespace CalamityMod.Projectiles.Melee Owner.heldProj = Projectile.whoAmI; Owner.itemTime = 2; Owner.itemAnimation = 2; + + Projectile.ai[2]--; } // This hurt my soul to do, but because the swing is done with a sprite animation, tracking specific visual rotation of the weapon is nigh impossible @@ -153,7 +155,8 @@ namespace CalamityMod.Projectiles.Melee Vector2 origin = texture.Size() / new Vector2(2f, 6f) * 0.5f; Rectangle frame = texture.Frame(2, 6, frameX, frameY); SpriteEffects spriteEffects = Projectile.spriteDirection == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally; - Main.EntitySpriteDraw(texture, position, frame, lightColor, Projectile.rotation, origin, Projectile.scale, spriteEffects, 0); + Color playerPos = Lighting.GetColor(Main.LocalPlayer.position.ToTileCoordinates()); + Main.EntitySpriteDraw(texture, position, frame, playerPos, Projectile.rotation, origin, Projectile.scale, spriteEffects, 0); Main.EntitySpriteDraw(glowTexture.Value, position, frame, Color.White, Projectile.rotation, origin, Projectile.scale, spriteEffects, 0); return false; } @@ -162,5 +165,20 @@ namespace CalamityMod.Projectiles.Melee // Deal damage only once it starts swinging down and then going back up public override bool? CanDamage() => ((frameX == 0 && frameY >= 3) || frameX == 1); + + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + int maxRifts = 1; + if (Projectile.ai[2] <= 0 && Main.player[Projectile.owner].ownedProjectileCounts[ModContent.ProjectileType()] < maxRifts) + { + int p = Projectile.NewProjectile(Projectile.GetSource_FromThis(), target.Center + Main.rand.NextVector2Circular(28, 28), Vector2.Zero, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, ai1: Main.rand.NextFloat(0, 3f)); + Main.projectile[p].rotation = Main.rand.NextFloat(-MathHelper.TwoPi, MathHelper.TwoPi); + SoundEngine.PlaySound(SoundID.Item165 with { Pitch = -1 }, Projectile.Center); + Projectile.ai[2] = 40; + float screenShakePower = 3 * Utils.GetLerpValue(1300f, 0f, target.Distance(Main.LocalPlayer.Center), true); + if (Main.LocalPlayer.Calamity().GeneralScreenShakePower < screenShakePower) + Main.LocalPlayer.Calamity().GeneralScreenShakePower = screenShakePower; + } + } } } diff --git a/Projectiles/Melee/EarthHoldout.cs b/Projectiles/Melee/EarthHoldout.cs index 6b2b95708d..736c25be17 100644 --- a/Projectiles/Melee/EarthHoldout.cs +++ b/Projectiles/Melee/EarthHoldout.cs @@ -61,6 +61,7 @@ namespace CalamityMod.Projectiles.Melee public override void UseStyle() { + AnimationProgress = Animation % useAnim; DrawUnconditionally = false; float rate = Main.GlobalTimeWrappedHourly * 19; diff --git a/Projectiles/Melee/GalaxiaHoldout.cs b/Projectiles/Melee/GalaxiaHoldout.cs index 14426ffbcf..03485e975a 100644 --- a/Projectiles/Melee/GalaxiaHoldout.cs +++ b/Projectiles/Melee/GalaxiaHoldout.cs @@ -3,6 +3,7 @@ using CalamityMod.DataStructures; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Particles; using CalamityMod.Sounds; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -87,41 +88,31 @@ namespace CalamityMod.Projectiles.Melee if (CycleDirection == -1) //Cycles goes Phoenix => Aries => Polaris => Andromeda { - switch (item.mainAttunement.id) + attunement = item.mainAttunement.id switch { - case AttunementID.Phoenix: //Switching to the aries attunement. - attunement = Attunement.attunementArray[(int)AttunementID.Aries]; - break; - case AttunementID.Aries: //Switching to the polaris attunement. - attunement = Attunement.attunementArray[(int)AttunementID.Polaris]; - break; - case AttunementID.Polaris: //Switching to the andromeda attunement. - attunement = Attunement.attunementArray[(int)AttunementID.Andromeda]; - break; - case AttunementID.Andromeda: //Switching to the phoenix attunement. - default: - attunement = Attunement.attunementArray[(int)AttunementID.Phoenix]; - break; - } + //Switching to the aries attunement. + AttunementID.Phoenix => AttunementSystem.FindOrNull(AttunementID.Aries), + //Switching to the polaris attunement. + AttunementID.Aries => AttunementSystem.FindOrNull(AttunementID.Polaris), + //Switching to the andromeda attunement. + AttunementID.Polaris => AttunementSystem.FindOrNull(AttunementID.Andromeda), + //Switching to the phoenix attunement. + _ => AttunementSystem.FindOrNull(AttunementID.Phoenix), + }; } else //Cycles goes Phoenix <= Aries <= Polaris <= Andromeda { - switch (item.mainAttunement.id) + attunement = item.mainAttunement.id switch { - case AttunementID.Phoenix: //Switching to the andromeda attunement. - attunement = Attunement.attunementArray[(int)AttunementID.Andromeda]; - break; - case AttunementID.Andromeda: //Switching to the polaris attunement. - attunement = Attunement.attunementArray[(int)AttunementID.Polaris]; - break; - case AttunementID.Polaris: //Switching to the aries attunement. - attunement = Attunement.attunementArray[(int)AttunementID.Aries]; - break; - case AttunementID.Aries: //Switching to the phoenix attunement. - default: - attunement = Attunement.attunementArray[(int)AttunementID.Phoenix]; - break; - } + //Switching to the andromeda attunement. + AttunementID.Phoenix => AttunementSystem.FindOrNull(AttunementID.Andromeda), + //Switching to the polaris attunement. + AttunementID.Andromeda => AttunementSystem.FindOrNull(AttunementID.Polaris), + //Switching to the aries attunement. + AttunementID.Polaris => AttunementSystem.FindOrNull(AttunementID.Aries), + //Switching to the phoenix attunement. + _ => AttunementSystem.FindOrNull(AttunementID.Phoenix), + }; } switch (attunement.id) diff --git a/Projectiles/Melee/GrandDadHoldout.cs b/Projectiles/Melee/GrandDadHoldout.cs index 8b3969866c..869acbd228 100644 --- a/Projectiles/Melee/GrandDadHoldout.cs +++ b/Projectiles/Melee/GrandDadHoldout.cs @@ -63,6 +63,7 @@ namespace CalamityMod.Projectiles.Melee public override void UseStyle() { + AnimationProgress = Animation % useAnim; DrawUnconditionally = false; if (CanHit || postSwing) diff --git a/Projectiles/Melee/GrandGuardianHoldout.cs b/Projectiles/Melee/GrandGuardianHoldout.cs index a5ea462ba3..d26ded3fa7 100644 --- a/Projectiles/Melee/GrandGuardianHoldout.cs +++ b/Projectiles/Melee/GrandGuardianHoldout.cs @@ -63,6 +63,7 @@ namespace CalamityMod.Projectiles.Melee public override void UseStyle() { + AnimationProgress = Animation % useAnim; DrawUnconditionally = false; if (CanHit || postSwing) diff --git a/Projectiles/Melee/MajesticGuardHoldout.cs b/Projectiles/Melee/MajesticGuardHoldout.cs index 56368fa447..36024f29ad 100644 --- a/Projectiles/Melee/MajesticGuardHoldout.cs +++ b/Projectiles/Melee/MajesticGuardHoldout.cs @@ -58,6 +58,7 @@ namespace CalamityMod.Projectiles.Melee public override void UseStyle() { + AnimationProgress = Animation % useAnim; DrawUnconditionally = false; if (CanHit || postSwing) diff --git a/Projectiles/Melee/OldLordClaymoreProj.cs b/Projectiles/Melee/OldLordClaymoreProj.cs index 2ad7609cef..a15390c1b4 100644 --- a/Projectiles/Melee/OldLordClaymoreProj.cs +++ b/Projectiles/Melee/OldLordClaymoreProj.cs @@ -41,6 +41,8 @@ namespace CalamityMod.Projectiles.Melee public override void SetStaticDefaults() { + base.SetStaticDefaults(); // DO NOT REMOVE THIS + ProjectileID.Sets.TrailingMode[Projectile.type] = 2; ProjectileID.Sets.TrailCacheLength[Projectile.type] = 3; } @@ -331,5 +333,10 @@ namespace CalamityMod.Projectiles.Melee } public override void OnKill(int timeLeft) => Owner.fullRotation = 0f; + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + modifiers.HitDirectionOverride = (Owner.Center.X < target.Center.X).ToDirectionInt(); + } } } diff --git a/Projectiles/Melee/Shortswords/StarburstShivProj.cs b/Projectiles/Melee/Shortswords/StarburstShivProj.cs index 52e9409cfd..8293e62d06 100644 --- a/Projectiles/Melee/Shortswords/StarburstShivProj.cs +++ b/Projectiles/Melee/Shortswords/StarburstShivProj.cs @@ -17,7 +17,7 @@ namespace CalamityMod.Projectiles.Melee.Shortswords public override void SetDefaults() { - Projectile.Size = new Vector2(22); + Projectile.width = Projectile.height = 44; Projectile.friendly = true; Projectile.penetrate = -1; Projectile.tileCollide = false; @@ -39,15 +39,15 @@ namespace CalamityMod.Projectiles.Melee.Shortswords public override void SetVisualOffsets() { - const int HalfSpriteWidth = 44 / 2; - const int HalfSpriteHeight = 44 / 2; + const int HalfSpriteWidth = 37; + const int HalfSpriteHeight = 47; int HalfProjWidth = Projectile.width / 2; - int HalfProjHeight = Projectile.height / 2; + int QuarterProjHeight = Projectile.height / 4; DrawOriginOffsetX = 0; DrawOffsetX = -(HalfSpriteWidth - HalfProjWidth); - DrawOriginOffsetY = -(HalfSpriteHeight - HalfProjHeight); + DrawOriginOffsetY = -(HalfSpriteHeight - QuarterProjHeight); } public override void ExtraBehavior() diff --git a/Projectiles/Melee/StellarStrikerHoldout.cs b/Projectiles/Melee/StellarStrikerHoldout.cs index 6476911dcf..6af8c3b7d9 100644 --- a/Projectiles/Melee/StellarStrikerHoldout.cs +++ b/Projectiles/Melee/StellarStrikerHoldout.cs @@ -60,6 +60,7 @@ namespace CalamityMod.Projectiles.Melee public override void UseStyle() { + AnimationProgress = Animation % useAnim; DrawUnconditionally = false; if (CanHit || postSwing) diff --git a/Projectiles/Melee/TrueBiomeBladeHoldout.cs b/Projectiles/Melee/TrueBiomeBladeHoldout.cs index bf24937c8e..e5492cc9f8 100644 --- a/Projectiles/Melee/TrueBiomeBladeHoldout.cs +++ b/Projectiles/Melee/TrueBiomeBladeHoldout.cs @@ -3,6 +3,7 @@ using CalamityMod.DataStructures; using CalamityMod.Items.Weapons.Melee; using CalamityMod.Particles; using CalamityMod.Sounds; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -132,13 +133,17 @@ namespace CalamityMod.Projectiles.Melee bool pogoAttune = Owner.ZoneDesert || Owner.ZoneUnderworldHeight || Owner.ZoneCorrupt || Owner.ZoneCrimson; bool whirlAttune = Owner.ZoneHallow || Owner.Calamity().ZoneAstral; - Attunement attunement = Attunement.attunementArray[(int)AttunementID.Shockwave]; - if (pogoAttune) - attunement = Attunement.attunementArray[(int)AttunementID.SuperPogo]; - if (flailAttune) - attunement = Attunement.attunementArray[(int)AttunementID.FlailBlade]; - if (whirlAttune) - attunement = Attunement.attunementArray[(int)AttunementID.Whirlwind]; + Attunement attunement = AttunementSystem.FindOrNull(AttunementID.Whirlwind); + if (desert || hell) + attunement = AttunementSystem.FindOrNull(AttunementID.SuperPogo); + if (jungle || ocean || snow) //Check put after the desert check so ocean doesnt get overriden as desert + attunement = AttunementSystem.FindOrNull(AttunementID.FlailBlade); + if (evil) //Evil check separated so that it overrides corrupted beach & snow biomes + attunement = AttunementSystem.FindOrNull(AttunementID.SuperPogo); + if (astral || marine) + attunement = AttunementSystem.FindOrNull(AttunementID.Shockwave); + if (hallow) + attunement = AttunementSystem.FindOrNull(AttunementID.Whirlwind); //Putting holy check at the end so it may override hallowed variants of biomes //If the owner already had the attunement, break out of it (And unswap) if (item.secondaryAttunement == attunement) diff --git a/Projectiles/Ranged/AquaBlast.cs b/Projectiles/Ranged/AquaBlast.cs index 0397ad3904..4f3777524d 100644 --- a/Projectiles/Ranged/AquaBlast.cs +++ b/Projectiles/Ranged/AquaBlast.cs @@ -1,5 +1,13 @@ -using Microsoft.Xna.Framework; +using System.Diagnostics.Contracts; +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Items.Weapons.Melee; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; @@ -8,21 +16,24 @@ namespace CalamityMod.Projectiles.Ranged public class AquaBlast : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Ranged"; + public override void SetStaticDefaults() { - Main.projFrames[Projectile.type] = 4; + Main.projFrames[Projectile.type] = 20; } + public int spreadDust = 0; + public static int Lifetime = 600; public override void SetDefaults() { - Projectile.width = 12; - Projectile.height = 12; + Projectile.width = 36; + Projectile.height = 26; Projectile.friendly = true; Projectile.ignoreWater = true; Projectile.penetrate = 1; - Projectile.timeLeft = 600; + Projectile.timeLeft = Lifetime; + Projectile.extraUpdates = 2; Projectile.DamageType = DamageClass.Ranged; - Projectile.extraUpdates = 1; Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration; } @@ -30,37 +41,94 @@ namespace CalamityMod.Projectiles.Ranged { //Animation Projectile.frameCounter++; - if (Projectile.frameCounter > 5) + if (Projectile.frameCounter > 21) { Projectile.frame++; Projectile.frameCounter = 0; } - if (Projectile.frame > 3) + if (Projectile.frame > 19) { Projectile.frame = 0; } + Projectile.frame = Projectile.frameCounter / 4 % Main.projFrames[Projectile.type]; //Rotation Projectile.spriteDirection = Projectile.direction = (Projectile.velocity.X > 0).ToDirectionInt(); Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == 1 ? 0f : MathHelper.Pi) + MathHelper.ToRadians(90) * Projectile.direction; - Lighting.AddLight(Projectile.Center, (255 - Projectile.alpha) * 0f / 255f, (255 - Projectile.alpha) * 0f / 255f, (255 - Projectile.alpha) * 0.75f / 255f); - for (int i = 0; i < 2; i++) + Lighting.AddLight(Projectile.Center, Color.AliceBlue.ToVector3() * 0.5f); + //Trailing effects + if (Projectile.timeLeft <= Lifetime - 7) { - Vector2 dspeed = -Projectile.velocity * Main.rand.NextFloat(0.5f * 0.8f); - int dust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Water, 0f, 0f, 100, default, 1f); - Main.dust[dust].noGravity = true; - Main.dust[dust].velocity = dspeed; + for (int i = 0; i < 2; i++) + { + SparkParticle spark = new SparkParticle(Projectile.Center - Projectile.velocity / 0.18f, Projectile.velocity * 0.01f, false, 5, 1.9f, Color.SeaGreen, true); + GeneralParticleHandler.SpawnParticle(spark); + } + } + if (Main.rand.NextBool(2)) + { + Gore bubble = Gore.NewGorePerfect(Projectile.GetSource_FromAI(), Projectile.position, Projectile.velocity * 0.2f + Main.rand.NextVector2Circular(1f, 1f), 411); + bubble.timeLeft = 6 + Main.rand.Next(7); + bubble.scale = Main.rand.NextFloat(0.6f, 0.8f); + bubble.type = Main.rand.NextBool(3) ? 412 : 411; + } + if (Main.rand.NextBool()) + { + Dust dust = Dust.NewDustPerfect(Projectile.Center + Main.rand.NextVector2Circular(6 + spreadDust, 6 + spreadDust), !Main.rand.NextBool(5) ? 278 : 267, -Projectile.velocity * Main.rand.NextFloat(0.05f, 0.35f), 0, default, Main.rand.NextFloat(0.4f, 0.6f)); + dust.noGravity = true; + dust.color = !Main.rand.NextBool(5) ? Color.Aquamarine : Color.Aqua; + if (dust.type == 278) + dust.scale *= 0.7f; } } + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + target.AddBuff(ModContent.BuffType(), 60); + } + public override void OnHitPlayer(Player target, Player.HurtInfo info) + { + target.AddBuff(ModContent.BuffType(), 60); + } + public override void OnSpawn(IEntitySource source) + { + Vector2 smokeVel = Projectile.velocity.SafeNormalize(Vector2.UnitY) * 5; + int smokeAmount = Main.rand.Next(8, 12 + 1); + for (int i = 0; i < smokeAmount; i++) + { + Particle smoke = new HeavySmokeParticle(Projectile.Center, smokeVel.RotatedByRandom(0.4f) * Main.rand.NextFloat(1.2f, 2f), Color.White, Main.rand.Next(40, 60 + 1), Main.rand.NextFloat(0.2f, 0.4f), 0.3f, Main.rand.NextFloat(-0.2f, 0.2f), Main.rand.NextBool(), required: true); + GeneralParticleHandler.SpawnParticle(smoke); + } + } public override void OnKill(int timeLeft) { - for (int lol = 0; lol < 10; lol++) + SoundEngine.PlaySound(SoundID.ShimmerWeak1 with { Pitch = 0.35f }, Projectile.Center); + for (int i = 0; i < 5; ++i) { - Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.Water, 0f, 0f, 100, default, 1f); + int bloodLifetime = Main.rand.Next(22, 25); + float bloodScale = Main.rand.NextFloat(0.6f, 0.8f); + Color bloodColor = Color.Lerp(Color.SkyBlue, Color.Aquamarine, Main.rand.NextFloat()); + bloodColor = Color.Lerp(bloodColor, new Color(51, 22, 94), Main.rand.NextFloat(0.65f)); + + if (Main.rand.NextBool(20)) + bloodScale *= 2f; + + float randomSpeedMultiplier = Main.rand.NextFloat(1.25f, 2.25f); + Vector2 bloodVelocity = Main.rand.NextVector2Unit() * 2 * randomSpeedMultiplier; + bloodVelocity.Y -= 5f; + BloodParticle blood = new BloodParticle(Projectile.Center, bloodVelocity, bloodLifetime, bloodScale, bloodColor); + GeneralParticleHandler.SpawnParticle(blood); } + Particle blastRing = new CustomPulse(Projectile.Center, Vector2.Zero, Color.Aquamarine * 0.8f, "CalamityMod/Particles/FlameExplosion", Vector2.One, Main.rand.NextFloat(-10, 10), 0f, 0.05f, 22); + GeneralParticleHandler.SpawnParticle(blastRing); + Particle blastRing2 = new CustomPulse(Projectile.Center, Vector2.Zero, Color.Aqua * 0.8f, "CalamityMod/Particles/FlameExplosion", Vector2.One, Main.rand.NextFloat(-10, 10), 0f, 0.04f, 22); + GeneralParticleHandler.SpawnParticle(blastRing2); + Particle blastRing3 = new CustomPulse(Projectile.Center, Vector2.Zero, Color.DeepSkyBlue, "CalamityMod/Particles/DetailedExplosion", Vector2.One, Main.rand.NextFloat(-10, 10), 0f, 0.2f, 22); + GeneralParticleHandler.SpawnParticle(blastRing3); + Particle orb2 = new GenericBloom(Projectile.Center, Vector2.Zero, Color.SkyBlue, 0.6f, 11, false, true); + GeneralParticleHandler.SpawnParticle(orb2); } } } diff --git a/Projectiles/Ranged/AquaBlast.png b/Projectiles/Ranged/AquaBlast.png index 91449ac4c5..3d5a42c1ee 100644 Binary files a/Projectiles/Ranged/AquaBlast.png and b/Projectiles/Ranged/AquaBlast.png differ diff --git a/Projectiles/Ranged/AquaBlastToxic.cs b/Projectiles/Ranged/AquaBlastToxic.cs deleted file mode 100644 index 963152fa75..0000000000 --- a/Projectiles/Ranged/AquaBlastToxic.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Projectiles.Ranged -{ - public class AquaBlastToxic : ModProjectile, ILocalizedModType - { - public new string LocalizationCategory => "Projectiles.Ranged"; - public override void SetStaticDefaults() - { - Main.projFrames[Projectile.type] = 4; - } - - public override void SetDefaults() - { - Projectile.width = 12; - Projectile.height = 12; - Projectile.friendly = true; - Projectile.ignoreWater = true; - Projectile.penetrate = 1; - Projectile.timeLeft = 600; - Projectile.DamageType = DamageClass.Ranged; - Projectile.extraUpdates = 1; - Projectile.Calamity().pointBlankShotDuration = CalamityGlobalProjectile.DefaultPointBlankDuration; - } - - public override void AI() - { - //Animation - Projectile.frameCounter++; - if (Projectile.frameCounter > 5) - { - Projectile.frame++; - Projectile.frameCounter = 0; - } - if (Projectile.frame > 3) - { - Projectile.frame = 0; - } - - //Rotation - Projectile.spriteDirection = Projectile.direction = (Projectile.velocity.X > 0).ToDirectionInt(); - Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == 1 ? 0f : MathHelper.Pi) + MathHelper.ToRadians(90) * Projectile.direction; - - Lighting.AddLight(Projectile.Center, (255 - Projectile.alpha) * 0f / 255f, (255 - Projectile.alpha) * 0.35f / 255f, (255 - Projectile.alpha) * 0.4f / 255f); - for (int i = 0; i < 2; i++) - { - Vector2 dspeed = -Projectile.velocity * Main.rand.NextFloat(0.5f * 0.8f); - int dust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.GemEmerald, 0f, 0f, 100, default, 1f); - Main.dust[dust].noGravity = true; - Main.dust[dust].velocity = dspeed; - } - } - - public override void OnKill(int timeLeft) - { - for (int lol = 0; lol < 10; lol++) - { - Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.GemEmerald, 0f, 0f, 100, default, 1f); - } - } - - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) - { - target.AddBuff(BuffID.Venom, 120); - } - } -} diff --git a/Projectiles/Ranged/AquaBlastToxic.png b/Projectiles/Ranged/AquaBlastToxic.png deleted file mode 100644 index db383de083..0000000000 Binary files a/Projectiles/Ranged/AquaBlastToxic.png and /dev/null differ diff --git a/Projectiles/Ranged/ChromaticEruptionHoldout.cs b/Projectiles/Ranged/ChromaticEruptionHoldout.cs index e737a8ba0a..a75797766f 100644 --- a/Projectiles/Ranged/ChromaticEruptionHoldout.cs +++ b/Projectiles/Ranged/ChromaticEruptionHoldout.cs @@ -13,9 +13,9 @@ namespace CalamityMod.Projectiles.Ranged public class ChromaticEruptionHoldout : BaseGunHoldoutProjectile { public override int AssociatedItemID => ModContent.ItemType(); - public override float MaxOffsetLengthFromArm => 15f; + public override float MaxOffsetLengthFromArm => 40f; public override float OffsetXUpwards => -10f; - public override float BaseOffsetY => -5f; + public override float BaseOffsetY => -12f; public override float OffsetYDownwards => 10f; public ref float ShotCooldown => ref Projectile.ai[0]; diff --git a/Projectiles/Ranged/ExoLight.cs b/Projectiles/Ranged/ExoLight.cs index d1db382e64..2cf433a89a 100644 --- a/Projectiles/Ranged/ExoLight.cs +++ b/Projectiles/Ranged/ExoLight.cs @@ -82,10 +82,19 @@ namespace CalamityMod.Projectiles.Ranged Projectile.scale = MathHelper.Lerp(0.001f, 1f, Utils.GetLerpValue(0f, 25f, Time, true)); if (Projectile.localAI[0] == 0f) { + float currentDist = 25000f; foreach (NPC n in Main.ActiveNPCs) { if (n.CanBeChasedBy(Projectile.GetSource_FromThis(), false)) - NPCDestination = n.Center + n.velocity * 5f; + { + Vector2 potentialDest = n.Center + n.velocity * 5f; + float newDist = potentialDest.Distance(Projectile.Center); + if (newDist < currentDist) + { + currentDist = newDist; + NPCDestination = potentialDest; + } + } } InitialCenter = Projectile.Center; Projectile.localAI[0] = 1f; diff --git a/Projectiles/Ranged/LeviatitanAberration.cs b/Projectiles/Ranged/LeviatitanAberration.cs new file mode 100644 index 0000000000..836c490874 --- /dev/null +++ b/Projectiles/Ranged/LeviatitanAberration.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Dusts; +using CalamityMod.Particles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Projectiles.Ranged +{ + public class LeviatitanAberration : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Ranged"; + public override string Texture => "CalamityMod/Projectiles/Summon/GastricBelcher"; + public override void SetStaticDefaults() + { + Main.projFrames[Projectile.type] = 4; + ProjectileID.Sets.CultistIsResistantTo[Type] = true; + } + public override void SetDefaults() + { + Projectile.width = 40; + Projectile.height = 40; + Projectile.aiStyle = ProjAIStyleID.Arrow; + Projectile.friendly = true; + Projectile.tileCollide = false; + Projectile.DamageType = DamageClass.Ranged; + Projectile.penetrate = 1; + Projectile.timeLeft = 600; + AIType = ProjectileID.Bullet; + } + + public override void AI() + { + CalamityUtils.HomeInOnNPC(Projectile, true, 500f, 16f, 8f); + + //Rotation + Projectile.spriteDirection = Projectile.direction = (Projectile.velocity.X > 0).ToDirectionInt(); + Projectile.rotation = Projectile.velocity.ToRotation() + (Projectile.spriteDirection == 1 ? 0f : MathHelper.Pi) + MathHelper.ToRadians(360) * Projectile.direction; + + //Update frames + if (Projectile.frameCounter++ % 6 == 0) + { + Projectile.frame++; + } + if (Projectile.frame >= Main.projFrames[Projectile.type]) + { + Projectile.frame = 0; + } + for (int i = 0; i < 3; i++) + { + int bloodDust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height / 2, DustID.Blood, 0f, 0f, 100, default, 1f); + Main.dust[bloodDust].noGravity = true; + Main.dust[bloodDust].velocity *= 0.5f; + Main.dust[bloodDust].velocity += Projectile.velocity * 0.1f; + } + } + public override void OnSpawn(IEntitySource source) + { + for (int i = 0; i < 36; i++) + { + Dust minion = Dust.NewDustPerfect(Projectile.Center, DustID.MoonBoulder); + minion.velocity = (MathHelper.TwoPi * i / 36f).ToRotationVector2() * 9f; + minion.scale = Main.rand.NextFloat(1.4f, 1.6f); + minion.noGravity = true; + } + } + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + target.AddBuff(ModContent.BuffType(), 120); + SoundEngine.PlaySound(SoundID.NPCDeath1 with { Volume = SoundID.NPCDeath1.Volume * 0.5f }, Projectile.Center); + } + public override void OnKill(int timeLeft) + { + for (int d = 0; d < 15; ++d) + { + int idx = Dust.NewDust(Projectile.Center - Vector2.One * 10f, 50, 50, DustID.Blood, 0f, -2f, 0, default, 1f); + Dust dust = Main.dust[idx]; + dust.velocity /= 2f; + } + } + } +} diff --git a/Projectiles/Ranged/LeviatitanExplosion.cs b/Projectiles/Ranged/LeviatitanExplosion.cs new file mode 100644 index 0000000000..fd318a87ec --- /dev/null +++ b/Projectiles/Ranged/LeviatitanExplosion.cs @@ -0,0 +1,30 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; +namespace CalamityMod.Projectiles.Ranged +{ + public class LeviatitanExplosion : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Ranged"; + public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public Player Owner => Main.player[Projectile.owner]; + private static float ExplosionRadius = 112f; + + public override void SetDefaults() + { + //These shouldn't matter because its circular + Projectile.width = 112; + Projectile.height = 112; + Projectile.friendly = true; + Projectile.DamageType = DamageClass.Ranged; + Projectile.ignoreWater = true; + Projectile.tileCollide = false; + Projectile.penetrate = -1; + Projectile.timeLeft = 2; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 10; + } + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, ExplosionRadius, targetHitbox); + } +} diff --git a/Projectiles/Ranged/LeviatitanMeteor.cs b/Projectiles/Ranged/LeviatitanMeteor.cs new file mode 100644 index 0000000000..ef3279a3ea --- /dev/null +++ b/Projectiles/Ranged/LeviatitanMeteor.cs @@ -0,0 +1,104 @@ +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.ID; +using Terraria.ModLoader; +using CalamityMod.Particles; +using Terraria.DataStructures; +using System; + +namespace CalamityMod.Projectiles.Ranged +{ + public class LeviatitanMeteor : ModProjectile, ILocalizedModType + { + public new string LocalizationCategory => "Projectiles.Ranged"; + public override string Texture => "CalamityMod/Projectiles/Melee/AftershockRock"; + public override void SetStaticDefaults() + { + ProjectileID.Sets.TrailCacheLength[Projectile.type] = 5; + ProjectileID.Sets.TrailingMode[Projectile.type] = 0; + } + public static int Lifetime = 600; + public override void SetDefaults() + { + Projectile.width = 38; + Projectile.height = 38; + Projectile.friendly = true; + Projectile.penetrate = 1; + Projectile.timeLeft = Lifetime; + Projectile.DamageType = DamageClass.Ranged; + } + + public override void AI() + { + if (Projectile.velocity.Y < 25f) + Projectile.velocity.Y += 0.12f; + Projectile.rotation += Projectile.velocity.X * 0.05f; + + if (Projectile.timeLeft <= Lifetime - 6) + { + if (Main.rand.NextBool(3)) + { + MediumMistParticle SandCloud = new MediumMistParticle(Projectile.Center + new Vector2(25, 25).RotatedByRandom(100) * Main.rand.NextFloat(0.1f, 1.3f) * Projectile.scale, (-Projectile.velocity * 0.2f).RotatedByRandom(0.2f) + (new Vector2(3, 3).RotatedByRandom(100)), Color.Peru, Color.PeachPuff, Main.rand.NextFloat(0.4f, 1.3f), 120f, Main.rand.NextFloat(0.03f, -0.03f)); + GeneralParticleHandler.SpawnParticle(SandCloud); + } + int dust = Dust.NewDust(Projectile.position, Projectile.width, Projectile.height, DustID.UnusedBrown, 0f, 0f, 100, default, Main.rand.NextFloat(0.75f, 1.2f)); + Main.dust[dust].velocity *= 0f; + } + } + public override void OnSpawn(IEntitySource source) + { + Vector2 smokeVel = Projectile.velocity.SafeNormalize(Vector2.UnitY) * 5; + int smokeAmount = Main.rand.Next(8, 12 + 1); + for (int i = 0; i < smokeAmount; i++) + { + Particle smoke = new HeavySmokeParticle(Projectile.Center, smokeVel.RotatedByRandom(0.4f) * Main.rand.NextFloat(1.2f, 2f), Color.White, Main.rand.Next(40, 60 + 1), Main.rand.NextFloat(0.2f, 0.4f), 0.3f, Main.rand.NextFloat(-0.2f, 0.2f), Main.rand.NextBool(), required: true); + GeneralParticleHandler.SpawnParticle(smoke); + + } + } + public override void OnKill(int timeLeft) + { + if (Projectile.owner == Main.myPlayer) + { + SoundStyle explo = new("CalamityMod/Sounds/Item/MineralMortarExplode"); + SoundEngine.PlaySound(explo with { Volume = 0.9f }, Projectile.Center); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 0f); + for (int i = 0; i < 8; i++) + { + Vector2 randVel = new Vector2(12, 12).RotatedByRandom(100) * Main.rand.NextFloat(0.2f, 0.7f); + Particle smoke = new HeavySmokeParticle(Projectile.Center + randVel, randVel, Color.Peru, Main.rand.Next(25, 35 + 1), Main.rand.NextFloat(0.9f, 2.3f), 0.4f); + GeneralParticleHandler.SpawnParticle(smoke); + MediumMistParticle SandCloud = new MediumMistParticle(Projectile.Center, randVel * 0.8f, Color.Peru, Color.PeachPuff, Main.rand.NextFloat(0.4f, 1.3f), 120f, Main.rand.NextFloat(0.03f, -0.03f)); + GeneralParticleHandler.SpawnParticle(SandCloud); + } + int debriAmount = Main.rand.Next(10, 15 + 1); + for (int debriIndex = 0; debriIndex < debriAmount; debriIndex++) + { + float angle = MathHelper.TwoPi / debriAmount * debriIndex; + Vector2 velocity = angle.ToRotationVector2() * Main.rand.NextFloat(2f, 8f); + Particle debri = new StoneDebrisParticle(Projectile.Center, velocity, Color.Lerp(Color.White, Color.LightGray, Main.rand.NextFloat()), Main.rand.NextFloat(0.4f, 0.6f), Main.rand.Next(30, 45 + 1), Main.rand.NextFloat(MathHelper.Pi)); + GeneralParticleHandler.SpawnParticle(debri); + } + int mistAmount = Main.rand.Next(5, 8 + 1); + for (int mistIndex = 0; mistIndex < mistAmount; mistIndex++) + { + float angle = MathHelper.TwoPi / mistAmount * mistIndex; + Vector2 velocity = angle.ToRotationVector2() * Main.rand.NextFloat(5f, 15f); + Particle boomMist = new MediumMistParticle(Projectile.Center, velocity, Color.SaddleBrown * 0.8f, Color.Transparent, Main.rand.NextFloat(.6f, 1.4f), Main.rand.NextFloat(200f, 400f)); + GeneralParticleHandler.SpawnParticle(boomMist); + } + Particle blastRing2 = new CustomPulse(Projectile.Center, Vector2.Zero, Color.Red, "CalamityMod/Particles/ShatteredExplosion", Vector2.One, Main.rand.NextFloat(-10, 10), Projectile.width / 5000f, Projectile.width / 200f, 29, true, 0.7f); + GeneralParticleHandler.SpawnParticle(blastRing2); + Particle blastRing = new CustomPulse(Projectile.Center, Vector2.Zero, Color.SaddleBrown * 0.8f, "CalamityMod/Particles/FlameExplosion", Vector2.One, Main.rand.NextFloat(-10, 10), Projectile.width / 5000f, Projectile.width / 300f, 29); + GeneralParticleHandler.SpawnParticle(blastRing); + } + } + public override bool PreDraw(ref Color lightColor) + { + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 1); + return false; + } + } +} diff --git a/Projectiles/Rogue/SamsaraSlicerProjectile.cs b/Projectiles/Rogue/SamsaraSlicerProjectile.cs index e0c48554f8..e4e11c27af 100644 --- a/Projectiles/Rogue/SamsaraSlicerProjectile.cs +++ b/Projectiles/Rogue/SamsaraSlicerProjectile.cs @@ -1,7 +1,12 @@ using System; +using CalamityMod.Particles; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using MonoMod.Core.Utils; +using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; @@ -12,9 +17,17 @@ namespace CalamityMod.Projectiles.Rogue public new string LocalizationCategory => "Projectiles.Rogue"; public override string Texture => "CalamityMod/Items/Weapons/Rogue/SamsaraSlicer"; - private bool initialized = false; - private int Lifetime = 180; - private int ReboundTime = 45; + public float ReboundVelocity => 20; + public float StealthReboundVelocity => 30; + public float StealthPauseTime => 55; + public int ReboundTime => 20; + + public int SmallDiskDamage => 8; + public int SmallDiskStealthDamage => 17; + + public bool initialized = false; + + Vector2 oldVelocity; public override void SetStaticDefaults() { @@ -27,180 +40,240 @@ namespace CalamityMod.Projectiles.Rogue Projectile.width = Projectile.height = 46; Projectile.ignoreWater = true; Projectile.friendly = true; - Projectile.tileCollide = false; + Projectile.tileCollide = true; Projectile.usesLocalNPCImmunity = true; - Projectile.localNPCHitCooldown = 10; + Projectile.localNPCHitCooldown = 30; Projectile.penetrate = -1; Projectile.DamageType = RogueDamageClass.Instance; + Projectile.aiStyle = -1; + Projectile.ai[0] = -200; + Projectile.ai[2] = -200; + } + + public override bool TileCollideStyle(ref int width, ref int height, ref bool fallThrough, ref Vector2 hitboxCenterFrac) + { + width = 20; + height = 20; + + return base.TileCollideStyle(ref width, ref height, ref fallThrough, ref hitboxCenterFrac); } public override void AI() { - Initialize(); - BoomerangAI(); - StealthStrikeAI(); - SpawnProjectilesNearEnemies(); - LightingandDust(); - } + Lighting.AddLight(Projectile.Center, new Vector3(0.1f, 0.5f, 0.03f)); - private void Initialize() - { - if (initialized) - return; - - Lifetime = Projectile.Calamity().stealthStrike ? 360 : 180; - ReboundTime = Projectile.Calamity().stealthStrike ? 90 : 45; - Projectile.timeLeft = Lifetime; - initialized = true; - } - - private void BoomerangAI() - { - // Boomerang rotation - Projectile.rotation += 0.4f * Projectile.direction; - - // Boomerang sound - if (Projectile.soundDelay == 0) + if (!initialized) { - Projectile.soundDelay = 8; - SoundEngine.PlaySound(SoundID.Item7, Projectile.position); + Projectile.ai[2] = -200; + Projectile.ai[0] = -200; + initialized = true; } - // Returns after some number of frames in the air - if (Projectile.timeLeft < Lifetime - ReboundTime) - Projectile.ai[0] = 1f; + Player player = Main.player[Projectile.owner]; - if (Projectile.ai[0] == 1f) + // Main movement + + if (Projectile.ai[0] < 0) { - //Ignore tiles and fly faster - Projectile.tileCollide = false; - Projectile.extraUpdates = 1; + Projectile.ai[1]++; - Player player = Main.player[Projectile.owner]; - float returnSpeed = 16f; - float acceleration = 1.4f; - Vector2 playerVec = player.Center - Projectile.Center; - float dist = playerVec.Length(); - - // Delete the projectile if it's excessively far away. - if (dist > 3000f) - Projectile.Kill(); - - playerVec.Normalize(); - playerVec *= returnSpeed; - - // Home back in on the player. - if (Projectile.velocity.X < playerVec.X) + if (Projectile.ai[1] > ReboundTime) { - Projectile.velocity.X += acceleration; - if (Projectile.velocity.X < 0f && playerVec.X > 0f) - Projectile.velocity.X += acceleration; - } - else if (Projectile.velocity.X > playerVec.X) - { - Projectile.velocity.X -= acceleration; - if (Projectile.velocity.X > 0f && playerVec.X < 0f) - Projectile.velocity.X -= acceleration; - } - if (Projectile.velocity.Y < playerVec.Y) - { - Projectile.velocity.Y += acceleration; - if (Projectile.velocity.Y < 0f && playerVec.Y > 0f) - Projectile.velocity.Y += acceleration; - } - else if (Projectile.velocity.Y > playerVec.Y) - { - Projectile.velocity.Y -= acceleration; - if (Projectile.velocity.Y > 0f && playerVec.Y < 0f) - Projectile.velocity.Y -= acceleration; - } + Projectile.tileCollide = false; - // Delete the projectile if it touches its owner. - if (Main.myPlayer == Projectile.owner) - if (Projectile.Hitbox.Intersects(player.Hitbox)) - Projectile.Kill(); - } - } + float lerp = (float)(Projectile.ai[1] - ReboundTime) * 0.01f; - private void StealthStrikeAI() - { - if (!Projectile.Calamity().stealthStrike) - return; + if (Projectile.Calamity().stealthStrike) + lerp = (float)(Projectile.ai[1] - ReboundTime) * 0.005f; - if (Projectile.timeLeft % 8f == 0f && Main.myPlayer == Projectile.owner) - { - int disk = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), Projectile.damage / 4, Projectile.knockBack / 4f, Projectile.owner, Projectile.identity, Main.rand.NextFloat(0.02f, 0.1f)); - Main.projectile[disk].timeLeft *= 2; - Main.projectile[disk].aiStyle = -1; - } - } + Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.DirectionTo(player.Center) * (Projectile.Calamity().stealthStrike ? StealthReboundVelocity : ReboundVelocity), lerp); - private void SpawnProjectilesNearEnemies() - { - if (!Projectile.friendly) - return; - - const float maxDistance = 300f; - bool homeIn = false; - - foreach (NPC npc in Main.ActiveNPCs) - { - if (npc.CanBeChasedBy(Projectile, false)) - { - float extraDistance = npc.width / 2 + npc.height / 2; - - bool canHit = true; - if (extraDistance < maxDistance) - canHit = Collision.CanHit(Projectile.Center, 1, 1, npc.Center, 1, 1); - - if (Vector2.Distance(npc.Center, Projectile.Center) < maxDistance + extraDistance && canHit) + if (Projectile.Distance(player.Center) < Projectile.velocity.Length() * 1.4f) { - homeIn = true; - break; - } - } - } - - if (homeIn) - { - if (Main.player[Projectile.owner].miscCounter % 50 == 0) - { - int splitProj = ModContent.ProjectileType(); - if (Projectile.owner == Main.myPlayer) - { - float spread = 60f * 0.0174f; - double startAngle = Math.Atan2(Projectile.velocity.X, Projectile.velocity.Y) - spread / 2; - double deltaAngle = spread / 6f; - for (int i = 0; i < 6; i++) + for (int i = 0; i < Main.projectile.Length; i++) { - Vector2 velocity = ((MathHelper.TwoPi * i / 6f) - MathHelper.PiOver2).ToRotationVector2() * 6f; - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), Projectile.damage / 2, Projectile.knockBack * 0.5f, Projectile.owner); + Projectile proj = Main.projectile[i]; + + if (proj.type == ModContent.ProjectileType()) + { + if ((proj.ModProjectile as SamsaraSlicerSmallDisk).Parent == Projectile) + { + (Main.projectile[i].ModProjectile as SamsaraSlicerSmallDisk).Parent = null; + } + } } + + Projectile.Kill(); } } } - } - private void LightingandDust() - { - Lighting.AddLight(Projectile.Center, 0f, 0.75f, 0f); - if (!Main.rand.NextBool(5)) - return; - Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.TerraBlade, Projectile.velocity.X, Projectile.velocity.Y); + // Frame pause + + if (Projectile.ai[0] > -150) Projectile.ai[0]--; + + if (Projectile.ai[0] == 0) + { + Projectile.velocity = oldVelocity; + + SoundEngine.PlaySound(SoundID.DD2_SkyDragonsFuryShot.WithPitchOffset(1f)); + + + if (Projectile.Calamity().stealthStrike) + { + SoundEngine.PlaySound(SoundID.Item122.WithPitchOffset(1f), Projectile.Center); + + for (int i = 1; i <= 3; i++) + { + GeneralParticleHandler.SpawnParticle(new CustomPulse(Projectile.Center, oldVelocity * MathHelper.Lerp(2f, 1f, (float)i / 3f) / 4, Color.LimeGreen, "CalamityMod/Particles/SoftRoundExplosion", new Vector2(0.6f, 1f), oldVelocity.ToRotation(), 0.02f, 0.05f * i, 30)); + } + + for (int i = -10; i <= 20; i++) + { + GeneralParticleHandler.SpawnParticle(new CustomSpark(Projectile.Center, new Vector2(i * 2, 0).RotatedBy(Projectile.velocity.ToRotation()), "CalamityMod/Particles/ThinEndedLine", false, 10, Main.rand.NextFloat(0.3f, 1f), Main.rand.NextBool() ? new Color(1f, 0.8f, 0.1f) : Color.LimeGreen, new Vector2(Main.rand.NextFloat(0.4f, 1f), 1f))); + } + } + else + { + for (int i = 1; i <= 2; i++) + GeneralParticleHandler.SpawnParticle(new CustomPulse(Projectile.Center, new Vector2(i == 1 ? 2 : 6, 0).RotatedBy(Projectile.velocity.ToRotation()), Color.LimeGreen, "CalamityMod/Particles/BloomRing", new Vector2(0.5f, 1f), Projectile.velocity.ToRotation(), 0.1f, 0.5f - (i * 0.1f), 20)); + } + + for (int i = 0; i <= 5; i++) + GeneralParticleHandler.SpawnParticle(new CustomSpark(Projectile.Center, new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-10f, 10f)).RotatedBy(Projectile.velocity.ToRotation()), "CalamityMod/Particles/ThinEndedLine", false, 10, Main.rand.NextFloat(0.3f, 1f), Main.rand.NextBool() ? new Color(1f, 0.8f, 0.1f) : Color.LimeGreen, new Vector2(Main.rand.NextFloat(0.4f, 1f), 1f))); + } + + if (Projectile.ai[0] <= 0 && Projectile.ai[0] > -4) + { + Projectile.extraUpdates = 1; + } + else + { + Projectile.extraUpdates = 0; + } + + Vector2 vel = Projectile.velocity; + if (Projectile.ai[0] > 0) + { + vel = new Vector2(18); + } + + if (Projectile.ai[2] > -150) + { + Projectile.ai[2]--; + } + + if (Projectile.ai[2] > 0) + { + if (Projectile.ai[2] % (Projectile.Calamity().stealthStrike ? 3 : 5) == 0) + { + SoundEngine.PlaySound(SoundID.Item23.WithPitchOffset(MathHelper.Lerp(1f, 0f, Projectile.ai[2] / 30)).WithVolumeScale(0.8f)); + } + + for (int i = 0; i <= 2; i++) + GeneralParticleHandler.SpawnParticle(new CustomSpark(Projectile.Center + new Vector2(25, 0).RotatedBy(oldVelocity.ToRotation()), new Vector2(Main.rand.NextFloat(-2f, 2f), Main.rand.NextFloat(-10f, 10f)).RotatedBy(oldVelocity.ToRotation()), "CalamityMod/Particles/ThinEndedLine", false, 10, Main.rand.NextFloat(0.3f, 1f), Main.rand.NextBool() ? new Color(1f, 0.8f, 0.1f) : Color.LimeGreen, new Vector2(Main.rand.NextFloat(0.4f, 1f), 1f))); + } + + if (Projectile.ai[2] > -150) + { + if (Projectile.Calamity().stealthStrike) + { + float SpawnVel = 15; + + float g = Main.rand.NextFloat(360f); + + if (!Main.dedServ) + { + Projectile proj = Projectile.NewProjectileDirect(new EntitySource_Parent(Projectile), Projectile.Center, new Vector2(SpawnVel, 0).RotatedBy(MathHelper.ToRadians(g)), + ModContent.ProjectileType(), Projectile.Calamity().stealthStrike ? SmallDiskStealthDamage : SmallDiskDamage, 1f, Projectile.owner, Projectile.whoAmI); + (proj.ModProjectile as SamsaraSlicerSmallDisk).Parent = Projectile; + } + } + } + + if (Projectile.ai[2] == 0) + { + Projectile.localNPCHitCooldown = 30; + } + + Projectile.rotation += MathHelper.ToRadians(vel.Length() * 1.5f); } public override bool PreDraw(ref Color lightColor) { - CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 2); + Asset tex = ModContent.Request(Texture); + + float rand = 0; + if (Projectile.ai[2] > 0) + { + rand = 4; + } + + Vector2 randVec = new Vector2(Main.rand.NextFloat(-rand, rand), 0).RotatedBy(oldVelocity.ToRotation()); + + Main.EntitySpriteDraw(tex.Value, Projectile.Center - Main.screenPosition + randVec, tex.Frame(), Color.White, Projectile.rotation, tex.Frame().Center(), 1f, SpriteEffects.None); + + if (Projectile.ai[2] < 0) + { + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], new Color(0f, 0.6f, 0f, 0f), 2, ModContent.Request("CalamityMod/Items/Weapons/Rogue/SamsaraSlicerGlow").Value); + } + else + { + //Main.EntitySpriteDraw(ModContent.Request("CalamityMod/Items/Weapons/Rogue/SamsaraSlicerGlow").Value, Projectile.Center - Main.screenPosition + randVec, tex.Frame(), new Color(0f, 1f, 0f, 0f), Projectile.rotation, tex.Frame().Center(), 1f, SpriteEffects.None); + + Main.EntitySpriteDraw(ModContent.Request("CalamityMod/Items/Weapons/Rogue/SamsaraSlicerGlow").Value, Projectile.Center - Main.screenPosition + randVec, tex.Frame(), new Color(0f, 1f, 0f, 0f), Projectile.rotation, tex.Frame().Center(), 1f, SpriteEffects.None); + } return false; } + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + if (Projectile.velocity != Vector2.Zero) + { + if (Projectile.ai[0] <= -200) + oldVelocity = Projectile.velocity * 1.5f; + else + oldVelocity = Projectile.velocity; + } + Projectile.ai[1] = ReboundTime - 10; + Projectile.velocity = Vector2.Zero; + Projectile.ai[0] = 5; + + SoundEngine.PlaySound(SoundID.DD2_WitherBeastCrystalImpact); + + if (Projectile.ai[2] == -200) + { + float lag = 20; + if (Projectile.Calamity().stealthStrike) lag = StealthPauseTime; + + Projectile.ai[0] = lag; + Projectile.ai[2] = lag; + + Projectile.localNPCHitCooldown = (int)lag; + + float g = Main.rand.NextFloat(360f); + + g -= 15f; + + float SpawnVel = 15; + if (Projectile.Calamity().stealthStrike) + SpawnVel = 20; + + if (!Main.dedServ) + { + for (float i = g; i < g + 360f; i += Projectile.Calamity().stealthStrike ? 45f : 90f) + { + Projectile proj = Projectile.NewProjectileDirect(new EntitySource_Parent(Projectile), Projectile.Center, new Vector2(SpawnVel, 0).RotatedBy(MathHelper.ToRadians(i)), + ModContent.ProjectileType(), Projectile.Calamity().stealthStrike ? SmallDiskStealthDamage : SmallDiskDamage, 1f, Projectile.owner, Projectile.whoAmI); + (proj.ModProjectile as SamsaraSlicerSmallDisk).Parent = Projectile; + proj.Calamity().stealthStrike = Projectile.Calamity().stealthStrike; + } + } + } + } + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { - // Return to the player after striking an enemy. Stealth strikes don't return immediately. - if (!Projectile.Calamity().stealthStrike || Projectile.ai[1] > 3) - Projectile.ai[0] = 1f; - Projectile.ai[1]++; } // Make it bounce on tiles. @@ -218,7 +291,7 @@ namespace CalamityMod.Projectiles.Rogue { Projectile.velocity.Y = -oldVelocity.Y; } - Projectile.ai[0] = 1f; + return false; } } diff --git a/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs b/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs index 9d0c40de2b..9e29cade13 100644 --- a/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs +++ b/Projectiles/Rogue/SamsaraSlicerSmallDisk.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; @@ -9,6 +10,7 @@ namespace CalamityMod.Projectiles.Rogue { public new string LocalizationCategory => "Projectiles.Rogue"; private double rotation = 0; + public Projectile Parent = null; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Projectile.type] = 10; @@ -19,78 +21,106 @@ namespace CalamityMod.Projectiles.Rogue { Projectile.width = 40; Projectile.height = 40; - Projectile.alpha = 75; Projectile.ignoreWater = true; Projectile.friendly = true; Projectile.tileCollide = false; Projectile.penetrate = -1; - Projectile.aiStyle = ProjAIStyleID.Boomerang; - Projectile.timeLeft = 60; - AIType = ProjectileID.WoodenBoomerang; + Projectile.aiStyle = -1; Projectile.DamageType = RogueDamageClass.Instance; - Projectile.usesIDStaticNPCImmunity = true; - Projectile.idStaticNPCHitCooldown = 6; + Projectile.usesLocalNPCImmunity = true; + Projectile.localNPCHitCooldown = 3; } public override void AI() { - StealthStrikeAI(); - LightingandDust(); - } - - private void StealthStrikeAI() - { - if (Projectile.aiStyle == 3) - return; - - Projectile.rotation += 0.4f * Projectile.direction; - - Projectile parent = Main.projectile[0]; - bool active = false; - foreach (Projectile p in Main.ActiveProjectiles) + if (Parent != null) { - if (p.identity == Projectile.ai[0] && p.type == ModContent.ProjectileType()) + if (!Parent.active) Parent = null; + } + + Player player = Main.player[Projectile.owner]; + + if (Projectile.Calamity().stealthStrike) + { + Projectile.localNPCHitCooldown = 3; + Projectile.usesLocalNPCImmunity = true; + } + + bool returning = false; + + Projectile.ai[1]++; + + Projectile.rotation += MathHelper.ToRadians(12f); + + float Vel = 15; + if (Projectile.Calamity().stealthStrike) Vel = 20; + + float length = 10; + if (Projectile.Calamity().stealthStrike) length = 15; + + if (Projectile.ai[1] > length) + { + Vel += (Projectile.ai[1] - length); + if (Parent != null) { - parent = p; - active = true; - break; + if (Parent.active) + { + Projectile.velocity = Vector2.Lerp(Projectile.velocity, Projectile.DirectionTo(Parent.Center) * Vel, Projectile.Calamity().stealthStrike ? 0.25f : 0.35f); + + if ((Projectile.Center + Projectile.velocity).Distance(Parent.Center) < Projectile.velocity.Length()) + { + Projectile.Kill(); + } + } + else returning = true; } + else returning = true; } - if (active) + if (Parent != null && Parent.active) { - Vector2 vector = parent.Center - Projectile.Center; - Projectile.Center = parent.Center + new Vector2(80, 0).RotatedBy(rotation); - double rotateAmt = (double)Projectile.ai[1]; - rotation += rotateAmt; - if (rotation >= 360) + Projectile.velocity = Projectile.velocity.RotatedBy(MathHelper.ToRadians(8f)); + } + + if (Parent != null && !returning) + { + Projectile.position += Parent.velocity; + } + + if (Parent == null) + { + Projectile.timeLeft = 5; + Projectile.position += player.velocity; + Projectile.velocity = Projectile.DirectionTo(player.Center) * 4f; + Projectile.scale *= 0.9f; + if (Projectile.Distance(player.Center) < Projectile.velocity.Length()) { - rotation = 0; + Projectile.Kill(); } - Projectile.velocity.X = (vector.X > 0f) ? -0.000001f : 0f; - } - else - { - Projectile.Kill(); - } - - if (!parent.active) - { - Projectile.Kill(); } } - private void LightingandDust() + public override void OnSpawn(IEntitySource source) { - Lighting.AddLight(Projectile.Center, 0f, 0.75f, 0f); - if (!Main.rand.NextBool(5)) - return; - Dust.NewDust(Projectile.position + Projectile.velocity, Projectile.width, Projectile.height, DustID.TerraBlade, Projectile.velocity.X, Projectile.velocity.Y); + Parent = Main.projectile[(int)Projectile.ai[0]]; + } + + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + target.immune[Projectile.owner] = 0; } public override bool PreDraw(ref Color lightColor) { - CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], lightColor, 2); + for (int i = 1; i < Projectile.oldPos.Length; i++) + { + Vector2 oldP1 = Projectile.oldPos[i]; + Vector2 oldP2 = Projectile.oldPos[i - 1]; + + Projectile.oldPos[i] = oldP2 + (oldP2.DirectionTo(oldP1) * MathHelper.Min(oldP2.Distance(oldP1), 5)); + } + + CalamityUtils.DrawAfterimagesCentered(Projectile, ProjectileID.Sets.TrailingMode[Projectile.type], new Color(0.2f, 1f, 0f, 0f), 2); return false; } } diff --git a/Projectiles/Summon/CelestialAxeMinion.cs b/Projectiles/Summon/CelestialAxeMinion.cs index ef8d7d91cb..0701bef64a 100644 --- a/Projectiles/Summon/CelestialAxeMinion.cs +++ b/Projectiles/Summon/CelestialAxeMinion.cs @@ -21,8 +21,8 @@ namespace CalamityMod.Projectiles.Summon public override void SetDefaults() { - Projectile.width = 52; - Projectile.height = 52; + Projectile.width = 100; + Projectile.height = 110; Projectile.netImportant = true; Projectile.friendly = true; Projectile.ignoreWater = true; @@ -33,6 +33,7 @@ namespace CalamityMod.Projectiles.Summon Projectile.minion = true; Projectile.tileCollide = false; Projectile.extraUpdates = 1; + Projectile.scale = 0.75f; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 30; Projectile.DamageType = DamageClass.Summon; @@ -68,11 +69,6 @@ namespace CalamityMod.Projectiles.Summon } } - public override Color? GetAlpha(Color lightColor) - { - return new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB, Projectile.alpha); - } - public override bool PreDraw(ref Color lightColor) { Texture2D tex = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; diff --git a/Projectiles/Summon/CelestialAxeMinion.png b/Projectiles/Summon/CelestialAxeMinion.png index d5862b9ec7..7ac940983f 100644 Binary files a/Projectiles/Summon/CelestialAxeMinion.png and b/Projectiles/Summon/CelestialAxeMinion.png differ diff --git a/Schematics/SchematicManager.cs b/Schematics/SchematicManager.cs index 44eb788302..1779d963b0 100644 --- a/Schematics/SchematicManager.cs +++ b/Schematics/SchematicManager.cs @@ -10,8 +10,7 @@ using Terraria.ModLoader; namespace CalamityMod.Schematics { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class SchematicManager + public sealed class SchematicManager : ModSystem { internal const string RustedWorkshopKey = "Rusted Workshop"; internal const string RustedWorkshopFilename = "Schematics/RustedWorkshop.csch"; @@ -96,7 +95,7 @@ namespace CalamityMod.Schematics public delegate void PilePlacementFunction(int x, int y, Rectangle placeInArea); #region Load/Unload - internal static void Load() + public override void OnModLoad() { PilePlacementMaps = new Dictionary(); TileMaps = new Dictionary @@ -152,7 +151,8 @@ namespace CalamityMod.Schematics ["Sulphurous Scrap 7"] = CalamitySchematicIO.LoadSchematic("Schematics/SulphurousScrap7.csch").ShaveOffEdge(), }; } - internal static void Unload() + + public override void Unload() { TileMaps = null; PilePlacementMaps = null; diff --git a/Skies/AstralMonolithSky.cs b/Skies/AstralMonolithSky.cs index 11135236e0..07dad080e5 100644 --- a/Skies/AstralMonolithSky.cs +++ b/Skies/AstralMonolithSky.cs @@ -40,7 +40,7 @@ namespace CalamityMod.Skies float whateverTheFuckThisVariableIsSupposedToBe = 3.40282347E+38f; if (maxDepth >= whateverTheFuckThisVariableIsSupposedToBe && minDepth < whateverTheFuckThisVariableIsSupposedToBe) { - spriteBatch.Draw(CalamityMod.AstralSky, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.White * opacity); + spriteBatch.Draw(SkyTextureRefs.AstralSky.Value, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.White * opacity); // Terraria's conditions. if (Main.netMode != NetmodeID.Server) diff --git a/Skies/AstralSky.cs b/Skies/AstralSky.cs index 7290303387..3c8d2caa0c 100644 --- a/Skies/AstralSky.cs +++ b/Skies/AstralSky.cs @@ -56,7 +56,7 @@ namespace CalamityMod.Skies float whateverTheFuckThisVariableIsSupposedToBe = 3.40282347E+38f; if (maxDepth >= whateverTheFuckThisVariableIsSupposedToBe && minDepth < whateverTheFuckThisVariableIsSupposedToBe) { - spriteBatch.Draw(CalamityMod.AstralSky, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.White * opacity); + spriteBatch.Draw(SkyTextureRefs.AstralSky.Value, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.White * opacity); // Terraria's conditions. if (Main.netMode != NetmodeID.Server) diff --git a/Skies/SkyTextureRefs.cs b/Skies/SkyTextureRefs.cs new file mode 100644 index 0000000000..6e27c10ae5 --- /dev/null +++ b/Skies/SkyTextureRefs.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria.ModLoader; + +namespace CalamityMod.Skies +{ + [Autoload(Side = ModSide.Client)] + internal sealed class SkyTextureRefs : ModSystem + { + // Astral Sky/BG + public static Asset AstralSky; + public static Asset AstralSurfaceFront; + public static Asset AstralSurfaceFrontGlow; + public static Asset AstralSurfaceClose; + public static Asset AstralSurfaceCloseGlow; + public static Asset AstralSurfaceMiddle; + public static Asset AstralSurfaceMiddleGlow; + + // Astral Desert Sky/BG + public static Asset AstralDesertSurfaceClose; + public static Asset AstralDesertSurfaceMiddle; + + // Astral Snow Sky/BG + public static Asset AstralSnowSurfaceMiddle; + + // Sulphur Sea Sky/BG + public static Asset SulphurSeaSky; + public static Asset SulphurSeaSkyFront; + public static Asset SulphurSeaSurface; + + public override void OnModLoad() + { + // Astral Sky/BG + AstralSky = ModContent.Request("CalamityMod/Skies/AstralSky"); + AstralSurfaceFront = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceFront"); + AstralSurfaceFrontGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceFrontGlow"); + AstralSurfaceClose = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceClose"); + AstralSurfaceCloseGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceCloseGlow"); + AstralSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceMiddle"); + AstralSurfaceMiddleGlow = ModContent.Request("CalamityMod/Backgrounds/AstralSurfaceMiddleGlow"); + + //Astral Desert Sky/BG + AstralDesertSurfaceClose = ModContent.Request("CalamityMod/Backgrounds/AstralDesertSurfaceClose"); + AstralDesertSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralDesertSurfaceMiddle"); + + //Astral Snow Sky/BG + AstralSnowSurfaceMiddle = ModContent.Request("CalamityMod/Backgrounds/AstralSnowSurfaceMiddle"); + + // Sulpher Sea Sky/BG + SulphurSeaSky = ModContent.Request("CalamityMod/Skies/SulphurSeaSky"); + SulphurSeaSkyFront = ModContent.Request("CalamityMod/Skies/SulphurSeaSkyFront"); + SulphurSeaSurface = ModContent.Request("CalamityMod/Skies/SulphurSeaSurface"); + } + + public override void Unload() + { + AstralSky = null; + AstralSurfaceFront = null; + AstralSurfaceFrontGlow = null; + AstralSurfaceClose = null; + AstralSurfaceCloseGlow = null; + AstralSurfaceMiddle = null; + AstralSurfaceMiddleGlow = null; + + AstralDesertSurfaceClose = null; + AstralDesertSurfaceMiddle = null; + + AstralSnowSurfaceMiddle = null; + + SulphurSeaSky = null; + SulphurSeaSkyFront = null; + SulphurSeaSurface = null; + } + } +} diff --git a/Skies/SulphurSeaSky.cs b/Skies/SulphurSeaSky.cs index bd8c4f1233..2c85b7fa4d 100644 --- a/Skies/SulphurSeaSky.cs +++ b/Skies/SulphurSeaSky.cs @@ -41,7 +41,7 @@ namespace CalamityMod.Skies public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth) { if (maxDepth >= 4f && minDepth < 4f) - spriteBatch.Draw(CalamityMod.SulphurSeaSky, new Rectangle(0, (int)(-Main.screenPosition.Y / 6f) + 1300, Main.screenWidth, Main.screenHeight), Color.Lerp(Main.ColorOfTheSkies, Color.LightSeaGreen, 0.33f) * 0.2f * opacity); + spriteBatch.Draw(SkyTextureRefs.SulphurSeaSky.Value, new Rectangle(0, (int)(-Main.screenPosition.Y / 6f) + 1300, Main.screenWidth, Main.screenHeight), Color.Lerp(Main.ColorOfTheSkies, Color.LightSeaGreen, 0.33f) * 0.2f * opacity); // Small worlds, default draw height int sulphurSeaHeight = (World.SulphurousSea.YStart + (int)Main.worldSurface) / 2; @@ -58,7 +58,7 @@ namespace CalamityMod.Skies // This changes the speed of the parralax, the closer the layer to the player the faster it should be. if (maxDepth >= 1f && minDepth < 1f) { - Texture2D texture = CalamityMod.SulphurSeaSkyFront; + Texture2D texture = SkyTextureRefs.SulphurSeaSkyFront.Value; // Keep in mind that y paralex should always be half of x's or it will feel odd compared to how terraria does it. // Keep in mind when you change screen parralax it affects the y offset for the bg in the world. @@ -84,7 +84,7 @@ namespace CalamityMod.Skies if (maxDepth >= 3f && minDepth < 3f) { - Texture2D texture = CalamityMod.SulphurSeaSurface; + Texture2D texture = SkyTextureRefs.SulphurSeaSurface.Value; int x = (int)(Main.screenPosition.X * ScreenParralaxMultiplier); x %= (int)(texture.Width * Scale); diff --git a/Systems/CalamityModWaterStyle.cs b/Systems/Graphic/CalamityModWaterStyle.cs similarity index 100% rename from Systems/CalamityModWaterStyle.cs rename to Systems/Graphic/CalamityModWaterStyle.cs diff --git a/Systems/HellBackgroundSystem.cs b/Systems/Graphic/HellBackgroundSystem.cs similarity index 100% rename from Systems/HellBackgroundSystem.cs rename to Systems/Graphic/HellBackgroundSystem.cs diff --git a/Systems/LavaRendering.cs b/Systems/Graphic/LavaRenderingSystem.cs similarity index 91% rename from Systems/LavaRendering.cs rename to Systems/Graphic/LavaRenderingSystem.cs index 8dc526e169..84d5f6cce2 100644 --- a/Systems/LavaRendering.cs +++ b/Systems/Graphic/LavaRenderingSystem.cs @@ -7,7 +7,9 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; using Terraria; +using Terraria.GameContent; using Terraria.GameContent.Liquid; using Terraria.Graphics; using Terraria.ID; @@ -16,18 +18,44 @@ using static Terraria.WaterfallManager; namespace CalamityMod.Systems { - public class LavaRendering : ModSystem + [Autoload(Side = ModSide.Client)] + public sealed class LavaRenderingSystem : ModSystem { //Welcome to Calamity's lava rendering. Prepare your eyes - public static LavaRendering instance; + public static LavaRenderingSystem Instance; - public int WaterStyleMaxCount = ModContent.GetContent().Count() + LoaderManager.Get().VanillaCount; + public static int LavaStyle; + public static float[] LavaAlpha = new float[1]; + internal static float[] AlphaSave = new float[1]; - internal static float[] alphaSave; + // Holds the Texture Arrays for all the lava textures. + // These are used for the lava styles. They are seperate from Textureasset.Instance._liquidTexture as they will conflict with ModWaterStyle + // Can hold up to 255 lava styles (more than enough) (excluding the normal lava texture which is liquidTexture 1) + public struct Textures + { + public static Asset[] liquid = new Asset[1]; + public static Asset[] slope = new Asset[1]; + public static Asset[] block = new Asset[1]; + public static Asset[] fall = new Asset[1]; + } + + public int WaterStyleMaxCount = 0; public override void Load() { - LavaRendering.alphaSave = new float[CalamityMod.lavaAlpha.Length]; + Instance = this; + } + + public override void OnModLoad() + { + WaterStyleMaxCount = ModContent.GetContent().Count() + LoaderManager.Get().VanillaCount; + + // Lava Texture + Textures.liquid[0] = LiquidRenderer.Instance._liquidTextures[1]; + Textures.slope[0] = TextureAssets.LiquidSlope[1]; + Textures.block[0] = TextureAssets.Liquid[1]; + var waterfallTexture = (Asset[])typeof(WaterfallManager).GetField("waterfallTexture", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Main.instance.waterfallManager); + Textures.fall[0] = waterfallTexture[1]; } public void DrawLavas(bool isBackground = false) @@ -35,17 +63,17 @@ namespace CalamityMod.Systems Main.drewLava = false; if (!isBackground) { - CalamityMod.LavaStyle = 0; + LavaStyle = 0; LavaStylesLoader.IsLavaActive(); for (int i = 0; i < 1; i++) { - if (CalamityMod.LavaStyle != i) + if (LavaStyle != i) { - CalamityMod.lavaAlpha[i] = Math.Max(CalamityMod.lavaAlpha[i] - 0.2f, 0f); + LavaAlpha[i] = Math.Max(LavaAlpha[i] - 0.2f, 0f); } else { - CalamityMod.lavaAlpha[i] = Math.Min(CalamityMod.lavaAlpha[i] + 0.2f, 1f); + LavaAlpha[i] = Math.Min(LavaAlpha[i] + 0.2f, 1f); } } LavaStylesLoader.UpdateLiquidAlphas(); @@ -53,18 +81,18 @@ namespace CalamityMod.Systems bool flag = false; for (int j = 0; j < LavaStylesLoader.TotalCount; j++) { - if (CalamityMod.lavaAlpha[j] > 0f && j != CalamityMod.LavaStyle) + if (LavaAlpha[j] > 0f && j != LavaStyle) { - DrawLiquid(isBackground, j, isBackground ? 1f : CalamityMod.lavaAlpha[j], drawSinglePassLiquids: false); + DrawLiquid(isBackground, j, isBackground ? 1f : LavaAlpha[j], drawSinglePassLiquids: false); flag = true; } } - DrawLiquid(isBackground, CalamityMod.LavaStyle, flag ? CalamityMod.lavaAlpha[CalamityMod.LavaStyle] : 1f); + DrawLiquid(isBackground, LavaStyle, flag ? LavaAlpha[LavaStyle] : 1f); } protected internal void DrawLiquid(bool bg = false, int lavaStyle = 0, float Alpha = 1f, bool drawSinglePassLiquids = true) { - if (!Lighting.NotRetro) + if (!Lighting.NotRetro) // Is Retro { oldDrawLava(bg, lavaStyle, Alpha); return; @@ -362,12 +390,12 @@ namespace CalamityMod.Systems color3.G = (byte)((color2.G * 3 + color4.G * 2) / 5); color3.B = (byte)((color2.B * 3 + color4.B * 2) / 5); color3.A = (byte)((color2.A * 3 + color4.A * 2) / 5); - Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + new Vector2((float)num20, (float)num21) + vector, (Rectangle?)new Rectangle(value.X + num20, value.Y + num21, width, height), color3, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + Main.spriteBatch.Draw(Textures.block[num4].Value, vector2 - Main.screenPosition + new Vector2((float)num20, (float)num21) + vector, (Rectangle?)new Rectangle(value.X + num20, value.Y + num21, width, height), color3, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); } } else { - Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)value, color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + Main.spriteBatch.Draw(Textures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)value, color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); } } else @@ -376,7 +404,7 @@ namespace CalamityMod.Systems { value.X += (int)(Main.wFrame * 18f); } - Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)value, color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + Main.spriteBatch.Draw(Textures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)value, color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); } if (!Main.tile[j, i + 1].IsHalfBlock) { @@ -389,7 +417,7 @@ namespace CalamityMod.Systems num19 = (float)(int)color.A * num9; color = new((int)(byte)num16, (int)(byte)num17, (int)(byte)num18, (int)(byte)num19); vector2 = new((float)(j * 16), (float)(i * 16 + 16)); - Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)new Rectangle(0, 4, 16, 8), color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + Main.spriteBatch.Draw(Textures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)new Rectangle(0, 4, 16, 8), color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); float num22 = 6f; float num24 = 0.75f; num22 = 4f; @@ -404,7 +432,7 @@ namespace CalamityMod.Systems float num26 = 1f - (float)m / num22; num26 *= num24; vector2 = new((float)(j * 16), (float)(num25 * 16 - 2)); - Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)new Rectangle(0, 18, 16, 16), color * num26, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + Main.spriteBatch.Draw(Textures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)new Rectangle(0, 18, 16, 16), color * num26, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); } } } @@ -550,11 +578,11 @@ namespace CalamityMod.Systems } if (waterStyleOverride != -1) { - CalamityMod.LavaStyle = waterStyleOverride; + LavaStyle = waterStyleOverride; } if (num2 == 0) { - num2 = CalamityMod.LavaStyle; + num2 = LavaStyle; } Lighting.GetCornerColors(tileX, tileY, out var vertices); Vector2 vector = new((float)(tileX * 16), (float)(tileY * 16)); @@ -653,7 +681,7 @@ namespace CalamityMod.Systems { for (int i = 0; i < LavaStylesLoader.TotalCount; i++) { - if (CalamityMod.lavaAlpha[i] > 0f && i != num2) + if (LavaAlpha[i] > 0f && i != num2) { DrawPartialLiquid(!solidLayer, tileCache, ref position, ref liquidSize, i, ref vertices); flag7 = true; @@ -662,7 +690,7 @@ namespace CalamityMod.Systems } } VertexColors colors = vertices; - float num7 = (flag7 ? CalamityMod.lavaAlpha[num2] : 1f); + float num7 = (flag7 ? LavaAlpha[num2] : 1f); ref Color bottomLeftColor2 = ref colors.BottomLeftColor; bottomLeftColor2 *= num7; ref Color bottomRightColor2 = ref colors.BottomRightColor; @@ -684,23 +712,23 @@ namespace CalamityMod.Systems } if (flag || num == 0) { - Main.tileBatch.Draw(CalamityMod.LavaTextures.block[liquidType].Value, position, liquidSize, colors, default(Vector2), 1f, (SpriteEffects)0); + Main.tileBatch.Draw(Textures.block[liquidType].Value, position, liquidSize, colors, default(Vector2), 1f, (SpriteEffects)0); return; } liquidSize.X += 18 * (num - 1); switch (num) { case 1: - Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + Main.tileBatch.Draw(Textures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); break; case 2: - Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + Main.tileBatch.Draw(Textures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); break; case 3: - Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + Main.tileBatch.Draw(Textures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); break; case 4: - Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + Main.tileBatch.Draw(Textures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); break; } } @@ -709,9 +737,9 @@ namespace CalamityMod.Systems { for (int i = 0; i < LavaStylesLoader.TotalCount; i++) { - if (CalamityMod.lavaAlpha[i] > 0f) + if (LavaAlpha[i] > 0f) { - DrawLavafall(waterfallManager, i, CalamityMod.lavaAlpha[i]); + DrawLavafall(waterfallManager, i, LavaAlpha[i]); } } } @@ -1117,8 +1145,8 @@ namespace CalamityMod.Systems private void DrawLavafall(int waterfallType, int x, int y, float opacity, Vector2 position, Rectangle sourceRect, Color color, SpriteEffects effects) { - Texture2D value = CalamityMod.LavaTextures.fall[waterfallType].Value; - Main.spriteBatch.Draw(value, position, (Rectangle?)sourceRect, color, 0f, default(Vector2), 1f, effects, 0f); + Texture2D value = Textures.fall[waterfallType].Value; + Main.spriteBatch.Draw(value, position, (Rectangle?)sourceRect, color, 0f, default, 1f, effects, 0f); } private static float GetLavafallAlpha(float Alpha, int maxSteps, int y, int s, Tile tileCache) @@ -1133,9 +1161,9 @@ namespace CalamityMod.Systems public static int dustLava() { - if (CalamityMod.LavaStyle >= 1) + if (LavaStyle >= 1) { - return LavaStylesLoader.Get(CalamityMod.LavaStyle).GetSplashDust(); + return LavaStylesLoader.Get(LavaStyle).GetSplashDust(); } else { @@ -1146,9 +1174,9 @@ namespace CalamityMod.Systems //just better as a method rather than hardcoded type values public static int goreLava() { - if (CalamityMod.LavaStyle >= 1) + if (LavaStyle >= 1) { - return LavaStylesLoader.Get(CalamityMod.LavaStyle).GetDropletGore(); + return LavaStylesLoader.Get(LavaStyle).GetDropletGore(); } else { diff --git a/Systems/LightingEffectsSystem.cs b/Systems/Graphic/LightingEffectsSystem.cs similarity index 100% rename from Systems/LightingEffectsSystem.cs rename to Systems/Graphic/LightingEffectsSystem.cs diff --git a/Systems/ModLavaStyle.cs b/Systems/Graphic/ModLavaStyle.cs similarity index 81% rename from Systems/ModLavaStyle.cs rename to Systems/Graphic/ModLavaStyle.cs index 84d229559a..bc015799fb 100644 --- a/Systems/ModLavaStyle.cs +++ b/Systems/Graphic/ModLavaStyle.cs @@ -127,11 +127,12 @@ namespace CalamityMod.Systems { orig.Invoke(unloading); int totalCount = TotalCount; - Array.Resize(ref CalamityMod.LavaTextures.liquid, totalCount); - Array.Resize(ref CalamityMod.LavaTextures.block, totalCount); - Array.Resize(ref CalamityMod.LavaTextures.slope, totalCount); - Array.Resize(ref CalamityMod.LavaTextures.fall, totalCount); - Array.Resize(ref CalamityMod.lavaAlpha, totalCount); + Array.Resize(ref LavaRenderingSystem.Textures.liquid, totalCount); + Array.Resize(ref LavaRenderingSystem.Textures.block, totalCount); + Array.Resize(ref LavaRenderingSystem.Textures.slope, totalCount); + Array.Resize(ref LavaRenderingSystem.Textures.fall, totalCount); + Array.Resize(ref LavaRenderingSystem.LavaAlpha, totalCount); + Array.Resize(ref LavaRenderingSystem.AlphaSave, totalCount); } private static readonly List _content = []; @@ -157,10 +158,10 @@ namespace CalamityMod.Systems foreach (ModLavaStyle item in Content) { int Slot = item.Slot; - CalamityMod.LavaTextures.liquid[Slot] = ModContent.Request(item.Texture, (AssetRequestMode)2); - CalamityMod.LavaTextures.block[Slot] = ModContent.Request(item.BlockTexture, (AssetRequestMode)2); - CalamityMod.LavaTextures.slope[Slot] = ModContent.Request(item.SlopeTexture, (AssetRequestMode)2); - CalamityMod.LavaTextures.fall[Slot] = ModContent.Request(item.WaterfallTexture, (AssetRequestMode)2); + LavaRenderingSystem.Textures.liquid[Slot] = ModContent.Request(item.Texture, AssetRequestMode.AsyncLoad); + LavaRenderingSystem.Textures.block[Slot] = ModContent.Request(item.BlockTexture, AssetRequestMode.AsyncLoad); + LavaRenderingSystem.Textures.slope[Slot] = ModContent.Request(item.SlopeTexture, AssetRequestMode.AsyncLoad); + LavaRenderingSystem.Textures.fall[Slot] = ModContent.Request(item.WaterfallTexture, AssetRequestMode.AsyncLoad); } } @@ -182,34 +183,34 @@ namespace CalamityMod.Systems public static void UpdateLiquidAlphas() { - if (CalamityMod.LavaStyle >= VanillaCount) + if (LavaRenderingSystem.LavaStyle >= VanillaCount) { for (int i = 0; i < VanillaCount; i++) { - CalamityMod.lavaAlpha[i] -= 0.2f; - if (CalamityMod.lavaAlpha[i] < 0f) + LavaRenderingSystem.LavaAlpha[i] -= 0.2f; + if (LavaRenderingSystem.LavaAlpha[i] < 0f) { - CalamityMod.lavaAlpha[i] = 0f; + LavaRenderingSystem.LavaAlpha[i] = 0f; } } } foreach (ModLavaStyle item in Content) { int type = item.Slot; - if (CalamityMod.LavaStyle == type) + if (LavaRenderingSystem.LavaStyle == type) { - CalamityMod.lavaAlpha[type] += 0.2f; - if (CalamityMod.lavaAlpha[type] > 1f) + LavaRenderingSystem.LavaAlpha[type] += 0.2f; + if (LavaRenderingSystem.LavaAlpha[type] > 1f) { - CalamityMod.lavaAlpha[type] = 1f; + LavaRenderingSystem.LavaAlpha[type] = 1f; } } else { - CalamityMod.lavaAlpha[type] -= 0.2f; - if (CalamityMod.lavaAlpha[type] < 0f) + LavaRenderingSystem.LavaAlpha[type] -= 0.2f; + if (LavaRenderingSystem.LavaAlpha[type] < 0f) { - CalamityMod.lavaAlpha[type] = 0f; + LavaRenderingSystem.LavaAlpha[type] = 0f; } } } @@ -253,7 +254,7 @@ namespace CalamityMod.Systems bool? flag = lavaStyle?.IsLavaActive(); if (flag != null && flag == true) { - CalamityMod.LavaStyle = lavaStyle.Slot; + LavaRenderingSystem.LavaStyle = lavaStyle.Slot; } } } diff --git a/Systems/Graphic/SkyEffectLoaderSystem.cs b/Systems/Graphic/SkyEffectLoaderSystem.cs new file mode 100644 index 0000000000..07ed6e0aac --- /dev/null +++ b/Systems/Graphic/SkyEffectLoaderSystem.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.NPCs.CalClone; +using CalamityMod.NPCs.DevourerofGods; +using CalamityMod.NPCs.Leviathan; +using CalamityMod.NPCs.PlaguebringerGoliath; +using CalamityMod.NPCs.Signus; +using CalamityMod.NPCs.Yharon; +using CalamityMod.Skies; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria.Graphics.Effects; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + [Autoload(Side = ModSide.Client)] + internal sealed class SkyEffectLoaderSystem : ModSystem + { + public override void Load() + { + Filters.Scene["CalamityMod:DevourerofGodsHead"] = new Filter(new DoGScreenShaderData("FilterMiniTower").UseColor(0.4f, 0.1f, 1.0f).UseOpacity(0.5f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:DevourerofGodsHead"] = new DoGSky(); + + Filters.Scene["CalamityMod:CalamitasRun3"] = new Filter(new CalScreenShaderData("FilterMiniTower").UseColor(1.1f, 0.3f, 0.3f).UseOpacity(0.6f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:CalamitasRun3"] = new CalSky(); + + Filters.Scene["CalamityMod:PlaguebringerGoliath"] = new Filter(new PbGScreenShaderData("FilterMiniTower").UseColor(0.2f, 0.6f, 0.2f).UseOpacity(0.35f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:PlaguebringerGoliath"] = new PbGSky(); + + Filters.Scene["CalamityMod:Yharon"] = new Filter(new YScreenShaderData("FilterMiniTower").UseColor(1f, 0.4f, 0f).UseOpacity(0.75f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:Yharon"] = new YSky(); + + Filters.Scene["CalamityMod:Leviathan"] = new Filter(new LevScreenShaderData("FilterMiniTower").UseColor(0f, 0f, 0.5f).UseOpacity(0.5f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:Leviathan"] = new LevSky(); + + Filters.Scene["CalamityMod:SupremeCalamitas"] = new Filter(new SCalScreenShaderData("FilterMiniTower").UseColor(Color.Transparent).UseOpacity(0f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:SupremeCalamitas"] = new SCalSky(); + + Filters.Scene["CalamityMod:Signus"] = new Filter(new SignusScreenShaderData("FilterMiniTower").UseColor(0.35f, 0.1f, 0.55f).UseOpacity(0.35f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:Signus"] = new SignusSky(); + + Filters.Scene["CalamityMod:BossRush"] = new Filter(new BossRushScreenShader("FilterMiniTower").UseOpacity(0.75f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:BossRush"] = new BossRushSky(); + + Filters.Scene["CalamityMod:ExoMechs"] = new Filter(new ExoMechsScreenShaderData("FilterMiniTower").UseColor(ExoMechsSky.DrawColor).UseOpacity(0.25f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:ExoMechs"] = new ExoMechsSky(); + + Filters.Scene["CalamityMod:MonolithAccursed"] = new Filter(new MonolithScreenShaderData("FilterMiniTower").UseColor(1.1f, 0.3f, 0.3f).UseOpacity(0.65f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:MonolithAccursed"] = new MonolithSky(); + + // Normal intensity is 4f + Texture2D DistortionTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/BlobbyNoise", AssetRequestMode.ImmediateLoad).Value; + Filters.Scene["CalamityMod:DrunkCrabulon"] = new Filter(new DrunkCrabScreenShaderData("FilterHeatDistortion").UseImage(DistortionTexture, 0, null).UseIntensity(20f), EffectPriority.VeryHigh); + + Filters.Scene["CalamityMod:BrimstoneCrag"] = new Filter(new MonolithScreenShaderData("FilterMiniTower").UseColor(0f, 0f, 0f).UseOpacity(0f), EffectPriority.VeryHigh); + SkyManager.Instance["CalamityMod:BrimstoneCrag"] = new BrimstoneCragSky(); + + SkyManager.Instance["CalamityMod:Astral"] = new AstralSky(); + SkyManager.Instance["CalamityMod:SulphurSea"] = new SulphurSeaSky(); + SkyManager.Instance["CalamityMod:Cryogen"] = new CryogenSky(); + SkyManager.Instance["CalamityMod:StormWeaverFlash"] = new StormWeaverFlashSky(); + } + } +} diff --git a/Systems/Mechanic/AttunementSystem.cs b/Systems/Mechanic/AttunementSystem.cs new file mode 100644 index 0000000000..0471e0d769 --- /dev/null +++ b/Systems/Mechanic/AttunementSystem.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.DataStructures; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + public sealed class AttunementSystem : ModSystem + { + public static Attunement[] Registry; + public static Attunement Empty => Registry[EmptyID]; + public static int EmptyID => Registry.Length - 1; + + public override void OnModLoad() + { + // This probably could be replaced to ReflectionHelper.IterateCalamityModTypes + Registry = [ + + // Broken Biome Blade + new DefaultAttunement(), new HotAttunement(), new ColdAttunement(), new TropicalAttunement(), new EvilAttunement(), + + // Biome Blade + new TrueDefaultAttunement(), new TrueHotAttunement(), new TrueColdAttunement(), new TrueTropicalAttunement(), new TrueEvilAttunement(), new HolyAttunement(), new AstralAttunement(), new MarineAttunement(), + + // True Biome Blade + new WhirlwindAttunement(), new FlailBladeAttunement(), new SuperPogoAttunement(), new ShockwaveAttunement(), + + // Galaxia + new PhoenixAttunement(), new AriesAttunement(), new PolarisAttunement(), new AndromedaAttunement(), + + // Empty Slot + null + ]; + } + + public override void Unload() + { + Registry = null; + } + + public static Attunement FindOrNull(int index) + { + if (index < 0) + return Empty; + + if (index >= Registry.Length) + return Empty; + + return Registry[index]; + } + + public static Attunement FindOrNull(AttunementID id) + { + return FindOrNull((int)id); + } + } +} diff --git a/Systems/DifficultyModeSystem.cs b/Systems/Mechanic/DifficultyModeSystem.cs similarity index 100% rename from Systems/DifficultyModeSystem.cs rename to Systems/Mechanic/DifficultyModeSystem.cs diff --git a/Systems/Mechanic/GraveyardBiomeSystem.cs b/Systems/Mechanic/GraveyardBiomeSystem.cs new file mode 100644 index 0000000000..b1104f87ba --- /dev/null +++ b/Systems/Mechanic/GraveyardBiomeSystem.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + internal sealed class GraveyardBiomeSystem : ModSystem + { + // For now it literally adjust the graveyard count required for GraveyardBiome + // But we can add something later on /shrug + + public override void OnModLoad() + { + // Make Graveyard biomes require more Gravestones + SceneMetrics.GraveyardTileMax = 60; + SceneMetrics.GraveyardTileMin = 40; + SceneMetrics.GraveyardTileThreshold = 52; + } + + public override void Unload() + { + SceneMetrics.GraveyardTileMax = 36; + SceneMetrics.GraveyardTileMin = 16; + SceneMetrics.GraveyardTileThreshold = 28; + } + } +} diff --git a/Systems/Mechanic/MountsBalancingSystem.cs b/Systems/Mechanic/MountsBalancingSystem.cs new file mode 100644 index 0000000000..4a71442443 --- /dev/null +++ b/Systems/Mechanic/MountsBalancingSystem.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.CalPlayer; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + internal sealed class MountsBalancingSystem : ModSystem + { + public override void OnModLoad() + { + // Mount balancing occurs during runtime and is undone when Calamity is unloaded. + Mount.mounts[MountID.Unicorn].dashSpeed *= CalamityPlayer.UnicornSpeedNerfPower; + Mount.mounts[MountID.Unicorn].runSpeed *= CalamityPlayer.UnicornSpeedNerfPower; + + // Buff DCU's pickaxe power to equal PML pickaxe capabilities + Mount.drillPickPower = 225; + } + + public override void Unload() + { + Mount.mounts[MountID.Unicorn].dashSpeed /= CalamityPlayer.UnicornSpeedNerfPower; + Mount.mounts[MountID.Unicorn].runSpeed /= CalamityPlayer.UnicornSpeedNerfPower; + + Mount.drillPickPower = 210; + } + } +} diff --git a/Systems/NerfExpertDebuffsSystem.cs b/Systems/Mechanic/NerfExpertDebuffsSystem.cs similarity index 100% rename from Systems/NerfExpertDebuffsSystem.cs rename to Systems/Mechanic/NerfExpertDebuffsSystem.cs diff --git a/Systems/RecipeSystem.cs b/Systems/Mechanic/RecipeSystem.cs similarity index 99% rename from Systems/RecipeSystem.cs rename to Systems/Mechanic/RecipeSystem.cs index 083c723721..e2e260a317 100644 --- a/Systems/RecipeSystem.cs +++ b/Systems/Mechanic/RecipeSystem.cs @@ -258,7 +258,8 @@ namespace CalamityMod.Systems ItemID.EbonstoneBlock, ItemID.CrimstoneBlock, ItemID.PearlstoneBlock, - ItemType() + ItemType(), + ItemType() }); AnyStoneBlock = RecipeGroup.RegisterGroup("AnyStoneBlock", group); @@ -502,6 +503,12 @@ namespace CalamityMod.Systems AddTile(TileID.DyeVat). Register(); + // Stohne smelts into Lihzahrd Bricks + Recipe.Create(ItemID.LihzahrdBrick). + AddIngredient(ItemType()). + AddTile(TileID.LihzahrdFurnace). + Register(); + // Earlier Rocket Is for early rocket weapons Recipe.Create(ItemID.RocketI, 100). AddRecipeGroup("IronBar"). diff --git a/Systems/Mechanic/SpeedrunTimerSystem.cs b/Systems/Mechanic/SpeedrunTimerSystem.cs new file mode 100644 index 0000000000..0a62f90e60 --- /dev/null +++ b/Systems/Mechanic/SpeedrunTimerSystem.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.CalPlayer; +using Terraria.ModLoader; +using static System.Net.Mime.MediaTypeNames; + +namespace CalamityMod.Systems +{ + internal sealed class SpeedrunTimerSystem : ModSystem + { + public static TimeSpan Elapsed => _SpeedrunTimer.Elapsed; + + private static Stopwatch _SpeedrunTimer = new(); + + private const string FormatStringForDay = @"hh\:mm\:ss\.ff"; + private const string FormatString = @"d\:hh\:mm\:ss\.ff"; + + public static void Restart() + { + _SpeedrunTimer.Restart(); + } + + public static string GetTimerText(CalamityPlayer player) + { + string formatStr = @"hh\:mm\:ss\.ff"; + string formatStrDays = @"d\:hh\:mm\:ss\.ff"; + TimeSpan totalTime = Elapsed.Add(player.previousSessionTotal); + return totalTime.ToString(totalTime.Days > 0 ? formatStrDays : formatStr); + } + + public static string GetSplitText(CalamityPlayer player) + { + TimeSpan split = player.lastSplit; + return split.ToString(split.Days > 0 ? FormatStringForDay : FormatString); + } + + public override void PreSaveAndQuit() => _SpeedrunTimer?.Stop(); + } +} diff --git a/Systems/TilePingerSystem.cs b/Systems/Mechanic/TilePingerSystem.cs similarity index 100% rename from Systems/TilePingerSystem.cs rename to Systems/Mechanic/TilePingerSystem.cs diff --git a/Systems/WorldSelectionDifficultySystem.cs b/Systems/Mechanic/WorldSelectionDifficultySystem.cs similarity index 99% rename from Systems/WorldSelectionDifficultySystem.cs rename to Systems/Mechanic/WorldSelectionDifficultySystem.cs index 73621eb404..7193069b77 100644 --- a/Systems/WorldSelectionDifficultySystem.cs +++ b/Systems/Mechanic/WorldSelectionDifficultySystem.cs @@ -19,7 +19,7 @@ namespace CalamityMod.Systems // The difficulty the world uses will be the latest applicable one, so these are added in order from easiest to hardest // These colors are all picked from the wiki's colors for each Difficulty combo // Calamity's own difficulties aren't added if the Luminance mod is on, as it adds its own world system - if (CalamityMod.Instance.luminance == null) + if (ExternalMods.luminance == null) { WorldDifficulties.Add(new WorldDifficulty(CalamityUtils.GetTextValue("UI.Revengeance"), GetRevengeance, new(211, 42, 42))); WorldDifficulties.Add(new WorldDifficulty(CalamityUtils.GetTextValue("UI.Death"), GetDeath, new(192, 64, 219))); diff --git a/Systems/AnyBossesOrEventsCheckSystem.cs b/Systems/ProgressionAndEvent/AnyBossesOrEventsCheckSystem.cs similarity index 100% rename from Systems/AnyBossesOrEventsCheckSystem.cs rename to Systems/ProgressionAndEvent/AnyBossesOrEventsCheckSystem.cs diff --git a/Systems/BossRushDialogueSystem.cs b/Systems/ProgressionAndEvent/BossRushDialogueSystem.cs similarity index 100% rename from Systems/BossRushDialogueSystem.cs rename to Systems/ProgressionAndEvent/BossRushDialogueSystem.cs diff --git a/Systems/DownedBossSystem.cs b/Systems/ProgressionAndEvent/DownedBossSystem.cs similarity index 100% rename from Systems/DownedBossSystem.cs rename to Systems/ProgressionAndEvent/DownedBossSystem.cs diff --git a/Systems/GungeonMusicSystem.cs b/Systems/Sound/GungeonMusicSystem.cs similarity index 100% rename from Systems/GungeonMusicSystem.cs rename to Systems/Sound/GungeonMusicSystem.cs diff --git a/Systems/MusicEventSystem.cs b/Systems/Sound/MusicEventSystem.cs similarity index 100% rename from Systems/MusicEventSystem.cs rename to Systems/Sound/MusicEventSystem.cs diff --git a/Systems/ORDERSystem.cs b/Systems/Sound/ORDERSystem.cs similarity index 100% rename from Systems/ORDERSystem.cs rename to Systems/Sound/ORDERSystem.cs diff --git a/Systems/SingularSoundInstanceSystem.cs b/Systems/Sound/SingularSoundInstanceSystem.cs similarity index 100% rename from Systems/SingularSoundInstanceSystem.cs rename to Systems/Sound/SingularSoundInstanceSystem.cs diff --git a/Systems/SpeedrunTimerStoppingSystem.cs b/Systems/SpeedrunTimerStoppingSystem.cs deleted file mode 100644 index 0923a54879..0000000000 --- a/Systems/SpeedrunTimerStoppingSystem.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Systems -{ - // TODO -- Expand this ModSystem to contain the Speedrun Timer itself, as well as the UI. - public class SpeedrunTimerStoppingSystem : ModSystem - { - public override void PreSaveAndQuit() => CalamityMod.SpeedrunTimer?.Stop(); - } -} diff --git a/Systems/BiomeTileCounterSystem.cs b/Systems/Tile/BiomeTileCounterSystem.cs similarity index 100% rename from Systems/BiomeTileCounterSystem.cs rename to Systems/Tile/BiomeTileCounterSystem.cs diff --git a/Systems/SulphuricWaterSafeZoneSystem.cs b/Systems/Tile/SulphuricWaterSafeZoneSystem.cs similarity index 100% rename from Systems/SulphuricWaterSafeZoneSystem.cs rename to Systems/Tile/SulphuricWaterSafeZoneSystem.cs diff --git a/Systems/TempTilesManagerSystem.cs b/Systems/Tile/TempTilesManagerSystem.cs similarity index 100% rename from Systems/TempTilesManagerSystem.cs rename to Systems/Tile/TempTilesManagerSystem.cs diff --git a/Systems/TileFramingSystem.cs b/Systems/Tile/TileFramingSystem.cs similarity index 71% rename from Systems/TileFramingSystem.cs rename to Systems/Tile/TileFramingSystem.cs index 7030a6f136..e55bedb771 100644 --- a/Systems/TileFramingSystem.cs +++ b/Systems/Tile/TileFramingSystem.cs @@ -43,47 +43,12 @@ namespace CalamityMod.Systems } #endregion - #region Merge Frame Data - public sealed class MergeFrameData - { - public byte[,] AdjacencyData { get; } - - public int TileID { get; } - - public int FrameOffsetX { get; } - - public int FrameOffsetY { get; } - - public Asset BlendSheet { get; } - - public MergeFrameData(byte[,] adjacencyData, int tileId, string blendSheetPath, int frameOffsetX = 0, int frameOffsetY = 0) - { - AdjacencyData = adjacencyData; - TileID = tileId; - FrameOffsetX = frameOffsetX; - FrameOffsetY = frameOffsetY; - - if (!cachedBlendSheets.TryGetValue(blendSheetPath, out var blendSheet)) - { - blendSheet = cachedBlendSheets[blendSheetPath] = ModContent.Request(blendSheetPath); - } - - BlendSheet = blendSheet; - } - } - #endregion - // This tiny GlobalTile exists for two purposes: // 1 - Ensure merge data is loaded and cached // 2 - Properly and automatically render merges in all cases for all tiles #region Sealed Global Tile private sealed class MergeableTileGlobalTile : GlobalTile { - public override void PostDraw(int i, int j, int type, SpriteBatch spriteBatch) - { - DrawUniversalMergeFrames(i, j, GetOrCreateTileAdjacencies(type)); - } - public override bool TileFrame(int i, int j, int type, ref bool resetFrame, ref bool noBreak) { // Custom plant framing @@ -98,9 +63,6 @@ namespace CalamityMod.Systems if (type == TileID.Vines || type == TileID.CrimsonVines || type == TileID.HallowedVines || type == ModContent.TileType()) VineFrame(i, j); - foreach (var adjacency in GetOrCreateTileAdjacencies(type)) - GetAdjacencyData(i, j, adjacency); - return base.TileFrame(i, j, type, ref resetFrame, ref noBreak); } } @@ -108,8 +70,6 @@ namespace CalamityMod.Systems // CONSIDER -- This is a triangle array, but does it need to be? Main.tileMerge is a triangle array as well public static bool[][] tileMergeTypes; - private static Dictionary> tileAdjacencyMap = []; - private static Dictionary> cachedBlendSheets = []; #region Plant Stuff private static ushort[] PlantTypes = @@ -206,12 +166,6 @@ namespace CalamityMod.Systems VineToGrass = null; tileMergeTypes = null; - - tileAdjacencyMap?.Clear(); - tileAdjacencyMap = null; - - cachedBlendSheets?.Clear(); - cachedBlendSheets = null; } #endregion @@ -2109,498 +2063,5 @@ namespace CalamityMod.Systems CustomMergeFrameExplicit(x, y, myType, mergeType, out _, out _, out _, out _, forceSameDown, forceSameUp, forceSameLeft, forceSameRight, true); } #endregion - - #region Universal Merge Code - // Code responsible for the 'Universal Tile Merge' code created to get around the issues with merging brimstone tile framing - // It'll work for any tile regardless of framing and could in theory be added to vanilla tiles as well if desired - // A single tile could also be set to blend with multiple other tiles, though a new adjacency data array will be needed for each tile type it'll merge with as well as a new call of each function so it's probably not the best - - // I chose to use bytes and byte masks to store and check the merge data so that the fully merge conditional tree wouldn't need to be called every frame for every tile - // Not sure if this is the best option, I thought it would minimise the amount of data required to store the adjacency info while being reasonably efficient - // Apologies for how unreadable this makes the code, I did my best to comment what each part of the merge tree in DrawUniversalMergeFrames is responsible for to compensate for this but it's still not ideal - // - Alta - - internal static void RegisterUniversalMerge(int tileId, int mergeType, string blendSheetPath) - { - SetUpUniversalMerge(tileId, mergeType, blendSheetPath, out var data); - GetOrCreateTileAdjacencies(tileId).Add(data); - } - - private static List GetOrCreateTileAdjacencies(int tileId) - { - if (!tileAdjacencyMap.TryGetValue(tileId, out var adjacencies)) - tileAdjacencyMap[tileId] = adjacencies = []; - - return adjacencies; - } - - /// - /// Call this in SetStaticDefaults. Used to set up the adjacency data array with the correct dimensions. - /// - internal static void SetUpUniversalMerge(int myType, int mergeType, string blendSheetPath, out MergeFrameData adjacencyData) - { - CalamityUtils.SetMerge(myType, mergeType, true); - adjacencyData = new MergeFrameData(new byte[Main.tile.Width, Main.tile.Height], mergeType, blendSheetPath); - } - - /// - /// Call this in PostDraw. Uses adjacency data generated by GetAdjacencyData to draw the correct blend state over a given tile, regardless of what tile frame that tile is using - /// - internal static void DrawUniversalMergeFrames(int x, int y, List mergeFrames) - { - var shadingColour = Lighting.GetColor(x, y); - var myTile = Main.tile[x, y]; - - foreach (var frame in mergeFrames) - { - // If it hasn't yet been initialized somehow... for some reason. - if (frame is null) - continue; - - DrawUniversalMergeFrames(x, y, frame, shadingColour, myTile); - } - } - - internal static void DrawUniversalMergeFrames(int x, int y, MergeFrameData mergeFrameData, Color shadingColour, Tile myTile) - { - var adjacencyData = mergeFrameData.AdjacencyData; - var blendLayer = mergeFrameData.BlendSheet.Value; - var frameOffsetX = mergeFrameData.FrameOffsetX; - var frameOffsetY = mergeFrameData.FrameOffsetY; - - var zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - var drawOffset = new Vector2(x * 16 - Main.screenPosition.X, y * 16 - Main.screenPosition.Y) + zero; - - // Used for blending with metatiles/composite tiles (as in the tile being blended with is a metatile, not this tile) - var subFrameX = frameOffsetX * 270; - var subFrameY = frameOffsetY * 198; - - var thisTileData = adjacencyData[x, y]; - - // Get tile variant number - var randomFrame = myTile.TileFrameNumber; - var randomFrameX18 = randomFrame * 18; - var randomFrameX36 = randomFrame * 36; - - // Couple of commonly used masks - // bit to relative tile pos for reference - // 4 0 5 - // 3 X 1 - // 7 2 6 - - byte maskAdjSides = 0b11110000; - byte maskAdjCorners = 0b00001111; - - #region Merge Checks & Drawing - // Switch statement for the mutually exclusive states - switch (thisTileData & maskAdjSides) - { - case 0b11110000: - // All sides - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX18 + subFrameX, 18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - - case 0b01110000: - // All except north - switch (thisTileData & 0b00001100) - { - case 0b00001100: - // Extend to both north corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 90 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00001000: - // Extend to northwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(198 + randomFrameX18 + subFrameX, 180 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000100: - // Extend to northeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 180 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 144 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - - case 0b10110000: - // All except east - switch (thisTileData & 0b00000110) - { - case 0b00000110: - // Extend to both east corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(108 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000100: - // Extend to northeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(234 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000010: - // Extend to southeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(198 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(162 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - - case 0b11010000: - // All except south - switch (thisTileData & 0b00000011) - { - case 0b00000011: - // Extend to both south corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 72 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000010: - // Extend to southeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 162 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000001: - // Extend to southwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(198 + randomFrameX18 + subFrameX, 162 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 126 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - - case 0b11100000: - // All except west - switch (thisTileData & 0b00001001) - { - case 0b00001001: - // Extend to both west corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(126 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000001: - // Extend to southwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(216 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00001000: - // Extend to northwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(252 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(180 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - - case 0b10010000: - // North & West edges - if ((thisTileData & 0b01100010) == 0b00000010) - { - // Blending tile at southeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36 + subFrameX, 54 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - - switch (thisTileData & 0b00000101) - { - case 0b00000101: - // Extend to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36 + subFrameX, 90 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000100: - // Extend to northeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(234 + subFrameX, 54 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000001: - // Extend to southwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(198 + subFrameX, 54 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36 + subFrameX, 126 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - case 0b11000000: - // North & East edges - if ((thisTileData & 0b00110001) == 0b00000001) - { - // Blending tile at southwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 54 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - - switch (thisTileData & 0b00001010) - { - case 0b00001010: - // Extend to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 90 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00001000: - // Extend to northwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(252 + subFrameX, 54 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000010: - // Extend to southeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(216 + subFrameX, 54 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 126 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - - case 0b01100000: - // South & East edges - if ((thisTileData & 0b10011000) == 0b00001000) - { - // Blending tile at northwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 72 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - - switch (thisTileData & 0b00000101) - { - case 0b00000101: - // Extend to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 108 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000100: - // Extend to northeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(216 + subFrameX, 72 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000001: - // Extend to southwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(252 + subFrameX, 72 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 144 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - - case 0b00110000: - // South & West edges - if ((thisTileData & 0b11000100) == 0b00000100) - { - // Blending tile at northeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36 + subFrameX, 72 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - - switch (thisTileData & 0b00001010) - { - case 0b00001010: - // Extend to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36, 108 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00001000: - // Extend to northwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(198 + subFrameX, 72 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - case 0b00000010: - // Extend to southeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(234 + subFrameX, 72 + randomFrameX36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - default: - // Extend to neither corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36 + subFrameX, 144 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - return; - } - } - - // Handle edges and corners, which due to how they can be overlayed in so many ways kind of need their own way of doing things - // North Edge - if ((thisTileData & 0b11010000) == 0b10000000) - { - switch (thisTileData & 0b00001100) - { - case 0b00000000: - // Narrow - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 108 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00001000: - // Extends to Northwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(126 + subFrameX, 108 + randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00000100: - // Extends to Northeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(108 + subFrameX, 108 + randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - default: - // Extends to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX18 + subFrameX, 36 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - } - } - - // East Edge - if ((thisTileData & 0b11100000) == 0b01000000) - { - switch (thisTileData & 0b00000110) - { - case 0b00000000: - // Narrow - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(90 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00000100: - // Extends to Northeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX18 + subFrameX, 180 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00000010: - // Extends to Southeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX18 + subFrameX, 162 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - default: - // Extends to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(0 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - } - } - - // South Edge - if ((thisTileData & 0b01110000) == 0b00100000) - { - switch (thisTileData & 0b00000011) - { - case 0b00000000: - // Narrow - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + randomFrameX18 + subFrameX, 54 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00000010: - // Extends to Southeast corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(108 + subFrameX, 54 + randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00000001: - // Extends to Southwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(126 + subFrameX, 54 + randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - default: - // Extends to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX18 + subFrameX, 0 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - } - } - - // West Edge - if ((thisTileData & 0b10110000) == 0b00010000) - { - switch (thisTileData & 0b00001001) - { - case 0b00000000: - // Narrow - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(144 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00000001: - // Extends to Southwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(54 + randomFrameX18 + subFrameX, 162 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - case 0b00001000: - // Extends to Northwest corner - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(54 + randomFrameX18 + subFrameX, 180 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - default: - // Extends to both corners - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(72 + subFrameX, randomFrameX18 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - break; - } - } - - // Northwest Corner - if ((thisTileData & 0b10011000) == 0b00001000) - { - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 72 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - - // Northeast Corner - if ((thisTileData & 0b11000100) == 0b00000100) - { - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36 + subFrameX, 72 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - - // Southeast Corner - if ((thisTileData & 0b01100010) == 0b00000010) - { - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(randomFrameX36 + subFrameX, 54 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - - // Southwest Corner - if ((thisTileData & 0b00110001) == 0b00000001) - { - Main.spriteBatch.Draw(blendLayer, drawOffset, new Rectangle?(new Rectangle(18 + randomFrameX36 + subFrameX, 54 + subFrameY, 18, 18)), shadingColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - #endregion - } - - /// - /// Call this in TileFrame. Used to generate adjacency data used in DrawUniversalMergeFrames. Tiles using this need a 2d byte array - /// - internal static void GetAdjacencyData(int x, int y, MergeFrameData data) - { - var blendType = data.TileID; - - // bit to relative tile pos for reference - // 4 0 5 - // 3 X 1 - // 7 2 6 - // 01234567 - ref byte adjacencyData = ref data.AdjacencyData[x, y]; - adjacencyData = 0b00000000; - - if (x < 0 || x >= Main.maxTilesX) - return; - if (y < 0 || y >= Main.maxTilesY) - return; - - var tile = Main.tile[x, y]; - var north = Main.tile[x, y - 1]; - var south = Main.tile[x, y + 1]; - var west = Main.tile[x - 1, y]; - var east = Main.tile[x + 1, y]; - var southwest = Main.tile[x - 1, y + 1]; - var southeast = Main.tile[x + 1, y + 1]; - var northwest = Main.tile[x - 1, y - 1]; - var northeast = Main.tile[x + 1, y - 1]; - - // North - if (GetBlendSpecific(tile, north, blendType, false) && (north.Slope == 0 || north.Slope == SlopeType.SlopeDownLeft || north.Slope == SlopeType.SlopeDownRight)) - adjacencyData |= 0b10000000; - // East - if (GetBlendSpecific(tile, east, blendType, false) && (east.Slope == 0 || east.Slope == SlopeType.SlopeDownLeft || east.Slope == SlopeType.SlopeUpLeft)) - adjacencyData |= 0b01000000; - // South - if (GetBlendSpecific(tile, south, blendType, false) && (south.Slope == 0 || south.Slope == SlopeType.SlopeUpLeft || south.Slope == SlopeType.SlopeUpRight)) - adjacencyData |= 0b00100000; - // West - if (GetBlendSpecific(tile, west, blendType, false) && (west.Slope == 0 || west.Slope == SlopeType.SlopeDownRight || west.Slope == SlopeType.SlopeUpRight)) - adjacencyData |= 0b00010000; - // Northwest - if (GetCornerBlendCondition(tile, northwest, north, west, blendType) && (northwest.Slope == 0 || northwest.Slope == SlopeType.SlopeDownRight) && - (north.Slope == 0 || north.Slope == SlopeType.SlopeDownLeft || north.Slope == SlopeType.SlopeUpLeft) && - (west.Slope == 0 || west.Slope == SlopeType.SlopeUpLeft || west.Slope == SlopeType.SlopeUpRight)) - adjacencyData |= 0b00001000; - // Northeast - if (GetCornerBlendCondition(tile, northeast, north, east, blendType) && (northeast.Slope == 0 || northeast.Slope == SlopeType.SlopeDownLeft) && - (north.Slope == 0 || north.Slope == SlopeType.SlopeDownRight || north.Slope == SlopeType.SlopeUpRight) && - (east.Slope == 0 || east.Slope == SlopeType.SlopeUpLeft || east.Slope == SlopeType.SlopeUpRight)) - adjacencyData |= 0b00000100; - // Southeast - if (GetCornerBlendCondition(tile, southeast, south, east, blendType) && !southeast.IsHalfBlock && (southeast.Slope == 0 || southeast.Slope == SlopeType.SlopeUpLeft) && - (south.Slope == 0 || south.Slope == SlopeType.SlopeDownRight || south.Slope == SlopeType.SlopeUpRight) && - (east.Slope == 0 || east.Slope == SlopeType.SlopeDownLeft || east.Slope == SlopeType.SlopeDownRight)) - adjacencyData |= 0b00000010; - // Southwest - if (GetCornerBlendCondition(tile, southwest, south, west, blendType) && !southwest.IsHalfBlock && (southwest.Slope == 0 || southwest.Slope == SlopeType.SlopeUpRight) && - (south.Slope == 0 || south.Slope == SlopeType.SlopeDownLeft || south.Slope == SlopeType.SlopeUpLeft) && - (west.Slope == 0 || west.Slope == SlopeType.SlopeDownLeft || west.Slope == SlopeType.SlopeDownRight)) - adjacencyData |= 0b00000001; - } - - /// - /// Used to get the correct corner adjacency data because it's more complex than the simpler cardinal directions - /// - private static bool GetCornerBlendCondition(Tile myTile, Tile mergeTileCorner, Tile mergeTileEdgeA, Tile mergeTileEdgeB, int blendType) - { - int cornerType = mergeTileCorner.TileType; - int edgeAType = mergeTileEdgeA.TileType; - int edgeBType = mergeTileEdgeB.TileType; - - var isBlendTypeAdjacent = cornerType == blendType || edgeAType == blendType || edgeBType == blendType; - var areAllAdjacentsBlendable = GetBlendSpecific(myTile, mergeTileCorner, blendType, true) && GetBlendSpecific(myTile, mergeTileEdgeA, blendType, true) && GetBlendSpecific(myTile, mergeTileEdgeB, blendType, true); - - return isBlendTypeAdjacent && areAllAdjacentsBlendable; - } - #endregion } } diff --git a/Systems/TileMerging/DataStructures.cs b/Systems/TileMerging/DataStructures.cs new file mode 100644 index 0000000000..2a326cca3f --- /dev/null +++ b/Systems/TileMerging/DataStructures.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria; +using Terraria.DataStructures; + +namespace CalamityMod.Systems +{ + // bit to relative tile pos for reference + // MSB 0->7 LSB + // 4 0 5 + // 2 X 3 + // 6 1 7 + + // NE N NW + // + // E □ W + // + // SE S SW + + public enum BlendSideFlags : byte + { + None = 0, + + Up = 0b1000_0000, + Down = 0b0100_0000, + Right = 0b0010_0000, + Left = 0b0001_0000, + UpLeft = 0b0000_1000, + UpRight = 0b0000_0100, + DownLeft = 0b0000_0010, + DownRight = 0b0000_0001, + + AllSide = 0b1111_1111, + + // Special Shapes + Shape_AllSide = AllSide, + ShapeCorner_UpLeft = UpLeft, + ShapeCorner_UpRight = UpRight, + ShapeCorner_DownLeft = DownLeft, + ShapeCorner_DownRight = DownRight, + + // I Shapes + + ShapeI_Up = Up | UpLeft | UpRight, + ShapeI_Up_End = Up, + ShapeI_Up_LeftEnd = Up | UpRight, + ShapeI_Up_RightEnd = Up | UpLeft, + + ShapeI_Down = Down | DownLeft | DownRight, + ShapeI_Down_End = Down, + ShapeI_Down_LeftEnd = Down | DownRight, + ShapeI_Down_RightEnd = Down | DownLeft, + + ShapeI_Left = Left | UpLeft | DownLeft, + ShapeI_Left_End = Left, + ShapeI_Left_UpEnd = Left | DownLeft, + ShapeI_Left_DownEnd = Left | UpLeft, + + ShapeI_Right = Right | UpRight | DownRight, + ShapeI_Right_End = Right, + ShapeI_Right_UpEnd = Right | DownRight, + ShapeI_Right_DownEnd = Right | UpRight, + + // L Shapes + + ShapeL_UpLeft = ShapeI_Up | ShapeI_Left, + ShapeL_UpLeft_End = ShapeI_Up_End | ShapeI_Left_End | UpLeft, + ShapeL_UpLeft_RightEnd = ShapeI_Up_RightEnd | ShapeI_Left, + ShapeL_UpLeft_DownEnd = ShapeI_Up | ShapeI_Left_DownEnd, + + ShapeL_UpRight = ShapeI_Up | ShapeI_Right, + ShapeL_UpRight_End = ShapeI_Up_End | ShapeI_Right_End | UpRight, + ShapeL_UpRight_LeftEnd = ShapeI_Up_End | ShapeI_Right, + ShapeL_UpRight_DownEnd = ShapeI_Up | ShapeI_Right_End, + + ShapeL_DownLeft = ShapeI_Down | ShapeI_Left, + ShapeL_DownLeft_End = ShapeI_Down_End | ShapeI_Left_End | DownLeft, + ShapeL_DownLeft_RightEnd = ShapeI_Down_End | ShapeI_Left, + ShapeL_DownLeft_UpEnd = ShapeI_Down | ShapeI_Left_End, + + ShapeL_DownRight = ShapeI_Down | ShapeI_Right, + ShapeL_DownRight_End = ShapeI_Down_End | ShapeI_Right_End | DownRight, + ShapeL_DownRight_LeftEnd = ShapeI_Down_End | ShapeI_Right, + ShapeL_DownRight_UpEnd = ShapeI_Down | ShapeI_Right_End, + + // U Shapes + + ShapeU_UpEmpty = ShapeI_Left | ShapeI_Right | ShapeI_Down, + ShapeU_UpEmpty_End = ShapeI_Left_End | ShapeI_Right_End | ShapeI_Down, + ShapeU_UpEmpty_LeftEnd = ShapeI_Left_End | ShapeI_Right | ShapeI_Down, + ShapeU_UpEmpty_RightEnd = ShapeI_Left | ShapeI_Right_End | ShapeI_Down, + + ShapeU_DownEmpty = ShapeI_Left | ShapeI_Right | ShapeI_Up, + ShapeU_DownEmpty_End = ShapeI_Left_End | ShapeI_Right_End | ShapeI_Up, + ShapeU_DownEmpty_LeftEnd = ShapeI_Left_End | ShapeI_Right | ShapeI_Up, + ShapeU_DownEmpty_RightEnd = ShapeI_Left | ShapeI_Right_End | ShapeI_Up, + + ShapeU_LeftEmpty = ShapeI_Up | ShapeI_Down | ShapeI_Right, + ShapeU_LeftEmpty_End = ShapeI_Up_End | ShapeI_Down_End | ShapeI_Right, + ShapeU_LeftEmpty_UpEnd = ShapeI_Up_End | ShapeI_Down | ShapeI_Right, + ShapeU_LeftEmpty_DownEnd = ShapeI_Up | ShapeI_Down_End | ShapeI_Right, + + ShapeU_RightEmpty = ShapeI_Up | ShapeI_Down | ShapeI_Left, + ShapeU_RightEmpty_End = ShapeI_Up_End | ShapeI_Down_End | ShapeI_Left, + ShapeU_RightEmpty_UpEnd = ShapeI_Up_End | ShapeI_Down | ShapeI_Left, + ShapeU_RightEmpty_DownEnd = ShapeI_Up | ShapeI_Down_End | ShapeI_Left, + } + + public struct TileBlendingData : ITileData + { + public const int Length = 8; + + private ulong SheetIndexPacked; // 8 bytes + private ulong DataPacked; // 8 bytes + + public void Clear() + { + for (int i = 0; i= Length) + throw new IndexOutOfRangeException(); + + var shift = idx * 8; + ulong value = ((ulong)data) << shift; + ulong mask = ((ulong)0xFF) << shift; + DataPacked = (DataPacked ^ (mask & DataPacked)) | value; + } + + public readonly byte GetData(int idx) + { + if (idx < 0 || idx >= Length) + throw new IndexOutOfRangeException(); + + var shift = idx * 8; + return (byte)((DataPacked >> shift) & 0xFF); + } + + public void SetSheetIndex(int idx, byte sheetIdx) + { + if (idx < 0 || idx >= Length) + throw new IndexOutOfRangeException(); + + var shift = idx * 8; + ulong value = ((ulong)sheetIdx) << shift; + ulong mask = ((ulong)0xFF) << shift; + SheetIndexPacked = (SheetIndexPacked ^ (mask & SheetIndexPacked)) | value; + } + + public readonly byte GetSheetIndex(int idx) + { + if (idx < 0 || idx >= Length) + throw new IndexOutOfRangeException(); + + var shift = idx * 8; + return (byte)((SheetIndexPacked >> shift) & 0xFF); + } + + public void Set(int idx, byte sheetIdx, byte data) + { + SetSheetIndex(idx, sheetIdx); + SetData(idx, data); + } + + public readonly void Get(int idx, out byte sheetIdx, out byte data) + { + sheetIdx = GetSheetIndex(idx); + data = GetData(idx); + } + } +} diff --git a/Systems/TileMerging/TileBlendMergeSystem.cs b/Systems/TileMerging/TileBlendMergeSystem.cs new file mode 100644 index 0000000000..6d5e593dd0 --- /dev/null +++ b/Systems/TileMerging/TileBlendMergeSystem.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Graphics; +using CalamityMod.Tiles.Abyss; +using CalamityMod.Tiles.Astral; +using CalamityMod.Tiles.AstralDesert; +using CalamityMod.Tiles.AstralSnow; +using CalamityMod.Tiles.SunkenSea; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using MonoMod.Utils; +using Newtonsoft.Json.Linq; +using ReLogic.Content; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent.Drawing; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + [Autoload(Side = ModSide.Client)] + public sealed partial class TileBlendMergeSystem : ModSystem + { + private static bool[,] _TileBlendable; // dimension: [TileTypeCount, AllBlendTextureCount] + private static bool[,] _TileBlendLooselyFillDiagonal; // dimension: [TileTypeCount, AllBlendTextureCount] + private static byte[] _TileTypeToBlendTextureSlot; // dimension: [TileTypeCount] + + #region Load/Unload + public override void OnModLoad() + { + var tileCount = TileLoader.TileCount; + var blendTextureCount = TileBlendTextureLoader.Count; + _TileBlendable = new bool[tileCount, blendTextureCount]; + _TileBlendLooselyFillDiagonal = new bool[tileCount, blendTextureCount]; + _TileTypeToBlendTextureSlot = new byte[tileCount]; + + Array.Fill(_TileTypeToBlendTextureSlot, (byte)TileBlendTextureLoader.EmptySlot); + + for (int i = 0; i(int myType, bool looselyFillDiagonal = false) where T : TileBlendTexture + { + var blendTexture = ModContent.GetInstance(); + RegisterMerge(myType, blendTexture, looselyFillDiagonal); + } + #endregion + } +} diff --git a/Systems/TileMerging/TileBlendMergeSystem_Draw.cs b/Systems/TileMerging/TileBlendMergeSystem_Draw.cs new file mode 100644 index 0000000000..5a37663367 --- /dev/null +++ b/Systems/TileMerging/TileBlendMergeSystem_Draw.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; +using Terraria.DataStructures; +using Terraria; +using Terraria.ModLoader; +using Microsoft.Xna.Framework; +using Terraria.GameContent.Drawing; + +namespace CalamityMod.Systems +{ + public sealed partial class TileBlendMergeSystem : ModSystem + { + private static void OnDrawSingleTile(On_TileDrawing.orig_DrawSingleTile orig, TileDrawing self, TileDrawInfo drawData, bool solidLayer, int waterStyleOverride, Vector2 screenPosition, Vector2 screenOffset, int tileX, int tileY) + { + orig(self, drawData, solidLayer, waterStyleOverride, screenPosition, screenOffset, tileX, tileY); + + var tile = drawData.tileCache; + + Color drawColor = drawData.tileLight; + if (drawColor.R <= 0 && drawColor.G <= 0 && drawColor.B <= 0) + return; + + Vector2 drawPos = new Vector2(tileX * 16, tileY * 16) - screenPosition + screenOffset; + var blendingData = tile.Get(); // Since we are not editing the value, we can just copy the values from here + for (int idx = 0; idx < TileBlendingData.Length; idx++) + { + blendingData.Get(idx, out var sheetIdx, out var data); + + // Break here as standard for TileBlendingData is 0->Count fill, so further fields should be also Invalid + if (sheetIdx == TileBlendTextureLoader.EmptySlot) + break; + + var rect = TileBlendTexture.SideFlagsToSheetRect(data); + var texture = TileBlendTextureLoader.Registry[sheetIdx]; + var variant = Math.Clamp(tile.TileFrameNumber, 0, 2); + Main.spriteBatch.Draw(texture.BlendTextures[variant], drawPos, rect, drawColor, rotation: 0.0f, origin: default, scale: 1.0f, SpriteEffects.None, layerDepth: 0.0f); + } + } + } +} diff --git a/Systems/TileMerging/TileBlendMergeSystem_GlobalTile.cs b/Systems/TileMerging/TileBlendMergeSystem_GlobalTile.cs new file mode 100644 index 0000000000..e20ad5757d --- /dev/null +++ b/Systems/TileMerging/TileBlendMergeSystem_GlobalTile.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + public sealed partial class TileBlendMergeSystem : ModSystem + { + #region Don't mind this, This is a small GlobalTile for hooks + [Autoload(Side = ModSide.Client)] + private class FancyTileMergeGlobalTile : GlobalTile + { + [SuppressMessage("Simplify Method Call", "IDE0002", Justification = "Leave this alone for Consistency")] + public override void PostSetupTileMerge() + { + TileBlendMergeSystem.SetupMergeData(); + } + + public override bool TileFrame(int i, int j, int type, ref bool resetFrame, ref bool noBreak) + { + TileBlendMergeSystem.TileFrame(i, j, type); + return base.TileFrame(i, j, type, ref resetFrame, ref noBreak); + } + } + #endregion + } +} diff --git a/Systems/TileMerging/TileBlendMergeSystem_TileFrame.cs b/Systems/TileMerging/TileBlendMergeSystem_TileFrame.cs new file mode 100644 index 0000000000..242a68ffc7 --- /dev/null +++ b/Systems/TileMerging/TileBlendMergeSystem_TileFrame.cs @@ -0,0 +1,397 @@ +using System.Runtime.CompilerServices; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +using BlendSidesReg = System.Collections.Generic.Dictionary; + +namespace CalamityMod.Systems +{ + public sealed partial class TileBlendMergeSystem : ModSystem + { + private static void TileFrame(int i, int j, int type) + { + if (!WorldGen.InWorld(i, j)) + return; + + var tile = Main.tile[i, j]; + tile.Get().Clear(); + + if (!tile.HasTile) // Is this even possible? But I'm doing this for sanity check anyways + return; + + var blendDataUniqueIndex = 0; + var blendSidesReg = PopulateBlendSidesReg(i, j, tile.TileType); + + CalculateSides(i, j, in blendSidesReg); + + foreach (var pair in blendSidesReg) + { + var blendTextureSlot = pair.Key; + var sideFlags = pair.Value; + + if (sideFlags != BlendSideFlags.None) + { + tile.Get().Set(blendDataUniqueIndex, (byte)blendTextureSlot, (byte)sideFlags); + blendDataUniqueIndex++; + } + } + } + + private static void CalculateSides(int i, int j, in BlendSidesReg blendSidesReg) + { + _ = TryGetTile(i, j, out var centerTile, out _); + + bool leftMerged = false; + bool rightMerged = false; + bool upMerged = false; + bool downMerged = false; + + #region Basic 4 Direction Merges + + bool hasLeft = TryGetTile(i - 1, j, out var leftTile, out var leftType); + if (hasLeft && HasLeftMerge(centerTile, leftTile)) + { + leftMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[leftType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.Left; + } + } + + bool hasRight = TryGetTile(i + 1, j, out var rightTile, out var rightType); + if (hasRight && HasRightMerge(centerTile, rightTile)) + { + rightMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[rightType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.Right; + } + } + + bool hasUp = TryGetTile(i, j - 1, out var upTile, out var upType); + if (hasUp && HasUpMerge(centerTile, upTile)) + { + upMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[upType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.Up; + } + } + + bool hasDown = TryGetTile(i, j + 1, out var downTile, out var downType); + if (hasDown && HasDownMerge(centerTile, downTile)) + { + downMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[downType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.Down; + } + } + + #endregion + + #region Diagonal Direction Merges + + bool upLeftMerged = false; + bool upRightMerged = false; + bool downLeftMerged = false; + bool downRightMerged = false; + + bool hasUpLeft = TryGetTile(i - 1, j - 1, out var upLeftTile, out var upLeftType); + if (hasUpLeft && upMerged && leftMerged && HasRightMerge(upLeftTile, upTile) && HasDownMerge(upLeftTile, leftTile)) + { + upLeftMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[upLeftType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.UpLeft; + } + } + + bool hasUpRight = TryGetTile(i + 1, j - 1, out var upRightTile, out var upRightType); + if (hasUpRight && upMerged && rightMerged && HasLeftMerge(upRightTile, upTile) && HasDownMerge(upRightTile, leftTile)) + { + upRightMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[upRightType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.UpRight; + } + } + + bool hasDownLeft = TryGetTile(i - 1, j + 1, out var downLeftTile, out var downLeftType); + if (hasDownLeft && downMerged && leftMerged && HasRightMerge(downLeftTile, downTile) && HasUpMerge(downLeftTile, leftTile)) + { + downLeftMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[downLeftType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.DownLeft; + } + } + + bool hasDownRight = TryGetTile(i + 1, j + 1, out var downRightTile, out var downRightType); + if (hasDownRight && downMerged && rightMerged && HasLeftMerge(downRightTile, downTile) && HasUpMerge(downLeftTile, leftTile)) + { + downRightMerged = true; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[downRightType]; + if (blendSidesReg.ContainsKey(blendTextureSlot)) + { + blendSidesReg[blendTextureSlot] |= BlendSideFlags.DownRight; + } + } + + #endregion + + #region Special Corner Cases + foreach (var kv in blendSidesReg) + { + var slot = kv.Key; + var sides = kv.Value; + + // Up + if (sides.HasFlag(BlendSideFlags.Up)) + { + if (leftMerged && upLeftMerged && IsBlendableOrSame(leftType, slot) && IsBlendableOrSame(upLeftType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.UpLeft; + } + + if (rightMerged && upRightMerged && IsBlendableOrSame(rightType, slot) && IsBlendableOrSame(upRightType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.UpRight; + } + } + + // Down + if (sides.HasFlag(BlendSideFlags.Down)) + { + if (leftMerged && downLeftMerged && IsBlendableOrSame(leftType, slot) && IsBlendableOrSame(downLeftType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.DownLeft; + } + + if (rightMerged && downRightMerged && IsBlendableOrSame(rightType, slot) && IsBlendableOrSame(downRightType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.DownRight; + } + } + + // Left + if (sides.HasFlag(BlendSideFlags.Left)) + { + if (upLeftMerged && upMerged && IsBlendableOrSame(upLeftType, slot) && IsBlendableOrSame(upType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.UpLeft; + } + + if (downLeftMerged && downMerged && IsBlendableOrSame(downLeftType, slot) && IsBlendableOrSame(downType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.DownLeft; + } + } + + // Right + if (sides.HasFlag(BlendSideFlags.Right)) + { + if (upRightMerged && upMerged && IsBlendableOrSame(upRightType, slot) && IsBlendableOrSame(upType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.UpRight; + } + + if (downRightMerged && downMerged && IsBlendableOrSame(downRightType, slot) && IsBlendableOrSame(downType, slot)) + { + blendSidesReg[slot] |= BlendSideFlags.DownRight; + } + } + } + #endregion + } + + #region Merge Utilities + private static bool IsBlendableOrSame(int tileType, int blendTextureSlot) + { + if (_TileBlendable[tileType, blendTextureSlot]) return true; + if (!_TileBlendLooselyFillDiagonal[tileType, blendTextureSlot] && _TileTypeToBlendTextureSlot[tileType] == blendTextureSlot) return true; + return false; + } + + private static bool HasLeftMerge(Tile tileOnCenter, Tile tileOnLeft) + { + if (!IsMergable(tileOnCenter.TileType, tileOnLeft.TileType)) return false; + if (!HasLeftSolid(tileOnCenter)) return false; + if (!HasRightSolid(tileOnLeft)) return false; + + return true; + } + + private static bool HasRightMerge(Tile tileOnCenter, Tile tileOnRight) + { + if (!IsMergable(tileOnCenter.TileType, tileOnRight.TileType)) return false; + if (!HasRightSolid(tileOnCenter)) return false; + if (!HasLeftSolid(tileOnRight)) return false; + + return true; + } + + private static bool HasUpMerge(Tile tileOnCenter, Tile tileOnUp) + { + if (!IsMergable(tileOnCenter.TileType, tileOnUp.TileType)) return false; + if (!HasUpSolid(tileOnCenter)) return false; + if (!HasDownSolid(tileOnUp)) return false; + + return true; + } + + private static bool HasDownMerge(Tile tileOnCenter, Tile tileOnDown) + { + if (!IsMergable(tileOnCenter.TileType, tileOnDown.TileType)) return false; + if (!HasDownSolid(tileOnCenter)) return false; + if (!HasUpSolid(tileOnDown)) return false; + + return true; + } + + // BlockType.Solid, BlockType.SlopeUpLeft, BlockType.SlopeDownLeft + // 024 + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool HasLeftSolid(Tile tile) => ((int)tile.BlockType & 1) == 0; + + // BlockType.Solid, BlockType.DownRight, BlockType.SlopeUpRight + // 035 (there is no way to optimize this) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool HasRightSolid(Tile tile) + { + int b = (int)tile.BlockType; + return b == 0 || b == 3 || b == 5; + } + + // BlockType.Solid, BlockType.HalfBlock, BlockType.SlopeUpLeft, BlockType.SlopeUpRight + // 0145 + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool HasUpSolid(Tile tile) + { + int b = (int)tile.BlockType; + return b < 2 || b > 3; + } + + // BlockType.Solid, BlockType.SlopeDownLeft, BlockType.SlopeDownRight + // 023 + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool HasDownSolid(Tile tile) + { + int b = (int)tile.BlockType; + return (b & 4) == 0 && b != 1; + } + + private static bool IsMergable(int type, int otherType) + { + if (type < 0 || otherType < 0) + return false; + + if (type == otherType) + return true; + + var canBeMerged = Main.tileMerge[type][otherType]; + if (Main.tileBlendAll[type]) + { + return canBeMerged && !TileID.Sets.BlockMergesWithMergeAllBlock[otherType]; + } + else + { + return canBeMerged; + } + } + + private static BlendSidesReg PopulateBlendSidesReg(int i, int j, int centerType) + { + var reg = new BlendSidesReg(); + + int left = GetTileType(i - 1, j); + int right = GetTileType(i + 1, j); + + int up = GetTileType(i, j - 1); + int upLeft = GetTileType(i - 1, j - 1); + int upRight = GetTileType(i + 1, j - 1); + + int down = GetTileType(i, j + 1); + int downLeft = GetTileType(i - 1, j + 1); + int downRight = GetTileType(i + 1, j + 1); + + void Populate(int sideType) + { + if (sideType < 0) + return; + + var blendTextureSlot = _TileTypeToBlendTextureSlot[sideType]; + if (blendTextureSlot == TileBlendTextureLoader.EmptySlot) + return; + + if (_TileBlendable[centerType, blendTextureSlot]) + { + reg[blendTextureSlot] = BlendSideFlags.None; + } + } + + Populate(left); + Populate(right); + + Populate(up); + Populate(upLeft); + Populate(upRight); + + Populate(down); + Populate(downLeft); + Populate(downRight); + + return reg; + } + + private static int GetTileType(int i, int j) + { + if (!WorldGen.InWorld(i, j)) + return -1; + + var tile = Main.tile[i, j]; + if (!tile.HasTile) + return -1; + + return tile.TileType; + } + + private static bool TryGetTile(int i, int j, out Tile tile, out int type) + { + if (!WorldGen.InWorld(i, j)) + { + tile = default; + type = -1; + return false; + } + + tile = Main.tile[i, j]; + if (!tile.HasTile) + { + tile = default; + type = -1; + return false; + } + + type = tile.TileType; + return true; + } + #endregion + } +} diff --git a/Systems/TileMerging/TileBlendTexture.cs b/Systems/TileMerging/TileBlendTexture.cs new file mode 100644 index 0000000000..da7b7ba41d --- /dev/null +++ b/Systems/TileMerging/TileBlendTexture.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.DataStructures; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + [Autoload(Side = ModSide.Client)] + public abstract partial class TileBlendTexture : ModTexturedType + { + #region Constants + public const byte EmptySheetIndex = byte.MaxValue; + public const int VariantCount = 3; + + public const int BlendTextureXCount = 16; + public const int BlendTextureYCount = 16; + public const int BlendTextureWidth = 18 * BlendTextureXCount; + public const int BlendTextureHeight = 18 * BlendTextureYCount; + #endregion + + + #region Properties + public Asset TextureAsset { get; private set; } + public int Slot { get; private set; } = -1; + public RenderTarget2D[] BlendTextures { get; private set; } // dimension: [3] + #endregion + + + #region Overrides + public abstract int TileType { get; } + #endregion + + + #region Setups + protected sealed override void Register() + { + Slot = TileBlendTextureLoader.Register(this); + TextureAsset = ModContent.Request(Texture); + BlendTextures = new RenderTarget2D[3]; + + Main.QueueMainThreadAction(() => + { + for (int v = 0; v < VariantCount; v++) + BlendTextures[v] = new( + Main.instance.GraphicsDevice, + BlendTextureWidth, + BlendTextureHeight, + mipMap: false, + preferredFormat: SurfaceFormat.Color, + preferredDepthFormat: DepthFormat.None, + preferredMultiSampleCount: 0, + usage: RenderTargetUsage.PreserveContents); + }); + } + + public sealed override void SetupContent() + { + SetStaticDefaults(); + } + + public sealed override void Unload() + { + Main.QueueMainThreadAction(() => + { + if (BlendTextures is not null) + { + foreach (var rt in BlendTextures) + { + if (rt is null) + continue; + + if (rt.IsDisposed) + continue; + + rt.Dispose(); + } + + Array.Clear(BlendTextures); + BlendTextures = null; + } + }); + + PostUnload(); + } + + public virtual void PostUnload() + { + + } + #endregion + + + #region Public API + public void RebuildBlendSheet(Texture2D texture = null) + { + texture ??= TextureAsset.Value; + BakeBlendTexture(texture); + } + #endregion + } +} diff --git a/Systems/TileMerging/TileBlendTextureLoader.cs b/Systems/TileMerging/TileBlendTextureLoader.cs new file mode 100644 index 0000000000..3409a1a0ee --- /dev/null +++ b/Systems/TileMerging/TileBlendTextureLoader.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.DataStructures; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + internal sealed class TileBlendTextureLoader : ModSystem + { + internal const int EmptySlot = 255; + + internal static TileBlendTexture[] Registry { get; private set; } + internal static IEnumerable AllTextures => Registry.Take(Count); + internal static int Count => _UniqueSlot; + + private static int _UniqueSlot = 0; + + public override void Load() + { + Registry = new TileBlendTexture[EmptySlot + 1]; + } + + public override void Unload() + { + Registry = null; + _UniqueSlot = 0; + } + + internal static int Register(TileBlendTexture sheet) + { + if (sheet.Slot >= 0) + throw new ArgumentException("Argument has already registered to System", nameof(sheet)); + + if (_UniqueSlot >= EmptySlot) + throw new InvalidOperationException($"Slots are all used up to {EmptySlot}, We can't allocate more!"); + + var slot = _UniqueSlot++; + Registry[slot] = sheet; + return slot; + } + } +} diff --git a/Systems/TileMerging/TileBlendTexture_Baking.cs b/Systems/TileMerging/TileBlendTexture_Baking.cs new file mode 100644 index 0000000000..f2fa9c35da --- /dev/null +++ b/Systems/TileMerging/TileBlendTexture_Baking.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + public abstract partial class TileBlendTexture : ModTexturedType + { + #region Sheet Baking Process + internal void BakeBlendTexture(Texture2D texture) + { + // It's baking moment + Main.QueueMainThreadAction(() => + { + BakeBlendTexture_Inner(texture); + }); + } + + private void BakeBlendTexture_Inner(Texture2D texture) + { + if (texture == null) + throw new ArgumentNullException(nameof(texture), "Texture is Null!"); + + if (texture.IsDisposed) + throw new ArgumentException(paramName: nameof(texture), message: "Texture is Disposed!"); + + for (int v = 0; v < VariantCount; v++) + { + var renderTarget = BlendTextures[v]; + var graphicsDevice = Main.instance.GraphicsDevice; + graphicsDevice.SetRenderTarget(renderTarget); + graphicsDevice.Clear(Color.Transparent); + + Main.spriteBatch.SafeBegin(SpriteSortMode.Immediate, BatchSetting.AlphaBlend, null, Matrix.Identity, () => + { + for (int i = 0; i < 256; i++) + { + var drawPos = SideFlagsToPositionInSheet((byte)i); + var mergeSides = (BlendSideFlags)i; + + // Easy cases, It match on Shape Lookup Sheet Directly + if (_ShapeLookup.TryGetValue(mergeSides, out var rects)) + { + Main.spriteBatch.Draw(texture, drawPos, rects[v], Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f); + continue; + } + + var extractedShapes = ConsumeMergeSides(mergeSides); + foreach (var shape in extractedShapes) + { + if (_ShapeLookup.TryGetValue(shape, out var shapeRects)) + { + Main.spriteBatch.Draw(texture, drawPos, shapeRects[v], Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f); + } + } + } + }); + + graphicsDevice.SetRenderTarget(null); + } + } + + private static IEnumerable ConsumeMergeSides(BlendSideFlags sideFlags) + { + if (sideFlags == BlendSideFlags.None) + yield break; + + foreach (var shapeGroup in _ShapeConsumeMap) + { + foreach (var shape in shapeGroup) + { + if ((shape & sideFlags) == shape) + { + // Consume Shape it given and push the extracted shape + sideFlags &= ~shape; + yield return shape; + } + } + + if (sideFlags == BlendSideFlags.None) + yield break; + } + yield break; + } + #endregion + + #region Utils + public static Rectangle SideFlagsToSheetRect(byte data) + { + int y = Math.DivRem(data, 16, out int x); + return new Rectangle(x * 18, y * 18, 16, 16); + } + + public static Vector2 SideFlagsToPositionInSheet(byte data) + { + int y = Math.DivRem(data, 16, out int x); + return new Vector2(x * 18, y * 18); + } + #endregion + } +} diff --git a/Systems/TileMerging/TileBlendTexture_Lookup.cs b/Systems/TileMerging/TileBlendTexture_Lookup.cs new file mode 100644 index 0000000000..8fd90fccb3 --- /dev/null +++ b/Systems/TileMerging/TileBlendTexture_Lookup.cs @@ -0,0 +1,319 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Terraria.ModLoader; + +using static CalamityMod.Systems.BlendSideFlags; + +namespace CalamityMod.Systems +{ + public abstract partial class TileBlendTexture : ModTexturedType + { + // Welcome to Hardcoded hell + // Do NOT change anything in here unless you understand absolutely everything + + #region Sheet Rects + // I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME + // I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME + // I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME I HATE THIS GAME + + // + // I shapes (16 variants) + // + + private static readonly Rectangle[] _I_Up = Create3RectsDirX(1, 2); + private static readonly Rectangle[] _I_Up_End = Create3RectsDirX(8, 6); + private static readonly Rectangle[] _I_Up_LeftEnd = Create3RectsDirY(6, 6); + private static readonly Rectangle[] _I_Up_RightEnd = Create3RectsDirY(7, 6); + + private static readonly Rectangle[] _I_Down = Create3RectsDirX(1, 0); + private static readonly Rectangle[] _I_Down_End = Create3RectsDirX(8, 3); + private static readonly Rectangle[] _I_Down_LeftEnd = Create3RectsDirY(6, 3); + private static readonly Rectangle[] _I_Down_RightEnd = Create3RectsDirY(7, 3); + + private static readonly Rectangle[] _I_Left = Create3RectsDirY(4, 0); + private static readonly Rectangle[] _I_Left_End = Create3RectsDirY(8, 0); + private static readonly Rectangle[] _I_Left_UpEnd = Create3RectsDirX(3, 9); + private static readonly Rectangle[] _I_Left_DownEnd = Create3RectsDirX(3, 10); + + private static readonly Rectangle[] _I_Right = Create3RectsDirY(0, 0); + private static readonly Rectangle[] _I_Right_End = Create3RectsDirY(5, 0); + private static readonly Rectangle[] _I_Right_UpEnd = Create3RectsDirX(0, 9); + private static readonly Rectangle[] _I_Right_DownEnd = Create3RectsDirX(0, 10); + + // + // L shapes (16 variants) + // + + private static readonly Rectangle[] _L_UpLeft = Create3RectsDirX(0, 5, increment: 2); + private static readonly Rectangle[] _L_UpLeft_End = Create3RectsDirX(0, 7, increment: 2); + private static readonly Rectangle[] _L_UpLeft_RightEnd = Create3RectsDirY(11, 3, increment: 2); + private static readonly Rectangle[] _L_UpLeft_DownEnd = Create3RectsDirY(13, 3, increment: 2); + + + private static readonly Rectangle[] _L_UpRight = Create3RectsDirX(1, 5, increment: 2); + private static readonly Rectangle[] _L_UpRight_End = Create3RectsDirX(1, 7, increment: 2); + private static readonly Rectangle[] _L_UpRight_LeftEnd = Create3RectsDirY(12, 3, increment: 2); + private static readonly Rectangle[] _L_UpRight_DownEnd = Create3RectsDirY(14, 3, increment: 2); + + + private static readonly Rectangle[] _L_DownLeft = Create3RectsDirX(0, 6, increment: 2); + private static readonly Rectangle[] _L_DownLeft_End = Create3RectsDirX(0, 8, increment: 2); + private static readonly Rectangle[] _L_DownLeft_RightEnd = Create3RectsDirY(11, 4, increment: 2); + private static readonly Rectangle[] _L_DownLeft_UpEnd = Create3RectsDirY(13, 4, increment: 2); + + + private static readonly Rectangle[] _L_DownRight = Create3RectsDirX(1, 6, increment: 2); + private static readonly Rectangle[] _L_DownRight_End = Create3RectsDirX(1, 8, increment: 2); + private static readonly Rectangle[] _L_DownRight_LeftEnd = Create3RectsDirY(12, 4, increment: 2); + private static readonly Rectangle[] _L_DownRight_UpEnd = Create3RectsDirY(14, 4, increment: 2); + + // + // U shapes (16 variants) + // + + private static readonly Rectangle[] _U_UpEmpty = Create3RectsDirX(8, 5); + private static readonly Rectangle[] _U_UpEmpty_End = Create3RectsDirX(8, 8); + private static readonly Rectangle[] _U_UpEmpty_LeftEnd = Create3RectsDirX(8, 10); + private static readonly Rectangle[] _U_UpEmpty_RightEnd = Create3RectsDirX(11, 10); + + private static readonly Rectangle[] _U_DownEmpty = Create3RectsDirX(8, 4); + private static readonly Rectangle[] _U_DownEmpty_End = Create3RectsDirX(8, 7); + private static readonly Rectangle[] _U_DownEmpty_LeftEnd = Create3RectsDirX(8, 9); + private static readonly Rectangle[] _U_DownEmpty_RightEnd = Create3RectsDirX(11, 9); + + private static readonly Rectangle[] _U_LeftEmpty = Create3RectsDirY(7, 0); + private static readonly Rectangle[] _U_LeftEmpty_End = Create3RectsDirY(10, 0); + private static readonly Rectangle[] _U_LeftEmpty_UpEnd = Create3RectsDirY(12, 0); + private static readonly Rectangle[] _U_LeftEmpty_DownEnd = Create3RectsDirY(14, 0); + + private static readonly Rectangle[] _U_RightEmpty = Create3RectsDirY(6, 0); + private static readonly Rectangle[] _U_RightEmpty_End = Create3RectsDirY(9, 0); + private static readonly Rectangle[] _U_RightEmpty_UpEnd = Create3RectsDirY(11, 0); + private static readonly Rectangle[] _U_RightEmpty_DownEnd = Create3RectsDirY(13, 0); + + // + // Special shapes (5 variants) + // + + private static readonly Rectangle[] _AllClosed = Create3RectsDirX(1, 1); + private static readonly Rectangle[] _Corner_UpLeft = Create3RectsDirX(1, 4, increment: 2); + private static readonly Rectangle[] _Corner_UpRight = Create3RectsDirX(0, 4, increment: 2); + private static readonly Rectangle[] _Corner_DownLeft = Create3RectsDirX(1, 3, increment: 2); + private static readonly Rectangle[] _Corner_DownRight = Create3RectsDirX(0, 3, increment: 2); + + // TOTAL: 53 + #endregion + + #region Sheet Lookup + private static readonly Dictionary _ShapeLookup = new() + { + // Special Shapes: 5 + [Shape_AllSide] = _AllClosed, + [ShapeCorner_UpLeft] = _Corner_UpLeft, + [ShapeCorner_UpRight] = _Corner_UpRight, + [ShapeCorner_DownLeft] = _Corner_DownLeft, + [ShapeCorner_DownRight] = _Corner_DownRight, + + // I Shape: 16 + [ShapeI_Up] = _I_Up, + [ShapeI_Up_End] = _I_Up_End, + [ShapeI_Up_RightEnd] = _I_Up_RightEnd, + [ShapeI_Up_LeftEnd] = _I_Up_LeftEnd, + + [ShapeI_Down] = _I_Down, + [ShapeI_Down_End] = _I_Down_End, + [ShapeI_Down_RightEnd] = _I_Down_RightEnd, + [ShapeI_Down_LeftEnd] = _I_Down_LeftEnd, + + [ShapeI_Left] = _I_Left, + [ShapeI_Left_End] = _I_Left_End, + [ShapeI_Left_DownEnd] = _I_Left_DownEnd, + [ShapeI_Left_UpEnd] = _I_Left_UpEnd, + + [ShapeI_Right] = _I_Right, + [ShapeI_Right_End] = _I_Right_End, + [ShapeI_Right_DownEnd] = _I_Right_DownEnd, + [ShapeI_Right_UpEnd] = _I_Right_UpEnd, + + // L Shape: 16 + [ShapeL_UpLeft] = _L_UpLeft, + [ShapeL_UpLeft_End] = _L_UpLeft_End, + [ShapeL_UpLeft_RightEnd] = _L_UpLeft_RightEnd, + [ShapeL_UpLeft_DownEnd] = _L_UpLeft_DownEnd, + + [ShapeL_UpRight] = _L_UpRight, + [ShapeL_UpRight_End] = _L_UpRight_End, + [ShapeL_UpRight_LeftEnd] = _L_UpRight_LeftEnd, + [ShapeL_UpRight_DownEnd] = _L_UpRight_DownEnd, + + [ShapeL_DownLeft] = _L_DownLeft, + [ShapeL_DownLeft_End] = _L_DownLeft_End, + [ShapeL_DownLeft_RightEnd] = _L_DownLeft_RightEnd, + [ShapeL_DownLeft_UpEnd] = _L_DownLeft_UpEnd, + + [ShapeL_DownRight] = _L_DownRight, + [ShapeL_DownRight_End] = _L_DownRight_End, + [ShapeL_DownRight_LeftEnd] = _L_DownRight_LeftEnd, + [ShapeL_DownRight_UpEnd] = _L_DownRight_UpEnd, + + // U Shape: 16 + [ShapeU_UpEmpty] = _U_UpEmpty, + [ShapeU_UpEmpty_End] = _U_UpEmpty_End, + [ShapeU_UpEmpty_LeftEnd] = _U_UpEmpty_LeftEnd, + [ShapeU_UpEmpty_RightEnd] = _U_UpEmpty_RightEnd, + + [ShapeU_DownEmpty] = _U_DownEmpty, + [ShapeU_DownEmpty_End] = _U_DownEmpty_End, + [ShapeU_DownEmpty_LeftEnd] = _U_DownEmpty_LeftEnd, + [ShapeU_DownEmpty_RightEnd] = _U_DownEmpty_RightEnd, + + [ShapeU_LeftEmpty] = _U_LeftEmpty, + [ShapeU_LeftEmpty_End] = _U_LeftEmpty_End, + [ShapeU_LeftEmpty_UpEnd] = _U_LeftEmpty_UpEnd, + [ShapeU_LeftEmpty_DownEnd] = _U_LeftEmpty_DownEnd, + + [ShapeU_RightEmpty] = _U_RightEmpty, + [ShapeU_RightEmpty_End] = _U_RightEmpty_End, + [ShapeU_RightEmpty_UpEnd] = _U_RightEmpty_UpEnd, + [ShapeU_RightEmpty_DownEnd] = _U_RightEmpty_DownEnd, + }; + + #endregion + + #region Shape Lookup + + private static readonly IReadOnlyCollection _Corner_Shapes = [ + ShapeCorner_UpLeft, + ShapeCorner_UpRight, + ShapeCorner_DownLeft, + ShapeCorner_DownRight + ]; + + private static readonly IReadOnlyCollection _I_Shapes = [ + ShapeI_Up, + ShapeI_Up_End, + ShapeI_Up_LeftEnd, + ShapeI_Up_RightEnd, + + ShapeI_Down, + ShapeI_Down_End, + ShapeI_Down_LeftEnd, + ShapeI_Down_RightEnd, + + ShapeI_Left, + ShapeI_Left_End, + ShapeI_Left_UpEnd, + ShapeI_Left_DownEnd, + + ShapeI_Right, + ShapeI_Right_End, + ShapeI_Right_UpEnd, + ShapeI_Right_DownEnd, + ]; + + private static readonly IReadOnlyCollection _L_Shapes = [ + ShapeL_UpLeft, + ShapeL_UpLeft_End, + ShapeL_UpLeft_RightEnd, + ShapeL_UpLeft_DownEnd, + + ShapeL_UpRight, + ShapeL_UpRight_End, + ShapeL_UpRight_LeftEnd, + ShapeL_UpRight_DownEnd, + + ShapeL_DownLeft, + ShapeL_DownLeft_End, + ShapeL_DownLeft_RightEnd, + ShapeL_DownLeft_UpEnd, + + ShapeL_DownRight, + ShapeL_DownRight_End, + ShapeL_DownRight_LeftEnd, + ShapeL_DownRight_UpEnd + ]; + + private static readonly IReadOnlyCollection _U_Shapes = [ + ShapeU_UpEmpty, + ShapeU_UpEmpty_End, + ShapeU_UpEmpty_LeftEnd, + ShapeU_UpEmpty_RightEnd, + + ShapeU_DownEmpty, + ShapeU_DownEmpty_End, + ShapeU_DownEmpty_LeftEnd, + ShapeU_DownEmpty_RightEnd, + + ShapeU_LeftEmpty, + ShapeU_LeftEmpty_End, + ShapeU_LeftEmpty_UpEnd, + ShapeU_LeftEmpty_DownEnd, + + ShapeU_RightEmpty, + ShapeU_RightEmpty_End, + ShapeU_RightEmpty_UpEnd, + ShapeU_RightEmpty_DownEnd + ]; + + /// + /// An Descend Ordered Consume Lookup Table + /// [U -> L -> I -> Corner] Order + /// [Most flags -> Least flags] Order + /// + private static readonly IReadOnlyCollection> _ShapeConsumeMap = [ + _U_Shapes.OrderByDescending(HotFlagCount).ToImmutableArray(), + _L_Shapes.OrderByDescending(HotFlagCount).ToImmutableArray(), + _I_Shapes.OrderByDescending(HotFlagCount).ToImmutableArray(), + // I shape includes up, down, left, right. So we don't need to consume them manually + _Corner_Shapes, + ]; + #endregion + + #region Utils + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Rectangle CreateRect(int sheetX, int sheetY) + { + return new Rectangle(sheetX * 18, sheetY * 18, 16, 16); + } + + private static Rectangle[] Create3RectsDirX(int leftSheetX, int leftSheetY, int increment = 1) + { + return [ + CreateRect(leftSheetX, leftSheetY), + CreateRect(leftSheetX + (1 * increment), leftSheetY), + CreateRect(leftSheetX + (2 * increment), leftSheetY) + ]; + } + + private static Rectangle[] Create3RectsDirY(int topSheetX, int topSheetY, int increment = 1) + { + return [ + CreateRect(topSheetX, topSheetY), + CreateRect(topSheetX, topSheetY + (1 * increment)), + CreateRect(topSheetX, topSheetY + (2 * increment)) + ]; + } + + private static int HotFlagCount(BlendSideFlags flags) + { + var count = 0; + for (int i = 0; i < 8; i++) + { + var flag = (BlendSideFlags)(1 << i); + if (flag == (flags & flag)) + { + count++; + } + } + return count; + } + #endregion + } +} diff --git a/Systems/BestiaryRegistrySystem.cs b/Systems/World/BestiaryRegistrySystem.cs similarity index 100% rename from Systems/BestiaryRegistrySystem.cs rename to Systems/World/BestiaryRegistrySystem.cs diff --git a/Systems/MiscWorldStateSystem.cs b/Systems/World/MiscWorldStateSystem.cs similarity index 100% rename from Systems/MiscWorldStateSystem.cs rename to Systems/World/MiscWorldStateSystem.cs diff --git a/Systems/WorldMiscUpdateSystem.cs b/Systems/World/WorldMiscUpdateSystem.cs similarity index 99% rename from Systems/WorldMiscUpdateSystem.cs rename to Systems/World/WorldMiscUpdateSystem.cs index eb8fc619f6..d9baa823af 100644 --- a/Systems/WorldMiscUpdateSystem.cs +++ b/Systems/World/WorldMiscUpdateSystem.cs @@ -99,7 +99,7 @@ namespace CalamityMod.Systems // Disable sandstorms if the Desert Scourge is still alive and Hardmode hasn't begun. if (!DownedBossSystem.downedDesertScourge && Main.netMode != NetmodeID.MultiplayerClient && !Main.hardMode) - CalamityUtils.StopSandstorm(); + CalamityWorld.StopSandstorm(); // Attempt to summon lab critters manually since they refuse to exist when using vanilla's spawn methods. // This needs to check all players since the method only runs server-side. diff --git a/Systems/WorldgenManagementSystem.cs b/Systems/World/WorldgenManagementSystem.cs similarity index 100% rename from Systems/WorldgenManagementSystem.cs rename to Systems/World/WorldgenManagementSystem.cs diff --git a/Tiles/Astral/AstralTree.cs b/Tiles/Astral/AstralTree.cs index 9bc4e6c1d6..e65767fa7f 100644 --- a/Tiles/Astral/AstralTree.cs +++ b/Tiles/Astral/AstralTree.cs @@ -1,4 +1,5 @@ -using CalamityMod.Dusts; +using System; +using CalamityMod.Dusts; using CalamityMod.Gores.Trees; using CalamityMod.Items.Materials; using CalamityMod.NPCs.Astral; @@ -14,7 +15,7 @@ using Terraria.ModLoader; namespace CalamityMod.Tiles.Astral { - public class AstralTree : ModTree + public class AstralTree : GlowMaskTree { public override void SetStaticDefaults() { @@ -32,7 +33,24 @@ namespace CalamityMod.Tiles.Astral SpecialGroupMaximumSaturationValue = 1f }; + public override Asset GetTexture() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTree"); + public override Asset GetGlowTexture() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTreeGlow"); + public override Asset GetBranchTextures() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTree_Branches"); + public override Asset GetBranchGlowTextures() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTree_BranchesGlow"); public override Asset GetTopTextures() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTree_Tops"); + public override Asset GetTopGlowTextures() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTree_TopsGlow"); + + public override Color GetGlowColor(int i, int j) + { + float brightness = 1f; + float declareThisHereToPreventRunningTheSameCalculationMultipleTimes = Main.GameUpdateCount * 0.012f; + brightness *= MathF.Sin(i / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(j / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(i * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(j * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness = MathHelper.Clamp(brightness, 0.0f, 1.0f); + return Color.White * MathHelper.Lerp(0.1f, 1.0f, brightness); + } public override void SetTreeFoliageSettings(Tile tile, ref int xoffset, ref int treeFrame, ref int floorY, ref int topTextureFrameWidth, ref int topTextureFrameHeight) { @@ -40,8 +58,6 @@ namespace CalamityMod.Tiles.Astral //treeFrame = (i + j * j) % 3; } - public override Asset GetBranchTextures() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTree_Branches"); - public override Asset GetTexture() => ModContent.Request("CalamityMod/Tiles/Astral/AstralTree"); public override int DropWood() => ModContent.ItemType(); public override int CreateDust() => ModContent.DustType(); diff --git a/Tiles/Astral/AstralTreeGlow.png b/Tiles/Astral/AstralTreeGlow.png new file mode 100644 index 0000000000..cc173b6b66 Binary files /dev/null and b/Tiles/Astral/AstralTreeGlow.png differ diff --git a/Tiles/Astral/AstralTree_BranchesGlow.png b/Tiles/Astral/AstralTree_BranchesGlow.png new file mode 100644 index 0000000000..2b3ef6685e Binary files /dev/null and b/Tiles/Astral/AstralTree_BranchesGlow.png differ diff --git a/Tiles/Astral/AstralTree_TopsGlow.png b/Tiles/Astral/AstralTree_TopsGlow.png new file mode 100644 index 0000000000..384729360c Binary files /dev/null and b/Tiles/Astral/AstralTree_TopsGlow.png differ diff --git a/Tiles/AstralDesert/AstralCactus.cs b/Tiles/AstralDesert/AstralCactus.cs index fa99db5039..d297df1600 100644 --- a/Tiles/AstralDesert/AstralCactus.cs +++ b/Tiles/AstralDesert/AstralCactus.cs @@ -1,10 +1,11 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria.ModLoader; namespace CalamityMod.Tiles.AstralDesert { - public class AstralCactus : ModCactus + public class AstralCactus : GlowMaskCactus { public override void SetStaticDefaults() { @@ -14,9 +15,15 @@ namespace CalamityMod.Tiles.AstralDesert //Idk what to make with the glowmask public override Asset GetTexture() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralCactus"); + public override Asset GetGlowTexture() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralCactusGlow"); - //What is a FruitTexture + // TODO: Fruit Texture for Astral Cactus (it's for Pink Prickly Pear) public override Asset GetFruitTexture() => null; + public override Asset GetFruitGlowTexture() => null; + public override Color GetGlowColor(int i, int j) + { + return Color.White; + } } } diff --git a/Tiles/AstralDesert/AstralPalmSaplingGlow.png b/Tiles/AstralDesert/AstralPalmSaplingGlow.png new file mode 100644 index 0000000000..2d52fe0746 Binary files /dev/null and b/Tiles/AstralDesert/AstralPalmSaplingGlow.png differ diff --git a/Tiles/AstralDesert/AstralPalmTree.cs b/Tiles/AstralDesert/AstralPalmTree.cs index 4ccdbe2be0..0c25cbe285 100644 --- a/Tiles/AstralDesert/AstralPalmTree.cs +++ b/Tiles/AstralDesert/AstralPalmTree.cs @@ -1,4 +1,5 @@ -using CalamityMod.Dusts; +using System; +using CalamityMod.Dusts; using CalamityMod.Gores.Trees; using CalamityMod.Items.Materials; using Microsoft.Xna.Framework; @@ -13,7 +14,7 @@ using Terraria.ModLoader; namespace CalamityMod.Tiles.AstralDesert { - public class AstralPalmTree : ModPalmTree + public class AstralPalmTree : GlowMaskPalmTree { public override void SetStaticDefaults() { @@ -32,12 +33,27 @@ namespace CalamityMod.Tiles.AstralDesert }; public override Asset GetTexture() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralPalmTree"); + public override Asset GetGlowTexture() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralPalmTreeGlow"); public override Asset GetTopTextures() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralPalmTree_Tops"); + public override Asset GetTopGlowTextures() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralPalmTree_TopsGlow"); //I don't know what this means. Why do palm trees have branches?? Since when. Will ask spriters for an oasis alt later public override Asset GetOasisTopTextures() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralPalmTree_OasisTops"); + public override Asset GetOasisTopGlowTextures() => ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralPalmTree_OasisTopsGlow"); + + public override Color GetGlowColor(int i, int j) + { + float brightness = 1f; + float declareThisHereToPreventRunningTheSameCalculationMultipleTimes = Main.GameUpdateCount * 0.012f; + brightness *= MathF.Sin(i / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(j / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(i * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(j * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness = MathHelper.Clamp(brightness, 0.0f, 1.0f); + return Color.White * MathHelper.Lerp(0.05f, 0.75f, brightness); + } public override int DropWood() => ModContent.ItemType(); diff --git a/Tiles/AstralDesert/AstralPalmTreeGlow.png b/Tiles/AstralDesert/AstralPalmTreeGlow.png new file mode 100644 index 0000000000..5542321a50 Binary files /dev/null and b/Tiles/AstralDesert/AstralPalmTreeGlow.png differ diff --git a/Tiles/AstralDesert/AstralPalmTree_OasisTopsGlow.png b/Tiles/AstralDesert/AstralPalmTree_OasisTopsGlow.png new file mode 100644 index 0000000000..1c5c9e36a7 Binary files /dev/null and b/Tiles/AstralDesert/AstralPalmTree_OasisTopsGlow.png differ diff --git a/Tiles/AstralDesert/AstralPalmTree_TopsGlow.png b/Tiles/AstralDesert/AstralPalmTree_TopsGlow.png new file mode 100644 index 0000000000..c55367677e Binary files /dev/null and b/Tiles/AstralDesert/AstralPalmTree_TopsGlow.png differ diff --git a/Tiles/AstralSnow/AstralSnowTree.cs b/Tiles/AstralSnow/AstralSnowTree.cs index f36ecac3c4..1343ccb1af 100644 --- a/Tiles/AstralSnow/AstralSnowTree.cs +++ b/Tiles/AstralSnow/AstralSnowTree.cs @@ -1,4 +1,5 @@ -using CalamityMod.Dusts; +using System; +using CalamityMod.Dusts; using CalamityMod.Gores.Trees; using CalamityMod.Items.Materials; using CalamityMod.NPCs.Astral; @@ -14,7 +15,7 @@ using Terraria.ModLoader; namespace CalamityMod.Tiles.AstralSnow { - public class AstralSnowTree : ModTree + public class AstralSnowTree : GlowMaskTree { public override void SetStaticDefaults() { @@ -32,7 +33,24 @@ namespace CalamityMod.Tiles.AstralSnow SpecialGroupMaximumSaturationValue = 1f }; + public override Asset GetTexture() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTree"); + public override Asset GetGlowTexture() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTreeGlow"); + public override Asset GetBranchTextures() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTree_Branches"); + public override Asset GetBranchGlowTextures() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTree_BranchesGlow"); public override Asset GetTopTextures() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTree_Tops"); + public override Asset GetTopGlowTextures() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTree_TopsGlow"); + + public override Color GetGlowColor(int i, int j) + { + float brightness = 1f; + float declareThisHereToPreventRunningTheSameCalculationMultipleTimes = Main.GameUpdateCount * 0.012f; + brightness *= MathF.Sin(i / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(j / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(i * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness *= MathF.Sin(j * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); + brightness = MathHelper.Clamp(brightness, 0.0f, 1.0f); + return Color.White * MathHelper.Lerp(0.35f, 1.0f, brightness); + } public override void SetTreeFoliageSettings(Tile tile, ref int xoffset, ref int treeFrame, ref int floorY, ref int topTextureFrameWidth, ref int topTextureFrameHeight) { @@ -40,10 +58,6 @@ namespace CalamityMod.Tiles.AstralSnow //treeFrame = (i + j * j) % 6; } - public override Asset GetBranchTextures() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTree_Branches"); - - public override Asset GetTexture() => ModContent.Request("CalamityMod/Tiles/AstralSnow/AstralSnowTree"); - public override int DropWood() => ModContent.ItemType(); public override int CreateDust() => ModContent.DustType(); diff --git a/Tiles/AstralSnow/AstralSnowTreeGlow.png b/Tiles/AstralSnow/AstralSnowTreeGlow.png new file mode 100644 index 0000000000..147cc38b7d Binary files /dev/null and b/Tiles/AstralSnow/AstralSnowTreeGlow.png differ diff --git a/Tiles/AstralSnow/AstralSnowTreeSaplingGlow.png b/Tiles/AstralSnow/AstralSnowTreeSaplingGlow.png new file mode 100644 index 0000000000..3b59887860 Binary files /dev/null and b/Tiles/AstralSnow/AstralSnowTreeSaplingGlow.png differ diff --git a/Tiles/AstralSnow/AstralSnowTree_BranchesGlow.png b/Tiles/AstralSnow/AstralSnowTree_BranchesGlow.png new file mode 100644 index 0000000000..00aac1645e Binary files /dev/null and b/Tiles/AstralSnow/AstralSnowTree_BranchesGlow.png differ diff --git a/Tiles/AstralSnow/AstralSnowTree_TopsGlow.png b/Tiles/AstralSnow/AstralSnowTree_TopsGlow.png new file mode 100644 index 0000000000..0a4fa7f4b6 Binary files /dev/null and b/Tiles/AstralSnow/AstralSnowTree_TopsGlow.png differ diff --git a/Tiles/CalamityGlobalTile.cs b/Tiles/CalamityGlobalTile.cs index a40f0dd4fe..d805d126a9 100644 --- a/Tiles/CalamityGlobalTile.cs +++ b/Tiles/CalamityGlobalTile.cs @@ -39,52 +39,6 @@ namespace CalamityMod.Tiles Main.tileOreFinderPriority[TileID.LunarOre] = 900; } - public override void PostDraw(int i, int j, int type, SpriteBatch spriteBatch) - { - // Guaranteed not null at this point - Tile tile = Main.tile[i, j]; - - // This function is only for Astral Cactus. If the tile isn't even cactus, forget about it. - if (type != TileID.Cactus) - return; - - Vector2 zero = new Vector2(Main.offScreenRange, Main.offScreenRange); - if (Main.drawToScreen) - zero = Vector2.Zero; - int frameX = tile.TileFrameX; - int frameY = tile.TileFrameY; - - // Search down the cactus to find out whether the block it is planted in is Astral Sand. - int xTile = i; - if (frameX == 36) // Cactus segment which splits left - xTile--; - if (frameX == 54) // Cactus segment which splits right - xTile++; - if (frameX == 108) // Cactus segment which splits both directions - xTile += (frameY == 18) ? -1 : 1; - - int yTile = j; - bool slidingDownCactus = Main.tile[xTile, yTile] != null && Main.tile[xTile, yTile].TileType == TileID.Cactus && Main.tile[xTile, yTile].HasTile; - while (!Main.tile[xTile, yTile].HasTile || !Main.tileSolid[Main.tile[xTile, yTile].TileType] || !slidingDownCactus) - { - if (Main.tile[xTile, yTile].TileType == TileID.Cactus && Main.tile[xTile, yTile].HasTile) - { - slidingDownCactus = true; - } - yTile++; - // Cacti are assumed to be no more than 20 blocks tall. - if (yTile > i + 20) - break; - } - bool astralCactus = Main.tile[xTile, yTile].TileType == (ushort)ModContent.TileType(); - - // If it is actually astral cactus, then draw its glowmask. - if (astralCactus) - { - spriteBatch.Draw(ModContent.Request("CalamityMod/Tiles/AstralDesert/AstralCactusGlow").Value, new Vector2((float)(i * 16 - (int)Main.screenPosition.X), (float)(j * 16 - (int)Main.screenPosition.Y)) + zero, new Rectangle((int)frameX, (int)frameY, 16, 18), Color.White * 0.75f, 0f, default, 1f, SpriteEffects.None, 0f); - } - } - public override void KillTile(int i, int j, int type, ref bool fail, ref bool effectOnly, ref bool noItem) { Tile tile = Main.tile[i, j]; diff --git a/Tiles/Crags/Tree/SpineSapling.cs b/Tiles/Crags/Tree/SpineSapling.cs index e1af1f142c..50ce8eee4e 100644 --- a/Tiles/Crags/Tree/SpineSapling.cs +++ b/Tiles/Crags/Tree/SpineSapling.cs @@ -49,12 +49,9 @@ namespace CalamityMod.Tiles.Crags.Tree { if (WorldGen.genRand.NextBool(20)) { - bool isPlayerNear = WorldGen.PlayerLOS(i, j); - - if (isPlayerNear && Main.tile[i, j + 1].TileType != ModContent.TileType()) - { - SpineTree.Spawn(i, j + 1, 22, 28, true); - } + // if below tile is somewhat not sappling (only possible if it's from below part) + if (Main.tile[i, j + 1].TileType != Type) + SpineTree.Spawn(i, j, 22, 28, true); } } diff --git a/Tiles/Crags/Tree/SpineTree.cs b/Tiles/Crags/Tree/SpineTree.cs index a5ab31f444..51c98ce0e4 100644 --- a/Tiles/Crags/Tree/SpineTree.cs +++ b/Tiles/Crags/Tree/SpineTree.cs @@ -62,13 +62,6 @@ namespace CalamityMod.Tiles.Crags.Tree public static bool Spawn(int i, int j, int minSize = 5, int maxSize = 18, bool saplingExists = false) { - //if this tree grew from a sapling, then kill the sapling its growing from - if (saplingExists) - { - WorldGen.KillTile(i, j, false, false, true); - WorldGen.KillTile(i, j - 1, false, false, true); - } - //set the minimum and maximum height the tree can grow to int height = Main.rand.Next(minSize, maxSize); for (int k = 1; k < height; ++k) @@ -85,6 +78,20 @@ namespace CalamityMod.Tiles.Crags.Tree return false; } + // something is blocking from growing the tree... + var sapplingType = ModContent.TileType(); + if (!WorldGen.EmptyTileCheck(i - 2, i + 2, j - height, j, sapplingType)) + { + return false; + } + + //if this tree grew from a sapling, then kill the sapling its growing from + if (saplingExists) + { + WorldGen.KillTile(i, j, false, false, true); + WorldGen.KillTile(i, j - 1, false, false, true); + } + //make sure the block is valid for the tree to place on if ((SolidTopTile(i, j + 1) || SolidTile(i, j + 1)) && !Framing.GetTileSafely(i, j).HasTile) { diff --git a/Tiles/Furniture/BossRelics/SlimeGodRelic.png b/Tiles/Furniture/BossRelics/SlimeGodRelic.png index 9f20a8d8b0..c52d4bf182 100644 Binary files a/Tiles/Furniture/BossRelics/SlimeGodRelic.png and b/Tiles/Furniture/BossRelics/SlimeGodRelic.png differ diff --git a/Tiles/FurnitureEutrophic/AncientSmoothNavystone.cs b/Tiles/FurnitureEutrophic/AncientSmoothNavystone.cs new file mode 100644 index 0000000000..18ae30d146 --- /dev/null +++ b/Tiles/FurnitureEutrophic/AncientSmoothNavystone.cs @@ -0,0 +1,33 @@ + +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.FurnitureEutrophic +{ + public class AncientSmoothNavystone : ModTile + { + public override void SetStaticDefaults() + { + Main.tileSolid[Type] = true; + Main.tileMergeDirt[Type] = true; + Main.tileBlockLight[Type] = true; + + CalamityUtils.MergeWithGeneral(Type); + CalamityUtils.MergeSmoothTiles(Type); + CalamityUtils.MergeDecorativeTiles(Type); + CalamityUtils.MergeWithDesert(Type); + + TileID.Sets.ChecksForMerge[Type] = true; + HitSound = SoundID.Tink; + AddMapEntry(new Color(39, 48, 53)); + } + + public override bool CreateDust(int i, int j, ref int type) + { + Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.SnowBlock, 0f, 0f, 1, new Color(54, 69, 72), 1f); + return false; + } + } +} diff --git a/Tiles/FurnitureEutrophic/AncientSmoothNavystone.png b/Tiles/FurnitureEutrophic/AncientSmoothNavystone.png new file mode 100644 index 0000000000..7d498f636a Binary files /dev/null and b/Tiles/FurnitureEutrophic/AncientSmoothNavystone.png differ diff --git a/Tiles/FurnitureEutrophic/SmoothNavystone.cs b/Tiles/FurnitureEutrophic/SmoothNavystone.cs index 6f71592d07..ce85324b05 100644 --- a/Tiles/FurnitureEutrophic/SmoothNavystone.cs +++ b/Tiles/FurnitureEutrophic/SmoothNavystone.cs @@ -1,4 +1,5 @@  +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; @@ -11,23 +12,29 @@ namespace CalamityMod.Tiles.FurnitureEutrophic public override void SetStaticDefaults() { Main.tileSolid[Type] = true; - Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; CalamityUtils.MergeWithGeneral(Type); CalamityUtils.MergeSmoothTiles(Type); CalamityUtils.MergeDecorativeTiles(Type); + CalamityUtils.MergeWithAbyss(Type); CalamityUtils.MergeWithDesert(Type); TileID.Sets.ChecksForMerge[Type] = true; + TileID.Sets.HasSlopeFrames[Type] = true; HitSound = SoundID.Tink; - AddMapEntry(new Color(39, 48, 53)); + DustType = 96; + AddMapEntry(new Color(44, 57, 64)); } - public override bool CreateDust(int i, int j, ref int type) + public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { - Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.SnowBlock, 0f, 0f, 1, new Color(54, 69, 72), 1f); - return false; + return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); + } + + public override void NumDust(int i, int j, bool fail, ref int num) + { + num = fail ? 1 : 3; } } } diff --git a/Tiles/FurnitureEutrophic/SmoothNavystone.png b/Tiles/FurnitureEutrophic/SmoothNavystone.png index 7d498f636a..2a125f4dd2 100644 Binary files a/Tiles/FurnitureEutrophic/SmoothNavystone.png and b/Tiles/FurnitureEutrophic/SmoothNavystone.png differ diff --git a/Tiles/GlowMaskCactus.cs b/Tiles/GlowMaskCactus.cs new file mode 100644 index 0000000000..7232b67601 --- /dev/null +++ b/Tiles/GlowMaskCactus.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria.GameContent.RGB; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles +{ + public abstract class GlowMaskCactus : ModCactus + { + public abstract Asset GetFruitGlowTexture(); + public abstract Asset GetGlowTexture(); + + public abstract Color GetGlowColor(int i, int j); + } +} diff --git a/Tiles/GlowMaskPalmTree.cs b/Tiles/GlowMaskPalmTree.cs new file mode 100644 index 0000000000..ce30f5374c --- /dev/null +++ b/Tiles/GlowMaskPalmTree.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria.GameContent; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles +{ + public abstract class GlowMaskPalmTree : ModPalmTree + { + public abstract Asset GetOasisTopGlowTextures(); + public abstract Asset GetGlowTexture(); + public abstract Asset GetTopGlowTextures(); + + public abstract Color GetGlowColor(int i, int j); + } +} diff --git a/Tiles/GlowMaskTree.cs b/Tiles/GlowMaskTree.cs new file mode 100644 index 0000000000..8e252b39e2 --- /dev/null +++ b/Tiles/GlowMaskTree.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles +{ + public struct GlowMaskPlantDrawInfo + { + public Texture2D Texture; + public Color Color; + } + + public abstract class GlowMaskTree : ModTree + { + public abstract Asset GetGlowTexture(); + public abstract Asset GetTopGlowTextures(); + public abstract Asset GetBranchGlowTextures(); + + public abstract Color GetGlowColor(int i, int j); + } +} diff --git a/Tiles/Merges/AbyssGravelMerge.cs b/Tiles/Merges/AbyssGravelMerge.cs new file mode 100644 index 0000000000..30a16d02bd --- /dev/null +++ b/Tiles/Merges/AbyssGravelMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class AbyssGravelMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/AshMerge.cs b/Tiles/Merges/AshMerge.cs new file mode 100644 index 0000000000..0e40adacc3 --- /dev/null +++ b/Tiles/Merges/AshMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class AshMerge : TileBlendTexture + { + public override int TileType => TileID.Ash; + } +} diff --git a/Tiles/Merges/AstralDirtMerge.cs b/Tiles/Merges/AstralDirtMerge.cs new file mode 100644 index 0000000000..bd375f30ce --- /dev/null +++ b/Tiles/Merges/AstralDirtMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Astral; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class AstralDirtMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/AstralSandMerge.cs b/Tiles/Merges/AstralSandMerge.cs new file mode 100644 index 0000000000..993c97bb4e --- /dev/null +++ b/Tiles/Merges/AstralSandMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.AstralDesert; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class AstralSandMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/AstralSandstoneMerge.cs b/Tiles/Merges/AstralSandstoneMerge.cs new file mode 100644 index 0000000000..83be67fd5b --- /dev/null +++ b/Tiles/Merges/AstralSandstoneMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.AstralDesert; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class AstralSandstoneMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/AstralSnowMerge.cs b/Tiles/Merges/AstralSnowMerge.cs new file mode 100644 index 0000000000..8b3719fbda --- /dev/null +++ b/Tiles/Merges/AstralSnowMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class AstralSnowMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/BrimstoneSlagMerge.cs b/Tiles/Merges/BrimstoneSlagMerge.cs new file mode 100644 index 0000000000..e6839eab2c --- /dev/null +++ b/Tiles/Merges/BrimstoneSlagMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Crags; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class BrimstoneSlagMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/CloudMerge.cs b/Tiles/Merges/CloudMerge.cs new file mode 100644 index 0000000000..486a71992f --- /dev/null +++ b/Tiles/Merges/CloudMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class CloudMerge : TileBlendTexture + { + public override int TileType => TileID.Cloud; + } +} diff --git a/Tiles/Merges/DirtMerge.cs b/Tiles/Merges/DirtMerge.cs new file mode 100644 index 0000000000..4b7fdf821f --- /dev/null +++ b/Tiles/Merges/DirtMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class DirtMerge : TileBlendTexture + { + public override int TileType => TileID.Dirt; + } +} diff --git a/Tiles/Merges/EutrophicSandMerge.cs b/Tiles/Merges/EutrophicSandMerge.cs new file mode 100644 index 0000000000..84f5014349 --- /dev/null +++ b/Tiles/Merges/EutrophicSandMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.SunkenSea; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class EutrophicSandMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/HardenedSandMerge.cs b/Tiles/Merges/HardenedSandMerge.cs new file mode 100644 index 0000000000..d82124c471 --- /dev/null +++ b/Tiles/Merges/HardenedSandMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class HardenedSandMerge : TileBlendTexture + { + public override int TileType => TileID.HardenedSand; + } +} diff --git a/Tiles/Merges/HardenedSulphurousSandstoneMerge.cs b/Tiles/Merges/HardenedSulphurousSandstoneMerge.cs new file mode 100644 index 0000000000..11c38bb34b --- /dev/null +++ b/Tiles/Merges/HardenedSulphurousSandstoneMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class HardenedSulphurousSandstoneMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/LuminiteMerge.cs b/Tiles/Merges/LuminiteMerge.cs new file mode 100644 index 0000000000..b98f1566ac --- /dev/null +++ b/Tiles/Merges/LuminiteMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class LuminiteMerge : TileBlendTexture + { + public override int TileType => TileID.LunarOre; + } +} diff --git a/Tiles/Merges/MudMerge.cs b/Tiles/Merges/MudMerge.cs new file mode 100644 index 0000000000..85b2fcc6fa --- /dev/null +++ b/Tiles/Merges/MudMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class MudMerge : TileBlendTexture + { + public override int TileType => TileID.Mud; + } +} diff --git a/Tiles/Merges/NavystoneMerge.cs b/Tiles/Merges/NavystoneMerge.cs new file mode 100644 index 0000000000..fc4331fe19 --- /dev/null +++ b/Tiles/Merges/NavystoneMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.SunkenSea; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class NavystoneMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/PearlstoneMerge.cs b/Tiles/Merges/PearlstoneMerge.cs new file mode 100644 index 0000000000..9e6a376cfd --- /dev/null +++ b/Tiles/Merges/PearlstoneMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class PearlstoneMerge : TileBlendTexture + { + public override int TileType => TileID.Pearlstone; + } +} diff --git a/Tiles/Merges/PyreMantleMerge.cs b/Tiles/Merges/PyreMantleMerge.cs new file mode 100644 index 0000000000..73458c5c7c --- /dev/null +++ b/Tiles/Merges/PyreMantleMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class PyreMantleMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/RainCloudMerge.cs b/Tiles/Merges/RainCloudMerge.cs new file mode 100644 index 0000000000..a741cf99cb --- /dev/null +++ b/Tiles/Merges/RainCloudMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class RainCloudMerge : TileBlendTexture + { + public override int TileType => TileID.RainCloud; + } +} diff --git a/Tiles/Merges/SandMerge.cs b/Tiles/Merges/SandMerge.cs new file mode 100644 index 0000000000..f52a18a8ff --- /dev/null +++ b/Tiles/Merges/SandMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class SandMerge : TileBlendTexture + { + public override int TileType => TileID.Sand; + } +} diff --git a/Tiles/Merges/SandstoneMerge.cs b/Tiles/Merges/SandstoneMerge.cs new file mode 100644 index 0000000000..3bf4d424f6 --- /dev/null +++ b/Tiles/Merges/SandstoneMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class SandstoneMerge : TileBlendTexture + { + public override int TileType => TileID.Sandstone; + } +} diff --git a/Tiles/Merges/SnowCloudMerge.cs b/Tiles/Merges/SnowCloudMerge.cs new file mode 100644 index 0000000000..be9736bf56 --- /dev/null +++ b/Tiles/Merges/SnowCloudMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class SnowCloudMerge : TileBlendTexture + { + public override int TileType => TileID.SnowCloud; + } +} diff --git a/Tiles/Merges/SnowMerge.cs b/Tiles/Merges/SnowMerge.cs new file mode 100644 index 0000000000..374ddd1d15 --- /dev/null +++ b/Tiles/Merges/SnowMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class SnowMerge : TileBlendTexture + { + public override int TileType => TileID.SnowBlock; + } +} diff --git a/Tiles/Merges/StoneMerge.cs b/Tiles/Merges/StoneMerge.cs new file mode 100644 index 0000000000..1ce0e06c10 --- /dev/null +++ b/Tiles/Merges/StoneMerge.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using Terraria.ID; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class StoneMerge : TileBlendTexture + { + public override int TileType => TileID.Stone; + } +} diff --git a/Tiles/Merges/SulphurousSandMerge.cs b/Tiles/Merges/SulphurousSandMerge.cs new file mode 100644 index 0000000000..ff3e1e2664 --- /dev/null +++ b/Tiles/Merges/SulphurousSandMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class SulphurousSandMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/SulphurousSandstoneMerge.cs b/Tiles/Merges/SulphurousSandstoneMerge.cs new file mode 100644 index 0000000000..ad3648857a --- /dev/null +++ b/Tiles/Merges/SulphurousSandstoneMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class SulphurousSandstoneMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/SulphurousShaleMerge.cs b/Tiles/Merges/SulphurousShaleMerge.cs new file mode 100644 index 0000000000..9fc08075c5 --- /dev/null +++ b/Tiles/Merges/SulphurousShaleMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class SulphurousShaleMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Merges/VoidstoneMerge.cs b/Tiles/Merges/VoidstoneMerge.cs new file mode 100644 index 0000000000..0f827eafc6 --- /dev/null +++ b/Tiles/Merges/VoidstoneMerge.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles.Merges +{ + public sealed class VoidstoneMerge : TileBlendTexture + { + public override int TileType => ModContent.TileType(); + } +} diff --git a/Tiles/Ores/AstralOre.cs b/Tiles/Ores/AstralOre.cs index 0b1f23af65..481d793184 100644 --- a/Tiles/Ores/AstralOre.cs +++ b/Tiles/Ores/AstralOre.cs @@ -74,7 +74,12 @@ namespace CalamityMod.Tiles.Ores public override IEnumerable GetItemDrops(int i, int j) { if (!DownedBossSystem.downedAstrumDeus) - yield return new Item(ModContent.ItemType(), Main.rand.Next(1, 2 + 1)); + { + if (Main.rand.NextBool()) + yield return new Item(ModContent.ItemType()); + else + yield return new Item(0); + } else yield return new Item(ModContent.ItemType()); } diff --git a/Tiles/Stohne.cs b/Tiles/Stohne.cs new file mode 100644 index 0000000000..64bf509eda --- /dev/null +++ b/Tiles/Stohne.cs @@ -0,0 +1,38 @@ +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles +{ + public class Stohne : ModTile + { + + public override void SetStaticDefaults() + { + Main.tileSolid[Type] = true; + Main.tileBlockLight[Type] = true; + HitSound = SoundID.Tink; + AddMapEntry(new Color(117, 42, 14)); + DustType = DustID.Lihzahrd; + + CalamityUtils.MergeWithGeneral(Type); + CalamityUtils.MergeWithOres(Type); + + TileID.Sets.Stone[Type] = true; + TileID.Sets.Conversion.Stone[Type] = true; + TileID.Sets.CanBeClearedDuringOreRunner[Type] = true; + TileID.Sets.HasSlopeFrames[Type] = true; + + this.RegisterUniversalMerge(TileID.Dirt, "CalamityMod/Tiles/Merges/DirtMerge"); + this.RegisterUniversalMerge(TileID.Stone, "CalamityMod/Tiles/Merges/StoneMerge"); + this.RegisterUniversalMerge(TileID.Mud, "CalamityMod/Tiles/Merges/MudMerge"); + } + + public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) + { + return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); + } + } +} diff --git a/Tiles/Stohne.png b/Tiles/Stohne.png new file mode 100644 index 0000000000..d053c4c58d Binary files /dev/null and b/Tiles/Stohne.png differ diff --git a/UI/BossHealthBarManager.cs b/UI/BossHealthBarManager.cs index a7a0ad791c..021fe2f7e6 100644 --- a/UI/BossHealthBarManager.cs +++ b/UI/BossHealthBarManager.cs @@ -25,6 +25,7 @@ using CalamityMod.NPCs.SunkenSea; using CalamityMod.NPCs.SupremeCalamitas; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using MonoMod.Utils; using ReLogic.Content; using ReLogic.Graphics; using Terraria; @@ -93,7 +94,15 @@ namespace CalamityMod.UI public delegate bool NPCSpecialHPGetRequirement(NPC npc); public delegate long NPCSpecialHPGetFunction(NPC npc, bool checkingForMaxLife); - internal static void Load(Mod mod) + public override void Load() + { + BossExclusionList = []; + MinibossHPBarList = []; + EntityExtensionHandler = []; + SpecialHPRequirements = []; + } + + public override void SetStaticDefaults() { Bars = new List(); @@ -175,10 +184,23 @@ namespace CalamityMod.UI SetupRequirementsList(); } + public override void Unload() + { + BossMainHPBar = null; + BossComboHPBar = null; + BossSeperatorBar = null; + HPBarFont = null; + Bars = null; + BossExclusionList = null; + MinibossHPBarList = null; + OneToMany = null; + EntityExtensionHandler = null; + SpecialHPRequirements = null; + } + public static void SetupBossExclusionList() { - BossExclusionList = new List - { + BossExclusionList.AddRange([ NPCID.None, NPCID.MoonLordFreeEye, NPCID.MoonLordHead, @@ -206,14 +228,13 @@ namespace CalamityMod.UI NPCType(), NPCType(), NPCType(), - NPCType(), - }; + NPCType() + ]); } public static void SetupMinibossHPBarList() { - MinibossHPBarList = new List - { + MinibossHPBarList.AddRange([ // DD2 Event. NPCID.DD2Betsy, NPCID.DD2OgreT2, @@ -271,12 +292,12 @@ namespace CalamityMod.UI NPCType(), NPCType(), NPCType() - }; + ]); } public static void SetupExtensionHandlerList() { - EntityExtensionHandler = new Dictionary() + EntityExtensionHandler.AddRange(new Dictionary() { [NPCID.EaterofWorldsHead] = new BossEntityExtension(CalamityUtils.GetText("UI.ExtensionName.Segments"), NPCID.EaterofWorldsHead, NPCID.EaterofWorldsBody, NPCID.EaterofWorldsTail), [NPCID.BrainofCthulhu] = new BossEntityExtension(CalamityUtils.GetText("UI.ExtensionName.Creepers"), NPCID.Creeper), @@ -286,7 +307,7 @@ namespace CalamityMod.UI [NPCID.PirateShip] = new BossEntityExtension(CalamityUtils.GetText("UI.ExtensionName.Cannons"), NPCID.PirateShipCannon), [NPCType()] = new BossEntityExtension(CalamityUtils.GetText("UI.ExtensionName.DarkEnergy"), NPCType()), [NPCType()] = new BossEntityExtension(CalamityUtils.GetText("UI.ExtensionName.BodyParts"), NPCType(), NPCType(), NPCType(), NPCType()), - }; + }); } // Collection simplification looks horrendous in the context of delegate creation. @@ -294,7 +315,6 @@ namespace CalamityMod.UI #pragma warning disable IDE0028 // Simplify collection initialization public static void SetupRequirementsList() { - SpecialHPRequirements = new Dictionary(); SpecialHPRequirements.Add(npc => npc.Calamity().SplittingWorm, (npc, checkingForMaxLife) => { // Go across the entire worm and accumulate life. The expectation is that the boss follows the linked-list-esque standard @@ -348,20 +368,6 @@ namespace CalamityMod.UI } #pragma warning restore IDE0028 // Simplify collection initialization - public override void Unload() - { - BossMainHPBar = null; - BossComboHPBar = null; - BossSeperatorBar = null; - HPBarFont = null; - Bars = null; - BossExclusionList = null; - MinibossHPBarList = null; - OneToMany = null; - EntityExtensionHandler = null; - SpecialHPRequirements = null; - } - public override void Update(IBigProgressBar currentBar, ref BigProgressBarInfo info) { foreach (NPC n in Main.ActiveNPCs) diff --git a/UI/CalamitasEnchantments/CalamitasEnchantUI.cs b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs index d4aa053294..0af121ab93 100644 --- a/UI/CalamitasEnchantments/CalamitasEnchantUI.cs +++ b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs @@ -176,8 +176,13 @@ namespace CalamityMod.UI.CalamitasEnchants // Increase the cost of enchanting significantly if doing so would upgrade the item directly. if (SelectedEnchantment.HasValue && SelectedEnchantment.Value.Name == CalamityUtils.GetText(EnchantmentManager.ExhumedNamePath)) + { cost = (int)MathHelper.Min(cost, Item.buyPrice(5)) * 5; + // 29SEP2024: Ozzatron: exhuming stackable items scales the cost with the stack size + cost *= CurrentlyHeldItem.stack; + } + // Make it 20% cheaper if the player has the Discount Card or Greedy Ring if (Main.LocalPlayer.discountAvailable) cost = (int)(cost * 0.8); @@ -374,7 +379,9 @@ namespace CalamityMod.UI.CalamitasEnchants bool IsExhuming = SelectedEnchantment.Value.Name == CalamityUtils.GetText(EnchantmentManager.ExhumedNamePath); + // 29SEP2024: Ozzatron: exhuming stackable items produces a stack of the same size int oldPrefix = CurrentlyHeldItem.prefix; + int oldStack = CurrentlyHeldItem.stack; CurrentlyHeldItem.SetDefaults(CurrentlyHeldItem.type); CurrentlyHeldItem.Prefix(oldPrefix); CurrentlyHeldItem = CurrentlyHeldItem.Clone(); @@ -383,6 +390,7 @@ namespace CalamityMod.UI.CalamitasEnchants { CurrentlyHeldItem.SetDefaults(EnchantmentManager.ItemUpgradeRelationship[CurrentlyHeldItem.type]); CurrentlyHeldItem.Prefix(oldPrefix); + CurrentlyHeldItem.stack = oldStack; } else { diff --git a/UI/CalamitasEnchantments/EnchantmentManager.cs b/UI/CalamitasEnchantments/EnchantmentManager.cs index ea58ed2b90..86de4cc8d0 100644 --- a/UI/CalamitasEnchantments/EnchantmentManager.cs +++ b/UI/CalamitasEnchantments/EnchantmentManager.cs @@ -16,8 +16,7 @@ using Terraria.ModLoader; namespace CalamityMod.UI.CalamitasEnchants { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class EnchantmentManager + public sealed class EnchantmentManager : ModSystem { internal const int ClearEnchantmentID = -18591774; internal const string ExhumedNamePath = "UI.Exhumed.DisplayName"; @@ -145,7 +144,7 @@ namespace CalamityMod.UI.CalamitasEnchants EnchantmentList.Add(new Enchantment(name, description, id, iconTexturePathElement, creationEffect, holdEffect, requirement)); } - internal static void LoadAllEnchantments() + public override void OnModLoad() { EnchantmentList = new List { @@ -322,7 +321,7 @@ namespace CalamityMod.UI.CalamitasEnchants }; } - internal static void UnloadAllEnchantments() + public override void Unload() { EnchantmentList = null; ItemUpgradeRelationship = null; diff --git a/UI/DraedonsArsenal/ChargeMeterUI.cs b/UI/DraedonsArsenal/ChargeMeterUI.cs index b3c159411e..af52bdb329 100644 --- a/UI/DraedonsArsenal/ChargeMeterUI.cs +++ b/UI/DraedonsArsenal/ChargeMeterUI.cs @@ -9,8 +9,8 @@ using Terraria.ModLoader; namespace CalamityMod.UI.DraedonsArsenal { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public class ChargeMeterUI + [Autoload(Side = ModSide.Client)] + public sealed class ChargeMeterUI : ModSystem { // These values were handpicked on a 1080p screen by Ozzatron. Please disregard the bizarre precision. internal const float DefaultChargePosX = 50.104603f; @@ -20,14 +20,14 @@ namespace CalamityMod.UI.DraedonsArsenal private static Vector2? dragOffset = null; private static Texture2D edgeTexture, barTexture; - internal static void Load() + public override void OnModLoad() { edgeTexture = ModContent.Request("CalamityMod/UI/DraedonsArsenal/ChargeMeterBorder", AssetRequestMode.ImmediateLoad).Value; barTexture = ModContent.Request("CalamityMod/UI/DraedonsArsenal/ChargeMeter", AssetRequestMode.ImmediateLoad).Value; Reset(); } - internal static void Unload() + public override void Unload() { Reset(); edgeTexture = barTexture = null; @@ -65,7 +65,7 @@ namespace CalamityMod.UI.DraedonsArsenal changed = true; } if (changed) - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } // If the Charge Meter is turned off or the player is not holding an item, stop. @@ -132,7 +132,7 @@ namespace CalamityMod.UI.DraedonsArsenal if (ms.LeftButton == ButtonState.Released) { dragOffset = null; - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } } } diff --git a/UI/FlightBar/FlightBar.cs b/UI/FlightBar/FlightBar.cs index a2afefa36f..f344bc517c 100644 --- a/UI/FlightBar/FlightBar.cs +++ b/UI/FlightBar/FlightBar.cs @@ -12,8 +12,8 @@ using Terraria.ModLoader; namespace CalamityMod.UI { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public class FlightBar + [Autoload(Side = ModSide.Client)] + public sealed class FlightBar : ModSystem { // These values were handpicked on a 1080p screen by Amber. Please disregard the bizarre precision. internal const float DefaultFlightPosX = 40.9375f; @@ -63,7 +63,7 @@ namespace CalamityMod.UI return result; } - internal static void Load() + public override void OnModLoad() { borderTexture = ModContent.Request("CalamityMod/UI/FlightBar/FlightBarBorder", AssetRequestMode.ImmediateLoad).Value; flightBarAnimTexture = ModContent.Request("CalamityMod/UI/FlightBar/FlightBarAnim", AssetRequestMode.ImmediateLoad).Value; @@ -74,7 +74,7 @@ namespace CalamityMod.UI Reset(); } - internal static void Unload() + public override void Unload() { Reset(); borderTexture = flightBarAnimTexture = barTexture = disabledBarTexture = infiniteBarTexture = limitedBarTexture = null; @@ -125,7 +125,7 @@ namespace CalamityMod.UI } if (changed) - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); return; } @@ -175,7 +175,7 @@ namespace CalamityMod.UI if (ms.LeftButton == ButtonState.Released) { dragOffset = null; - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } } } diff --git a/UI/InvasionProgressUIManager.cs b/UI/InvasionProgressUIManager.cs index 4c037c5a74..c349471eb3 100644 --- a/UI/InvasionProgressUIManager.cs +++ b/UI/InvasionProgressUIManager.cs @@ -2,14 +2,15 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework.Graphics; +using Terraria.ModLoader; using Terraria.ModLoader.Core; namespace CalamityMod.UI { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class InvasionProgressUIManager + [Autoload(Side = ModSide.Client)] + public sealed class InvasionProgressUIManager : ModSystem { - private static readonly List gUIs = new List(); + private static readonly List gUIs = []; public static int TotalGUIsActive => gUIs.Count(gui => gui.IsActive); public static bool AnyGUIsActive => TotalGUIsActive > 0; public static InvasionProgressUI GetActiveGUI => gUIs.FirstOrDefault(gui => gui.IsActive); @@ -23,19 +24,18 @@ namespace CalamityMod.UI } } - public static void LoadGUIs() + public override void OnModLoad() { // Look through every type in the mod, and check if it's derived from InvasionProgressUI. If it is, create a copy and save it in the static list. - Type[] types = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code); - foreach (Type type in types) + ReflectionHelper.IterateCalamityTypes(action: type => { - // Don't load abstract classes since they cannot have instances. - if (type.IsAbstract) - continue; - if (type.IsSubclassOf(typeof(InvasionProgressUI))) - gUIs.Add(Activator.CreateInstance(type) as InvasionProgressUI); - } + gUIs.Add(Activator.CreateInstance(type) as InvasionProgressUI); + }); + } + + public override void Unload() + { + gUIs?.Clear(); } - public static void UnloadGUIs() => gUIs.Clear(); } } diff --git a/UI/PopupGUIManager.cs b/UI/PopupGUIManager.cs index 0f472693a9..0e37676da0 100644 --- a/UI/PopupGUIManager.cs +++ b/UI/PopupGUIManager.cs @@ -8,10 +8,10 @@ using Terraria.ModLoader.Core; namespace CalamityMod.UI { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class PopupGUIManager + [Autoload(Side = ModSide.Client)] + public sealed class PopupGUIManager : ModSystem { - private static readonly List gUIs = new List(); + private static readonly List gUIs = []; public static bool GUIActive(PopupGUI gui) => gui.Active || gui.FadeTime > 0; public static bool AnyGUIsActive => gUIs.Any(GUIActive); public static PopupGUI GetActiveGUI => gUIs.FirstOrDefault(GUIActive); @@ -57,21 +57,18 @@ namespace CalamityMod.UI gUIs.First(gui => gui.GetType() == type).Active = !gUIs.First(gui => gui.GetType() == type).Active; } - public static void LoadGUIs() + public override void OnModLoad() { // Look through every type in the mod, and check if it's derived from PopupGUI. If it is, create a copy and save it in the static list. - foreach (Mod mod in ModLoader.Mods) + ReflectionHelper.IterateEveryModsTypes(action: type => { - foreach (Type type in AssemblyManager.GetLoadableTypes(mod.Code)) - { - // Don't load abstract classes since they cannot have instances. - if (type.IsAbstract) - continue; - if (type.IsSubclassOf(typeof(PopupGUI))) - gUIs.Add(Activator.CreateInstance(type) as PopupGUI); - } - } + gUIs.Add(Activator.CreateInstance(type) as PopupGUI); + }); + } + + public override void Unload() + { + gUIs?.Clear(); } - public static void UnloadGUIs() => gUIs.Clear(); } } diff --git a/UI/Rippers/RipperUI.cs b/UI/Rippers/RipperUI.cs index 2f9cce458e..424310e6ec 100644 --- a/UI/Rippers/RipperUI.cs +++ b/UI/Rippers/RipperUI.cs @@ -11,8 +11,8 @@ using Terraria.ModLoader; namespace CalamityMod.UI.Rippers { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class RipperUI + [Autoload(Side = ModSide.Client)] + public sealed class RipperUI : ModSystem { // These values were handpicked on a 1080p screen by Ozzatron. Please disregard the bizarre precision. public const float DefaultRagePosX = 35.77406f; @@ -51,7 +51,7 @@ namespace CalamityMod.UI.Rippers private static Texture2D adrenBarTex, adrenBorderTex, adrenBorderTexFull, adrenAnimTex, draedonBarTex, draedonAnimTex; private static Texture2D electrolyteGelTex, starlightFuelTex, ectoheartTex; - internal static void Load() + public override void OnModLoad() { rageBarTex = ModContent.Request("CalamityMod/UI/Rippers/RageBar", AssetRequestMode.ImmediateLoad).Value; rageBorderTex = ModContent.Request("CalamityMod/UI/Rippers/RageBarBorder", AssetRequestMode.ImmediateLoad).Value; @@ -79,7 +79,7 @@ namespace CalamityMod.UI.Rippers Reset(); } - internal static void Unload() + public override void Unload() { Reset(); rageBarTex = rageBorderTex = rageAnimTex = null; @@ -146,7 +146,7 @@ namespace CalamityMod.UI.Rippers changed = true; } if (changed) - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } if (modPlayer.AdrenalineEnabled) @@ -165,7 +165,7 @@ namespace CalamityMod.UI.Rippers changed = true; } if (changed) - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } #region Mouse Interaction @@ -225,7 +225,7 @@ namespace CalamityMod.UI.Rippers if (ms.LeftButton == ButtonState.Released) { rageDragOffset = null; - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } } else if (adrenHover) @@ -267,7 +267,7 @@ namespace CalamityMod.UI.Rippers if (ms.LeftButton == ButtonState.Released) { adrenDragOffset = null; - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } } #endregion diff --git a/UI/SpeedrunTimerUI.cs b/UI/SpeedrunTimerUI.cs index 7835193f47..19eb113455 100644 --- a/UI/SpeedrunTimerUI.cs +++ b/UI/SpeedrunTimerUI.cs @@ -23,6 +23,7 @@ using CalamityMod.NPCs.Ravager; using CalamityMod.NPCs.Signus; using CalamityMod.NPCs.SlimeGod; using CalamityMod.NPCs.Yharon; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -32,7 +33,6 @@ using Terraria.ModLoader; namespace CalamityMod.UI { - // TODO -- Combine with SpeedrunTimerStoppingSystem, which should be renamed and call the UI draw code in this file. public class SpeedrunTimerUI { // These values put the Speedrun Timer roughly at the top center of a 1080p screen. @@ -63,10 +63,7 @@ namespace CalamityMod.UI CalamityPlayer calamityPlayer = player.Calamity(); // Main timer - string formatStr = @"hh\:mm\:ss\.ff"; - string formatStrDays = @"d\:hh\:mm\:ss\.ff"; - TimeSpan totalTime = CalamityMod.SpeedrunTimer.Elapsed.Add(calamityPlayer.previousSessionTotal); - string text = totalTime.ToString(totalTime.Days > 0 ? formatStrDays : formatStr); + string text = SpeedrunTimerSystem.GetTimerText(calamityPlayer); float scale = 2f; Utils.DrawBorderStringFourWay(Main.spriteBatch, FontAssets.MouseText.Value, text, screenPos.X, screenPos.Y, Color.White, Color.Black, default, scale); @@ -74,8 +71,7 @@ namespace CalamityMod.UI return; // Latest split - TimeSpan split = calamityPlayer.lastSplit; - text = split.ToString(split.Days > 0 ? formatStrDays : formatStr); + text = SpeedrunTimerSystem.GetSplitText(calamityPlayer); scale = 1f; float lineTwoX = screenPos.X + SplitHorizontalOffset; float lineTwoY = screenPos.Y + SplitVerticalOffset; diff --git a/UI/StealthUI.cs b/UI/StealthUI.cs index 5abcc3896f..42c9269e04 100644 --- a/UI/StealthUI.cs +++ b/UI/StealthUI.cs @@ -10,8 +10,8 @@ using static Microsoft.Xna.Framework.Input.Keys; namespace CalamityMod.UI { - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public class StealthUI + [Autoload(Side = ModSide.Client)] + public sealed class StealthUI : ModSystem { // These values were handpicked on a 1080p screen by Ozzatron. Please disregard the bizarre precision. internal const float DefaultStealthPosX = 50.104603f; @@ -21,7 +21,7 @@ namespace CalamityMod.UI private static Vector2? dragOffset = null; private static Texture2D edgeTexture, indicatorTexture, barTexture, fullBarTexture; - internal static void Load() + public override void OnModLoad() { edgeTexture = ModContent.Request("CalamityMod/UI/MiscTextures/StealthMeter", AssetRequestMode.ImmediateLoad).Value; indicatorTexture = ModContent.Request("CalamityMod/UI/MiscTextures/StealthMeterStrikeIndicator", AssetRequestMode.ImmediateLoad).Value; @@ -30,7 +30,7 @@ namespace CalamityMod.UI Reset(); } - internal static void Unload() + public override void Unload() { Reset(); edgeTexture = indicatorTexture = barTexture = fullBarTexture = null; @@ -76,7 +76,7 @@ namespace CalamityMod.UI } if (changed) - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } Rectangle mouseHitbox = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 8, 8); @@ -139,7 +139,7 @@ namespace CalamityMod.UI if (ms.LeftButton == ButtonState.Released) { dragOffset = null; - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } } } diff --git a/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs b/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs index 97a3df2f64..04b5b562da 100644 --- a/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs +++ b/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs @@ -70,7 +70,7 @@ namespace CalamityMod.UI.SulphurousWaterMeter } if (changed) - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } Rectangle mouseHitbox = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 8, 8); @@ -123,7 +123,7 @@ namespace CalamityMod.UI.SulphurousWaterMeter if (ms.LeftButton == ButtonState.Released) { dragOffset = null; - CalamityMod.SaveConfig(CalamityClientConfig.Instance); + CalamityClientConfig.SaveConfig(); } } else diff --git a/Utilities/MiscUtils.cs b/Utilities/MiscUtils.cs index 9283578090..27cb806879 100644 --- a/Utilities/MiscUtils.cs +++ b/Utilities/MiscUtils.cs @@ -39,7 +39,6 @@ namespace CalamityMod return -1; } - public static bool ChangeIngredientStack(this Recipe r, int itemID, int stack) { int idx = r.IngredientIndex(itemID); @@ -198,109 +197,6 @@ namespace CalamityMod sfx.Volume = MathHelper.Clamp(sfx.Volume * volumeMultiplier, 0f, 1f); } - public static void StartRain(bool torrentialTear = false, bool maxSeverity = false, bool worldSync = true) - { - int framesInDay = 86400; - int framesInHour = framesInDay / 24; - Main.rainTime = Main.rand.Next(framesInHour * 8, framesInDay); - if (Main.rand.NextBool(3)) - { - Main.rainTime += Main.rand.Next(0, framesInHour); - } - if (Main.rand.NextBool(4)) - { - Main.rainTime += Main.rand.Next(0, framesInHour * 2); - } - if (Main.rand.NextBool(5)) - { - Main.rainTime += Main.rand.Next(0, framesInHour * 2); - } - if (Main.rand.NextBool(6)) - { - Main.rainTime += Main.rand.Next(0, framesInHour * 3); - } - if (Main.rand.NextBool(7)) - { - Main.rainTime += Main.rand.Next(0, framesInHour * 4); - } - if (Main.rand.NextBool(8)) - { - Main.rainTime += Main.rand.Next(0, framesInHour * 5); - } - float randRainExtender = 1f; - if (Main.rand.NextBool()) - { - randRainExtender += 0.05f; - } - if (Main.rand.NextBool(3)) - { - randRainExtender += 0.1f; - } - if (Main.rand.NextBool(4)) - { - randRainExtender += 0.15f; - } - if (Main.rand.NextBool(5)) - { - randRainExtender += 0.2f; - } - Main.rainTime = (int)(Main.rainTime * randRainExtender); - Main.raining = true; - if (torrentialTear) - TorrentialTear.AdjustRainSeverity(maxSeverity); - - if (worldSync) - CalamityNetcode.SyncWorld(); - } - - public static void StopRain(bool clearWeather = false, bool worldSync = true) - { - if (clearWeather) - Main.StopRain(); - else - Main.raining = false; - - if (worldSync) - CalamityNetcode.SyncWorld(); - } - - public static void StartSandstorm() - { - if (Main.netMode != NetmodeID.MultiplayerClient && !Sandstorm.Happening) - { - // If it's not windy enough, make it windy enough for a sandstorm - // 0.6f is the minimum for vanilla but Calamity changes it to 0.2f - // Windy days occur when wind speed is at least 0.5f (0.4f in vanilla) so this should never cause a windy day - float windSpeed = 0f; - if (Main.windSpeedCurrent == 0f) - { - windSpeed = Main.rand.NextFloat(0.3f, 0.4f) * (Main.rand.Next(0, 2) * 2 - 1); - } - else if (Main.windSpeedCurrent < 0.3f && Main.windSpeedCurrent > 0f) - { - windSpeed = Main.rand.NextFloat(0.3f, 0.4f); - } - else if (Main.windSpeedCurrent > -0.3f && Main.windSpeedCurrent < 0f) - { - windSpeed = Main.rand.NextFloat(-0.4f, -0.3f); - } - if (windSpeed != 0f) - { - Main.windSpeedCurrent = windSpeed < 0f ? -0.3f : 0.3f; - Main.windSpeedTarget = windSpeed; - } - Sandstorm.StartSandstorm(); - } - } - - public static void StopSandstorm() - { - if (Main.netMode != NetmodeID.MultiplayerClient && Sandstorm.Happening) - { - Sandstorm.StopSandstorm(); - } - } - public static void AddWithCondition(this List list, T type, bool condition) { if (condition) diff --git a/Utilities/NPCUtils.cs b/Utilities/NPCUtils.cs index a5ec20c2dd..77b8af6dbd 100644 --- a/Utilities/NPCUtils.cs +++ b/Utilities/NPCUtils.cs @@ -809,6 +809,63 @@ namespace CalamityMod } } + public static bool DrawAnimatedBestiaryWorm(SpriteBatch spriteBatch, NPC npc, Color drawColor, Texture2D headTexture, Texture2D bodyTexture, int segmentCount, int segmentSpacing, float rotationStrength, Vector2 baseOffset, int animationSpeed, float range, float headOffset = 0, float headSpeedOffset = 0, bool flip = false) + { + DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, headTexture, [bodyTexture], segmentCount, segmentSpacing, rotationStrength, baseOffset, animationSpeed, range, headOffset, headSpeedOffset, flip); + return false; + } + + public static bool DrawAnimatedBestiaryWorm(SpriteBatch spriteBatch, NPC npc, Color drawColor, Texture2D headTexture, Texture2D bodyTexture, Texture2D bodyTextureAlt, int segmentCount, int segmentSpacing, float rotationStrength, Vector2 baseOffset, int animationSpeed, float range, float headOffset = 0, float headSpeedOffset = 0, bool flip = false) + { + DrawAnimatedBestiaryWorm(spriteBatch, npc, drawColor, headTexture, [bodyTexture, bodyTextureAlt], segmentCount, segmentSpacing, rotationStrength, baseOffset, animationSpeed, range, headOffset, headSpeedOffset, flip); + return false; + } + + /// + /// Draws animated wiggly worms for the Bestiary + /// + /// The PreDraw's SpriteBatch + /// The NPC to draw + /// The NPC's drawColor + /// The worm's head texture + /// The worm's body textures + /// The amount of segments that should be added + /// The spacing between segments + /// How strongly the worm rotates. Higher values cause it to make sharper turns + /// Moves around the position of the worm + /// How fast the worm moves + /// How far up and down the worm moves + /// How far to bash (move) the head horizontally in case the automated math is too off or the worm's head extends past its neck joint + /// Offsets the animation progression for the head. Meant to pair with headOffset + /// If the sprites should be flipped. Used for worms viewed from the side like Wyverns + /// + public static bool DrawAnimatedBestiaryWorm(SpriteBatch spriteBatch, NPC npc, Color drawColor, Texture2D headTexture, Texture2D[] bodyTextures, int segmentCount, int segmentSpacing, float rotationStrength, Vector2 baseOffset, int animationSpeed, float range, float headOffset = 0, float headSpeedOffset = 0, bool flip = false) + { + npc.frame = headTexture.Frame(); + // Buffers the segment position and rotations + float offset = -0.2f; + float startX = baseOffset.X; + float startY = baseOffset.Y; + SpriteEffects fx = flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None; + float wormTimer = npc.Calamity().bestiaryWormTimer; + // Draw the body segments + for (int i = segmentCount; i > 0; i--) + { + // The first segment is slightly closer to keep up with the head + float bodyOffset = i == 1 ? i * segmentSpacing * 0.4f : i * segmentSpacing - segmentSpacing * 0.5f; + + // If there's only one texture passed in, use it for all segments + // If two are passed in, alternate between them + // If more are passed in, each iteration must correspond to a texture + Texture2D toUse = bodyTextures.Length == 1 ? bodyTextures[0] : bodyTextures.Length == 2 ? (i % 2 == 0 ? bodyTextures[0] : bodyTextures[1]) : bodyTextures[i - 1]; + spriteBatch.Draw(toUse, npc.position + new Vector2(startX + bodyOffset, MathF.Sin((wormTimer + offset * i) * animationSpeed) * range + startY), toUse.Frame(1, 1, 0, 0), npc.GetAlpha(drawColor), npc.rotation - MathHelper.PiOver2 - MathF.Cos((wormTimer + offset * i) * animationSpeed) * MathHelper.PiOver4 * rotationStrength, toUse.Size () / 2, npc.scale, fx, 0f); + } + // Draw the head + spriteBatch.Draw(headTexture, npc.position + new Vector2(startX + headOffset, MathF.Sin((wormTimer - headSpeedOffset) * animationSpeed) * range + startY), npc.frame, npc.GetAlpha(drawColor), npc.rotation - MathHelper.PiOver2 - MathF.Cos((wormTimer - headSpeedOffset) * animationSpeed) * MathHelper.PiOver4 * rotationStrength, new Vector2(headTexture.Width * 0.5f, headTexture.Height), npc.scale, fx, 0f); + + return false; + } + #region Boss Spawning /// /// Shortcut for the generic boss summon message. @@ -824,7 +881,7 @@ namespace CalamityMod } else if (Main.netMode == NetmodeID.Server) { - ChatHelper.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[] { Main.npc[npcIndex].GetTypeNetName() }), new Color(175, 75, 255)); + ChatHelper.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", [Main.npc[npcIndex].GetTypeNetName()]), new Color(175, 75, 255)); } } diff --git a/Utilities/ReflectionHelper.cs b/Utilities/ReflectionHelper.cs index cad3cd63bd..e1aff58a66 100644 --- a/Utilities/ReflectionHelper.cs +++ b/Utilities/ReflectionHelper.cs @@ -6,6 +6,10 @@ using System.Reflection.Emit; using System.Text; using System.Threading.Tasks; using Terraria.GameContent; +using Terraria.ModLoader.Core; +using Terraria.ModLoader; +using System.Collections; +using CalamityMod.Particles; namespace CalamityMod { @@ -58,5 +62,49 @@ namespace CalamityMod return (Func)getterMethod.CreateDelegate(typeof(Func)); } + + public static IEnumerable GetEveryModsTypes() + { + return ModLoader.Mods.SelectMany(mod => AssemblyManager.GetLoadableTypes(mod.Code)); + } + + public static void IterateEveryModsTypes(bool includeBaseType = false, Action action = null) + { + // WHY???? + if (action is null) + return; + + Type baseType = typeof(T); + var types = GetEveryModsTypes(); + foreach (var type in types) + { + if (type.IsSubclassOf(baseType) && !type.IsAbstract && (!includeBaseType && type != baseType)) + { + action.Invoke(type); + } + } + } + + public static IEnumerable GetCalamityTypes() + { + return AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code); + } + + public static void IterateCalamityTypes(bool includeBaseType = false, Action action = null) + { + // WHY???? + if (action is null) + return; + + Type baseType = typeof(T); + var types = GetCalamityTypes(); + foreach (var type in types) + { + if (type.IsSubclassOf(baseType) && !type.IsAbstract && (!includeBaseType && type != baseType)) + { + action.Invoke(type); + } + } + } } } diff --git a/Utilities/TileUtils.cs b/Utilities/TileUtils.cs index 9877c9d708..9f9685e2df 100644 --- a/Utilities/TileUtils.cs +++ b/Utilities/TileUtils.cs @@ -317,9 +317,11 @@ namespace CalamityMod // Extension shorthand for the Tile Framing System Universal Merges. // As this must be defined in a static class, it's out here in CalamityUtils. + [Obsolete("Use TileBlendMergeSystem.RegisterMerge Instead")] public static void RegisterUniversalMerge(this ModTile tile, int mergeType, string blendSheetPath) { - TileFramingSystem.RegisterUniversalMerge(tile.Type, mergeType, blendSheetPath); + //TileFramingSystem.RegisterUniversalMerge(tile.Type, mergeType, blendSheetPath); + TileBlendMergeSystem.RegisterMerge(tile.Type, mergeType); } /// @@ -387,6 +389,7 @@ namespace CalamityMod TileType(), TileType(), TileType(), + TileType(), }); /// @@ -559,6 +562,7 @@ namespace CalamityMod SetMerge(type, TileID.MarbleBlock); SetMerge(type, TileID.GraniteBlock); //Calam + SetMerge(type, TileType()); SetMerge(type, TileType()); SetMerge(type, TileType()); SetMerge(type, TileType()); diff --git a/Utilities/WorldgenUtils.cs b/Utilities/WorldgenUtils.cs index 508f5595f1..f8162760c3 100644 --- a/Utilities/WorldgenUtils.cs +++ b/Utilities/WorldgenUtils.cs @@ -216,7 +216,7 @@ namespace CalamityMod paddedArea.Inflate(padding, padding); // If Fargo's Mutant Mod is loaded, add to their Indestructible Rectangle list, which prevents structures from being trashed by Fargo's terrain tools. - Mod fargos = CalamityMod.Instance.fargos; + Mod fargos = ExternalMods.fargos; fargos?.Call("AddIndestructibleRectangle", paddedArea); } } diff --git a/World/AstralBiome.cs b/World/AstralBiome.cs index b38c4b12b4..5b99807bfe 100644 --- a/World/AstralBiome.cs +++ b/World/AstralBiome.cs @@ -75,7 +75,7 @@ namespace CalamityMod.World public static void PlaceAstralMeteor() { - Mod ancientsAwakened = CalamityMod.Instance.ancientsAwakened; + Mod ancientsAwakened = ExternalMods.ancientsAwakened; // This flag is also used to determine whether players are nearby. bool meteorDropped = true; @@ -222,7 +222,7 @@ namespace CalamityMod.World // Pre-cache a list of Magic Storage tiles to avoid, for performance reasons // It is plausible that only StorageComponent and StorageConnector are needed, but I aint gonna risk corrupting worlds // or crashes as containers can do some serious shit as seen with the Abyss chests - Shade - Mod magicStorage = CalamityMod.Instance.magicStorage; + Mod magicStorage = ExternalMods.magicStorage; IList MSTilesToAvoid = new List(16); if (magicStorage is not null) { diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index 731bba40fd..1f481d23c4 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -1,4 +1,5 @@ using System.Reflection; +using CalamityMod.Items.Tools.ClimateChange; using CalamityMod.NPCs.ExoMechs; using CalamityMod.NPCs.ExoMechs.Apollo; using CalamityMod.NPCs.ExoMechs.Ares; @@ -7,7 +8,10 @@ using CalamityMod.NPCs.ExoMechs.Thanatos; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; +using Terraria.GameContent.Events; +using Terraria.ID; using Terraria.ModLoader; +using Terraria.Utilities; namespace CalamityMod.World { @@ -98,5 +102,121 @@ namespace CalamityMod.World public static Vector2 CavernLabCenter; #endregion + + #region Rain Utils + public static void StartRain(bool adjustSeverity = false, bool maxSeverity = false, bool worldSync = true) + { + int framesInDay = 86400; + int framesInHour = framesInDay / 24; + Main.rainTime = Main.rand.Next(framesInHour * 8, framesInDay); + if (Main.rand.NextBool(3)) + { + Main.rainTime += Main.rand.Next(0, framesInHour); + } + if (Main.rand.NextBool(4)) + { + Main.rainTime += Main.rand.Next(0, framesInHour * 2); + } + if (Main.rand.NextBool(5)) + { + Main.rainTime += Main.rand.Next(0, framesInHour * 2); + } + if (Main.rand.NextBool(6)) + { + Main.rainTime += Main.rand.Next(0, framesInHour * 3); + } + if (Main.rand.NextBool(7)) + { + Main.rainTime += Main.rand.Next(0, framesInHour * 4); + } + if (Main.rand.NextBool(8)) + { + Main.rainTime += Main.rand.Next(0, framesInHour * 5); + } + float randRainExtender = 1f; + if (Main.rand.NextBool()) + { + randRainExtender += 0.05f; + } + if (Main.rand.NextBool(3)) + { + randRainExtender += 0.1f; + } + if (Main.rand.NextBool(4)) + { + randRainExtender += 0.15f; + } + if (Main.rand.NextBool(5)) + { + randRainExtender += 0.2f; + } + Main.rainTime = (int)(Main.rainTime * randRainExtender); + Main.raining = true; + if (adjustSeverity) + TorrentialTear.AdjustRainSeverity(maxSeverity); + + if (worldSync) + CalamityNetcode.SyncWorld(); + } + + public static void StopRain(bool clearWeather = false, bool worldSync = true) + { + if (clearWeather) + Main.StopRain(); + else + Main.raining = false; + + if (worldSync) + CalamityNetcode.SyncWorld(); + } + #endregion + + #region Sandstorm Utils + public static void StartSandstorm() + { + if (Main.netMode != NetmodeID.MultiplayerClient && !Sandstorm.Happening) + { + // If it's not windy enough, make it windy enough for a sandstorm + // 0.6f is the minimum for vanilla but Calamity changes it to 0.2f + // Windy days occur when wind speed is at least 0.5f (0.4f in vanilla) so this should never cause a windy day + float windSpeed = 0f; + if (Main.windSpeedCurrent == 0f) + { + windSpeed = Main.rand.NextFloat(0.3f, 0.4f) * (Main.rand.Next(0, 2) * 2 - 1); + } + else if (Main.windSpeedCurrent < 0.3f && Main.windSpeedCurrent > 0f) + { + windSpeed = Main.rand.NextFloat(0.3f, 0.4f); + } + else if (Main.windSpeedCurrent > -0.3f && Main.windSpeedCurrent < 0f) + { + windSpeed = Main.rand.NextFloat(-0.4f, -0.3f); + } + if (windSpeed != 0f) + { + Main.windSpeedCurrent = windSpeed < 0f ? -0.3f : 0.3f; + Main.windSpeedTarget = windSpeed; + } + Sandstorm.StartSandstorm(); + } + } + + public static void StopSandstorm() + { + if (Main.netMode != NetmodeID.MultiplayerClient && Sandstorm.Happening) + { + Sandstorm.StopSandstorm(); + } + } + #endregion + + #region Time Utils + public static void ResetTime(bool changeToDay) + { + Main.time = 0D; + Main.dayTime = changeToDay; + CalamityNetcode.SyncWorld(); + } + #endregion } } diff --git a/World/DraedonStructures.cs b/World/DraedonStructures.cs index 69a981f3fc..22e924564b 100644 --- a/World/DraedonStructures.cs +++ b/World/DraedonStructures.cs @@ -568,7 +568,7 @@ namespace CalamityMod.World contents.Insert(8, new ChestItem(ItemID.CrimsonPlanterBox, WorldGen.genRand.Next(5, 9 + 1))); // Add Thorium Marine Kelp if Thorium is loaded. - Mod thorium = CalamityMod.Instance.thorium; + Mod thorium = ExternalMods.thorium; if (thorium is not null) { var marineKelpPlanterBox = thorium.Find("MarineKelpPlanterBox"); diff --git a/World/Planets/Planetoid.cs b/World/Planets/Planetoid.cs index 90d5bcd15f..5e9684fb5b 100644 --- a/World/Planets/Planetoid.cs +++ b/World/Planets/Planetoid.cs @@ -103,7 +103,7 @@ namespace CalamityMod.World.Planets public static bool InvalidSkyPlacementArea(Rectangle area) { - Mod varia = CalamityMod.Instance.varia; + Mod varia = ExternalMods.varia; for (int i = area.Left; i < area.Right; i++) { for (int j = area.Top; j < area.Bottom; j++)