Fixed Prov and DoG not dropping items in MP

This commit is contained in:
Dominic committed 2022-03-17 23:55:47 -05:00
1 parent 4075f7f8c9
commit 7c60dfe73f
4 files changed
+94 -57

No files matched your search

+34 -25
View File
@@ -197,28 +197,32 @@ namespace CalamityMod.NPCs.DevourerofGods
{
if (Main.npc[(int)npc.ai[2]].ModNPC<DevourerofGodsHead>()?.AttemptingToEnterPortal ?? false)
{
Projectile portal = Main.projectile[Main.npc[(int)npc.ai[2]].ModNPC<DevourerofGodsHead>().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<DevourerofGodsHead>().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<DevourerofGodsHead>().Dying))
{
if (npc.realLife >= 0 && !Main.npc[npc.realLife].ModNPC<DevourerofGodsHead>().Dying)
if (npc.realLife >= 0)
{
damage = 0D;
npc.dontTakeDamage = true;
Main.npc[npc.realLife].ModNPC<DevourerofGodsHead>().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<DevourerofGodsHead>().Dying)
{
Main.npc[npc.realLife].ModNPC<DevourerofGodsHead>().Dying = true;
Main.npc[npc.realLife].dontTakeDamage = true;
Main.npc[npc.realLife].active = true;
Main.npc[npc.realLife].netUpdate = true;
}
}
return false;
}
@@ -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)
+37 -28
View File
@@ -217,28 +217,32 @@ namespace CalamityMod.NPCs.DevourerofGods
{
if (Main.npc[(int)npc.ai[2]].ModNPC<DevourerofGodsHead>()?.AttemptingToEnterPortal ?? false)
{
Projectile portal = Main.projectile[Main.npc[(int)npc.ai[2]].ModNPC<DevourerofGodsHead>().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<DevourerofGodsHead>().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<DevourerofGodsHead>().Dying))
{
if (npc.realLife >= 0 && !Main.npc[npc.realLife].ModNPC<DevourerofGodsHead>().Dying)
if (npc.realLife >= 0)
{
damage = 0D;
npc.dontTakeDamage = true;
Main.npc[npc.realLife].ModNPC<DevourerofGodsHead>().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<DevourerofGodsHead>().Dying)
{
Main.npc[npc.realLife].ModNPC<DevourerofGodsHead>().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()
+14 -4
View File
@@ -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;
}