Search in sources :

Example 46 with Item

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

the class MapleStorageInventory method sortItems.

public List<Item> sortItems() {
    ArrayList<Item> itemarray = new ArrayList<>();
    for (short i = 1; i <= this.getSlotLimit(); i++) {
        Item item = this.getItem(i);
        if (item != null) {
            itemarray.add((Item) item.copy());
        }
    }
    for (Item item : itemarray) {
        this.removeSlot(item.getPosition());
    }
    int invTypeCriteria = 1;
    int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
    PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
    inventory.clear();
    return itemarray;
}
Also used : Item(client.inventory.Item) ArrayList(java.util.ArrayList)

Example 47 with Item

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

the class MapleStorageInventory method PartitionByItemId.

private void PartitionByItemId(int Esq, int Dir, ArrayList<Item> A) {
    Item x, w;
    i = Esq;
    j = Dir;
    x = A.get((i + j) / 2);
    do {
        while (x.getItemId() > A.get(i).getItemId()) i++;
        while (x.getItemId() < A.get(j).getItemId()) j--;
        if (i <= j) {
            w = A.get(i);
            A.set(i, A.get(j));
            A.set(j, w);
            i++;
            j--;
        }
    } while (i <= j);
}
Also used : Item(client.inventory.Item)

Example 48 with Item

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

the class MapleStorageInventory method move.

private void move(short sSlot, short dSlot, short slotMax) {
    Item source = (Item) inventory.get(sSlot);
    Item target = (Item) inventory.get(dSlot);
    if (source == null) {
        return;
    }
    if (target == null) {
        source.setPosition(dSlot);
        inventory.put(dSlot, source);
        inventory.remove(sSlot);
    } else if (target.getItemId() == source.getItemId() && !ItemConstants.isRechargable(source.getItemId()) && !MapleItemInformationProvider.getInstance().isPickupRestricted(source.getItemId()) && isSameOwner(source, target)) {
        if (isEquipOrCash(source)) {
            swap(target, source);
        } else if (source.getQuantity() + target.getQuantity() > slotMax) {
            short rest = (short) ((source.getQuantity() + target.getQuantity()) - slotMax);
            source.setQuantity(rest);
            target.setQuantity(slotMax);
        } else {
            target.setQuantity((short) (source.getQuantity() + target.getQuantity()));
            inventory.remove(sSlot);
        }
    } else {
        swap(target, source);
    }
}
Also used : Item(client.inventory.Item)

Example 49 with Item

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

the class MapleStorageInventory method mergeItems.

public void mergeItems() {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item srcItem, dstItem;
    for (short dst = 1; dst <= this.getSlotLimit(); dst++) {
        dstItem = this.getItem(dst);
        if (dstItem == null)
            continue;
        for (short src = (short) (dst + 1); src <= this.getSlotLimit(); src++) {
            srcItem = this.getItem(src);
            if (srcItem == null)
                continue;
            if (dstItem.getItemId() != srcItem.getItemId())
                continue;
            if (dstItem.getQuantity() == ii.getSlotMax(c, this.getItem(dst).getItemId()))
                break;
            moveItem(src, dst);
        }
    }
    boolean sorted = false;
    while (!sorted) {
        short freeSlot = this.getNextFreeSlot();
        if (freeSlot != -1) {
            short itemSlot = -1;
            for (short i = (short) (freeSlot + 1); i <= this.getSlotLimit(); i = (short) (i + 1)) {
                if (this.getItem(i) != null) {
                    itemSlot = i;
                    break;
                }
            }
            if (itemSlot > 0) {
                moveItem(itemSlot, freeSlot);
            } else {
                sorted = true;
            }
        } else {
            sorted = true;
        }
    }
}
Also used : Item(client.inventory.Item)

Example 50 with Item

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

the class UseSolomonHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    slea.readInt();
    short slot = slea.readShort();
    int itemId = slea.readInt();
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item slotItem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
    int gachaexp = ii.getExpById(itemId);
    if (c.getPlayer().getInventory(MapleInventoryType.USE).countById(itemId) <= 0 || slotItem.getItemId() != itemId || c.getPlayer().getLevel() > ii.getMaxLevelById(itemId)) {
        return;
    }
    if ((c.getPlayer().getGachaExp() + gachaexp) > Integer.MAX_VALUE) {
        return;
    }
    c.getPlayer().gainGachaExp(gachaexp);
    MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
    c.announce(MaplePacketCreator.enableActions());
}
Also used : Item(client.inventory.Item) MapleItemInformationProvider(server.MapleItemInformationProvider)

Aggregations

Item (client.inventory.Item)124 MapleMapItem (server.maps.MapleMapItem)33 Equip (client.inventory.Equip)31 ArrayList (java.util.ArrayList)31 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)31 Point (java.awt.Point)29 SQLException (java.sql.SQLException)25 MapleCharacter (client.MapleCharacter)21 MapleInventoryType (client.inventory.MapleInventoryType)20 PreparedStatement (java.sql.PreparedStatement)20 Connection (java.sql.Connection)19 DatabaseConnection (tools.DatabaseConnection)19 MapleInventory (client.inventory.MapleInventory)18 MapleItemInformationProvider (server.MapleItemInformationProvider)18 ResultSet (java.sql.ResultSet)16 Pair (tools.Pair)15 CashItem (server.CashShop.CashItem)13 SpecialCashItem (server.CashShop.SpecialCashItem)12 MapleShopItem (server.MapleShopItem)12 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)11