Search in sources :

Example 1 with ItemContainer

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

the class PuzzleSolverOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if ((!config.displaySolution() && !config.displayRemainingMoves()) || client.getGameState() != GameState.LOGGED_IN) {
        return null;
    }
    ItemContainer container = client.getItemContainer(InventoryID.PUZZLE_BOX);
    if (container == null) {
        return null;
    }
    Widget puzzleBox = client.getWidget(WidgetInfo.PUZZLE_BOX);
    if (puzzleBox == null) {
        return null;
    }
    net.runelite.api.Point puzzleBoxLocation = puzzleBox.getCanvasLocation();
    String infoString = "Solving..";
    int[] itemIds = getItemIds(container);
    boolean shouldCache = false;
    if (solver != null) {
        if (solver.hasFailed()) {
            infoString = "The puzzle could not be solved";
        } else {
            if (solver.hasSolution()) {
                boolean foundPosition = false;
                // Find the current state by looking at the current step and then the next 5 steps
                for (int i = 0; i < 6; i++) {
                    int j = solver.getPosition() + i;
                    if (j == solver.getStepCount()) {
                        break;
                    }
                    PuzzleState currentState = solver.getStep(j);
                    // If this is false, player has moved the empty tile
                    if (currentState != null && currentState.hasPieces(itemIds)) {
                        foundPosition = true;
                        solver.setPosition(j);
                        if (i > 0) {
                            shouldCache = true;
                        }
                        break;
                    }
                }
                // see if we can find the current state in the 5 previous steps
                if (!foundPosition) {
                    for (int i = 1; i < 6; i++) {
                        int j = solver.getPosition() - i;
                        if (j < 0) {
                            break;
                        }
                        PuzzleState currentState = solver.getStep(j);
                        if (currentState != null && currentState.hasPieces(itemIds)) {
                            foundPosition = true;
                            shouldCache = true;
                            solver.setPosition(j);
                            break;
                        }
                    }
                }
                if (foundPosition) {
                    int stepsLeft = solver.getStepCount() - solver.getPosition() - 1;
                    if (stepsLeft == 0) {
                        infoString = "Solved!";
                    } else if (config.displayRemainingMoves()) {
                        infoString = "Moves left: " + stepsLeft;
                    } else {
                        infoString = null;
                    }
                    if (config.displaySolution()) {
                        if (config.drawDots()) {
                            graphics.setColor(Color.YELLOW);
                            // Display the next 4 steps
                            for (int i = 1; i < 5; i++) {
                                int j = solver.getPosition() + i;
                                if (j >= solver.getStepCount()) {
                                    break;
                                }
                                PuzzleState futureMove = solver.getStep(j);
                                if (futureMove == null) {
                                    break;
                                }
                                int blankX = futureMove.getEmptyPiece() % DIMENSION;
                                int blankY = futureMove.getEmptyPiece() / DIMENSION;
                                int markerSize = DOT_MARKER_SIZE - i * 3;
                                int x = puzzleBoxLocation.getX() + blankX * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - markerSize / 2;
                                int y = puzzleBoxLocation.getY() + blankY * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - markerSize / 2;
                                graphics.fillOval(x, y, markerSize, markerSize);
                            }
                        } else {
                            // Find the current blank tile position
                            PuzzleState currentMove = solver.getStep(solver.getPosition());
                            int lastBlankX = currentMove.getEmptyPiece() % DIMENSION;
                            int lastBlankY = currentMove.getEmptyPiece() / DIMENSION;
                            // Display the next 3 steps
                            for (int i = 1; i < 4; i++) {
                                int j = solver.getPosition() + i;
                                if (j >= solver.getStepCount()) {
                                    break;
                                }
                                PuzzleState futureMove = solver.getStep(j);
                                if (futureMove == null) {
                                    break;
                                }
                                int blankX = futureMove.getEmptyPiece() % DIMENSION;
                                int blankY = futureMove.getEmptyPiece() / DIMENSION;
                                int xDelta = blankX - lastBlankX;
                                int yDelta = blankY - lastBlankY;
                                BufferedImage arrow;
                                if (xDelta > 0) {
                                    arrow = getRightArrow();
                                } else if (xDelta < 0) {
                                    arrow = getLeftArrow();
                                } else if (yDelta > 0) {
                                    arrow = getDownArrow();
                                } else {
                                    arrow = getUpArrow();
                                }
                                int x = puzzleBoxLocation.getX() + blankX * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - arrow.getWidth() / 2;
                                int y = puzzleBoxLocation.getY() + blankY * PUZZLE_TILE_SIZE + PUZZLE_TILE_SIZE / 2 - arrow.getHeight() / 2;
                                OverlayUtil.renderImageLocation(graphics, new net.runelite.api.Point(x, y), arrow);
                                lastBlankX = blankX;
                                lastBlankY = blankY;
                            }
                        }
                    }
                }
            }
        }
    }
    // Draw info box
    if (infoString != null) {
        int x = puzzleBoxLocation.getX() + puzzleBox.getWidth() / 2 - INFO_BOX_WIDTH / 2;
        int y = puzzleBoxLocation.getY() - INFO_BOX_OFFSET_Y;
        FontMetrics fm = graphics.getFontMetrics();
        int height = INFO_BOX_TOP_BORDER + fm.getHeight() + INFO_BOX_BOTTOM_BORDER;
        BackgroundComponent backgroundComponent = new BackgroundComponent();
        backgroundComponent.setRectangle(new Rectangle(x, y, INFO_BOX_WIDTH, height));
        backgroundComponent.render(graphics);
        int textOffsetX = (INFO_BOX_WIDTH - fm.stringWidth(infoString)) / 2;
        int textOffsetY = fm.getHeight();
        TextComponent textComponent = new TextComponent();
        textComponent.setPosition(new Point(x + textOffsetX, y + textOffsetY));
        textComponent.setText(infoString);
        textComponent.render(graphics);
    }
    // Solve the puzzle if we don't have an up to date solution
    if (solver == null || cachedItems == null || (!shouldCache && !Arrays.equals(cachedItems, itemIds))) {
        solve(itemIds);
        shouldCache = true;
    }
    if (shouldCache) {
        cacheItems(itemIds);
    }
    return null;
}
Also used : ItemContainer(net.runelite.api.ItemContainer) TextComponent(net.runelite.client.ui.overlay.components.TextComponent) PuzzleState(net.runelite.client.plugins.puzzlesolver.solver.PuzzleState) Widget(net.runelite.api.widgets.Widget) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) BackgroundComponent(net.runelite.client.ui.overlay.components.BackgroundComponent) FontMetrics(java.awt.FontMetrics)

