Search in sources :

Example 21 with MapleInventoryType

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

the class DropEntry method calculateChance.

private int calculateChance(int item_id) {
    MapleInventoryType mit = ItemConstants.getInventoryType(item_id);
    boolean boss = DataTool.isBoss(monster_id);
    int number = (item_id / 1000) % 1000;
    switch(mit) {
        case EQUIP:
            if (boss) {
                return 40000;
            }
            return 700;
        case USE:
            if (boss) {
                mindrop = 1;
                maxdrop = 4;
            }
            switch(number) {
                case // normal potions
                0:
                    mindrop = 1;
                    if (version > 98) {
                        maxdrop = 5;
                    }
                    return 40000;
                // watermelons, pills, speed potions, etc
                case 1:
                case // same thing
                2:
                    return 10000;
                // advanced potions from crafting (should not drop)
                case 3:
                // same thing
                case 4:
                // poison mushroom
                case 11:
                // cool items
                case 28:
                // return scrolls
                case 30:
                case // gallant scrolls
                46:
                    return 0;
                // strange potions like apples, eggs
                case 10:
                // drakes blood, sap of ancient tree (rare use)
                case 12:
                // salad, fried chicken, dews
                case 20:
                // air bubbles and stuff. ALSO nependeath honey but oh well
                case 22:
                case // antidotes and stuff
                50:
                    return 3000;
                case // mastery books
                290:
                    if (boss)
                        return 40000;
                    else
                        return 1000;
                // Scrolls
                case 40:
                // Scrolls
                case 41:
                // Scrolls
                case 43:
                // Scrolls
                case 44:
                case // pet scrolls
                48:
                    if (boss)
                        return 10000;
                    else
                        return 750;
                // summon bags
                case 100:
                // summon bags
                case 101:
                // summon bags
                case 102:
                // summon bags
                case 109:
                // pet food
                case 120:
                // cliffs special potion
                case 211:
                // rings
                case 240:
                // pheromone, additional weird stuff
                case 270:
                // teleport rock
                case 310:
                // weird drops
                case 320:
                // weird
                case 390:
                // Scripted items
                case 430:
                // jukebox
                case 440:
                // magnifying glass
                case 460:
                // golden hammer
                case 470:
                // crystanol
                case 490:
                case // sp reset
                500:
                    return 0;
                case // tablets from dragon rider
                47:
                    return 220000;
                // clean slats, potential scroll, ees
                case 49:
                // throwing stars
                case 70:
                // rare monster piece drops
                case 210:
                case // bullets
                330:
                    if (boss)
                        return 2500;
                    else
                        return 400;
                // bow arrows
                case 60:
                case // crossbow arrows
                61:
                    mindrop = 10;
                    maxdrop = 50;
                    return 10000;
                case // boss transfrom
                213:
                    return 100000;
                case // skill books
                280:
                    if (boss)
                        return 20000;
                    else
                        return 1000;
                // monster book things
                case 381:
                case 382:
                case 383:
                case 384:
                case 385:
                case 386:
                case 387:
                case 388:
                    return 20000;
                // recipes
                case 510:
                case 511:
                case 512:
                    return 10000;
                default:
                    return 0;
            }
        case ETC:
            switch(number) {
                case // monster pieces
                0:
                    return 200000;
                // crystal ores
                case 4:
                // simulators
                case 130:
                case // manuals
                131:
                    return 3000;
                case // game pieces
                30:
                    return 10000;
                case // misc items
                32:
                    return 10000;
                default:
                    return 7000;
            }
        default:
            return 7000;
    }
}
Also used : MapleInventoryType(client.inventory.MapleInventoryType)

Example 22 with MapleInventoryType

use of client.inventory.MapleInventoryType 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 23 with MapleInventoryType

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

