diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index de3ff2cad0..0dcb703949 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -216,6 +216,9 @@ namespace CalamityMod int type = reader.ReadInt32(); CalamityWorld.bossType = type; break; + case CalamityModMessageType.EndBossRush: + BossRushEvent.EndEffects(); + break; case CalamityModMessageType.BRHostileProjKillSync: int countdown3 = reader.ReadInt32(); CalamityWorld.bossRushHostileProjKillCounter = countdown3; @@ -240,6 +243,17 @@ namespace CalamityMod CalamityWorld.encounteredOldDuke = reader.ReadBoolean(); break; + // + // Draedon Summoner stuff + // + case CalamityModMessageType.CodebreakerSummonStuff: + CalamityWorld.DraedonSummonCountdown = reader.ReadInt32(); + CalamityWorld.DraedonSummonPosition = reader.ReadVector2(); + break; + case CalamityModMessageType.ExoMechSelection: + CalamityWorld.DraedonMechToSummon = (ExoMech)reader.ReadInt32(); + break; + // // Death Mode environmental syncs // @@ -359,12 +373,17 @@ namespace CalamityMod UpdateCodebreakerContainedStuff, UpdateCodebreakerDecryptCountdown, + // Draedon Summoner + CodebreakerSummonStuff, + ExoMechSelection, + // Boss Rush BossRushStage, BossRushStartTimer, BossRushEndTimer, BossSpawnCountdownSync, BossTypeSync, + EndBossRush, BRHostileProjKillSync, // TODO -- Simplify this. Only one packet needs be sent: "kill all hostile projectiles for N frames". TeleportPlayer, // also used by Astral Arcanum. diff --git a/Events/BossRushEvent.cs b/Events/BossRushEvent.cs index 65f38669fb..bcef047dd4 100644 --- a/Events/BossRushEvent.cs +++ b/Events/BossRushEvent.cs @@ -469,8 +469,21 @@ namespace CalamityMod.Events } public static void End() + { + if (Main.netMode == NetmodeID.SinglePlayer) + { + EndEffects(); + return; + } + + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.EndBossRush); + netMessage.Send(); + } + + internal static void EndEffects() { - for (int doom = 0; doom < 200; doom++) + for (int doom = 0; doom < Main.maxNPCs; doom++) { NPC n = Main.npc[doom]; if (!n.active) @@ -480,29 +493,18 @@ namespace CalamityMod.Events bool shouldDespawn = n.boss || n.type == NPCID.EaterofWorldsHead || n.type == NPCID.EaterofWorldsBody || n.type == NPCID.EaterofWorldsTail; if (shouldDespawn) { + n.life = 0; + n.HitEffect(); + n.checkDead(); n.active = false; - n.netUpdate = true; } } BossRushActive = false; BossRushStage = 0; + StartTimer = 0; + EndTimer = 0; CalamityUtils.KillAllHostileProjectiles(); - - CalamityNetcode.SyncWorld(); - if (Main.netMode != NetmodeID.MultiplayerClient) - { - SyncStartTimer(0); - SyncEndTimer(0); - } - - if (Main.netMode == NetmodeID.Server) - { - var netMessage = CalamityMod.Instance.GetPacket(); - netMessage.Write((byte)CalamityModMessageType.BossRushStage); - netMessage.Write(BossRushStage); - netMessage.Send(); - } } #endregion diff --git a/NPCs/ExoMechs/Draedon.cs b/NPCs/ExoMechs/Draedon.cs index 89c62c9f1b..939a868631 100644 --- a/NPCs/ExoMechs/Draedon.cs +++ b/NPCs/ExoMechs/Draedon.cs @@ -314,8 +314,9 @@ namespace CalamityMod.NPCs.ExoMechs public override void FindFrame(int frameHeight) { npc.frame.Width = 102; + int xFrame = npc.frame.X / npc.frame.Width; - int yFrame = npc.frame.Y / npc.frame.Height; + int yFrame = npc.frame.Y / frameHeight; int frame = xFrame * Main.npcFrameCount[npc.type] + yFrame; // Prepare to stand up if called for and not already doing so. @@ -347,7 +348,7 @@ namespace CalamityMod.NPCs.ExoMechs } npc.frame.X = frame / Main.npcFrameCount[npc.type] * npc.frame.Width; - npc.frame.Y = frame % Main.npcFrameCount[npc.type] * npc.frame.Height; + npc.frame.Y = frame % Main.npcFrameCount[npc.type] * frameHeight; } public override void ScaleExpertStats(int numPlayers, float bossLifeScale) diff --git a/NPCs/Leviathan/Siren.cs b/NPCs/Leviathan/Siren.cs index 46b6f581b5..942a59a2c7 100644 --- a/NPCs/Leviathan/Siren.cs +++ b/NPCs/Leviathan/Siren.cs @@ -74,6 +74,7 @@ namespace CalamityMod.NPCs.Leviathan writer.Write(frameUsed); writer.Write(npc.dontTakeDamage); writer.Write(npc.Calamity().newAI[0]); + writer.Write(HasBegunSummoningLeviathan); } public override void ReceiveExtraAI(BinaryReader reader) @@ -86,6 +87,7 @@ namespace CalamityMod.NPCs.Leviathan frameUsed = reader.ReadInt32(); npc.dontTakeDamage = reader.ReadBoolean(); npc.Calamity().newAI[0] = reader.ReadSingle(); + HasBegunSummoningLeviathan = reader.ReadBoolean(); } public override void AI() diff --git a/NPCs/TownNPCs/FAP.cs b/NPCs/TownNPCs/FAP.cs index f874d3d9cc..fea1887bee 100644 --- a/NPCs/TownNPCs/FAP.cs +++ b/NPCs/TownNPCs/FAP.cs @@ -132,7 +132,8 @@ namespace CalamityMod.NPCs.TownNPCs dialogue.Add("Are you sure you're 21? ...alright, fine, but don't tell anyone I sold you this."); } - dialogue.Add("Drink something that turns you into a magical flying unicorn so you can be super gay."); + dialogue.Add("I HATE WALMART!"); + dialogue.Add("Drink something that turns you into a magical flying unicorn so you can be super gay."); dialogue.Add("Did anyone ever tell you that large assets cause back pain? Well, they were right."); if (BirthdayParty.PartyIsUp) diff --git a/Projectiles/Boss/SCalRitualDrama.cs b/Projectiles/Boss/SCalRitualDrama.cs index eb6ca69f86..d83f316ede 100644 --- a/Projectiles/Boss/SCalRitualDrama.cs +++ b/Projectiles/Boss/SCalRitualDrama.cs @@ -12,7 +12,6 @@ namespace CalamityMod.Projectiles.Boss { public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; public ref float Time => ref projectile.ai[0]; - public const int PulseTime = 45; public const int TotalRitualTime = 270; public override void SetStaticDefaults() => DisplayName.SetDefault("Calamitous Ritual Drama"); @@ -21,18 +20,32 @@ namespace CalamityMod.Projectiles.Boss projectile.width = projectile.height = 2; projectile.tileCollide = false; projectile.ignoreWater = true; - projectile.timeLeft = TotalRitualTime; + projectile.timeLeft = TotalRitualTime + 420; } - public override void AI() - { - SCalSky.OverridingIntensity = Utils.InverseLerp(90f, TotalRitualTime - 25f, Time, true); - Main.LocalPlayer.Calamity().GeneralScreenShakePower = Utils.InverseLerp(90f, TotalRitualTime - 25f, Time, true); - Main.LocalPlayer.Calamity().GeneralScreenShakePower *= Utils.InverseLerp(3400f, 1560f, Main.LocalPlayer.Distance(projectile.Center), true) * 4f; + public override void AI() + { + // If needed, these effects may continue after the ritual timer, to ensure that there are no awkward + // background changes between the time it takes for SCal to appear after this projectile is gone. + // If SCal is already present, this does not happen. + if (!NPC.AnyNPCs(ModContent.NPCType())) + { + SCalSky.OverridingIntensity = Utils.InverseLerp(90f, TotalRitualTime - 25f, Time, true); + Main.LocalPlayer.Calamity().GeneralScreenShakePower = Utils.InverseLerp(90f, TotalRitualTime - 25f, Time, true); + Main.LocalPlayer.Calamity().GeneralScreenShakePower *= Utils.InverseLerp(3400f, 1560f, Main.LocalPlayer.Distance(projectile.Center), true) * 4f; + } + + // Summon SCal right before the ritual effect ends. + // The projectile lingers a little longer, however, to ensure that desync delays in MP do not interfere with the background transition. + if (Time == TotalRitualTime - 1f) + SummonSCal(); + + if (Time >= TotalRitualTime) + return; int fireReleaseRate = Time > 150f ? 2 : 1; for (int i = 0; i < fireReleaseRate; i++) - { + { if (Main.rand.NextBool(4)) { Dust brimstone = Dust.NewDustPerfect(projectile.Center + new Vector2(Main.rand.NextFloat(-20f, 24f), Main.rand.NextFloat(10f, 18f)), 267); @@ -45,19 +58,22 @@ namespace CalamityMod.Projectiles.Boss } Time++; - } + } - public override void Kill(int timeLeft) - { + public void SummonSCal() + { + // Summon SCal serverside. + // All the other acoustic and visual effects can happen client-side. if (Main.netMode != NetmodeID.MultiplayerClient) CalamityUtils.SpawnBossBetter(projectile.Center - new Vector2(60f), ModContent.NPCType()); // Make a laugh sound and create a burst of brimstone dust. Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/Custom/SupremeCalamitasSpawn"), projectile.Center); + // Make a sudden screen shake. Main.LocalPlayer.Calamity().GeneralScreenShakePower = Utils.InverseLerp(3400f, 1560f, Main.LocalPlayer.Distance(projectile.Center), true) * 16f; - // Generate a dust explosion + // Generate a dust explosion at the ritual's position. float burstDirectionVariance = 3; float burstSpeed = 14f; for (int j = 0; j < 16; j++) @@ -74,5 +90,5 @@ namespace CalamityMod.Projectiles.Boss burstSpeed += 1.8f; } } - } + } } diff --git a/TileEntities/TECodebreaker.cs b/TileEntities/TECodebreaker.cs index 94bc3632f8..231a3943fb 100644 --- a/TileEntities/TECodebreaker.cs +++ b/TileEntities/TECodebreaker.cs @@ -184,6 +184,7 @@ namespace CalamityMod.TileEntities packet.Write((byte)CalamityModMessageType.UpdateCodebreakerConstituents); packet.Write(ID); packet.Write(containmentFlagWrapper); + packet.Send(); } public static void ReadConstituentsUpdateSync(Mod mod, BinaryReader reader) @@ -228,6 +229,7 @@ namespace CalamityMod.TileEntities packet.Write(InputtedCellCount); packet.Write(InitialCellCountBeforeDecrypting); packet.Write(HeldSchematicID); + packet.Send(); } public static void ReadContainmentSync(Mod mod, BinaryReader reader) @@ -265,6 +267,7 @@ namespace CalamityMod.TileEntities packet.Write((byte)CalamityModMessageType.UpdateCodebreakerDecryptCountdown); packet.Write(ID); packet.Write(DecryptionCountdown); + packet.Send(); } public static void ReadDecryptCountdownSync(Mod mod, BinaryReader reader) diff --git a/UI/CodebreakerUI.cs b/UI/CodebreakerUI.cs index 7c713ddeb9..68fee2d7d9 100644 --- a/UI/CodebreakerUI.cs +++ b/UI/CodebreakerUI.cs @@ -434,7 +434,11 @@ namespace CalamityMod.UI CalamityWorld.DraedonSummonCountdown = CalamityWorld.DraedonSummonCountdownMax; CalamityWorld.DraedonSummonPosition = codebreakerTileEntity.Center + new Vector2(-8f, -100f); - CalamityNetcode.SyncWorld(); + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.CodebreakerSummonStuff); + netMessage.Write(CalamityWorld.DraedonSummonCountdown); + netMessage.WriteVector2(CalamityWorld.DraedonSummonPosition); + netMessage.Send(); } } diff --git a/UI/ExoMechSelectionUI.cs b/UI/ExoMechSelectionUI.cs index 13963df5a5..6f272e7235 100644 --- a/UI/ExoMechSelectionUI.cs +++ b/UI/ExoMechSelectionUI.cs @@ -76,7 +76,11 @@ namespace CalamityMod.UI if (Main.mouseLeft && Main.mouseLeftRelease) { CalamityWorld.DraedonMechToSummon = exoMech; - CalamityNetcode.SyncWorld(); + + var netMessage = CalamityMod.Instance.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.ExoMechSelection); + netMessage.Write((int)CalamityWorld.DraedonMechToSummon); + netMessage.Send(); } Main.blockMouse = Main.LocalPlayer.mouseInterface = true; } diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index 862d2bdf8b..8d84a74198 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -892,6 +892,11 @@ namespace CalamityMod.World writer.Write(DraedonSummonCountdown); writer.Write((int)DraedonMechToSummon); writer.WriteVector2(DraedonSummonPosition); + writer.WriteVector2(SunkenSeaLabCenter); + writer.WriteVector2(PlanetoidLabCenter); + writer.WriteVector2(JungleLabCenter); + writer.WriteVector2(HellLabCenter); + writer.WriteVector2(IceLabCenter); } #endregion @@ -1014,6 +1019,11 @@ namespace CalamityMod.World DraedonSummonCountdown = reader.ReadInt32(); DraedonMechToSummon = (ExoMech)reader.ReadInt32(); DraedonSummonPosition = reader.ReadVector2(); + SunkenSeaLabCenter = reader.ReadVector2(); + PlanetoidLabCenter = reader.ReadVector2(); + JungleLabCenter = reader.ReadVector2(); + HellLabCenter = reader.ReadVector2(); + IceLabCenter = reader.ReadVector2(); } #endregion diff --git a/World/WorldUpdateMiscEffects.cs b/World/WorldUpdateMiscEffects.cs index e20d4186d8..1b15bbfedb 100644 --- a/World/WorldUpdateMiscEffects.cs +++ b/World/WorldUpdateMiscEffects.cs @@ -39,13 +39,10 @@ namespace CalamityMod.World public static void PerformWorldUpdates() { // Reset the exo mech to summon if Draedon is absent. - if (Main.netMode != NetmodeID.MultiplayerClient && DraedonMechToSummon != ExoMech.None && CalamityGlobalNPC.draedon == -1) - { + if (DraedonMechToSummon != ExoMech.None && CalamityGlobalNPC.draedon == -1) DraedonMechToSummon = ExoMech.None; - CalamityNetcode.SyncWorld(); - } - if (DraedonSummonCountdown > 0) + if (Main.netMode != NetmodeID.MultiplayerClient && DraedonSummonCountdown > 0) { DraedonSummonCountdown--; HandleDraedonSummoning(); @@ -131,11 +128,11 @@ namespace CalamityMod.World public static void HandleDraedonSummoning() { // Fire a giant laser into the sky. - if (Main.netMode != NetmodeID.MultiplayerClient && DraedonSummonCountdown == DraedonSummonCountdownMax - 45) + if (DraedonSummonCountdown == DraedonSummonCountdownMax - 45) Projectile.NewProjectile(DraedonSummonPosition + Vector2.UnitY * 80f, Vector2.Zero, ModContent.ProjectileType(), 70, 0f); if (DraedonSummonCountdown == 0) - NPC.NewNPC((int)DraedonSummonPosition.X, (int)DraedonSummonPosition.Y, ModContent.NPCType(), 0, 0f, (int)DraedonMechToSummon); + NPC.NewNPC((int)DraedonSummonPosition.X, (int)DraedonSummonPosition.Y, ModContent.NPCType()); } #endregion Handle Draedon Summoning