Package model

Examples of model.Avatar


                    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);


View Full Code Here


        return avatar_id;
    }

    public static Avatar getAvatar(int avatar_id) throws SQLException {
        Avatar avatar = null;

        String query = "SELECT * FROM `avatar` WHERE `avatar_id` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

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

            if (rs.next()) {
                avatar = new Avatar(rs.getInt("avatar_id"));
                avatar.setAvatarType(rs.getInt("type"));
                avatar.setExperience(rs.getInt("experience"));
                avatar.setAbilityPoints(rs.getInt("ability_points"));
                avatar.setCurrency(rs.getInt("currency"));
                avatar.setLevel(rs.getInt("level"));
                avatar.setGameScaleVote(rs.getInt("gamescale_vote"));
                avatar.setLastPlayed(rs.getString("last_played"));
            }

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

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

            while (rs.next()) {
                Avatar avatar = new Avatar(rs.getInt("avatar_id"));
                avatar.setAvatarType(rs.getInt("type"));
                avatar.setExperience(rs.getInt("experience"));
                avatar.setAbilityPoints(rs.getInt("ability_points"));
                avatar.setCurrency(rs.getInt("currency"));
                avatar.setLevel(rs.getInt("level"));
                avatar.setGameScaleVote(rs.getInt("gamescale_vote"));
                avatar.setLastPlayed(rs.getString("last_played"));

                avatars.add(avatar);
            }

            rs.close();
View Full Code Here

        avatar_id = DataReader.readInt(dataInput);
    }

    @Override
    public void doBusiness() throws Exception {
        Avatar avatar = client.getAvatar();

        if (avatar != null) {
        } else {
//            avatar = AvatarDAO.getAvatar(avatar_id);
            avatar = AvatarDAO.getAvatars(client.getPlayer().getID()).get(0);
View Full Code Here

     * @return Returns the first AvatarType which matches the passed argument,
     * avatarType, in the database.  If none found returns null.
     * @throws SQLException
     */
    public static Avatar getAvatarByAvatarTypeSpecialUse(String avatarType) throws SQLException {
        Avatar returnFirstAvatar = null;

        List<Avatar> holdAvatarList = new ArrayList<Avatar>();

        String query = "SELECT * FROM `avatar` WHERE `type` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

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

            while (rs.next()) {
                Avatar holdAvatar = new Avatar(rs.getInt("avatar_id"));
                holdAvatar.setAvatarType(rs.getInt("type"));
                holdAvatar.setExperience(rs.getInt("experience"));
                holdAvatar.setAbilityPoints(rs.getInt("ability_points"));
                holdAvatar.setCurrency(rs.getInt("currency"));
                holdAvatar.setPlayerID(rs.getInt("player_id"));
                holdAvatar.setLevel(rs.getInt("level"));
                holdAvatar.setGameScaleVote(rs.getInt("gamescale_vote"));
                holdAvatarList.add(holdAvatar);
            }

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

            } else if (PlayerDAO.containsUsername(username)) {
                responseRegist.setStatus((short) 2);
            } else {
                int player_id = PlayerDAO.createAccount(email, password, username, first_name, last_name, client.getIP());
               
                Avatar avatar = new Avatar(-1);
                avatar.setAvatarType(1);
                avatar.setCurrency(Constants.INITIAL_GOLD);
                avatar.setPlayerID(player_id);
                AvatarDAO.createAvatar(avatar);
                responseRegist.setStatus((short) 0);
            }
        }
    }
View Full Code Here

            }
        }
    }

    public void updateCash(Player player, int amount) {
        Avatar avatar = player.getAvatar();
        avatar.setCurrency(Math.min(Constants.MAX_GOLD, avatar.getCurrency() + amount));

        try {
            AvatarDAO.updateCurrency(avatar);
        } catch (SQLException ex) {
            System.err.println(ex.getMessage());
        }

        ResponseUpdateCash updateResponse = new ResponseUpdateCash();
        updateResponse.setAmount(amount);
        updateResponse.setCash(avatar.getCurrency());

        addResponseForUser(player.getID(), updateResponse);
    }
View Full Code Here

    }

    public void updateExperience(Player player, int amount) {
        amount *= Constants.MULTIPLIER_EXP;

        Avatar avatar = player.getAvatar();
        avatar.setExperience(Math.min(ExpTable.getExp(Constants.MAX_LEVEL - 1), avatar.getExperience() + amount));

        try {
            AvatarDAO.updateExperience(avatar);
        } catch (SQLException ex) {
            System.err.println(ex.getMessage());
        }

        int oldLevel = avatar.getLevel(), newLevel = ExpTable.getLevel(avatar.getExperience());

        if (newLevel > oldLevel) {
            avatar.setLevel(newLevel);

            try {
                AvatarDAO.updateLevel(avatar);
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }

            ResponseUpdateLevel updateLevelResponse = new ResponseUpdateLevel();
            updateLevelResponse.setAmount(newLevel - oldLevel);
            updateLevelResponse.setLevel(newLevel);

            String range = String.valueOf(ExpTable.getExpToAdvance(oldLevel + 1));
            for (int i = oldLevel + 2; i <= newLevel; i++) {
                range += "," + ExpTable.getExpToAdvance(i);
            }
            updateLevelResponse.setRange(range);

            addResponseForUser(player.getID(), updateLevelResponse);

            updateCash(player, amount);

            List<SpeciesType> unlockList = new ArrayList<SpeciesType>();

            try {
                for (int i = oldLevel + 1; i <= newLevel; i++) {
                    unlockList.addAll(ShopDAO.getAnimalsByLevel(i));
                    unlockList.addAll(ShopDAO.getPlantsByLevel(i));
                }

                ResponseShopUnlock unlockResponse = new ResponseShopUnlock();
                unlockResponse.setUnlockList(unlockList);

                GameServer.getInstance().addResponseForUser(player.getID(), unlockResponse);
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }
        }

        ResponseUpdateXP updateResponse = new ResponseUpdateXP();
        updateResponse.setAmount(amount);
        updateResponse.setTotal(avatar.getExperience());

        addResponseForUser(player.getID(), updateResponse);
    }
View Full Code Here

        }
    }

    public short buyOrganism(int organism_type, int player_id, int species_id, int amount, int zone_id, float xCoor, float yCoor) {
        Player player = GameServer.getInstance().getActivePlayer(player_id);
        Avatar avatar = player.getAvatar();

        if (avatar != null) {
            SpeciesType species = null;

            if (organism_type == Constants.ORGANISM_TYPE_PLANT) {
                species = GameServer.getInstance().getPlantType(species_id);
            } else if (organism_type == Constants.ORGANISM_TYPE_ANIMAL) {
                species = GameServer.getInstance().getAnimalType(species_id);
            }

            boolean canBuy = avatar.spendCash(species.getCost());

            if (canBuy) {
                GameServer.getInstance().updateCash(player, 0);

                Zone zone = zones.get(zone_id);
View Full Code Here

TOP

Related Classes of model.Avatar

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.