From 7c60dfe73f63dd7ffbb873d2c157a14ccdf91445 Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 17 Mar 2022 23:55:47 -0500 Subject: [PATCH] Fixed Prov and DoG not dropping items in MP --- NPCs/DevourerofGods/DevourerofGodsBody.cs | 59 +++++++++++--------- NPCs/DevourerofGods/DevourerofGodsHead.cs | 9 ++++ NPCs/DevourerofGods/DevourerofGodsTail.cs | 65 +++++++++++++---------- NPCs/Providence/Providence.cs | 18 +++++-- 4 files changed, 94 insertions(+), 57 deletions(-) diff --git a/NPCs/DevourerofGods/DevourerofGodsBody.cs b/NPCs/DevourerofGods/DevourerofGodsBody.cs index 15a3d1de45..356dcb1735 100644 --- a/NPCs/DevourerofGods/DevourerofGodsBody.cs +++ b/NPCs/DevourerofGods/DevourerofGodsBody.cs @@ -197,28 +197,32 @@ namespace CalamityMod.NPCs.DevourerofGods { if (Main.npc[(int)npc.ai[2]].ModNPC()?.AttemptingToEnterPortal ?? false) { - Projectile portal = Main.projectile[Main.npc[(int)npc.ai[2]].ModNPC().PortalIndex]; - float newOpacity = 1f - Utils.InverseLerp(270f, 100f, npc.Distance(portal.Center), true); - if (Main.netMode != NetmodeID.MultiplayerClient && newOpacity > 0f && npc.Opacity > newOpacity) + if (Main.netMode != NetmodeID.MultiplayerClient) { - npc.Opacity = newOpacity; - - // Create dust at the portal position. - if (Vector2.Dot((npc.rotation - MathHelper.PiOver2).ToRotationVector2(), Main.npc[(int)npc.ai[2]].velocity) > 0f) + Projectile portal = Main.projectile[Main.npc[(int)npc.ai[2]].ModNPC().PortalIndex]; + float newOpacity = 1f - Utils.InverseLerp(270f, 100f, npc.Distance(portal.Center), true); + if (newOpacity > 0f && npc.Opacity > newOpacity) { - for (int i = 0; i < 2; i++) - { - Dust cosmicMagic = Dust.NewDustPerfect(portal.Center, Main.rand.NextBool() ? 180 : 173); - cosmicMagic.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(2f, 8f); - cosmicMagic.scale *= Main.rand.NextFloat(1f, 1.8f); - cosmicMagic.noGravity = true; - } - } - npc.netUpdate = true; - } + npc.Opacity = newOpacity; - if (npc.Opacity < 0.2f) - npc.Opacity = 0f; + // Create dust at the portal position. + if (Vector2.Dot((npc.rotation - MathHelper.PiOver2).ToRotationVector2(), Main.npc[(int)npc.ai[2]].velocity) > 0f) + { + for (int i = 0; i < 2; i++) + { + Dust cosmicMagic = Dust.NewDustPerfect(portal.Center, Main.rand.NextBool() ? 180 : 173); + cosmicMagic.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(2f, 8f); + cosmicMagic.scale *= Main.rand.NextFloat(1f, 1.8f); + cosmicMagic.noGravity = true; + } + } + + if (npc.Opacity < 0.2f) + npc.Opacity = 0f; + + npc.netUpdate = true; + } + } } else npc.alpha = Main.npc[(int)npc.ai[2]].alpha; @@ -333,17 +337,22 @@ namespace CalamityMod.NPCs.DevourerofGods public override bool StrikeNPC(ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit) { - if ((damage * (crit ? 2D : 1D)) >= npc.life) + if ((damage * (crit ? 2D : 1D)) >= npc.life || (npc.realLife >= 0 && Main.npc[npc.realLife].ModNPC().Dying)) { - if (npc.realLife >= 0 && !Main.npc[npc.realLife].ModNPC().Dying) + if (npc.realLife >= 0) { damage = 0D; npc.dontTakeDamage = true; - Main.npc[npc.realLife].ModNPC().Dying = true; - Main.npc[npc.realLife].life = 1; Main.npc[npc.realLife].dontTakeDamage = true; - Main.npc[npc.realLife].active = true; - Main.npc[npc.realLife].netUpdate = true; + Main.npc[npc.realLife].life = 1; + + if (!Main.npc[npc.realLife].ModNPC().Dying) + { + Main.npc[npc.realLife].ModNPC().Dying = true; + Main.npc[npc.realLife].dontTakeDamage = true; + Main.npc[npc.realLife].active = true; + Main.npc[npc.realLife].netUpdate = true; + } } return false; } diff --git a/NPCs/DevourerofGods/DevourerofGodsHead.cs b/NPCs/DevourerofGods/DevourerofGodsHead.cs index 6781b9a93c..97cbab0edd 100644 --- a/NPCs/DevourerofGods/DevourerofGodsHead.cs +++ b/NPCs/DevourerofGods/DevourerofGodsHead.cs @@ -179,6 +179,8 @@ namespace CalamityMod.NPCs.DevourerofGods public override void SendExtraAI(BinaryWriter writer) { + bool wasDyingBefore = Dying; + // Phase 1 syncs writer.Write(npc.dontTakeDamage); writer.Write(spawnedGuardians); @@ -211,6 +213,13 @@ namespace CalamityMod.NPCs.DevourerofGods writer.Write(Dying); writer.Write(DeathAnimationTimer); writer.Write(DestroyedSegmentCount); + + // Be sure to inform clients of the fact that The Devourer of Gods is dying if only the server recieved this packet. + if (Main.netMode == NetmodeID.Server && !wasDyingBefore && Dying) + { + npc.netSpam = 0; + npc.netUpdate = true; + } } public override void ReceiveExtraAI(BinaryReader reader) diff --git a/NPCs/DevourerofGods/DevourerofGodsTail.cs b/NPCs/DevourerofGods/DevourerofGodsTail.cs index 83297d6003..b3d4e26723 100644 --- a/NPCs/DevourerofGods/DevourerofGodsTail.cs +++ b/NPCs/DevourerofGods/DevourerofGodsTail.cs @@ -217,28 +217,32 @@ namespace CalamityMod.NPCs.DevourerofGods { if (Main.npc[(int)npc.ai[2]].ModNPC()?.AttemptingToEnterPortal ?? false) { - Projectile portal = Main.projectile[Main.npc[(int)npc.ai[2]].ModNPC().PortalIndex]; - float newOpacity = 1f - Utils.InverseLerp(200f, 130f, npc.Distance(portal.Center), true); - if (Main.netMode != NetmodeID.MultiplayerClient && newOpacity > 0f && npc.Opacity > newOpacity) + if (Main.netMode != NetmodeID.MultiplayerClient) { - npc.Opacity = newOpacity; - - // Create dust at the portal position. - if (Vector2.Dot((npc.rotation - MathHelper.PiOver2).ToRotationVector2(), Main.npc[(int)npc.ai[2]].velocity) > 0f) + Projectile portal = Main.projectile[Main.npc[(int)npc.ai[2]].ModNPC().PortalIndex]; + float newOpacity = 1f - Utils.InverseLerp(270f, 100f, npc.Distance(portal.Center), true); + if (newOpacity > 0f && npc.Opacity > newOpacity) { - for (int i = 0; i < 2; i++) - { - Dust cosmicMagic = Dust.NewDustPerfect(portal.Center, Main.rand.NextBool() ? 180 : 173); - cosmicMagic.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(2f, 8f); - cosmicMagic.scale *= Main.rand.NextFloat(1f, 1.8f); - cosmicMagic.noGravity = true; - } - } - npc.netUpdate = true; - } + npc.Opacity = newOpacity; - if (npc.Opacity < 0.2f) - npc.Opacity = 0f; + // Create dust at the portal position. + if (Vector2.Dot((npc.rotation - MathHelper.PiOver2).ToRotationVector2(), Main.npc[(int)npc.ai[2]].velocity) > 0f) + { + for (int i = 0; i < 2; i++) + { + Dust cosmicMagic = Dust.NewDustPerfect(portal.Center, Main.rand.NextBool() ? 180 : 173); + cosmicMagic.velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(2f, 8f); + cosmicMagic.scale *= Main.rand.NextFloat(1f, 1.8f); + cosmicMagic.noGravity = true; + } + } + + if (npc.Opacity < 0.2f) + npc.Opacity = 0f; + + npc.netUpdate = true; + } + } } else npc.alpha = Main.npc[(int)npc.ai[2]].alpha; @@ -385,22 +389,27 @@ namespace CalamityMod.NPCs.DevourerofGods } public override bool StrikeNPC(ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit) - { - if ((damage * (crit ? 2D : 1D)) >= npc.life) + { + if ((damage * (crit ? 2D : 1D)) >= npc.life || (npc.realLife >= 0 && Main.npc[npc.realLife].ModNPC().Dying)) { - if (npc.realLife >= 0 && !Main.npc[npc.realLife].ModNPC().Dying) + if (npc.realLife >= 0) { damage = 0D; npc.dontTakeDamage = true; - Main.npc[npc.realLife].ModNPC().Dying = true; - Main.npc[npc.realLife].life = 1; Main.npc[npc.realLife].dontTakeDamage = true; - Main.npc[npc.realLife].active = true; - Main.npc[npc.realLife].netUpdate = true; + Main.npc[npc.realLife].life = 1; + + if (!Main.npc[npc.realLife].ModNPC().Dying) + { + Main.npc[npc.realLife].ModNPC().Dying = true; + Main.npc[npc.realLife].dontTakeDamage = true; + Main.npc[npc.realLife].active = true; + Main.npc[npc.realLife].netUpdate = true; + } } return false; - } - return true; + } + return true; } public override bool CheckDead() diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 8bea978483..35acfe9457 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -133,6 +133,7 @@ namespace CalamityMod.NPCs.Providence public override void ReceiveExtraAI(BinaryReader reader) { + bool wasDyingBefore = Dying; text = reader.ReadBoolean(); useDefenseFrames = reader.ReadBoolean(); biomeType = reader.ReadInt32(); @@ -149,6 +150,13 @@ namespace CalamityMod.NPCs.Providence DeathAnimationTimer = reader.ReadInt32(); for (int i = 0; i < 4; i++) npc.Calamity().newAI[i] = reader.ReadSingle(); + + // Be sure to inform clients of the fact that Providence is dying if only the server recieved this packet. + if (Main.netMode == NetmodeID.Server && !wasDyingBefore && Dying) + { + npc.netSpam = 0; + npc.netUpdate = true; + } } public override void AI() @@ -1883,8 +1891,6 @@ namespace CalamityMod.NPCs.Providence { DespawnSpecificProjectiles(true); Dying = true; - npc.life = 1; - npc.dontTakeDamage = true; npc.active = true; npc.netUpdate = true; } @@ -1893,10 +1899,14 @@ namespace CalamityMod.NPCs.Providence public override bool StrikeNPC(ref double damage, int defense, ref float knockback, int hitDirection, ref bool crit) { - if (!Dying && (damage * (crit ? 2D : 1D)) >= npc.life) + if ((damage * (crit ? 2D : 1D)) >= npc.life) { damage = 0D; - CheckDead(); + + npc.life = 1; + npc.dontTakeDamage = true; + if (!Dying) + CheckDead(); return false; }