Search in sources :

Example 11 with Item

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

the class DueyHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!ServerConstants.USE_DUEY) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    byte operation = slea.readByte();
    if (operation == Actions.TOSERVER_SEND_ITEM.getCode()) {
        final int fee = 5000;
        byte inventId = slea.readByte();
        short itemPos = slea.readShort();
        short amount = slea.readShort();
        int mesos = slea.readInt();
        String recipient = slea.readMapleAsciiString();
        if (mesos < 0 || ((long) mesos + fee + getFee(mesos)) > Integer.MAX_VALUE || (amount < 1 && mesos == 0)) {
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
            FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use duey with mesos " + mesos + " and amount " + amount + "\r\n");
            c.disconnect(true, false);
            return;
        }
        int finalcost = mesos + fee + getFee(mesos);
        boolean send = false;
        if (c.getPlayer().getMeso() >= finalcost) {
            int accid = getAccIdFromCNAME(recipient, true);
            if (accid != -1) {
                if (accid != c.getAccID()) {
                    send = true;
                } else {
                    c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SAMEACC_ERROR.getCode()));
                }
            } else {
                c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode()));
            }
        } else {
            c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_NOT_ENOUGH_MESOS.getCode()));
        }
        MapleClient rClient = null;
        int channel = c.getWorldServer().find(recipient);
        if (channel > -1) {
            Channel rcserv = c.getWorldServer().getChannel(channel);
            rClient = rcserv.getPlayerStorage().getCharacterByName(recipient).getClient();
        }
        if (send) {
            if (inventId > 0) {
                MapleInventoryType inv = MapleInventoryType.getByType(inventId);
                Item item = c.getPlayer().getInventory(inv).getItem(itemPos);
                if (item != null && c.getPlayer().getItemQuantity(item.getItemId(), false) >= amount) {
                    c.getPlayer().gainMeso(-finalcost, false);
                    c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
                    if (ItemConstants.isRechargable(item.getItemId())) {
                        MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, item.getQuantity(), true);
                    } else {
                        MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, amount, true, false);
                    }
                    addItemToDB(item, amount, mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
                } else {
                    if (item != null) {
                        c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_INCORRECT_REQUEST.getCode()));
                    }
                    return;
                }
            } else {
                c.getPlayer().gainMeso(-finalcost, false);
                c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
                addMesoToDB(mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
            }
            if (rClient != null && rClient.isLoggedIn() && !rClient.getPlayer().isAwayFromWorld()) {
                showDueyNotification(rClient, rClient.getPlayer());
            }
        }
    } else if (operation == Actions.TOSERVER_REMOVE_PACKAGE.getCode()) {
        int packageid = slea.readInt();
        removeItemFromDB(packageid);
        c.announce(MaplePacketCreator.removeItemFromDuey(true, packageid));
    } else if (operation == Actions.TOSERVER_CLAIM_PACKAGE.getCode()) {
        int packageid = slea.readInt();
        List<DueyPackages> packages = new LinkedList<>();
        DueyPackages dp = null;
        Connection con = null;
        try {
            con = DatabaseConnection.getConnection();
            DueyPackages dueypack;
            try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?")) {
                ps.setInt(1, packageid);
                try (ResultSet rs = ps.executeQuery()) {
                    dueypack = null;
                    if (rs.next()) {
                        dueypack = getItemByPID(rs);
                        dueypack.setSender(rs.getString("SenderName"));
                        dueypack.setMesos(rs.getInt("Mesos"));
                        dueypack.setSentTime(rs.getString("TimeStamp"));
                        packages.add(dueypack);
                    }
                }
            }
            dp = dueypack;
            if (dp == null) {
                c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
                FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to receive package from duey with id " + packageid + "\r\n");
                return;
            }
            if (dp.getItem() != null) {
                if (!MapleInventoryManipulator.checkSpace(c, dp.getItem().getItemId(), dp.getItem().getQuantity(), dp.getItem().getOwner())) {
                    int itemid = dp.getItem().getItemId();
                    if (MapleItemInformationProvider.getInstance().isPickupRestricted(itemid) && c.getPlayer().getInventory(ItemConstants.getInventoryType(itemid)).findById(itemid) != null) {
                        c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_RECEIVER_WITH_UNIQUE.getCode()));
                    } else {
                        c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_NO_FREE_SLOTS.getCode()));
                    }
                    return;
                } else {
                    MapleInventoryManipulator.addFromDrop(c, dp.getItem(), false);
                }
            }
            long gainmesos = 0;
            long totalmesos = (long) dp.getMesos() + (long) c.getPlayer().getMeso();
            if (totalmesos < 0 || dp.getMesos() < 0)
                gainmesos = 0;
            else {
                totalmesos = Math.min(totalmesos, Integer.MAX_VALUE);
                gainmesos = totalmesos - c.getPlayer().getMeso();
            }
            c.getPlayer().gainMeso((int) gainmesos, false);
            removeItemFromDB(packageid);
            c.announce(MaplePacketCreator.removeItemFromDuey(false, packageid));
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
Also used : SQLException(java.sql.SQLException) Channel(net.server.channel.Channel) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) LinkedList(java.util.LinkedList) Item(client.inventory.Item) DueyPackages(server.DueyPackages) MapleInventoryType(client.inventory.MapleInventoryType) ResultSet(java.sql.ResultSet) MapleClient(client.MapleClient)

