diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 6bacb6fc1e..6626872f28 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -219,10 +219,6 @@ namespace CalamityMod.Effects /// internal static Asset DozeLightingShader; /// - /// Flips the screen. Used for Gravity Globe. - /// - internal static Asset FlipScreenShader; - /// /// Distorts a texture towards the center based on a provided noisemap. Meant to emulate the Terraria Otherworld barrier effects. /// Opacity is the intensity of this distortion, and Saturation is the speed the noisemap moves at. /// @@ -501,9 +497,6 @@ namespace CalamityMod.Effects DozeLightingShader = LoadShader("DozeLightingShader"); RegisterMiscShader(DozeLightingShader, "ShadowPass", "DozeLightingShader"); - FlipScreenShader = LoadShader("ScreenShaders/FlipScreen"); - RegisterScreenShader(FlipScreenShader, "FlipTheScreen", "FlipScreen",EffectPriority.VeryHigh); - OtherworldBarrierDistortionShader = LoadShader("OtherworldBarrierDistortion"); RegisterMiscShader(OtherworldBarrierDistortionShader, "DistortionPass", "OtherworldBarrierDistortion"); #endregion diff --git a/Effects/ScreenShaders/FlipScreen.fx b/Effects/ScreenShaders/FlipScreen.fx deleted file mode 100644 index 39ad44126c..0000000000 --- a/Effects/ScreenShaders/FlipScreen.fx +++ /dev/null @@ -1,38 +0,0 @@ -sampler uImage0 : register(s0); -sampler uImage1 : register(s1); -sampler uImage2 : register(s2); -sampler uImage3 : register(s3); -float3 uColor; -float3 uSecondaryColor; -float2 uScreenResolution; -float2 uScreenPosition; -float2 uTargetPosition; -float2 uDirection; -float uOpacity; -float uTime; -float uIntensity; -float uProgress; -float2 uImageSize1; -float2 uImageSize2; -float2 uImageSize3; -float2 uImageOffset; -float uSaturation; -float4 uSourceRect; -float2 uZoom; - -float4 FilterMyShader(float2 coords : TEXCOORD0) : COLOR0 -{ - float2 newCoords; - newCoords.x = coords.x; - newCoords.y = 1 - coords.y; - float4 color = tex2D(uImage0, newCoords); - return color; -} - -technique Technique1 -{ - pass FlipTheScreen - { - PixelShader = compile ps_2_0 FilterMyShader(); - } -} \ No newline at end of file diff --git a/Effects/ScreenShaders/FlipScreen.xnb b/Effects/ScreenShaders/FlipScreen.xnb deleted file mode 100644 index 842a5d7873..0000000000 Binary files a/Effects/ScreenShaders/FlipScreen.xnb and /dev/null differ diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 93c842f281..41e3ff9dc0 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -173,11 +173,6 @@ namespace CalamityMod.ILEditing IL_Main.DrawInfoAccs += RemoveDamageConditionFromRadar; //On_ShopHelper.ApplyNpcRelationshipEffect += AllowMultipleLikedNPCs; - On_Player.UpdateControlHolds += DelayGravity; - On_PlayerInput.SetZoom_MouseInWorld += GravityMouse; - On_Main.DrawPlayerChatBubbles += UI_Unflip_Start; - On_Main.DrawInterface += UI_Unflip_End; - // Fix vanilla not accounting for spritebatch modification in held projectile drawing On_PlayerDrawLayers.DrawHeldProj += FixHeldProjectileBlendState; diff --git a/ILEditing/VanillaStupidityFixingILChanges.cs b/ILEditing/VanillaStupidityFixingILChanges.cs index 8bf0bb5c8e..d38654671b 100644 --- a/ILEditing/VanillaStupidityFixingILChanges.cs +++ b/ILEditing/VanillaStupidityFixingILChanges.cs @@ -18,7 +18,9 @@ using Terraria.DataStructures; using Terraria.GameContent.Drawing; using Terraria.GameContent.ItemDropRules; using Terraria.GameInput; +using Terraria.Graphics; using Terraria.Graphics.Effects; +using Terraria.Graphics.Renderers; using Terraria.ID; using Terraria.ModLoader; @@ -713,103 +715,6 @@ namespace CalamityMod.ILEditing }*/ #endregion - #region Allow Disabling Gravity Swap Visual and Allow Gravity Keybind - private static void DelayGravity(On_Player.orig_UpdateControlHolds orig, Player Player) - { - var cplay = Player.Calamity(); - if (CalamityKeybinds.SwitchGravityHotkey.GetAssignedKeysOrEmpty().Count != 0 && (Player.gravControl || Player.gravControl2) && !Player.mount.Active) - { - if (Player.controlUp && Player.releaseUp) - { - Player.gravDir *= -1; - } - if (CalamityKeybinds.SwitchGravityHotkey.JustPressed) - { - Player.gravDir *= -1; - Player.fallStart = (int)(Player.position.Y / 16f); - Player.jump = 0; - SoundEngine.PlaySound(SoundID.Item8, Player.position); - } - - if (Player.forcedGravity > 0) - { - Player.gravDir = -1f; - } - } - - if (cplay.justChangedGravity) - { - Player.gravDir = cplay.oldGravDir; - } - cplay.justChangedGravity = cplay.oldGravDir != Player.gravDir; - - cplay.oldGravDir = Player.gravDir; - if (!Main.dedServ && !Main.gameMenu && CalamityClientConfig.Instance.DisableGravityScreenSwap) - { - if (Player.gravDir == -1) - { - if (!Filters.Scene["CalamityMod:FlipScreen"].IsActive()) - { - Filters.Scene.Activate("CalamityMod:FlipScreen"); - Filters.Scene["CalamityMod:FlipScreen"].Opacity = 1f; - - } - } - else - { - if (Filters.Scene["CalamityMod:FlipScreen"].IsActive()) - { - Filters.Scene["CalamityMod:FlipScreen"].Opacity = 0f; - Filters.Scene.Deactivate("CalamityMod:FlipScreen"); - - } - } - } - if (!Main.dedServ && !CalamityClientConfig.Instance.DisableGravityScreenSwap) - { - if (Filters.Scene["CalamityMod:FlipScreen"].IsActive()) - { - Filters.Scene["CalamityMod:FlipScreen"].Opacity = 0f; - Filters.Scene.Deactivate("CalamityMod:FlipScreen"); - } - } - if (cplay.justChangedGravity) - { - Player.gravDir *= -1; - } - orig(Player); - } - - private static void GravityMouse(On_PlayerInput.orig_SetZoom_MouseInWorld orig) - { - orig(); - if (!Main.gameMenu && Filters.Scene["CalamityMod:FlipScreen"].IsActive())//((Main.LocalPlayer.gravDir == -1 && !Main.LocalPlayer.Calamity().justChangedGravity) || (Main.LocalPlayer.Calamity().oldGravDir == -1 && Main.LocalPlayer.Calamity().justChangedGravity)) - { - var center = Main.screenHeight / 2; - Main.mouseY = center - (Main.mouseY - center); - } - ; - } - private static void UI_Unflip_Start(On_Main.orig_DrawPlayerChatBubbles orig, Main self) - { - if (!Main.gameMenu && (Filters.Scene["CalamityMod:FlipScreen"].IsActive() || Main.LocalPlayer.Calamity().justChangedGravity)) - { - Main.LocalPlayer.Calamity().tempGravDir = Main.LocalPlayer.gravDir; - Main.LocalPlayer.gravDir = 1; - } - orig(self); - } - - private static void UI_Unflip_End(On_Main.orig_DrawInterface orig, Main self, GameTime gameTime) - { - orig(self, gameTime); - if (!Main.gameMenu && Filters.Scene["CalamityMod:FlipScreen"].IsActive()) - { - Main.LocalPlayer.gravDir = Main.LocalPlayer.Calamity().tempGravDir; - } - } - #endregion - // 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)] diff --git a/NPCs/BaseWormNPC.cs b/NPCs/BaseWormNPC.cs index f37a581f3d..15401cd837 100644 --- a/NPCs/BaseWormNPC.cs +++ b/NPCs/BaseWormNPC.cs @@ -645,6 +645,11 @@ namespace CalamityMod.NPCs //The segments near a player spawn a hitbox NPC to allow damaging players and taking damage public abstract class BaseWormHitboxNPC : ModNPC { + public override void SetStaticDefaults() + { + this.HideFromBestiary(); + } + public override void SetDefaults() { NPC.width = 200; diff --git a/NPCs/Deconstructors/Burrower.cs b/NPCs/Deconstructors/Burrower.cs index 9e83c3b69c..cedac1aebe 100644 --- a/NPCs/Deconstructors/Burrower.cs +++ b/NPCs/Deconstructors/Burrower.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Effects; @@ -23,6 +24,7 @@ using Terraria.ModLoader; using Terraria.ModLoader.Utilities; namespace CalamityMod.NPCs.Deconstructors { + [LongDistanceNetSync(SyncWith = typeof(Burrower))] public class BurrowerHitbox : BaseWormHitboxNPC { public override LocalizedText DisplayName => CalamityUtils.GetText("NPCs.Burrower.DisplayName"); @@ -58,13 +60,19 @@ namespace CalamityMod.NPCs.Deconstructors public override void AI() { base.AI(); - var headNPC = Main.npc[(int)NPC.ai[0]]; - NPC.Calamity().DR = headNPC.Calamity().DR; - NPC.HitSound = headNPC.HitSound; + if (Main.npc.IndexInRange((int)NPC.ai[0])) + { + NPC headNPC = Main.npc[(int)NPC.ai[0]]; + NPC.Calamity().DR = headNPC.Calamity().DR; + NPC.HitSound = headNPC.HitSound; + } + NPC.width = 38; NPC.height = 38; } } + + [LongDistanceNetSync] public class Burrower : BaseWormNPC { public override string Texture => "CalamityMod/NPCs/Deconstructors/DeconstructorMK1Head"; @@ -174,23 +182,22 @@ namespace CalamityMod.NPCs.Deconstructors set { NPC.ai[2] = value; } } - public float StateChangeCounter - { - get { return NPC.ai[3]; } - set { NPC.ai[3] = value; } - } - public float VelocityRotation - { - - get { return NPC.velocity.ToRotation(); } - set { NPC.velocity = value.ToRotationVector2() * NPC.velocity.Length(); } - } - public Vector2 TargetVector = Vector2.Zero; public Vector2 SecondaryVector = Vector2.Zero; - public float StoredValue = 0; #endregion + public override void SendExtraAI(BinaryWriter writer) + { + writer.WriteVector2(TargetVector); + writer.WriteVector2(SecondaryVector); + } + + public override void ReceiveExtraAI(BinaryReader reader) + { + TargetVector = reader.ReadVector2(); + SecondaryVector = reader.ReadVector2(); + } + public void SwitchAttackState(AttackState State, float Substate = 0, bool resetVector = true) { ActiveAttackState = State; @@ -198,15 +205,11 @@ namespace CalamityMod.NPCs.Deconstructors MainTimer = 0; if (resetVector) TargetVector = Vector2.Zero; + NPC.ForceNetUpdate(); } public override void AI() { - //Force burrower bestiary to unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } HandleAIStates(); MainTimer++; UpdateSegments(); @@ -316,9 +319,12 @@ namespace CalamityMod.NPCs.Deconstructors public void HandleAIStates() { - NPC.CalamityTargeting(CalamityTargetingParameters.BossDefaults); if (!NPC.HasValidTarget) + { + NPC.CalamityTargeting(CalamityTargetingParameters.BossDefaults); return; + } + Player player = Main.player[NPC.target]; SegmentMaxRotation = 0.65f; SegmentRigidity = 0.2f; @@ -356,9 +362,11 @@ namespace CalamityMod.NPCs.Deconstructors veins.Remove(targetVein); } } + TargetVector = player.Center + Main.rand.NextVector2Circular(800, 800); LowerTargetToGround(); MainTimer = 0; + NPC.netUpdate = true; } if (AttackSubstate <= 0 && noGravity) { diff --git a/NPCs/DraedonLabThings/Androomba.cs b/NPCs/DraedonLabThings/Androomba.cs index 90182bcdaa..4d4db9b7c9 100644 --- a/NPCs/DraedonLabThings/Androomba.cs +++ b/NPCs/DraedonLabThings/Androomba.cs @@ -151,12 +151,6 @@ namespace CalamityMod.NPCs.DraedonLabThings } break; } - - // Force bestiary unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } } public void ChangeAI(int phase) diff --git a/NPCs/DraedonLabThings/RepairUnitCritter.cs b/NPCs/DraedonLabThings/RepairUnitCritter.cs index a3c7bcb9c1..cbd39311c1 100644 --- a/NPCs/DraedonLabThings/RepairUnitCritter.cs +++ b/NPCs/DraedonLabThings/RepairUnitCritter.cs @@ -137,13 +137,8 @@ namespace CalamityMod.NPCs.DraedonLabThings break; } Time++; - - // Force bestiary unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } } + public override bool? CanFallThroughPlatforms() => CurrentState == BehaviorState.WalkOnWalls; public void WalkAroundOnGround() diff --git a/NPCs/NormalNPCs/DivineSwine.cs b/NPCs/NormalNPCs/DivineSwine.cs index ee698f3b0b..9dfea10249 100644 --- a/NPCs/NormalNPCs/DivineSwine.cs +++ b/NPCs/NormalNPCs/DivineSwine.cs @@ -74,7 +74,7 @@ namespace CalamityMod.NPCs.NormalNPCs public Vector2 IdleMovementVector; - public SlotId SwineSpeakSoundSlot; + public SlotId SwineSpeakSoundSlot = SlotId.Invalid; public static float MaxSpeed => 0.38f; public static float MaxAcceleration => 0.06f; @@ -118,7 +118,7 @@ namespace CalamityMod.NPCs.NormalNPCs Main.npcFrameCount[Type] = 14; NPCID.Sets.CountsAsCritter[Type] = true; NPCID.Sets.CantTakeLunchMoney[Type] = true; - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); NPCID.Sets.ImmuneToAllBuffs[Type] = true; NPCID.Sets.ShimmerImmunity[Type] = true; } @@ -128,7 +128,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.damage = 0; NPC.width = 32; NPC.height = 34; - NPC.lifeMax = 5; + NPC.lifeMax = 99999999; NPC.defense = 99999999; NPC.rarity = 5; NPC.aiStyle = -1; @@ -305,6 +305,8 @@ namespace CalamityMod.NPCs.NormalNPCs if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out ActiveSound swineSpeakInstance)) swineSpeakInstance.Stop(); + if (SwineSpeakSoundSlot.IsValid) + SwineSpeakSoundSlot = SlotId.Invalid; NPC.Transform(ModContent.NPCType()); } @@ -443,6 +445,8 @@ namespace CalamityMod.NPCs.NormalNPCs if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out ActiveSound swineSpeakInstance)) swineSpeakInstance.Stop(); + if (SwineSpeakSoundSlot.IsValid) + SwineSpeakSoundSlot = SlotId.Invalid; // Despawn immediately afterwards. NPC.checkDead(); @@ -482,6 +486,8 @@ namespace CalamityMod.NPCs.NormalNPCs if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out ActiveSound swineSpeakInstance)) swineSpeakInstance.Stop(); + if (SwineSpeakSoundSlot.IsValid) + SwineSpeakSoundSlot = SlotId.Invalid; NPC.checkDead(); NPC.active = false; @@ -616,6 +622,14 @@ namespace CalamityMod.NPCs.NormalNPCs SwineSpeakSoundSlot = SoundEngine.PlaySound(MisophoniaSwineSpeakLoopingSound, NPC.Center, SoundCallbackMethod); } + if (!NPC.active) + { + if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out ActiveSound swineSpeakInstance)) + swineSpeakInstance.Stop(); + if (SwineSpeakSoundSlot.IsValid) + SwineSpeakSoundSlot = SlotId.Invalid; + } + // Fade the music depending on the distance between the player and Divine Swine. float musicVolumeInterpolant = Utils.Remap(NPC.Distance(Main.LocalPlayer.Center), 600f, 100f, 1f, 0.2f, true); Main.musicFade[Main.curMusic] = musicVolumeInterpolant; @@ -812,6 +826,7 @@ namespace CalamityMod.NPCs.NormalNPCs Effect tintShader = CalamityShaders.BasicTintShader.Value; tintShader.Parameters["uColor"].SetValue(Color.White.ToVector3()); tintShader.Parameters["uOpacity"].SetValue(DivineSwineTintStrength); + tintShader.Parameters["uSaturation"].SetValue(NPC.Opacity); spriteBatch.EnterShaderRegion(effect: tintShader); spriteBatch.Draw(baseTexture, drawPosition, NPC.frame, NPC.GetAlpha(Color.White), NPC.rotation, NPC.frame.Size() * 0.5f, SquashVector * NPC.scale, spriteEffects, 0f); diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.Drawing.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.Drawing.cs index 5235c05262..7388ebba0a 100644 --- a/NPCs/NormalNPCs/HorribleHog/HorribleHog.Drawing.cs +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.Drawing.cs @@ -149,6 +149,8 @@ namespace CalamityMod.NPCs.NormalNPCs.HorribleHog Effect tintShader = CalamityShaders.BasicTintShader.Value; tintShader.Parameters["uColor"].SetValue(TintColor.ToVector3()); tintShader.Parameters["uOpacity"].SetValue(TintStrength); + tintShader.Parameters["uSaturation"].SetValue(NPC.Opacity); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, tintShader, Main.GameViewMatrix.TransformationMatrix); spriteBatch.Draw(lease.Target, Vector2.Zero, Color.White); spriteBatch.End(); diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs index b04feae8ff..3abb8efdd0 100644 --- a/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.cs @@ -128,11 +128,11 @@ namespace CalamityMod.NPCs.NormalNPCs.HorribleHog public Color TintColorTarget; - public SlotId DeathLaughSoundSlot; + public SlotId DeathLaughSoundSlot = SlotId.Invalid; - public SlotId DiggingSoundSlot; + public SlotId DiggingSoundSlot = SlotId.Invalid; - public SlotId DevilsTongueSlot; + public SlotId DevilsTongueSlot = SlotId.Invalid; #region Static Behavior Properties public static int MaxAttacks_ChasePlayer => 2; @@ -437,6 +437,25 @@ namespace CalamityMod.NPCs.NormalNPCs.HorribleHog break; } + // Disable all active sounds if Hog despawns. + if (!NPC.active) + { + if (SoundEngine.TryGetActiveSound(DevilsTongueSlot, out ActiveSound devilsTongue)) + devilsTongue.Stop(); + if (DevilsTongueSlot.IsValid) + DevilsTongueSlot = SlotId.Invalid; + + if (SoundEngine.TryGetActiveSound(DiggingSoundSlot, out ActiveSound digging)) + digging.Stop(); + if (DiggingSoundSlot.IsValid) + DiggingSoundSlot = SlotId.Invalid; + + if (SoundEngine.TryGetActiveSound(DeathLaughSoundSlot, out ActiveSound deathLaugh)) + deathLaugh.Stop(); + if (DeathLaughSoundSlot.IsValid) + DeathLaughSoundSlot = SlotId.Invalid; + } + SquashVector = Vector2.Lerp(SquashVector, SquashVectorTarget, 0.125f); EyeGlintScale = MathHelper.Lerp(EyeGlintScale, 0f, 0.125f); TintColor = Color.Lerp(TintColor, TintColorTarget, 0.125f); @@ -647,6 +666,7 @@ namespace CalamityMod.NPCs.NormalNPCs.HorribleHog { if (SoundEngine.TryGetActiveSound(DevilsTongueSlot, out ActiveSound sound)) sound.Stop(); + DevilsTongueSlot = SlotId.Invalid; return; } diff --git a/NPCs/NormalNPCs/Piggy.cs b/NPCs/NormalNPCs/Piggy.cs index 825c692c0c..d6b6b79140 100644 --- a/NPCs/NormalNPCs/Piggy.cs +++ b/NPCs/NormalNPCs/Piggy.cs @@ -1,9 +1,6 @@ using System; -using System.Security.Policy; -using CalamityMod.Effects; using CalamityMod.Items.Critters; using CalamityMod.Items.Placeables.Banners; -using CalamityMod.NPCs.NormalNPCs.HorribleHog; using CalamityMod.Particles; using CalamityMod.Systems.Graphic.PixelationSystem; using CalamityMod.Utilities.Daybreak; @@ -14,7 +11,6 @@ using ReLogic.Content; using ReLogic.Utilities; using Terraria; using Terraria.Audio; -using Terraria.DataStructures; using Terraria.GameContent; using Terraria.GameContent.Bestiary; using Terraria.ID; @@ -79,7 +75,7 @@ namespace CalamityMod.NPCs.NormalNPCs public Vector2 SquashVector; - public SlotId NearbySoundSlot; + public SlotId NearbySoundSlot = SlotId.Invalid; public static float MaxAcceleration_Walking => 0.035f; public static float MaxAcceleration_Running => 0.085f; @@ -110,7 +106,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPCID.Sets.CountsAsCritter[Type] = true; NPCID.Sets.CantTakeLunchMoney[Type] = true; NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true; - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); } public override void SetDefaults() @@ -146,10 +142,6 @@ namespace CalamityMod.NPCs.NormalNPCs public override void AI() { - // Force bestiary cause this doesn't count as Vanilla's definition of a critter for the Bestiary. - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - Main.BestiaryTracker.Kills.SetKillCountDirectly(NPC.GetBestiaryCreditId(), 100); - if (NPC.direction == 0) NPC.direction = Utils.SelectRandom(Main.rand, -1, 1); @@ -173,7 +165,6 @@ namespace CalamityMod.NPCs.NormalNPCs } NPC.StepUpBlocks(); - SquashVector = Vector2.Lerp(SquashVector, Vector2.One, 0.125f); Timer++; } @@ -183,13 +174,10 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.velocity.X *= 0.9f; NPC.rotation = 0f; - if (Timer < 2 && !SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) { if (!CalamityClientConfig.Instance.MisophoniaSupport) - { NearbySoundSlot = SoundEngine.PlaySound(DivineSwine_SwineSpeakLoopingSound, NPC.Center, NearbySoundCallbackMethod); - } else NearbySoundSlot = SoundEngine.PlaySound(DivineSwine_MisophoniaSwineSpeakLoopingSound, NPC.Center, NearbySoundCallbackMethod); } @@ -253,6 +241,8 @@ namespace CalamityMod.NPCs.NormalNPCs SoundEngine.PlaySound(DivineSwine_CoinFailSound, NPC.Center); if (SoundEngine.TryGetActiveSound(NearbySoundSlot, out var activeSound)) activeSound.Stop(); + if (NearbySoundSlot.IsValid) + NearbySoundSlot = SlotId.Invalid; NPC.Transform(ModContent.NPCType()); } @@ -266,9 +256,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (Timer < 2 && !SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) { if (!CalamityClientConfig.Instance.MisophoniaSupport) - { NearbySoundSlot = SoundEngine.PlaySound(HorribleHog_DevilsTongueLoopingSound, NPC.Center, NearbySoundCallbackMethod); - } else NearbySoundSlot = SoundEngine.PlaySound(HorribleHog_MisophoniaDevilsTongueLoopingSound, NPC.Center, NearbySoundCallbackMethod); } @@ -293,6 +281,8 @@ namespace CalamityMod.NPCs.NormalNPCs SoundEngine.PlaySound(HorribleHog_CackleSound, NPC.Center); if (SoundEngine.TryGetActiveSound(NearbySoundSlot, out var activeSound)) activeSound.Stop(); + if (NearbySoundSlot.IsValid) + NearbySoundSlot = SlotId.Invalid; NPC.Transform(ModContent.NPCType()); } @@ -300,6 +290,16 @@ namespace CalamityMod.NPCs.NormalNPCs public void MainBehavior_IdleAndWalk() { + // Run away when damaged. + if (NPC.justHit && Main.rand.NextBool(3)) + { + AIState = (int)BehaviorState.Running; + Timer = 0f; + LocalAIState = 0f; + NPC.netUpdate = true; + return; + } + // Idling. if (LocalAIState == 0f) { @@ -340,8 +340,9 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.netUpdate = true; } - if (MathF.Abs(NPC.velocity.X) < MaxSpeed_Walking) - NPC.velocity.X += MaxAcceleration_Walking * NPC.direction; + NPC.velocity.X += MaxAcceleration_Walking * NPC.direction; + NPC.velocity.X = MathHelper.Clamp(NPC.velocity.X, -MaxSpeed_Walking, MaxSpeed_Walking); + NPC.direction = NPC.velocity.X.DirectionalSign(); if (NPC.collideX && NPC.velocity.Y == 0f) NPC.velocity.Y -= 6f; @@ -368,7 +369,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.spriteDirection = NPC.direction; float targetAngle = (NPC.velocity.Y != 0f) ? NPC.velocity.X * 0.085f * (NPC.velocity.Y < 0).ToDirectionInt() : 0f; - NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.075f); + NPC.rotation = NPC.rotation.AngleLerp(targetAngle, 0.125f); } public void MainBehavior_Running() @@ -376,8 +377,9 @@ namespace CalamityMod.NPCs.NormalNPCs // Run in a random direction until collision with a wall is made. if (LocalAIState == 0f) { - if (MathF.Abs(NPC.velocity.X) < MaxSpeed_Running) - NPC.velocity.X += MaxAcceleration_Running * NPC.direction; + NPC.velocity.X += MaxAcceleration_Running * NPC.direction; + NPC.velocity.X = MathHelper.Clamp(NPC.velocity.X, -MaxSpeed_Running, MaxSpeed_Running); + NPC.direction = NPC.velocity.X.DirectionalSign(); NPC.spriteDirection = NPC.direction; // Spawn particles when running at max speed. diff --git a/NPCs/NormalNPCs/PiggyGold.cs b/NPCs/NormalNPCs/PiggyGold.cs index c8729e2514..32043e3c04 100644 --- a/NPCs/NormalNPCs/PiggyGold.cs +++ b/NPCs/NormalNPCs/PiggyGold.cs @@ -23,7 +23,7 @@ namespace CalamityMod.NPCs.NormalNPCs NPCID.Sets.CantTakeLunchMoney[Type] = true; NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true; NPCID.Sets.GoldCrittersCollection.Add(Type); - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(ModContent.NPCType()) + 1, Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type); } public override void SetDefaults() @@ -38,11 +38,12 @@ namespace CalamityMod.NPCs.NormalNPCs public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { // All gold critters have the same Bestiary entry. - var flavorText = database.FindEntryByNPCID(NPCID.GoldBunny).Info.Where(info => info is FlavorTextBestiaryInfoElement).FirstOrDefault(); + string key = Lang.GetNPCName(NPCID.GoldBunny).Key.Replace("NPCName.", ""); + string flavorText = "Bestiary_FlavorText.npc_" + key; bestiaryEntry.AddTags( BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Times.DayTime, - BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface, - flavorText); + BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface, + new FlavorTextBestiaryInfoElement(flavorText)); } public override void AI() diff --git a/NPCs/NormalNPCs/Shroomble.cs b/NPCs/NormalNPCs/Shroomble.cs index 3dd653a19f..676fbd882e 100644 --- a/NPCs/NormalNPCs/Shroomble.cs +++ b/NPCs/NormalNPCs/Shroomble.cs @@ -49,12 +49,6 @@ namespace CalamityMod.NPCs.NormalNPCs public override void AI() { - // Force bestiary unlock - if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0) - { - Main.BestiaryTracker.Kills.RegisterKill(NPC); - } - bool walking = NPC.ai[0] == 1; // Do a cute lil' hop randomly int jumpChance = walking ? 600 : 100; diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 8d238e2028..e751c0a2b2 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -111,10 +111,14 @@ namespace CalamityMod.NPCs.Providence public static readonly SoundStyle NearBurnSound = new("CalamityMod/Sounds/Custom/Providence/ProvidenceSizzle"); public static readonly SoundStyle BurnStartSound = new("CalamityMod/Sounds/Custom/Providence/ProvidenceBurn"); - public static readonly SoundStyle BurnLoopSound = new SoundStyle("CalamityMod/Sounds/Custom/Providence/ProvidenceBurnLoop") with { IsLooped = true }; + public static readonly SoundStyle BurnLoopSound = new SoundStyle("CalamityMod/Sounds/Custom/Providence/ProvidenceBurnLoop") + { + IsLooped = true, + PauseBehavior = PauseBehavior.PauseWithGame, + }; // Sound slot for the burning damage over time effect - public SlotId BurningSoundSlot; + public SlotId BurningSoundSlot = SlotId.Invalid; // Level of sound playing public float SoundWarningLevel = -1f; @@ -374,7 +378,10 @@ namespace CalamityMod.NPCs.Providence { //ensure projectiles all despawn when she does if (NPC.timeLeft == 1) + { DespawnSpecificProjectiles(true); + StopHolyInfernoSounds(); + } // Set the border drawing to true if it isn't set to true // Can happen when another mod sets to false for a difficulty and that difficulty is then toggled off. @@ -493,7 +500,8 @@ namespace CalamityMod.NPCs.Providence { // Initialize sound SoundEngine.PlaySound(BurnStartSound, player.Center); - BurningSoundSlot = SoundEngine.PlaySound(BurnLoopSound, player.Center); + if (!SoundEngine.TryGetActiveSound(BurningSoundSlot, out _)) + BurningSoundSlot = SoundEngine.PlaySound(BurnLoopSound, player.Center, HolyInfernoSoundCallback); SoundWarningLevel = 2f; } player.AddBuff(ModContent.BuffType(), 2); @@ -525,17 +533,12 @@ namespace CalamityMod.NPCs.Providence SoundWarningLevel -= 1 / 50f; // Updating the looping sound - if (SoundEngine.TryGetActiveSound(BurningSoundSlot, out var burningSound) && burningSound.IsPlaying) + if (SoundEngine.TryGetActiveSound(BurningSoundSlot, out var burningSound)) burningSound.Position = player.Center; - // Adjust the volume or break the loop accordingly - if (burningSound is not null) - { - if (SoundWarningLevel <= 1f) - burningSound?.Stop(); - else if (SoundWarningLevel <= 2f) - burningSound.Volume = SoundWarningLevel - 1f; - } + // Stop the sounds when necessary. + if (!NPC.active || SoundWarningLevel <= 1f) + StopHolyInfernoSounds(); // Count the remaining Guardians, healer especially because it allows the boss to heal int guardianAmt = 0; @@ -1892,10 +1895,26 @@ namespace CalamityMod.NPCs.Providence } } + private void StopHolyInfernoSounds() + { + if (SoundEngine.TryGetActiveSound(BurningSoundSlot, out ActiveSound infernoSound)) + infernoSound.Stop(); + if (BurningSoundSlot.IsValid) + BurningSoundSlot = SlotId.Invalid; + } + + private bool HolyInfernoSoundCallback(ActiveSound sound) + { + if (SoundWarningLevel <= 2f) + sound.Volume = SoundWarningLevel - 1f; + return NPC.active; + } + public override bool CheckDead() { NPC.life = 1; DespawnSpecificProjectiles(true); + StopHolyInfernoSounds(); Dying = true; NPC.active = true; NPC.dontTakeDamage = true; diff --git a/Particles/EmoteExpressionParticle.cs b/Particles/EmoteExpressionParticle.cs index 4e9de2e4e0..8f3ff7e080 100644 --- a/Particles/EmoteExpressionParticle.cs +++ b/Particles/EmoteExpressionParticle.cs @@ -26,7 +26,7 @@ namespace CalamityMod.Particles BigSmile } - private Rectangle Frame; + private EmoteType Emote; public EmoteExpressionParticle(Vector2 position, Vector2 velocity, float scale, Color color, int lifeTime, EmoteType emote) { @@ -35,7 +35,7 @@ namespace CalamityMod.Particles Velocity = velocity; Color = color; Lifetime = lifeTime; - Frame = ModContent.Request(Texture).Value.Frame(horizontalFrames: 8, verticalFrames: 1, frameX: (int)emote); + Emote = emote; Rotation = velocity.ToRotation() + MathHelper.PiOver2; } @@ -48,10 +48,11 @@ namespace CalamityMod.Particles public override void CustomDraw(SpriteBatch spriteBatch) { Texture2D emoteTexture = ModContent.Request(Texture).Value; - Vector2 origin = new Vector2(Frame.Width / 2f, Frame.Height); float opacity = 1 - (float)Math.Pow(LifetimeCompletion, 4f); + Rectangle frame = emoteTexture.Frame(horizontalFrames: 8, verticalFrames: 1, frameX: (int)Emote); + Vector2 origin = new Vector2(frame.Width / 2f, frame.Height); - spriteBatch.Draw(emoteTexture, Position - Main.screenPosition, Frame, Color * opacity, Rotation, origin, Scale, SpriteEffects.None, 0); + spriteBatch.Draw(emoteTexture, Position - Main.screenPosition, frame, Color * opacity, Rotation, origin, Scale, SpriteEffects.None, 0); } } } diff --git a/Projectiles/Boss/HolyBurnOrb.cs b/Projectiles/Boss/HolyBurnOrb.cs index a88beb4dcf..4dd4882761 100644 --- a/Projectiles/Boss/HolyBurnOrb.cs +++ b/Projectiles/Boss/HolyBurnOrb.cs @@ -163,6 +163,9 @@ namespace CalamityMod.Projectiles.Boss public void DrawTrail() { + if (Projectile.oldPos.Length <= 0) + return; + Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -200f, 200f); Vector2 basePosition = Projectile.Center - Main.screenPosition; Rectangle screenBounds = new Rectangle(-40, -40, Main.screenWidth + 40, Main.screenHeight + 40); @@ -187,7 +190,7 @@ namespace CalamityMod.Projectiles.Boss Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap; using var shaderScope = SanePrimitiveRenderer.BeginShaderScope(shader, Matrix.Identity, Matrix.Identity, projection); - using var trailMesh = TriangleStripBuilder.BuildStripPooled(path, progress => FireWidthFunction(progress), progress => FireColorFunction(progress), PrimitiveMeshCache.Shared, textured: true); + using var trailMesh = TriangleStripBuilder.BuildStripPooled(path, progress => FireWidthFunction(progress), progress => FireColorFunction(progress), PrimitiveMeshCache.Shared, textured: true, smoothingCurve: StripCurveType.Hermite); shaderScope.Draw(trailMesh.View); } } diff --git a/Projectiles/Boss/HolyLight.cs b/Projectiles/Boss/HolyLight.cs index 54fc96cc2d..935ce48c29 100644 --- a/Projectiles/Boss/HolyLight.cs +++ b/Projectiles/Boss/HolyLight.cs @@ -152,6 +152,9 @@ namespace CalamityMod.Projectiles.Boss public void DrawTrail() { + if (Projectile.oldPos.Length <= 0) + return; + Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -200f, 200f); Vector2 basePosition = Projectile.Center - Main.screenPosition; Rectangle screenBounds = new Rectangle(-40, -40, Main.screenWidth + 40, Main.screenHeight + 40); @@ -176,7 +179,7 @@ namespace CalamityMod.Projectiles.Boss Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap; using var shaderScope = SanePrimitiveRenderer.BeginShaderScope(shader, Matrix.Identity, Matrix.Identity, projection); - using var trailMesh = TriangleStripBuilder.BuildStripPooled(path, progress => FireWidthFunction(progress), progress => FireColorFunction(progress), PrimitiveMeshCache.Shared, textured: true); + using var trailMesh = TriangleStripBuilder.BuildStripPooled(path, progress => FireWidthFunction(progress), progress => FireColorFunction(progress), PrimitiveMeshCache.Shared, textured: true, smoothingCurve: StripCurveType.Hermite); shaderScope.Draw(trailMesh.View); } } @@ -215,13 +218,13 @@ namespace CalamityMod.Projectiles.Boss Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, MathHelper.PiOver2 - Projectile.rotation, halfTextureSize, timeLeftDrawEffect, spriteEffects, 0); Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, 0f - Projectile.rotation, halfTextureSize, timeLeftDrawEffect2, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3 + Vector2.UnitX * 60f, null, halfBrightGreen, MathHelper.PiOver2 - Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3 + Vector2.UnitX * 60f, null, halfBrightGreen, 0f - Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, MathHelper.PiOver2 - Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, 0f - Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitX * 60f, null, brightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitX * 60f, null, brightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitY * 60f, null, halfBrightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.36f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitY * 60f, null, halfBrightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.36f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.36f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.36f, spriteEffects, 0); } private void DrawHealOrbAdditive() diff --git a/Projectiles/CalamityGlobalProjectile.cs b/Projectiles/CalamityGlobalProjectile.cs index 9d961e3dc6..6a5aa23037 100644 --- a/Projectiles/CalamityGlobalProjectile.cs +++ b/Projectiles/CalamityGlobalProjectile.cs @@ -519,7 +519,7 @@ namespace CalamityMod.Projectiles EnhancedDarknessSystem.lights.Add(new() { center = projectile.Center, scale = 1 }); // 24DEC2025: Ozzatron: victide bobber culled with SSO - if (projectile.bobber /*&& projectile.type != ProjectileType()*/ && RunFishingMinigames(projectile) && !Main.LocalPlayer.dead) + if (projectile.bobber /*&& projectile.type != ProjectileType()*/ && RunFishingChanges(projectile) && !Main.LocalPlayer.dead) return false; //Reset the Homing Target immediately before AI can re-set it on applicable projectiles @@ -3033,7 +3033,7 @@ namespace CalamityMod.Projectiles /// public Vector2 PersistentFishingDataVector2 = Vector2.Zero; - public bool RunFishingMinigames(Projectile projectile) + public bool RunFishingChanges(Projectile projectile) { var owner = Main.player[projectile.owner]; var cplayer = owner.Calamity(); @@ -3041,6 +3041,28 @@ namespace CalamityMod.Projectiles bool reelingIn = projectile.ai[0] == 1; bool lineSnapped = projectile.ai[0] == 2; + // When using rage bait, gives a chance that your items turn to junk + bool alreadyJunk = projectile.ai[1] == ItemID.OldShoe || projectile.ai[1] == ItemID.FishingSeaweed || projectile.ai[1] == ItemID.TinCan; + bool canRageBaitThePlayer = Main.rand.NextBool(RageBait.junkChance.Item1, RageBait.junkChance.Item2); + if (baitItem?.type == ModContent.ItemType() && reelingIn && !alreadyJunk && canRageBaitThePlayer && projectile.localAI[1] != 0) + { + Fishing_DoRageBaitEffects(projectile, owner); + return false; + } + + // Trusty Old Rod functionality. + bool pulledNPC = Main.rand.NextBool(TrustyOldRod.enemyChance.Item1, TrustyOldRod.enemyChance.Item2); + if (owner.HeldItem.type == ModContent.ItemType() && reelingIn && projectile.ai[1] != 0 && projectile.localAI[1] != 0 && pulledNPC) + { + Fishing_DoTrustyOldRodEffects(projectile, owner); + return false; + } + + // For allowing Rage Bait and TOR to function correctly while using custom bobbers. + // See the ReelTheBobberChecks function. + bool canLetRageBaitRunForMinigame = baitItem?.type == ModContent.ItemType() && !alreadyJunk && canRageBaitThePlayer; + bool canLetTrustyOldRodRunForMinigame = owner.HeldItem.type == ModContent.ItemType() && pulledNPC; + #region Utilities void SmallSplashAtOffset(Vector2 offset) { @@ -3076,7 +3098,15 @@ namespace CalamityMod.Projectiles } void ReelTheBobberChecks() { - if (projectile.localAI[1] == 1) + if (canLetRageBaitRunForMinigame) + { + Fishing_DoRageBaitEffects(projectile, owner); + } + else if (canLetTrustyOldRodRunForMinigame) + { + Fishing_DoTrustyOldRodEffects(projectile, owner); + } + else if (projectile.localAI[1] == 1) { if (Main.netMode != NetmodeID.MultiplayerClient) { @@ -3810,62 +3840,60 @@ namespace CalamityMod.Projectiles } - bool alreadyJunk = projectile.ai[1] == ItemID.OldShoe || projectile.ai[1] == ItemID.FishingSeaweed || projectile.ai[1] == ItemID.TinCan; - // When using rage bait, gives a chance that your items turn to junk - if (baitItem?.type == ModContent.ItemType() && reelingIn && !alreadyJunk && Main.rand.NextBool(RageBait.junkChance.Item1, RageBait.junkChance.Item2) && projectile.localAI[1] != 0) - { - var junk = Main.rand.Next(3) switch - { - 0 => ItemID.OldShoe, - 1 => ItemID.FishingSeaweed, - _ => ItemID.TinCan, - }; - - SoundStyle epicFail = new("CalamityMod/Sounds/Item/Swine", 2); - SoundEngine.PlaySound(epicFail with { Volume = 0.9f, Pitch = 0.3f }, projectile.Center); - if (CalamityWorld.revenge) - owner.Calamity().rage += 25; - - for (int i = 0; i < 12; i++) - { - Particle spray = new CustomSpark(projectile.Center + Vector2.UnitX * Main.rand.NextFloat(-10, 10), -Vector2.UnitY * Main.rand.NextFloat(3, 8), "CalamityMod/Particles/BloomCircle", true, Main.rand.Next(18, 24) * 5, Main.rand.NextFloat(0.3f, 0.5f), Color.Lerp(Color.Gray, Color.White, Main.rand.NextFloat(0, 0.7f)) * 0.3f, new Vector2(0.8f, 1f), true, false, 0, false, false); - GeneralParticleHandler.SpawnParticle(spray); - - if (i % 2 == 0) - { - Particle rage = new CustomSpark(owner.Center + Vector2.UnitX * Main.rand.NextFloat(-10, 10) + -Vector2.UnitY * 7.5f, -Vector2.UnitY * Main.rand.NextFloat(0.5f, 2f), "CalamityMod/Particles/BloomCircle", false, Main.rand.Next(12, 18) * 4, Main.rand.NextFloat(0.3f, 0.5f), Color.Lerp(Color.Crimson, Color.Red, Main.rand.NextFloat(0, 0.7f)) * 0.7f, new Vector2(0.7f, 1f), true, false, 0, false, false); - GeneralParticleHandler.SpawnParticle(rage); - } - } - - projectile.ai[1] = junk; - return false; - } - - bool pulledNPC = Main.rand.NextBool(TrustyOldRod.enemyChance.Item1, TrustyOldRod.enemyChance.Item2); - - if (owner.HeldItem.type == ModContent.ItemType() && reelingIn && projectile.ai[1] != 0 && projectile.localAI[1] != 0 && pulledNPC) - { - // Remove any item you would have fished up - projectile.ai[1] = 0; - // Get rarity of pull - int rarity; - int roll = Main.rand.Next(1, 100 + 1); - if (roll == 1) rarity = 3; // UltraRare (1/100) - else if (roll <= 21) rarity = 2; // Rare ~(1/5) - else rarity = 1; // Common ~(4/5) - - if (Main.netMode == NetmodeID.MultiplayerClient && Main.myPlayer == owner.whoAmI) - TrustyOldRodEnemyPacket.Send(owner, projectile.identity, rarity, projectile.lavaWet, projectile.honeyWet); - else if(Main.netMode == NetmodeID.SinglePlayer) - TrustyOldRodEnemySystem.SpawnTrustyOldRodNPC(owner, projectile.identity, rarity, projectile.lavaWet, projectile.honeyWet); - - TrustyOldRodEnemySystem.DoTrustyOldRodVFX(owner, projectile.identity, rarity, projectile.lavaWet, projectile.honeyWet); - projectile.ai[0] = 2; // snap line - return false; - } return false; } + + private void Fishing_DoRageBaitEffects(Projectile projectile, Player owner) + { + var junk = Main.rand.Next(3) switch + { + 0 => ItemID.OldShoe, + 1 => ItemID.FishingSeaweed, + _ => ItemID.TinCan, + }; + + SoundStyle epicFail = new("CalamityMod/Sounds/Item/Swine", 2); + SoundEngine.PlaySound(epicFail with { Volume = 0.9f, Pitch = 0.3f }, projectile.Center); + if (CalamityWorld.revenge) + owner.Calamity().rage += 25; + + for (int i = 0; i < 12; i++) + { + Particle spray = new CustomSpark(projectile.Center + Vector2.UnitX * Main.rand.NextFloat(-10, 10), -Vector2.UnitY * Main.rand.NextFloat(3, 8), "CalamityMod/Particles/BloomCircle", true, Main.rand.Next(18, 24) * 5, Main.rand.NextFloat(0.3f, 0.5f), Color.Lerp(Color.Gray, Color.White, Main.rand.NextFloat(0, 0.7f)) * 0.3f, new Vector2(0.8f, 1f), true, false, 0, false, false); + GeneralParticleHandler.SpawnParticle(spray); + + if (i % 2 == 0) + { + Particle rage = new CustomSpark(owner.Center + Vector2.UnitX * Main.rand.NextFloat(-10, 10) + -Vector2.UnitY * 7.5f, -Vector2.UnitY * Main.rand.NextFloat(0.5f, 2f), "CalamityMod/Particles/BloomCircle", false, Main.rand.Next(12, 18) * 4, Main.rand.NextFloat(0.3f, 0.5f), Color.Lerp(Color.Crimson, Color.Red, Main.rand.NextFloat(0, 0.7f)) * 0.7f, new Vector2(0.7f, 1f), true, false, 0, false, false); + GeneralParticleHandler.SpawnParticle(rage); + } + } + + projectile.ai[1] = junk; + CaughtItemID = junk; + } + + private void Fishing_DoTrustyOldRodEffects(Projectile projectile, Player owner) + { + // Remove any item you would have fished up + projectile.ai[1] = 0; + CaughtItemID = 0; + + // Get rarity of pull + int rarity; + int roll = Main.rand.Next(1, 100 + 1); + if (roll == 1) rarity = 3; // UltraRare (1/100) + else if (roll <= 21) rarity = 2; // Rare ~(1/5) + else rarity = 1; // Common ~(4/5) + + if (Main.netMode == NetmodeID.MultiplayerClient && Main.myPlayer == owner.whoAmI) + TrustyOldRodEnemyPacket.Send(owner, projectile.identity, rarity, projectile.lavaWet, projectile.honeyWet); + else if (Main.netMode == NetmodeID.SinglePlayer) + TrustyOldRodEnemySystem.SpawnTrustyOldRodNPC(owner, projectile.identity, rarity, projectile.lavaWet, projectile.honeyWet); + + TrustyOldRodEnemySystem.DoTrustyOldRodVFX(owner, projectile.identity, rarity, projectile.lavaWet, projectile.honeyWet); + projectile.ai[0] = 2; // snap line + } #endregion #region AI diff --git a/Systems/Collections/CalamityNPCSets.cs b/Systems/Collections/CalamityNPCSets.cs index bde061e0e1..4bcadfb295 100644 --- a/Systems/Collections/CalamityNPCSets.cs +++ b/Systems/Collections/CalamityNPCSets.cs @@ -12,8 +12,10 @@ using CalamityMod.NPCs.CeaselessVoid; using CalamityMod.NPCs.Crabulon; using CalamityMod.NPCs.Crags; using CalamityMod.NPCs.Cryogen; +using CalamityMod.NPCs.Deconstructors; using CalamityMod.NPCs.DesertScourge; using CalamityMod.NPCs.DevourerofGods; +using CalamityMod.NPCs.DraedonLabThings; using CalamityMod.NPCs.ExoMechs.Apollo; using CalamityMod.NPCs.ExoMechs.Ares; using CalamityMod.NPCs.ExoMechs.Artemis; @@ -337,6 +339,35 @@ namespace CalamityMod.Systems.Collections NPCType(), 18000 // 5:00 (300 seconds) ); + + /// + /// Allows an NPC to be automatically registered as a critter in the Bestiary when the player is near them.
+ /// Should only be used in cases where an NPC does NOT follow the Vanilla definition of a critter. See . + ///
+ public static List ForciblyRegisterAsCritterInBestiary = new List + { + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType(), + NPCType() + }; + + /// + /// Allows a variant of an NPC to count as credits towards another in the Bestiary.
+ /// This exists to prevent cases where dupilcate entries are made for two variants of the same creature, such as worms and their segments. + ///
+ public static Dictionary CountVariantsAsTheSameInBestiary = new Dictionary + { + { NPCType(), NPCType() }, + { NPCType(), NPCType() }, + { NPCType(), NPCType() }, + { NPCType(), NPCType() }, + }; + /// /// Associates an NPC type with the base value of their max health in Boss Rush.
/// If an NPC type is not a key in this dictionary, then it will use its standard max health value. diff --git a/Systems/Mechanic/GravityManipulationChangesSystem.cs b/Systems/Mechanic/GravityManipulationChangesSystem.cs new file mode 100644 index 0000000000..1f526e24b5 --- /dev/null +++ b/Systems/Mechanic/GravityManipulationChangesSystem.cs @@ -0,0 +1,126 @@ +using CalamityMod.Effects; +using CalamityMod.Utilities.Daybreak; +using CalamityMod.Utilities.Daybreak.Buffers; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Audio; +using Terraria.GameInput; +using Terraria.Graphics; +using Terraria.Graphics.Effects; +using Terraria.Graphics.Renderers; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Systems.Mechanic +{ + public class GravityManipulationChangesSystem : ModSystem + { + public override void Load() + { + On_Player.UpdateControlHolds += DelayGravity; + On_PlayerInput.SetZoom_MouseInWorld += AdjustMousePositionWithGravityConfig; + + if (!Main.dedServ) + { + Main.QueueMainThreadAction(() => + { + On_Main.DoDraw += ForceGravityDirectionForDrawing; + On_LegacyPlayerRenderer.DrawPlayerInternal += FlipPlayerWithConfig; + }); + } + } + + public override void Unload() + { + On_Player.UpdateControlHolds -= DelayGravity; + On_PlayerInput.SetZoom_MouseInWorld -= AdjustMousePositionWithGravityConfig; + + if (!Main.dedServ) + { + Main.QueueMainThreadAction(() => + { + On_Main.DoDraw -= ForceGravityDirectionForDrawing; + On_LegacyPlayerRenderer.DrawPlayerInternal -= FlipPlayerWithConfig; + }); + } + } + + private static void DelayGravity(On_Player.orig_UpdateControlHolds orig, Player Player) + { + var cplay = Player.Calamity(); + if (CalamityKeybinds.SwitchGravityHotkey.GetAssignedKeysOrEmpty().Count != 0 && (Player.gravControl || Player.gravControl2) && !Player.mount.Active) + { + if (Player.controlUp && Player.releaseUp) + { + Player.gravDir *= -1; + } + if (CalamityKeybinds.SwitchGravityHotkey.JustPressed) + { + Player.gravDir *= -1; + Player.fallStart = (int)(Player.position.Y / 16f); + Player.jump = 0; + SoundEngine.PlaySound(SoundID.Item8, Player.position); + } + + if (Player.forcedGravity > 0) + { + Player.gravDir = -1f; + } + } + + if (cplay.justChangedGravity) + { + Player.gravDir = cplay.oldGravDir; + } + cplay.justChangedGravity = cplay.oldGravDir != Player.gravDir; + + cplay.oldGravDir = Player.gravDir; + + if (cplay.justChangedGravity) + { + Player.gravDir *= -1; + } + orig(Player); + } + + private static void AdjustMousePositionWithGravityConfig(On_PlayerInput.orig_SetZoom_MouseInWorld orig) + { + orig(); + if (!Main.gameMenu && CalamityClientConfig.Instance.DisableGravityScreenSwap && ((Main.LocalPlayer.gravDir == -1 && !Main.LocalPlayer.Calamity().justChangedGravity) || (Main.LocalPlayer.Calamity().oldGravDir == -1 && Main.LocalPlayer.Calamity().justChangedGravity)))//((Main.LocalPlayer.gravDir == -1 && !Main.LocalPlayer.Calamity().justChangedGravity) || (Main.LocalPlayer.Calamity().oldGravDir == -1 && Main.LocalPlayer.Calamity().justChangedGravity)) + { + var center = Main.screenHeight / 2; + Main.mouseY = center - (Main.mouseY - center); + } + } + + private void ForceGravityDirectionForDrawing(On_Main.orig_DoDraw orig, Main self, GameTime gameTime) + { + if (!CalamityClientConfig.Instance.DisableGravityScreenSwap || Main.gameMenu || Main.dedServ) + { + orig(self, gameTime); + } + else + { + Main.LocalPlayer.Calamity().tempGravDir = Main.LocalPlayer.gravDir; + Main.LocalPlayer.gravDir = 1; + orig(self, gameTime); + Main.LocalPlayer.gravDir = Main.LocalPlayer.Calamity().tempGravDir; + } + } + + private void FlipPlayerWithConfig(On_LegacyPlayerRenderer.orig_DrawPlayerInternal orig, LegacyPlayerRenderer self, Camera camera, Player drawPlayer, Vector2 position, float rotation, Vector2 rotationOrigin, float shadow, float alpha, float scale, bool headOnly) + { + if (!CalamityClientConfig.Instance.DisableGravityScreenSwap || Main.gameMenu || Main.dedServ || drawPlayer.whoAmI != Main.myPlayer) + { + orig(self, camera, drawPlayer, position, rotation, rotationOrigin, shadow, alpha, scale, headOnly); + } + else + { + drawPlayer.gravDir = drawPlayer.Calamity().tempGravDir; + orig(self, camera, drawPlayer, position, rotation, rotationOrigin, shadow, alpha, scale, headOnly); + drawPlayer.gravDir = 1; + } + } + } +} diff --git a/Systems/World/BestiaryRegistrySystem.cs b/Systems/World/BestiaryRegistrySystem.cs index ced469a837..d0d8bab95c 100644 --- a/Systems/World/BestiaryRegistrySystem.cs +++ b/Systems/World/BestiaryRegistrySystem.cs @@ -1,6 +1,11 @@ -using CalamityMod.NPCs.Abyss; +using System.Collections.Generic; +using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.Astral; using CalamityMod.NPCs.Crags; +using CalamityMod.NPCs.Deconstructors; +using CalamityMod.Systems.Collections; +using Terraria; +using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; using static Terraria.ModLoader.ModContent; @@ -11,10 +16,56 @@ namespace CalamityMod.Systems { public override void PostSetupContent() { + On_BestiaryDatabaseNPCsPopulator.AddEmptyEntries_CrittersAndEnemies_Automated += ForciblyAddEmptyEntriesForCritters; + On_NPCWasNearPlayerTracker.ScanWorldForFinds += ForciblySetWasSeenByPlayer; + // Manually register variants post-initiailization - ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()]; - ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()]; - ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType()]; + foreach (var pair in CalamityNPCSets.CountVariantsAsTheSameInBestiary) + ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[pair.Key] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[pair.Value]; + } + + private void ForciblyAddEmptyEntriesForCritters(On_BestiaryDatabaseNPCsPopulator.orig_AddEmptyEntries_CrittersAndEnemies_Automated orig, BestiaryDatabaseNPCsPopulator self) + { + orig(self); + + // Run through all entries again and remove the empty Enemy entries that are added by tMod itself. + // Afterwards, mnually add empty Critter entries for all NPCs within the ID set. + HashSet exclusions = BestiaryDatabaseNPCsPopulator.GetExclusions(); + foreach (KeyValuePair pair in ContentSamples.NpcsByNetId) + { + if (!exclusions.Contains(pair.Key)) + { + if (CalamityNPCSets.ForciblyRegisterAsCritterInBestiary.Contains(pair.Value.type)) + { + if (BestiaryDatabaseNPCsPopulator._currentDatabase._byNpcId.TryGetValue(pair.Value.netID, out BestiaryEntry enemyEntry) && enemyEntry.UIInfoProvider is not CritterUICollectionInfoProvider) + { + BestiaryDatabaseNPCsPopulator._currentDatabase.Entries.Remove(enemyEntry); + NPCLoader.SetBestiary(pair.Value, BestiaryDatabaseNPCsPopulator._currentDatabase, self.Register(BestiaryEntry.Critter(pair.Key))); + } + } + } + } + } + + private void ForciblySetWasSeenByPlayer(On_NPCWasNearPlayerTracker.orig_ScanWorldForFinds orig, NPCWasNearPlayerTracker self) + { + orig(self); + + // Allow NPCs with manully added empty critter entries to be registered by player proximity. + foreach (NPC npc in Main.ActiveNPCs) + { + if (!CalamityNPCSets.ForciblyRegisterAsCritterInBestiary.Contains(npc.type) || self._wasSeenNearPlayerByNetId.Contains(npc.netID)) + continue; + + for (int i = 0; i < self._playerHitboxesForBestiary.Count; i++) + { + if (npc.Hitbox.Intersects(self._playerHitboxesForBestiary[i])) + { + self._wasSeenNearPlayerByNetId.Add(npc.netID); + self.RegisterWasNearby(npc); + } + } + } } } } diff --git a/Tiles/SunkenSea/SeaPrism.cs b/Tiles/SunkenSea/SeaPrism.cs index 0539abd2f6..085c79e037 100644 --- a/Tiles/SunkenSea/SeaPrism.cs +++ b/Tiles/SunkenSea/SeaPrism.cs @@ -2,6 +2,7 @@ using CalamityMod.Effects; using CalamityMod.Items.Placeables.SunkenSea; using CalamityMod.Systems; +using CalamityMod.Utilities.Daybreak; using CalamityMod.Walls; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -358,8 +359,14 @@ namespace CalamityMod.Tiles.SunkenSea public override void OnModLoad() { - On_Main.DrawTiles += DrawSeaPrismsAndCrystals; - On_Main.DrawWalls += DrawSeaPrismWalls; + if (!Main.dedServ) + { + Main.QueueMainThreadAction(() => + { + On_Main.DrawTiles += DrawSeaPrismsAndCrystals; + On_Main.DrawWalls += DrawSeaPrismWalls; + }); + } SeaPrismTileType = ModContent.TileType(); SeaPrismCrystalTileType = ModContent.TileType(); @@ -397,9 +404,6 @@ namespace CalamityMod.Tiles.SunkenSea { Vector2 offscreenPosition = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Main.tileBatch.End(); - Main.spriteBatch.End(); - var oldTex1 = Main.instance.GraphicsDevice.Textures[1]; var oldSampler1 = Main.instance.GraphicsDevice.SamplerStates[1]; var oldTex2 = Main.instance.GraphicsDevice.Textures[2]; @@ -415,11 +419,13 @@ namespace CalamityMod.Tiles.SunkenSea shader.Parameters["doGlint"].SetValue(true); Vector2 unscaledPosition = Main.Camera.UnscaledPosition; - GetScreenDrawArea(unscaledPosition, offscreenPosition + (Main.Camera.UnscaledPosition - Main.Camera.ScaledPosition), out var firstTileX, out var lastTileX, out var firstTileY, out var lastTileY); - if (solidLayer) + if ((solidLayer && !Main.drawToScreen) || (!solidLayer && Main.drawToScreen)) { + Main.tileBatch.End(); + Main.spriteBatch.End(out var snapshot); + Main.instance.GraphicsDevice.Textures[1] = SeaPrism.Green.Value; Main.instance.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; Main.instance.GraphicsDevice.Textures[2] = SeaPrism.Purple.Value; @@ -427,7 +433,8 @@ namespace CalamityMod.Tiles.SunkenSea Main.instance.GraphicsDevice.Textures[3] = SeaPrism.Glint.Value; Main.instance.GraphicsDevice.SamplerStates[3] = SamplerState.LinearClamp; - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, shader, Matrix.Identity); + Main.tileBatch.Begin(snapshot.RasterizerState, snapshot.TransformMatrix); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, snapshot.RasterizerState, shader, snapshot.TransformMatrix); for (int y = firstTileY; y < lastTileY + 4; y++) { @@ -437,9 +444,6 @@ namespace CalamityMod.Tiles.SunkenSea continue; Tile tile = Main.tile[x, y]; - if (tile == null) - continue; - int type = tile.TileType; if (type != SeaPrismTileType) continue; @@ -456,9 +460,26 @@ namespace CalamityMod.Tiles.SunkenSea Main.spriteBatch.Draw(SeaPrism.Blue.Value, position, sourceRect, light); } } + + Main.tileBatch.End(); + Main.spriteBatch.End(); + + Main.instance.GraphicsDevice.Textures[1] = oldTex1; + Main.instance.GraphicsDevice.SamplerStates[1] = oldSampler1; + Main.instance.GraphicsDevice.Textures[2] = oldTex2; + Main.instance.GraphicsDevice.SamplerStates[2] = oldSampler2; + Main.instance.GraphicsDevice.Textures[3] = oldTex3; + Main.instance.GraphicsDevice.SamplerStates[3] = oldSampler3; + + Main.tileBatch.Begin(snapshot.RasterizerState, snapshot.TransformMatrix); + Main.spriteBatch.Begin(snapshot); } - else + + if (!solidLayer) { + Main.tileBatch.End(); + Main.spriteBatch.End(out var snapshot); + Main.instance.GraphicsDevice.Textures[1] = SeaPrismCrystals.GreenCrystals.Value; Main.instance.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; Main.instance.GraphicsDevice.Textures[2] = SeaPrismCrystals.PurpleCrystals.Value; @@ -466,7 +487,7 @@ namespace CalamityMod.Tiles.SunkenSea Main.instance.GraphicsDevice.Textures[3] = SeaPrismCrystals.Glint.Value; Main.instance.GraphicsDevice.SamplerStates[3] = SamplerState.LinearClamp; - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, shader, Matrix.Identity); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, snapshot.RasterizerState, shader, snapshot.TransformMatrix); for (int y = firstTileY; y < lastTileY + 4; y++) { @@ -476,15 +497,11 @@ namespace CalamityMod.Tiles.SunkenSea continue; Tile tile = Main.tile[x, y]; - if (tile == null) - continue; - int type = tile.TileType; if (type != SeaPrismCrystalTileType) continue; - Vector2 offScreen = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 position = new Vector2(x * 16, y * 16) - Main.screenPosition + offScreen; + Vector2 position = new Vector2(x * 16, y * 16) - Main.screenPosition + offscreenPosition; Rectangle sourceRect = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); Color light = Lighting.GetColor(x, y) * 1.5f; @@ -502,7 +519,7 @@ namespace CalamityMod.Tiles.SunkenSea Main.instance.GraphicsDevice.Textures[3] = MediumSeaPrismCrystal.Glint.Value; Main.instance.GraphicsDevice.SamplerStates[3] = SamplerState.LinearClamp; - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, shader, Matrix.Identity); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, snapshot.RasterizerState, shader, snapshot.TransformMatrix); for (int y = firstTileY; y < lastTileY + 4; y++) { @@ -512,15 +529,11 @@ namespace CalamityMod.Tiles.SunkenSea continue; Tile tile = Main.tile[x, y]; - if (tile == null) - continue; - int type = tile.TileType; if (type != MediumSeaPrismCrystalTileType) continue; - Vector2 offScreen = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 position = new Vector2(x * 16, y * 16) - Main.screenPosition + offScreen; + Vector2 position = new Vector2(x * 16, y * 16) - Main.screenPosition + offscreenPosition; Rectangle sourceRect = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); Color light = Lighting.GetColor(x, y) * 1.5f; @@ -529,20 +542,19 @@ namespace CalamityMod.Tiles.SunkenSea } } + Main.spriteBatch.End(); + + Main.instance.GraphicsDevice.Textures[1] = oldTex1; + Main.instance.GraphicsDevice.SamplerStates[1] = oldSampler1; + Main.instance.GraphicsDevice.Textures[2] = oldTex2; + Main.instance.GraphicsDevice.SamplerStates[2] = oldSampler2; + Main.instance.GraphicsDevice.Textures[3] = oldTex3; + Main.instance.GraphicsDevice.SamplerStates[3] = oldSampler3; + + Main.tileBatch.Begin(snapshot.RasterizerState, snapshot.TransformMatrix); + Main.spriteBatch.Begin(snapshot); } - Main.spriteBatch.End(); - - Main.instance.GraphicsDevice.Textures[1] = oldTex1; - Main.instance.GraphicsDevice.SamplerStates[1] = oldSampler1; - Main.instance.GraphicsDevice.Textures[2] = oldTex2; - Main.instance.GraphicsDevice.SamplerStates[2] = oldSampler2; - Main.instance.GraphicsDevice.Textures[3] = oldTex3; - Main.instance.GraphicsDevice.SamplerStates[3] = oldSampler3; - - Main.spriteBatch.Begin(); - Main.tileBatch.Begin(); - orig(self, solidLayer, forRenderTargets, intoRenderTargets, waterStyleOverride); } @@ -551,7 +563,7 @@ namespace CalamityMod.Tiles.SunkenSea Vector2 offscreenPosition = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); Main.tileBatch.End(); - Main.spriteBatch.End(); + Main.spriteBatch.End(out var snapshot); var oldTex1 = Main.instance.GraphicsDevice.Textures[1]; var oldSampler1 = Main.instance.GraphicsDevice.SamplerStates[1]; @@ -572,7 +584,7 @@ namespace CalamityMod.Tiles.SunkenSea shader.Parameters["diagonalScreenLength"].SetValue((Main.screenWidth / 2f) - (Main.screenHeight / 2f)); shader.Parameters["doGlint"].SetValue(false); - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, snapshot.RasterizerState, null, snapshot.TransformMatrix); Vector2 unscaledPosition = Main.Camera.UnscaledPosition; @@ -618,8 +630,8 @@ namespace CalamityMod.Tiles.SunkenSea Main.instance.GraphicsDevice.SamplerStates[2] = oldSampler2; Main.instance.GraphicsDevice.Textures[3] = oldTex3; - Main.spriteBatch.Begin(); Main.tileBatch.Begin(); + Main.spriteBatch.Begin(snapshot); orig(self); }