int world_id = WorldDAO.createWorld(world);
world.setID(world_id);
client.getServer().addToActivePvEWorld(world);
PvEWorldMap pveMap = new PvEWorldMap(world.getID());
client.getServer().addPvEWorldMap(pveMap);
WorldMapDAO.savePvEWorldMap(pveMap);
world.setGameEngine(client.getServer().createGameEngine(world));
}
}
if (world == null) {
world = WorldDAO.getWorldByName(worldName);
if (world != null) {
world.setGameEngine(client.getServer().createGameEngine(world));
world.setEnvironments(EnvironmentDAO.getEnvironmentByWorldID(world.getID()));
client.getServer().addToActivePvEWorld(world);
client.getServer().addPvEWorldMap(WorldMapDAO.getPvEWorldMapByWorldID(world.getID()));
}
}
if (world != null && !world.hasPlayer(client.getPlayer().getID())) {//If the pve world is active
//Try to see if the environment of the current player is in the world buffer.
if (world.hasEnvironmentOfPlayer(client.getPlayer().getID())) {
responseJoinPvEWorld.setStatus((short) 0);
responseJoinPvEWorld.setWorld(world);
world.setPlayer(client.getPlayer());
responseGetEnv.setWorld(world);
client.setWorld(world);
WorldDAO.updateLastPlayed(world.getID());
for (Environment env : world.getEnvironments()) {
for (Zone zone : env.getZones()) {
if (zone.isEnable()) {
zone.setScoreCSV(ScoreCSVDAO.getCSV(zone.getID()));
zone.setParameters(ParamTableDAO.getByZoneID(zone.getID()));
PreyPredatorRatioDAO.createParameters(world.getCreatorID(),zone.getID());
HashMap<Integer, Integer[]> speciesList = ZoneSpeciesDAO.getSpecies(zone.getID());
HashMap<Integer, List<Object[]>> groupList = ZoneGroupsDAO.getGroups(zone.getID());
for (int species_id : speciesList.keySet()) {
Integer[] value = speciesList.get(species_id);
int num_groups = value[0], amount = value[1];
if (amount != 0 && num_groups != 0) {
List<Object[]> groups = groupList.get(species_id);
world.getGameEngine().createExistingOrganisms(species_id, zone.getID(), num_groups, amount, groups, Constants.CREATE_STATUS_DEFAULT);
}
}
zone.setBirthList(BirthListDAO.getList(zone.getID()));
zone.setDeathList(DeathListDAO.getList(zone.getID()));
zone.setAddNodeList(ZoneNodeAddDAO.getList(zone.getID()));
}
}
}
} else {
if (world.getEnvironments().size() < world.getMaxPlayers()) {
responseJoinPvEWorld.setStatus((short) 0);
responseJoinPvEWorld.setWorld(world);
//Create an environment for this player
PvEWorldMap map = client.getServer().getPvEWorldMap(world.getID());
if (map != null) {
int position = map.assignEnvironmentPosition();
int row = map.getRow(position);
int col = map.getCol(position);
WorldMapDAO.updatePvEWorldMap(map);
//Create a new environment for this user.
Environment env = new Environment(-1);