Search in sources :

Example 11 with MapleInventory

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

the class AbstractPlayerInteraction method removeFromParty.

public void removeFromParty(int id, List<MapleCharacter> party) {
    for (MapleCharacter chr : party) {
        MapleInventoryType type = ItemConstants.getInventoryType(id);
        MapleInventory iv = chr.getInventory(type);
        int possesed = iv.countById(id);
        if (possesed > 0) {
            MapleInventoryManipulator.removeById(c, ItemConstants.getInventoryType(id), id, possesed, true, false);
            chr.announce(MaplePacketCreator.getShowItemGain(id, (short) -possesed, true));
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) MapleInventoryType(client.inventory.MapleInventoryType) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point)

Example 12 with MapleInventory

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

the class MapleCharacter method insertNewChar.

public final boolean insertNewChar() {
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = DatabaseConnection.getConnection();
        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        con.setAutoCommit(false);
        ps = con.prepareStatement("INSERT INTO characters (str, dex, luk, `int`, gm, skincolor, gender, job, hair, face, map, meso, spawnpoint, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, 12);
        ps.setInt(2, 5);
        ps.setInt(3, 4);
        ps.setInt(4, 4);
        ps.setInt(5, gmLevel);
        ps.setInt(6, skinColor.getId());
        ps.setInt(7, gender);
        ps.setInt(8, getJob().getId());
        ps.setInt(9, hair);
        ps.setInt(10, face);
        ps.setInt(11, mapid);
        ps.setInt(12, Math.abs(meso.get()));
        ps.setInt(13, 0);
        ps.setInt(14, accountid);
        ps.setString(15, name);
        ps.setInt(16, world);
        int updateRows = ps.executeUpdate();
        if (updateRows < 1) {
            ps.close();
            FilePrinter.printError(FilePrinter.INSERT_CHAR, "Error trying to insert " + name);
            return false;
        }
        ResultSet rs = ps.getGeneratedKeys();
        if (rs.next()) {
            this.id = rs.getInt(1);
            rs.close();
            ps.close();
        } else {
            rs.close();
            ps.close();
            FilePrinter.printError(FilePrinter.INSERT_CHAR, "Inserting char failed " + name);
            return false;
        }
        // Select a keybinding method
        int[] selectedKey;
        int[] selectedType;
        int[] selectedAction;
        if (ServerConstants.USE_CUSTOM_KEYSET) {
            selectedKey = GameConstants.getCustomKey(true);
            selectedType = GameConstants.getCustomType(true);
            selectedAction = GameConstants.getCustomAction(true);
        } else {
            selectedKey = GameConstants.getCustomKey(false);
            selectedType = GameConstants.getCustomType(false);
            selectedAction = GameConstants.getCustomAction(false);
        }
        ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
        ps.setInt(1, id);
        for (int i = 0; i < selectedKey.length; i++) {
            ps.setInt(2, selectedKey[i]);
            ps.setInt(3, selectedType[i]);
            ps.setInt(4, selectedAction[i]);
            ps.execute();
        }
        ps.close();
        final List<Pair<Item, MapleInventoryType>> itemsWithType = new ArrayList<>();
        for (MapleInventory iv : inventory) {
            for (Item item : iv.list()) {
                itemsWithType.add(new Pair<>(item, iv.getType()));
            }
        }
        ItemFactory.INVENTORY.saveItems(itemsWithType, id, con);
        con.commit();
        return true;
    } catch (Throwable t) {
        FilePrinter.printError(FilePrinter.INSERT_CHAR, t, "Error creating " + name + " Level: " + level + " Job: " + job.getId());
        try {
            con.rollback();
        } catch (SQLException se) {
            FilePrinter.printError(FilePrinter.INSERT_CHAR, se, "Error trying to rollback " + name);
        }
        return false;
    } finally {
        try {
            if (ps != null && !ps.isClosed()) {
                ps.close();
            }
            con.setAutoCommit(true);
            con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point) MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) ResultSet(java.sql.ResultSet) Pair(tools.Pair)

Example 13 with MapleInventory

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

the class MapleCharacter method expirationTask.

public void expirationTask() {
    if (itemExpireTask == null) {
        itemExpireTask = TimerManager.getInstance().register(new Runnable() {

            @Override
            public void run() {
                boolean deletedCoupon = false;
                long expiration, currenttime = System.currentTimeMillis();
                Set<Skill> keys = getSkills().keySet();
                for (Iterator<Skill> i = keys.iterator(); i.hasNext(); ) {
                    Skill key = i.next();
                    SkillEntry skill = getSkills().get(key);
                    if (skill.expiration != -1 && skill.expiration < currenttime) {
                        changeSkillLevel(key, (byte) -1, 0, -1);
                    }
                }
                List<Item> toberemove = new ArrayList<>();
                for (MapleInventory inv : inventory) {
                    for (Item item : inv.list()) {
                        expiration = item.getExpiration();
                        if (expiration != -1 && (expiration < currenttime) && ((item.getFlag() & ItemConstants.LOCK) == ItemConstants.LOCK)) {
                            byte aids = item.getFlag();
                            aids &= ~(ItemConstants.LOCK);
                            // Probably need a check, else people can make expiring items into permanent items...
                            item.setFlag(aids);
                            item.setExpiration(-1);
                            // TEST :3
                            forceUpdateItem(item);
                        } else if (expiration != -1 && expiration < currenttime) {
                            if (!ItemConstants.isPet(item.getItemId())) {
                                client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
                                toberemove.add(item);
                                if (ItemConstants.isRateCoupon(item.getItemId())) {
                                    deletedCoupon = true;
                                }
                            } else {
                                if (item.getPetId() > -1) {
                                    int petIdx = getPetIndex(item.getPetId());
                                    if (petIdx > -1)
                                        unequipPet(getPet(petIdx), true);
                                }
                                if (ItemConstants.isExpirablePet(item.getItemId())) {
                                    client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
                                    toberemove.add(item);
                                } else {
                                    item.setExpiration(-1);
                                    forceUpdateItem(item);
                                }
                            }
                        }
                    }
                    for (Item item : toberemove) {
                        MapleInventoryManipulator.removeFromSlot(client, inv.getType(), item.getPosition(), item.getQuantity(), true);
                    }
                    toberemove.clear();
                    if (deletedCoupon) {
                        updateCouponRates();
                    }
                }
            }
        }, 60000);
    }
}
Also used : MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) MobSkill(server.life.MobSkill) ArrayList(java.util.ArrayList) MapleInventory(client.inventory.MapleInventory)

Example 14 with MapleInventory

use of client.inventory.MapleInventory 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 15 with MapleInventory

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

Aggregations

MapleInventory (client.inventory.MapleInventory)20 Item (client.inventory.Item)18 MapleCharacter (client.MapleCharacter)10 Point (java.awt.Point)8 ArrayList (java.util.ArrayList)8 MapleMapItem (server.maps.MapleMapItem)7 Equip (client.inventory.Equip)6 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)6 MapleInventoryType (client.inventory.MapleInventoryType)4 SQLException (java.sql.SQLException)4 CashItem (server.CashShop.CashItem)3 MapleItemInformationProvider (server.MapleItemInformationProvider)3 MobSkill (server.life.MobSkill)3 Pair (tools.Pair)3 Skill (client.Skill)2 MapleWeaponType (client.inventory.MapleWeaponType)2 ModifyInventory (client.inventory.ModifyInventory)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2