Search in sources :

Example 6 with Item

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

the class ClueScrollPlugin method checkForClues.

@Schedule(period = 600, unit = ChronoUnit.MILLIS)
public void checkForClues() {
    if (client.getGameState() == GameState.LOGIN_SCREEN) {
        clue = null;
        return;
    }
    npcsToMark = null;
    objectsToMark = null;
    equippedItems = null;
    if (clue instanceof NpcClueScroll) {
        String npc = ((NpcClueScroll) clue).getNpc();
        if (npc != null) {
            Query query = new NPCQuery().nameContains(npc);
            npcsToMark = queryRunner.runQuery(query);
        }
    }
    if (clue instanceof ObjectClueScroll) {
        int objectId = ((ObjectClueScroll) clue).getObjectId();
        if (objectId != -1) {
            GameObjectQuery query = new GameObjectQuery().idEquals(objectId);
            objectsToMark = queryRunner.runQuery(query);
        }
    }
    if (clue instanceof EmoteClue) {
        equippedItems = new HashSet<>();
        Item[] result = queryRunner.runQuery(new InventoryItemQuery(InventoryID.EQUIPMENT));
        if (result != null) {
            for (Item item : result) {
                equippedItems.add(item.getId());
            }
        }
    }
    ClueScroll clue = findClueScroll();
    if (clue == null && this.clue != null) {
        // wait for WAIT_DURATION before discarding the knowledge of the player having a clue.
        if (Instant.now().compareTo(clueTimeout.plus(WAIT_DURATION)) < 0) {
            return;
        }
    }
    // so the clue window doesn't have to be open.
    if (clue != null) {
        this.clue = clue;
        this.clueTimeout = Instant.now();
    }
}
Also used : InventoryItemQuery(net.runelite.api.queries.InventoryItemQuery) NPCQuery(net.runelite.api.queries.NPCQuery) Query(net.runelite.api.Query) GameObjectQuery(net.runelite.api.queries.GameObjectQuery) TextClueScroll(net.runelite.client.plugins.cluescrolls.clues.TextClueScroll) ClueScroll(net.runelite.client.plugins.cluescrolls.clues.ClueScroll) NpcClueScroll(net.runelite.client.plugins.cluescrolls.clues.NpcClueScroll) ObjectClueScroll(net.runelite.client.plugins.cluescrolls.clues.ObjectClueScroll) NPCQuery(net.runelite.api.queries.NPCQuery) InventoryItemQuery(net.runelite.api.queries.InventoryItemQuery) WorldPoint(net.runelite.api.coords.WorldPoint) NpcClueScroll(net.runelite.client.plugins.cluescrolls.clues.NpcClueScroll) Item(net.runelite.api.Item) EmoteClue(net.runelite.client.plugins.cluescrolls.clues.EmoteClue) ObjectClueScroll(net.runelite.client.plugins.cluescrolls.clues.ObjectClueScroll) GameObjectQuery(net.runelite.api.queries.GameObjectQuery) Schedule(net.runelite.client.task.Schedule)

Example 7 with Item

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

the class ClueScrollPlugin method findClueScroll.

private ClueScroll findClueScroll() {
    Widget clueScrollText = client.getWidget(WidgetInfo.CLUE_SCROLL_TEXT);
    if (clueScrollText != null) {
        // Remove line breaks and also the rare occasion where there are double line breaks
        String text = clueScrollText.getText().replaceAll("-<br>", "-").replaceAll("<br>", " ").replaceAll("[ ]+", " ").toLowerCase();
        if (clue != null && clue instanceof TextClueScroll) {
            if (((TextClueScroll) clue).getText().equalsIgnoreCase(text)) {
                return clue;
            }
        }
        if (text.startsWith("this anagram reveals who to speak to next:")) {
            return AnagramClue.forText(text);
        } else if (text.startsWith("the cipher reveals who to speak to next:")) {
            return CipherClue.forText(text);
        } else if (text.contains("degrees") && text.contains("minutes")) {
            return coordinatesToWorldPoint(text);
        } else {
            CrypticClue crypticClue = CrypticClue.forText(text);
            if (crypticClue != null) {
                return crypticClue;
            }
            EmoteClue emoteClue = EmoteClue.forText(text);
            if (emoteClue != null) {
                return emoteClue;
            }
            return FairyRingClue.forText(text);
        }
    }
    Item[] result = queryRunner.runQuery(new InventoryItemQuery(InventoryID.INVENTORY));
    if (result == null) {
        return null;
    }
    for (Item item : result) {
        MapClue clue = MapClue.forItemId(item.getId());
        if (clue != null) {
            return clue;
        }
    }
    return null;
}
Also used : Item(net.runelite.api.Item) MapClue(net.runelite.client.plugins.cluescrolls.clues.MapClue) EmoteClue(net.runelite.client.plugins.cluescrolls.clues.EmoteClue) Widget(net.runelite.api.widgets.Widget) InventoryItemQuery(net.runelite.api.queries.InventoryItemQuery) TextClueScroll(net.runelite.client.plugins.cluescrolls.clues.TextClueScroll) CrypticClue(net.runelite.client.plugins.cluescrolls.clues.CrypticClue)

