From 15b36e1789aaa6e015cbecbeb795a3fc4fe9ade5 Mon Sep 17 00:00:00 2001 From: DominicKarma42 <51094361+DominicKarma@users.noreply.github.com> Date: Sun, 1 Dec 2019 16:50:52 -0600 Subject: [PATCH] Various MP fixes in description * Partially fixed Golem Free Head in rev (a little jittery, but I couldn't locate the root cause of that) * Added packets for toggleable items, such as the defiled rune, so that the server and client don't bitch at each other over the boolean * Added various logic checks and netcode to the mechworm. Hopefully removed most, if not all mechworm bugs. --- CalamityMod.cs | 38 +++++++++++++++++++++++++++- Items/DifficultyItems/Armageddon.cs | 8 ++++++ Items/DifficultyItems/Death.cs | 8 ++++++ Items/DifficultyItems/DefiledRune.cs | 10 ++++++++ Items/DifficultyItems/IronHeart.cs | 8 ++++++ Items/DifficultyItems/MLGRune.cs | 7 +++++ Items/DifficultyItems/Revenge.cs | 7 +++++ NPCs/CalamityGlobalAI.cs | 10 +++++--- NPCs/CalamityGlobalNPC.cs | 2 +- Projectiles/Melee/GaelSkull.cs | 2 +- Projectiles/Melee/GaelSkull2.cs | 2 +- Projectiles/Summon/MechwormBody.cs | 17 +++++++++++++ Projectiles/Summon/MechwormBody2.cs | 17 +++++++++++++ Projectiles/Summon/MechwormHead.cs | 1 + Projectiles/Summon/MechwormTail.cs | 19 +++++++++++++- 15 files changed, 147 insertions(+), 9 deletions(-) diff --git a/CalamityMod.cs b/CalamityMod.cs index 927af218d4..be9db6a4ec 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -15,6 +15,7 @@ using CalamityMod.Items.Fishing.AstralCatches; using CalamityMod.Items.Fishing.SunkenSeaCatches; using CalamityMod.Items.Fishing.FishingRods; using CalamityMod.Localization; +using CalamityMod.NPCs; using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.AquaticScourge; using CalamityMod.NPCs.Astral; @@ -3265,6 +3266,32 @@ namespace CalamityMod case CalamityModMessageType.DeathCountSync: Main.player[reader.ReadInt32()].Calamity().HandleDeathCount(reader); break; + case CalamityModMessageType.RevengeanceBoolSync: + bool revActive = reader.ReadBoolean(); + CalamityWorld.revenge = revActive; + break; + case CalamityModMessageType.DeathBoolSync: + bool revActive2 = reader.ReadBoolean(); + CalamityWorld.revenge = revActive2; + bool deathActive = reader.ReadBoolean(); + CalamityWorld.death = deathActive; + break; + case CalamityModMessageType.DefiledBoolSync: + bool defiledActive = reader.ReadBoolean(); + CalamityWorld.defiled = defiledActive; + break; + case CalamityModMessageType.IronHeartBoolSync: + bool ironHeartActive = reader.ReadBoolean(); + CalamityWorld.ironHeart = ironHeartActive; + break; + case CalamityModMessageType.ArmageddonBoolSync: + bool armaActive = reader.ReadBoolean(); + CalamityWorld.armageddon = armaActive; + break; + case CalamityModMessageType.NPCRegenerationSync: + byte npcIndex = reader.ReadByte(); + Main.npc[npcIndex].lifeRegen = reader.ReadInt32(); + break; default: Logger.Warn("Unknown Message type: " + msgType); break; @@ -3286,7 +3313,9 @@ namespace CalamityMod public static void UpdateServerBoolean() { if (Main.netMode == NetmodeID.Server) + { NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0); + } } #endregion } @@ -3318,7 +3347,14 @@ namespace CalamityMod DoGCountdownSync, BossSpawnCountdownSync, BossTypeSync, - DeathCountSync + DeathCountSync, + RevengeanceBoolSync, + DeathBoolSync, + DefiledBoolSync, + IronHeartBoolSync, + ArmageddonBoolSync, + DemonTrophyBoolSync, + NPCRegenerationSync //DistanceFromBossSync } } diff --git a/Items/DifficultyItems/Armageddon.cs b/Items/DifficultyItems/Armageddon.cs index 8d265a0007..c42330f06d 100644 --- a/Items/DifficultyItems/Armageddon.cs +++ b/Items/DifficultyItems/Armageddon.cs @@ -72,6 +72,14 @@ namespace CalamityMod.Items.DifficultyItems } CalamityMod.UpdateServerBoolean(); + + if (Main.netMode == NetmodeID.Server) + { + var netMessage = mod.GetPacket(); + netMessage.Write((uint)CalamityModMessageType.ArmageddonBoolSync); + netMessage.Write(CalamityWorld.armageddon); + netMessage.Send(); + } return true; } diff --git a/Items/DifficultyItems/Death.cs b/Items/DifficultyItems/Death.cs index 0e5a68eb3c..20322b64dd 100644 --- a/Items/DifficultyItems/Death.cs +++ b/Items/DifficultyItems/Death.cs @@ -86,6 +86,14 @@ namespace CalamityMod.Items.DifficultyItems } CalamityMod.UpdateServerBoolean(); + + if (Main.netMode == NetmodeID.Server) + { + var netMessage = mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.DeathBoolSync); + netMessage.Write(CalamityWorld.death); + netMessage.Send(); + } return true; } diff --git a/Items/DifficultyItems/DefiledRune.cs b/Items/DifficultyItems/DefiledRune.cs index c86876f8ec..8a633f5557 100644 --- a/Items/DifficultyItems/DefiledRune.cs +++ b/Items/DifficultyItems/DefiledRune.cs @@ -83,6 +83,16 @@ namespace CalamityMod.Items.DifficultyItems } CalamityMod.UpdateServerBoolean(); + + if (Main.netMode == NetmodeID.Server) + { + var netMessage = mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.RevengeanceBoolSync); + netMessage.Write(CalamityWorld.revenge); + netMessage.Write((byte)CalamityModMessageType.DefiledBoolSync); + netMessage.Write(CalamityWorld.defiled); + netMessage.Send(); + } return true; } diff --git a/Items/DifficultyItems/IronHeart.cs b/Items/DifficultyItems/IronHeart.cs index fcc45eeafe..58236f96e4 100644 --- a/Items/DifficultyItems/IronHeart.cs +++ b/Items/DifficultyItems/IronHeart.cs @@ -83,6 +83,14 @@ namespace CalamityMod.Items.DifficultyItems } } CalamityMod.UpdateServerBoolean(); + + if (Main.netMode == NetmodeID.Server) + { + var netMessage = mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.IronHeartBoolSync); + netMessage.Write(CalamityWorld.ironHeart); + netMessage.Send(); + } return true; } } diff --git a/Items/DifficultyItems/MLGRune.cs b/Items/DifficultyItems/MLGRune.cs index cdb8ef2931..3fbbabeb5f 100644 --- a/Items/DifficultyItems/MLGRune.cs +++ b/Items/DifficultyItems/MLGRune.cs @@ -31,6 +31,13 @@ namespace CalamityMod.Items.DifficultyItems { CalamityWorld.demonMode = true; CalamityMod.UpdateServerBoolean(); + if (Main.netMode == NetmodeID.Server) + { + var netMessage = mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.DemonTrophyBoolSync); + netMessage.Write(CalamityWorld.demonMode); + netMessage.Send(); + } return true; } } diff --git a/Items/DifficultyItems/Revenge.cs b/Items/DifficultyItems/Revenge.cs index a1ad1ae0f5..0b66eabc2f 100644 --- a/Items/DifficultyItems/Revenge.cs +++ b/Items/DifficultyItems/Revenge.cs @@ -128,6 +128,13 @@ namespace CalamityMod.Items.DifficultyItems } CalamityMod.UpdateServerBoolean(); + if (Main.netMode == NetmodeID.Server) + { + var netMessage = mod.GetPacket(); + netMessage.Write((byte)CalamityModMessageType.RevengeanceBoolSync); + netMessage.Write(CalamityWorld.revenge); + netMessage.Send(); + } } return true; } diff --git a/NPCs/CalamityGlobalAI.cs b/NPCs/CalamityGlobalAI.cs index dd9c4d6099..7a11c65f06 100644 --- a/NPCs/CalamityGlobalAI.cs +++ b/NPCs/CalamityGlobalAI.cs @@ -9222,9 +9222,6 @@ namespace CalamityMod.NPCs bool phase3 = lifeRatio < 0.4f || golemLifeRatio < 0.7f || CalamityWorld.death || CalamityWorld.bossRushActive; bool phase4 = lifeRatio < 0.1f || golemLifeRatio < 0.55f || CalamityWorld.death || CalamityWorld.bossRushActive; - // Target - npc.TargetClosest(true); - // Float through tiles or not bool flag44 = false; if (!Collision.CanHit(npc.Center, 1, 1, Main.player[npc.target].Center, 1, 1) || phase3) @@ -9252,6 +9249,10 @@ namespace CalamityMod.NPCs // Move to new location if (npc.ai[3] <= 0f) { + // Target + npc.TargetClosest(true); + npc.netSpam = 5; + npc.ai[3] = 300f; float maxDistance = 300f; @@ -9315,7 +9316,7 @@ namespace CalamityMod.NPCs calamityGlobalNPC.newAI[1] = -maxDistance; } - npc.netUpdate = true; + npc.netUpdate = true; } npc.ai[3] -= 1f + @@ -9470,6 +9471,7 @@ namespace CalamityMod.NPCs } } } + NetMessage.SendData(23, -1, -1, null, npc.whoAmI, 0f, 0f, 0f, 0, 0, 0); if (ModLoader.GetMod("FargowiltasSouls") != null) ModLoader.GetMod("FargowiltasSouls").Call("FargoSoulsAI", npc.whoAmI); diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index ab3eca7f43..a6bccab994 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -80,7 +80,7 @@ namespace CalamityMod.NPCs // private int ironHeartDamage = 0; // NewAI - private const int maxAIMod = 4; + internal const int maxAIMod = 4; public float[] newAI = new float[maxAIMod]; // Town NPC Patreon diff --git a/Projectiles/Melee/GaelSkull.cs b/Projectiles/Melee/GaelSkull.cs index 5116e5cebb..a00e03f1d2 100644 --- a/Projectiles/Melee/GaelSkull.cs +++ b/Projectiles/Melee/GaelSkull.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Projectiles.Melee { public override void SetStaticDefaults() { - DisplayName.SetDefault("Skull"); + DisplayName.SetDefault("Ark of the Cosmos' Superior Cousin"); ProjectileID.Sets.TrailCacheLength[projectile.type] = 4; ProjectileID.Sets.TrailingMode[projectile.type] = 0; Main.projFrames[projectile.type] = 5; diff --git a/Projectiles/Melee/GaelSkull2.cs b/Projectiles/Melee/GaelSkull2.cs index e9410baadb..35c69be239 100644 --- a/Projectiles/Melee/GaelSkull2.cs +++ b/Projectiles/Melee/GaelSkull2.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Projectiles.Melee { public override void SetStaticDefaults() { - DisplayName.SetDefault("Skull"); + DisplayName.SetDefault("Ark of the Cosmos' Superior Cousin"); ProjectileID.Sets.TrailCacheLength[projectile.type] = 4; ProjectileID.Sets.TrailingMode[projectile.type] = 0; Main.projFrames[projectile.type] = 5; diff --git a/Projectiles/Summon/MechwormBody.cs b/Projectiles/Summon/MechwormBody.cs index 344b84a2aa..35360d9ab3 100644 --- a/Projectiles/Summon/MechwormBody.cs +++ b/Projectiles/Summon/MechwormBody.cs @@ -79,6 +79,22 @@ namespace CalamityMod.Projectiles.Summon float scaleFactor18; if (chase >= 0 && Main.projectile[chase].active) { + //Delete the player's mechworm if it's attaching to something weird + if (Main.projectile[chase].type != ModContent.ProjectileType() && + Main.projectile[chase].type != ModContent.ProjectileType()) + { + for (int i = 0; i < Main.projectile.Length; i++) + { + if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && + (Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType())) + { + Main.projectile[i].Kill(); + } + } + } value68 = Main.projectile[chase].Center; Vector2 arg_2DE6A_0 = Main.projectile[chase].velocity; num1064 = Main.projectile[chase].rotation; @@ -113,6 +129,7 @@ namespace CalamityMod.Projectiles.Summon projectile.Center = value68 - Vector2.Normalize(vector134) * scaleFactor17 * scaleFactor18; } projectile.spriteDirection = (vector134.X > 0f) ? 1 : -1; + projectile.netSpam = 5; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Summon/MechwormBody2.cs b/Projectiles/Summon/MechwormBody2.cs index dba4f74489..dee4b8bf91 100644 --- a/Projectiles/Summon/MechwormBody2.cs +++ b/Projectiles/Summon/MechwormBody2.cs @@ -79,6 +79,22 @@ namespace CalamityMod.Projectiles.Summon float scaleFactor18; if (chase >= 0 && Main.projectile[chase].active) { + //Delete the player's mechworm if it's attaching to something weird + if (Main.projectile[chase].type != ModContent.ProjectileType() && + Main.projectile[chase].type != ModContent.ProjectileType()) + { + for (int i = 0; i < Main.projectile.Length; i++) + { + if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && + (Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType())) + { + Main.projectile[i].Kill(); + } + } + } value68 = Main.projectile[chase].Center; Vector2 arg_2DE6A_0 = Main.projectile[chase].velocity; num1064 = Main.projectile[chase].rotation; @@ -112,6 +128,7 @@ namespace CalamityMod.Projectiles.Summon projectile.Center = value68 - Vector2.Normalize(vector134) * scaleFactor17 * scaleFactor18; } projectile.spriteDirection = (vector134.X > 0f) ? 1 : -1; + projectile.netSpam = 5; return; } diff --git a/Projectiles/Summon/MechwormHead.cs b/Projectiles/Summon/MechwormHead.cs index 41e8821143..3e51a80044 100644 --- a/Projectiles/Summon/MechwormHead.cs +++ b/Projectiles/Summon/MechwormHead.cs @@ -208,6 +208,7 @@ namespace CalamityMod.Projectiles.Summon projectile.alpha = 0; } } + projectile.netSpam = 5; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) diff --git a/Projectiles/Summon/MechwormTail.cs b/Projectiles/Summon/MechwormTail.cs index 91b121c1a6..80c0f4f77d 100644 --- a/Projectiles/Summon/MechwormTail.cs +++ b/Projectiles/Summon/MechwormTail.cs @@ -79,11 +79,27 @@ namespace CalamityMod.Projectiles.Summon float scaleFactor18; if (chase >= 0 && Main.projectile[chase].active) { + //Delete the player's mechworm if it's attaching to something weird + if (Main.projectile[chase].type != ModContent.ProjectileType() && + Main.projectile[chase].type != ModContent.ProjectileType()) + { + for (int i = 0; i < Main.projectile.Length; i++) + { + if (Main.projectile[i].active && Main.projectile[i].owner == projectile.owner && + (Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType() || + Main.projectile[chase].type == ModContent.ProjectileType())) + { + Main.projectile[i].Kill(); + } + } + } value68 = Main.projectile[chase].Center; Vector2 arg_2DE6A_0 = Main.projectile[chase].velocity; num1064 = Main.projectile[chase].rotation; scaleFactor18 = MathHelper.Clamp(Main.projectile[chase].scale, 0f, 50f); - scaleFactor17 = 16f; + scaleFactor17 = 6f; Main.projectile[chase].localAI[0] = projectile.localAI[0] + 1f; } else @@ -113,6 +129,7 @@ namespace CalamityMod.Projectiles.Summon projectile.Center = value68 - Vector2.Normalize(vector134) * scaleFactor17 * scaleFactor18; } projectile.spriteDirection = (vector134.X > 0f) ? 1 : -1; + projectile.netSpam = 5; return; }