Package model

Examples of model.World


        System.out.println("****Parse end*****");
    }

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

        if (world != null) {
            for (Environment env : world.getEnvironments()) {
                if (env.getOwnerID() == client.getPlayer().getID()) {
                    int teamNo = env.getRow();
                    int position = env.getColumn();

                    if (teamNo != teamNumber) {
                        PvPWorldMap map = client.getServer().getPvPWorldMap(world.getID());

                        //Try to join new team
                        int newPosition = map.getPositionInNewTeam(teamNumber);
                        if (newPosition >= 0) {//Change team successful!
                            //Quit old team
                            map.quitOldTeamAndPosition(teamNo, position);
                            //Update the map
                            WorldMapDAO.updatePvPWorldMap(map);

                            //Update environment.
                            int row = teamNumber;
                            int col = newPosition;
                            env.setRow(row);
                            env.setColumn(col);
                            EnvironmentDAO.updateEnvironment(env);

                            //Update avatar
                            client.getAvatar().setTeamNo(row);
                            AvatarDAO.updateAvatar(client.getAvatar());

                            responseChangeTeamPVP.setWorld(world);
                        } else {
                            System.out.println("The target team is full already.");
                        }
                    } else {
                        System.out.println("Team number is the same.");
                    }
                }
            }
        } else {
            System.out.println("World with the name does not exist");
        }

        if (responseChangeTeamPVP.getStatus() == 0) {
            client.getServer().addResponseForWorld(world.getID(), responseChangeTeamPVP);
        }
    }
View Full Code Here


    private World world;
    // Responses
    private ResponseSearchPrivateWorld responseSearchPrivateWorld;

    public RequestSearchPrivateWorld() {
        world = new World(-1);
        responses.add(responseSearchPrivateWorld = new ResponseSearchPrivateWorld());
    }
View Full Code Here

    }

    @Override
    public void doBusiness() throws Exception {
        //PvP and PvE worlds will be stored in db. After a pvp world ends, it will be deleted from db.
        World wld = null;

        try {
            wld = WorldDAO.getPrivateWorldByWorldNameAndPassword(world);

            if (wld != null) {
                System.out.println("*****Searched world from db start*****");
                wld.toString();
                System.out.println("*****Searched world from db end*****");
            } else {
                System.out.println("Searched world is null");
            }
        } catch (SQLException ex) {
        }

        if (wld != null) {
            if (wld.getEnvironments().size() < wld.getMaxPlayers()) {
                if (wld.getGameMode() == Constants.GAME_TYPE_PVP && wld.isHasStarted()) {
                    responseSearchPrivateWorld.setStatus((short) 1);
                    System.out.println("The pvp world has been started");
                } else {//The world could be join
                    responseSearchPrivateWorld.setStatus((short) 0);
                    responseSearchPrivateWorld.setWorld(wld);
View Full Code Here

     * Test of getEnvironmentByWorldID method, of class EnvironmentDAO.
     */
    @Test
    public void testGetEnvironmentByWorldID_World() throws Exception {
        System.out.println("getEnvironmentByWorldID");
        World world = null;
        EnvironmentDAO instance = new EnvironmentDAO();
        List expResult = null;
        List result = instance.getEnvironmentByWorldID(world);
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
View Full Code Here

            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, Constants.GAME_TYPE_PVE);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                World world = new World(rs.getInt("world_id"));
                world.setGameName(rs.getString("game_name"));
                world.setSeconds(rs.getLong("seconds"));
                world.setDays(rs.getInt("days"));
                world.setMaxPlayers(rs.getInt("max_players"));
                world.setEnvType(rs.getString("env_type"));
                world.setAccessType(rs.getShort("access_type"));
                world.setGameMode(rs.getShort("game_mode"));
                world.setCreatorID(rs.getInt("creator_id"));
                world.setPassword(rs.getString("password"));
                worldList.add(world);
            }

            rs.close();
            pstmt.close();

            for (World world : worldList) {
                world.setEnvironments(EnvironmentDAO.getEnvironmentByWorldID(world.getID()));
            }
        } finally {
            if (connection != null) {
                connection.close();
            }
View Full Code Here

            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, Constants.GAME_TYPE_PVP);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                World world = new World(rs.getInt("world_id"));
                world.setGameName(rs.getString("game_name"));
                world.setSeconds(rs.getLong("seconds"));
                world.setDays(rs.getInt("days"));
                world.setMaxPlayers(rs.getInt("max_players"));
                world.setEnvType(rs.getString("env_type"));
                world.setAccessType(rs.getShort("access_type"));
                world.setGameMode(rs.getShort("game_mode"));
                world.setPassword(rs.getString("password"));
                world.setCreatorID(rs.getInt("creator_id"));
                worldList.add(world);
            }

            rs.close();
            pstmt.close();

            for (World world : worldList) {
                world.setEnvironments(EnvironmentDAO.getEnvironmentByWorldID(world.getID()));
            }
        } finally {
            if (connection != null) {
                connection.close();
            }
View Full Code Here

            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, player_id);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                World world = new World(rs.getInt("world_id"));
                world.setGameName(rs.getString("game_name"));
                world.setPlayTime(rs.getInt("play_time"));
                world.setTimeRate(rs.getFloat("time_rate"));
                world.setSeconds(rs.getLong("seconds"));
                world.setYear(rs.getInt("year"));
                world.setMonth(rs.getInt("month"));
                world.setDays(rs.getInt("days"));
                world.setMaxPlayers(rs.getInt("max_players"));
                world.setEnvType(rs.getString("env_type"));
                world.setAccessType(rs.getShort("access_type"));
                world.setGameMode(rs.getShort("game_mode"));
                world.setPassword(rs.getString("password"));
                world.setCreatorID(rs.getInt("creator_id"));
                world.setLastPlayed(rs.getString("last_played"));
                worldList.add(world);
            }

            rs.close();
            pstmt.close();
