Search in sources :

Example 16 with Equip

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

the class MaplePacketCreator method addCashItemInformation.

public static void addCashItemInformation(final MaplePacketLittleEndianWriter mplew, Item item, int accountId, String giftMessage) {
    boolean isGift = giftMessage != null;
    boolean isRing = false;
    Equip equip = null;
    if (item.getInventoryType().equals(MapleInventoryType.EQUIP)) {
        equip = (Equip) item;
        isRing = equip.getRingId() > -1;
    }
    mplew.writeLong(item.getPetId() > -1 ? item.getPetId() : isRing ? equip.getRingId() : item.getCashId());
    if (!isGift) {
        mplew.writeInt(accountId);
        mplew.writeInt(0);
    }
    mplew.writeInt(item.getItemId());
    if (!isGift) {
        mplew.writeInt(item.getSN());
        mplew.writeShort(item.getQuantity());
    }
    mplew.writeAsciiString(StringUtil.getRightPaddedStr(item.getGiftFrom(), '\0', 13));
    if (isGift) {
        mplew.writeAsciiString(StringUtil.getRightPaddedStr(giftMessage, '\0', 73));
        return;
    }
    addExpirationTime(mplew, item.getExpiration());
    mplew.writeLong(0);
}
Also used : Equip(client.inventory.Equip)

Example 17 with Equip

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

the class MaplePacketCreator method addItemInfo.

private static void addItemInfo(final MaplePacketLittleEndianWriter mplew, Item item, boolean zeroPosition) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    boolean isCash = ii.isCash(item.getItemId());
    boolean isPet = item.getPetId() > -1;
    boolean isRing = false;
    Equip equip = null;
    short pos = item.getPosition();
    byte itemType = item.getItemType();
    if (itemType == 1) {
        equip = (Equip) item;
        isRing = equip.getRingId() > -1;
    }
    if (!zeroPosition) {
        if (equip != null) {
            if (pos < 0) {
                pos *= -1;
            }
            mplew.writeShort(pos > 100 ? pos - 100 : pos);
        } else {
            mplew.write(pos);
        }
    }
    mplew.write(itemType);
    mplew.writeInt(item.getItemId());
    mplew.writeBool(isCash);
    if (isCash) {
        mplew.writeLong(isPet ? item.getPetId() : isRing ? equip.getRingId() : item.getCashId());
    }
    addExpirationTime(mplew, item.getExpiration());
    if (isPet) {
        MaplePet pet = item.getPet();
        mplew.writeAsciiString(StringUtil.getRightPaddedStr(pet.getName(), '\0', 13));
        mplew.write(pet.getLevel());
        mplew.writeShort(pet.getCloseness());
        mplew.write(pet.getFullness());
        addExpirationTime(mplew, item.getExpiration());
        mplew.writeInt(0);
        // wonder what this is
        mplew.write(new byte[] { (byte) 0x50, (byte) 0x46 });
        mplew.writeInt(0);
        return;
    }
    if (equip == null) {
        mplew.writeShort(item.getQuantity());
        mplew.writeMapleAsciiString(item.getOwner());
        // flag
        mplew.writeShort(item.getFlag());
        if (ItemConstants.isRechargable(item.getItemId())) {
            mplew.writeInt(2);
            mplew.write(new byte[] { (byte) 0x54, 0, 0, (byte) 0x34 });
        }
        return;
    }
    // upgrade slots
    mplew.write(equip.getUpgradeSlots());
    // level
    mplew.write(equip.getLevel());
    // str
    mplew.writeShort(equip.getStr());
    // dex
    mplew.writeShort(equip.getDex());
    // int
    mplew.writeShort(equip.getInt());
    // luk
    mplew.writeShort(equip.getLuk());
    // hp
    mplew.writeShort(equip.getHp());
    // mp
    mplew.writeShort(equip.getMp());
    // watk
    mplew.writeShort(equip.getWatk());
    // matk
    mplew.writeShort(equip.getMatk());
    // wdef
    mplew.writeShort(equip.getWdef());
    // mdef
    mplew.writeShort(equip.getMdef());
    // accuracy
    mplew.writeShort(equip.getAcc());
    // avoid
    mplew.writeShort(equip.getAvoid());
    // hands
    mplew.writeShort(equip.getHands());
    // speed
    mplew.writeShort(equip.getSpeed());
    // jump
    mplew.writeShort(equip.getJump());
    // owner name
    mplew.writeMapleAsciiString(equip.getOwner());
    // Item Flags
    mplew.writeShort(equip.getFlag());
    if (isCash) {
        for (int i = 0; i < 10; i++) {
            mplew.write(0x40);
        }
    } else {
        mplew.write(0);
        // Item Level
        mplew.write(equip.getItemLevel());
        mplew.writeShort(0);
        // Works pretty weird :s
        mplew.writeShort(equip.getItemExp());
        // WTF NEXON ARE YOU SERIOUS?
        mplew.writeInt(equip.getVicious());
        mplew.writeLong(0);
    }
    mplew.writeLong(getTime(-2));
    mplew.writeInt(-1);
}
Also used : Equip(client.inventory.Equip) MapleItemInformationProvider(server.MapleItemInformationProvider) MaplePet(client.inventory.MaplePet) Point(java.awt.Point)