Example 8 with Item

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

the class DevToolsOverlay method renderGroundItems.

private void renderGroundItems(Graphics2D graphics, Tile tile, Player player) {
    ItemLayer itemLayer = tile.getItemLayer();
    if (itemLayer != null) {
        if (player.getLocalLocation().distanceTo(itemLayer.getLocalLocation()) <= MAX_DISTANCE) {
            Node current = itemLayer.getBottom();
            while (current instanceof Item) {
                Item item = (Item) current;
                OverlayUtil.renderTileOverlay(graphics, itemLayer, "ID: " + item.getId() + " Qty:" + item.getQuantity(), RED);
                current = current.getNext();
            }
        }
    }
}
Also used : ItemLayer(net.runelite.api.ItemLayer) WidgetItem(net.runelite.api.widgets.WidgetItem) Item(net.runelite.api.Item) Node(net.runelite.api.Node)

Example 9 with Item

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

the class GroundItemsPlugin method checkItems.

void checkItems() {
    final Player player = client.getLocalPlayer();
    if (!dirty || player == null || client.getViewportWidget() == null) {
        return;
    }
    dirty = false;
    final Region region = client.getRegion();
    final Tile[][][] tiles = region.getTiles();
    final int z = client.getPlane();
    final LocalPoint from = player.getLocalLocation();
    final int lowerX = Math.max(0, from.getRegionX() - MAX_RANGE);
    final int lowerY = Math.max(0, from.getRegionY() - MAX_RANGE);
    final int upperX = Math.min(from.getRegionX() + MAX_RANGE, REGION_SIZE - 1);
    final int upperY = Math.min(from.getRegionY() + MAX_RANGE, REGION_SIZE - 1);
    groundItems.clear();
    for (int x = lowerX; x <= upperX; ++x) {
        for (int y = lowerY; y <= upperY; ++y) {
            Tile tile = tiles[z][x][y];
            if (tile == null) {
                continue;
            }
            ItemLayer itemLayer = tile.getItemLayer();
            if (itemLayer == null) {
                continue;
            }
            Node current = itemLayer.getBottom();
            // adds the items on the ground to the ArrayList to be drawn
            while (current instanceof Item) {
                final Item item = (Item) current;
                // Continue iteration
                current = current.getNext();
                // Build ground item
                final GroundItem groundItem = buildGroundItem(tile, item);
                if (groundItem != null) {
                    groundItems.add(groundItem);
                }
            }
        }
    }
    // Group ground items together and sort them properly
    collectedGroundItems.clear();
    Lists.reverse(groundItems).stream().collect(groundItemMapCollector);
}
Also used : ItemLayer(net.runelite.api.ItemLayer) Item(net.runelite.api.Item) Player(net.runelite.api.Player) LocalPoint(net.runelite.api.coords.LocalPoint) Node(net.runelite.api.Node) Region(net.runelite.api.Region) Tile(net.runelite.api.Tile) LocalPoint(net.runelite.api.coords.LocalPoint)

Example 10 with Item

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

Item (net.runelite.api.Item)10 ItemContainer (net.runelite.api.ItemContainer)3 ItemLayer (net.runelite.api.ItemLayer)3 Node (net.runelite.api.Node)3 Subscribe (com.google.common.eventbus.Subscribe)2 Region (net.runelite.api.Region)2 Tile (net.runelite.api.Tile)2 LocalPoint (net.runelite.api.coords.LocalPoint)2 InventoryItemQuery (net.runelite.api.queries.InventoryItemQuery)2 Widget (net.runelite.api.widgets.Widget)2 EmoteClue (net.runelite.client.plugins.cluescrolls.clues.EmoteClue)2 TextClueScroll (net.runelite.client.plugins.cluescrolls.clues.TextClueScroll)2 Color (java.awt.Color)1 Point (java.awt.Point)1 ItemComposition (net.runelite.api.ItemComposition)1 MenuEntry (net.runelite.api.MenuEntry)1 Player (net.runelite.api.Player)1 Query (net.runelite.api.Query)1 WorldPoint (net.runelite.api.coords.WorldPoint)1 Inject (net.runelite.api.mixins.Inject)1