Search in sources :

Example 1 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class BankCalculation method calculate.

/**
 * Calculate the bank based on the cache, price can be 0 if bank not active, or cache not set
 */
void calculate() {
    Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
    // Don't update on a search because rs seems to constantly update the title
    if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden() || widgetBankTitleBar.getText().contains("Showing")) {
        return;
    }
    WidgetItem[] widgetItems = new BankItemQuery().result(client);
    if (widgetItems.length == 0 || !isBankDifferent(widgetItems)) {
        return;
    }
    log.debug("Calculating new bank value...");
    gePrice = haPrice = 0;
    finished = false;
    List<ItemComposition> itemCompositions = new ArrayList<>();
    Map<Integer, WidgetItem> itemMap = new HashMap<>();
    List<Integer> itemIds = new ArrayList<>();
    // Generate our lists (and do some quick price additions)
    for (WidgetItem widgetItem : widgetItems) {
        if (widgetItem.getId() <= 0 || widgetItem.getQuantity() == 0) {
            continue;
        }
        if (widgetItem.getId() == COINS_995) {
            gePrice += widgetItem.getQuantity();
            haPrice += widgetItem.getQuantity();
            continue;
        }
        if (widgetItem.getId() == PLATINUM_TOKEN) {
            gePrice += widgetItem.getQuantity() * 1000;
            haPrice += widgetItem.getQuantity() * 1000;
            continue;
        }
        ItemComposition itemComposition = itemManager.getItemComposition(widgetItem.getId());
        itemCompositions.add(itemComposition);
        itemMap.put(widgetItem.getId(), widgetItem);
        if (config.showGE()) {
            itemIds.add(widgetItem.getId());
        }
    }
    // Now do the calculations
    if (config.showGE() && !itemIds.isEmpty()) {
        CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemIds);
        future.whenComplete((ItemPrice[] itemPrices, Throwable ex) -> {
            if (ex != null) {
                log.debug("Error looking up item prices", ex);
                return;
            }
            if (itemPrices == null) {
                log.debug("Error looking up item prices");
                return;
            }
            log.debug("Price lookup is complete. {} prices.", itemPrices.length);
            try {
                for (ItemPrice itemPrice : itemPrices) {
                    if (itemPrice.getItem() == null) {
                        // cached no price
                        continue;
                    }
                    gePrice += itemPrice.getPrice() * itemMap.get(itemPrice.getItem().getId()).getQuantity();
                }
            } catch (Exception ex2) {
                log.warn("error calculating price", ex2);
            } finally {
                finished = true;
            }
        });
    } else {
        finished = true;
    }
    if (config.showHA()) {
        for (ItemComposition itemComposition : itemCompositions) {
            int price = itemComposition.getPrice();
            if (price > 0) {
                haPrice += Math.round(price * HIGH_ALCHEMY_CONSTANT) * itemMap.get(itemComposition.getId()).getQuantity();
            }
        }
    }
}
Also used : BankItemQuery(net.runelite.api.queries.BankItemQuery) HashMap(java.util.HashMap) Widget(net.runelite.api.widgets.Widget) ArrayList(java.util.ArrayList) ItemPrice(net.runelite.http.api.item.ItemPrice) WidgetItem(net.runelite.api.widgets.WidgetItem) ItemComposition(net.runelite.api.ItemComposition)

Example 2 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class ItemPricesOverlay method getItemStackValueText.

private String getItemStackValueText(Item item) {
    int id = item.getId();
    int qty = item.getQuantity();
    // Special case for coins and platinum tokens
    if (id == ItemID.COINS_995) {
        return StackFormatter.formatNumber(qty) + " gp";
    } else if (id == ItemID.PLATINUM_TOKEN) {
        return StackFormatter.formatNumber(qty * 1000) + " gp";
    }
    final ItemComposition itemDef = itemManager.getItemComposition(id);
    // Only check prices for things with store prices
    if (itemDef.getPrice() <= 0) {
        return null;
    }
    int gePrice = 0;
    int haPrice = 0;
    if (config.showGEPrice()) {
        final ItemPrice price = itemManager.getItemPriceAsync(id);
        if (price != null) {
            gePrice = price.getPrice();
        }
    }
    if (config.showHAValue()) {
        haPrice = Math.round(itemDef.getPrice() * HIGH_ALCHEMY_CONSTANT);
    }
    if (gePrice > 0 || haPrice > 0) {
        return stackValueText(qty, gePrice, haPrice);
    }
    return null;
}
Also used : ItemPrice(net.runelite.http.api.item.ItemPrice) ItemComposition(net.runelite.api.ItemComposition)

