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