Example 2 with ItemContainer

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

the class BankTagsPlugin method onMenuOptionClicked.

@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event) {
    if (event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId() && event.getMenuAction() == MenuAction.EXAMINE_ITEM_BANK_EQ && event.getId() == EDIT_TAGS_MENU_INDEX) {
        int inventoryIndex = event.getActionParam();
        ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK);
        if (bankContainer == null) {
            return;
        }
        Item[] items = bankContainer.getItems();
        if (inventoryIndex < 0 || inventoryIndex >= items.length) {
            return;
        }
        Item item = bankContainer.getItems()[inventoryIndex];
        if (item == null) {
            return;
        }
        int itemId = item.getId();
        String itemName = itemManager.getItemComposition(itemId).getName();
        String initialValue = getTags(itemId);
        chatboxInputManager.openInputWindow(itemName + " Tags", initialValue, (newTags) -> {
            if (newTags == null) {
                return;
            }
            setTags(itemId, newTags);
            Widget bankContainerWidget = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
            if (bankContainerWidget == null) {
                return;
            }
            Widget[] bankItemWidgets = bankContainerWidget.getDynamicChildren();
            if (bankItemWidgets == null || inventoryIndex >= bankItemWidgets.length) {
                return;
            }
            Widget bankItemWidget = bankItemWidgets[inventoryIndex];
            String[] actions = bankItemWidget.getActions();
            if (actions == null || EDIT_TAGS_MENU_INDEX - 1 >= actions.length) {
                return;
            }
            int tagCount = getTagCount(itemId);
            actions[EDIT_TAGS_MENU_INDEX - 1] = EDIT_TAGS_MENU_OPTION;
            if (tagCount > 0) {
                actions[EDIT_TAGS_MENU_INDEX - 1] += " (" + tagCount + ")";
            }
        });
    }
}
Also used : ItemContainer(net.runelite.api.ItemContainer) Item(net.runelite.api.Item) Widget(net.runelite.api.widgets.Widget) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with ItemContainer

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