Example 12 with Item

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

the class EnterMTSHandler method getTransfer.

private List<MTSItemInfo> getTransfer(int cid) {
    List<MTSItemInfo> items = new ArrayList<>();
    try {
        Connection con = DatabaseConnection.getConnection();
        try (PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_items WHERE transfer = 1 AND seller = ? ORDER BY id DESC")) {
            ps.setInt(1, cid);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    if (rs.getInt("type") != 1) {
                        Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
                        i.setOwner(rs.getString("owner"));
                        items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
                    } 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.setVicious((short) rs.getInt("vicious"));
                        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.setFlag((byte) rs.getInt("flag"));
                        items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
                    }
                }
            }
        }
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return items;
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MTSItemInfo(server.MTSItemInfo) PreparedStatement(java.sql.PreparedStatement)

Example 13 with Item

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

the class EnterMTSHandler method getNotYetSold.

private List<MTSItemInfo> getNotYetSold(int cid) {
    List<MTSItemInfo> items = new ArrayList<>();
    try {
        Connection con = DatabaseConnection.getConnection();
        try (PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 0 ORDER BY id DESC")) {
            ps.setInt(1, cid);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    if (rs.getInt("type") != 1) {
                        Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
                        i.setOwner(rs.getString("owner"));
                        items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
                    } 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.setVicious((short) rs.getInt("vicious"));
                        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.setFlag((byte) rs.getInt("flag"));
                        items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
                    }
                }
            }
        }
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return items;
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MTSItemInfo(server.MTSItemInfo) PreparedStatement(java.sql.PreparedStatement)

Example 14 with Item

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

the class FredrickHandler method handlePacket.

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    byte operation = slea.readByte();
    switch(operation) {
        case // Will never come...
        0x19:
            // c.announce(MaplePacketCreator.getFredrick((byte) 0x24));
            break;
        case 0x1A:
            List<Pair<Item, MapleInventoryType>> items;
            try {
                items = ItemFactory.MERCHANT.loadItems(chr.getId(), false);
                if (!check(chr, items)) {
                    c.announce(MaplePacketCreator.fredrickMessage((byte) 0x21));
                    return;
                }
                chr.gainMeso(chr.getMerchantMeso(), false);
                chr.setMerchantMeso(0);
                if (deleteItems(chr)) {
                    if (chr.getHiredMerchant() != null)
                        chr.getHiredMerchant().clearItems();
                    for (int i = 0; i < items.size(); i++) {
                        Item item = items.get(i).getLeft();
                        MapleInventoryManipulator.addFromDrop(c, item, false);
                        String itemName = MapleItemInformationProvider.getInstance().getName(item.getItemId());
                        FilePrinter.print(FilePrinter.FREDRICK + chr.getName() + ".txt", chr.getName() + " gained " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")\r\n");
                    }
                    c.announce(MaplePacketCreator.fredrickMessage((byte) 0x1E));
                } else {
                    chr.message("An unknown error has occured.");
                }
                break;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            break;
        case // Exit
        0x1C:
            break;
        default:
    }
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) Pair(tools.Pair)

Example 15 with Item

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

the class ItemRewardHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    byte slot = (byte) slea.readShort();
    // will load from xml I don't care.
    int itemId = slea.readInt();
    if (c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot).getItemId() != itemId || c.getPlayer().getInventory(MapleInventoryType.USE).countById(itemId) < 1)
        return;
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Pair<Integer, List<RewardItem>> rewards = ii.getItemReward(itemId);
    for (RewardItem reward : rewards.getRight()) {
        if (!MapleInventoryManipulator.checkSpace(c, reward.itemid, reward.quantity, "")) {
            c.announce(MaplePacketCreator.getShowInventoryFull());
            break;
        }
        if (Randomizer.nextInt(rewards.getLeft()) < reward.prob) {
            // Is it even possible to get an item with prob 1?
            if (ItemConstants.getInventoryType(reward.itemid) == MapleInventoryType.EQUIP) {
                final Item item = ii.getEquipById(reward.itemid);
                if (reward.period != -1) {
                    item.setExpiration(System.currentTimeMillis() + (reward.period * 60 * 60 * 10));
                }
                MapleInventoryManipulator.addFromDrop(c, item, false);
            } else {
                MapleInventoryManipulator.addById(c, reward.itemid, reward.quantity);
            }
            MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, false, false);
            if (reward.worldmsg != null) {
                String msg = reward.worldmsg;
                msg.replaceAll("/name", c.getPlayer().getName());
                msg.replaceAll("/item", ii.getName(reward.itemid));
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, msg));
            }
            break;
        }
    }
    c.announce(MaplePacketCreator.enableActions());
}
Also used : RewardItem(server.MapleItemInformationProvider.RewardItem) Item(client.inventory.Item) MapleItemInformationProvider(server.MapleItemInformationProvider) RewardItem(server.MapleItemInformationProvider.RewardItem) List(java.util.List)

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