feat: Enhance BuildingRemove logic to correctly manage Player.inst during building removal

This commit is contained in:
2025-12-15 09:22:50 +01:00
parent 7d06145a34
commit 46ebeb1f80
2 changed files with 44 additions and 1 deletions

View File

@@ -42,7 +42,20 @@ namespace KCM.Packets.Game.GameBuilding
// Set flag to prevent sending packet back
isProcessingPacket = true;
// Set Player.inst to the correct player for this building
// This ensures Remove() modifies the correct player's job lists
Player originalPlayer = Player.inst;
Player correctPlayer = Main.GetPlayerByBuilding(building);
if (correctPlayer != null)
{
Player.inst = correctPlayer;
}
building.Remove();
// Restore original Player.inst
Player.inst = originalPlayer;
isProcessingPacket = false;
}
catch (Exception e)