Search in sources :

Example 6 with ItemPrice

use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.

the class ItemManager method getItemPriceAsync.

/**
 * Look up an item's price asynchronously.
 *
 * @param itemId item id
 * @return the price, or null if the price is not yet loaded
 */
public ItemPrice getItemPriceAsync(int itemId) {
    ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
    if (itemPrice != null && itemPrice != EMPTY) {
        return itemPrice == NONE ? null : itemPrice;
    }
    itemPriceCache.refresh(itemId);
    return null;
}
Also used : ItemPrice(net.runelite.http.api.item.ItemPrice)

Example 7 with ItemPrice

use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.

the class ItemManager method getItemPrice.

/**
 * Look up an item's price synchronously
 *
 * @param itemId item id
 * @return item price
 * @throws IOException
 */
public ItemPrice getItemPrice(int itemId) throws IOException {
    ItemPrice itemPrice = itemPriceCache.getIfPresent(itemId);
    if (itemPrice != null && itemPrice != EMPTY) {
        return itemPrice == NONE ? null : itemPrice;
    }
    itemPrice = itemClient.lookupItemPrice(itemId);
    if (itemPrice == null) {
        itemPriceCache.put(itemId, NONE);
        return null;
    }
    itemPriceCache.put(itemId, itemPrice);
    return itemPrice;
}
Also used : ItemPrice(net.runelite.http.api.item.ItemPrice)

Example 8 with ItemPrice

use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.

the class ItemController method prices.

@RequestMapping("/price")
public ItemPrice[] prices(@RequestParam("id") int[] itemIds) {
    if (itemIds.length > MAX_BATCH_LOOKUP) {
        itemIds = Arrays.copyOf(itemIds, MAX_BATCH_LOOKUP);
    }
    List<ItemPrice> itemPrices = new ArrayList<>(itemIds.length);
    for (int itemId : itemIds) {
        ItemEntry item = itemService.getItem(itemId);
        PriceEntry priceEntry = itemService.getPrice(itemId, null);
        if (item == null || priceEntry == null) {
            continue;
        }
        ItemPrice itemPrice = new ItemPrice();
        itemPrice.setItem(item.toItem());
        itemPrice.setPrice(priceEntry.getPrice());
        itemPrice.setTime(priceEntry.getTime());
        itemPrices.add(itemPrice);
    }
    return itemPrices.toArray(new ItemPrice[itemPrices.size()]);
}
Also used : ItemPrice(net.runelite.http.api.item.ItemPrice) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ItemPrice

use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.

the class GroundItemsPlugin method buildGroundItem.

@Nullable
private GroundItem buildGroundItem(final Tile tile, final Item item) {
    // Collect the data for the item
    final int itemId = item.getId();
    final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
    final int realItemId = itemComposition.getNote() != -1 ? itemComposition.getLinkedNoteId() : itemId;
    final int alchPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT);
    final String name = itemComposition.getName();
    final boolean hidden = isHidden(name);
    if (!isHotKeyPressed() && hidden) {
        return null;
    }
    final boolean highlighted = isHighlighted(name);
    if (config.showHighlightedOnly() && !isHotKeyPressed() && !highlighted) {
        return null;
    }
    final GroundItem groundItem = GroundItem.builder().id(itemId).location(tile.getWorldLocation()).itemId(realItemId).quantity(item.getQuantity()).name(itemComposition.getName()).haPrice(alchPrice * item.getQuantity()).build();
    // Set the correct item price
    if (realItemId == COINS) {
        groundItem.setHaPrice(item.getQuantity());
        groundItem.setGePrice(item.getQuantity());
    } else {
        final ItemPrice itemPrice = itemManager.getItemPriceAsync(realItemId);
        groundItem.setGePrice(itemPrice != null ? itemPrice.getPrice() * item.getQuantity() : 0);
    }
    return groundItem;
}
Also used : ItemPrice(net.runelite.http.api.item.ItemPrice) ItemComposition(net.runelite.api.ItemComposition) LocalPoint(net.runelite.api.coords.LocalPoint) Nullable(javax.annotation.Nullable)

Example 10 with ItemPrice

use of net.runelite.http.api.item.ItemPrice in project runelite by runelite.

the class GroundItemsPlugin method onMenuEntryAdded.

@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event) {
    if ((config.highlightMenuOption() || config.highlightMenuItemName()) && event.getOption().equals("Take") && event.getType() == MenuAction.GROUND_ITEM_THIRD_OPTION.getId()) {
        int itemId = event.getIdentifier();
        ItemComposition itemComposition = client.getItemDefinition(itemId);
        if (isHidden(itemComposition.getName())) {
            return;
        }
        Region region = client.getRegion();
        Tile tile = region.getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()];
        ItemLayer itemLayer = tile.getItemLayer();
        if (itemLayer == null) {
            return;
        }
        MenuEntry[] menuEntries = client.getMenuEntries();
        MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
        int quantity = 1;
        Node current = itemLayer.getBottom();
        while (current instanceof Item) {
            Item item = (Item) current;
            if (item.getId() == itemId) {
                quantity = item.getQuantity();
            }
            current = current.getNext();
        }
        ItemPrice itemPrice = getItemPrice(itemComposition);
        int price = itemPrice == null ? itemComposition.getPrice() : itemPrice.getPrice();
        int cost = quantity * price;
        Color color = overlay.getCostColor(cost, isHighlighted(itemComposition.getName()), isHidden(itemComposition.getName()));
        if (!color.equals(config.defaultColor())) {
            String hexColor = Integer.toHexString(color.getRGB() & 0xFFFFFF);
            String colTag = "<col=" + hexColor + ">";
            if (config.highlightMenuOption()) {
                lastEntry.setOption(colTag + "Take");
            }
            if (config.highlightMenuItemName()) {
                String target = lastEntry.getTarget().substring(lastEntry.getTarget().indexOf(">") + 1);
                lastEntry.setTarget(colTag + target);
            }
        }
        if (config.showMenuItemQuantities() && itemComposition.isStackable() && quantity > 1) {
            lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")");
        }
        client.setMenuEntries(menuEntries);
    }
}
Also used : ItemLayer(net.runelite.api.ItemLayer) Item(net.runelite.api.Item) MenuEntry(net.runelite.api.MenuEntry) Node(net.runelite.api.Node) Color(java.awt.Color) ItemPrice(net.runelite.http.api.item.ItemPrice) ItemComposition(net.runelite.api.ItemComposition) Region(net.runelite.api.Region) Tile(net.runelite.api.Tile) LocalPoint(net.runelite.api.coords.LocalPoint) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

ItemPrice (net.runelite.http.api.item.ItemPrice)12 ItemComposition (net.runelite.api.ItemComposition)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)3 LocalPoint (net.runelite.api.coords.LocalPoint)2 ChatMessageBuilder (net.runelite.client.chat.ChatMessageBuilder)2 Item (net.runelite.http.api.item.Item)2 SearchResult (net.runelite.http.api.item.SearchResult)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Subscribe (com.google.common.eventbus.Subscribe)1 Color (java.awt.Color)1 BufferedImage (java.awt.image.BufferedImage)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Nullable (javax.annotation.Nullable)1 Item (net.runelite.api.Item)1 ItemLayer (net.runelite.api.ItemLayer)1