Search in sources :

Example 71 with Item

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

the class MapleInventoryManipulator method checkSpaceProgressively.

public static int checkSpaceProgressively(MapleClient c, int itemid, int quantity, String owner, int usedSlots) {
    // return value --> bit0: if has space for this one;
    // value after: new slots filled;
    // assumption: equipments always have slotMax == 1.
    int returnValue;
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = ItemConstants.getInventoryType(itemid);
    if (ii.isPickupRestricted(itemid) && haveItemWithId(c.getPlayer().getInventory(type), itemid)) {
        return 0;
    }
    if (!type.equals(MapleInventoryType.EQUIP)) {
        short slotMax = ii.getSlotMax(c, itemid);
        if (!ItemConstants.isRechargable(itemid)) {
            List<Item> existing = c.getPlayer().getInventory(type).listById(itemid);
            if (// first update all existing slots to slotMax
            existing.size() > 0) {
                for (Item eItem : existing) {
                    short oldQ = eItem.getQuantity();
                    if (oldQ < slotMax && owner.equals(eItem.getOwner())) {
                        short newQ = (short) Math.min(oldQ + quantity, slotMax);
                        quantity -= (newQ - oldQ);
                    }
                    if (quantity <= 0) {
                        break;
                    }
                }
            }
        }
        final int numSlotsNeeded;
        if (slotMax > 0) {
            numSlotsNeeded = (int) (Math.ceil(((double) quantity) / slotMax));
        } else if (ItemConstants.isRechargable(itemid)) {
            numSlotsNeeded = 1;
        } else {
            numSlotsNeeded = 1;
        }
        returnValue = ((numSlotsNeeded + usedSlots) << 1);
        returnValue += (numSlotsNeeded == 0 || !c.getPlayer().getInventory(type).isFullAfterSomeItems(numSlotsNeeded - 1, usedSlots)) ? 1 : 0;
    // System.out.print(" needed " + numSlotsNeeded + " used " + usedSlots + " rval " + returnValue);
    } else {
        returnValue = ((quantity + usedSlots) << 1);
        returnValue += (!c.getPlayer().getInventory(type).isFullAfterSomeItems(0, usedSlots)) ? 1 : 0;
    // System.out.print(" eqpneeded " + 1 + " used " + usedSlots + " rval " + returnValue);
    }
    return returnValue;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) Point(java.awt.Point)

Example 72 with Item

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

the class MapleInventoryManipulator method move.

public static void move(MapleClient c, MapleInventoryType type, short src, short dst) {
    if (src < 0 || dst < 0) {
        return;
    }
    if (dst > c.getPlayer().getInventory(type).getSlotLimit()) {
        return;
    }
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item source = c.getPlayer().getInventory(type).getItem(src);
    Item initialTarget = c.getPlayer().getInventory(type).getItem(dst);
    if (source == null) {
        return;
    }
    short olddstQ = -1;
    if (initialTarget != null) {
        olddstQ = initialTarget.getQuantity();
    }
    short oldsrcQ = source.getQuantity();
    short slotMax = ii.getSlotMax(c, source.getItemId());
    c.getPlayer().getInventory(type).move(src, dst, slotMax);
    final List<ModifyInventory> mods = new ArrayList<>();
    if (!(type.equals(MapleInventoryType.EQUIP) || type.equals(MapleInventoryType.CASH)) && initialTarget != null && initialTarget.getItemId() == source.getItemId() && !ItemConstants.isRechargable(source.getItemId()) && isSameOwner(source, initialTarget)) {
        if ((olddstQ + oldsrcQ) > slotMax) {
            mods.add(new ModifyInventory(1, source));
            mods.add(new ModifyInventory(1, initialTarget));
        } else {
            mods.add(new ModifyInventory(3, source));
            mods.add(new ModifyInventory(1, initialTarget));
        }
    } else {
        mods.add(new ModifyInventory(2, source, src));
    }
    c.announce(MaplePacketCreator.modifyInventory(true, mods));
}
Also used : Item(client.inventory.Item) ArrayList(java.util.ArrayList) ModifyInventory(client.inventory.ModifyInventory)

Example 73 with Item

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

the class MapleInventoryManipulator method checkSpace.

