Search in sources :

Example 31 with Equip

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

the class AutoAssignHandler method handlePacket.

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    int[] statGain = new int[4];
    int[] statEqpd = new int[4];
    statGain[0] = 0;
    statGain[1] = 0;
    statGain[2] = 0;
    statGain[3] = 0;
    slea.skip(8);
    // useful for pirate autoassigning
    byte opt = slea.readByte();
    if (chr.getRemainingAp() < 1)
        return;
    if (ServerConstants.USE_SERVER_AUTOASSIGNER) {
        // --------- Ronan Lana's AUTOASSIGNER ---------
        // This method excels for assigning APs in such a way to cover all equipments AP requirements.
        int str = 0, dex = 0, luk = 0, int_ = 0;
        List<Short> eqpStrList = new ArrayList<>();
        List<Short> eqpDexList = new ArrayList<>();
        List<Short> eqpLukList = new ArrayList<>();
        MapleInventory iv = chr.getInventory(MapleInventoryType.EQUIPPED);
        Collection<Item> equippedC = iv.list();
        Equip nEquip;
        for (Item item : equippedC) {
            // selecting the biggest AP value of each stat from each equipped item.
            nEquip = (Equip) item;
            if (nEquip.getStr() > 0)
                eqpStrList.add(nEquip.getStr());
            str += nEquip.getStr();
            if (nEquip.getDex() > 0)
                eqpDexList.add(nEquip.getDex());
            dex += nEquip.getDex();
            if (nEquip.getLuk() > 0)
                eqpLukList.add(nEquip.getLuk());
            luk += nEquip.getLuk();
            // if(nEquip.getInt() > 0) eqpIntList.add(nEquip.getInt()); //not needed...
            int_ += nEquip.getInt();
        }
        statEqpd[0] = str;
        statEqpd[1] = dex;
        statEqpd[2] = luk;
        statEqpd[3] = int_;
        Collections.sort(eqpStrList, Collections.reverseOrder());
        Collections.sort(eqpDexList, Collections.reverseOrder());
        Collections.sort(eqpLukList, Collections.reverseOrder());
        // Autoassigner looks up the 1st/2nd placed equips for their stats to calculate the optimal upgrade.
        int eqpStr = getNthHighestStat(eqpStrList, (short) 0) + getNthHighestStat(eqpStrList, (short) 1);
        int eqpDex = getNthHighestStat(eqpDexList, (short) 0) + getNthHighestStat(eqpDexList, (short) 1);
        int eqpLuk = getNthHighestStat(eqpLukList, (short) 0) + getNthHighestStat(eqpLukList, (short) 1);
        // c.getPlayer().message("----------------------------------------");
        // c.getPlayer().message("SDL: s" + eqpStr + " d" + eqpDex + " l" + eqpLuk + " BASE STATS --> STR: " + chr.getStr() + " DEX: " + chr.getDex() + " INT: " + chr.getInt() + " LUK: " + chr.getLuk());
        // c.getPlayer().message("SUM EQUIP STATS -> STR: " + str + " DEX: " + dex + " LUK: " + luk + " INT: " + int_);
        MapleJob stance = c.getPlayer().getJobStyle(opt);
        int prStat = 0, scStat = 0, trStat = 0, temp, tempAp = chr.getRemainingAp(), CAP;
        MapleStat primary, secondary, tertiary = MapleStat.LUK;
        switch(stance) {
            case MAGICIAN:
                CAP = 165;
                scStat = (chr.getLevel() + 3) - (chr.getLuk() + luk - eqpLuk);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                int_ = prStat;
                luk = scStat;
                str = 0;
                dex = 0;
                if (luk + chr.getLuk() > CAP) {
                    temp = luk + chr.getLuk() - CAP;
                    luk -= temp;
                    int_ += temp;
                }
                primary = MapleStat.INT;
                secondary = MapleStat.LUK;
                tertiary = MapleStat.DEX;
                break;
            case BOWMAN:
                CAP = 125;
                scStat = (chr.getLevel() + 5) - (chr.getStr() + str - eqpStr);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                dex = prStat;
                str = scStat;
                int_ = 0;
                luk = 0;
                if (str + chr.getStr() > CAP) {
                    temp = str + chr.getStr() - CAP;
                    str -= temp;
                    dex += temp;
                }
                primary = MapleStat.DEX;
                secondary = MapleStat.STR;
                break;
            case GUNSLINGER:
            case CROSSBOWMAN:
                CAP = 120;
                scStat = chr.getLevel() - (chr.getStr() + str - eqpStr);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                dex = prStat;
                str = scStat;
                int_ = 0;
                luk = 0;
                if (str + chr.getStr() > CAP) {
                    temp = str + chr.getStr() - CAP;
                    str -= temp;
                    dex += temp;
                }
                primary = MapleStat.DEX;
                secondary = MapleStat.STR;
                break;
            case THIEF:
                CAP = 160;
                scStat = 0;
                if (chr.getDex() < 80) {
                    scStat = (2 * chr.getLevel()) - (chr.getDex() + dex - eqpDex);
                    if (scStat < 0)
                        scStat = 0;
                    scStat = Math.min(80 - chr.getDex(), scStat);
                    scStat = Math.min(tempAp, scStat);
                    tempAp -= scStat;
                }
                temp = (chr.getLevel() + 40) - Math.max(80, scStat + chr.getDex() + dex - eqpDex);
                if (temp < 0)
                    temp = 0;
                temp = Math.min(tempAp, temp);
                scStat += temp;
                tempAp -= temp;
                // thieves will upgrade STR as well only if a level-based threshold is reached.
                if (chr.getStr() >= Math.max(13, (int) (0.4 * chr.getLevel()))) {
                    if (chr.getStr() < 50) {
                        trStat = (chr.getLevel() - 10) - (chr.getStr() + str - eqpStr);
                        if (trStat < 0)
                            trStat = 0;
                        trStat = Math.min(50 - chr.getStr(), trStat);
                        trStat = Math.min(tempAp, trStat);
                        tempAp -= trStat;
                    }
                    temp = (20 + (chr.getLevel() / 2)) - Math.max(50, trStat + chr.getStr() + str - eqpStr);
                    if (temp < 0)
                        temp = 0;
                    temp = Math.min(tempAp, temp);
                    trStat += temp;
                    tempAp -= temp;
                }
                prStat = tempAp;
                luk = prStat;
                dex = scStat;
                str = trStat;
                int_ = 0;
                if (dex + chr.getDex() > CAP) {
                    temp = dex + chr.getDex() - CAP;
                    dex -= temp;
                    luk += temp;
                }
                if (str + chr.getStr() > CAP) {
                    temp = str + chr.getStr() - CAP;
                    str -= temp;
                    luk += temp;
                }
                primary = MapleStat.LUK;
                secondary = MapleStat.DEX;
                tertiary = MapleStat.STR;
                break;
            case BRAWLER:
                CAP = 120;
                scStat = chr.getLevel() - (chr.getDex() + dex - eqpDex);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                str = prStat;
                dex = scStat;
                int_ = 0;
                luk = 0;
                if (dex + chr.getDex() > CAP) {
                    temp = dex + chr.getDex() - CAP;
                    dex -= temp;
                    str += temp;
                }
                primary = MapleStat.STR;
                secondary = MapleStat.DEX;
                break;
            default:
                // warrior, beginner, ...
                CAP = 80;
                scStat = ((2 * chr.getLevel()) / 3) - (chr.getDex() + dex - eqpDex);
                if (scStat < 0)
                    scStat = 0;
                scStat = Math.min(scStat, tempAp);
                if (tempAp > scStat)
                    tempAp -= scStat;
                else
                    tempAp = 0;
                prStat = tempAp;
                str = prStat;
                dex = scStat;
                int_ = 0;
                luk = 0;
                if (dex + chr.getDex() > CAP) {
                    temp = dex + chr.getDex() - CAP;
                    dex -= temp;
                    str += temp;
                }
                primary = MapleStat.STR;
                secondary = MapleStat.DEX;
        }
        // -------------------------------------------------------------------------------------
        int extras = 0;
        extras = gainStatByType(chr, primary, statGain, prStat + extras);
        extras = gainStatByType(chr, secondary, statGain, scStat + extras);
        extras = gainStatByType(chr, tertiary, statGain, trStat + extras);
        if (extras > 0) {
            // redistribute surplus in priority order
            extras = gainStatByType(chr, primary, statGain, extras);
            extras = gainStatByType(chr, secondary, statGain, extras);
            extras = gainStatByType(chr, tertiary, statGain, extras);
            gainStatByType(chr, getQuaternaryStat(stance), statGain, extras);
        }
        int remainingAp = (chr.getRemainingAp() - getAccumulatedStatGain(statGain));
        chr.setRemainingAp(remainingAp);
        chr.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
        c.announce(MaplePacketCreator.enableActions());
        // ----------------------------------------------------------------------------------------
        c.announce(MaplePacketCreator.serverNotice(1, "Better AP applications detected:\r\nSTR: +" + statGain[0] + "\r\nDEX: +" + statGain[1] + "\r\nINT: +" + statGain[3] + "\r\nLUK: +" + statGain[2]));
    } else {
        int total = 0;
        int extras = 0;
        if (slea.available() < 16) {
            AutobanFactory.PACKET_EDIT.alert(chr, "Didn't send full packet for Auto Assign.");
            c.disconnect(false, false);
            return;
        }
        MapleInventory iv = chr.getInventory(MapleInventoryType.EQUIPPED);
        Collection<Item> equippedC = iv.list();
        for (Item item : equippedC) {
            // selecting the biggest AP value of each stat from each equipped item.
            Equip nEquip = (Equip) item;
            statEqpd[0] += nEquip.getStr();
            statEqpd[1] += nEquip.getDex();
            statEqpd[2] += nEquip.getLuk();
            statEqpd[3] += nEquip.getInt();
        }
        for (int i = 0; i < 2; i++) {
            int type = slea.readInt();
            int tempVal = slea.readInt();
            if (tempVal < 0 || tempVal > c.getPlayer().getRemainingAp()) {
                return;
            }
            total += tempVal;
            extras += gainStatByType(chr, MapleStat.getBy5ByteEncoding(type), statGain, tempVal);
        }
        int remainingAp = (chr.getRemainingAp() - total) + extras;
        chr.setRemainingAp(remainingAp);
        chr.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
        c.announce(MaplePacketCreator.enableActions());
    }
}
Also used : MapleCharacter(client.MapleCharacter) ArrayList(java.util.ArrayList) MapleStat(client.MapleStat) MapleInventory(client.inventory.MapleInventory) Item(client.inventory.Item) Equip(client.inventory.Equip) MapleJob(client.MapleJob)

