Search in sources :

Example 96 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class MTSHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!c.getPlayer().getCashShop().isOpened()) {
        return;
    }
    if (slea.available() > 0) {
        byte op = slea.readByte();
        if (op == 2) {
            // put item up for sale
            byte itemtype = slea.readByte();
            int itemid = slea.readInt();
            slea.readShort();
            slea.skip(7);
            short stars = 1;
            if (itemtype == 1) {
                slea.skip(32);
            } else {
                stars = slea.readShort();
            }
            // another useless thing (owner)
            slea.readMapleAsciiString();
            if (itemtype == 1) {
                slea.skip(32);
            } else {
                slea.readShort();
            }
            short slot;
            short quantity;
            if (itemtype != 1) {
                if (itemid / 10000 == 207 || itemid / 10000 == 233) {
                    slea.skip(8);
                }
                slot = (short) slea.readInt();
            } else {
                slot = (short) slea.readInt();
            }
            if (itemtype != 1) {
                if (itemid / 10000 == 207 || itemid / 10000 == 233) {
                    quantity = stars;
                    slea.skip(4);
                } else {
                    quantity = (short) slea.readInt();
                }
            } else {
                quantity = (byte) slea.readInt();
            }
            int price = slea.readInt();
            if (itemtype == 1) {
                quantity = 1;
            }
            if (quantity < 0 || price < 110 || c.getPlayer().getItemQuantity(itemid, false) < quantity) {
                return;
            }
            MapleInventoryType invType = ItemConstants.getInventoryType(itemid);
            Item i = c.getPlayer().getInventory(invType).getItem(slot).copy();
            if (i != null && c.getPlayer().getMeso() >= 5000) {
                Connection con = null;
                try {
                    con = DatabaseConnection.getConnection();
                    PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE seller = ?");
                    ps.setInt(1, c.getPlayer().getId());
                    ResultSet rs = ps.executeQuery();
                    if (rs.next()) {
                        if (rs.getInt(1) > 10) {
                            // They have more than 10 items up for sale already!
                            c.getPlayer().dropMessage(1, "You already have 10 items up for auction!");
                            c.announce(getMTS(1, 0, 0));
                            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
                            rs.close();
                            ps.close();
                            return;
                        }
                    }
                    rs.close();
                    ps.close();
                    Calendar calendar = Calendar.getInstance();
                    int year;
                    int month;
                    int day;
                    int oldmax = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    int oldday = calendar.get(Calendar.DAY_OF_MONTH) + 7;
                    if (oldmax < oldday) {
                        if (calendar.get(Calendar.MONTH) + 2 > 12) {
                            year = calendar.get(Calendar.YEAR) + 1;
                            month = 1;
                            calendar.set(year, month, 1);
                            day = oldday - oldmax;
                        } else {
                            month = calendar.get(Calendar.MONTH) + 2;
                            year = calendar.get(Calendar.YEAR);
                            calendar.set(year, month, 1);
                            day = oldday - oldmax;
                        }
                    } else {
                        day = calendar.get(Calendar.DAY_OF_MONTH) + 7;
                        month = calendar.get(Calendar.MONTH);
                        year = calendar.get(Calendar.YEAR);
                    }
                    String date = year + "-";
                    if (month < 10) {
                        date += "0" + month + "-";
                    } else {
                        date += month + "-";
                    }
                    if (day < 10) {
                        date += "0" + day;
                    } else {
                        date += day + "";
                    }
                    if (!i.getInventoryType().equals(MapleInventoryType.EQUIP)) {
                        Item item = (Item) i;
                        ps = con.prepareStatement("INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, owner, sellername, sell_ends) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
                        ps.setInt(1, 1);
                        ps.setInt(2, (int) invType.getType());
                        ps.setInt(3, item.getItemId());
                        ps.setInt(4, quantity);
                        ps.setInt(5, c.getPlayer().getId());
                        ps.setInt(6, price);
                        ps.setString(7, item.getOwner());
                        ps.setString(8, c.getPlayer().getName());
                        ps.setString(9, date);
                    } else {
                        Equip equip = (Equip) i;
                        ps = con.prepareStatement("INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, locked, owner, sellername, sell_ends, vicious, flag) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                        ps.setInt(1, 1);
                        ps.setInt(2, (int) invType.getType());
                        ps.setInt(3, equip.getItemId());
                        ps.setInt(4, quantity);
                        ps.setInt(5, c.getPlayer().getId());
                        ps.setInt(6, price);
                        ps.setInt(7, equip.getUpgradeSlots());
                        ps.setInt(8, equip.getLevel());
                        ps.setInt(9, equip.getStr());
                        ps.setInt(10, equip.getDex());
                        ps.setInt(11, equip.getInt());
                        ps.setInt(12, equip.getLuk());
                        ps.setInt(13, equip.getHp());
                        ps.setInt(14, equip.getMp());
                        ps.setInt(15, equip.getWatk());
                        ps.setInt(16, equip.getMatk());
                        ps.setInt(17, equip.getWdef());
                        ps.setInt(18, equip.getMdef());
                        ps.setInt(19, equip.getAcc());
                        ps.setInt(20, equip.getAvoid());
                        ps.setInt(21, equip.getHands());
                        ps.setInt(22, equip.getSpeed());
                        ps.setInt(23, equip.getJump());
                        ps.setInt(24, 0);
                        ps.setString(25, equip.getOwner());
                        ps.setString(26, c.getPlayer().getName());
                        ps.setString(27, date);
                        ps.setInt(28, equip.getVicious());
                        ps.setInt(29, equip.getFlag());
                    }
                    ps.executeUpdate();
                    ps.close();
                    MapleInventoryManipulator.removeFromSlot(c, invType, slot, quantity, false);
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                c.getPlayer().gainMeso(-5000, false);
                c.announce(MaplePacketCreator.MTSConfirmSell());
                c.announce(getMTS(1, 0, 0));
                c.announce(MaplePacketCreator.enableCSUse());
                c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
            }
        } else if (op == 3) {
        // send offer for wanted item
        } else if (op == 4) {
            // list wanted item
            slea.readInt();
            slea.readInt();
            slea.readInt();
            slea.readShort();
            slea.readMapleAsciiString();
        } else if (op == 5) {
            // change page
            int tab = slea.readInt();
            int type = slea.readInt();
            int page = slea.readInt();
            c.getPlayer().changePage(page);
            if (tab == 4 && type == 0) {
                c.announce(getCart(c.getPlayer().getId()));
            } else if (tab == c.getPlayer().getCurrentTab() && type == c.getPlayer().getCurrentType() && c.getPlayer().getSearch() != null) {
                c.announce(getMTSSearch(tab, type, c.getPlayer().getCurrentCI(), c.getPlayer().getSearch(), page));
            } else {
                c.getPlayer().setSearch(null);
                c.announce(getMTS(tab, type, page));
            }
            c.getPlayer().changeTab(tab);
            c.getPlayer().changeType(type);
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 6) {
            // search
            int tab = slea.readInt();
            int type = slea.readInt();
            slea.readInt();
            int ci = slea.readInt();
            String search = slea.readMapleAsciiString();
            c.getPlayer().setSearch(search);
            c.getPlayer().changeTab(tab);
            c.getPlayer().changeType(type);
            c.getPlayer().changeCI(ci);
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.enableActions());
            c.announce(getMTSSearch(tab, type, ci, search, c.getPlayer().getCurrentPage()));
            c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 7) {
            // cancel sale
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            try {
                con = DatabaseConnection.getConnection();
                PreparedStatement ps = con.prepareStatement("UPDATE mts_items SET transfer = 1 WHERE id = ? AND seller = ?");
                ps.setInt(1, id);
                ps.setInt(2, c.getPlayer().getId());
                ps.executeUpdate();
                ps.close();
                ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
                ps.setInt(1, id);
                ps.executeUpdate();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
        } else if (op == 8) {
            // transfer item from transfer inv.
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            PreparedStatement ps;
            ResultSet rs;
            try {
                con = DatabaseConnection.getConnection();
                ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 1  AND id= ? ORDER BY id DESC");
                ps.setInt(1, c.getPlayer().getId());
                ps.setInt(2, id);
                rs = ps.executeQuery();
                if (rs.next()) {
                    Item i;
                    if (rs.getInt("type") != 1) {
                        Item ii = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
                        ii.setOwner(rs.getString("owner"));
                        ii.setPosition(c.getPlayer().getInventory(ItemConstants.getInventoryType(rs.getInt("itemid"))).getNextFreeSlot());
                        i = ii.copy();
                    } else {
                        Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
                        equip.setOwner(rs.getString("owner"));
                        equip.setQuantity((short) 1);
                        equip.setAcc((short) rs.getInt("acc"));
                        equip.setAvoid((short) rs.getInt("avoid"));
                        equip.setDex((short) rs.getInt("dex"));
                        equip.setHands((short) rs.getInt("hands"));
                        equip.setHp((short) rs.getInt("hp"));
                        equip.setInt((short) rs.getInt("int"));
                        equip.setJump((short) rs.getInt("jump"));
                        equip.setLuk((short) rs.getInt("luk"));
                        equip.setMatk((short) rs.getInt("matk"));
                        equip.setMdef((short) rs.getInt("mdef"));
                        equip.setMp((short) rs.getInt("mp"));
                        equip.setSpeed((short) rs.getInt("speed"));
                        equip.setStr((short) rs.getInt("str"));
                        equip.setWatk((short) rs.getInt("watk"));
                        equip.setWdef((short) rs.getInt("wdef"));
                        equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
                        equip.setLevel((byte) rs.getInt("level"));
                        equip.setVicious((byte) rs.getInt("vicious"));
                        equip.setFlag((byte) rs.getInt("flag"));
                        equip.setPosition(c.getPlayer().getInventory(ItemConstants.getInventoryType(rs.getInt("itemid"))).getNextFreeSlot());
                        i = equip.copy();
                    }
                    try (PreparedStatement pse = con.prepareStatement("DELETE FROM mts_items WHERE id = ? AND seller = ? AND transfer = 1")) {
                        pse.setInt(1, id);
                        pse.setInt(2, c.getPlayer().getId());
                        pse.executeUpdate();
                    }
                    MapleInventoryManipulator.addFromDrop(c, i, false);
                    c.announce(MaplePacketCreator.enableCSUse());
                    c.announce(getCart(c.getPlayer().getId()));
                    c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
                    c.announce(MaplePacketCreator.MTSConfirmTransfer(i.getQuantity(), i.getPosition()));
                    c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                }
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("MTS Transfer error: " + e);
            }
        } else if (op == 9) {
            // add to cart
            // id of the item
            int id = slea.readInt();
            Connection con;
            try {
                con = DatabaseConnection.getConnection();
                try (PreparedStatement ps1 = con.prepareStatement("SELECT id FROM mts_items WHERE id = ? AND seller <> ?")) {
                    // Dummy query, prevents adding to cart self owned items
                    ps1.setInt(1, id);
                    ps1.setInt(2, c.getPlayer().getId());
                    try (ResultSet rs1 = ps1.executeQuery()) {
                        if (rs1.next()) {
                            PreparedStatement ps = con.prepareStatement("SELECT cid FROM mts_cart WHERE cid = ? AND itemid = ?");
                            ps.setInt(1, c.getPlayer().getId());
                            ps.setInt(2, id);
                            try (ResultSet rs = ps.executeQuery()) {
                                if (!rs.next()) {
                                    try (PreparedStatement pse = con.prepareStatement("INSERT INTO mts_cart (cid, itemid) VALUES (?, ?)")) {
                                        pse.setInt(1, c.getPlayer().getId());
                                        pse.setInt(2, id);
                                        pse.executeUpdate();
                                    }
                                }
                            }
                        }
                    }
                }
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.enableActions());
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 10) {
            // delete from cart
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            try {
                con = DatabaseConnection.getConnection();
                try (PreparedStatement ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ? AND cid = ?")) {
                    ps.setInt(1, id);
                    ps.setInt(2, c.getPlayer().getId());
                    ps.executeUpdate();
                }
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            c.announce(getCart(c.getPlayer().getId()));
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 12) {
        // put item up for auction
        } else if (op == 13) {
        // cancel wanted cart thing
        } else if (op == 14) {
        // buy auction item now
        } else if (op == 16) {
            // buy
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            PreparedStatement ps;
            ResultSet rs;
            try {
                con = DatabaseConnection.getConnection();
                ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
                ps.setInt(1, id);
                rs = ps.executeQuery();
                if (rs.next()) {
                    // taxes
                    int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
                    if (c.getPlayer().getCashShop().getCash(4) >= price) {
                        // FIX
                        boolean alwaysnull = true;
                        for (Channel cserv : Server.getInstance().getAllChannels()) {
                            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
                            if (victim != null) {
                                victim.getCashShop().gainCash(4, rs.getInt("price"));
                                alwaysnull = false;
                            }
                        }
                        if (alwaysnull) {
                            ResultSet rse;
                            try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
                                pse.setInt(1, rs.getInt("seller"));
                                rse = pse.executeQuery();
                                if (rse.next()) {
                                    try (PreparedStatement psee = con.prepareStatement("UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?")) {
                                        psee.setInt(1, rs.getInt("price"));
                                        psee.setInt(2, rse.getInt("accountid"));
                                        psee.executeUpdate();
                                    }
                                }
                            }
                            rse.close();
                        }
                        PreparedStatement pse = con.prepareStatement("UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
                        pse.setInt(1, c.getPlayer().getId());
                        pse.setInt(2, id);
                        pse.executeUpdate();
                        pse.close();
                        pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
                        pse.setInt(1, id);
                        pse.executeUpdate();
                        pse.close();
                        c.getPlayer().getCashShop().gainCash(4, -price);
                        c.announce(MaplePacketCreator.enableCSUse());
                        c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
                        c.announce(MaplePacketCreator.MTSConfirmBuy());
                        c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
                        c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                        c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
                        c.announce(MaplePacketCreator.enableActions());
                    } else {
                        c.announce(MaplePacketCreator.MTSFailBuy());
                    }
                }
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
                c.announce(MaplePacketCreator.MTSFailBuy());
            }
        } else if (op == 17) {
            // buy from cart
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            PreparedStatement ps;
            ResultSet rs;
            try {
                con = DatabaseConnection.getConnection();
                ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
                ps.setInt(1, id);
                rs = ps.executeQuery();
                if (rs.next()) {
                    int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
                    if (c.getPlayer().getCashShop().getCash(4) >= price) {
                        for (Channel cserv : Server.getInstance().getAllChannels()) {
                            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
                            if (victim != null) {
                                victim.getCashShop().gainCash(4, rs.getInt("price"));
                            } else {
                                ResultSet rse;
                                try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
                                    pse.setInt(1, rs.getInt("seller"));
                                    rse = pse.executeQuery();
                                    if (rse.next()) {
                                        try (PreparedStatement psee = con.prepareStatement("UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?")) {
                                            psee.setInt(1, rs.getInt("price"));
                                            psee.setInt(2, rse.getInt("accountid"));
                                            psee.executeUpdate();
                                        }
                                    }
                                }
                                rse.close();
                            }
                        }
                        PreparedStatement pse = con.prepareStatement("UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
                        pse.setInt(1, c.getPlayer().getId());
                        pse.setInt(2, id);
                        pse.executeUpdate();
                        pse.close();
                        pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
                        pse.setInt(1, id);
                        pse.executeUpdate();
                        pse.close();
                        c.getPlayer().getCashShop().gainCash(4, -price);
                        c.announce(getCart(c.getPlayer().getId()));
                        c.announce(MaplePacketCreator.enableCSUse());
                        c.announce(MaplePacketCreator.MTSConfirmBuy());
                        c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
                        c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                        c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
                    } else {
                        c.announce(MaplePacketCreator.MTSFailBuy());
                    }
                }
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
                c.announce(MaplePacketCreator.MTSFailBuy());
            }
        } else {
            System.out.println("Unhandled OP(MTS): " + op + " Packet: " + slea.toString());
        }
    } else {
        c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
    }
}
Also used : MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) Channel(net.server.channel.Channel) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Item(client.inventory.Item) Equip(client.inventory.Equip) MapleInventoryType(client.inventory.MapleInventoryType) ResultSet(java.sql.ResultSet)

Example 97 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class MakerSkillHandler method addBoostedMakerItem.

private static boolean addBoostedMakerItem(MapleClient c, int itemid, int stimulantid, Map<Integer, Short> reagentids) {
    if (stimulantid != -1 && !ii.rollSuccessChance(90.0)) {
        return false;
    }
    Item item = ii.getEquipById(itemid);
    if (item == null)
        return false;
    Equip eqp = (Equip) item;
    if (ItemConstants.isAccessory(item.getItemId()) && eqp.getUpgradeSlots() <= 0)
        eqp.setUpgradeSlots(3);
    if (ServerConstants.USE_ENHANCED_CRAFTING == true) {
        if (!(c.getPlayer().isGM() && ServerConstants.USE_PERFECT_GM_SCROLL)) {
            eqp.setUpgradeSlots((byte) (eqp.getUpgradeSlots() + 1));
        }
        item = MapleItemInformationProvider.getInstance().scrollEquipWithId(eqp, 2049100, true, 2049100, c.getPlayer().isGM());
    }
    if (!reagentids.isEmpty()) {
        Map<String, Integer> stats = new LinkedHashMap<>();
        List<Short> randOption = new LinkedList<>();
        List<Short> randStat = new LinkedList<>();
        for (Entry<Integer, Short> r : reagentids.entrySet()) {
            Pair<String, Integer> reagentBuff = ii.getMakerReagentStatUpgrade(r.getKey());
            if (reagentBuff != null) {
                String s = reagentBuff.getLeft();
                if (s.substring(0, 4).contains("rand")) {
                    if (s.substring(4).equals("Stat")) {
                        randStat.add((short) (reagentBuff.getRight() * r.getValue()));
                    } else {
                        randOption.add((short) (reagentBuff.getRight() * r.getValue()));
                    }
                } else {
                    String stat = s.substring(3);
                    if (!stat.equals("ReqLevel")) {
                        // improve req level... really?
                        switch(stat) {
                            case "MaxHP":
                                stat = "MHP";
                                break;
                            case "MaxMP":
                                stat = "MMP";
                                break;
                        }
                        Integer d = stats.get(stat);
                        if (d == null) {
                            stats.put(stat, reagentBuff.getRight() * r.getValue());
                        } else {
                            stats.put(stat, d + (reagentBuff.getRight() * r.getValue()));
                        }
                    }
                }
            }
        }
        ii.improveEquipStats(eqp, stats);
        for (Short sh : randStat) {
            ii.scrollOptionEquipWithChaos(eqp, sh, false);
        }
        for (Short sh : randOption) {
            ii.scrollOptionEquipWithChaos(eqp, sh, true);
        }
    }
    if (stimulantid != -1) {
        eqp = ii.randomizeUpgradeStats(eqp);
    }
    MapleInventoryManipulator.addFromDrop(c, item, false, -1);
    c.announce(MaplePacketCreator.getShowItemGain(itemid, (short) 1, true));
    return true;
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap)

Example 98 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class AutoAssignHandler method handlePacket.

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    int[] statGain = new int[4];
    int[] statEqpd = new int[4];
    statGain[0] = 0;
    statGain[1] = 0;
    statGain[2] = 0;
    statGain[3] = 0;
    slea.skip(8);
    // useful for pirate autoassigning
    byte opt = slea.readByte();
    if (chr.getRemainingAp() < 1)
        return;
    if (ServerConstants.USE_SERVER_AUTOASSIGNER) {
        // --------- Ronan Lana's AUTOASSIGNER ---------
        // This method excels for assigning APs in such a way to cover all equipments AP requirements.
        int str = 0, dex = 0, luk = 0, int_ = 0;
        List<Short> eqpStrList = new ArrayList<>();
        List<Short> eqpDexList = new ArrayList<>();
        List<Short> eqpLukList = new ArrayList<>();
        MapleInventory iv = chr.getInventory(MapleInventoryType.EQUIPPED);
        Collection<Item> equippedC = iv.list();
        Equip nEquip;
        for (Item item : equippedC) {
            // selecting the biggest AP value of each stat from each equipped item.
            nEquip = (Equip) item;
            if (nEquip.getStr() > 0)
                eqpStrList.add(nEquip.getStr());
            str += nEquip.getStr();
            if (nEquip.getDex() > 0)
                eqpDexList.add(nEquip.getDex());
            dex += nEquip.getDex();
            if (nEquip.getLuk() > 0)
                eqpLukList.add(nEquip.getLuk());
            luk += nEquip.getLuk();
            // if(nEquip.getInt() > 0) eqpIntList.add(nEquip.getInt()); //not needed...
            int_ += nEquip.getInt();
        }
        statEqpd[0] = str;
        statEqpd[1] = dex;
        statEqpd[2] = luk;
        statEqpd[3] = int_;
        Collections.sort(eqpStrList, Collections.reverseOrder());
        Collections.sort(eqpDexList, Collections.reverseOrder());
        Collections.sort(eqpLukList, Collections.reverseOrder());
        // Autoassigner looks up the 1st/2nd placed equips for their stats to calculate the optimal upgrade.
        int eqpStr = getNthHighestStat(eqpStrList, (short) 0) + getNthHighestStat(eqpStrList, (short) 1);
        int eqpDex = getNthHighestStat(eqpDexList, (short) 0) + getNthHighestStat(eqpDexList, (short) 1);
        int eqpLuk = getNthHighestStat(eqpLukList, (short) 0) + getNthHighestStat(eqpLukList, (short) 1);
        // c.getPlayer().message("----------------------------------------");
        // c.getPlayer().message("SDL: s" + eqpStr + " d" + eqpDex + " l" + eqpLuk + " BASE STATS --> STR: " + chr.getStr() + " DEX: " + chr.getDex() + " INT: " + chr.getInt() + " LUK: " + chr.getLuk());
        // c.getPlayer().message("SUM EQUIP STATS -> STR: " + str + " DEX: " + dex + " LUK: " + luk + " INT: " + int_);
        MapleJob stance = c.getPlayer().getJobStyle(opt);
        int prStat = 0, scStat = 0, trStat = 0, temp, tempAp = chr.getRemainingAp(), CAP;
        MapleStat primary, secondary, tertiary = MapleStat.LUK;
        switch(stance) {
            case MAGICIAN:
                CAP = 165;
                scStat = (chr.getLevel() + 3) - (chr.getLuk() + luk - eqpLuk);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                int_ = prStat;
                luk = scStat;
                str = 0;
                dex = 0;
                if (luk + chr.getLuk() > CAP) {
                    temp = luk + chr.getLuk() - CAP;
                    luk -= temp;
                    int_ += temp;
                }
                primary = MapleStat.INT;
                secondary = MapleStat.LUK;
                tertiary = MapleStat.DEX;
                break;
            case BOWMAN:
                CAP = 125;
                scStat = (chr.getLevel() + 5) - (chr.getStr() + str - eqpStr);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                dex = prStat;
                str = scStat;
                int_ = 0;
                luk = 0;
                if (str + chr.getStr() > CAP) {
                    temp = str + chr.getStr() - CAP;
                    str -= temp;
                    dex += temp;
                }
                primary = MapleStat.DEX;
                secondary = MapleStat.STR;
                break;
            case GUNSLINGER:
            case CROSSBOWMAN:
                CAP = 120;
                scStat = chr.getLevel() - (chr.getStr() + str - eqpStr);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                dex = prStat;
                str = scStat;
                int_ = 0;
                luk = 0;
                if (str + chr.getStr() > CAP) {
                    temp = str + chr.getStr() - CAP;
                    str -= temp;
                    dex += temp;
                }
                primary = MapleStat.DEX;
                secondary = MapleStat.STR;
                break;
            case THIEF:
                CAP = 160;
                scStat = 0;
                if (chr.getDex() < 80) {
                    scStat = (2 * chr.getLevel()) - (chr.getDex() + dex - eqpDex);
                    if (scStat < 0)
                        scStat = 0;
                    scStat = Math.min(80 - chr.getDex(), scStat);
                    scStat = Math.min(tempAp, scStat);
                    tempAp -= scStat;
                }
                temp = (chr.getLevel() + 40) - Math.max(80, scStat + chr.getDex() + dex - eqpDex);
                if (temp < 0)
                    temp = 0;
                temp = Math.min(tempAp, temp);
                scStat += temp;
                tempAp -= temp;
                // thieves will upgrade STR as well only if a level-based threshold is reached.
                if (chr.getStr() >= Math.max(13, (int) (0.4 * chr.getLevel()))) {
                    if (chr.getStr() < 50) {
                        trStat = (chr.getLevel() - 10) - (chr.getStr() + str - eqpStr);
                        if (trStat < 0)
                            trStat = 0;
                        trStat = Math.min(50 - chr.getStr(), trStat);
                        trStat = Math.min(tempAp, trStat);
                        tempAp -= trStat;
                    }
                    temp = (20 + (chr.getLevel() / 2)) - Math.max(50, trStat + chr.getStr() + str - eqpStr);
                    if (temp < 0)
                        temp = 0;
                    temp = Math.min(tempAp, temp);
                    trStat += temp;
                    tempAp -= temp;
                }
                prStat = tempAp;
                luk = prStat;
                dex = scStat;
                str = trStat;
                int_ = 0;
                if (dex + chr.getDex() > CAP) {
                    temp = dex + chr.getDex() - CAP;
                    dex -= temp;
                    luk += temp;
                }
                if (str + chr.getStr() > CAP) {
                    temp = str + chr.getStr() - CAP;
                    str -= temp;
                    luk += temp;
                }
                primary = MapleStat.LUK;
                secondary = MapleStat.DEX;
                tertiary = MapleStat.STR;
                break;
            case BRAWLER:
                CAP = 120;
                scStat = chr.getLevel() - (chr.getDex() + dex - eqpDex);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                str = prStat;
                dex = scStat;
                int_ = 0;
                luk = 0;
                if (dex + chr.getDex() > CAP) {
                    temp = dex + chr.getDex() - CAP;
                    dex -= temp;
                    str += temp;
                }
                primary = MapleStat.STR;
                secondary = MapleStat.DEX;
                break;
            default:
                // warrior, beginner, ...
                CAP = 80;
                scStat = ((2 * chr.getLevel()) / 3) - (chr.getDex() + dex - eqpDex);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                str = prStat;
                dex = scStat;
                int_ = 0;
                luk = 0;
                if (dex + chr.getDex() > CAP) {
                    temp = dex + chr.getDex() - CAP;
                    dex -= temp;
                    str += temp;
                }
                primary = MapleStat.STR;
                secondary = MapleStat.DEX;
        }
        // -------------------------------------------------------------------------------------
        int extras = 0;
        extras = gainStatByType(chr, primary, statGain, prStat + extras);
        extras = gainStatByType(chr, secondary, statGain, scStat + extras);
        extras = gainStatByType(chr, tertiary, statGain, trStat + extras);
        if (extras > 0) {
            // redistribute surplus in priority order
            extras = gainStatByType(chr, primary, statGain, extras);
            extras = gainStatByType(chr, secondary, statGain, extras);
            extras = gainStatByType(chr, tertiary, statGain, extras);
            gainStatByType(chr, getQuaternaryStat(stance), statGain, extras);
        }
        int remainingAp = (chr.getRemainingAp() - getAccumulatedStatGain(statGain));
        chr.setRemainingAp(remainingAp);
        chr.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
        c.announce(MaplePacketCreator.enableActions());
        // ----------------------------------------------------------------------------------------
        c.announce(MaplePacketCreator.serverNotice(1, "Better AP applications detected:\r\nSTR: +" + statGain[0] + "\r\nDEX: +" + statGain[1] + "\r\nINT: +" + statGain[3] + "\r\nLUK: +" + statGain[2]));
    } else {
        int total = 0;
        int extras = 0;
        if (slea.available() < 16) {
            AutobanFactory.PACKET_EDIT.alert(chr, "Didn't send full packet for Auto Assign.");
            c.disconnect(false, false);
            return;
        }
        MapleInventory iv = chr.getInventory(MapleInventoryType.EQUIPPED);
        Collection<Item> equippedC = iv.list();
        for (Item item : equippedC) {
            // selecting the biggest AP value of each stat from each equipped item.
            Equip nEquip = (Equip) item;
            statEqpd[0] += nEquip.getStr();
            statEqpd[1] += nEquip.getDex();
            statEqpd[2] += nEquip.getLuk();
            statEqpd[3] += nEquip.getInt();
        }
        for (int i = 0; i < 2; i++) {
            int type = slea.readInt();
            int tempVal = slea.readInt();
            if (tempVal < 0 || tempVal > c.getPlayer().getRemainingAp()) {
                return;
            }
            total += tempVal;
            extras += gainStatByType(chr, MapleStat.getBy5ByteEncoding(type), statGain, tempVal);
        }
        int remainingAp = (chr.getRemainingAp() - total) + extras;
        chr.setRemainingAp(remainingAp);
        chr.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
        c.announce(MaplePacketCreator.enableActions());
    }
}
Also used : MapleCharacter(client.MapleCharacter) ArrayList(java.util.ArrayList) MapleStat(client.MapleStat) MapleInventory(client.inventory.MapleInventory) Item(client.inventory.Item) Equip(client.inventory.Equip) MapleJob(client.MapleJob)

Example 99 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class CashOperationHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    CashShop cs = chr.getCashShop();
    if (!cs.isOpened()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    final int action = slea.readByte();
    if (action == 0x03 || action == 0x1E) {
        slea.readByte();
        final int useNX = slea.readInt();
        final int snCS = slea.readInt();
        CashItem cItem = CashItemFactory.getItem(snCS);
        if (cItem == null || !cItem.isOnSale() || cs.getCash(useNX) < cItem.getPrice()) {
            FilePrinter.printError(FilePrinter.ITEM, "Denied to sell cash item with SN " + cItem.getSN());
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (action == 0x03) {
            // Item
            Item item = cItem.toItem();
            cs.addToInventory(item);
            c.announce(MaplePacketCreator.showBoughtCashItem(item, c.getAccID()));
        } else {
            // Package
            List<Item> cashPackage = CashItemFactory.getPackage(cItem.getItemId());
            for (Item item : cashPackage) {
                cs.addToInventory(item);
            }
            c.announce(MaplePacketCreator.showBoughtCashPackage(cashPackage, c.getAccID()));
        }
        cs.gainCash(useNX, -cItem.getPrice());
        c.announce(MaplePacketCreator.showCash(chr));
    } else if (action == 0x04) {
        // TODO check for gender
        int birthday = slea.readInt();
        CashItem cItem = CashItemFactory.getItem(slea.readInt());
        Map<String, String> recipient = MapleCharacter.getCharacterFromDatabase(slea.readMapleAsciiString());
        String message = slea.readMapleAsciiString();
        if (!canBuy(cItem, cs.getCash(4)) || message.length() < 1 || message.length() > 73) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (!checkBirthday(c, birthday)) {
            c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xC4));
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (recipient == null) {
            c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA9));
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (recipient.get("accountid").equals(String.valueOf(c.getAccID()))) {
            c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA8));
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        cs.gift(Integer.parseInt(recipient.get("id")), chr.getName(), message, cItem.getSN());
        c.announce(MaplePacketCreator.showGiftSucceed(recipient.get("name"), cItem));
        cs.gainCash(4, -cItem.getPrice());
        c.announce(MaplePacketCreator.showCash(chr));
        try {
            // fame or not
            chr.sendNote(recipient.get("name"), chr.getName() + " has sent you a gift! Go check out the Cash Shop.", (byte) 0);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        MapleCharacter receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient.get("name"));
        if (receiver != null)
            receiver.showNote();
    } else if (action == 0x05) {
        // Modify wish list
        cs.clearWishList();
        for (byte i = 0; i < 10; i++) {
            int sn = slea.readInt();
            CashItem cItem = CashItemFactory.getItem(sn);
            if (cItem != null && cItem.isOnSale() && sn != 0) {
                cs.addToWishList(sn);
            }
        }
        c.announce(MaplePacketCreator.showWishList(chr, true));
    } else if (action == 0x06) {
        // Increase Inventory Slots
        slea.skip(1);
        int cash = slea.readInt();
        byte mode = slea.readByte();
        if (mode == 0) {
            byte type = slea.readByte();
            if (cs.getCash(cash) < 4000) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.gainSlots(type, 4, false)) {
                c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
                cs.gainCash(cash, -4000);
                c.announce(MaplePacketCreator.showCash(chr));
            }
        } else {
            CashItem cItem = CashItemFactory.getItem(slea.readInt());
            int type = (cItem.getItemId() - 9110000) / 1000;
            if (!canBuy(cItem, cs.getCash(cash))) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.gainSlots(type, 8, false)) {
                c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
                cs.gainCash(cash, -cItem.getPrice());
                c.announce(MaplePacketCreator.showCash(chr));
            }
        }
    } else if (action == 0x07) {
        // Increase Storage Slots
        slea.skip(1);
        int cash = slea.readInt();
        byte mode = slea.readByte();
        if (mode == 0) {
            if (cs.getCash(cash) < 4000) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.getStorage().gainSlots(4)) {
                c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
                cs.gainCash(cash, -4000);
                c.announce(MaplePacketCreator.showCash(chr));
            }
        } else {
            CashItem cItem = CashItemFactory.getItem(slea.readInt());
            if (!canBuy(cItem, cs.getCash(cash))) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.getStorage().gainSlots(8)) {
                c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
                cs.gainCash(cash, -cItem.getPrice());
                c.announce(MaplePacketCreator.showCash(chr));
            }
        }
    } else if (action == 0x08) {
        // Increase Character Slots
        slea.skip(1);
        int cash = slea.readInt();
        CashItem cItem = CashItemFactory.getItem(slea.readInt());
        if (!canBuy(cItem, cs.getCash(cash))) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (c.gainCharacterSlot()) {
            c.announce(MaplePacketCreator.showBoughtCharacterSlot(c.getCharacterSlots()));
            cs.gainCash(cash, -cItem.getPrice());
            c.announce(MaplePacketCreator.showCash(chr));
        }
    } else if (action == 0x0D) {
        // Take from Cash Inventory
        Item item = cs.findByCashId(slea.readInt());
        if (item == null) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (chr.getInventory(item.getInventoryType()).addItem(item) != -1) {
            cs.removeFromInventory(item);
            c.announce(MaplePacketCreator.takeFromCashInventory(item));
            if (item instanceof Equip) {
                Equip equip = (Equip) item;
                if (equip.getRingId() >= 0) {
                    MapleRing ring = MapleRing.loadFromDb(equip.getRingId());
                    if (ring.getItemId() > 1112012) {
                        chr.addFriendshipRing(ring);
                    } else {
                        chr.addCrushRing(ring);
                    }
                }
            }
        }
    } else if (action == 0x0E) {
        // Put into Cash Inventory
        int cashId = slea.readInt();
        slea.skip(4);
        MapleInventory mi = chr.getInventory(MapleInventoryType.getByType(slea.readByte()));
        Item item = mi.findByCashId(cashId);
        if (item == null) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (c.getPlayer().getPetIndex(item.getPetId()) > -1) {
            chr.getClient().announce(MaplePacketCreator.serverNotice(1, "You cannot put the pet you currently equip into the Cash Shop inventory."));
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        cs.addToInventory(item);
        mi.removeSlot(item.getPosition());
        c.announce(MaplePacketCreator.putIntoCashInventory(item, c.getAccID()));
    } else if (action == 0x1D) {
        // crush ring (action 28)
        // Birthday
        slea.readInt();
        // if (checkBirthday(c, birthday)) { //We're using a default birthday, so why restrict rings to only people who know of it?
        int toCharge = slea.readInt();
        int SN = slea.readInt();
        String recipientName = slea.readMapleAsciiString();
        String text = slea.readMapleAsciiString();
        CashItem itemRing = CashItemFactory.getItem(SN);
        MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(recipientName);
        if (partner == null) {
            chr.getClient().announce(MaplePacketCreator.serverNotice(1, "The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel."));
        } else {
            if (itemRing.toItem() instanceof Equip) {
                Equip eqp = (Equip) itemRing.toItem();
                int ringid = MapleRing.createRing(itemRing.getItemId(), chr, partner);
                eqp.setRingId(ringid);
                cs.addToInventory(eqp);
                c.announce(MaplePacketCreator.showBoughtCashItem(eqp, c.getAccID()));
                cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), (ringid + 1));
                cs.gainCash(toCharge, -itemRing.getPrice());
                chr.addCrushRing(MapleRing.loadFromDb(ringid));
                try {
                    chr.sendNote(partner.getName(), text, (byte) 1);
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
                partner.showNote();
            }
        }
        /* } else {
                chr.dropMessage("The birthday you entered was incorrect.");
            }*/
        c.announce(MaplePacketCreator.showCash(c.getPlayer()));
    } else if (action == 0x20) {
        // everything is 1 meso...
        int itemId = CashItemFactory.getItem(slea.readInt()).getItemId();
        if (chr.getMeso() > 0) {
            if (chr.canHold(itemId)) {
                chr.gainMeso(-1, false);
                MapleInventoryManipulator.addById(c, itemId, (short) 1);
                c.announce(MaplePacketCreator.showBoughtQuestItem(itemId));
            }
        }
        c.announce(MaplePacketCreator.showCash(c.getPlayer()));
    } else if (action == 0x23) {
        // Friendship :3
        // Birthday
        slea.readInt();
        // if (checkBirthday(c, birthday)) {
        int payment = slea.readByte();
        // 0s
        slea.skip(3);
        int snID = slea.readInt();
        CashItem itemRing = CashItemFactory.getItem(snID);
        String sentTo = slea.readMapleAsciiString();
        int available = slea.readShort() - 1;
        String text = slea.readAsciiString(available);
        slea.readByte();
        MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(sentTo);
        if (partner == null) {
            chr.dropMessage("The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel.");
        } else {
            // Need to check to make sure its actually an equip and the right SN...
            if (itemRing.toItem() instanceof Equip) {
                Equip eqp = (Equip) itemRing.toItem();
                int ringid = MapleRing.createRing(itemRing.getItemId(), chr, partner);
                eqp.setRingId(ringid);
                cs.addToInventory(eqp);
                c.announce(MaplePacketCreator.showBoughtCashItem(eqp, c.getAccID()));
                cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), (ringid + 1));
                cs.gainCash(payment, -itemRing.getPrice());
                chr.addFriendshipRing(MapleRing.loadFromDb(ringid));
                try {
                    chr.sendNote(partner.getName(), text, (byte) 1);
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
                partner.showNote();
            }
        }
        /* } else {
                chr.dropMessage("The birthday you entered was incorrect.");
            } */
        c.announce(MaplePacketCreator.showCash(c.getPlayer()));
    } else {
        System.out.println(slea);
    }
}
Also used : CashShop(server.CashShop) MapleCharacter(client.MapleCharacter) CashItem(server.CashShop.CashItem) SQLException(java.sql.SQLException) MapleRing(client.MapleRing) MapleInventory(client.inventory.MapleInventory) Item(client.inventory.Item) CashItem(server.CashShop.CashItem) Equip(client.inventory.Equip) Map(java.util.Map)

