Search in sources :

Example 31 with Item

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

the class CashShop method findByCashId.

public Item findByCashId(int cashId) {
    boolean isRing = false;
    Equip equip = null;
    for (Item item : getInventory()) {
        if (item.getInventoryType().equals(MapleInventoryType.EQUIP)) {
            equip = (Equip) item;
            isRing = equip.getRingId() > -1;
        }
        if ((item.getPetId() > -1 ? item.getPetId() : isRing ? equip.getRingId() : item.getCashId()) == cashId) {
            return item;
        }
    }
    return null;
}
Also used : Equip(client.inventory.Equip) Item(client.inventory.Item)

Example 32 with Item

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

the class MapleInventoryManipulator method equip.

public static void equip(MapleClient c, short src, short dst) {
    Equip source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src);
    if (source == null || !MapleItemInformationProvider.getInstance().canWearEquipment(c.getPlayer(), source, dst)) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    } else if ((((source.getItemId() >= 1902000 && source.getItemId() <= 1902002) || source.getItemId() == 1912000) && c.getPlayer().isCygnus()) || ((source.getItemId() >= 1902005 && source.getItemId() <= 1902007) || source.getItemId() == 1912005) && !c.getPlayer().isCygnus()) {
        // Adventurer taming equipment
        return;
    }
    boolean itemChanged = false;
    if (MapleItemInformationProvider.getInstance().isUntradeableOnEquip(source.getItemId())) {
        source.setFlag((byte) ItemConstants.UNTRADEABLE);
        itemChanged = true;
    }
    if (source.getRingId() > -1) {
        c.getPlayer().getRingById(source.getRingId()).equip();
    }
    if (dst == -6) {
        // unequip the overall
        Item top = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -5);
        if (top != null && ItemConstants.isOverall(top.getItemId())) {
            if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
                c.announce(MaplePacketCreator.getInventoryFull());
                c.announce(MaplePacketCreator.getShowInventoryFull());
                return;
            }
            unequip(c, (byte) -5, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
        }
    } else if (dst == -5) {
        final Item bottom = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -6);
        if (bottom != null && ItemConstants.isOverall(source.getItemId())) {
            if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
                c.announce(MaplePacketCreator.getInventoryFull());
                c.announce(MaplePacketCreator.getShowInventoryFull());
                return;
            }
            unequip(c, (byte) -6, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
        }
    } else if (dst == -10) {
        // check if weapon is two-handed
        Item weapon = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -11);
        if (weapon != null && MapleItemInformationProvider.getInstance().isTwoHanded(weapon.getItemId())) {
            if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
                c.announce(MaplePacketCreator.getInventoryFull());
                c.announce(MaplePacketCreator.getShowInventoryFull());
                return;
            }
            unequip(c, (byte) -11, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
        }
    } else if (dst == -11) {
        Item shield = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -10);
        if (shield != null && MapleItemInformationProvider.getInstance().isTwoHanded(source.getItemId())) {
            if (c.getPlayer().getInventory(MapleInventoryType.EQUIP).isFull()) {
                c.announce(MaplePacketCreator.getInventoryFull());
                c.announce(MaplePacketCreator.getShowInventoryFull());
                return;
            }
            unequip(c, (byte) -10, c.getPlayer().getInventory(MapleInventoryType.EQUIP).getNextFreeSlot());
        }
    }
    if (dst == -18) {
        if (c.getPlayer().getMount() != null) {
            c.getPlayer().getMount().setItemId(source.getItemId());
        }
    }
    if (source.getItemId() == 1122017) {
        c.getPlayer().equipPendantOfSpirit();
    }
    // 1112413, 1112414, 1112405 (Lilin's Ring)
    source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(src);
    Equip target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
    c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeSlot(src);
    if (target != null) {
        c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeSlot(dst);
    }
    final List<ModifyInventory> mods = new ArrayList<>();
    if (itemChanged) {
        mods.add(new ModifyInventory(3, source));
        // to prevent crashes
        mods.add(new ModifyInventory(0, source.copy()));
    }
    source.setPosition(dst);
    c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(source);
    if (target != null) {
        target.setPosition(src);
        c.getPlayer().getInventory(MapleInventoryType.EQUIP).addFromDB(target);
    }
    if (c.getPlayer().getBuffedValue(MapleBuffStat.BOOSTER) != null && ItemConstants.isWeapon(source.getItemId())) {
        c.getPlayer().cancelBuffStats(MapleBuffStat.BOOSTER);
    }
    mods.add(new ModifyInventory(2, source, src));
    c.announce(MaplePacketCreator.modifyInventory(true, mods));
    c.getPlayer().equipChanged();
}
Also used : Equip(client.inventory.Equip) Item(client.inventory.Item) ArrayList(java.util.ArrayList) ModifyInventory(client.inventory.ModifyInventory)

Example 33 with Item

use of client.inventory.Item 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;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) ModifyInventory(client.inventory.ModifyInventory)

Example 34 with Item

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

the class MapleInventoryManipulator method removeById.

public static void removeById(MapleClient c, MapleInventoryType type, int itemId, int quantity, boolean fromDrop, boolean consume) {
    int removeQuantity = quantity;
    MapleInventory inv = c.getPlayer().getInventory(type);
    int slotLimit = type == MapleInventoryType.EQUIPPED ? 128 : inv.getSlotLimit();
    for (short i = 0; i <= slotLimit; i++) {
        Item item = inv.getItem((short) (type == MapleInventoryType.EQUIPPED ? -i : i));
        if (item != null) {
            if (item.getItemId() == itemId || item.getCashId() == itemId) {
                if (removeQuantity <= item.getQuantity()) {
                    removeFromSlot(c, type, item.getPosition(), (short) removeQuantity, fromDrop, consume);
                    removeQuantity = 0;
                    break;
                } else {
                    removeQuantity -= item.getQuantity();
                    removeFromSlot(c, type, item.getPosition(), item.getQuantity(), fromDrop, consume);
                }
            }
        }
    }
    if (removeQuantity > 0) {
        throw new RuntimeException("[HACK] Not enough items available of Item:" + itemId + ", Quantity (After Quantity/Over Current Quantity): " + (quantity - removeQuantity) + "/" + quantity);
    }
}
Also used : Item(client.inventory.Item) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point)

Example 35 with Item

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

the class MapleInventoryManipulator method removeFromSlot.

public static void removeFromSlot(MapleClient c, MapleInventoryType type, short slot, short quantity, boolean fromDrop, boolean consume) {
    Item item = c.getPlayer().getInventory(type).getItem(slot);
    boolean allowZero = consume && ItemConstants.isRechargable(item.getItemId());
    c.getPlayer().getInventory(type).removeItem(slot, quantity, allowZero);
    if (item.getQuantity() == 0 && !allowZero) {
        c.announce(MaplePacketCreator.modifyInventory(fromDrop, Collections.singletonList(new ModifyInventory(3, item))));
    } else {
        c.announce(MaplePacketCreator.modifyInventory(fromDrop, Collections.singletonList(new ModifyInventory(1, item))));
    }
}
Also used : Item(client.inventory.Item) ModifyInventory(client.inventory.ModifyInventory)

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