Example 18 with Equip

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

the class CashShop method loadGifts.

public List<Pair<Item, String>> loadGifts() {
    List<Pair<Item, String>> gifts = new ArrayList<>();
    Connection con = null;
    try {
        con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM `gifts` WHERE `to` = ?");
        ps.setInt(1, characterId);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            notes++;
            CashItem cItem = CashItemFactory.getItem(rs.getInt("sn"));
            Item item = cItem.toItem();
            Equip equip = null;
            item.setGiftFrom(rs.getString("from"));
            if (item.getInventoryType().equals(MapleInventoryType.EQUIP)) {
                equip = (Equip) item;
                equip.setRingId(rs.getInt("ringid"));
                gifts.add(new Pair<Item, String>(equip, rs.getString("message")));
            } else
                gifts.add(new Pair<>(item, rs.getString("message")));
            if (CashItemFactory.isPackage(cItem.getItemId())) {
                // Packages never contains a ring
                for (Item packageItem : CashItemFactory.getPackage(cItem.getItemId())) {
                    packageItem.setGiftFrom(rs.getString("from"));
                    addToInventory(packageItem);
                }
            } else {
                addToInventory(equip == null ? item : equip);
            }
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("DELETE FROM `gifts` WHERE `to` = ?");
        ps.setInt(1, characterId);
        ps.executeUpdate();
        ps.close();
        con.close();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    }
    return gifts;
}
Also used : Item(client.inventory.Item) Equip(client.inventory.Equip) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Pair(tools.Pair)

Example 19 with Equip

use of client.inventory.Equip 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 20 with Equip

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

the class MapleItemInformationProvider method getEquipById.

Item getEquipById(int equipId, int ringId) {
    Equip nEquip;
    nEquip = new Equip(equipId, (byte) 0, ringId);
    nEquip.setQuantity((short) 1);
    Map<String, Integer> stats = this.getEquipStats(equipId);
    if (stats != null) {
        for (Entry<String, Integer> stat : stats.entrySet()) {
            if (stat.getKey().equals("STR")) {
                nEquip.setStr((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("DEX")) {
                nEquip.setDex((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("INT")) {
                nEquip.setInt((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("LUK")) {
                nEquip.setLuk((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("PAD")) {
                nEquip.setWatk((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("PDD")) {
                nEquip.setWdef((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("MAD")) {
                nEquip.setMatk((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("MDD")) {
                nEquip.setMdef((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("ACC")) {
                nEquip.setAcc((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("EVA")) {
                nEquip.setAvoid((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("Speed")) {
                nEquip.setSpeed((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("Jump")) {
                nEquip.setJump((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("MHP")) {
                nEquip.setHp((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("MMP")) {
                nEquip.setMp((short) stat.getValue().intValue());
            } else if (stat.getKey().equals("tuc")) {
                nEquip.setUpgradeSlots((byte) stat.getValue().intValue());
            } else if (isDropRestricted(equipId)) {
                byte flag = nEquip.getFlag();
                flag |= ItemConstants.UNTRADEABLE;
                nEquip.setFlag(flag);
            } else if (stats.get("fs") > 0) {
                byte flag = nEquip.getFlag();
                flag |= ItemConstants.SPIKES;
                nEquip.setFlag(flag);
                equipCache.put(equipId, nEquip);
            }
        }
    }
    return nEquip.copy();
}
Also used : Equip(client.inventory.Equip)

Aggregations

Equip (client.inventory.Equip)39 Item (client.inventory.Item)31 SQLException (java.sql.SQLException)16 ArrayList (java.util.ArrayList)13 Connection (java.sql.Connection)12 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)12 DatabaseConnection (tools.DatabaseConnection)12 MapleItemInformationProvider (server.MapleItemInformationProvider)10 Point (java.awt.Point)8 MTSItemInfo (server.MTSItemInfo)8 MapleCharacter (client.MapleCharacter)6 MapleInventory (client.inventory.MapleInventory)6 MapleMapItem (server.maps.MapleMapItem)5 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)5 MapleInventoryType (client.inventory.MapleInventoryType)4 MaplePet (client.inventory.MaplePet)4 ModifyInventory (client.inventory.ModifyInventory)4 LinkedList (java.util.LinkedList)3 Pair (tools.Pair)3