public static boolean checkSpace(MapleClient c, int itemid, int quantity, String owner) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = ItemConstants.getInventoryType(itemid);
    if (ii.isPickupRestricted(itemid) && haveItemWithId(c.getPlayer().getInventory(type), itemid)) {
        return false;
    }
    if (!type.equals(MapleInventoryType.EQUIP)) {
        short slotMax = ii.getSlotMax(c, itemid);
        List<Item> existing = c.getPlayer().getInventory(type).listById(itemid);
        if (!ItemConstants.isRechargable(itemid)) {
            if (// first update all existing slots to slotMax
            existing.size() > 0) {
                for (Item eItem : existing) {
                    short oldQ = eItem.getQuantity();
                    if (oldQ < slotMax && owner.equals(eItem.getOwner())) {
                        short newQ = (short) Math.min(oldQ + quantity, slotMax);
                        quantity -= (newQ - oldQ);
                    }
                    if (quantity <= 0) {
                        break;
                    }
                }
            }
        }
        final int numSlotsNeeded;
        if (slotMax > 0) {
            numSlotsNeeded = (int) (Math.ceil(((double) quantity) / slotMax));
        } else if (ItemConstants.isRechargable(itemid)) {
            numSlotsNeeded = 1;
        } else {
            numSlotsNeeded = 1;
        }
        return !c.getPlayer().getInventory(type).isFull(numSlotsNeeded - 1);
    } else {
        return !c.getPlayer().getInventory(type).isFull();
    }
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) Point(java.awt.Point)

Example 74 with Item

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

the class MapleInventoryManipulator method addById.

public static boolean addById(MapleClient c, int itemId, short quantity, String owner, int petid, byte flag, long expiration) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    MapleInventoryType type = ItemConstants.getInventoryType(itemId);
    if (!type.equals(MapleInventoryType.EQUIP)) {
        short slotMax = ii.getSlotMax(c, itemId);
        List<Item> existing = c.getPlayer().getInventory(type).listById(itemId);
        if (!ItemConstants.isRechargable(itemId) && 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 && (eItem.getOwner().equals(owner) || owner == null)) {
                            short newQ = (short) Math.min(oldQ + quantity, slotMax);
                            quantity -= (newQ - oldQ);
                            eItem.setQuantity(newQ);
                            eItem.setExpiration(expiration);
                            c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(1, eItem))));
                        }
                    } else {
                        break;
                    }
                }
            }
            while (quantity > 0 || ItemConstants.isRechargable(itemId)) {
                short newQ = (short) Math.min(quantity, slotMax);
                if (newQ != 0) {
                    quantity -= newQ;
                    Item nItem = new Item(itemId, (short) 0, newQ, petid);
                    nItem.setFlag(flag);
                    nItem.setExpiration(expiration);
                    short newSlot = c.getPlayer().getInventory(type).addItem(nItem);
                    if (newSlot == -1) {
                        c.announce(MaplePacketCreator.getInventoryFull());
                        c.announce(MaplePacketCreator.getShowInventoryFull());
                        return false;
                    }
                    if (owner != null) {
                        nItem.setOwner(owner);
                    }
                    c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, nItem))));
                    if ((ItemConstants.isRechargable(itemId)) && quantity == 0) {
                        break;
                    }
                } else {
                    c.announce(MaplePacketCreator.enableActions());
                    return false;
                }
            }
        } else {
            Item nItem = new Item(itemId, (short) 0, quantity, petid);
            nItem.setFlag(flag);
            nItem.setExpiration(expiration);
            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))));
        }
    } else if (quantity == 1) {
        Item nEquip = ii.getEquipById(itemId);
        nEquip.setFlag(flag);
        nEquip.setExpiration(expiration);
        if (owner != null) {
            nEquip.setOwner(owner);
        }
        short newSlot = c.getPlayer().getInventory(type).addItem(nEquip);
        if (newSlot == -1) {
            c.announce(MaplePacketCreator.getInventoryFull());
            c.announce(MaplePacketCreator.getShowInventoryFull());
            return false;
        }
        c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(0, nEquip))));
    } else {
        throw new RuntimeException("Trying to create equip with non-one quantity");
    }
    return true;
}
Also used : Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) ModifyInventory(client.inventory.ModifyInventory)