View Full Code Here

     * world and list of EnvironmentType that is to say list of environments
     * belonging to the world.  If no world found in database returns null.
     * @throws SQLException
     */
    public static World getWorldByName(String name) throws SQLException {
        World world = null;

        String query = "SELECT * FROM `world` WHERE `game_name` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setString(1, name);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                world = new World(rs.getInt("world_id"));
                world.setGameName(rs.getString("game_name"));
                world.setPlayTime(rs.getInt("play_time"));
                world.setTimeRate(rs.getFloat("time_rate"));
                world.setSeconds(rs.getLong("seconds"));
                world.setYear(rs.getInt("year"));
                world.setMonth(rs.getInt("month"));
                world.setDays(rs.getInt("days"));
                world.setMaxPlayers(rs.getInt("max_players"));
                world.setEnvType(rs.getString("env_type"));
                world.setAccessType(rs.getShort("access_type"));
                world.setGameMode(rs.getShort("game_mode"));
                world.setCreatorID(rs.getInt("creator_id"));
                world.setPassword(rs.getString("password"));
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

        return world;
    }

    public static World getWorldByPlayerID(int player_id) throws SQLException {
        World world = null;

        String query = "SELECT * FROM `world` WHERE `creator_id` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, player_id);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                world = new World(rs.getInt("world_id"));
                world.setGameName(rs.getString("game_name"));
                world.setPlayTime(rs.getInt("play_time"));
                world.setTimeRate(rs.getFloat("time_rate"));
                world.setSeconds(rs.getLong("seconds"));
                world.setYear(rs.getInt("year"));
                world.setMonth(rs.getInt("month"));
                world.setDays(rs.getInt("days"));
                world.setMaxPlayers(rs.getInt("max_players"));
                world.setEnvType(rs.getString("env_type"));
                world.setAccessType(rs.getShort("access_type"));
                world.setGameMode(rs.getShort("game_mode"));
                world.setCreatorID(rs.getInt("creator_id"));
                world.setPassword(rs.getString("password"));
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

     * EnvironmentType that is to say list of environments belonging to the world.
     * If no world found in database returns null.
     * @throws SQLException
     */
    public static World getPrivateWorldByWorldNameAndPassword(World world) throws SQLException {
        World returnWorld = null;

        String query = "SELECT * FROM `world` WHERE `access_type` = ? AND `game_name` = ? AND `password` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setShort(1, world.getAccessType());
            pstmt.setString(2, world.getGameName());
            pstmt.setString(3, world.getPassword());
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                returnWorld = new World(rs.getInt("world_id"));
                returnWorld.setGameName(rs.getString("game_name"));
                returnWorld.setSeconds(rs.getLong("seconds"));
                returnWorld.setDays(rs.getInt("days"));
                returnWorld.setMaxPlayers(rs.getInt("max_players"));
                returnWorld.setEnvType(rs.getString("env_type"));
                returnWorld.setAccessType(rs.getShort("access_type"));
                returnWorld.setGameMode(rs.getShort("game_mode"));
                returnWorld.setCreatorID(rs.getInt("creator_id"));
                returnWorld.setPassword(rs.getString("password"));
            }

            rs.close();
            pstmt.close();

            returnWorld.setCreatorID(returnWorld.getCreatorID());
            returnWorld.setEnvironments(EnvironmentDAO.getEnvironmentByWorldID(returnWorld.getID()));
        } finally {
            if (connection != null) {
                connection.close();
            }
        }
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.