Package model

Examples of model.World


     *
     */
    public void printAllActivePvPWorlds() {
        System.out.println("********All the active PvP Worlds Start*******");
        for (Integer key : activePvPWorld.keySet()) {
            World pvpWorld = activePvPWorld.get(key);
            pvpWorld.toString();
        }
        System.out.println("********All the active PvP Worlds End*******");
    }
View Full Code Here


    public List<GameClient> getThreadsByTeam(int pvpWorldID, int teamID) {
        List<GameClient> clients = new ArrayList<GameClient>();

        Set<Integer> keySet = activePvPWorld.keySet();
        for (Integer key : keySet) {
            World pvpWorld = activePvPWorld.get(key);
            if (pvpWorld.getID() == pvpWorldID) {
                for (Environment env : pvpWorld.getEnvironments()) {
//                    if (env.getAvatar().getTeamNo() == teamID) {
//                        int userID = env.getAvatar().getPlayer().getID();
//                        GameClient client = getThreadByPlayerID(userID);
//                        clients.add(client);
//                    }
View Full Code Here

     * @param  col                  The col of the environment
     */
    public Environment removeAnEnvFromWorld(int worldID, int worldType, int row, int col) {
        Environment env = null;
        if (worldType == Constants.GAME_TYPE_PVP) {
            World pvpWorld = activePvPWorld.get(worldID);
            if (pvpWorld != null) {
                env = pvpWorld.getEnvByRowAndCol(row, col);
                if (env != null) {
                    pvpWorld.getEnvironments().remove(env);
                } else {
                    System.out.println("In GameServer.java---no env with the given row and col.");
                }
            }
        }
        if (worldType == Constants.GAME_TYPE_PVE) {
            World pveWorld = activePvEWorld.get(worldID);
            if (pveWorld != null) {
                env = pveWorld.getEnvByRowAndCol(row, col);
                if (env != null) {
                    pveWorld.getEnvironments().remove(env);
                } else {
                    System.out.println("In GameServer.java---no env with the given row and col.");
                }
            }
        }
View Full Code Here

     * Get an active world with the name of worldName
     *
     * @param worldName             The name of the target world
     */
    public World getOnlineActiveWorld(String worldName) {
        World world = getActivePvPWorld(worldName);
        if (world == null) {
            world = getActivePvEWorld(worldName);
        }
        return world;
    }
View Full Code Here

        System.out.println("Parse---world name:" + worldName);
    }

    @Override
    public void doBusiness() throws Exception {
        World world = client.getServer().getOnlineActiveWorld(worldName);

        if (world != null) {
            if (world.getEnvironments() != null) {
                for (Environment env : world.getEnvironments()) {
                    if (env.getOwnerID() == client.getPlayer().getID()) {
                        //Remove the environment from the world
                        world.getEnvironments().remove(env);

                        WorldDAO.updateWorldProperties(world);

                        //Update the world map.
                        if (world.getGameMode() == Constants.GAME_TYPE_PVE) {
                            PvPWorldMap pvpMap = client.getServer().getPvPWorldMap(world.getID());
                            pvpMap.quitOldTeamAndPosition(env.getRow(), env.getColumn());
                            pvpMap.printObject();

                            WorldMapDAO.updatePvPWorldMap(pvpMap);
                        } else if (world.getGameMode() == Constants.GAME_TYPE_PVE) {
                            PvEWorldMap pveMap = client.getServer().getPvEWorldMap(world.getID());
                            int position = pveMap.getPositionBasingOnRowAndCol(env.getRow(), env.getColumn());
                            pveMap.quitPosition(position);
                            pveMap.toString();

                            WorldMapDAO.updatePvEWorldMap(pveMap);
                        }

                        //Delete the environment from database.
                        EnvironmentDAO.deleteEnvironmentByID(env.getID());
                        AvatarDAO.deleteAvatarByID(client.getAvatar().getID());

                        client.setAvatar(null);
                        client.setWorld(null);
                    }
                }


                if (world.getEnvironments().isEmpty()) {//No one else in the world.
                    //Delete the world in the database.
                    try {
                        //No one else in the world.
                        //Delete the world in the database.
                        WorldDAO.removeWorld(world.getID());
                    } catch (SQLException ex) {
                    }

                    //Remove the world and worldMap in the buffer
                    client.getServer().removeWorldAndWorldMapFromBuffer(world.getID(), world.getGameMode());
                }

                responseCancelToJoinGame.setWorld(world);
            } else {
                System.out.println("world.getEnvironment() is null");
            }

            client.getServer().addResponseForWorld(world.getID(), responseCancelToJoinGame);
        } else {
            System.out.println("World is not active any more");
        }
    }
View Full Code Here

        worldName = DataReader.readString(dataInput);
    }

    @Override
    public void doBusiness() throws Exception {
        World pvpWorld = client.getServer().getActivePvPWorld(worldName);

        if (pvpWorld != null) {
        }
    }
View Full Code Here

        /* 1. If the pve world is active, the player is a new user
         * 2. If the pve world is active, the player is an old user
         * 3. If the pve world is non-active, the player is a new user
         * 4. If the pve world is non-active, the player is an old user.
         */
        World world = client.getServer().getActivePvEWorld(worldName);

        if (worldName.equals("NEW201204")) {
            world = WorldDAO.getWorldByPlayerID(client.getPlayer().getID());

            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()));
            } else if (world == null) {
                world = new World(-1);
                world.setGameMode(Constants.GAME_TYPE_PVE);
                world.setGameName(String.valueOf(client.getPlayer().getID()) + "_" + System.currentTimeMillis() % 100000);
                world.setMaxPlayers(100);
                world.setEnvType("Savanna");
                world.setAccessType(Constants.PRIVACY_TYPE_PUBLIC);
                world.setCreatorID(client.getPlayer().getID());

                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);
                        env.setOwnerID(client.getPlayer().getID());
                        env.setPos(row, col);
                        env.setWorldID(world.getID());

                        int env_id = EnvironmentDAO.createEnvironment(env);
                        env.setID(env_id);

                        Random random = new Random();

                        //Handle the zones in this environment.
                        for (int i = 0; i < 3; i++) {
                            for (int j = 0; j < 3; j++) {
                                Zone zone = new Zone(-1);
                                zone.setOrder(i * 3 + j);
                                zone.setEnvID(env.getID());
                                zone.setEnvironment(env);
                                zone.setRow(i);
                                zone.setColumn(j);
                                zone.setCurrentTimeStep(1);

                                zone.setType(random.nextInt(3) + 1);

                                int zone_id = ZoneDAO.createZone(zone);
                                zone.setID(zone_id);

                                ParamTableDAO.createParameters(zone_id);
                                PreyPredatorRatioDAO.createParameters(world.getCreatorID(),zone_id);
                                zone.setParameters(ParamTableDAO.getByZoneID(zone_id));

                                ZoneType zoneType = ZoneTypeDAO.getZoneType(zone.getType());

                                if (zoneType.containsWater()) {
                                    WaterSource waterSource = new WaterSource(-1);
                                    waterSource.setMaxWater(100);
                                    waterSource.setWater(100);
                                    waterSource.setZoneID(zone_id);

                                    int water_source_id = WaterSourceDAO.createWaterSource(waterSource);
                                    waterSource.setID(water_source_id);

                                    zone.setWaterSource(waterSource);
                                }

                                env.setZone(zone);
                            }
                        }

                        for (Environment e : world.getEnvironments()) {
                            for (Zone zone : e.getZones()) {
                                if (zone.isEnable()) {
                                    for (Organism organism : zone.getOrganisms()) {
                                        if (organism.getOrganismType() == Constants.ORGANISM_TYPE_PLANT) {
                                            ResponseBirthPlant responseBirthPlant = new ResponseBirthPlant();
                                            responseBirthPlant.setPlant((Plant) organism);
                                            responses.add(responseBirthPlant);
                                        } else if (organism.getOrganismType() == Constants.ORGANISM_TYPE_ANIMAL) {
                                            ResponseBirthAnimal responseBirthAnimal = new ResponseBirthAnimal();
                                            responseBirthAnimal.setAnimal((Animal) organism);
                                            responses.add(responseBirthAnimal);
                                        }
                                    }
                                }
                            }
                        }

                        ResponseCreateEnv responseCreateEnv = new ResponseCreateEnv();
                        responseCreateEnv.setEnvironment(env);
                        client.getServer().addResponseToOtherPeopleInTheSameWorld(client.getId(), world.getID(), responseCreateEnv);

                        Zone startZone = env.getZones().get(0);

                        SimulationEngine se = startZone.getSimulationEngine();
                        String networkName = "WoB-" + env.getID() + "." + startZone.getOrder() + "-" + System.currentTimeMillis() % 100000;

                        int nodeList[] = {13, 20, 31};
                        startZone.setManipulationID(se.createAndRunSeregenttiSubFoodweb(nodeList, networkName, 0, 0, false));

                        ZoneDAO.updateManipulationID(startZone.getID(), startZone.getManipulationID());

                        List<NodeBiomass> lNodeBiomass = new ArrayList<NodeBiomass>();

                        lNodeBiomass.add(new NodeBiomass(GameServer.getInstance().getSpeciesTypeByNodeID(13).getAvgBiomass() * 10 / Constants.BIOMASS_SCALE, 13));
                        lNodeBiomass.add(new NodeBiomass(GameServer.getInstance().getSpeciesTypeByNodeID(20).getAvgBiomass() * 10 / Constants.BIOMASS_SCALE, 20));
                        lNodeBiomass.add(new NodeBiomass(GameServer.getInstance().getSpeciesTypeByNodeID(31).getAvgBiomass() * 10 / Constants.BIOMASS_SCALE, 31));

                        if (!lNodeBiomass.isEmpty()) {
                            System.out.println("Updating Initial Biomass...");
                            se.updateBiomass(startZone.getManipulationID(), lNodeBiomass, 0);
                        }

                        se.getBiomass(startZone.getManipulationID(), 0, 0);

                        world.setEnvironment(env);
                        world.setPlayer(client.getPlayer());
                        responseGetEnv.setWorld(world);
                        client.setWorld(world);

                        WorldDAO.updateLastPlayed(world.getID());
                        WorldDAO.updateWorldProperties(world);

                        int initialAmount = 3;

                        for (SpeciesZoneType szt : se.getSpecies().values()) {
                            int species_id = GameServer.getInstance().getSpeciesTypeByNodeID(szt.getNodeIndex()).getID();

                            se.setParameter(0, szt, startZone.getManipulationID(), Constants.PARAMETER_X, szt.getParamX());

                            world.getGameEngine().createOrganisms(species_id, startZone.getID(), initialAmount, Constants.CREATE_STATUS_DEFAULT);
                            world.getGameEngine().createOrganismsByBirth(species_id, startZone.getID(), szt.getSpeciesCount() - initialAmount);
                        }

                        try {
                            String csv = null;

                            while (true) {
                                csv = se.getBiomassCSVString(startZone.getManipulationID());

                                if (!csv.isEmpty()) {
                                    break;
                                } else {
                                    System.out.println("Error: CSV [" + startZone.getManipulationID() + "] Retrieval Failed!");
                                }
                            }

                            BiomassCSVDAO.createCSV(startZone.getManipulationID(), GameServer.removeNodesFromCSV(csv));
                            SpeciesCSVDAO.createCSV(startZone.getManipulationID(), GameServer.convertBiomassCSVtoSpeciesCSV(csv));

                            String score_csv = ",\"Environment Score\"\n1,0";
                            ScoreCSVDAO.createCSV(startZone.getID(), score_csv);
                            startZone.setScoreCSV(score_csv);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            System.err.println(ex.getMessage());
                        }
                    }
                } else {
                    responseJoinPvEWorld.setStatus((short) 1); // World Full
                }
            }

            if (world.getPlayers().size() == 1) {
                world.getGameEngine().start();
            }
        }

        ResponseChat responseChat = new ResponseChat();
        responseChat.setMessage("[" + client.getPlayer().getUsername() + "] has logged on.");
View Full Code Here

TOP

Related Classes of model.World

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.