Search in sources :

Example 41 with Item

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

the class MapleStorage method sendStorage.

public void sendStorage(MapleClient c, int npcId) {
    if (c.getPlayer().getLevel() < 15) {
        c.getPlayer().dropMessage(1, "You may only use the storage once you have reached level 15.");
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    lock.lock();
    try {
        Collections.sort(items, new Comparator<Item>() {

            @Override
            public int compare(Item o1, Item o2) {
                if (o1.getInventoryType().getType() < o2.getInventoryType().getType()) {
                    return -1;
                } else if (o1.getInventoryType() == o2.getInventoryType()) {
                    return 0;
                }
                return 1;
            }
        });
        List<Item> storageItems = getItems();
        for (MapleInventoryType type : MapleInventoryType.values()) {
            typeItems.put(type, new ArrayList<>(storageItems));
        }
        c.announce(MaplePacketCreator.getStorage(npcId, slots, storageItems, meso));
    } finally {
        lock.unlock();
    }
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType)

Example 42 with Item

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

the class MapleStorage method getSlot.

public byte getSlot(MapleInventoryType type, byte slot) {
    lock.lock();
    try {
        byte ret = 0;
        List<Item> storageItems = getItems();
        for (Item item : storageItems) {
            if (item == typeItems.get(type).get(slot)) {
                return ret;
            }
            ret++;
        }
        return -1;
    } finally {
        lock.unlock();
    }
}
Also used : Item(client.inventory.Item)

Example 43 with Item

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

the class MapleStorage method loadOrCreateFromDB.

public static MapleStorage loadOrCreateFromDB(int id, int world) {
    MapleStorage ret = null;
    int storeId;
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT storageid, slots, meso FROM storages WHERE accountid = ? AND world = ?");
        ps.setInt(1, id);
        ps.setInt(2, world);
        ResultSet rs = ps.executeQuery();
        if (!rs.next()) {
            rs.close();
            ps.close();
            con.close();
            return create(id, world);
        } else {
            storeId = rs.getInt("storageid");
            ret = new MapleStorage(storeId, (byte) rs.getInt("slots"), rs.getInt("meso"));
            rs.close();
            ps.close();
            for (Pair<Item, MapleInventoryType> item : ItemFactory.STORAGE.loadItems(ret.id, false)) {
                ret.items.add(item.getLeft());
            }
        }
        con.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return ret;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) SQLException(java.sql.SQLException) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 44 with Item

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

the class MapleStorage method takeOut.

public Item takeOut(byte slot) {
    Item ret;
    lock.lock();
    try {
        ret = items.remove(slot);
        MapleInventoryType type = ret.getInventoryType();
        typeItems.put(type, new ArrayList<>(filterItems(type)));
    } finally {
        lock.unlock();
    }
    return ret;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType)

Example 45 with Item

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

the class MapleStorageInventory method PartitionByName.

private void PartitionByName(int Esq, int Dir, ArrayList<Item> A) {
    Item x, w;
    i = Esq;
    j = Dir;
    x = A.get((i + j) / 2);
    do {
        while (ii.getName(x.getItemId()).compareTo(ii.getName(A.get(i).getItemId())) > 0) i++;
        while (ii.getName(x.getItemId()).compareTo(ii.getName(A.get(j).getItemId())) < 0) j--;
        if (i <= j) {
            w = A.get(i);
            A.set(i, A.get(j));
            A.set(j, w);
            i++;
            j--;
        }
    } while (i <= j);
}
Also used : Item(client.inventory.Item)

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