Package model

Examples of model.World


    @Transactional
    public void generateWorldsForTest() {

        for (int i = 0; i < 10000; i++) {

            World world = new World();
            world.randomNumber = i; // not really a random number. But we can test with that...
            entitiyManagerProvider.get().persist(world);

        }
View Full Code Here


    }

    @Override
    public void doBusiness() throws Exception {
        //If it is a pvp world, make sure that the two teams have equal number of players.
        World pvpWorld = client.getServer().getActivePvPWorld(worldName);
        if (pvpWorld != null) {//The world is a pvp world.
            PvPWorldMap map = client.getServer().getPvPWorldMap(pvpWorld.getID());
            System.out.println("Original PvP Map:");
            map.printObject();

            if (map != null) {
                int team0PlayerNum = map.getTeam0().size();
                int team1PlayerNum = map.getTeam1().size();
                if (team0PlayerNum > team1PlayerNum) {
                    int diff = team0PlayerNum - team1PlayerNum;
                    for (int i = 0; i < diff; i++) {
                        int playerPosition = map.removeLastOnePlayerFromTeamN(0);

                        //Remove the environment in row: 0, position: playerPosition of the current world.
                        Environment removedEnv = client.getServer().removeAnEnvFromWorld(pvpWorld.getID(), Constants.GAME_TYPE_PVP, 0, playerPosition);

                        EnvironmentDAO.deleteEnvironmentByID(removedEnv.getID());
                        AvatarDAO.deleteAvatarByID(client.getAvatar().getID());
                    }
                } else if (team1PlayerNum > team0PlayerNum) {
                    int diff = team1PlayerNum - team0PlayerNum;
                    for (int i = 0; i < diff; i++) {
                        int playerPosition = map.removeLastOnePlayerFromTeamN(1);

                        //Remove the environment in row: 0, position: playerPosition of the current world.
                        Environment removedEnv = client.getServer().removeAnEnvFromWorld(pvpWorld.getID(), Constants.GAME_TYPE_PVP, 0, playerPosition);

                        EnvironmentDAO.deleteEnvironmentByID(removedEnv.getID());
                        AvatarDAO.deleteAvatarByID(client.getAvatar().getID());
                    }
                }
            } else {
                System.out.println("PvP world map is null");
            }

        }

        //Until now the world, environment, avatar are ready for both buffer and database
        //After this block the zones will be ready for both buffer and database too.
        //In this block each environment will be assigned a map id.
        Random ran = new Random();
        World world = client.getServer().getOnlineActiveWorld(worldName);
        if (world != null) {
            for (Environment env : world.getEnvironments()) {
                if (env.getOwnerID() == client.getPlayer().getID()) {//Find the environment of the current player
                    if (!env.isOldEnvironment()) {//It is a new environment.
                        EnvironmentDAO.updateEnvironment(env);

                        //Handle the zones in this environment.
View Full Code Here

    }

    @Override
    public void doBusiness() throws Exception {
        //The target world is PvP world, so it is only searched in the active pvp worlds.
        World world = client.getServer().getActivePvPWorld(worldName);

        if (world != null) {//The requested world exists
            System.out.println("*******The pvp world start*******");
            world.toString();
            System.out.println("*******The pvp world end*******");

            if (world.isHasStarted()) {//The requested PvP world has started.
                responseJoinPvPWorld.setStatus((short) 1);
                System.out.println("The world has started");
            } else {
                if (world.getEnvironments().size() < world.getMaxPlayers()) {
                    responseJoinPvPWorld.setStatus((short) 0);
                    responseJoinPvPWorld.setWorld(world);

                    WorldDAO.updateWorldProperties(world);

                    //Set the world to the current thread.
                    client.setWorld(world);

                    //Create an environment for this player
                    int row = 0;//The row of the environment.
                    int col = 0;//The collumn of the environment.
                    PvPWorldMap map = client.getServer().getPvPWorldMap(world.getID());
                    if (map != null) {
                        map.assignEnvironmentPosition();
                        row = map.getRow();
                        col = map.getCol();

                        System.out.println("*****A PvP Map start*****");
                        map.printObject();
                        System.out.println("*****A PvP Map end*****");

                        try {
                            WorldMapDAO.updatePvPWorldMap(map);
                        } catch (SQLException ex) {
                        }
                    } else {
                        System.out.println("In RequestJoinPvPWorld.java---map is null");
                    }

                    //Create a new environment for this user.
                    Environment env = new Environment(world.getID());
                    env.setRow(row);
                    env.setColumn(col);
                    try {
                        EnvironmentDAO.createEnvironment(env);
                    } catch (SQLException ex) {
                    }

                    Environment sameEnv = null;
                    try {
                        sameEnv = EnvironmentDAO.getEnvironmentByWorldIDAndRowAndCol(env);//Get the environment out of db just to get its id which is generated in db.
                        if (sameEnv != null) {
                            sameEnv.toString();
                        } else {
                            System.out.println("The environment from db is null.");
                        }
                    } catch (SQLException ex) {
                    }

                    world.getEnvironments().add(sameEnv);
                    System.out.println("*****World start*****");
                    world.toString();
                    System.out.println("*****World end*****");

                    //Create an avatar for this user.
                    Avatar ava = new Avatar(-1);
                    ava.setPlayerID(client.getPlayer().getID());
                    //Set [team_no] & [envPosition] for this avatar.
                    ava.setTeamNo(sameEnv.getRow());

                    int avatar_id = AvatarDAO.createAvatar(ava);

                    ava.setPlayerID(client.getPlayer().getID());

                    client.setAvatar(ava);
                    client.setWorld(world);


                    System.out.println("*****{At the end of RequestCreateNewWorld}World start*****");
                    world.toString();
                    System.out.println("*****{At the end of RequestCreateNewWorld}World end*****");

                    //Track the current position of this player.
                    client.getServer().trackPlayerPosition(client.getPlayer().getID(), Constants.LOCATION_PVP_W_LOBBY);

                    //Add this response too all the players in the same world.
                    client.getServer().addResponseForWorld(world.getID(), responseJoinPvPWorld);

                } else {
                    responseJoinPvPWorld.setStatus((short) 1);
                    System.out.println("The world is full already.");
                }
View Full Code Here

            } catch (IOException ex) {
                System.err.println(ex.getMessage());
            }
        }

        World world = client.getWorld();

        if (world != null) {
            GameEngine gameEngine = world.getGameEngine();
            if (gameEngine != null) {
                gameEngine.run();
            }
        }
    }
View Full Code Here

    public void parse() throws IOException {
    }

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

        if (world != null) {
            world.removePlayer(client.getPlayer().getID());

            if (world.getPlayers().isEmpty()) {
                GameServer.getInstance().removeWorldAndWorldMapFromBuffer(world.getID(), world.getGameMode());
            }
        }
    }
View Full Code Here

    @Override
    public void doBusiness() throws Exception {

        if (type == 0) {
            World world = client.getWorld();

            if (world != null) {
                for (Zone zone : world.getGameEngine().getZoneList()) {
                    if (zone.isEnable()) {
                        String csv = BiomassCSVDAO.getCSV(zone.getManipulationID());

                        if (csv != null) {
                            csv = csv.substring(0, csv.lastIndexOf("\n"));

                            ResponseChartBiomass responseChartBiomass = new ResponseChartBiomass();
                            responseChartBiomass.setType(type);
                            responseChartBiomass.setCSV(csv);

                            responses.add(responseChartBiomass);
                        }
                    }
                }
            }
        } else if (type == 1) {
            World world = client.getWorld();

            if (world != null) {
                for (Zone zone : world.getGameEngine().getZoneList()) {
                    if (zone.isEnable()) {
                        String csv = SpeciesCSVDAO.getCSV(zone.getManipulationID());

                        if (csv != null) {
                            csv = csv.substring(0, csv.lastIndexOf("\n"));

                            ResponseChartBiomass responseChartBiomass = new ResponseChartBiomass();
                            responseChartBiomass.setType(type);
                            responseChartBiomass.setCSV(csv);

                            responses.add(responseChartBiomass);
                        }
                    }
                }
            }
        } else if (type == 2) {
            World world = client.getWorld();

            if (world != null) {
                for (Zone zone : world.getGameEngine().getZoneList()) {
                    if (zone.isEnable()) {
                        String csv = ScoreCSVDAO.getCSV(zone.getID());

                        if (csv != null) {
                            ResponseChartBiomass responseChartBiomass = new ResponseChartBiomass();
View Full Code Here

        worldName = DataReader.readString(dataInput);
    }

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

        if (currentWorld != null) {
            responseStartToReadyWorld.setStatus((short) 0);
            client.getServer().addResponseToOtherPeopleInTheSameWorld(client.getId(), currentWorld.getID(), responseStartToReadyWorld);

        } else {
            responseStartToReadyWorld.setStatus((short) 1);
            System.out.println("The world does not exist");
        }
View Full Code Here

    private World world;//Store the world information the client sends to server.
    // Responses
    private ResponseCreateNewWorld responseCreateNewWorld;

    public RequestCreateNewWorld() {
        world = new World(-1);
        responses.add(responseCreateNewWorld = new ResponseCreateNewWorld());
    }
View Full Code Here

    }

    @Override
    public void doBusiness() throws Exception {
        if (status) {
            World world = client.getWorld();

            if (world != null) {
                Environment env = world.getEnvByUserID(client.getPlayer().getID());

                for (Zone zone : env.getZones()) {
                    if (zone.isEnable()) {
                        zone.restart();
View Full Code Here

        status = true;
    }

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

        if (world != null) {
            world.setReady(client.getPlayer().getID(), status);

            responseReady.setStatus(status);
            responseReady.setUsername(client.getPlayer().getUsername());
//            client.getServer().addResponseToOtherPeopleInTheSameWorld(client.getId(), world.getID(), responseReady);

            if (world.isReady()) {
                for (Zone zone : world.getGameEngine().getZoneList()) {
                    if (zone.isEnable()) {
                        zone.startTimeActiveTimer();
                    }
                }

                responses.add(responseStartWorld = new ResponseStartWorld());

                responseStartWorld.setStatus(true);

                responses.add(responseUpdateTime = new ResponseUpdateTime());

                responseUpdateTime.setMonth(world.getMonth());
                responseUpdateTime.setYear(world.getYear());
                responseUpdateTime.setDuration(Constants.MONTH_DURATION);
                responseUpdateTime.setCurrent((int) world.getSeconds());
                responseUpdateTime.setRate(world.getGameEngine().getGameScale());
            }
        }
    }
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.