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;
}
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();
}
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();
}
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();
}
Aggregations