Example 32 with Equip

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

the class CashOperationHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    CashShop cs = chr.getCashShop();
    if (!cs.isOpened()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    final int action = slea.readByte();
    if (action == 0x03 || action == 0x1E) {
        slea.readByte();
        final int useNX = slea.readInt();
        final int snCS = slea.readInt();
        CashItem cItem = CashItemFactory.getItem(snCS);
        if (cItem == null || !cItem.isOnSale() || cs.getCash(useNX) < cItem.getPrice()) {
            FilePrinter.printError(FilePrinter.ITEM, "Denied to sell cash item with SN " + cItem.getSN());
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (action == 0x03) {
            // Item
            Item item = cItem.toItem();
            cs.addToInventory(item);
            c.announce(MaplePacketCreator.showBoughtCashItem(item, c.getAccID()));
        } else {
            // Package
            List<Item> cashPackage = CashItemFactory.getPackage(cItem.getItemId());
            for (Item item : cashPackage) {
                cs.addToInventory(item);
            }
            c.announce(MaplePacketCreator.showBoughtCashPackage(cashPackage, c.getAccID()));
        }
        cs.gainCash(useNX, -cItem.getPrice());
        c.announce(MaplePacketCreator.showCash(chr));
    } else if (action == 0x04) {
        // TODO check for gender
        int birthday = slea.readInt();
        CashItem cItem = CashItemFactory.getItem(slea.readInt());
        Map<String, String> recipient = MapleCharacter.getCharacterFromDatabase(slea.readMapleAsciiString());
        String message = slea.readMapleAsciiString();
        if (!canBuy(cItem, cs.getCash(4)) || message.length() < 1 || message.length() > 73) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (!checkBirthday(c, birthday)) {
            c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xC4));
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (recipient == null) {
            c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA9));
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (recipient.get("accountid").equals(String.valueOf(c.getAccID()))) {
            c.announce(MaplePacketCreator.showCashShopMessage((byte) 0xA8));
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        cs.gift(Integer.parseInt(recipient.get("id")), chr.getName(), message, cItem.getSN());
        c.announce(MaplePacketCreator.showGiftSucceed(recipient.get("name"), cItem));
        cs.gainCash(4, -cItem.getPrice());
        c.announce(MaplePacketCreator.showCash(chr));
        try {
            // fame or not
            chr.sendNote(recipient.get("name"), chr.getName() + " has sent you a gift! Go check out the Cash Shop.", (byte) 0);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        MapleCharacter receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient.get("name"));
        if (receiver != null)
            receiver.showNote();
    } else if (action == 0x05) {
        // Modify wish list
        cs.clearWishList();
        for (byte i = 0; i < 10; i++) {
            int sn = slea.readInt();
            CashItem cItem = CashItemFactory.getItem(sn);
            if (cItem != null && cItem.isOnSale() && sn != 0) {
                cs.addToWishList(sn);
            }
        }
        c.announce(MaplePacketCreator.showWishList(chr, true));
    } else if (action == 0x06) {
        // Increase Inventory Slots
        slea.skip(1);
        int cash = slea.readInt();
        byte mode = slea.readByte();
        if (mode == 0) {
            byte type = slea.readByte();
            if (cs.getCash(cash) < 4000) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.gainSlots(type, 4, false)) {
                c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
                cs.gainCash(cash, -4000);
                c.announce(MaplePacketCreator.showCash(chr));
            }
        } else {
            CashItem cItem = CashItemFactory.getItem(slea.readInt());
            int type = (cItem.getItemId() - 9110000) / 1000;
            if (!canBuy(cItem, cs.getCash(cash))) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.gainSlots(type, 8, false)) {
                c.announce(MaplePacketCreator.showBoughtInventorySlots(type, chr.getSlots(type)));
                cs.gainCash(cash, -cItem.getPrice());
                c.announce(MaplePacketCreator.showCash(chr));
            }
        }
    } else if (action == 0x07) {
        // Increase Storage Slots
        slea.skip(1);
        int cash = slea.readInt();
        byte mode = slea.readByte();
        if (mode == 0) {
            if (cs.getCash(cash) < 4000) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.getStorage().gainSlots(4)) {
                c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
                cs.gainCash(cash, -4000);
                c.announce(MaplePacketCreator.showCash(chr));
            }
        } else {
            CashItem cItem = CashItemFactory.getItem(slea.readInt());
            if (!canBuy(cItem, cs.getCash(cash))) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (chr.getStorage().gainSlots(8)) {
                c.announce(MaplePacketCreator.showBoughtStorageSlots(chr.getStorage().getSlots()));
                cs.gainCash(cash, -cItem.getPrice());
                c.announce(MaplePacketCreator.showCash(chr));
            }
        }
    } else if (action == 0x08) {
        // Increase Character Slots
        slea.skip(1);
        int cash = slea.readInt();
        CashItem cItem = CashItemFactory.getItem(slea.readInt());
        if (!canBuy(cItem, cs.getCash(cash))) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (c.gainCharacterSlot()) {
            c.announce(MaplePacketCreator.showBoughtCharacterSlot(c.getCharacterSlots()));
            cs.gainCash(cash, -cItem.getPrice());
            c.announce(MaplePacketCreator.showCash(chr));
        }
    } else if (action == 0x0D) {
        // Take from Cash Inventory
        Item item = cs.findByCashId(slea.readInt());
        if (item == null) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (chr.getInventory(item.getInventoryType()).addItem(item) != -1) {
            cs.removeFromInventory(item);
            c.announce(MaplePacketCreator.takeFromCashInventory(item));
            if (item instanceof Equip) {
                Equip equip = (Equip) item;
                if (equip.getRingId() >= 0) {
                    MapleRing ring = MapleRing.loadFromDb(equip.getRingId());
                    if (ring.getItemId() > 1112012) {
                        chr.addFriendshipRing(ring);
                    } else {
                        chr.addCrushRing(ring);
                    }
                }
            }
        }
    } else if (action == 0x0E) {
        // Put into Cash Inventory
        int cashId = slea.readInt();
        slea.skip(4);
        MapleInventory mi = chr.getInventory(MapleInventoryType.getByType(slea.readByte()));
        Item item = mi.findByCashId(cashId);
        if (item == null) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else if (c.getPlayer().getPetIndex(item.getPetId()) > -1) {
            chr.getClient().announce(MaplePacketCreator.serverNotice(1, "You cannot put the pet you currently equip into the Cash Shop inventory."));
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        cs.addToInventory(item);
        mi.removeSlot(item.getPosition());
        c.announce(MaplePacketCreator.putIntoCashInventory(item, c.getAccID()));
    } else if (action == 0x1D) {
        // crush ring (action 28)
        // Birthday
        slea.readInt();
        // if (checkBirthday(c, birthday)) { //We're using a default birthday, so why restrict rings to only people who know of it?
        int toCharge = slea.readInt();
        int SN = slea.readInt();
        String recipientName = slea.readMapleAsciiString();
        String text = slea.readMapleAsciiString();
        CashItem itemRing = CashItemFactory.getItem(SN);
        MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(recipientName);
        if (partner == null) {
            chr.getClient().announce(MaplePacketCreator.serverNotice(1, "The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel."));
        } else {
            if (itemRing.toItem() instanceof Equip) {
                Equip eqp = (Equip) itemRing.toItem();
                int ringid = MapleRing.createRing(itemRing.getItemId(), chr, partner);
                eqp.setRingId(ringid);
                cs.addToInventory(eqp);
                c.announce(MaplePacketCreator.showBoughtCashItem(eqp, c.getAccID()));
                cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), (ringid + 1));
                cs.gainCash(toCharge, -itemRing.getPrice());
                chr.addCrushRing(MapleRing.loadFromDb(ringid));
                try {
                    chr.sendNote(partner.getName(), text, (byte) 1);
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
                partner.showNote();
            }
        }
        /* } else {
                chr.dropMessage("The birthday you entered was incorrect.");
            }*/
        c.announce(MaplePacketCreator.showCash(c.getPlayer()));
    } else if (action == 0x20) {
        // everything is 1 meso...
        int itemId = CashItemFactory.getItem(slea.readInt()).getItemId();
        if (chr.getMeso() > 0) {
            if (chr.canHold(itemId)) {
                chr.gainMeso(-1, false);
                MapleInventoryManipulator.addById(c, itemId, (short) 1);
                c.announce(MaplePacketCreator.showBoughtQuestItem(itemId));
            }
        }
        c.announce(MaplePacketCreator.showCash(c.getPlayer()));
    } else if (action == 0x23) {
        // Friendship :3
        // Birthday
        slea.readInt();
        // if (checkBirthday(c, birthday)) {
        int payment = slea.readByte();
        // 0s
        slea.skip(3);
        int snID = slea.readInt();
        CashItem itemRing = CashItemFactory.getItem(snID);
        String sentTo = slea.readMapleAsciiString();
        int available = slea.readShort() - 1;
        String text = slea.readAsciiString(available);
        slea.readByte();
        MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(sentTo);
        if (partner == null) {
            chr.dropMessage("The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel.");
        } else {
            // Need to check to make sure its actually an equip and the right SN...
            if (itemRing.toItem() instanceof Equip) {
                Equip eqp = (Equip) itemRing.toItem();
                int ringid = MapleRing.createRing(itemRing.getItemId(), chr, partner);
                eqp.setRingId(ringid);
                cs.addToInventory(eqp);
                c.announce(MaplePacketCreator.showBoughtCashItem(eqp, c.getAccID()));
                cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), (ringid + 1));
                cs.gainCash(payment, -itemRing.getPrice());
                chr.addFriendshipRing(MapleRing.loadFromDb(ringid));
                try {
                    chr.sendNote(partner.getName(), text, (byte) 1);
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
                partner.showNote();
            }
        }
        /* } else {
                chr.dropMessage("The birthday you entered was incorrect.");
            } */
        c.announce(MaplePacketCreator.showCash(c.getPlayer()));
    } else {
        System.out.println(slea);
    }
}
Also used : CashShop(server.CashShop) MapleCharacter(client.MapleCharacter) CashItem(server.CashShop.CashItem) SQLException(java.sql.SQLException) MapleRing(client.MapleRing) MapleInventory(client.inventory.MapleInventory) Item(client.inventory.Item) CashItem(server.CashShop.CashItem) Equip(client.inventory.Equip) Map(java.util.Map)