Example 75 with Item

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

the class MapleInventoryManipulator method drop.

public static void drop(MapleClient c, MapleInventoryType type, short src, short quantity) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    if (src < 0) {
        type = MapleInventoryType.EQUIPPED;
    }
    Item source = c.getPlayer().getInventory(type).getItem(src);
    if (c.getPlayer().getTrade() != null || c.getPlayer().getMiniGame() != null || source == null) {
        // Only check needed would prob be merchants (to see if the player is in one)
        return;
    }
    int itemId = source.getItemId();
    if (ItemConstants.isPet(itemId)) {
        return;
    }
    if (type == MapleInventoryType.EQUIPPED && itemId == 1122017) {
        c.getPlayer().unequipPendantOfSpirit();
    }
    if (c.getPlayer().getItemEffect() == itemId && source.getQuantity() == 1) {
        c.getPlayer().setItemEffect(0);
        c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.itemEffect(c.getPlayer().getId(), 0));
    } else if (itemId == 5370000 || itemId == 5370001) {
        if (c.getPlayer().getItemQuantity(itemId, false) == 1) {
            c.getPlayer().setChalkboard(null);
        }
    }
    if ((!ItemConstants.isRechargable(itemId) && source.getQuantity() < quantity) || quantity < 0) {
        return;
    }
    Point dropPos = new Point(c.getPlayer().getPosition());
    if (quantity < source.getQuantity() && !ItemConstants.isRechargable(itemId)) {
        Item target = source.copy();
        target.setQuantity(quantity);
        source.setQuantity((short) (source.getQuantity() - quantity));
        c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(1, source))));
        if (ItemConstants.isNewYearCardEtc(itemId)) {
            if (itemId == 4300000) {
                NewYearCardRecord.removeAllNewYearCard(true, c.getPlayer());
                c.getAbstractPlayerInteraction().removeAll(4300000);
            } else {
                NewYearCardRecord.removeAllNewYearCard(false, c.getPlayer());
                c.getAbstractPlayerInteraction().removeAll(4301000);
            }
        }
        boolean weddingRing = source.getItemId() == 1112803 || source.getItemId() == 1112806 || source.getItemId() == 1112807 || source.getItemId() == 1112809;
        if (weddingRing) {
            c.getPlayer().getMap().disappearingItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos);
        } else if (c.getPlayer().getMap().getEverlast()) {
            if (ii.isDropRestricted(target.getItemId()) || ii.isCash(target.getItemId()) || isDroppedItemRestricted(target)) {
                c.getPlayer().getMap().disappearingItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos);
            } else {
                c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos, true, true);
            }
        } else if (ii.isDropRestricted(target.getItemId()) || ii.isCash(target.getItemId()) || isDroppedItemRestricted(target)) {
            c.getPlayer().getMap().disappearingItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos);
        } else {
            c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), target, dropPos, true, true);
        }
    } else {
        c.getPlayer().getInventory(type).removeSlot(src);
        c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(3, source))));
        if (src < 0) {
            c.getPlayer().equipChanged();
        } else if (ItemConstants.isNewYearCardEtc(itemId)) {
            if (itemId == 4300000) {
                NewYearCardRecord.removeAllNewYearCard(true, c.getPlayer());
                c.getAbstractPlayerInteraction().removeAll(4300000);
            } else {
                NewYearCardRecord.removeAllNewYearCard(false, c.getPlayer());
                c.getAbstractPlayerInteraction().removeAll(4301000);
            }
        }
        if (c.getPlayer().getMap().getEverlast()) {
            if (ii.isDropRestricted(itemId) || ii.isCash(itemId) || isDroppedItemRestricted(source)) {
                c.getPlayer().getMap().disappearingItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos);
            } else {
                c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos, true, true);
            }
        } else if (ii.isDropRestricted(itemId) || ii.isCash(itemId) || isDroppedItemRestricted(source)) {
            c.getPlayer().getMap().disappearingItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos);
        } else {
            c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), source, dropPos, true, true);
        }
    }
}
Also used : Item(client.inventory.Item) Point(java.awt.Point) Point(java.awt.Point) 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