Search in sources :

Example 1 with ItemScriptManager

use of scripting.item.ItemScriptManager in project HeavenMS by ronancpl.

the class MapleCharacter method pickupItem.

public final void pickupItem(MapleMapObject ob, int petIndex) {
    // yes, one picks the MapleMapObject, not the MapleMapItem
    if (ob == null) {
        // pet index refers to the one picking up the item
        return;
    }
    if (ob instanceof MapleMapItem) {
        MapleMapItem mapitem = (MapleMapItem) ob;
        if (System.currentTimeMillis() - mapitem.getDropTime() < 900 || !mapitem.canBePickedBy(this)) {
            client.announce(MaplePacketCreator.enableActions());
            return;
        }
        boolean isPet = petIndex > -1;
        final byte[] pickupPacket = MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), (isPet) ? 5 : 2, this.getId(), isPet, petIndex);
        boolean hasSpaceInventory = true;
        if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866 || mapitem.getMeso() > 0 || ii.isConsumeOnPickup(mapitem.getItemId()) || (hasSpaceInventory = MapleInventoryManipulator.checkSpace(client, mapitem.getItemId(), mapitem.getItem().getQuantity(), mapitem.getItem().getOwner()))) {
            if ((this.getMapId() > 209000000 && this.getMapId() < 209000016) || (this.getMapId() >= 990000500 && this.getMapId() <= 990000502)) {
                // happyville trees and guild PQ
                if (!mapitem.isPlayerDrop() || mapitem.getDropper().getObjectId() == client.getPlayer().getObjectId()) {
                    if (mapitem.getMeso() > 0) {
                        this.gainMeso(mapitem.getMeso(), true, true, false);
                        this.getMap().pickItemDrop(pickupPacket, mapitem);
                    } else if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
                        // Add NX to account, show effect and make item disappear
                        int nxGain = mapitem.getItemId() == 4031865 ? 100 : 250;
                        this.getCashShop().gainCash(1, nxGain);
                        showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
                        this.getMap().pickItemDrop(pickupPacket, mapitem);
                    } else if (MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
                        this.getMap().pickItemDrop(pickupPacket, mapitem);
                    } else {
                        client.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                } else {
                    client.announce(MaplePacketCreator.showItemUnavailable());
                    client.announce(MaplePacketCreator.enableActions());
                    return;
                }
                client.announce(MaplePacketCreator.enableActions());
                return;
            }
            synchronized (mapitem) {
                if (mapitem.getQuest() > 0 && !this.needQuestItem(mapitem.getQuest(), mapitem.getItemId())) {
                    client.announce(MaplePacketCreator.showItemUnavailable());
                    client.announce(MaplePacketCreator.enableActions());
                    return;
                }
                if (mapitem.isPickedUp()) {
                    client.announce(MaplePacketCreator.showItemUnavailable());
                    client.announce(MaplePacketCreator.enableActions());
                    return;
                }
                if (mapitem.getMeso() > 0) {
                    prtLock.lock();
                    try {
                        if (this.party != null) {
                            int mesosamm = mapitem.getMeso();
                            if (mesosamm > 50000 * this.getMesoRate()) {
                                return;
                            }
                            int partynum = 0;
                            for (MaplePartyCharacter partymem : this.party.getMembers()) {
                                if (partymem.isOnline() && partymem.getMapId() == this.getMap().getId() && partymem.getChannel() == client.getChannel()) {
                                    partynum++;
                                }
                            }
                            for (MaplePartyCharacter partymem : this.party.getMembers()) {
                                if (partymem.isOnline() && partymem.getMapId() == this.getMap().getId()) {
                                    MapleCharacter somecharacter = client.getChannelServer().getPlayerStorage().getCharacterById(partymem.getId());
                                    if (somecharacter != null) {
                                        somecharacter.gainMeso(mesosamm / partynum, true, true, false);
                                    }
                                }
                            }
                        } else {
                            this.gainMeso(mapitem.getMeso(), true, true, false);
                        }
                    } finally {
                        prtLock.unlock();
                    }
                } else if (mapitem.getItem().getItemId() / 10000 == 243) {
                    MapleItemInformationProvider.scriptedItem info = ii.getScriptedItemInfo(mapitem.getItem().getItemId());
                    if (info.runOnPickup()) {
                        ItemScriptManager ism = ItemScriptManager.getInstance();
                        String scriptName = info.getScript();
                        if (ism.scriptExists(scriptName)) {
                            ism.getItemScript(client, scriptName);
                        }
                    } else {
                        if (!MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
                            client.announce(MaplePacketCreator.enableActions());
                            return;
                        }
                    }
                } else if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
                    // Add NX to account, show effect and make item disappear
                    int nxGain = mapitem.getItemId() == 4031865 ? 100 : 250;
                    this.getCashShop().gainCash(1, nxGain);
                    showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
                } else if (useItem(client, mapitem.getItem().getItemId())) {
                    if (mapitem.getItem().getItemId() / 10000 == 238) {
                        this.getMonsterBook().addCard(client, mapitem.getItem().getItemId());
                    }
                } else if (MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
                } else if (mapitem.getItem().getItemId() == 4031868) {
                    this.getMap().broadcastMessage(MaplePacketCreator.updateAriantPQRanking(this.getName(), this.getItemQuantity(4031868, false), false));
                } else {
                    client.announce(MaplePacketCreator.enableActions());
                    return;
                }
                this.getMap().pickItemDrop(pickupPacket, mapitem);
            }
        } else if (!hasSpaceInventory) {
            client.announce(MaplePacketCreator.getInventoryFull());
            client.announce(MaplePacketCreator.getShowInventoryFull());
        }
    }
    client.announce(MaplePacketCreator.enableActions());
}
Also used : ItemScriptManager(scripting.item.ItemScriptManager) MapleMapItem(server.maps.MapleMapItem) Point(java.awt.Point) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Example 2 with ItemScriptManager

use of scripting.item.ItemScriptManager in project HeavenMS by ronancpl.

the class ScriptedItemHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    // trash stamp (thx rmzero)
    slea.readInt();
    // item sl0t (thx rmzero)
    short itemSlot = slea.readShort();
    // itemId
    int itemId = slea.readInt();
    scriptedItem info = ii.getScriptedItemInfo(itemId);
    if (info == null)
        return;
    ItemScriptManager ism = ItemScriptManager.getInstance();
    Item item = c.getPlayer().getInventory(ItemConstants.getInventoryType(itemId)).getItem(itemSlot);
    if (item == null || item.getItemId() != itemId || item.getQuantity() < 1 || !ism.scriptExists(info.getScript())) {
        return;
    }
    ism.getItemScript(c, info.getScript());
    c.announce(MaplePacketCreator.enableActions());
// NPCScriptManager.getInstance().start(c, info.getNpc(), null, null);
}
Also used : MapleItemInformationProvider.scriptedItem(server.MapleItemInformationProvider.scriptedItem) Item(client.inventory.Item) MapleItemInformationProvider.scriptedItem(server.MapleItemInformationProvider.scriptedItem) ItemScriptManager(scripting.item.ItemScriptManager) MapleItemInformationProvider(server.MapleItemInformationProvider)

Aggregations

ItemScriptManager (scripting.item.ItemScriptManager)2 Item (client.inventory.Item)1 Point (java.awt.Point)1 MaplePartyCharacter (net.server.world.MaplePartyCharacter)1 MapleItemInformationProvider (server.MapleItemInformationProvider)1 MapleItemInformationProvider.scriptedItem (server.MapleItemInformationProvider.scriptedItem)1 MapleMapItem (server.maps.MapleMapItem)1