Fix Deus and Levi MP issues

This commit is contained in:
Cameron Ewell authored and GitHub committed 2020-09-20 23:27:58 -04:00
commit 982eb4265a
4 files changed
+116 -64

No files matched your search

+20 -5
View File
@@ -1,4 +1,5 @@
using CalamityMod.Events;
using CalamityMod.NPCs;
using CalamityMod.NPCs.NormalNPCs;
using CalamityMod.NPCs.Providence;
using CalamityMod.TileEntities;
@@ -165,13 +166,27 @@ namespace CalamityMod
TELabHologramProjector.ReadSyncPacket(mod, reader);
break;
// This code has been edited to fail gracefully when trying to provide data for an invalid NPC.
case CalamityModMessageType.SyncCalamityNPCAIArray:
byte npcIndex2 = reader.ReadByte();
Main.npc[npcIndex2].Calamity().newAI[0] = reader.ReadSingle();
Main.npc[npcIndex2].Calamity().newAI[1] = reader.ReadSingle();
Main.npc[npcIndex2].Calamity().newAI[2] = reader.ReadSingle();
Main.npc[npcIndex2].Calamity().newAI[3] = reader.ReadSingle();
// Read the entire packet regardless of anything
byte npcIdx = reader.ReadByte();
float ai0 = reader.ReadSingle();
float ai1 = reader.ReadSingle();
float ai2 = reader.ReadSingle();
float ai3 = reader.ReadSingle();
// If the NPC in question isn't valid, don't do anything.
NPC npc = Main.npc[npcIdx];
if (!npc.active)
break;
CalamityGlobalNPC cgn = npc.Calamity();
cgn.newAI[0] = ai0;
cgn.newAI[1] = ai1;
cgn.newAI[2] = ai2;
cgn.newAI[3] = ai3;
break;
case CalamityModMessageType.ProvidenceDyeConditionSync:
byte npcIndex3 = reader.ReadByte();
(Main.npc[npcIndex3].modNPC as Providence).hasTakenDaytimeDamage = reader.ReadBoolean();
+16 -8
View File
@@ -194,13 +194,7 @@ namespace CalamityMod.NPCs.AstrumDeus
}
}
public override void BossLoot(ref string name, ref int potionType)
{
if (npc.Calamity().newAI[0] == 0f)
return;
potionType = ModContent.ItemType<Stardust>();
}
public override void BossLoot(ref string name, ref int potionType) => potionType = ModContent.ItemType<Stardust>();
public override bool SpecialNPCLoot()
{
@@ -217,9 +211,23 @@ namespace CalamityMod.NPCs.AstrumDeus
public override void NPCLoot()
{
if (npc.Calamity().newAI[0] == 0f)
// Unsplit Deus does not drop anything when killed/despawned.
if (npc.Calamity().newAI[0] == 0f)
return;
// Killing ANY split Deus makes all other Deus heads die immediately.
for (int i = 0; i < Main.maxNPCs; ++i)
{
NPC otherWormHead = Main.npc[i];
if (otherWormHead.active && otherWormHead.type == npc.type)
{
// Kill the other worm head after setting it to not drop loot.
otherWormHead.Calamity().newAI[0] = 0f;
otherWormHead.life = 0;
otherWormHead.checkDead();
}
}
DropHelper.DropBags(npc);
DropHelper.DropItem(npc, ItemID.GreaterHealingPotion, 8, 14);
+72 -44
View File
@@ -2880,56 +2880,84 @@ namespace CalamityMod.NPCs
bool despawning = calamityGlobalNPC.newAI[2] == splitAnimationTime;
//
// CODE TWEAKED BY: OZZATRON
// September 20th, 2020
// reason: fixing Astrum Deus death mode NPC cap bug
//
// Despawn the unsplit Astrum Deus and spawn two half-size Astrum Deus worms.
if (despawning)
{
if (!doubleWormPhase)
{
if (Main.netMode != NetmodeID.MultiplayerClient)
{
int startCount = npc.whoAmI + phase1Length + 1;
int npc2 = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, npc.type, startCount);
Main.npc[npc2].Calamity().newAI[0] = 1f;
Main.npc[npc2].velocity = Vector2.Normalize(player.Center - Main.npc[npc2].Center) * 16f;
Main.npc[npc2].timeLeft *= 20;
Main.npc[npc2].netUpdate = true;
if (Main.netMode == NetmodeID.Server)
{
var netMessage = mod.GetPacket();
netMessage.Write((byte)CalamityModMessageType.SyncCalamityNPCAIArray);
netMessage.Write((byte)npc2);
netMessage.Write(Main.npc[npc2].Calamity().newAI[0]);
netMessage.Write(Main.npc[npc2].Calamity().newAI[1]);
netMessage.Write(Main.npc[npc2].Calamity().newAI[2]);
netMessage.Write(Main.npc[npc2].Calamity().newAI[3]);
netMessage.Send();
}
// If this is already a split worm (newAI[0] != 0f) then don't do anything. At all.
if (doubleWormPhase)
return;
int npc3 = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, npc.type, startCount + phase2Length + 1);
Main.npc[npc3].Calamity().newAI[0] = 2f;
Main.npc[npc3].Calamity().newAI[3] = 600f;
Main.npc[npc3].velocity = Vector2.Normalize(player.Center - Main.npc[npc3].Center) * 16f;
Main.npc[npc3].timeLeft *= 20;
Main.npc[npc3].netUpdate = true;
if (Main.netMode == NetmodeID.Server)
{
var netMessage = mod.GetPacket();
netMessage.Write((byte)CalamityModMessageType.SyncCalamityNPCAIArray);
netMessage.Write((byte)npc3);
netMessage.Write(Main.npc[npc3].Calamity().newAI[0]);
netMessage.Write(Main.npc[npc3].Calamity().newAI[1]);
netMessage.Write(Main.npc[npc3].Calamity().newAI[2]);
netMessage.Write(Main.npc[npc3].Calamity().newAI[3]);
netMessage.Send();
}
// Mark all existing body and tail segments as inactive. This instantly frees up their NPC slots for the freshly spawned worms.
int bodyID = ModContent.NPCType<AstrumDeusBodySpectral>();
int tailID = ModContent.NPCType<AstrumDeusTailSpectral>();
for (int i = 0; i < Main.maxNPCs; i++)
{
NPC wormseg = Main.npc[i];
if (!wormseg.active)
continue;
if (wormseg.type == bodyID || wormseg.type == tailID)
{
wormseg.life = 0;
wormseg.active = false;
}
}
for (int i = 0; i < Main.maxNPCs; i++)
{
if (i == npc.whoAmI || Main.npc[i].type == ModContent.NPCType<AstrumDeusBodySpectral>() || Main.npc[i].type == ModContent.NPCType<AstrumDeusTailSpectral>())
Main.npc[i].life = 0;
}
// The unsplit Astrum Deus worm head will die next frame.
npc.life = 0;
// Do not spawn worms client side. The server handles this.
if (Main.netMode != NetmodeID.MultiplayerClient)
{
// Now that the original worm doesn't exist, startCount can be zero.
// int startCount = npc.whoAmI + phase1Length + 1;
int startIndexHeadOne = 1;
int headOneID = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, npc.type, startIndexHeadOne);
Main.npc[headOneID].Calamity().newAI[0] = 1f;
Main.npc[headOneID].velocity = Vector2.Normalize(player.Center - Main.npc[headOneID].Center) * 16f;
Main.npc[headOneID].timeLeft *= 20;
Main.npc[headOneID].netUpdate = true;
// On server, immediately send the correct extra AI of this head to clients.
if (Main.netMode == NetmodeID.Server)
{
var netMessage = mod.GetPacket();
netMessage.Write((byte)CalamityModMessageType.SyncCalamityNPCAIArray);
netMessage.Write((byte)headOneID);
netMessage.Write(Main.npc[headOneID].Calamity().newAI[0]);
netMessage.Write(Main.npc[headOneID].Calamity().newAI[1]);
netMessage.Write(Main.npc[headOneID].Calamity().newAI[2]);
netMessage.Write(Main.npc[headOneID].Calamity().newAI[3]);
netMessage.Send();
}
// Make sure the second split worm is also contiguous.
int startIndexHeadTwo = startIndexHeadOne + phase2Length + 1;
int headTwoID = NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, npc.type, startIndexHeadTwo);
Main.npc[headTwoID].Calamity().newAI[0] = 2f;
Main.npc[headTwoID].Calamity().newAI[3] = 600f;
Main.npc[headTwoID].velocity = Vector2.Normalize(player.Center - Main.npc[headTwoID].Center) * 16f;
Main.npc[headTwoID].timeLeft *= 20;
Main.npc[headTwoID].netUpdate = true;
// On server, immediately send the correct extra AI of this head to clients.
if (Main.netMode == NetmodeID.Server)
{
var netMessage = mod.GetPacket();
netMessage.Write((byte)CalamityModMessageType.SyncCalamityNPCAIArray);
netMessage.Write((byte)headTwoID);
netMessage.Write(Main.npc[headTwoID].Calamity().newAI[0]);
netMessage.Write(Main.npc[headTwoID].Calamity().newAI[1]);
netMessage.Write(Main.npc[headTwoID].Calamity().newAI[2]);
netMessage.Write(Main.npc[headTwoID].Calamity().newAI[3]);
netMessage.Send();
}
}
return;
}
}
@@ -2970,7 +2998,7 @@ namespace CalamityMod.NPCs
}
// Check if other segments are still alive, if not, die
if (npc.type > ModContent.NPCType<AstrumDeusHeadSpectral>())
if (npc.type != ModContent.NPCType<AstrumDeusHeadSpectral>())
{
bool shouldDespawn = true;
for (int i = 0; i < Main.maxNPCs; i++)
+8 -7
View File
@@ -28,11 +28,14 @@ namespace CalamityMod.NPCs.Leviathan
int counter = 0;
bool initialised = false;
int soundDelay = 0;
public static Texture2D AttackTexture = null;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("The Leviathan");
Main.npcFrameCount[npc.type] = 6;
Main.npcFrameCount[npc.type] = 3;
if (!Main.dedServ)
AttackTexture = ModContent.GetTexture("CalamityMod/NPCs/Leviathan/LeviathanAttack");
}
public override void SetDefaults()
@@ -95,17 +98,15 @@ namespace CalamityMod.NPCs.Leviathan
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(npc.dontTakeDamage);
writer.Write(counter);
writer.Write(initialised);
writer.Write(soundDelay);
writer.Write(npc.Calamity().newAI[3]);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
npc.dontTakeDamage = reader.ReadBoolean();
counter = reader.ReadInt32();
initialised = reader.ReadBoolean();
soundDelay = reader.ReadInt32();
npc.Calamity().newAI[3] = reader.ReadSingle();
}
public override void AI()
@@ -713,7 +714,7 @@ namespace CalamityMod.NPCs.Leviathan
public override bool PreDraw(SpriteBatch spriteBatch, Color drawColor)
{
Texture2D texture = ModContent.GetTexture("CalamityMod/NPCs/Leviathan/LeviathanAttack");
Texture2D texture = AttackTexture;
if (npc.ai[0] == 1f || npc.Calamity().newAI[3] < 180f)
{
texture = Main.npcTexture[npc.type];
@@ -756,7 +757,7 @@ namespace CalamityMod.NPCs.Leviathan
npc.frame.Y += height;
}
if (counter == Main.npcFrameCount[npc.type])
if (counter == 6)
{
counter = 1;
npc.frame.Y = 0;