Search in sources :

Example 6 with ItemComposition

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

the class EmoteClue method makeOverlayHint.

@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin) {
    panelComponent.setTitle("Emote Clue");
    panelComponent.getLines().add(new PanelComponent.Line("Emotes:"));
    panelComponent.getLines().add(new PanelComponent.Line(getFirstEmote().getName(), TITLED_CONTENT_COLOR));
    if (getSecondEmote() != null) {
        panelComponent.getLines().add(new PanelComponent.Line(getSecondEmote().getName(), TITLED_CONTENT_COLOR));
    }
    if (getItemIds().length != 0) {
        panelComponent.setWidth(160);
        panelComponent.getLines().add(new PanelComponent.Line("Equip:"));
        if (plugin.getEquippedItems() != null) {
            for (int itemId : getItemIds()) {
                ItemComposition itemDefinition = plugin.getClient().getItemDefinition(itemId);
                if (itemDefinition != null) {
                    if (plugin.getEquippedItems().contains(itemId)) {
                        panelComponent.getLines().add(new PanelComponent.Line(itemDefinition.getName(), TITLED_CONTENT_COLOR, "X", Color.GREEN));
                    } else {
                        panelComponent.getLines().add(new PanelComponent.Line(itemDefinition.getName(), TITLED_CONTENT_COLOR, "-", Color.RED));
                    }
                }
            }
        }
    } else {
        panelComponent.setWidth(130);
        panelComponent.getLines().add(new PanelComponent.Line("Items:", "None"));
    }
}
Also used : PanelComponent(net.runelite.client.ui.overlay.components.PanelComponent) ItemComposition(net.runelite.api.ItemComposition) LocalPoint(net.runelite.api.coords.LocalPoint) WorldPoint(net.runelite.api.coords.WorldPoint)

Example 7 with ItemComposition

use of net.runelite.api.ItemComposition 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 8 with ItemComposition

use of net.runelite.api.ItemComposition 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)

Example 9 with ItemComposition

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

the class ChatCommandsPlugin method itemPriceLookup.

/**
 * Looks up the item price and changes the original message to the
 * response.
 *
 * @param messageNode The chat message containing the command.
 * @param search The item given with the command.
 */
private void itemPriceLookup(MessageNode messageNode, String search) {
    SearchResult result;
    try {
        result = itemManager.searchForItem(search);
    } catch (ExecutionException ex) {
        log.warn("Unable to search for item {}", search, ex);
        return;
    }
    if (result != null && !result.getItems().isEmpty()) {
        Item item = retrieveFromList(result.getItems(), search);
        if (item == null) {
            log.debug("Unable to find item {} in result {}", search, result);
            return;
        }
        int itemId = item.getId();
        ItemPrice itemPrice;
        try {
            itemPrice = itemManager.getItemPrice(itemId);
        } catch (IOException ex) {
            log.warn("Unable to fetch item price for {}", itemId, ex);
            return;
        }
        final ChatMessageBuilder builder = new ChatMessageBuilder().append(ChatColorType.NORMAL).append("Price of ").append(ChatColorType.HIGHLIGHT).append(item.getName()).append(ChatColorType.NORMAL).append(": GE average ").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(itemPrice.getPrice()));
        ItemComposition itemComposition = itemManager.getItemComposition(itemId);
        if (itemComposition != null) {
            int alchPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT);
            builder.append(ChatColorType.NORMAL).append(" HA value ").append(ChatColorType.HIGHLIGHT).append(StackFormatter.formatNumber(alchPrice));
        }
        String response = builder.build();
        log.debug("Setting response {}", response);
        messageNode.setRuneLiteFormatMessage(response);
        chatMessageManager.update(messageNode);
        client.refreshChat();
    }
}
Also used : Item(net.runelite.http.api.item.Item) ItemPrice(net.runelite.http.api.item.ItemPrice) ItemComposition(net.runelite.api.ItemComposition) SearchResult(net.runelite.http.api.item.SearchResult) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ChatMessageBuilder(net.runelite.client.chat.ChatMessageBuilder)

Example 10 with ItemComposition

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

the class GrandExchangePlugin method startUp.

@Override
protected void startUp() throws IOException {
    panel = injector.getInstance(GrandExchangePanel.class);
    BufferedImage icon;
    synchronized (ImageIO.class) {
        icon = ImageIO.read(getClass().getResourceAsStream("ge_icon.png"));
    }
    button = NavigationButton.builder().name("GE Offers").icon(icon).panel(panel).build();
    pluginToolbar.addNavigation(button);
    itemClick = new MouseListener() {

        @Override
        public MouseEvent mouseClicked(MouseEvent e) {
            // Check if left click + alt
            if (e.getButton() == MouseEvent.BUTTON1 && e.isAltDown()) {
                Point mousePosition = client.getMouseCanvasPosition();
                Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
                if (inventoryWidget != null && !inventoryWidget.isHidden()) {
                    for (WidgetItem item : inventoryWidget.getWidgetItems()) {
                        if (item.getCanvasBounds().contains(mousePosition.getX(), mousePosition.getY())) {
                            ItemComposition itemComp = client.getItemDefinition(item.getId());
                            if (itemComp != null) {
                                e.consume();
                                SwingUtilities.invokeLater(() -> {
                                    panel.showSearch();
                                    if (!button.isSelected()) {
                                        button.getOnSelect().run();
                                    }
                                    panel.getSearchPanel().priceLookup(itemComp.getName());
                                });
                            }
                            break;
                        }
                    }
                }
            }
            return super.mouseClicked(e);
        }
    };
    if (config.quickLookup()) {
        mouseManager.registerMouseListener(itemClick);
    }
}
Also used : MouseListener(net.runelite.client.input.MouseListener) MouseEvent(java.awt.event.MouseEvent) Widget(net.runelite.api.widgets.Widget) ItemComposition(net.runelite.api.ItemComposition) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(net.runelite.api.Point) BufferedImage(java.awt.image.BufferedImage) ImageIO(javax.imageio.ImageIO)

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