Search in sources :

Example 6 with MaplePlayerShopItem

use of server.maps.MaplePlayerShopItem 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)

Example 7 with MaplePlayerShopItem

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

the class MaplePacketCreator method owlOfMinerva.

public static byte[] owlOfMinerva(MapleClient c, int itemid, List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> hmsAvailable) {
    byte itemType = ItemConstants.getInventoryType(itemid).getType();
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    // header.
    mplew.writeShort(SendOpcode.SHOP_SCANNER_RESULT.getValue());
    mplew.write(6);
    mplew.writeInt(0);
    mplew.writeInt(itemid);
    mplew.writeInt(hmsAvailable.size());
    for (Pair<MaplePlayerShopItem, AbstractMapleMapObject> hme : hmsAvailable) {
        MaplePlayerShopItem item = hme.getLeft();
        AbstractMapleMapObject mo = hme.getRight();
        if (mo instanceof MaplePlayerShop) {
            MaplePlayerShop ps = (MaplePlayerShop) mo;
            MapleCharacter owner = ps.getOwner();
            mplew.writeMapleAsciiString(owner.getName());
            mplew.writeInt(owner.getMapId());
            mplew.writeMapleAsciiString(ps.getDescription());
            mplew.writeInt(item.getBundles());
            mplew.writeInt(item.getItem().getQuantity());
            mplew.writeInt(item.getPrice());
            mplew.writeInt(owner.getId());
            mplew.write(owner.getClient().getChannel() - 1);
        } else {
            MapleHiredMerchant hm = (MapleHiredMerchant) mo;
            mplew.writeMapleAsciiString(hm.getOwner());
            mplew.writeInt(hm.getMapId());
            mplew.writeMapleAsciiString(hm.getDescription());
            mplew.writeInt(item.getBundles());
            mplew.writeInt(item.getItem().getQuantity());
            mplew.writeInt(item.getPrice());
            mplew.writeInt(hm.getOwnerId());
            mplew.write(hm.getChannel() - 1);
        }
        mplew.write(itemType);
        if (itemType == MapleInventoryType.EQUIP.getType()) {
            addItemInfo(mplew, item.getItem(), true);
        }
    }
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MapleCharacter(client.MapleCharacter) MapleHiredMerchant(server.maps.MapleHiredMerchant) MaplePlayerShop(server.maps.MaplePlayerShop) AbstractMapleMapObject(server.maps.AbstractMapleMapObject) MaplePlayerShopItem(server.maps.MaplePlayerShopItem)

Example 8 with MaplePlayerShopItem

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

the class MaplePacketCreator method getPlayerShop.

/**
 * @param c
 * @param shop
 * @param owner
 * @return
 */
public static byte[] getPlayerShop(MaplePlayerShop shop, boolean owner) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.PLAYER_INTERACTION.getValue());
    mplew.write(PlayerInteractionHandler.Action.ROOM.getCode());
    mplew.write(4);
    mplew.write(4);
    mplew.write(owner ? 0 : 1);
    mplew.write(0);
    addCharLook(mplew, shop.getOwner(), false);
    mplew.writeMapleAsciiString(shop.getOwner().getName());
    MapleCharacter[] visitors = shop.getVisitors();
    for (int i = 0; i < 3; i++) {
        if (visitors[i] != null) {
            mplew.write(i + 1);
            addCharLook(mplew, visitors[i], false);
            mplew.writeMapleAsciiString(visitors[i].getName());
        }
    }
    mplew.write(0xFF);
    mplew.writeMapleAsciiString(shop.getDescription());
    List<MaplePlayerShopItem> items = shop.getItems();
    mplew.write(0x10);
    mplew.write(items.size());
    for (MaplePlayerShopItem item : items) {
        mplew.writeShort(item.getBundles());
        mplew.writeShort(item.getItem().getQuantity());
        mplew.writeInt(item.getPrice());
        addItemInfo(mplew, item.getItem(), true);
    }
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MapleCharacter(client.MapleCharacter) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Point(java.awt.Point)

Example 9 with MaplePlayerShopItem

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

the class MaplePacketCreator method getPlayerShopItemUpdate.

public static byte[] getPlayerShopItemUpdate(MaplePlayerShop shop) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.PLAYER_INTERACTION.getValue());
    mplew.write(PlayerInteractionHandler.Action.UPDATE_MERCHANT.getCode());
    mplew.write(shop.getItems().size());
    for (MaplePlayerShopItem item : shop.getItems()) {
        mplew.writeShort(item.getBundles());
        mplew.writeShort(item.getItem().getQuantity());
        mplew.writeInt(item.getPrice());
        addItemInfo(mplew, item.getItem(), true);
    }
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MaplePlayerShopItem(server.maps.MaplePlayerShopItem)

Aggregations

MaplePlayerShopItem (server.maps.MaplePlayerShopItem)9 MapleCharacter (client.MapleCharacter)5 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)5 MaplePlayerShop (server.maps.MaplePlayerShop)4 Item (client.inventory.Item)3 MapleHiredMerchant (server.maps.MapleHiredMerchant)3 MapleInventoryType (client.inventory.MapleInventoryType)2 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 MapleItemInformationProvider (server.MapleItemInformationProvider)2 AbstractMapleMapObject (server.maps.AbstractMapleMapObject)2 Pair (tools.Pair)2 MapleClient (client.MapleClient)1 MapleJob (client.MapleJob)1 Skill (client.Skill)1 Equip (client.inventory.Equip)1 ScrollResult (client.inventory.Equip.ScrollResult)1 MaplePet (client.inventory.MaplePet)1 ModifyInventory (client.inventory.ModifyInventory)1 SQLException (java.sql.SQLException)1