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();
}
}
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;
}
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;
}
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));
}
}
}
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;
}
Aggregations