Example 3 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class MenuEntrySwapperPlugin method cycleItemShiftClickAction.

public void cycleItemShiftClickAction(WidgetItem item, int mouseClick) {
    ItemComposition itemComposition = client.getItemDefinition(item.getId());
    if (mouseClick == MouseEvent.BUTTON1) {
        String[] actions = itemComposition.getInventoryActions();
        int shiftClickActionIndex = itemComposition.getShiftClickActionIndex();
        int nextActionIndex = getNextActionIndex(actions, shiftClickActionIndex);
        setSwapConfig(item.getId(), nextActionIndex);
        itemComposition.setShiftClickActionIndex(nextActionIndex);
    } else if (mouseClick == MouseEvent.BUTTON3) {
        unsetSwapConfig(item.getId());
        itemComposition.resetShiftClickActionIndex();
    }
}
Also used : ItemComposition(net.runelite.api.ItemComposition) PostItemComposition(net.runelite.api.events.PostItemComposition)

Example 4 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class MenuEntrySwapperPlugin method onPostItemComposition.

@Subscribe
public void onPostItemComposition(PostItemComposition event) {
    ItemComposition itemComposition = event.getItemComposition();
    Integer option = getSwapConfig(itemComposition.getId());
    if (option != null) {
        itemComposition.setShiftClickActionIndex(option);
        // Update our cached item composition too
        ItemComposition ourItemComposition = itemManager.getItemComposition(itemComposition.getId());
        ourItemComposition.setShiftClickActionIndex(option);
    }
}
Also used : ItemComposition(net.runelite.api.ItemComposition) PostItemComposition(net.runelite.api.events.PostItemComposition) Subscribe(com.google.common.eventbus.Subscribe)

Example 5 with ItemComposition

use of net.runelite.api.ItemComposition in project runelite by runelite.

the class ShiftClickConfigurationOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if (!plugin.isConfiguringShiftClick() || client.isMenuOpen() || client.getWidget(WidgetInfo.INVENTORY).isHidden()) {
        return null;
    }
    Font font = FontManager.getRunescapeSmallFont();
    graphics.setFont(font);
    net.runelite.api.Point mouseCanvasPosition = client.getMouseCanvasPosition();
    Point mousePoint = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY());
    for (WidgetItem item : plugin.getInventoryItems()) {
        final Rectangle bounds = item.getCanvasBounds();
        if (!bounds.contains(mousePoint)) {
            continue;
        }
        ItemComposition itemComposition = client.getItemDefinition(item.getId());
        String[] actions = itemComposition.getInventoryActions();
        int index = itemComposition.getShiftClickActionIndex();
        if (index >= 0 && actions[index] == null) {
            continue;
        }
        String action = index == -1 ? "Use" : actions[index];
        int textWidth = graphics.getFontMetrics().stringWidth(action);
        int textLocationX = (int) (bounds.x + bounds.getWidth() / 2 - textWidth / 2);
        int textLocationY = bounds.y + 28;
        final TextComponent textComponent = new TextComponent();
        textComponent.setPosition(new Point(textLocationX, textLocationY));
        textComponent.setText(action);
        textComponent.render(graphics);
    }
    return null;
}
Also used : TextComponent(net.runelite.client.ui.overlay.components.TextComponent) Rectangle(java.awt.Rectangle) ItemComposition(net.runelite.api.ItemComposition) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(java.awt.Point) Font(java.awt.Font) Point(java.awt.Point)

Aggregations

ItemComposition (net.runelite.api.ItemComposition)13 ItemPrice (net.runelite.http.api.item.ItemPrice)6 WidgetItem (net.runelite.api.widgets.WidgetItem)4 Subscribe (com.google.common.eventbus.Subscribe)3 BufferedImage (java.awt.image.BufferedImage)3 LocalPoint (net.runelite.api.coords.LocalPoint)3 Widget (net.runelite.api.widgets.Widget)3 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 PostItemComposition (net.runelite.api.events.PostItemComposition)2 Item (net.runelite.http.api.item.Item)2 SearchResult (net.runelite.http.api.item.SearchResult)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 MouseEvent (java.awt.event.MouseEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1