diff --git a/Enums/Packets.cs b/Enums/Packets.cs index f7da401..57625c4 100644 --- a/Enums/Packets.cs +++ b/Enums/Packets.cs @@ -18,11 +18,8 @@ namespace KCM.Enums KingdomName = 32, StartGame = 33, WorldSeed = 34, - - Building = 50, BuildingOnPlacement = 51, - World = 70, WorldPlace = 71, FellTree = 72, diff --git a/Packets/Lobby/WorldSeed.cs b/Packets/Lobby/WorldSeed.cs index 38655c9..a276063 100644 --- a/Packets/Lobby/WorldSeed.cs +++ b/Packets/Lobby/WorldSeed.cs @@ -13,6 +13,11 @@ namespace KCM.Packets.Lobby public override ushort packetId => (int)Enums.Packets.WorldSeed; public int Seed { get; set; } + // Map parameters to ensure correct generation + public World.MapSize WorldSize { get; set; } + public World.MapBias WorldType { get; set; } + public World.MapRiverLakes WorldRivers { get; set; } + public override void HandlePacketServer() { //SetWorldSeed(); @@ -27,12 +32,21 @@ namespace KCM.Packets.Lobby { try { + // Set map parameters BEFORE generating to ensure correct world + World.inst.mapSize = WorldSize; + World.inst.mapBias = WorldType; + World.inst.mapRiverLakes = WorldRivers; + + Main.helper.Log($"[WORLD SYNC] Generating world - Seed: {Seed}, Size: {WorldSize}, Type: {WorldType}, Rivers: {WorldRivers}"); + foreach (var player in Main.kCPlayers.Values) player.inst.Reset(); World.inst.Generate(Seed); Vector3 center = World.inst.GetCellData(World.inst.GridWidth / 2, World.inst.GridHeight / 2).Center; Cam.inst.SetTrackingPos(center); + + Main.helper.Log("[WORLD SYNC] World generation complete"); } catch (Exception e) { diff --git a/Packets/Network/ClientConnected.cs b/Packets/Network/ClientConnected.cs index 6c55639..0e89e3b 100644 --- a/Packets/Network/ClientConnected.cs +++ b/Packets/Network/ClientConnected.cs @@ -111,11 +111,16 @@ namespace KCM.Packets.Network } else { - + // Send world seed with all map parameters to ensure correct generation new WorldSeed() { - Seed = World.inst.seed + Seed = World.inst.seed, + WorldSize = World.inst.mapSize, + WorldType = World.inst.mapBias, + WorldRivers = World.inst.mapRiverLakes }.SendToAll(KCClient.client.Id); + + Main.helper.Log($"[WORLD SYNC] Sent world to new client - Seed: {World.inst.seed}, Size: {World.inst.mapSize}, Type: {World.inst.mapBias}, Rivers: {World.inst.mapRiverLakes}"); } } diff --git a/ServerLobby/ServerLobbyScript.cs b/ServerLobby/ServerLobbyScript.cs index a4990fa..3917fa3 100644 --- a/ServerLobby/ServerLobbyScript.cs +++ b/ServerLobby/ServerLobbyScript.cs @@ -247,10 +247,16 @@ namespace KCM foreach (var player in Main.kCPlayers.Values) player.inst.SetupJobPriorities(); + // Send world seed with all map parameters to ensure clients generate identical world new WorldSeed() { - Seed = World.inst.seed + Seed = World.inst.seed, + WorldSize = World.inst.mapSize, + WorldType = World.inst.mapBias, + WorldRivers = World.inst.mapRiverLakes }.SendToAll(KCClient.client.Id); + + Main.helper.Log($"[WORLD SYNC] Generated new world - Seed: {World.inst.seed}, Size: {World.inst.mapSize}, Type: {World.inst.mapBias}, Rivers: {World.inst.mapRiverLakes}"); } catch (Exception ex) {