Search in sources :

Example 21 with Item

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

the class InventoryMergeHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    chr.getAutobanManager().setTimestamp(2, slea.readInt(), 3);
    MapleInventoryType inventoryType = MapleInventoryType.getByType(slea.readByte());
    if (!ServerConstants.USE_ITEM_SORT) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    MapleInventory inventory = c.getPlayer().getInventory(inventoryType);
    // ------------------- RonanLana's SLOT MERGER -----------------
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item srcItem, dstItem;
    for (short dst = 1; dst <= inventory.getSlotLimit(); dst++) {
        dstItem = inventory.getItem(dst);
        if (dstItem == null)
            continue;
        for (short src = (short) (dst + 1); src <= inventory.getSlotLimit(); src++) {
            srcItem = inventory.getItem(src);
            if (srcItem == null)
                continue;
            if (dstItem.getItemId() != srcItem.getItemId())
                continue;
            if (dstItem.getQuantity() == ii.getSlotMax(c, inventory.getItem(dst).getItemId()))
                break;
            MapleInventoryManipulator.move(c, inventoryType, src, dst);
        }
    }
    // ------------------------------------------------------------
    inventory = c.getPlayer().getInventory(inventoryType);
    boolean sorted = false;
    while (!sorted) {
        short freeSlot = inventory.getNextFreeSlot();
        if (freeSlot != -1) {
            short itemSlot = -1;
            for (short i = (short) (freeSlot + 1); i <= inventory.getSlotLimit(); i = (short) (i + 1)) {
                if (inventory.getItem(i) != null) {
                    itemSlot = i;
                    break;
                }
            }
            if (itemSlot > 0) {
                MapleInventoryManipulator.move(c, inventoryType, itemSlot, freeSlot);
            } else {
                sorted = true;
            }
        } else {
            sorted = true;
        }
    }
    c.announce(MaplePacketCreator.finishedSort(inventoryType.getType()));
    c.announce(MaplePacketCreator.enableActions());
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) MapleInventoryType(client.inventory.MapleInventoryType) MapleItemInformationProvider(server.MapleItemInformationProvider) MapleInventory(client.inventory.MapleInventory)

Example 22 with Item

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

the class InventorySortHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    chr.getAutobanManager().setTimestamp(3, slea.readInt(), 3);
    byte inventoryType = slea.readByte();
    if (!ServerConstants.USE_ITEM_SORT) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (inventoryType < 1 || inventoryType > 5) {
        c.disconnect(false, false);
        return;
    }
    MapleInventory inventory = chr.getInventory(MapleInventoryType.getByType(inventoryType));
    ArrayList<Item> itemarray = new ArrayList<>();
    List<ModifyInventory> mods = new ArrayList<>();
    for (short i = 1; i <= inventory.getSlotLimit(); i++) {
        Item item = inventory.getItem(i);
        if (item != null) {
            itemarray.add((Item) item.copy());
        }
    }
    for (Item item : itemarray) {
        inventory.removeSlot(item.getPosition());
        mods.add(new ModifyInventory(3, item));
    }
    int invTypeCriteria = (MapleInventoryType.getByType(inventoryType) == MapleInventoryType.EQUIP) ? 3 : 1;
    int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
    PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
    for (Item item : itemarray) {
        inventory.addItem(item);
        // to prevent crashes
        mods.add(new ModifyInventory(0, item.copy()));
    }
    itemarray.clear();
    c.announce(MaplePacketCreator.modifyInventory(true, mods));
    c.announce(MaplePacketCreator.finishedSort2(inventoryType));
    c.announce(MaplePacketCreator.enableActions());
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) ArrayList(java.util.ArrayList) MapleInventory(client.inventory.MapleInventory) ModifyInventory(client.inventory.ModifyInventory)

Example 23 with Item

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

Example 24 with Item

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

the class SkillBookHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!c.getPlayer().isAlive()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    slea.readInt();
    short slot = (short) slea.readShort();
    int itemId = slea.readInt();
    MapleCharacter player = c.getPlayer();
    Item toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
    if (toUse != null && toUse.getQuantity() == 1) {
        if (toUse.getItemId() != itemId) {
            return;
        }
        Map<String, Integer> skilldata = MapleItemInformationProvider.getInstance().getSkillStats(toUse.getItemId(), c.getPlayer().getJob().getId());
        boolean canuse;
        boolean success = false;
        int skill = 0;
        int maxlevel = 0;
        if (skilldata == null) {
            return;
        }
        Skill skill2 = SkillFactory.getSkill(skilldata.get("skillid"));
        if (skilldata.get("skillid") == 0) {
            canuse = false;
        } else if ((player.getSkillLevel(skill2) >= skilldata.get("reqSkillLevel") || skilldata.get("reqSkillLevel") == 0) && player.getMasterLevel(skill2) < skilldata.get("masterLevel")) {
            canuse = true;
            if (MapleItemInformationProvider.rollSuccessChance(skilldata.get("success"))) {
                success = true;
                player.changeSkillLevel(skill2, player.getSkillLevel(skill2), Math.max(skilldata.get("masterLevel"), player.getMasterLevel(skill2)), -1);
            } else {
                success = false;
            // player.dropMessage("The skill book lights up, but the skill winds up as if nothing happened.");
            }
            MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
        } else {
            canuse = false;
        }
        player.getClient().announce(MaplePacketCreator.skillBookSuccess(player, skill, maxlevel, canuse, success));
    }
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) Skill(client.Skill)

Example 25 with Item

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

the class UseItemHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!c.getPlayer().isAlive()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    slea.readInt();
    short slot = slea.readShort();
    int itemId = slea.readInt();
    Item toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
    if (toUse != null && toUse.getQuantity() > 0 && toUse.getItemId() == itemId) {
        if (itemId == 2022178 || itemId == 2050004) {
            c.getPlayer().dispelDebuffs();
            remove(c, slot);
            return;
        } else if (itemId == 2050001) {
            c.getPlayer().dispelDebuff(MapleDisease.DARKNESS);
            remove(c, slot);
            return;
        } else if (itemId == 2050002) {
            c.getPlayer().dispelDebuff(MapleDisease.WEAKEN);
            c.getPlayer().dispelDebuff(MapleDisease.SLOW);
            remove(c, slot);
            return;
        } else if (itemId == 2050003) {
            c.getPlayer().dispelDebuff(MapleDisease.SEAL);
            c.getPlayer().dispelDebuff(MapleDisease.CURSE);
            remove(c, slot);
            return;
        } else if (ItemConstants.isTownScroll(itemId)) {
            if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
                remove(c, slot);
            }
            return;
        } else if (ItemConstants.isAntibanishScroll(itemId)) {
            if (ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer())) {
                remove(c, slot);
            } else {
                c.getPlayer().dropMessage(5, "You cannot recover from a banish state at the moment.");
            }
            return;
        }
        remove(c, slot);
        ii.getItemEffect(toUse.getItemId()).applyTo(c.getPlayer());
        c.getPlayer().checkBerserk(c.getPlayer().isHidden());
    }
}
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