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