Search in sources :

Example 6 with ModifyInventory

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

the class AbstractPlayerInteraction method gainAndEquip.

public void gainAndEquip(int itemid, short slot) {
    final Item old = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(slot);
    if (old != null) {
        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.EQUIPPED, slot, old.getQuantity(), false, false);
    }
    final Item newItem = MapleItemInformationProvider.getInstance().getEquipById(itemid);
    newItem.setPosition(slot);
    c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(newItem);
    c.announce(MaplePacketCreator.modifyInventory(false, Collections.singletonList(new ModifyInventory(0, newItem))));
}
Also used : Item(client.inventory.Item) ModifyInventory(client.inventory.ModifyInventory)

Example 7 with ModifyInventory

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

the class MapleInventoryManipulator method unequip.

public static void unequip(MapleClient c, short src, short dst) {
    Equip source = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(src);
    Equip target = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(dst);
    if (dst < 0) {
        return;
    }
    if (source == null) {
        return;
    }
    if (target != null && src <= 0) {
        c.announce(MaplePacketCreator.getInventoryFull());
        return;
    }
    if (source.getItemId() == 1122017) {
        c.getPlayer().unequipPendantOfSpirit();
    }
    if (source.getRingId() > -1) {
        c.getPlayer().getRingById(source.getRingId()).unequip();
    }
    c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeSlot(src);
    if (target != null) {
        c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeSlot(dst);
    }
    source.setPosition(dst);
    c.getPlayer().getInventory(MapleInventoryType.EQUIP).addFromDB(source);
    if (target != null) {
        target.setPosition(src);
        c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(target);
    }
    c.announce(MaplePacketCreator.modifyInventory(true, Collections.singletonList(new ModifyInventory(2, source, src))));
    c.getPlayer().equipChanged();
}
Also used : Equip(client.inventory.Equip) ModifyInventory(client.inventory.ModifyInventory)

Example 8 with ModifyInventory

use of client.inventory.ModifyInventory 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 9 with ModifyInventory

use of client.inventory.ModifyInventory 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 10 with ModifyInventory

use of client.inventory.ModifyInventory 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

ModifyInventory (client.inventory.ModifyInventory)13 Item (client.inventory.Item)10 ArrayList (java.util.ArrayList)5 Equip (client.inventory.Equip)4 MapleInventoryType (client.inventory.MapleInventoryType)3 MapleCharacter (client.MapleCharacter)2 Skill (client.Skill)2 ScrollResult (client.inventory.Equip.ScrollResult)2 MapleInventory (client.inventory.MapleInventory)2 Point (java.awt.Point)2 LinkedList (java.util.LinkedList)2 MapleItemInformationProvider (server.MapleItemInformationProvider)2 MapleClient (client.MapleClient)1 MapleJob (client.MapleJob)1 MaplePet (client.inventory.MaplePet)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 MapleShop (server.MapleShop)1 MapleMap (server.maps.MapleMap)1 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)1