the class ItemPricesOverlay method makeValueTooltip.

private String makeValueTooltip(MenuEntry menuEntry) {
    // Disabling both disables all value tooltips
    if (!config.showGEPrice() && !config.showHAValue()) {
        return null;
    }
    final int widgetId = menuEntry.getParam1();
    ItemContainer container = null;
    // Inventory item
    if (widgetId == INVENTORY_ITEM_WIDGETID || widgetId == BANK_INVENTORY_ITEM_WIDGETID) {
        container = client.getItemContainer(InventoryID.INVENTORY);
    } else // Bank item
    if (widgetId == BANK_ITEM_WIDGETID) {
        container = client.getItemContainer(InventoryID.BANK);
    }
    if (container == null) {
        return null;
    }
    // Find the item in the container to get stack size
    final Item[] items = container.getItems();
    final int index = menuEntry.getParam0();
    if (index < items.length) {
        final Item item = items[index];
        return getItemStackValueText(item);
    }
    return null;
}
Also used : ItemContainer(net.runelite.api.ItemContainer) Item(net.runelite.api.Item)

Example 4 with ItemContainer

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

the class PrayerPotion method heals.

@Override
public int heals(Client client) {
    boolean hasHolyWrench = false;
    ItemContainer equipContainer = client.getItemContainer(InventoryID.EQUIPMENT);
    if (equipContainer != null) {
        Item[] equip = equipContainer.getItems();
        hasHolyWrench |= equip.length > RING_SLOT && equip[RING_SLOT].getId() == ItemID.RING_OF_THE_GODS_I;
        if (equip.length > CAPE_SLOT) {
            int cape = equip[CAPE_SLOT].getId();
            hasHolyWrench |= cape == ItemID.PRAYER_CAPE;
            hasHolyWrench |= cape == ItemID.PRAYER_CAPET;
            // No idea what this is
            hasHolyWrench |= cape == ItemID.PRAYER_CAPE_10643;
            hasHolyWrench |= cape == ItemID.MAX_CAPE;
            // Or these
            hasHolyWrench |= cape == ItemID.MAX_CAPE_13282;
            hasHolyWrench |= cape == ItemID.MAX_CAPE_13342;
        }
    }
    if (!hasHolyWrench) {
        ItemContainer invContainer = client.getItemContainer(InventoryID.INVENTORY);
        if (invContainer != null) {
            for (Item itemStack : invContainer.getItems()) {
                int item = itemStack.getId();
                hasHolyWrench |= item == ItemID.HOLY_WRENCH;
                hasHolyWrench |= item == ItemID.PRAYER_CAPE;
                hasHolyWrench |= item == ItemID.PRAYER_CAPET;
                hasHolyWrench |= item == ItemID.PRAYER_CAPE_10643;
                hasHolyWrench |= item == ItemID.MAX_CAPE;
                hasHolyWrench |= item == ItemID.MAX_CAPE_13282;
                hasHolyWrench |= item == ItemID.MAX_CAPE_13342;
                if (hasHolyWrench) {
                    break;
                }
            }
        }
    }
    double perc = hasHolyWrench ? .27 : .25;
    int max = getStat().getMaximum(client);
    return (((int) (max * perc)) * (delta >= 0 ? 1 : -1)) + delta;
}
Also used : ItemContainer(net.runelite.api.ItemContainer) Item(net.runelite.api.Item)

Aggregations

ItemContainer (net.runelite.api.ItemContainer)4 Item (net.runelite.api.Item)3 Widget (net.runelite.api.widgets.Widget)2 Subscribe (com.google.common.eventbus.Subscribe)1 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 PuzzleState (net.runelite.client.plugins.puzzlesolver.solver.PuzzleState)1 BackgroundComponent (net.runelite.client.ui.overlay.components.BackgroundComponent)1 TextComponent (net.runelite.client.ui.overlay.components.TextComponent)1