Example 100 with Item

use of client.inventory.Item in project HeavenMS by ronancpl.

the class DueyHandler method getItemByPID.

private static DueyPackages getItemByPID(ResultSet rs) {
    try {
        DueyPackages dueypack;
        if (rs.getInt("type") == 1) {
            Equip eq = new Equip(rs.getInt("itemid"), (byte) 0, -1);
            eq.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
            eq.setLevel((byte) rs.getInt("level"));
            eq.setStr((short) rs.getInt("str"));
            eq.setDex((short) rs.getInt("dex"));
            eq.setInt((short) rs.getInt("int"));
            eq.setLuk((short) rs.getInt("luk"));
            eq.setHp((short) rs.getInt("hp"));
            eq.setMp((short) rs.getInt("mp"));
            eq.setWatk((short) rs.getInt("watk"));
            eq.setMatk((short) rs.getInt("matk"));
            eq.setWdef((short) rs.getInt("wdef"));
            eq.setMdef((short) rs.getInt("mdef"));
            eq.setAcc((short) rs.getInt("acc"));
            eq.setAvoid((short) rs.getInt("avoid"));
            eq.setHands((short) rs.getInt("hands"));
            eq.setSpeed((short) rs.getInt("speed"));
            eq.setJump((short) rs.getInt("jump"));
            eq.setOwner(rs.getString("owner"));
            dueypack = new DueyPackages(rs.getInt("PackageId"), eq);
        } else if (rs.getInt("type") == 2) {
            Item newItem = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
            newItem.setOwner(rs.getString("owner"));
            dueypack = new DueyPackages(rs.getInt("PackageId"), newItem);
        } else {
            dueypack = new DueyPackages(rs.getInt("PackageId"));
        }
        return dueypack;
    } catch (SQLException se) {
        se.printStackTrace();
        return null;
    }
}
Also used : DueyPackages(server.DueyPackages) Equip(client.inventory.Equip) Item(client.inventory.Item) SQLException(java.sql.SQLException)

Aggregations

Item (client.inventory.Item)124 MapleMapItem (server.maps.MapleMapItem)33 Equip (client.inventory.Equip)31 ArrayList (java.util.ArrayList)31 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)31 Point (java.awt.Point)29 SQLException (java.sql.SQLException)25 MapleCharacter (client.MapleCharacter)21 MapleInventoryType (client.inventory.MapleInventoryType)20 PreparedStatement (java.sql.PreparedStatement)20 Connection (java.sql.Connection)19 DatabaseConnection (tools.DatabaseConnection)19 MapleInventory (client.inventory.MapleInventory)18 MapleItemInformationProvider (server.MapleItemInformationProvider)18 ResultSet (java.sql.ResultSet)16 Pair (tools.Pair)15 CashItem (server.CashShop.CashItem)13 SpecialCashItem (server.CashShop.SpecialCashItem)12 MapleShopItem (server.MapleShopItem)12 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)11