Example 33 with Equip

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

the class DueyHandler method getItemByPID.

private static DueyPackages getItemByPID(ResultSet rs) {
    try {
        DueyPackages dueypack;
        if (rs.getInt("type") == 1) {
            Equip eq = new Equip(rs.getInt("itemid"), (byte) 0, -1);
            eq.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
            eq.setLevel((byte) rs.getInt("level"));
            eq.setStr((short) rs.getInt("str"));
            eq.setDex((short) rs.getInt("dex"));
            eq.setInt((short) rs.getInt("int"));
            eq.setLuk((short) rs.getInt("luk"));
            eq.setHp((short) rs.getInt("hp"));
            eq.setMp((short) rs.getInt("mp"));
            eq.setWatk((short) rs.getInt("watk"));
            eq.setMatk((short) rs.getInt("matk"));
            eq.setWdef((short) rs.getInt("wdef"));
            eq.setMdef((short) rs.getInt("mdef"));
            eq.setAcc((short) rs.getInt("acc"));
            eq.setAvoid((short) rs.getInt("avoid"));
            eq.setHands((short) rs.getInt("hands"));
            eq.setSpeed((short) rs.getInt("speed"));
            eq.setJump((short) rs.getInt("jump"));
            eq.setOwner(rs.getString("owner"));
            dueypack = new DueyPackages(rs.getInt("PackageId"), eq);
        } else if (rs.getInt("type") == 2) {
            Item newItem = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
            newItem.setOwner(rs.getString("owner"));
            dueypack = new DueyPackages(rs.getInt("PackageId"), newItem);
        } else {
            dueypack = new DueyPackages(rs.getInt("PackageId"));
        }
        return dueypack;
    } catch (SQLException se) {
        se.printStackTrace();
        return null;
    }
}
Also used : DueyPackages(server.DueyPackages) Equip(client.inventory.Equip) Item(client.inventory.Item) SQLException(java.sql.SQLException)

