Search in sources :

Example 11 with MapleInventoryType

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

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

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

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

the class WeddingHandler method handlePacket.

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    // System.out.println("Wedding Packet: " + slea);
    MapleCharacter chr = c.getPlayer();
    byte operation = slea.readByte();
    switch(operation) {
        case // Add an item to the Wedding Registry
        0x06:
            short slot = slea.readShort();
            int itemid = slea.readInt();
            short quantity = slea.readShort();
            MapleInventoryType type = ItemConstants.getInventoryType(itemid);
            Item item = chr.getInventory(type).getItem(slot);
            if (itemid == item.getItemId() && quantity <= item.getQuantity()) {
                c.announce(MaplePacketCreator.addItemToWeddingRegistry(chr, item));
            }
    }
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) MapleInventoryType(client.inventory.MapleInventoryType)

Example 15 with MapleInventoryType

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

the class ItemRequirement method check.

@Override
public boolean check(MapleCharacter chr, Integer npcid) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    for (Integer itemId : items.keySet()) {
        int countNeeded = items.get(itemId);
        int count = 0;
        MapleInventoryType iType = ItemConstants.getInventoryType(itemId);
        if (iType.equals(MapleInventoryType.UNDEFINED)) {
            return false;
        }
        for (Item item : chr.getInventory(iType).listById(itemId)) {
            count += item.getQuantity();
        }
        // Weird stuff, nexon made some quests only available when wearing gm clothes. This enables us to accept it ><
        if (iType.equals(MapleInventoryType.EQUIP)) {
            if (chr.isGM()) {
                for (Item item : chr.getInventory(MapleInventoryType.EQUIPPED).listById(itemId)) {
                    count += item.getQuantity();
                }
            } else {
                if (count < countNeeded) {
                    if (chr.getInventory(MapleInventoryType.EQUIPPED).countById(itemId) + count >= countNeeded) {
                        chr.dropMessage(5, "Unequip the required " + ii.getName(itemId) + " before trying this quest operation.");
                        return false;
                    }
                }
            }
        }
        if (count < countNeeded || countNeeded <= 0 && count > 0) {
            return false;
        }
    }
    return true;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) MapleItemInformationProvider(server.MapleItemInformationProvider)

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