Search in sources :

Example 1 with MapleHiredMerchant

use of server.maps.MapleHiredMerchant in project HeavenMS by ronancpl.

the class MapleCharacter method closeHiredMerchant.

public void closeHiredMerchant(boolean closeMerchant) {
    MapleHiredMerchant merchant = this.getHiredMerchant();
    if (merchant == null)
        return;
    if (closeMerchant) {
        merchant.removeVisitor(this);
        this.setHiredMerchant(null);
    } else {
        if (merchant.isOwner(this)) {
            merchant.setOpen(true);
        } else {
            merchant.removeVisitor(this);
        }
        try {
            merchant.saveItems(false);
        } catch (SQLException ex) {
            ex.printStackTrace();
            System.out.println("Error while saving Hired Merchant items.");
        }
    }
}
Also used : MapleHiredMerchant(server.maps.MapleHiredMerchant) SQLException(java.sql.SQLException)

Example 2 with MapleHiredMerchant

use of server.maps.MapleHiredMerchant in project HeavenMS by ronancpl.

the class World method runHiredMerchantSchedule.

public void runHiredMerchantSchedule() {
    Map<Integer, Pair<MapleHiredMerchant, Byte>> deployedMerchants;
    activeMerchantsLock.lock();
    try {
        merchantUpdate = System.currentTimeMillis();
        deployedMerchants = new LinkedHashMap<>(activeMerchants);
        for (Map.Entry<Integer, Pair<MapleHiredMerchant, Byte>> dm : deployedMerchants.entrySet()) {
            byte timeOn = dm.getValue().getRight();
            MapleHiredMerchant hm = dm.getValue().getLeft();
            if (timeOn <= 144) {
                // 1440 minutes == 24hrs
                activeMerchants.put(hm.getOwnerId(), new Pair<>(dm.getValue().getLeft(), (byte) (timeOn + 1)));
            } else {
                hm.forceClose();
                this.getChannel(hm.getChannel()).removeHiredMerchant(hm.getOwnerId());
                activeMerchants.remove(dm.getKey());
            }
        }
    } finally {
        activeMerchantsLock.unlock();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapleHiredMerchant(server.maps.MapleHiredMerchant) MapleMap(server.maps.MapleMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Pair(tools.Pair)

Example 3 with MapleHiredMerchant

use of server.maps.MapleHiredMerchant in project HeavenMS by ronancpl.

the class World method getActiveMerchants.

public List<MapleHiredMerchant> getActiveMerchants() {
    List<MapleHiredMerchant> hmList = new ArrayList<>();
    activeMerchantsLock.lock();
    try {
        for (Pair<MapleHiredMerchant, Byte> hmp : activeMerchants.values()) {
            MapleHiredMerchant hm = hmp.getLeft();
            if (hm.isOpen()) {
                hmList.add(hm);
            }
        }
        return hmList;
    } finally {
        activeMerchantsLock.unlock();
    }
}
Also used : MapleHiredMerchant(server.maps.MapleHiredMerchant) ArrayList(java.util.ArrayList)

Example 4 with MapleHiredMerchant

use of server.maps.MapleHiredMerchant in project HeavenMS by ronancpl.

the class PlayerInteractionHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    byte mode = slea.readByte();
    MapleCharacter chr = c.getPlayer();
    if (mode == Action.CREATE.getCode()) {
        byte createType = slea.readByte();
        if (createType == 3) {
            // trade
            MapleTrade.startTrade(chr);
        } else if (createType == 1) {
            // omok mini game
            if (chr.getChalkboard() != null || FieldLimit.CANNOTMINIGAME.check(chr.getMap().getFieldLimit())) {
                return;
            }
            String desc = slea.readMapleAsciiString();
            // 20 6E 4E
            slea.readByte();
            // 20 6E 4E
            int type = slea.readByte();
            MapleMiniGame game = new MapleMiniGame(chr, desc);
            chr.setMiniGame(game);
            game.setPieceType(type);
            game.setGameType("omok");
            chr.getMap().addMapObject(game);
            chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(chr, 1, 0));
            game.sendOmok(c, type);
        } else if (createType == 2) {
            // matchcard
            if (chr.getChalkboard() != null) {
                return;
            }
            String desc = slea.readMapleAsciiString();
            // 20 6E 4E
            slea.readByte();
            // 20 6E 4E
            int type = slea.readByte();
            MapleMiniGame game = new MapleMiniGame(chr, desc);
            game.setPieceType(type);
            if (type == 0) {
                game.setMatchesToWin(6);
            } else if (type == 1) {
                game.setMatchesToWin(10);
            } else if (type == 2) {
                game.setMatchesToWin(15);
            }
            game.setGameType("matchcard");
            chr.setMiniGame(game);
            chr.getMap().addMapObject(game);
            chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(chr, 1, 0));
            game.sendMatchCard(c, type);
        } else if (createType == 4 || createType == 5) {
            // shop
            if (!chr.getMap().getMapObjectsInRange(chr.getPosition(), 23000, Arrays.asList(MapleMapObjectType.SHOP, MapleMapObjectType.HIRED_MERCHANT)).isEmpty()) {
                return;
            }
            String desc = slea.readMapleAsciiString();
            slea.skip(3);
            int itemId = slea.readInt();
            if (chr.getInventory(MapleInventoryType.CASH).countById(itemId) < 1) {
                return;
            }
            if (GameConstants.isFreeMarketRoom(chr.getMapId()) || itemId > 5030000 && itemId < 5030012 || itemId > 5140000 && itemId < 5140006) {
                if (createType == 4) {
                    MaplePlayerShop shop = new MaplePlayerShop(c.getPlayer(), desc);
                    chr.setPlayerShop(shop);
                    chr.getMap().addMapObject(shop);
                    shop.sendShop(c);
                    c.getWorldServer().registerPlayerShop(shop);
                // c.announce(MaplePacketCreator.getPlayerShopRemoveVisitor(1));
                } else {
                    MapleHiredMerchant merchant = new MapleHiredMerchant(chr, itemId, desc);
                    chr.setHiredMerchant(merchant);
                    c.getWorldServer().registerHiredMerchant(merchant);
                    chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
                    chr.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, true));
                }
            }
        }
    } else if (mode == Action.INVITE.getCode()) {
        int otherPlayer = slea.readInt();
        if (chr.getId() == chr.getMap().getCharacterById(otherPlayer).getId()) {
            return;
        }
        MapleTrade.inviteTrade(chr, chr.getMap().getCharacterById(otherPlayer));
    } else if (mode == Action.DECLINE.getCode()) {
        MapleTrade.declineTrade(chr);
    } else if (mode == Action.VISIT.getCode()) {
        if (chr.getTrade() != null && chr.getTrade().getPartner() != null) {
            if (!chr.getTrade().isFullTrade() && !chr.getTrade().getPartner().isFullTrade()) {
                MapleTrade.visitTrade(chr, chr.getTrade().getPartner().getChr());
            } else {
                // Ill be nice and not dc u
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
        } else {
            int oid = slea.readInt();
            MapleMapObject ob = chr.getMap().getMapObject(oid);
            if (ob instanceof MaplePlayerShop) {
                MaplePlayerShop shop = (MaplePlayerShop) ob;
                shop.visitShop(chr);
            } else if (ob instanceof MapleMiniGame) {
                MapleMiniGame game = (MapleMiniGame) ob;
                if (game.hasFreeSlot() && !game.isVisitor(c.getPlayer())) {
                    game.addVisitor(c.getPlayer());
                    chr.setMiniGame(game);
                    switch(game.getGameType()) {
                        case "omok":
                            game.sendOmok(c, game.getPieceType());
                            break;
                        case "matchcard":
                            game.sendMatchCard(c, game.getPieceType());
                            break;
                    }
                } else {
                    chr.getClient().announce(MaplePacketCreator.getMiniGameFull());
                }
            } else if (ob instanceof MapleHiredMerchant && chr.getHiredMerchant() == null) {
                MapleHiredMerchant merchant = (MapleHiredMerchant) ob;
                if (merchant.isOwner(c.getPlayer())) {
                    merchant.setOpen(false);
                    merchant.removeAllVisitors();
                    c.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, false));
                } else if (!merchant.isOpen()) {
                    c.announce(MaplePacketCreator.hiredMerchantMaintenanceMessage());
                    return;
                } else if (!merchant.addVisitor(c.getPlayer())) {
                    chr.dropMessage(1, "This shop has reached it's maximum capacity, please come by later.");
                    return;
                } else {
                    c.announce(MaplePacketCreator.getHiredMerchant(c.getPlayer(), merchant, false));
                }
                chr.setHiredMerchant(merchant);
            }
        }
    } else if (mode == Action.CHAT.getCode()) {
        // chat lol
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (chr.getTrade() != null) {
            chr.getTrade().chat(slea.readMapleAsciiString());
        } else if (chr.getPlayerShop() != null) {
            // mini game
            MaplePlayerShop shop = chr.getPlayerShop();
            if (shop != null) {
                shop.chat(c, slea.readMapleAsciiString());
            }
        } else if (chr.getMiniGame() != null) {
            MapleMiniGame game = chr.getMiniGame();
            if (game != null) {
                game.chat(c, slea.readMapleAsciiString());
            }
        } else if (merchant != null) {
            merchant.sendMessage(c.getPlayer(), slea.readMapleAsciiString());
        }
    } else if (mode == Action.EXIT.getCode()) {
        if (chr.getTrade() != null) {
            MapleTrade.cancelTrade(c.getPlayer());
        } else {
            chr.closePlayerShop();
            chr.closeMiniGame();
            chr.closeHiredMerchant(true);
        }
    } else if (mode == Action.OPEN.getCode()) {
        MaplePlayerShop shop = chr.getPlayerShop();
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (shop != null && shop.isOwner(c.getPlayer())) {
            // 01
            slea.readByte();
            if (ServerConstants.USE_ERASE_PERMIT_ON_OPENSHOP) {
                try {
                    MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5140000, 1, true, false);
                }// fella does not have a player shop permit...
                 catch (RuntimeException re) {
                }
            }
            chr.getMap().broadcastMessage(MaplePacketCreator.addCharBox(c.getPlayer(), 4));
            shop.setOpen(true);
        } else if (merchant != null && merchant.isOwner(c.getPlayer())) {
            chr.setHasMerchant(true);
            merchant.setOpen(true);
            chr.getMap().addMapObject(merchant);
            chr.setHiredMerchant(null);
            chr.getMap().broadcastMessage(MaplePacketCreator.spawnHiredMerchant(merchant));
            slea.readByte();
        }
    } else if (mode == Action.READY.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        game.broadcast(MaplePacketCreator.getMiniGameReady(game));
    } else if (mode == Action.UN_READY.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        game.broadcast(MaplePacketCreator.getMiniGameUnReady(game));
    } else if (mode == Action.START.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.getGameType().equals("omok")) {
            game.broadcast(MaplePacketCreator.getMiniGameStart(game, game.getLoser()));
            chr.getMap().broadcastMessage(MaplePacketCreator.addOmokBox(game.getOwner(), 2, 1));
        }
        if (game.getGameType().equals("matchcard")) {
            game.shuffleList();
            game.broadcast(MaplePacketCreator.getMatchCardStart(game, game.getLoser()));
            chr.getMap().broadcastMessage(MaplePacketCreator.addMatchCardBox(game.getOwner(), 2, 1));
        }
    } else if (mode == Action.GIVE_UP.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.getGameType().equals("omok")) {
            if (game.isOwner(c.getPlayer())) {
                game.broadcast(MaplePacketCreator.getMiniGameOwnerForfeit(game));
            } else {
                game.broadcast(MaplePacketCreator.getMiniGameVisitorForfeit(game));
            }
        }
        if (game.getGameType().equals("matchcard")) {
            if (game.isOwner(c.getPlayer())) {
                game.broadcast(MaplePacketCreator.getMatchCardVisitorWin(game));
            } else {
                game.broadcast(MaplePacketCreator.getMatchCardOwnerWin(game));
            }
        }
    } else if (mode == Action.REQUEST_TIE.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.isOwner(c.getPlayer())) {
            game.broadcastToVisitor(MaplePacketCreator.getMiniGameRequestTie(game));
        } else {
            game.getOwner().getClient().announce(MaplePacketCreator.getMiniGameRequestTie(game));
        }
    } else if (mode == Action.ANSWER_TIE.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        slea.readByte();
        if (game.getGameType().equals("omok")) {
            game.broadcast(MaplePacketCreator.getMiniGameTie(game));
        }
        if (game.getGameType().equals("matchcard")) {
            game.broadcast(MaplePacketCreator.getMatchCardTie(game));
        }
    } else if (mode == Action.SKIP.getCode()) {
        MapleMiniGame game = chr.getMiniGame();
        if (game.isOwner(c.getPlayer())) {
            game.broadcast(MaplePacketCreator.getMiniGameSkipOwner(game));
        } else {
            game.broadcast(MaplePacketCreator.getMiniGameSkipVisitor(game));
        }
    } else if (mode == Action.MOVE_OMOK.getCode()) {
        // x point
        int x = slea.readInt();
        // y point
        int y = slea.readInt();
        // piece ( 1 or 2; Owner has one piece, visitor has another, it switches every game.)
        int type = slea.readByte();
        chr.getMiniGame().setPiece(x, y, type, c.getPlayer());
    } else if (mode == Action.SELECT_CARD.getCode()) {
        // 1st turn = 1; 2nd turn = 0
        int turn = slea.readByte();
        // slot
        int slot = slea.readByte();
        MapleMiniGame game = chr.getMiniGame();
        int firstslot = game.getFirstSlot();
        if (turn == 1) {
            game.setFirstSlot(slot);
            if (game.isOwner(c.getPlayer())) {
                game.broadcastToVisitor(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
            } else {
                game.getOwner().getClient().announce(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, turn));
            }
        } else if ((game.getCardId(firstslot + 1)) == (game.getCardId(slot + 1))) {
            if (game.isOwner(c.getPlayer())) {
                game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 2));
                game.setOwnerPoints();
            } else {
                game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 3));
                game.setVisitorPoints();
            }
        } else if (game.isOwner(c.getPlayer())) {
            game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 0));
        } else {
            game.broadcast(MaplePacketCreator.getMatchCardSelect(game, turn, slot, firstslot, 1));
        }
    } else if (mode == Action.SET_MESO.getCode()) {
        chr.getTrade().setMeso(slea.readInt());
    } else if (mode == Action.SET_ITEMS.getCode()) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
        Item item = chr.getInventory(ivType).getItem(slea.readShort());
        short quantity = slea.readShort();
        byte targetSlot = slea.readByte();
        if (quantity < 1 || quantity > item.getQuantity()) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (chr.getTrade() != null) {
            if ((quantity <= item.getQuantity() && quantity >= 0) || ItemConstants.isRechargable(item.getItemId())) {
                if (ii.isDropRestricted(item.getItemId())) {
                    // ensure that undroppable items do not make it to the trade window
                    if (!((item.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA)) {
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                }
                Item tradeItem = item.copy();
                if (ItemConstants.isRechargable(item.getItemId())) {
                    tradeItem.setQuantity(item.getQuantity());
                    MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), item.getQuantity(), true);
                } else {
                    tradeItem.setQuantity(quantity);
                    MapleInventoryManipulator.removeFromSlot(c, ivType, item.getPosition(), quantity, true);
                }
                tradeItem.setPosition(targetSlot);
                chr.getTrade().addItem(tradeItem);
            }
        }
    } else if (mode == Action.CONFIRM.getCode()) {
        MapleTrade.completeTrade(c.getPlayer());
    } else if (mode == Action.ADD_ITEM.getCode() || mode == Action.PUT_ITEM.getCode()) {
        MapleInventoryType ivType = MapleInventoryType.getByType(slea.readByte());
        short slot = slea.readShort();
        short bundles = slea.readShort();
        if (chr.getInventory(ivType).getItem(slot) == null || chr.getItemQuantity(chr.getInventory(ivType).getItem(slot).getItemId(), false) < bundles || chr.getInventory(ivType).getItem(slot).getFlag() == ItemConstants.UNTRADEABLE) {
            return;
        }
        short perBundle = slea.readShort();
        int price = slea.readInt();
        if (perBundle <= 0 || perBundle * bundles > 2000 || bundles <= 0 || price <= 0 || price > Integer.MAX_VALUE) {
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with hired merchants.");
            FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " might of possibly packet edited Hired Merchants\nperBundle: " + perBundle + "\nperBundle * bundles (This multiplied cannot be greater than 2000): " + perBundle * bundles + "\nbundles: " + bundles + "\nprice: " + price);
            return;
        }
        Item ivItem = chr.getInventory(ivType).getItem(slot);
        Item sellItem = ivItem.copy();
        if (chr.getItemQuantity(ivItem.getItemId(), false) < perBundle * bundles) {
            return;
        } else if (ServerConstants.USE_ENFORCE_UNMERCHABLE_PET && ItemConstants.isPet(ivItem.getItemId())) {
            c.announce(MaplePacketCreator.serverNotice(1, "Pets are not allowed to be sold on the Player Shop."));
            return;
        }
        sellItem.setQuantity(perBundle);
        MaplePlayerShopItem shopItem = new MaplePlayerShopItem(sellItem, bundles, price);
        MaplePlayerShop shop = chr.getPlayerShop();
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (shop != null && shop.isOwner(c.getPlayer())) {
            if (ivItem != null && ivItem.getQuantity() >= bundles * perBundle) {
                shop.addItem(shopItem);
                c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
            }
        } else if (merchant != null && merchant.isOwner(c.getPlayer())) {
            merchant.addItem(shopItem);
            c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
        }
        if (ItemConstants.isRechargable(ivItem.getItemId())) {
            MapleInventoryManipulator.removeFromSlot(c, ivType, slot, ivItem.getQuantity(), true);
        } else {
            MapleInventoryManipulator.removeFromSlot(c, ivType, slot, (short) (bundles * perBundle), true);
        }
    } else if (mode == Action.REMOVE_ITEM.getCode()) {
        MaplePlayerShop shop = chr.getPlayerShop();
        if (shop != null && shop.isOwner(c.getPlayer())) {
            int slot = slea.readShort();
            if (slot >= shop.getItems().size() || slot < 0) {
                AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a player shop.");
                FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to remove item at slot " + slot + "\r\n");
                c.disconnect(true, false);
                return;
            }
            MaplePlayerShopItem shopItem = shop.getItems().get(slot);
            Item ivItem = shopItem.getItem().copy();
            shop.removeItem(slot);
            ivItem.setQuantity(shopItem.getBundles());
            MapleInventoryManipulator.addFromDrop(c, ivItem, false);
            c.announce(MaplePacketCreator.getPlayerShopItemUpdate(shop));
        }
    } else if (mode == Action.MERCHANT_MESO.getCode()) {
    // Hmmmm
    /*if (!chr.getHiredMerchant().isOwner(chr) || chr.getMerchantMeso() < 1) return;
            int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
            if (possible > 0) {
                if (possible < chr.getMerchantMeso()) {
                    chr.gainMeso(possible, false);
                    chr.setMerchantMeso(chr.getMerchantMeso() - possible);
                } else {
                    chr.gainMeso(chr.getMerchantMeso(), false);
                    chr.setMerchantMeso(0);
                }
                c.announce(MaplePacketCreator.updateHiredMerchant(chr.getHiredMerchant(), chr));
            }*/
    } else if (mode == Action.MERCHANT_ORGANIZE.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (!merchant.isOwner(chr))
            return;
        if (chr.getMerchantMeso() > 0) {
            int possible = Integer.MAX_VALUE - chr.getMerchantMeso();
            if (possible > 0) {
                if (possible < chr.getMerchantMeso()) {
                    chr.gainMeso(possible, false);
                    chr.setMerchantMeso(chr.getMerchantMeso() - possible);
                } else {
                    chr.gainMeso(chr.getMerchantMeso(), false);
                    chr.setMerchantMeso(0);
                }
            }
        }
        for (int i = 0; i < merchant.getItems().size(); i++) {
            if (!merchant.getItems().get(i).isExist())
                merchant.removeFromSlot(i);
        }
        if (merchant.getItems().isEmpty()) {
            c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
            c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
            merchant.closeShop(c, false);
            chr.setHasMerchant(false);
            return;
        }
        c.announce(MaplePacketCreator.updateHiredMerchant(merchant, chr));
    } else if (mode == Action.BUY.getCode() || mode == Action.MERCHANT_BUY.getCode()) {
        int itemid = slea.readByte();
        short quantity = slea.readShort();
        if (quantity < 1) {
            AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with a hired merchant and or player shop.");
            FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to buy item " + itemid + " with quantity " + quantity + "\r\n");
            c.disconnect(true, false);
            return;
        }
        MaplePlayerShop shop = chr.getPlayerShop();
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (shop != null && shop.isVisitor(c.getPlayer())) {
            shop.buy(c, itemid, quantity);
            shop.broadcast(MaplePacketCreator.getPlayerShopItemUpdate(shop));
        } else if (merchant != null && !merchant.isOwner(chr)) {
            merchant.buy(c, itemid, quantity);
            merchant.broadcastToVisitorsThreadsafe(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
        }
    } else if (mode == Action.TAKE_ITEM_BACK.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (merchant != null && merchant.isOwner(c.getPlayer())) {
            int slot = slea.readShort();
            MaplePlayerShopItem shopItem = merchant.getItems().get(slot);
            if (!MapleInventory.checkSpot(chr, shopItem.getItem())) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
            if (shopItem.getBundles() > 0) {
                Item iitem = shopItem.getItem();
                iitem.setQuantity((short) (shopItem.getItem().getQuantity() * shopItem.getBundles()));
                MapleInventoryManipulator.addFromDrop(c, iitem, true);
            }
            merchant.removeFromSlot(slot);
            c.announce(MaplePacketCreator.updateHiredMerchant(merchant, c.getPlayer()));
        }
    } else if (mode == Action.CLOSE_MERCHANT.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (merchant != null && merchant.isOwner(c.getPlayer())) {
            c.announce(MaplePacketCreator.hiredMerchantOwnerLeave());
            c.announce(MaplePacketCreator.leaveHiredMerchant(0x00, 0x03));
            merchant.closeShop(c, false);
            chr.setHasMerchant(false);
        }
    } else if (mode == Action.MAINTENANCE_OFF.getCode()) {
        MapleHiredMerchant merchant = chr.getHiredMerchant();
        if (merchant != null) {
            if (merchant.getItems().isEmpty() && merchant.isOwner(c.getPlayer())) {
                merchant.closeShop(c, false);
                chr.setHasMerchant(false);
            }
            if (merchant.isOwner(c.getPlayer())) {
                merchant.clearMessages();
                merchant.setOpen(true);
            }
        }
        chr.setHiredMerchant(null);
        c.announce(MaplePacketCreator.enableActions());
    } else if (mode == Action.BAN_PLAYER.getCode()) {
        slea.skip(1);
        if (chr.getPlayerShop() != null && chr.getPlayerShop().isOwner(c.getPlayer())) {
            chr.getPlayerShop().banPlayer(slea.readMapleAsciiString());
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) MapleHiredMerchant(server.maps.MapleHiredMerchant) MaplePlayerShop(server.maps.MaplePlayerShop) MapleMapObject(server.maps.MapleMapObject) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Item(client.inventory.Item) MapleInventoryType(client.inventory.MapleInventoryType) MapleMiniGame(server.maps.MapleMiniGame) MapleItemInformationProvider(server.MapleItemInformationProvider) MaplePlayerShopItem(server.maps.MaplePlayerShopItem)

Example 5 with MapleHiredMerchant

use of server.maps.MapleHiredMerchant in project HeavenMS by ronancpl.

the class World method getAvailableItemBundles.

public List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> getAvailableItemBundles(int itemid) {
    List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> hmsAvailable = new ArrayList<>();
    for (MapleHiredMerchant hm : getActiveMerchants()) {
        List<MaplePlayerShopItem> itemBundles = hm.sendAvailableBundles(itemid);
        for (MaplePlayerShopItem mpsi : itemBundles) {
            hmsAvailable.add(new Pair<>(mpsi, (AbstractMapleMapObject) hm));
        }
    }
    for (MaplePlayerShop ps : getActivePlayerShops()) {
        List<MaplePlayerShopItem> itemBundles = ps.sendAvailableBundles(itemid);
        for (MaplePlayerShopItem mpsi : itemBundles) {
            hmsAvailable.add(new Pair<>(mpsi, (AbstractMapleMapObject) ps));
        }
    }
    Collections.sort(hmsAvailable, new Comparator<Pair<MaplePlayerShopItem, AbstractMapleMapObject>>() {

        @Override
        public int compare(Pair<MaplePlayerShopItem, AbstractMapleMapObject> p1, Pair<MaplePlayerShopItem, AbstractMapleMapObject> p2) {
            return p1.getLeft().getPrice() - p2.getLeft().getPrice();
        }
    });
    // truncates the list to have up to 200 elements
    hmsAvailable.subList(0, Math.min(hmsAvailable.size(), 200));
    return hmsAvailable;
}
Also used : MapleHiredMerchant(server.maps.MapleHiredMerchant) ArrayList(java.util.ArrayList) MaplePlayerShop(server.maps.MaplePlayerShop) AbstractMapleMapObject(server.maps.AbstractMapleMapObject) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Pair(tools.Pair)

Aggregations

MapleHiredMerchant (server.maps.MapleHiredMerchant)8 MaplePlayerShop (server.maps.MaplePlayerShop)4 MapleCharacter (client.MapleCharacter)3 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)3 ArrayList (java.util.ArrayList)2 CharacterIdChannelPair (net.server.channel.CharacterIdChannelPair)2 AbstractMapleMapObject (server.maps.AbstractMapleMapObject)2 Pair (tools.Pair)2 Item (client.inventory.Item)1 MapleInventoryType (client.inventory.MapleInventoryType)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MapleItemInformationProvider (server.MapleItemInformationProvider)1 MapleMap (server.maps.MapleMap)1 MapleMapObject (server.maps.MapleMapObject)1 MapleMiniGame (server.maps.MapleMiniGame)1 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)1