the class ItemMoveHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    slea.skip(4);
    if (c.getPlayer().getAutobanManager().getLastSpam(6) + 300 > System.currentTimeMillis()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    MapleInventoryType type = MapleInventoryType.getByType(slea.readByte());
    // is there any reason to use byte instead of short in src and action?
    short src = slea.readShort();
    short action = slea.readShort();
    short quantity = slea.readShort();
    if (src < 0 && action > 0) {
        MapleInventoryManipulator.unequip(c, src, action);
    } else if (action < 0) {
        MapleInventoryManipulator.equip(c, src, action);
    } else if (action == 0) {
        MapleInventoryManipulator.drop(c, type, src, quantity);
    } else {
        MapleInventoryManipulator.move(c, type, src, action);
    }
    if (c.getPlayer().getMap().getHPDec() > 0)
        c.getPlayer().resetHpDecreaseTask();
    c.getPlayer().getAutobanManager().spam(6);
}
Also used : MapleInventoryType(client.inventory.MapleInventoryType)

Example 24 with MapleInventoryType

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

the class PlayerInteractionHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    byte mode = slea.readByte();
    MapleCharacter chr = c.getPlayer();
    if (mode == Action.CREATE.getCode()) {
        byte createType = slea.readByte();
        if (createType == 3) {
            // trade
            MapleTrade.startTrade(chr);
        } else if (createType == 1) {
            // omok mini game
            if (chr.getChalkboard() != null || FieldLimit.CANNOTMINIGAME.check(chr.getMap().getFieldLimit())) {
                return;
            }
            String desc = slea.readMapleAsciiString();
            // 20 6E 4E
            slea.readByte();
            // 20 6E 4E
            int type = slea.readByte();
            MapleMiniGame game = new MapleMiniGame(chr, desc);
            chr.setMiniGame(game);
            game.setPieceType(type);
            game.setGameType("omok");
            chr.getMap().addMapObject(game);
            chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(chr, 1, 0));
            game.sendOmok(c, type);
        } else if (createType == 2) {
            // matchcard
            if (chr.getChalkboard() != null) {
                return;
            }
            String desc = slea.readMapleAsciiString();
            // 20 6E 4E
            slea.readByte();
            // 20 6E 4E
            int type = slea.readByte();
            MapleMiniGame game = new MapleMiniGame(chr, desc);
            game.setPieceType(type);
            if (type == 0) {
                game.setMatchesToWin(6);
            } else if (type == 1) {
                game.setMatchesToWin(10);
            } else if (type == 2) {
                game.setMatchesToWin(15);
            }
            game.setGameType("matchcard");
            chr.setMiniGame(game);
            chr.getMap().addMapObject(game);
            chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(chr, 1, 0));
            game.sendMatchCard(c, type);
        } else if (createType == 4 || createType == 5) {
            // shop
            if (!chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapleMapObjectType.SHOP, MapleMapObjectType.HIRED_MERCHANT)).isEmpty()) {
                return;
            }
            String desc = slea.readMapleAsciiString();
            slea.skip(3);
            int itemId = slea.readInt();
            if (chr.getInventory(MapleInventoryType.CASH).countById(itemId) < 1) {
                return;
            }
            if (GameConstants.isFreeMarketRoom(chr.getMapId()) || itemId > 5030000 && itemId < 5030012 || itemId > 5140000 && itemId < 5140006) {
                if (createType == 4) {
                    MaplePlayerShop shop = new MaplePlayerShop(c.getPlayer(), desc);
                    chr.setPlayerShop(shop);
                    chr.getMap().addMapObject(shop);
                    shop.sendShop(c);
                    c.getWorldServer().registerPlayerShop(shop);
                // c.announce(MaplePacketCreator.getPlayerShopRemoveVisitor(1));
                } else {
                    MapleHiredMerchant merchant = new MapleHiredMerchant(chr, itemId, desc);
                    chr.setHiredMerchant(merchant);
                    c.getWorldServer().registerHiredMerchant(merchant);
                    chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
                    chr.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, true));
                }
            }
        }
    } else if (mode == Action.INVITE.getCode()) {
        int otherPlayer = slea.readInt();
        if (chr.getId() == chr.getMap().getCharacterById(otherPlayer).getId()) {
            return;
        }
        MapleTrade.inviteTrade(chr, chr.getMap().getCharacterById(otherPlayer));
    } else if (mode == Action.DECLINE.getCode()) {
        MapleTrade.declineTrade(chr);
    } else if (mode == Action.VISIT.getCode()) {
        if (chr.getTrade() != null && chr.getTrade().getPartner() != null) {
            if (!chr.getTrade().isFullTrade() && !chr.getTrade().getPartner().isFullTrade()) {
                MapleTrade.visitTrade(chr, chr.getTrade().getPartner().getChr());
            } else {
                // Ill be nice and not dc u
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
        } else {
            int oid = slea.readInt();
            MapleMapObject ob = chr.getMap().getMapObject(oid);
            if (ob instanceof MaplePlayerShop) {
                MaplePlayerShop shop = (MaplePlayerShop) ob;
                shop.visitShop(chr);
            } else if (ob instanceof MapleMiniGame) {
                MapleMiniGame game = (MapleMiniGame) ob;
                if (game.hasFreeSlot() && !game.isVisitor(c.getPlayer())) {
                    game.addVisitor(c.getPlayer());
                    chr.setMiniGame(game);
                    switch(game.getGameType()) {
                        case "omok":
                            game.sendOmok(c, game.getPieceType());
                            break;
                        case "matchcard":
                            game.sendMatchCard(c, game.getPieceType());
                            break;
                    }
                } else {
                    chr.getClient().announce(MaplePacketCreator.getMiniGameFull());
                }
            } else if (ob instanceof MapleHiredMerchant && chr.getHiredMerchant() == null) {
                MapleHiredMerchant merchant = (MapleHiredMerchant) ob;
                if (merchant.isOwner(c.getPlayer())) {
                    merchant.setOpen(false);
                    merchant.removeAllVisitors();
                    c.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, false));
                } else if (!merchant.isOpen()) {
                    c.announce(MaplePacketCreator.hiredMerchantMaintenanceMessage());
                    return;
                } else if (!merchant.addVisitor(c.getPlayer())) {
                    chr.dropMessage(1, "This shop has reached it's maximum capacity, please come by later.");
                    return;
                } else {
                    c.announce(MaplePacketCreator.getHiredMerchant(c.getPlayer(), merchant, false));
                }
                chr.setHiredMerchant(merchant);
            }
        }
    } else if (mode == Action.CHAT.getCode()) {
        // chat lol
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (chr.getTrade() != null) {
            chr.getTrade().chat(slea.readMapleAsciiString());
        } else if (chr.getPlayerShop() != null) {
            // mini game
            MaplePlayerShop shop = chr.getPlayerShop();
            if (shop != null) {
                shop.chat(c, slea.readMapleAsciiString());
            }
        } else if (chr.getMiniGame() != null) {
            MapleMiniGame game = chr.getMiniGame();
            if (game != null) {
                game.chat(c, slea.readMapleAsciiString());
            }
        } else if (merchant != null) {
            merchant.sendMessage(c.getPlayer(), slea.readMapleAsciiString());
        }
    } else if (mode == Action.EXIT.getCode()) {
        if (chr.getTrade() != null) {
            MapleTrade.cancelTrade(c.getPlayer());
        } else {
            chr.closePlayerShop();
            chr.closeMiniGame();
            chr.closeHiredMerchant(true);
        }
    } else if (mode == Action.OPEN.getCode()) {
        MaplePlayerShop shop = chr.getPlayerShop();
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (shop != null && shop.isOwner(c.getPlayer())) {
            // 01
            slea.readByte();
            if (ServerConstants.USE_ERASE_PERMIT_ON_OPENSHOP) {
                try {
                    MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5140000, 1, true, false);
                }// fella does not have a player shop permit...
                 catch (RuntimeException re) {
                }
            }
            chr.getMap().broadcastMessage(MaplePacketCreator.addCharBox(c.getPlayer(), 4));
            shop.setOpen(true);
        } else if (merchant != null && merchant.isOwner(c.getPlayer())) {
            chr.setHasMerchant(true);
            merchant.setOpen(true);
            chr.getMap().addMapObject(merchant);
            chr.setHiredMerchant(null);
            chr.getMap().broadcastMessage(MaplePacketCreator.spawnHiredMerchant(merchant));
            slea.readByte();
        }
    } else if (mode == Action.READY.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        game.broadcast(MaplePacketCreator.getMiniGameReady(game));
    } else if (mode == Action.UN_READY.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        game.broadcast(MaplePacketCreator.getMiniGameUnReady(game));
    } else if (mode == Action.START.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.getGameType().equals("omok")) {
            game.broadcast(MaplePacketCreator.getMiniGameStart(game, game.getLoser()));
            chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(game.getOwner(), 2, 1));
        }
        if (game.getGameType().equals("matchcard")) {
            game.shuffleList();
            game.broadcast(MaplePacketCreator.getMatchCardStart(game, game.getLoser()));
            chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(game.getOwner(), 2, 1));
        }
    } else if (mode == Action.GIVE_UP.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.getGameType().equals("omok")) {
            if (game.isOwner(c.getPlayer())) {
                game.broadcast(MaplePacketCreator.getMiniGameOwnerForfeit(game));
            } else {
                game.broadcast(MaplePacketCreator.getMiniGameVisitorForfeit(game));
            }
        }
        if (game.getGameType().equals("matchcard")) {
            if (game.isOwner(c.getPlayer())) {
                game.broadcast(MaplePacketCreator.getMatchCardVisitorWin(game));
            } else {
                game.broadcast(MaplePacketCreator.getMatchCardOwnerWin(game));
            }
        }
    } else if (mode == Action.REQUEST_TIE.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.isOwner(c.getPlayer())) {
            game.broadcastToVisitor(MaplePacketCreator.getMiniGameRequestTie(game));
        } else {
            game.getOwner().getClient().announce(MaplePacketCreator.getMiniGameRequestTie(game));
        }
    } else if (mode == Action.ANSWER_TIE.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        slea.readByte();
        if (game.getGameType().equals("omok")) {
            game.broadcast(MaplePacketCreator.getMiniGameTie(game));
        }
        if (game.getGameType().equals("matchcard")) {
            game.broadcast(MaplePacketCreator.getMatchCardTie(game));
        }
    } else if (mode == Action.SKIP.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.isOwner(c.getPlayer())) {
            game.broadcast(MaplePacketCreator.getMiniGameSkipOwner(game));
        } else {
            game.broadcast(MaplePacketCreator.getMiniGameSkipVisitor(game));
        }
    } else if (mode == Action.MOVE_OMOK.getCode()) {
        // x point
        int x = slea.readInt();
        // y point
        int y = slea.readInt();
        // piece ( 1 or 2; Owner has one piece, visitor has another, it switches every game.)
        int type = slea.readByte();
        chr.getMiniGame().setPiece(x, y, type, c.getPlayer());
    } else if (mode == Action.SELECT_CARD.getCode()) {
        // 1st turn = 1; 2nd turn = 0
        int turn = slea.readByte();
        // slot
        int slot = slea.readByte();
        MapleMiniGame game = chr.getMiniGame();
        int firstslot = game.getFirstSlot();
        if (turn == 1) {
            game.setFirstSlot(slot);
            if (game.isOwner(c.getPlayer())) {
                game.broadcastToVisitor(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
            } else {
                game.getOwner().getClient().announce(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
            }
        } else if ((game.getCardId(firstslot + 1)) == (game.getCardId(slot + 1))) {
            if (game.isOwner(c.getPlayer())) {
                game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 2));
                game.setOwnerPoints();
            } else {
                game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 3));
                game.setVisitorPoints();
            }
        } else if (game.isOwner(c.getPlayer())) {
            game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 0));
        } else {
            game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 1));
        }
    } else if (mode == Action.SET_MESO.getCode()) {
        chr.getTrade().setMeso(slea.readInt());
    } else if (mode == Action.SET_ITEMS.getCode()) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
        Item item = chr.getInventory(ivType).getItem(slea.readShort());
        short quantity = slea.readShort();
        byte targetSlot = slea.readByte();
        if (quantity < 1 || quantity > item.getQuantity()) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (chr.getTrade() != null) {
            if ((quantity <= item.getQuantity() && quantity >= 0) || ItemConstants.isRechargable(item.getItemId())) {
                if (ii.isDropRestricted(item.getItemId())) {
                    // ensure that undroppable items do not make it to the trade window
                    if (!((item.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA)) {
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                }
                Item tradeItem = item.copy();
                if (ItemConstants.isRechargable(item.getItemId())) {
                    tradeItem.setQuantity(item.getQuantity());
                    MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), item.getQuantity(), true);
                } else {
                    tradeItem.setQuantity(quantity);
                    MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), quantity, true);
                }
                tradeItem.setPosition(targetSlot);
                chr.getTrade().addItem(tradeItem);
            }
        }
    } else if (mode == Action.CONFIRM.getCode()) {
        MapleTrade.completeTrade(c.getPlayer());
    } else if (mode == Action.ADD_ITEM.getCode() || mode == Action.PUT_ITEM.getCode()) {
        MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
        short slot = slea.readShort();
        short bundles = slea.readShort();
        if (chr.getInventory(ivType).getItem(slot) == null || chr.getItemQuantity(chr.getInventory(ivType).getItem(slot).getItemId(), false) < bundles || chr.getInventory(ivType).getItem(slot).getFlag() == ItemConstants.UNTRADEABLE) {
            return;
        }
        short perBundle = slea.readShort();
        int price = slea.readInt();
        if (perBundle <= 0 || perBundle * bundles > 2000 || bundles <= 0 || price <= 0 || price > Integer.MAX_VALUE) {
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with hired merchants.");
            FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " might of possibly packet edited Hired Merchants\nperBundle: " + perBundle + "\nperBundle * bundles (This multiplied cannot be greater than 2000): " + perBundle * bundles + "\nbundles: " + bundles + "\nprice: " + price);
            return;
        }
        Item ivItem = chr.getInventory(ivType).getItem(slot);
        Item sellItem = ivItem.copy();
        if (chr.getItemQuantity(ivItem.getItemId(), false) < perBundle * bundles) {
            return;
        } else if (ServerConstants.USE_ENFORCE_UNMERCHABLE_PET && ItemConstants.isPet(ivItem.getItemId())) {
            c.announce(MaplePacketCreator.serverNotice(1, "Pets are not allowed to be sold on the Player Shop."));
            return;
        }
        sellItem.setQuantity(perBundle);
        MaplePlayerShopItem shopItem = new MaplePlayerShopItem(sellItem, bundles, price);
        MaplePlayerShop shop = chr.getPlayerShop();
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (shop != null && shop.isOwner(c.getPlayer())) {
            if (ivItem != null && ivItem.getQuantity() >= bundles * perBundle) {
                shop.addItem(shopItem);
                c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
            }
        } else if (merchant != null && merchant.isOwner(c.getPlayer())) {
            merchant.addItem(shopItem);
            c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
        }
        if (ItemConstants.isRechargable(ivItem.getItemId())) {
            MapleInventoryManipulator.removeFromSlot(c, ivType, slot, ivItem.getQuantity(), true);
        } else {
            MapleInventoryManipulator.removeFromSlot(c, ivType, slot, (short) (bundles * perBundle), true);
        }
    } else if (mode == Action.REMOVE_ITEM.getCode()) {
        MaplePlayerShop shop = chr.getPlayerShop();
        if (shop != null && shop.isOwner(c.getPlayer())) {
            int slot = slea.readShort();
            if (slot >= shop.getItems().size() || slot < 0) {
                AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a player shop.");
                FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to remove item at slot " + slot + "\r\n");
                c.disconnect(true, false);
                return;
            }
            MaplePlayerShopItem shopItem = shop.getItems().get(slot);
            Item ivItem = shopItem.getItem().copy();
            shop.removeItem(slot);
            ivItem.setQuantity(shopItem.getBundles());
            MapleInventoryManipulator.addFromDrop(c, ivItem, false);
            c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
        }
    } else if (mode == Action.MERCHANT_MESO.getCode()) {
    // Hmmmm
    /*if (!chr.getHiredMerchant().isOwner(chr) || chr.getMerchantMeso() < 1) return;
            int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
            if (possible > 0) {
                if (possible < chr.getMerchantMeso()) {
                    chr.gainMeso(possible, false);
                    chr.setMerchantMeso(chr.getMerchantMeso() - possible);
                } else {
                    chr.gainMeso(chr.getMerchantMeso(), false);
                    chr.setMerchantMeso(0);
                }
                c.announce(MaplePacketCreator.updateHiredMerchant(chr.getHiredMerchant(), chr));
            }*/
    } else if (mode == Action.MERCHANT_ORGANIZE.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (!merchant.isOwner(chr))
            return;
        if (chr.getMerchantMeso() > 0) {
            int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
            if (possible > 0) {
                if (possible < chr.getMerchantMeso()) {
                    chr.gainMeso(possible, false);
                    chr.setMerchantMeso(chr.getMerchantMeso() - possible);
                } else {
                    chr.gainMeso(chr.getMerchantMeso(), false);
                    chr.setMerchantMeso(0);
                }
            }
        }
        for (int i = 0; i < merchant.getItems().size(); i++) {
            if (!merchant.getItems().get(i).isExist())
                merchant.removeFromSlot(i);
        }
        if (merchant.getItems().isEmpty()) {
            c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
            c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
            merchant.closeShop(c, false);
            chr.setHasMerchant(false);
            return;
        }
        c.announce(MaplePacketCreator.updateHiredMerchant(merchant, chr));
    } else if (mode == Action.BUY.getCode() || mode == Action.MERCHANT_BUY.getCode()) {
        int itemid = slea.readByte();
        short quantity = slea.readShort();
        if (quantity < 1) {
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a hired merchant and or player shop.");
            FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to buy item " + itemid + " with quantity " + quantity + "\r\n");
            c.disconnect(true, false);
            return;
        }
        MaplePlayerShop shop = chr.getPlayerShop();
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (shop != null && shop.isVisitor(c.getPlayer())) {
            shop.buy(c, itemid, quantity);
            shop.broadcast(MaplePacketCreator.getPlayerShopItemUpdate(shop));
        } else if (merchant != null && !merchant.isOwner(chr)) {
            merchant.buy(c, itemid, quantity);
            merchant.broadcastToVisitorsThreadsafe(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
        }
    } else if (mode == Action.TAKE_ITEM_BACK.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (merchant != null && merchant.isOwner(c.getPlayer())) {
            int slot = slea.readShort();
            MaplePlayerShopItem shopItem = merchant.getItems().get(slot);
            if (!MapleInventory.checkSpot(chr, shopItem.getItem())) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (shopItem.getBundles() > 0) {
                Item iitem = shopItem.getItem();
                iitem.setQuantity((short) (shopItem.getItem().getQuantity() * shopItem.getBundles()));
                MapleInventoryManipulator.addFromDrop(c, iitem, true);
            }
            merchant.removeFromSlot(slot);
            c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
        }
    } else if (mode == Action.CLOSE_MERCHANT.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (merchant != null && merchant.isOwner(c.getPlayer())) {
            c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
            c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
            merchant.closeShop(c, false);
            chr.setHasMerchant(false);
        }
    } else if (mode == Action.MAINTENANCE_OFF.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (merchant != null) {
            if (merchant.getItems().isEmpty() && merchant.isOwner(c.getPlayer())) {
                merchant.closeShop(c, false);
                chr.setHasMerchant(false);
            }
            if (merchant.isOwner(c.getPlayer())) {
                merchant.clearMessages();
                merchant.setOpen(true);
            }
        }
        chr.setHiredMerchant(null);
        c.announce(MaplePacketCreator.enableActions());
    } else if (mode == Action.BAN_PLAYER.getCode()) {
        slea.skip(1);
        if (chr.getPlayerShop() != null && chr.getPlayerShop().isOwner(c.getPlayer())) {
            chr.getPlayerShop().banPlayer(slea.readMapleAsciiString());
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) MapleHiredMerchant(server.maps.MapleHiredMerchant) MaplePlayerShop(server.maps.MaplePlayerShop) MapleMapObject(server.maps.MapleMapObject) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) MapleMiniGame(server.maps.MapleMiniGame) MapleItemInformationProvider(server.MapleItemInformationProvider) MaplePlayerShopItem(server.maps.MaplePlayerShopItem)

Example 25 with MapleInventoryType

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

the class StorageHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    byte mode = slea.readByte();
    final MapleStorage storage = chr.getStorage();
    if (chr.getLevel() < 15) {
        chr.dropMessage(1, "You may only use the storage once you have reached level 15.");
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (mode == 4) {
        // take out
        byte type = slea.readByte();
        byte slot = slea.readByte();
        if (slot < 0 || slot > storage.getSlots()) {
            // removal starts at zero
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with storage.");
            FilePrinter.print(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to work with storage slot " + slot + "\r\n");
            c.disconnect(true, false);
            return;
        }
        slot = storage.getSlot(MapleInventoryType.getByType(type), slot);
        Item item = storage.getItem(slot);
        if (item != null) {
            if (MapleItemInformationProvider.getInstance().isPickupRestricted(item.getItemId()) && chr.haveItemWithId(item.getItemId(), true)) {
                c.announce(MaplePacketCreator.getStorageError((byte) 0x0C));
                return;
            }
            if (chr.getMap().getId() == 910000000) {
                if (chr.getMeso() < 1000) {
                    c.announce(MaplePacketCreator.getStorageError((byte) 0x0B));
                    return;
                } else {
                    chr.gainMeso(-1000, false);
                }
            }
            if (MapleInventoryManipulator.checkSpace(c, item.getItemId(), item.getQuantity(), item.getOwner())) {
                // actually the same but idc
                item = storage.takeOut(slot);
                String itemName = MapleItemInformationProvider.getInstance().getName(item.getItemId());
                FilePrinter.print(FilePrinter.STORAGE + c.getAccountName() + ".txt", c.getPlayer().getName() + " took out " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")\r\n");
                if ((item.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA) {
                    // items with scissors of karma used on them are reset once traded
                    item.setFlag((byte) (item.getFlag() ^ ItemConstants.KARMA));
                }
                MapleInventoryManipulator.addFromDrop(c, item, false);
                storage.sendTakenOut(c, item.getInventoryType());
            } else {
                c.announce(MaplePacketCreator.getStorageError((byte) 0x0A));
            }
        }
    } else if (mode == 5) {
        // store
        short slot = slea.readShort();
        int itemId = slea.readInt();
        short quantity = slea.readShort();
        MapleInventoryType slotType = ItemConstants.getInventoryType(itemId);
        MapleInventory Inv = chr.getInventory(slotType);
        if (slot < 1 || slot > Inv.getSlotLimit()) {
            // player inv starts at one
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with storage.");
            FilePrinter.print(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to store item at slot " + slot + "\r\n");
            c.disconnect(true, false);
            return;
        }
        if (quantity < 1 || chr.getItemQuantity(itemId, false) < quantity) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (storage.isFull()) {
            c.announce(MaplePacketCreator.getStorageError((byte) 0x11));
            return;
        }
        short meso = (short) (chr.getMap().getId() == 910000000 ? -500 : -100);
        if (chr.getMeso() < meso) {
            c.announce(MaplePacketCreator.getStorageError((byte) 0x0B));
        } else {
            MapleInventoryType invType = ItemConstants.getInventoryType(itemId);
            Item item = chr.getInventory(invType).getItem(slot).copy();
            if (item.getItemId() == itemId && (item.getQuantity() >= quantity || ItemConstants.isRechargable(itemId))) {
                if (ItemConstants.isRechargable(itemId)) {
                    quantity = item.getQuantity();
                }
                chr.gainMeso(meso, false, true, false);
                MapleInventoryManipulator.removeFromSlot(c, invType, slot, quantity, false);
                item.setQuantity(quantity);
                storage.store(item);
                storage.sendStored(c, ItemConstants.getInventoryType(itemId));
                String itemName = MapleItemInformationProvider.getInstance().getName(item.getItemId());
                FilePrinter.print(FilePrinter.STORAGE + c.getAccountName() + ".txt", c.getPlayer().getName() + " stored " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")\r\n");
            }
        }
    } else if (mode == 6) {
        // arrange items
        if (ServerConstants.USE_STORAGE_ITEM_SORT)
            storage.arrangeItems(c);
        c.announce(MaplePacketCreator.enableActions());
    } else if (mode == 7) {
        // meso
        int meso = slea.readInt();
        int storageMesos = storage.getMeso();
        int playerMesos = chr.getMeso();
        if ((meso > 0 && storageMesos >= meso) || (meso < 0 && playerMesos >= -meso)) {
            if (meso < 0 && (storageMesos - meso) < 0) {
                meso = -2147483648 + storageMesos;
                if (meso < playerMesos) {
                    c.announce(MaplePacketCreator.enableActions());
                    return;
                }
            } else if (meso > 0 && (playerMesos + meso) < 0) {
                meso = 2147483647 - playerMesos;
                if (meso > storageMesos) {
                    c.announce(MaplePacketCreator.enableActions());
                    return;
                }
            }
            storage.setMeso(storageMesos - meso);
            chr.gainMeso(meso, false, true, false);
            FilePrinter.print(FilePrinter.STORAGE + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + (meso > 0 ? " took out " : " stored ") + Math.abs(meso) + " mesos\r\n");
        } else {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        storage.sendMeso(c);
    } else if (mode == 8) {
        // close
        storage.close();
    }
}
Also used : MapleStorage(server.MapleStorage) Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) MapleInventoryType(client.inventory.MapleInventoryType) MapleInventory(client.inventory.MapleInventory)

Aggregations

MapleInventoryType (client.inventory.MapleInventoryType)28 Item (client.inventory.Item)20 MapleCharacter (client.MapleCharacter)9 Point (java.awt.Point)7 SQLException (java.sql.SQLException)6 MapleItemInformationProvider (server.MapleItemInformationProvider)5 Equip (client.inventory.Equip)4 MapleInventory (client.inventory.MapleInventory)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 LinkedList (java.util.LinkedList)4 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)4 DatabaseConnection (tools.DatabaseConnection)4 MapleClient (client.MapleClient)3 ModifyInventory (client.inventory.ModifyInventory)3 ArrayList (java.util.ArrayList)3 MapleMap (server.maps.MapleMap)3 MapleMapObject (server.maps.MapleMapObject)3 Pair (tools.Pair)3