Example 34 with Equip

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

the class EnterMTSHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!ServerConstants.USE_MTS) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (MapleMiniDungeonInfo.isDungeonMap(c.getPlayer().getMapId())) {
        c.announce(MaplePacketCreator.serverNotice(5, "Changing channels or entering Cash Shop or MTS are disabled when inside a Mini-Dungeon."));
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    MapleCharacter chr = c.getPlayer();
    if (!chr.isAlive()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (chr.getLevel() < 10) {
        c.announce(MaplePacketCreator.blockedMessage2(5));
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    chr.unregisterChairBuff();
    Server.getInstance().getPlayerBuffStorage().addBuffsToStorage(chr.getId(), chr.getAllBuffs());
    chr.setAwayFromWorld(true);
    chr.cancelAllBuffs(true);
    chr.cancelBuffExpireTask();
    chr.cancelDiseaseExpireTask();
    chr.cancelSkillCooldownTask();
    chr.cancelExpirationTask();
    chr.forfeitExpirableQuests();
    chr.cancelQuestExpirationTask();
    chr.saveToDB();
    chr.getMap().removePlayer(c.getPlayer());
    try {
        c.announce(MaplePacketCreator.openCashShop(c, true));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // xD
    chr.getCashShop().open(true);
    c.announce(MaplePacketCreator.enableCSUse());
    c.announce(MaplePacketCreator.MTSWantedListingOver(0, 0));
    c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
    List<MTSItemInfo> items = new ArrayList<>();
    int pages = 0;
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM mts_items WHERE tab = 1 AND transfer = 0 ORDER BY id DESC LIMIT 16, 16");
        ResultSet 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(i, rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1), 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.setFlag((byte) rs.getInt("flag"));
                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"));
                items.add(new MTSItemInfo((Item) equip, rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1), rs.getInt("id"), rs.getInt("seller"), rs.getString("sellername"), rs.getString("sell_ends")));
            }
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items");
        rs = ps.executeQuery();
        if (rs.next()) {
            pages = (int) Math.ceil(rs.getInt(1) / 16);
        }
        rs.close();
        ps.close();
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    c.announce(MaplePacketCreator.sendMTS(items, 1, 0, 0, pages));
    c.announce(MaplePacketCreator.transferInventory(getTransfer(chr.getId())));
    c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(chr.getId())));
}
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) MTSItemInfo(server.MTSItemInfo) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 35 with Equip

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

