Search in sources :

Example 1 with CashShop

use of server.CashShop in project HeavenMS by ronancpl.

the class MapleCharacter method loadCharFromDB.

public static MapleCharacter loadCharFromDB(int charid, MapleClient client, boolean channelserver) throws SQLException {
    try {
        MapleCharacter ret = new MapleCharacter();
        ret.client = client;
        ret.id = charid;
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?");
        ps.setInt(1, charid);
        ResultSet rs = ps.executeQuery();
        if (!rs.next()) {
            rs.close();
            ps.close();
            throw new RuntimeException("Loading char failed (not found)");
        }
        ret.name = rs.getString("name");
        ret.level = rs.getInt("level");
        ret.fame = rs.getInt("fame");
        ret.quest_fame = rs.getInt("fquest");
        ret.str = rs.getInt("str");
        ret.dex = rs.getInt("dex");
        ret.int_ = rs.getInt("int");
        ret.luk = rs.getInt("luk");
        ret.exp.set(rs.getInt("exp"));
        ret.gachaexp.set(rs.getInt("gachaexp"));
        ret.hp = rs.getInt("hp");
        ret.maxhp = rs.getInt("maxhp");
        ret.mp = rs.getInt("mp");
        ret.maxmp = rs.getInt("maxmp");
        ret.hpMpApUsed = rs.getInt("hpMpUsed");
        ret.hasMerchant = rs.getInt("HasMerchant") == 1;
        String[] skillPoints = rs.getString("sp").split(",");
        for (int i = 0; i < ret.remainingSp.length; i++) {
            ret.remainingSp[i] = Integer.parseInt(skillPoints[i]);
        }
        ret.remainingAp = rs.getInt("ap");
        ret.meso.set(rs.getInt("meso"));
        ret.merchantmeso = rs.getInt("MerchantMesos");
        ret.gmLevel = rs.getInt("gm");
        ret.skinColor = MapleSkinColor.getById(rs.getInt("skincolor"));
        ret.gender = rs.getInt("gender");
        ret.job = MapleJob.getById(rs.getInt("job"));
        ret.finishedDojoTutorial = rs.getInt("finishedDojoTutorial") == 1;
        ret.vanquisherKills = rs.getInt("vanquisherKills");
        ret.omokwins = rs.getInt("omokwins");
        ret.omoklosses = rs.getInt("omoklosses");
        ret.omokties = rs.getInt("omokties");
        ret.matchcardwins = rs.getInt("matchcardwins");
        ret.matchcardlosses = rs.getInt("matchcardlosses");
        ret.matchcardties = rs.getInt("matchcardties");
        ret.hair = rs.getInt("hair");
        ret.face = rs.getInt("face");
        ret.accountid = rs.getInt("accountid");
        ret.mapid = rs.getInt("map");
        ret.jailExpiration = rs.getLong("jailexpire");
        ret.initialSpawnPoint = rs.getInt("spawnpoint");
        ret.world = rs.getByte("world");
        ret.rank = rs.getInt("rank");
        ret.rankMove = rs.getInt("rankMove");
        ret.jobRank = rs.getInt("jobRank");
        ret.jobRankMove = rs.getInt("jobRankMove");
        int mountexp = rs.getInt("mountexp");
        int mountlevel = rs.getInt("mountlevel");
        int mounttiredness = rs.getInt("mounttiredness");
        ret.guildid = rs.getInt("guildid");
        ret.guildRank = rs.getInt("guildrank");
        ret.allianceRank = rs.getInt("allianceRank");
        ret.familyId = rs.getInt("familyId");
        ret.bookCover = rs.getInt("monsterbookcover");
        ret.monsterbook = new MonsterBook();
        ret.monsterbook.loadCards(charid);
        ret.vanquisherStage = rs.getInt("vanquisherStage");
        ret.dojoPoints = rs.getInt("dojoPoints");
        ret.dojoStage = rs.getInt("lastDojoStage");
        ret.dataString = rs.getString("dataString");
        ret.mgc = new MapleGuildCharacter(ret);
        int buddyCapacity = rs.getInt("buddyCapacity");
        ret.buddylist = new BuddyList(buddyCapacity);
        ret.getInventory(MapleInventoryType.EQUIP).setSlotLimit(rs.getByte("equipslots"));
        ret.getInventory(MapleInventoryType.USE).setSlotLimit(rs.getByte("useslots"));
        ret.getInventory(MapleInventoryType.SETUP).setSlotLimit(rs.getByte("setupslots"));
        ret.getInventory(MapleInventoryType.ETC).setSlotLimit(rs.getByte("etcslots"));
        for (Pair<Item, MapleInventoryType> item : ItemFactory.INVENTORY.loadItems(ret.id, !channelserver)) {
            ret.getInventory(item.getRight()).addFromDB(item.getLeft());
            Item itemz = item.getLeft();
            if (itemz.getPetId() > -1) {
                MaplePet pet = itemz.getPet();
                if (pet != null && pet.isSummoned()) {
                    ret.addPet(pet);
                }
                continue;
            }
            if (item.getRight().equals(MapleInventoryType.EQUIP) || item.getRight().equals(MapleInventoryType.EQUIPPED)) {
                Equip equip = (Equip) item.getLeft();
                if (equip.getRingId() > -1) {
                    MapleRing ring = MapleRing.loadFromDb(equip.getRingId());
                    if (item.getRight().equals(MapleInventoryType.EQUIPPED)) {
                        ring.equip();
                    }
                    if (ring.getItemId() > 1112012) {
                        ret.addFriendshipRing(ring);
                    } else {
                        ret.addCrushRing(ring);
                    }
                }
            }
        }
        NewYearCardRecord.loadPlayerNewYearCards(ret);
        PreparedStatement ps2, ps3;
        ResultSet rs2, rs3;
        ps3 = con.prepareStatement("SELECT petid FROM inventoryitems WHERE characterid = ? AND petid > -1");
        ps3.setInt(1, charid);
        rs3 = ps3.executeQuery();
        while (rs3.next()) {
            int petId = rs3.getInt("petid");
            ps2 = con.prepareStatement("SELECT itemid FROM petignores WHERE petid = ?");
            ps2.setInt(1, petId);
            ret.resetExcluded(petId);
            rs2 = ps2.executeQuery();
            while (rs2.next()) {
                ret.addExcluded(petId, rs2.getInt("itemid"));
            }
            ps2.close();
            rs2.close();
        }
        ps3.close();
        rs3.close();
        ret.commitExcludedItems();
        if (channelserver) {
            MapleMapFactory mapFactory = client.getChannelServer().getMapFactory();
            ret.map = mapFactory.getMap(ret.mapid);
            if (ret.map == null) {
                ret.map = mapFactory.getMap(100000000);
            }
            MaplePortal portal = ret.map.getPortal(ret.initialSpawnPoint);
            if (portal == null) {
                portal = ret.map.getPortal(0);
                ret.initialSpawnPoint = 0;
            }
            ret.setPosition(portal.getPosition());
            int partyid = rs.getInt("party");
            MapleParty party = Server.getInstance().getWorld(ret.world).getParty(partyid);
            if (party != null) {
                ret.mpc = party.getMemberById(ret.id);
                if (ret.mpc != null) {
                    ret.mpc = new MaplePartyCharacter(ret);
                    ret.party = party;
                }
            }
            int messengerid = rs.getInt("messengerid");
            int position = rs.getInt("messengerposition");
            if (messengerid > 0 && position < 4 && position > -1) {
                MapleMessenger messenger = Server.getInstance().getWorld(ret.world).getMessenger(messengerid);
                if (messenger != null) {
                    ret.messenger = messenger;
                    ret.messengerposition = position;
                }
            }
            ret.loggedIn = true;
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT mapid,vip FROM trocklocations WHERE characterid = ? LIMIT 15");
        ps.setInt(1, charid);
        rs = ps.executeQuery();
        byte v = 0;
        byte r = 0;
        while (rs.next()) {
            if (rs.getInt("vip") == 1) {
                ret.viptrockmaps.add(rs.getInt("mapid"));
                v++;
            } else {
                ret.trockmaps.add(rs.getInt("mapid"));
                r++;
            }
        }
        while (v < 10) {
            ret.viptrockmaps.add(999999999);
            v++;
        }
        while (r < 5) {
            ret.trockmaps.add(999999999);
            r++;
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT name FROM accounts WHERE id = ?", Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, ret.accountid);
        rs = ps.executeQuery();
        if (rs.next()) {
            ret.getClient().setAccountName(rs.getString("name"));
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT `area`,`info` FROM area_info WHERE charid = ?");
        ps.setInt(1, ret.id);
        rs = ps.executeQuery();
        while (rs.next()) {
            ret.area_info.put(rs.getShort("area"), rs.getString("info"));
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT `name`,`info` FROM eventstats WHERE characterid = ?");
        ps.setInt(1, ret.id);
        rs = ps.executeQuery();
        while (rs.next()) {
            String name = rs.getString("name");
            if (rs.getString("name").equals("rescueGaga")) {
                ret.events.put(name, new RescueGaga(rs.getInt("info")));
            }
        // ret.events = new MapleEvents(new RescueGaga(rs.getInt("rescuegaga")), new ArtifactHunt(rs.getInt("artifacthunt")));
        }
        rs.close();
        ps.close();
        ret.cashshop = new CashShop(ret.accountid, ret.id, ret.getJobType());
        ret.autoban = new AutobanManager(ret);
        // for now
        ret.marriageRing = null;
        ps = con.prepareStatement("SELECT name, level FROM characters WHERE accountid = ? AND id != ? ORDER BY level DESC limit 1");
        ps.setInt(1, ret.accountid);
        ps.setInt(2, charid);
        rs = ps.executeQuery();
        if (rs.next()) {
            ret.linkedName = rs.getString("name");
            ret.linkedLevel = rs.getInt("level");
        }
        rs.close();
        ps.close();
        if (channelserver) {
            ps = con.prepareStatement("SELECT * FROM queststatus WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            PreparedStatement psf;
            try (PreparedStatement pse = con.prepareStatement("SELECT * FROM questprogress WHERE queststatusid = ?")) {
                psf = con.prepareStatement("SELECT mapid FROM medalmaps WHERE queststatusid = ?");
                while (rs.next()) {
                    MapleQuest q = MapleQuest.getInstance(rs.getShort("quest"));
                    MapleQuestStatus status = new MapleQuestStatus(q, MapleQuestStatus.Status.getById(rs.getInt("status")));
                    long cTime = rs.getLong("time");
                    if (cTime > -1) {
                        status.setCompletionTime(cTime * 1000);
                    }
                    long eTime = rs.getLong("expires");
                    if (eTime > 0) {
                        status.setExpirationTime(eTime);
                    }
                    status.setForfeited(rs.getInt("forfeited"));
                    ret.quests.put(q.getId(), status);
                    pse.setInt(1, rs.getInt("queststatusid"));
                    try (ResultSet rsProgress = pse.executeQuery()) {
                        while (rsProgress.next()) {
                            status.setProgress(rsProgress.getInt("progressid"), rsProgress.getString("progress"));
                        }
                    }
                    psf.setInt(1, rs.getInt("queststatusid"));
                    try (ResultSet medalmaps = psf.executeQuery()) {
                        while (medalmaps.next()) {
                            status.addMedalMap(medalmaps.getInt("mapid"));
                        }
                    }
                }
                rs.close();
                ps.close();
            }
            psf.close();
            ps = con.prepareStatement("SELECT skillid,skilllevel,masterlevel,expiration FROM skills WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                ret.skills.put(SkillFactory.getSkill(rs.getInt("skillid")), new SkillEntry(rs.getByte("skilllevel"), rs.getInt("masterlevel"), rs.getLong("expiration")));
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT SkillID,StartTime,length FROM cooldowns WHERE charid = ?");
            ps.setInt(1, ret.getId());
            rs = ps.executeQuery();
            while (rs.next()) {
                final int skillid = rs.getInt("SkillID");
                final long length = rs.getLong("length"), startTime = rs.getLong("StartTime");
                if (skillid != 5221999 && (length + startTime < System.currentTimeMillis())) {
                    continue;
                }
                ret.giveCoolDowns(skillid, startTime, length);
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("DELETE FROM cooldowns WHERE charid = ?");
            ps.setInt(1, ret.getId());
            ps.executeUpdate();
            ps.close();
            ps = con.prepareStatement("SELECT * FROM skillmacros WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                int position = rs.getInt("position");
                SkillMacro macro = new SkillMacro(rs.getInt("skill1"), rs.getInt("skill2"), rs.getInt("skill3"), rs.getString("name"), rs.getInt("shout"), position);
                ret.skillMacros[position] = macro;
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT `key`,`type`,`action` FROM keymap WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                int key = rs.getInt("key");
                int type = rs.getInt("type");
                int action = rs.getInt("action");
                ret.keymap.put(Integer.valueOf(key), new MapleKeyBinding(type, action));
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT `locationtype`,`map`,`portal` FROM savedlocations WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                ret.savedLocations[SavedLocationType.valueOf(rs.getString("locationtype")).ordinal()] = new SavedLocation(rs.getInt("map"), rs.getInt("portal"));
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT `characterid_to`,`when` FROM famelog WHERE characterid = ? AND DATEDIFF(NOW(),`when`) < 30");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            ret.lastfametime = 0;
            ret.lastmonthfameids = new ArrayList<>(31);
            while (rs.next()) {
                ret.lastfametime = Math.max(ret.lastfametime, rs.getTimestamp("when").getTime());
                ret.lastmonthfameids.add(Integer.valueOf(rs.getInt("characterid_to")));
            }
            rs.close();
            ps.close();
            ret.buddylist.loadFromDb(charid);
            ret.storage = MapleStorage.loadOrCreateFromDB(ret.accountid, ret.world);
            ret.recalcLocalStats();
            // ret.resetBattleshipHp();
            ret.silentEnforceMaxHpMp();
        }
        int mountid = ret.getJobType() * 10000000 + 1004;
        if (ret.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -18) != null) {
            ret.maplemount = new MapleMount(ret, ret.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -18).getItemId(), mountid);
        } else {
            ret.maplemount = new MapleMount(ret, 0, mountid);
        }
        ret.maplemount.setExp(mountexp);
        ret.maplemount.setLevel(mountlevel);
        ret.maplemount.setTiredness(mounttiredness);
        ret.maplemount.setActive(false);
        con.close();
        return ret;
    } catch (SQLException | RuntimeException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : MapleQuest(server.quest.MapleQuest) AutobanManager(client.autoban.AutobanManager) SQLException(java.sql.SQLException) MapleGuildCharacter(net.server.guild.MapleGuildCharacter) RescueGaga(server.events.RescueGaga) MapleMapFactory(server.maps.MapleMapFactory) MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Equip(client.inventory.Equip) MapleInventoryType(client.inventory.MapleInventoryType) ResultSet(java.sql.ResultSet) MaplePet(client.inventory.MaplePet) CashShop(server.CashShop) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) SavedLocation(server.maps.SavedLocation) MapleParty(net.server.world.MapleParty) PreparedStatement(java.sql.PreparedStatement) Point(java.awt.Point) MaplePortal(server.MaplePortal) MaplePartyCharacter(net.server.world.MaplePartyCharacter) MapleMessenger(net.server.world.MapleMessenger)

Example 2 with CashShop

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

Equip (client.inventory.Equip)2 Item (client.inventory.Item)2 SQLException (java.sql.SQLException)2 CashShop (server.CashShop)2 MapleCharacter (client.MapleCharacter)1 MapleRing (client.MapleRing)1 AutobanManager (client.autoban.AutobanManager)1 MapleInventory (client.inventory.MapleInventory)1 MapleInventoryType (client.inventory.MapleInventoryType)1 MaplePet (client.inventory.MaplePet)1 Point (java.awt.Point)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Map (java.util.Map)1 MapleGuildCharacter (net.server.guild.MapleGuildCharacter)1 MapleMessenger (net.server.world.MapleMessenger)1 MapleParty (net.server.world.MapleParty)1 MaplePartyCharacter (net.server.world.MaplePartyCharacter)1 CashItem (server.CashShop.CashItem)1