From bb8ad3c97157a9b7f38fe21c24973aeeb4da8c55 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 25 Jun 2024 21:00:36 -0500 Subject: [PATCH] character creation population message --- src/engine/db/handlers/dbCityHandler.java | 18 ++++++++++++++++++ src/engine/net/client/msg/ServerInfoMsg.java | 13 ++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/engine/db/handlers/dbCityHandler.java b/src/engine/db/handlers/dbCityHandler.java index bf3d9d98..ea9609df 100644 --- a/src/engine/db/handlers/dbCityHandler.java +++ b/src/engine/db/handlers/dbCityHandler.java @@ -95,7 +95,25 @@ public class dbCityHandler extends dbHandlerBase { return objectList; } + public Integer GET_CITY_COUNT() { + int cityCount = 0; + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM obj_city;")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while(rs.next()){ + if(rs.getInt("isNpc") == 0) + cityCount++; + } + + } catch (SQLException e) { + Logger.error(e); + } + + return cityCount; + } public ArrayList GET_CITIES_BY_ZONE(final int objectUUID) { ArrayList cityList = new ArrayList<>(); diff --git a/src/engine/net/client/msg/ServerInfoMsg.java b/src/engine/net/client/msg/ServerInfoMsg.java index 33320c0f..143f5121 100644 --- a/src/engine/net/client/msg/ServerInfoMsg.java +++ b/src/engine/net/client/msg/ServerInfoMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.gameManager.ConfigManager; +import engine.gameManager.DbManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -53,15 +54,17 @@ public class ServerInfoMsg extends ClientNetMsg { writer.putInt(WorldServer.worldMapID); writer.putString(ConfigManager.MB_WORLD_NAME.getValue()); - if (LoginServer.population < MBServerStatics.LOW_POPULATION) + int TotalTrees = 275; + int currentTrees = DbManager.CityQueries.GET_CITY_COUNT(); + if (currentTrees < TotalTrees * 0.2f) writer.putInt(0); //Land Rush - else if (LoginServer.population < MBServerStatics.NORMAL_POPULATION) + else if (currentTrees < TotalTrees * 0.4f) writer.putInt(1); //Low pop - else if (LoginServer.population < MBServerStatics.HIGH_POPULATION) + else if (currentTrees < TotalTrees * 0.6f) writer.putInt(2); //Normal pop - else if (LoginServer.population < MBServerStatics.VERY_OVERPOPULATED_POPULATION) + else if (currentTrees < TotalTrees * 0.8f) writer.putInt(3); //High Pop - else if (LoginServer.population < MBServerStatics.FULL_POPULATION) + else if (currentTrees < TotalTrees) writer.putInt(4); //Very overpopulated pop else writer.putInt(5); //Full pop