Death Mode enemy projectile fix

* Fixed enemy projectiles on Death Mode not syncing changes to Projectile.extraUpdates from the server to its clients after being spawned.
This commit is contained in:
fryzahh authored and Cameron Ewell committed 2026-06-12 19:42:01 -04:00
1 parent 0262efa0c8
commit 543ea7dde9
7 files changed
+68 -27

No files matched your search

@@ -284,12 +284,14 @@ public static partial class RevengeanceAndDeathAI
int type = ProjectileID.HarpyFeather;
Vector2 featherVelocity = NPC.SafeDirectionTo(Main.player[NPC.target].Center) * (CalamityWorld.death ? 4f : 6f);
int feather = Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, featherVelocity, type, damage, 0f, Main.myPlayer);
int feather = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), NPC.Center, featherVelocity, type, damage, 0f, Main.myPlayer).identity;
Main.projectile[feather].timeLeft = 300;
if (CalamityWorld.death)
{
Main.projectile[feather].extraUpdates += 1;
Main.projectile[feather].Calamity().extraUpdatesToSync = 1;
Main.projectile[feather].timeLeft = 600;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, feather);
}
}
}
@@ -316,12 +318,14 @@ public static partial class RevengeanceAndDeathAI
int type = ProjectileID.DemonSickle;
Vector2 sickleVelocity = NPC.SafeDirectionTo(Main.player[NPC.target].Center) * (CalamityWorld.death ? 0.15f : 0.2f);
int sickle = Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, sickleVelocity, type, damage, 0f, Main.myPlayer);
int sickle = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), NPC.Center, sickleVelocity, type, damage, 0f, Main.myPlayer).identity;
Main.projectile[sickle].timeLeft = 300;
if (CalamityWorld.death)
{
Main.projectile[sickle].extraUpdates += 1;
Main.projectile[sickle].Calamity().extraUpdatesToSync = 1;
Main.projectile[sickle].timeLeft = 600;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, sickle);
}
}
}
@@ -352,12 +356,14 @@ public static partial class RevengeanceAndDeathAI
int damage = 80;
int type = ProjectileID.UnholyTridentHostile;
int trident = Projectile.NewProjectile(NPC.GetSource_FromAI(), spawnPosition + tridentVelocity * 100f, tridentVelocity, type, damage, 3f, Main.myPlayer);
int trident = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), spawnPosition + tridentVelocity * 100f, tridentVelocity, type, damage, 3f, Main.myPlayer).identity;
Main.projectile[trident].timeLeft = 300;
if (CalamityWorld.death)
{
Main.projectile[trident].extraUpdates += 1;
Main.projectile[trident].Calamity().extraUpdatesToSync = 1;
Main.projectile[trident].timeLeft = 600;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, trident);
}
}
}
@@ -296,10 +296,13 @@ public static partial class RevengeanceAndDeathAI
if (canSpawnProj)
{
int proj = Projectile.NewProjectile(NPC.GetSource_FromAI(), (float)(spiritProjSpawnX * 16 + 8), (float)(spiritProjSpawnY * 16 + 8), 0f, 0f, ProjectileID.DesertDjinnCurse, 0, 1f, Main.myPlayer, (float)NPC.target, 0f);
int proj = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), new Vector2((float)(spiritProjSpawnX * 16 + 8), (float)(spiritProjSpawnY * 16 + 8)), Vector2.Zero, ProjectileID.DesertDjinnCurse, 0, 1f, Main.myPlayer, (float)NPC.target, 0f).identity;
if (CalamityWorld.death)
Main.projectile[proj].extraUpdates += 1;
{
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
break;
}
}
@@ -2922,22 +2922,26 @@ PrepareToShoot:
}
else if (npcType == NPCID.StardustSoldier)
{
int proj = Projectile.NewProjectile(NPC.GetSource_FromAI(), spawnPosition.X, spawnPosition.Y, distX, distY, projectileType, damage, 0f, Main.myPlayer, 0f, (float)NPC.whoAmI);
int proj = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), spawnPosition, new Vector2(distX, distY), projectileType, damage, 0f, Main.myPlayer, 0f, NPC.whoAmI).identity;
if (CalamityWorld.death)
{
Main.projectile[proj].extraUpdates += 1;
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
Main.projectile[proj].timeLeft = 480;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
}
else if (npcType == NPCID.NebulaSoldier)
{
for (int i = 0; i < 4; i++)
{
int proj = Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center.X - (float)(NPC.spriteDirection * 4), NPC.Center.Y + 6f, (float)(-3 + 2 * i) * 0.15f, (float)(-(float)Main.rand.Next(0, 3)) * 0.2f - 0.1f, projectileType, damage, 0f, Main.myPlayer, 0f, (float)NPC.whoAmI);
int proj = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), new Vector2(NPC.Center.X - (float)(NPC.spriteDirection * 4), NPC.Center.Y + 6f), new Vector2((float)(-3 + 2 * i) * 0.15f, (float)(-(float)Main.rand.Next(0, 3)) * 0.2f - 0.1f), projectileType, damage, 0f, Main.myPlayer, 0f, (float)NPC.whoAmI).identity;
if (CalamityWorld.death)
{
Main.projectile[proj].extraUpdates += 1;
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
Main.projectile[proj].timeLeft = 1200;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
}
}
@@ -2948,11 +2952,13 @@ PrepareToShoot:
}
else
{
int proj = Projectile.NewProjectile(NPC.GetSource_FromAI(), spawnPosition.X, spawnPosition.Y, distX, distY, projectileType, damage, 0f, Main.myPlayer);
int proj = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), spawnPosition, new Vector2(distX, distY), projectileType, damage, 0f, Main.myPlayer).identity;
if (CalamityWorld.death)
{
Main.projectile[proj].extraUpdates += 1;
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
Main.projectile[proj].timeLeft = 1200;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
}
}
@@ -3192,12 +3198,14 @@ PrepareToShoot:
{
int velocityX = 3 * NPC.direction;
int velocityY = -5;
int clownBomb = Projectile.NewProjectile(NPC.GetSource_FromAI(), spawnPosition.X, spawnPosition.Y, velocityX, velocityY, ProjectileID.HappyBomb, 0, 0f, Main.myPlayer, 0f, 0f);
int clownBomb = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), spawnPosition, new Vector2(velocityX, velocityY), ProjectileID.HappyBomb, 0, 0f, Main.myPlayer, 0f, 0f).identity;
Main.projectile[clownBomb].timeLeft = 300;
if (CalamityWorld.death)
{
Main.projectile[clownBomb].extraUpdates += 1;
Main.projectile[clownBomb].Calamity().extraUpdatesToSync = 1;
Main.projectile[clownBomb].timeLeft = 600;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, clownBomb);
}
NPC.ai[2] = 0f;
}
@@ -50,8 +50,10 @@ public static partial class RevengeanceAndDeathAI
while (Math.Abs(projDirection.X) < 1.5f)
projDirection = Vector2.UnitY.RotatedByRandom(MathHelper.PiOver2) * new Vector2(5f, 3f);
int proj = Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, projDirection, ProjectileID.StardustJellyfishSmall, 60, 0f, Main.myPlayer, 0f, NPC.whoAmI);
Main.projectile[proj].extraUpdates += 1;
int proj = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), NPC.Center, projDirection, ProjectileID.StardustJellyfishSmall, 60, 0f, Main.myPlayer, 0f, NPC.whoAmI).identity;
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
return false;
@@ -598,9 +598,11 @@ public static partial class RevengeanceAndDeathAI
projDamage = (int)(30f * NPC.scale);
int stingerType = ProjectileID.Stinger;
int stingerSpawn = Projectile.NewProjectile(NPC.GetSource_FromAI(), projSpawnPosition.X, projSpawnPosition.Y, projTargetXDist, projTargetYDist, stingerType, projDamage, 0f, Main.myPlayer);
int stingerSpawn = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), projSpawnPosition, new Vector2(projTargetXDist, projTargetYDist), stingerType, projDamage, 0f, Main.myPlayer).identity;
Main.projectile[stingerSpawn].timeLeft = (CalamityWorld.death || Main.hardMode) ? 600 : 300;
Main.projectile[stingerSpawn].extraUpdates += (CalamityWorld.death || Main.hardMode) ? 1 : 0;
Main.projectile[stingerSpawn].Calamity().extraUpdatesToSync = (CalamityWorld.death || Main.hardMode) ? 1 : 0;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, stingerSpawn);
NPC.ai[1] = 301f;
NPC.netUpdate = true;
}
@@ -673,11 +675,13 @@ public static partial class RevengeanceAndDeathAI
NPC.netUpdate = true;
NPC.localAI[0] = 0f;
bloodShotPosition = NPC.DirectionTo(new Vector2(targetData.Center.X, targetData.Position.Y));
int proj = Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, bloodShotPosition * (CalamityWorld.death ? 6f : 10f), ProjectileID.BloodShot, 50, 1f, Main.myPlayer);
int proj = Projectile.NewProjectileDirect(NPC.GetSource_FromAI(), NPC.Center, bloodShotPosition * (CalamityWorld.death ? 6f : 10f), ProjectileID.BloodShot, 50, 1f, Main.myPlayer).identity;
if (CalamityWorld.death)
{
Main.projectile[proj].extraUpdates += 1;
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
Main.projectile[proj].timeLeft = 1200;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
}
else
@@ -188,9 +188,13 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.RegularEnemies
spikeShootVelocity *= Main.rand.NextVector2Square(0.75f, 1.25f);
spikeShootVelocity.Normalize();
spikeShootVelocity *= Main.rand.NextFloat(3.5f, 4.5f) * projectileShootSpeedFactor;
int proj = Projectile.NewProjectile(source, NPC.Center, spikeShootVelocity, projectileShootType, 9, 0f, Main.myPlayer);
int proj = Projectile.NewProjectileDirect(source, NPC.Center, spikeShootVelocity, projectileShootType, 9, 0f, Main.myPlayer).identity;
if (CalamityWorld.death)
Main.projectile[proj].extraUpdates += 1;
{
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
projectileShootCountdown = 30f;
}
@@ -198,11 +202,13 @@ namespace CalamityMod.NPCs.VanillaNPCAIOverrides.RegularEnemies
else
{
Vector2 velocity = NPC.SafeDirectionTo(Main.player[NPC.target].Center - Vector2.UnitY * 100f) * projectileShootSpeedFactor * (CalamityWorld.death ? 3.25f : CalamityWorld.revenge ? 5.5f : 4.5f);
int proj = Projectile.NewProjectile(source, NPC.Center, velocity, projectileShootType, 9, 0f, Main.myPlayer);
int proj = Projectile.NewProjectileDirect(source, NPC.Center, velocity, projectileShootType, 9, 0f, Main.myPlayer).identity;
if (CalamityWorld.death)
{
Main.projectile[proj].extraUpdates += 1;
Main.projectile[proj].Calamity().extraUpdatesToSync = 1;
Main.projectile[proj].timeLeft = 1200;
if (Main.dedServ)
NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, proj);
}
projectileShootCountdown = 50f;
+12
View File
@@ -93,6 +93,7 @@ namespace CalamityMod.Projectiles
/// <br/>* Reducing projectile damage for Hardmode enemies and in Master Mode.
/// <br/>* Adding armor penetration to rogue projectiles spawned while wearing Filthy Glove or its upgrades.
/// <br/>* Increasing the damage of projectiles from the post-Moon Lord Dungeon, and from the post-DoG Pumpkin Moon, Frost Moon, and Solar Eclipse.
/// <br/>* Manually setting the extraUpdates fields of projectiles who use <see cref="extraUpdatesToSync"/>.
/// </summary>
private bool frameOneHacksExecuted = false;
@@ -225,6 +226,12 @@ namespace CalamityMod.Projectiles
/// </summary>
public int defExtraUpdates = -1;
/// <summary>
/// Set this to a value higher than one to have a projectile automatically have their extraUpdates field synced across all clients on a server when spawned. <br></br>
/// Please ensure <c>SyncProjectile</c> (or simply <see cref="Projectile.netUpdate"/> is called after setting this.
/// </summary>
public int extraUpdatesToSync = 0;
/// <summary>
/// How many times this projectile has pierced an enemy which applies pierce resist.<br/>
/// Used for calculating pierce resist damage reduction.
@@ -437,10 +444,12 @@ namespace CalamityMod.Projectiles
public override void SendExtraAI(Projectile projectile, BitWriter bitWriter, BinaryWriter binaryWriter)
{
binaryWriter.Write(ParentNPCIndex);
binaryWriter.Write(extraUpdatesToSync);
}
public override void ReceiveExtraAI(Projectile projectile, BitReader bitReader, BinaryReader binaryReader)
{
ParentNPCIndex = binaryReader.ReadInt32();
extraUpdatesToSync = binaryReader.ReadInt32();
}
#endregion On Spawn
@@ -3795,6 +3804,9 @@ namespace CalamityMod.Projectiles
if (!frameOneHacksExecuted)
{
if (extraUpdatesToSync > 0)
projectile.extraUpdates = extraUpdatesToSync;
if (projectile.hostile)
{
// Reduce Nail damage from Nailheads because they're stupid