Package model

Examples of model.PvPWorldMap


    @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());
View Full Code Here


                    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) {
View Full Code Here

            if (world.getGameMode() == Constants.GAME_TYPE_PVP) {
                client.getServer().addToActivePvPWorld(world);

                //Create a pvp map for this world
                PvPWorldMap pvpMap = new PvPWorldMap(world.getID(), world.getMaxPlayers());
                client.getServer().addPvPWorldMap(pvpMap);

                WorldMapDAO.savePvPWorldMap(pvpMap);
            } else if (world.getGameMode() == Constants.GAME_TYPE_PVE) {
                client.getServer().addToActivePvEWorld(world);
View Full Code Here

     * @return Returns a PvPWorldMapType from database by matching worldIDFk
     * If none found returns null.
     * @throws SQLException
     */
    public static PvPWorldMap getPvPWorldMapByWorldID(int worldId) throws SQLException {
        PvPWorldMap returnPvPWorldMap = null;

        if (worldId <= 0) {
            System.out.println("In WorldMapDAO.java -- worldId, passed argument, value is: " + worldId);
            System.out.println("Expected value > 0\nReturning null.");
        } else {
            String query = "SELECT * FROM world_map WHERE world_id = ?";

            Connection connection = null;
            PreparedStatement pstmt = null;

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

                if (rs.next()) {
                    returnPvPWorldMap = new PvPWorldMap();
                    returnPvPWorldMap.setTableID(rs.getInt("table_id"));
                    returnPvPWorldMap.setWorldID(rs.getInt("world_id"));
                    returnPvPWorldMap.setTeam0Map(rs.getString("team0_map"));
                    returnPvPWorldMap.setTeam1Map(rs.getString("team1_map"));
                }

                rs.close();
                pstmt.close();
            } catch (SQLException ex) {
View Full Code Here

     * @return Returns a PvPWorldMapType from database by matching worldIDFk
     * which is extracted from passed map. If none found returns null.
     * @throws SQLException
     */
    public static PvPWorldMap getPvPWorldMapByWorldID(PvPWorldMap map) throws SQLException {
        PvPWorldMap returnPvPWorldMap = null;

        if (map == null || map.getWorldID() <= 0) {
            System.out.println("In WorldMapDAO.java -- map is null or worldIDFk <= 0");
            System.out.println("Expected value > 0\nReturning null");
        } else {
            String query = "SELECT * FROM world_map WHERE world_id = ?";

            Connection connection = null;
            PreparedStatement pstmt = null;

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

                if (rs.next()) {
                    returnPvPWorldMap = new PvPWorldMap();
                    returnPvPWorldMap.setTableID(rs.getInt("table_id"));
                    returnPvPWorldMap.setWorldID(rs.getInt("world_id"));
                    returnPvPWorldMap.setTeam0Map(rs.getString("team0_map"));
                    returnPvPWorldMap.setTeam1Map(rs.getString("team1_map"));
                }

                rs.close();
                pstmt.close();
            } catch (SQLException ex) {
View Full Code Here

     * @return Returns a PvPWorldMapType from database by matching worldIDFk
     * which is extracted from passed worldIdPk. If none found returns null.
     * @throws SQLException
     */
    public static PvPWorldMap getPvPWorldMapByWorldID(World world) throws SQLException {
        PvPWorldMap returnPvPWorldMap = null;

        if (world == null || world.getID() <= 0) {
            System.out.println("In WorldMapDAO.java -- world is null or worldIdPk <= 0");
            System.out.println("Expected value > 0\nReturning null");
        } else {
            String query = "SELECT * FROM world_map WHERE world_id = ?";

            Connection connection = null;
            PreparedStatement pstmt = null;

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

                if (rs.next()) {
                    returnPvPWorldMap = new PvPWorldMap();
                    returnPvPWorldMap.setTableID(rs.getInt("table_id"));
                    returnPvPWorldMap.setWorldID(rs.getInt("world_id"));
                    returnPvPWorldMap.setTeam0Map(rs.getString("team0_map"));
                    returnPvPWorldMap.setTeam1Map(rs.getString("team1_map"));
                }

                rs.close();
                pstmt.close();
            } catch (SQLException ex) {
View Full Code Here

    public static void updatePvPWorldMap(PvPWorldMap map) throws SQLException {
        if (map == null || map.getWorldID() <= 0) {
            System.out.println("In WorldMapDAO.java -- map is null or worldIDFk <= 0");
            System.out.println("Expected value > 0");
        } else {
            PvPWorldMap checkPvPWorldMap = getPvPWorldMapByWorldID(map);

            if (checkPvPWorldMap == null || checkPvPWorldMap.getTableID() == 0) {
                System.out.println("PvPWorldMap does not exist in the database.");
            } else {
                String query = "UPDATE world_map SET world_id = ?, team0_map = ?, team1_map = ?, square_size = ? WHERE table_id = ?";

                Connection connection = null;
                PreparedStatement pstmt = null;

                try {
                    connection = DAO.getDataSource().getConnection();
                    pstmt = connection.prepareStatement(query);
                    pstmt.setInt(1, map.getWorldID());
                    pstmt.setString(2, map.getTeam0Map());
                    pstmt.setString(3, map.getTeam1Map());
                    pstmt.setInt(4, 0);
                    pstmt.setInt(5, checkPvPWorldMap.getTableID());
                    pstmt.execute();
                    pstmt.close();
                } finally {
                    if (connection != null) {
                        connection.close();
View Full Code Here

                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;
View Full Code Here

     */
    public void printAllMaps() {
        System.out.println("********All maps start**********");
        System.out.println("All PvP maps====================");
        for (Integer key : pvpWorldMaps.keySet()) {
            PvPWorldMap pvpMap = pvpWorldMaps.get(key);
            pvpMap.printObject();
        }

        System.out.println("All PvE maps====================");
        for (Integer key : pveWorldMaps.keySet()) {
            PvEWorldMap pveMap = pveWorldMaps.get(key);
View Full Code Here

                        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());
View Full Code Here

TOP

Related Classes of model.PvPWorldMap

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.