Search in sources :

Example 1 with MapleItemInformationProvider

use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.

the class ItemRewardHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    byte slot = (byte) slea.readShort();
    // will load from xml I don't care.
    int itemId = slea.readInt();
    if (c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot).getItemId() != itemId || c.getPlayer().getInventory(MapleInventoryType.USE).countById(itemId) < 1)
        return;
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Pair<Integer, List<RewardItem>> rewards = ii.getItemReward(itemId);
    for (RewardItem reward : rewards.getRight()) {
        if (!MapleInventoryManipulator.checkSpace(c, reward.itemid, reward.quantity, "")) {
            c.announce(MaplePacketCreator.getShowInventoryFull());
            break;
        }
        if (Randomizer.nextInt(rewards.getLeft()) < reward.prob) {
            // Is it even possible to get an item with prob 1?
            if (ItemConstants.getInventoryType(reward.itemid) == MapleInventoryType.EQUIP) {
                final Item item = ii.getEquipById(reward.itemid);
                if (reward.period != -1) {
                    item.setExpiration(System.currentTimeMillis() + (reward.period * 60 * 60 * 10));
                }
                MapleInventoryManipulator.addFromDrop(c, item, false);
            } else {
                MapleInventoryManipulator.addById(c, reward.itemid, reward.quantity);
            }
            MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, false, false);
            if (reward.worldmsg != null) {
                String msg = reward.worldmsg;
                msg.replaceAll("/name", c.getPlayer().getName());
                msg.replaceAll("/item", ii.getName(reward.itemid));
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, msg));
            }
            break;
        }
    }
    c.announce(MaplePacketCreator.enableActions());
}
Also used : RewardItem(server.MapleItemInformationProvider.RewardItem) Item(client.inventory.Item) MapleItemInformationProvider(server.MapleItemInformationProvider) RewardItem(server.MapleItemInformationProvider.RewardItem) List(java.util.List)

Example 2 with MapleItemInformationProvider

use of server.MapleItemInformationProvider in project HeavenMS by ronancpl.

the class MTSHandler method getMTSSearch.

public byte[] getMTSSearch(int tab, int type, int cOi, String search, int page) {
    List<MTSItemInfo> items = new ArrayList<>();
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    String listaitems = "";
    if (cOi != 0) {
        List<String> retItems = new ArrayList<>();
        for (Pair<Integer, String> itemPair : ii.getAllItems()) {
            if (itemPair.getRight().toLowerCase().contains(search.toLowerCase())) {
                retItems.add(" itemid=" + itemPair.getLeft() + " OR ");
            }
        }
        listaitems += " AND (";
        if (retItems != null && retItems.size() > 0) {
            for (String singleRetItem : retItems) {
                listaitems += singleRetItem;
            }
            listaitems += " itemid=0 )";
        }
    } else {
        listaitems = " AND sellername LIKE CONCAT('%','" + search + "', '%')";
    }
    Connection con = null;
    PreparedStatement ps;
    ResultSet rs;
    int pages = 0;
    try {
        con = DatabaseConnection.getConnection();
        if (type != 0) {
            ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? " + listaitems + " AND type = ? AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
        } else {
            ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = ? " + listaitems + " AND transfer = 0 ORDER BY id DESC LIMIT ?, 16");
        }
        ps.setInt(1, tab);
        if (type != 0) {
            ps.setInt(2, type);
            ps.setInt(3, page * 16);
        } else {
            ps.setInt(2, page * 16);
        }
        rs = ps.executeQuery();
        while (rs.next()) {
            if (rs.getInt("type") != 1) {
                Item i = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
                i.setOwner(rs.getString("owner"));
                items.add(new MTSItemInfo((Item) i, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            } else {
                Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
                equip.setOwner(rs.getString("owner"));
                equip.setQuantity((short) 1);
                equip.setAcc((short) rs.getInt("acc"));
                equip.setAvoid((short) rs.getInt("avoid"));
                equip.setDex((short) rs.getInt("dex"));
                equip.setHands((short) rs.getInt("hands"));
                equip.setHp((short) rs.getInt("hp"));
                equip.setInt((short) rs.getInt("int"));
                equip.setJump((short) rs.getInt("jump"));
                equip.setVicious((short) rs.getInt("vicious"));
                equip.setLuk((short) rs.getInt("luk"));
                equip.setMatk((short) rs.getInt("matk"));
                equip.setMdef((short) rs.getInt("mdef"));
                equip.setMp((short) rs.getInt("mp"));
                equip.setSpeed((short) rs.getInt("speed"));
                equip.setStr((short) rs.getInt("str"));
                equip.setWatk((short) rs.getInt("watk"));
                equip.setWdef((short) rs.getInt("wdef"));
                equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
                equip.setLevel((byte) rs.getInt("level"));
                equip.setFlag((byte) rs.getInt("flag"));
                items.add(new MTSItemInfo((Item) equip, rs.getInt("price"), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            }
        }
        rs.close();
        ps.close();
        if (type == 0) {
            ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE tab = ? " + listaitems + " AND transfer = 0");
            ps.setInt(1, tab);
            if (type != 0) {
                ps.setInt(2, type);
            }
            rs = ps.executeQuery();
            if (rs.next()) {
                pages = rs.getInt(1) / 16;
                if (rs.getInt(1) % 16 > 0) {
                    pages++;
                }
            }
            rs.close();
            ps.close();
        }
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return MaplePacketCreator.sendMTS(items, tab, type, page, pages);
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Item(client.inventory.Item) Equip(client.inventory.Equip) MapleItemInformationProvider(server.MapleItemInformationProvider) ResultSet(java.sql.ResultSet) MTSItemInfo(server.MTSItemInfo)

Example 3 with MapleItemInformationProvider

use of server.MapleItemInformationProvider 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 4 with MapleItemInformationProvider

use of server.MapleItemInformationProvider 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 5 with MapleItemInformationProvider

use of server.MapleItemInformationProvider 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

MapleItemInformationProvider (server.MapleItemInformationProvider)26 Item (client.inventory.Item)18 Equip (client.inventory.Equip)10 MapleCharacter (client.MapleCharacter)9 Point (java.awt.Point)9 MapleInventoryType (client.inventory.MapleInventoryType)5 ArrayList (java.util.ArrayList)5 SpawnPoint (server.life.SpawnPoint)5 SQLException (java.sql.SQLException)4 MapleMap (server.maps.MapleMap)4 Skill (client.Skill)3 MapleInventory (client.inventory.MapleInventory)3 MaplePet (client.inventory.MaplePet)3 MapleMonster (server.life.MapleMonster)3 MapleMapItem (server.maps.MapleMapItem)3 MapleMapObject (server.maps.MapleMapObject)3 ScrollResult (client.inventory.Equip.ScrollResult)2 ModifyInventory (client.inventory.ModifyInventory)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2