the class UseCashItemHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final MapleCharacter player = c.getPlayer();
    if (System.currentTimeMillis() - player.getLastUsedCashItem() < 3000) {
        player.dropMessage(1, "You have used a cash item recently. Wait a moment, then try again.");
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    player.setLastUsedCashItem(System.currentTimeMillis());
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    slea.readShort();
    int itemId = slea.readInt();
    int itemType = itemId / 10000;
    Item toUse = c.getPlayer().getInventory(MapleInventoryType.CASH).getItem(c.getPlayer().getInventory(MapleInventoryType.CASH).findById(itemId).getPosition());
    String medal = "";
    Item medalItem = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -49);
    if (medalItem != null) {
        medal = "<" + ii.getName(medalItem.getItemId()) + "> ";
    }
    if (toUse == null || toUse.getItemId() != itemId || toUse.getQuantity() < 1) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (itemType == 505) {
        // AP/SP reset
        if (!player.isAlive()) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (itemId > 5050000) {
            int SPTo = slea.readInt();
            int SPFrom = slea.readInt();
            Skill skillSPTo = SkillFactory.getSkill(SPTo);
            Skill skillSPFrom = SkillFactory.getSkill(SPFrom);
            byte curLevel = player.getSkillLevel(skillSPTo);
            byte curLevelSPFrom = player.getSkillLevel(skillSPFrom);
            if ((curLevel < skillSPTo.getMaxLevel()) && curLevelSPFrom > 0) {
                player.changeSkillLevel(skillSPFrom, (byte) (curLevelSPFrom - 1), player.getMasterLevel(skillSPFrom), -1);
                player.changeSkillLevel(skillSPTo, (byte) (curLevel + 1), player.getMasterLevel(skillSPTo), -1);
            }
        } else {
            List<Pair<MapleStat, Integer>> statupdate = new ArrayList<>(2);
            int APTo = slea.readInt();
            int APFrom = slea.readInt();
            switch(APFrom) {
                case // str
                64:
                    if (player.getStr() < 5) {
                        c.getPlayer().message("You don't have the minimum STR required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(1, -1);
                    break;
                case // dex
                128:
                    if (player.getDex() < 5) {
                        c.getPlayer().message("You don't have the minimum DEX required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(2, -1);
                    break;
                case // int
                256:
                    if (player.getInt() < 5) {
                        c.getPlayer().message("You don't have the minimum INT required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(3, -1);
                    break;
                case // luk
                512:
                    if (player.getLuk() < 5) {
                        c.getPlayer().message("You don't have the minimum LUK required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(4, -1);
                    break;
                case // HP
                2048:
                    if (ServerConstants.USE_ENFORCE_HPMP_SWAP) {
                        if (APTo != 8192) {
                            c.getPlayer().message("You can only swap HP ability points to MP.");
                            c.announce(MaplePacketCreator.enableActions());
                            return;
                        }
                    }
                    if (player.getHpMpApUsed() < 1) {
                        c.getPlayer().message("You don't have enough HPMP stat points to spend on AP Reset.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    int hp = player.getMaxHp();
                    int level_ = player.getLevel();
                    boolean canWash_ = true;
                    if (hp < level_ * 14 + 148) {
                        canWash_ = false;
                    }
                    if (!canWash_) {
                        c.getPlayer().message("You don't have the minimum HP pool required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.setHpMpApUsed(player.getHpMpApUsed() - 1);
                    int hplose = -DistributeAPHandler.takeHp(player, player.getJob());
                    int nextHp = Math.max(1, player.getHp() + hplose), nextMaxHp = Math.max(50, player.getMaxHp() + hplose);
                    player.setHp(nextHp);
                    player.setMaxHp(nextMaxHp);
                    statupdate.add(new Pair<>(MapleStat.HP, nextHp));
                    statupdate.add(new Pair<>(MapleStat.MAXHP, nextMaxHp));
                    break;
                case // MP
                8192:
                    if (ServerConstants.USE_ENFORCE_HPMP_SWAP) {
                        if (APTo != 2048) {
                            c.getPlayer().message("You can only swap MP ability points to HP.");
                            c.announce(MaplePacketCreator.enableActions());
                            return;
                        }
                    }
                    if (player.getHpMpApUsed() < 1) {
                        c.getPlayer().message("You don't have enough HPMP stat points to spend on AP Reset.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    int mp = player.getMaxMp();
                    int level = player.getLevel();
                    MapleJob job = player.getJob();
                    boolean canWash = true;
                    if (job.isA(MapleJob.SPEARMAN) && mp < 4 * level + 156) {
                        canWash = false;
                    } else if (job.isA(MapleJob.FIGHTER) && mp < 4 * level + 56) {
                        canWash = false;
                    } else if (job.isA(MapleJob.THIEF) && job.getId() % 100 > 0 && mp < level * 14 - 4) {
                        canWash = false;
                    } else if (mp < level * 14 + 148) {
                        canWash = false;
                    }
                    if (!canWash) {
                        c.getPlayer().message("You don't have the minimum MP pool required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.setHpMpApUsed(player.getHpMpApUsed() - 1);
                    int mplose = -DistributeAPHandler.takeMp(player, job);
                    int nextMp = Math.max(0, player.getMp() + mplose), nextMaxMp = Math.max(5, player.getMaxMp() + mplose);
                    player.setMp(nextMp);
                    player.setMaxMp(nextMaxMp);
                    statupdate.add(new Pair<>(MapleStat.MP, nextMp));
                    statupdate.add(new Pair<>(MapleStat.MAXMP, nextMaxMp));
                    break;
                default:
                    c.announce(MaplePacketCreator.updatePlayerStats(MaplePacketCreator.EMPTY_STATUPDATE, true, c.getPlayer()));
                    return;
            }
            DistributeAPHandler.addStat(c, APTo, true);
            c.announce(MaplePacketCreator.updatePlayerStats(statupdate, true, c.getPlayer()));
        }
        remove(c, itemId);
    } else if (itemType == 506) {
        Item eq = null;
        if (itemId == 5060000) {
            // Item tag.
            int equipSlot = slea.readShort();
            if (equipSlot == 0) {
                return;
            }
            eq = player.getInventory(MapleInventoryType.EQUIPPED).getItem((short) equipSlot);
            eq.setOwner(player.getName());
        } else if (itemId == 5060001 || itemId == 5061000 || itemId == 5061001 || itemId == 5061002 || itemId == 5061003) {
            // Sealing lock
            MapleInventoryType type = MapleInventoryType.getByType((byte) slea.readInt());
            eq = c.getPlayer().getInventory(type).getItem((short) slea.readInt());
            if (eq == null) {
                // Check if the type is EQUIPMENT?
                return;
            }
            byte flag = eq.getFlag();
            flag |= ItemConstants.LOCK;
            if (eq.getExpiration() > -1) {
                // No perma items pls
                return;
            }
            eq.setFlag(flag);
            long period = 0;
            if (itemId == 5061000) {
                period = 7;
            } else if (itemId == 5061001) {
                period = 30;
            } else if (itemId == 5061002) {
                period = 90;
            } else if (itemId == 5061003) {
                period = 365;
            }
            if (period > 0) {
                eq.setExpiration(System.currentTimeMillis() + (period * 60 * 60 * 24 * 1000));
            }
            remove(c, itemId);
        } else if (itemId == 5060002) {
            // Incubator
            byte inventory2 = (byte) slea.readInt();
            short slot2 = (short) slea.readInt();
            Item item2 = c.getPlayer().getInventory(MapleInventoryType.getByType(inventory2)).getItem(slot2);
            if (// hacking
            item2 == null) {
                return;
            }
            if (getIncubatedItem(c, itemId)) {
                MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.getByType(inventory2), slot2, (short) 1, false);
                remove(c, itemId);
            }
            return;
        }
        // time stamp
        slea.readInt();
        if (eq != null) {
            player.forceUpdateItem(eq);
            remove(c, itemId);
        }
    } else if (itemType == 507) {
        boolean whisper;
        switch(itemId / 1000 % 10) {
            case // Megaphone
            1:
                if (player.getLevel() > 9) {
                    player.getClient().getChannelServer().broadcastPacket(MaplePacketCreator.serverNotice(2, medal + player.getName() + " : " + slea.readMapleAsciiString()));
                } else {
                    player.dropMessage(1, "You may not use this until you're level 10.");
                }
                break;
            case // Super megaphone
            2:
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + slea.readMapleAsciiString(), (slea.readByte() != 0)));
                break;
            case // Maple TV
            5:
                int tvType = itemId % 10;
                boolean megassenger = false;
                boolean ear = false;
                MapleCharacter victim = null;
                if (tvType != 1) {
                    if (tvType >= 3) {
                        megassenger = true;
                        if (tvType == 3) {
                            slea.readByte();
                        }
                        ear = 1 == slea.readByte();
                    } else if (tvType != 2) {
                        slea.readByte();
                    }
                    if (tvType != 4) {
                        victim = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
                    }
                }
                List<String> messages = new LinkedList<>();
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < 5; i++) {
                    String message = slea.readMapleAsciiString();
                    if (megassenger) {
                        builder.append(" ").append(message);
                    }
                    messages.add(message);
                }
                slea.readInt();
                if (megassenger) {
                    Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + builder.toString(), ear));
                }
                if (!MapleTVEffect.isActive()) {
                    new MapleTVEffect(player, victim, messages, tvType);
                    remove(c, itemId);
                } else {
                    player.dropMessage(1, "MapleTV is already in use.");
                    return;
                }
                break;
            case // item megaphone
            6:
                String msg = medal + c.getPlayer().getName() + " : " + slea.readMapleAsciiString();
                whisper = slea.readByte() == 1;
                Item item = null;
                if (slea.readByte() == 1) {
                    // item
                    item = c.getPlayer().getInventory(MapleInventoryType.getByType((byte) slea.readInt())).getItem((short) slea.readInt());
                    if (// hack
                    item == null) {
                        return;
                    } else if (((item.getFlag() & ItemConstants.UNTRADEABLE) == ItemConstants.UNTRADEABLE) || ii.isDropRestricted(item.getItemId())) {
                        player.dropMessage(1, "You cannot trade this item.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                }
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.itemMegaphone(msg, whisper, c.getChannel(), item));
                break;
            case // triple megaphone
            7:
                int lines = slea.readByte();
                if (// hack
                lines < 1 || lines > 3) {
                    return;
                }
                String[] msg2 = new String[lines];
                for (int i = 0; i < lines; i++) {
                    msg2[i] = medal + c.getPlayer().getName() + " : " + slea.readMapleAsciiString();
                }
                whisper = slea.readByte() == 1;
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.getMultiMegaphone(msg2, c.getChannel(), whisper));
                break;
        }
        remove(c, itemId);
    } else if (itemType == 508) {
        // graduation banner
        // message, separated by 0A for lines
        slea.readMapleAsciiString();
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 509) {
        String sendTo = slea.readMapleAsciiString();
        String msg = slea.readMapleAsciiString();
        try {
            player.sendNote(sendTo, msg, (byte) 0);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        remove(c, itemId);
    } else if (itemType == 510) {
        player.getMap().broadcastMessage(MaplePacketCreator.musicChange("Jukebox/Congratulation"));
        remove(c, itemId);
    } else if (itemType == 512) {
        if (ii.getStateChangeItem(itemId) != 0) {
            for (MapleCharacter mChar : c.getPlayer().getMap().getCharacters()) {
                ii.getItemEffect(ii.getStateChangeItem(itemId)).applyTo(mChar);
            }
        }
        player.getMap().startMapEffect(ii.getMsg(itemId).replaceFirst("%s", c.getPlayer().getName()).replaceFirst("%s", slea.readMapleAsciiString()), itemId);
        remove(c, itemId);
    } else if (itemType == 517) {
        MaplePet pet = player.getPet(0);
        if (pet == null) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        String newName = slea.readMapleAsciiString();
        pet.setName(newName);
        pet.saveToDb();
        Item item = player.getInventory(MapleInventoryType.CASH).getItem(pet.getPosition());
        if (item != null)
            player.forceUpdateItem(item);
        player.getMap().broadcastMessage(player, MaplePacketCreator.changePetName(player, newName, 1), true);
        c.announce(MaplePacketCreator.enableActions());
        remove(c, itemId);
    } else if (itemType == 504) {
        // vip teleport rock
        String error1 = "Either the player could not be found or you were trying to teleport to an illegal location.";
        boolean vip = slea.readByte() == 1;
        remove(c, itemId);
        if (!vip) {
            int mapId = slea.readInt();
            if (c.getChannelServer().getMapFactory().getMap(mapId).getForcedReturnId() == 999999999) {
                player.changeMap(c.getChannelServer().getMapFactory().getMap(mapId));
            } else {
                MapleInventoryManipulator.addById(c, itemId, (short) 1);
                c.getPlayer().dropMessage(1, error1);
                c.announce(MaplePacketCreator.enableActions());
            }
        } else {
            String name = slea.readMapleAsciiString();
            MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(name);
            boolean success = false;
            if (victim != null) {
                MapleMap target = victim.getMap();
                if (c.getChannelServer().getMapFactory().getMap(victim.getMapId()).getForcedReturnId() == 999999999 || victim.getMapId() < 100000000) {
                    if (victim.gmLevel() <= player.gmLevel()) {
                        if (itemId == 5041000 || victim.getMapId() / player.getMapId() == 1) {
                            // viprock & same continent
                            player.changeMap(target, target.findClosestPlayerSpawnpoint(victim.getPosition()));
                            success = true;
                        } else {
                            player.dropMessage(1, "You cannot teleport between continents with this teleport rock.");
                        }
                    } else {
                        player.dropMessage(1, error1);
                    }
                } else {
                    player.dropMessage(1, "You cannot teleport to this map.");
                }
            } else {
                player.dropMessage(1, "Player could not be found in this channel.");
            }
            if (!success) {
                MapleInventoryManipulator.addById(c, itemId, (short) 1);
                c.announce(MaplePacketCreator.enableActions());
            }
        }
    } else if (itemType == 520) {
        player.gainMeso(ii.getMeso(itemId), true, false, true);
        remove(c, itemId);
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 523) {
        int itemid = slea.readInt();
        if (!ServerConstants.USE_ENFORCE_OWL_SUGGESTIONS)
            c.getWorldServer().addOwlItemSearch(itemid);
        player.setOwlSearch(itemid);
        List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> hmsAvailable = c.getWorldServer().getAvailableItemBundles(itemid);
        if (!hmsAvailable.isEmpty())
            remove(c, itemId);
        c.announce(MaplePacketCreator.owlOfMinerva(c, itemid, hmsAvailable));
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 524) {
        for (byte i = 0; i < 3; i++) {
            MaplePet pet = player.getPet(i);
            if (pet != null) {
                if (pet.canConsume(itemId)) {
                    pet.gainClosenessFullness(player, 100, 100, 1);
                    remove(c, itemId);
                    break;
                }
            } else {
                break;
            }
        }
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 530) {
        ii.getItemEffect(itemId).applyTo(player);
        remove(c, itemId);
    } else if (itemType == 533) {
        NPCScriptManager.getInstance().start(c, 9010009, null);
    } else if (itemType == 537) {
        player.setChalkboard(slea.readMapleAsciiString());
        player.getMap().broadcastMessage(MaplePacketCreator.useChalkboard(player, false));
        player.getClient().announce(MaplePacketCreator.enableActions());
    } else if (itemType == 539) {
        List<String> strLines = new LinkedList<>();
        for (int i = 0; i < 4; i++) {
            strLines.add(slea.readMapleAsciiString());
        }
        final int world = c.getWorld();
        Server.getInstance().broadcastMessage(world, MaplePacketCreator.getAvatarMega(c.getPlayer(), medal, c.getChannel(), itemId, strLines, (slea.readByte() != 0)));
        TimerManager.getInstance().schedule(new Runnable() {

            @Override
            public void run() {
                Server.getInstance().broadcastMessage(world, MaplePacketCreator.byeAvatarMega());
            }
        }, 1000 * 10);
        remove(c, itemId);
    } else if (itemType == 545) {
        // MiuMiu's travel store
        if (player.getShop() == null) {
            MapleShop shop = MapleShopFactory.getInstance().getShop(1338);
            if (shop != null) {
                shop.sendShop(c);
                remove(c, itemId);
            }
        } else {
            c.announce(MaplePacketCreator.enableActions());
        }
    } else if (itemType == 550) {
        // Extend item expiration
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 552) {
        MapleInventoryType type = MapleInventoryType.getByType((byte) slea.readInt());
        short slot = (short) slea.readInt();
        Item item = c.getPlayer().getInventory(type).getItem(slot);
        if (item == null || item.getQuantity() <= 0 || (item.getFlag() & ItemConstants.KARMA) > 0 && ii.isKarmaAble(item.getItemId())) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (!type.equals(MapleInventoryType.USE)) {
            item.setFlag((byte) ItemConstants.KARMA);
        }
        c.getPlayer().forceUpdateItem(item);
        remove(c, itemId);
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 552) {
        // DS EGG THING
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 557) {
        slea.readInt();
        int itemSlot = slea.readInt();
        slea.readInt();
        final Equip equip = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) itemSlot);
        if (equip.getVicious() == 2 || c.getPlayer().getInventory(MapleInventoryType.CASH).findById(5570000) == null) {
            return;
        }
        equip.setVicious(equip.getVicious() + 1);
        equip.setUpgradeSlots(equip.getUpgradeSlots() + 1);
        remove(c, itemId);
        c.announce(MaplePacketCreator.enableActions());
        c.announce(MaplePacketCreator.sendHammerData(equip.getVicious()));
        player.forceUpdateItem(equip);
    } else if (itemType == 561) {
        // VEGA'S SPELL
        if (slea.readInt() != 1) {
            return;
        }
        final byte eSlot = (byte) slea.readInt();
        final Item eitem = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(eSlot);
        if (slea.readInt() != 2) {
            return;
        }
        final byte uSlot = (byte) slea.readInt();
        final Item uitem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(uSlot);
        if (eitem == null || uitem == null) {
            return;
        }
        Equip toScroll = (Equip) eitem;
        if (toScroll.getUpgradeSlots() < 1) {
            c.getSession().write(MaplePacketCreator.getInventoryFull());
            return;
        }
        // should have a check here against PE hacks
        if (itemId / 1000000 != 5)
            itemId = 0;
        c.getPlayer().toggleBlockCashShop();
        final int curlevel = toScroll.getLevel();
        c.getSession().write(MaplePacketCreator.sendVegaScroll(0x40));
        final Equip scrolled = (Equip) ii.scrollEquipWithId(toScroll, uitem.getItemId(), false, itemId, c.getPlayer().isGM());
        c.getSession().write(MaplePacketCreator.sendVegaScroll(scrolled.getLevel() > curlevel ? 0x41 : 0x43));
        // opcodes 0x42, 0x44: "this item cannot be used"; 0x39, 0x45: crashes
        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, uSlot, (short) 1, false);
        remove(c, itemId);
        final MapleClient client = c;
        TimerManager.getInstance().schedule(new Runnable() {

            @Override
            public void run() {
                if (!player.isLoggedin())
                    return;
                player.toggleBlockCashShop();
                final List<ModifyInventory> mods = new ArrayList<>();
                mods.add(new ModifyInventory(3, scrolled));
                mods.add(new ModifyInventory(0, scrolled));
                client.announce(MaplePacketCreator.modifyInventory(true, mods));
                ScrollResult scrollResult = scrolled.getLevel() > curlevel ? ScrollResult.SUCCESS : ScrollResult.FAIL;
                player.getMap().broadcastMessage(MaplePacketCreator.getScrollEffect(player.getId(), scrollResult, false));
                if (eSlot < 0 && (scrollResult == ScrollResult.SUCCESS)) {
                    player.equipChanged();
                }
                client.getSession().write(MaplePacketCreator.enableActions());
            }
        }, 1000 * 3);
    } else {
        System.out.println("NEW CASH ITEM: " + itemType + "\n" + slea.toString());
        c.announce(MaplePacketCreator.enableActions());
    }
}
Also used : MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Item(client.inventory.Item) MapleMap(server.maps.MapleMap) Equip(client.inventory.Equip) MapleInventoryType(client.inventory.MapleInventoryType) ScrollResult(client.inventory.Equip.ScrollResult) MapleItemInformationProvider(server.MapleItemInformationProvider) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MaplePet(client.inventory.MaplePet) Pair(tools.Pair) MapleTVEffect(server.maps.MapleTVEffect) MapleShop(server.MapleShop) LinkedList(java.util.LinkedList) ModifyInventory(client.inventory.ModifyInventory) Skill(client.Skill) MapleClient(client.MapleClient) MapleJob(client.MapleJob)

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