Search in sources :

Example 6 with MapleInventoryType

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

the class ItemConstants method getInventoryType.

public static MapleInventoryType getInventoryType(final int itemId) {
    if (inventoryTypeCache.containsKey(itemId)) {
        return inventoryTypeCache.get(itemId);
    }
    MapleInventoryType ret = MapleInventoryType.UNDEFINED;
    final byte type = (byte) (itemId / 1000000);
    if (type >= 1 && type <= 5) {
        ret = MapleInventoryType.getByType(type);
    }
    inventoryTypeCache.put(itemId, ret);
    return ret;
}
Also used : MapleInventoryType(client.inventory.MapleInventoryType)

Example 7 with MapleInventoryType

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

the class MapleInventoryManipulator method addFromDrop.

public static boolean addFromDrop(MapleClient c, Item item, boolean show, int petId) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = item.getInventoryType();
    if (ii.isPickupRestricted(item.getItemId()) && c.getPlayer().haveItemWithId(item.getItemId(), true)) {
        c.announce(MaplePacketCreator.getInventoryFull());
        c.announce(MaplePacketCreator.showItemUnavailable());
        return false;
    }
    short quantity = item.getQuantity();
    if (!type.equals(MapleInventoryType.EQUIP)) {
        short slotMax = ii.getSlotMax(c, item.getItemId());
        List<Item> existing = c.getPlayer().getInventory(type).listById(item.getItemId());
        if (!ItemConstants.isRechargable(item.getItemId()) && petId == -1) {
            if (existing.size() > 0) {
                // first update all existing slots to slotMax
                Iterator<Item> i = existing.iterator();
                while (quantity > 0) {
                    if (i.hasNext()) {
                        Item eItem = (Item) i.next();
                        short oldQ = eItem.getQuantity();
                        if (oldQ < slotMax && item.getOwner().equals(eItem.getOwner())) {
                            short newQ = (short) Math.min(oldQ + quantity, slotMax);
                            quantity -= (newQ - oldQ);
                            eItem.setQuantity(newQ);
                            c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(1, eItem))));
                        }
                    } else {
                        break;
                    }
                }
            }
            while (quantity > 0) {
                short newQ = (short) Math.min(quantity, slotMax);
                quantity -= newQ;
                Item nItem = new Item(item.getItemId(), (short) 0, newQ, petId);
                nItem.setExpiration(item.getExpiration());
                nItem.setOwner(item.getOwner());
                nItem.setFlag(item.getFlag());
                short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
                if (newSlot == -1) {
                    c.announce(MaplePacketCreator.getInventoryFull());
                    c.announce(MaplePacketCreator.getShowInventoryFull());
                    item.setQuantity((short) (quantity + newQ));
                    return false;
                }
                c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, nItem))));
            }
        } else {
            Item nItem = new Item(item.getItemId(), (short) 0, quantity, petId);
            nItem.setExpiration(item.getExpiration());
            short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
            if (newSlot == -1) {
                c.announce(MaplePacketCreator.getInventoryFull());
                c.announce(MaplePacketCreator.getShowInventoryFull());
                return false;
            }
            c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, nItem))));
            c.announce(MaplePacketCreator.enableActions());
        }
    } else if (quantity == 1) {
        short newSlot = c.getPlayer().getInventory(type).addItem(item);
        if (newSlot == -1) {
            c.announce(MaplePacketCreator.getInventoryFull());
            c.announce(MaplePacketCreator.getShowInventoryFull());
            return false;
        }
        c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, item))));
    } else {
        FilePrinter.printError(FilePrinter.ITEM, "Tried to pickup Equip id " + item.getItemId() + " containing more than 1 quantity --> " + quantity);
        c.announce(MaplePacketCreator.getInventoryFull());
        c.announce(MaplePacketCreator.showItemUnavailable());
        return false;
    }
    if (show) {
        c.announce(MaplePacketCreator.getShowItemGain(item.getItemId(), item.getQuantity()));
    }
    return true;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) ModifyInventory(client.inventory.ModifyInventory)

Example 8 with MapleInventoryType

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

the class AbstractPlayerInteraction method removeAll.

public void removeAll(int id, MapleClient cl) {
    MapleInventoryType invType = ItemConstants.getInventoryType(id);
    int possessed = cl.getPlayer().getInventory(invType).countById(id);
    if (possessed > 0) {
        MapleInventoryManipulator.removeById(cl, ItemConstants.getInventoryType(id), id, possessed, true, false);
        cl.announce(MaplePacketCreator.getShowItemGain(id, (short) -possessed, true));
    }
    if (invType == MapleInventoryType.EQUIP) {
        if (cl.getPlayer().getInventory(MapleInventoryType.EQUIPPED).countById(id) > 0) {
            MapleInventoryManipulator.removeById(cl, MapleInventoryType.EQUIPPED, id, 1, true, false);
            cl.announce(MaplePacketCreator.getShowItemGain(id, (short) -1, true));
        }
    }
}
Also used : MapleInventoryType(client.inventory.MapleInventoryType) Point(java.awt.Point)

Example 9 with MapleInventoryType

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

the class MapleStorage method arrangeItems.

public void arrangeItems(MapleClient c) {
    lock.lock();
    try {
        MapleStorageInventory msi = new MapleStorageInventory(c, items);
        msi.mergeItems();
        items = msi.sortItems();
        for (MapleInventoryType type : MapleInventoryType.values()) {
            typeItems.put(type, new ArrayList<>(items));
        }
        c.announce(MaplePacketCreator.arrangeStorage(slots, items));
    } finally {
        lock.unlock();
    }
}
Also used : MapleInventoryType(client.inventory.MapleInventoryType)

Example 10 with MapleInventoryType

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

the class MapleStorage method store.

public void store(Item item) {
    lock.lock();
    try {
        items.add(item);
        MapleInventoryType type = item.getInventoryType();
        typeItems.put(type, new ArrayList<>(filterItems(type)));
    } finally {
        lock.unlock();
    }
}
Also used : MapleInventoryType(client.inventory.MapleInventoryType)

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