From 0593a243d4e1ee865668c88a56376d0584fb179a Mon Sep 17 00:00:00 2001 From: DominicKarma42 <51094361+DominicKarma@users.noreply.github.com> Date: Sat, 21 Mar 2020 12:31:56 -0500 Subject: [PATCH] Multiplayer is an insidious fuckhead Attempted to fix Old Duke spam spawning at the end of the invasion when possible. --- CalamityMod.cs | 9 +++- Events/AcidRainEvent.cs | 15 +++++- Items/SummonItems/Invasion/CausticTear.cs | 1 + NPCs/AcidRain/AcidEel.cs | 2 +- NPCs/AcidRain/FlakCrab.cs | 15 ++++++ NPCs/AcidRain/GammaSlime.cs | 10 ++-- NPCs/AcidRain/Orthocera.cs | 2 +- NPCs/AcidRain/Skyfin.cs | 2 +- NPCs/AcidRain/SulfurousSkater.cs | 49 +++++++------------ NPCs/AcidRain/Trilobite.cs | 2 +- NPCs/AcidRain/WaterLeech.cs | 4 +- NPCs/CalamityAI.cs | 1 + NPCs/CalamityGlobalNPCLoot.cs | 1 + .../Boss/OverlyDramaticDukeSummoner.cs | 4 +- Waters/SulphuricWater.cs | 9 +++- World/CalamityWorld.cs | 34 +++++++++---- 16 files changed, 105 insertions(+), 55 deletions(-) diff --git a/CalamityMod.cs b/CalamityMod.cs index 89d4196cde..88624935de 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -3651,11 +3651,15 @@ namespace CalamityMod case CalamityModMessageType.AcidRainUIDrawFadeSync: CalamityWorld.acidRainExtraDrawTime = reader.ReadInt32(); break; + case CalamityModMessageType.AcidRainOldDukeSummonSync: + CalamityWorld.triedToSummonOldDuke = reader.ReadBoolean(); + break; default: Logger.Error($"Failed to parse Calamity packet: No Calamity packet exists with ID {msgType}."); break; } - } catch(Exception e) + } + catch(Exception e) { if (e is EndOfStreamException eose) Logger.Error("Failed to parse Calamity packet: Packet was too short, missing data, or otherwise corrupt.", eose); @@ -3729,6 +3733,7 @@ namespace CalamityMod DeathModeBlizzardTimeSync, DeathBossSpawnCountdownSync, AcidRainSync, - AcidRainUIDrawFadeSync + AcidRainUIDrawFadeSync, + AcidRainOldDukeSummonSync } } diff --git a/Events/AcidRainEvent.cs b/Events/AcidRainEvent.cs index adf901eb59..ed261950bc 100644 --- a/Events/AcidRainEvent.cs +++ b/Events/AcidRainEvent.cs @@ -112,7 +112,7 @@ namespace CalamityMod.Events /// public static void TryStartEvent() { - if (CalamityWorld.rainingAcid || (!NPC.downedBoss1 && !Main.hardMode)) + if (CalamityWorld.rainingAcid || (!NPC.downedBoss1 && !Main.hardMode) || CalamityWorld.bossRushActive) return; int playerCount = 0; for (int i = 0; i < Main.player.Length; i++) @@ -141,6 +141,7 @@ namespace CalamityMod.Events // If abyssSide is true, then the abyss was generated on the left side of the world. // If false, the right. Main.invasionX = CalamityWorld.abyssSide ? 0 : Main.maxTilesX; + CalamityWorld.triedToSummonOldDuke = false; } UpdateInvasion(); BroadcastEventText("Mods.CalamityMod.AcidRainStart"); // A toxic downpour falls over the wasteland seas! @@ -174,10 +175,15 @@ namespace CalamityMod.Events CalamityWorld.downedEoCAcidRain = true; CalamityWorld.downedAquaticScourgeAcidRain = CalamityWorld.downedAquaticScourge; } + CalamityWorld.triedToSummonOldDuke = false; CalamityMod.StopRain(); } CalamityMod.UpdateServerBoolean(); + // You will be tempted to turn this into a single if conditional. + // Don't do this. Doing so has caused so much misery, with various things being read instead + // of the correct thing, look booleans being mixed up in the sending and receiving process. + // In short, leave this alone. if (Main.netMode == NetmodeID.Server) { var netMessage = CalamityMod.instance.GetPacket(); @@ -193,6 +199,13 @@ namespace CalamityMod.Events netMessage.Write(CalamityWorld.acidRainExtraDrawTime); netMessage.Send(); } + if (Main.netMode == NetmodeID.Server) + { + var netMessage = CalamityMod.instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.AcidRainOldDukeSummonSync); + netMessage.Write(CalamityWorld.triedToSummonOldDuke); + netMessage.Send(); + } } } } diff --git a/Items/SummonItems/Invasion/CausticTear.cs b/Items/SummonItems/Invasion/CausticTear.cs index 3a225dc91c..46476b5ef8 100644 --- a/Items/SummonItems/Invasion/CausticTear.cs +++ b/Items/SummonItems/Invasion/CausticTear.cs @@ -35,6 +35,7 @@ namespace CalamityMod.Items.SummonItems.Invasion else { CalamityWorld.acidRainPoints = 0; + CalamityWorld.triedToSummonOldDuke = false; AcidRainEvent.UpdateInvasion(false); } return true; diff --git a/NPCs/AcidRain/AcidEel.cs b/NPCs/AcidRain/AcidEel.cs index 4125fbcc77..fbe8697660 100644 --- a/NPCs/AcidRain/AcidEel.cs +++ b/NPCs/AcidRain/AcidEel.cs @@ -28,7 +28,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.damage = 260; + npc.damage = 160; npc.lifeMax = 6650; npc.defense = 45; } diff --git a/NPCs/AcidRain/FlakCrab.cs b/NPCs/AcidRain/FlakCrab.cs index d694df73bc..e286726d54 100644 --- a/NPCs/AcidRain/FlakCrab.cs +++ b/NPCs/AcidRain/FlakCrab.cs @@ -6,6 +6,7 @@ using CalamityMod.Projectiles.Enemy; using CalamityMod.World; using Microsoft.Xna.Framework; using System; +using System.IO; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -46,6 +47,16 @@ namespace CalamityMod.NPCs.AcidRain banner = npc.type; bannerItem = ModContent.ItemType(); } + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(npc.localAI[0]); + writer.Write(npc.localAI[1]); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + npc.localAI[0] = reader.ReadSingle(); + npc.localAI[1] = reader.ReadSingle(); + } public override void ScaleExpertStats(int numPlayers, float bossLifeScale) { npc.lifeMax = (int)(npc.lifeMax * 0.8f * bossLifeScale); @@ -58,7 +69,10 @@ namespace CalamityMod.NPCs.AcidRain npc.defense = npc.localAI[1] < 10f ? 999999 : 20; if (npc.justHit) + { npc.localAI[0] = 240; + npc.netUpdate = true; + } if (npc.localAI[0] == 0f || npc.localAI[1] < 10f) { npc.chaseable = false; @@ -104,6 +118,7 @@ namespace CalamityMod.NPCs.AcidRain npc.ai[2] = 0f; npc.velocity.Y -= jumpSpeed; npc.velocity.X = lungeForwardSpeed * -npc.direction; + npc.netUpdate = true; } } else diff --git a/NPCs/AcidRain/GammaSlime.cs b/NPCs/AcidRain/GammaSlime.cs index 3f7b1ac83e..cbb96877a4 100644 --- a/NPCs/AcidRain/GammaSlime.cs +++ b/NPCs/AcidRain/GammaSlime.cs @@ -25,7 +25,7 @@ namespace CalamityMod.NPCs.AcidRain npc.width = 40; npc.height = 30; - npc.damage = 205; + npc.damage = 145; npc.lifeMax = 6410; npc.defense = 50; @@ -82,9 +82,10 @@ namespace CalamityMod.NPCs.AcidRain { float angle = MathHelper.TwoPi / 5f * i + (npc.ai[1] % 2) * MathHelper.PiOver2; Projectile.NewProjectile(npc.Center, angle.ToRotationVector2() * 7f, ModContent.ProjectileType(), - 40, 3f); + 45, 3f); } } + npc.netUpdate = true; } } else @@ -113,12 +114,12 @@ namespace CalamityMod.NPCs.AcidRain { angularMultiplier1 = Main.rand.NextFloat(3f); angularMultiplier2 = Main.rand.NextFloat(4f); + npc.netUpdate = true; if (Main.netMode != NetmodeID.MultiplayerClient) { Main.PlaySound(SoundID.Zombie, (int)npc.position.X, (int)npc.position.Y, 104); // Moon lord beam sound - Projectile.NewProjectile(npc.Center, -Vector2.UnitY, ModContent.ProjectileType(), 105, 4f, 0, 0f, npc.whoAmI); + Projectile.NewProjectile(npc.Center, -Vector2.UnitY, ModContent.ProjectileType(), 120, 4f, Main.myPlayer, 0f, npc.whoAmI); } - npc.netUpdate = true; } // Very complex particle effects while releasing the beam else if (npc.ai[3] >= 300f) @@ -143,6 +144,7 @@ namespace CalamityMod.NPCs.AcidRain Main.rand.NextBool(110)) { npc.ai[3] = 600f; + npc.netUpdate = true; } } diff --git a/NPCs/AcidRain/Orthocera.cs b/NPCs/AcidRain/Orthocera.cs index 957679679e..104b279fc0 100644 --- a/NPCs/AcidRain/Orthocera.cs +++ b/NPCs/AcidRain/Orthocera.cs @@ -31,7 +31,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.damage = 300; + npc.damage = 180; npc.lifeMax = 5700; npc.defense = 65; } diff --git a/NPCs/AcidRain/Skyfin.cs b/NPCs/AcidRain/Skyfin.cs index 4a3c88f04b..c6d681a293 100644 --- a/NPCs/AcidRain/Skyfin.cs +++ b/NPCs/AcidRain/Skyfin.cs @@ -33,7 +33,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.damage = 285; + npc.damage = 175; npc.lifeMax = 6300; npc.defense = 58; } diff --git a/NPCs/AcidRain/SulfurousSkater.cs b/NPCs/AcidRain/SulfurousSkater.cs index ed4c9fd208..32b2cc119c 100644 --- a/NPCs/AcidRain/SulfurousSkater.cs +++ b/NPCs/AcidRain/SulfurousSkater.cs @@ -30,7 +30,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.damage = 210; + npc.damage = 140; npc.lifeMax = 6600; npc.defense = 33; } @@ -89,7 +89,10 @@ namespace CalamityMod.NPCs.AcidRain if (npc.wet) { if (npc.velocity.Y >= 0f) + { npc.velocity.Y = -3f; + npc.netUpdate = true; + } } if (closestBubble != null && minimumDistance < 200f) @@ -99,8 +102,8 @@ namespace CalamityMod.NPCs.AcidRain if (closestBubble.Hitbox.Intersects(npc.Hitbox)) { npc.ai[0] = 1f; - npc.netUpdate = true; closestBubble.Kill(); + npc.netUpdate = true; } } if (npc.velocity.Y == 0f || npc.wet) @@ -108,18 +111,19 @@ namespace CalamityMod.NPCs.AcidRain npc.TargetClosest(false); npc.velocity.X *= 0.85f; npc.ai[1]++; - float lungeForwardSpeed = 13f; - float jumpSpeed = 3f; + float lungeForwardSpeed = 15f; + float jumpSpeed = 4f; if (Collision.CanHit(npc.Center, 1, 1, Main.player[npc.target].Center, 1, 1)) { lungeForwardSpeed *= 1.2f; } - if (npc.ai[1] >= 10) + if (npc.ai[1] >= 17) { npc.ai[1] = 0f; npc.velocity.Y -= jumpSpeed; npc.velocity.X = lungeForwardSpeed * (npc.Center.X - destination.X < 0).ToDirectionInt(); npc.spriteDirection = (npc.Center.X - destination.X < 0).ToDirectionInt(); + npc.netUpdate = true; } } else @@ -135,40 +139,21 @@ namespace CalamityMod.NPCs.AcidRain if (npc.Distance(player.Center) < 200f) inertia *= 0.667f; npc.velocity = (npc.velocity * inertia + npc.DirectionTo(player.Center) * speed) / (inertia + 1f); - - float SAImovement = 0.5f; - for (int index = 0; index < Main.npc.Length; index++) - { - NPC other = Main.npc[index]; - if (index != npc.whoAmI && - other.active && - other.type == npc.type && Math.Abs(npc.position.X - other.position.X) + Math.Abs(npc.position.Y - other.position.Y) < npc.width) - { - if (npc.position.X < other.position.X) - { - npc.velocity.X -= SAImovement; - } - else - { - npc.velocity.X += SAImovement; - } - if (npc.position.Y < other.position.Y) - { - npc.velocity.Y -= SAImovement; - } - else - { - npc.velocity.Y += SAImovement; - } - } - } npc.spriteDirection = (npc.velocity.X > 0).ToDirectionInt(); + if (player.dead && npc.Distance(player.Center) < 20f) + { + npc.ai[0] = 0f; + npc.netUpdate = true; + } } } public override void ModifyHitPlayer(Player target, ref int damage, ref bool crit) { if (npc.ai[0] != 0f) + { npc.ai[0] = 0f; + npc.netUpdate = true; + } } public override void FindFrame(int frameHeight) { diff --git a/NPCs/AcidRain/Trilobite.cs b/NPCs/AcidRain/Trilobite.cs index d7906039c5..be3833c619 100644 --- a/NPCs/AcidRain/Trilobite.cs +++ b/NPCs/AcidRain/Trilobite.cs @@ -34,7 +34,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.damage = 233; + npc.damage = 160; npc.lifeMax = 7200; npc.defense = 78; } diff --git a/NPCs/AcidRain/WaterLeech.cs b/NPCs/AcidRain/WaterLeech.cs index fc10202c9b..bbccc0ccc7 100644 --- a/NPCs/AcidRain/WaterLeech.cs +++ b/NPCs/AcidRain/WaterLeech.cs @@ -28,7 +28,7 @@ namespace CalamityMod.NPCs.AcidRain if (CalamityWorld.downedPolterghast) { - npc.damage = 315; + npc.damage = 172; npc.lifeMax = 4000; npc.defense = 30; } @@ -72,6 +72,7 @@ namespace CalamityMod.NPCs.AcidRain { // Revert back to swimming around after successfully devouring the player npc.ai[0] = 0f; + npc.netUpdate = true; return; } // Stick to player and make them bleed @@ -122,6 +123,7 @@ namespace CalamityMod.NPCs.AcidRain { npc.ai[0] = 1f; npc.ai[1] = 300f; + npc.netUpdate = true; } npc.velocity = (npc.velocity * (swimIntertia - 1f) + npc.DirectionTo(player.Center) * speed) / swimIntertia; } diff --git a/NPCs/CalamityAI.cs b/NPCs/CalamityAI.cs index 63994eacb8..c255833660 100644 --- a/NPCs/CalamityAI.cs +++ b/NPCs/CalamityAI.cs @@ -4301,6 +4301,7 @@ namespace CalamityMod.NPCs if (npc.timeLeft == 1) { CalamityWorld.acidRainPoints = 0; + CalamityWorld.triedToSummonOldDuke = false; AcidRainEvent.UpdateInvasion(false); npc.timeLeft = 0; } diff --git a/NPCs/CalamityGlobalNPCLoot.cs b/NPCs/CalamityGlobalNPCLoot.cs index c8de0f2322..21afa5576f 100644 --- a/NPCs/CalamityGlobalNPCLoot.cs +++ b/NPCs/CalamityGlobalNPCLoot.cs @@ -1612,6 +1612,7 @@ namespace CalamityMod.NPCs npc.type == ModContent.NPCType() && CalamityWorld.acidRainPoints <= 2f) { + CalamityWorld.triedToSummonOldDuke = false; CalamityWorld.acidRainPoints = 0; } AcidRainEvent.UpdateInvasion(); diff --git a/Projectiles/Boss/OverlyDramaticDukeSummoner.cs b/Projectiles/Boss/OverlyDramaticDukeSummoner.cs index c5ff4a0b6b..f6f350c300 100644 --- a/Projectiles/Boss/OverlyDramaticDukeSummoner.cs +++ b/Projectiles/Boss/OverlyDramaticDukeSummoner.cs @@ -127,7 +127,6 @@ namespace CalamityMod.Projectiles.Boss } if (Main.netMode != NetmodeID.MultiplayerClient) { - Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/OldDukeRoar").SoundId, (int)projectile.Top.X, (int)projectile.Top.Y, volumeScale: 1.45f); int boomer = NPC.NewNPC((int)projectile.Top.X, (int)projectile.Top.Y + 100, ModContent.NPCType()); string boomerName = Main.npc[boomer].TypeName; @@ -149,11 +148,14 @@ namespace CalamityMod.Projectiles.Boss Main.npc[boomer].alpha = 255; Main.npc[boomer].Calamity().newAI[3] = 1f; // To signal that Old Duke should not deccelerate as it normally would Main.npc[boomer].netUpdate = true; + CalamityWorld.triedToSummonOldDuke = true; + AcidRainEvent.UpdateInvasion(false); } } else { CalamityWorld.acidRainPoints = 0; + CalamityWorld.triedToSummonOldDuke = false; AcidRainEvent.UpdateInvasion(false); } } diff --git a/Waters/SulphuricWater.cs b/Waters/SulphuricWater.cs index e2557dc2cd..7a8b7c3179 100644 --- a/Waters/SulphuricWater.cs +++ b/Waters/SulphuricWater.cs @@ -1,3 +1,4 @@ +using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; using Terraria.ModLoader; @@ -8,7 +9,13 @@ namespace CalamityMod.Waters { public override bool ChooseWaterStyle() { - return Main.LocalPlayer.Calamity().ZoneSulphur; + bool inXZone = Main.LocalPlayer.Center.X < 10400f; + if (!CalamityWorld.abyssSide) + inXZone = Main.LocalPlayer.Center.X > Main.maxTilesX * 16f - 10400f; + + bool inYZone = Main.LocalPlayer.Center.Y < Main.rockLayer * 16f - 320 && Main.LocalPlayer.Center.Y >= 5800f; + + return (inXZone && inYZone) || Main.LocalPlayer.Calamity().ZoneSulphur; } public override int ChooseWaterfallStyle() diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index f0e170be53..bda08b59ab 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -107,6 +107,7 @@ namespace CalamityMod.World public static bool rainingAcid; public static int acidRainPoints = 0; public static int acidRainExtraDrawTime = 0; + public static bool triedToSummonOldDuke = false; public static float AcidRainCompletionRatio { get @@ -364,6 +365,8 @@ namespace CalamityMod.World downed.Add("eocRain"); if (downedAquaticScourgeAcidRain) downed.Add("hmRain"); + if (triedToSummonOldDuke) + downed.Add("spawnedBoomer"); return new TagCompound { @@ -431,6 +434,7 @@ namespace CalamityMod.World spawnedCirrus = downed.Contains("drunkPrincess"); downedEoCAcidRain = downed.Contains("eocRain"); downedAquaticScourgeAcidRain = downed.Contains("hmRain"); + triedToSummonOldDuke = downed.Contains("spawnedBoomer"); abyssChasmBottom = tag.GetInt("abyssChasmBottom"); acidRainPoints = tag.GetInt("acidRainPoints"); @@ -514,8 +518,9 @@ namespace CalamityMod.World downedCLAM = flags7[2]; dragonScalesBought = flags7[3]; rainingAcid = flags7[4]; - downedEoCAcidRain = flags[5]; - downedAquaticScourgeAcidRain = flags[6]; + downedEoCAcidRain = flags7[5]; + downedAquaticScourgeAcidRain = flags7[6]; + triedToSummonOldDuke = flags7[7]; } else { @@ -597,6 +602,7 @@ namespace CalamityMod.World flags7[4] = rainingAcid; flags7[5] = downedEoCAcidRain; flags7[6] = downedAquaticScourgeAcidRain; + flags7[7] = triedToSummonOldDuke; writer.Write(flags); writer.Write(flags2); @@ -681,8 +687,9 @@ namespace CalamityMod.World downedCLAM = flags7[2]; dragonScalesBought = flags7[3]; rainingAcid = flags7[4]; - downedEoCAcidRain = flags[5]; - downedAquaticScourgeAcidRain = flags[6]; + downedEoCAcidRain = flags7[5]; + downedAquaticScourgeAcidRain = flags7[6]; + triedToSummonOldDuke = flags7[7]; abyssChasmBottom = reader.ReadInt32(); acidRainPoints = reader.ReadInt32(); @@ -919,12 +926,21 @@ namespace CalamityMod.World !NPC.AnyNPCs(ModContent.NPCType()) && CalamityUtils.CountProjectiles(ModContent.ProjectileType()) <= 0) { - int playerClosestToAbyss = Player.FindClosest(new Vector2(abyssSide ? 0 : Main.maxTilesX * 16, (int)Main.worldSurface), 0, 0); - Player closestToAbyss = Main.player[playerClosestToAbyss]; - if (Main.netMode != NetmodeID.MultiplayerClient && Math.Abs(closestToAbyss.Center.X - (abyssSide ? 0 : Main.maxTilesX * 16)) <= 12000f) + if (triedToSummonOldDuke) { - Projectile.NewProjectile(closestToAbyss.Center + Vector2.UnitY * 160f, Vector2.Zero, - ModContent.ProjectileType(), 120, 8f); + acidRainPoints = 0; + triedToSummonOldDuke = false; + AcidRainEvent.UpdateInvasion(false); + } + else + { + int playerClosestToAbyss = Player.FindClosest(new Vector2(abyssSide ? 0 : Main.maxTilesX * 16, (int)Main.worldSurface), 0, 0); + Player closestToAbyss = Main.player[playerClosestToAbyss]; + if (Main.netMode != NetmodeID.MultiplayerClient && Math.Abs(closestToAbyss.Center.X - (abyssSide ? 0 : Main.maxTilesX * 16)) <= 12000f) + { + Projectile.NewProjectile(closestToAbyss.Center + Vector2.UnitY * 160f, Vector2.Zero, + ModContent.ProjectileType(), 120, 8f, Main.myPlayer); + } } } }