Search in sources :

Example 1 with AbstractMapleMapObject

use of server.maps.AbstractMapleMapObject 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 2 with AbstractMapleMapObject

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

Aggregations

AbstractMapleMapObject (server.maps.AbstractMapleMapObject)2 MapleHiredMerchant (server.maps.MapleHiredMerchant)2 MaplePlayerShop (server.maps.MaplePlayerShop)2 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)2 MapleCharacter (client.MapleCharacter)1 ArrayList (java.util.ArrayList)1 CharacterIdChannelPair (net.server.channel.CharacterIdChannelPair)1 Pair (tools.Pair)1 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)1