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