Search in sources :

Example 11 with Tile

use of net.runelite.api.Tile 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 12 with Tile

use of net.runelite.api.Tile 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 13 with Tile

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

the class HerbiboarOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    if (!plugin.isInHerbiboarArea()) {
        return null;
    }
    HerbiboarTrail currentTrail = plugin.getCurrentTrail();
    int finishId = plugin.getFinishId();
    // Draw start objects
    if (config.isStartShown() && (currentTrail == null && finishId == 0)) {
        plugin.getStarts().keySet().forEach((obj) -> {
            OverlayUtil.renderTileOverlay(graphics, obj, "", config.getStartColor());
        });
    }
    // Draw trails
    if (config.isTrailShown()) {
        Set<Integer> shownTrailIds = plugin.getShownTrails();
        plugin.getTrails().keySet().forEach((x) -> {
            int id = x.getId();
            if (shownTrailIds.contains(id) && (finishId > 0 || (currentTrail != null && currentTrail.getTrailId() != id && currentTrail.getTrailId() + 1 != id))) {
                OverlayUtil.renderTileOverlay(graphics, x, "", config.getTrailColor());
            }
        });
    }
    // Draw trail objects (mushrooms, mud, etc)
    if (config.isObjectShown() && currentTrail != null) {
        int currentPath = plugin.getCurrentPath();
        plugin.getTrailObjects().keySet().forEach((obj) -> {
            WorldPoint loc = obj.getWorldLocation();
            WorldPoint[] trailLocs = currentTrail.getObjectLocs(currentPath);
            for (WorldPoint trailLoc : trailLocs) {
                if (trailLoc == null) {
                    continue;
                }
                if (trailLoc.equals(loc)) {
                    if (config.showClickBoxes()) {
                        Area clickbox = obj.getClickbox();
                        graphics.setColor(config.getObjectColor());
                        graphics.draw(clickbox);
                        graphics.setColor(new Color(255, 0, 255, 20));
                        graphics.fill(clickbox);
                    } else {
                        OverlayUtil.renderTileOverlay(graphics, obj, "", config.getObjectColor());
                    }
                }
            }
        });
    }
    // Draw finish tunnels
    if (config.isTunnelShown() && finishId > 0) {
        WorldPoint finishLoc = plugin.getEndLocations().get(finishId - 1);
        Map<TileObject, Tile> tunnels = plugin.getTunnels();
        tunnels.keySet().forEach((obj) -> {
            WorldPoint loc = obj.getWorldLocation();
            if (finishLoc.equals(loc)) {
                if (config.showClickBoxes()) {
                    Area clickbox = obj.getClickbox();
                    Color col = config.getObjectColor();
                    graphics.setColor(col);
                    graphics.draw(clickbox);
                    graphics.setColor(new Color(col.getRed(), col.getGreen(), col.getBlue(), 20));
                    graphics.fill(clickbox);
                } else {
                    OverlayUtil.renderTileOverlay(graphics, obj, "", config.getTunnelColor());
                }
            }
        });
    }
    return null;
}
Also used : Area(java.awt.geom.Area) WorldPoint(net.runelite.api.coords.WorldPoint) Color(java.awt.Color) TileObject(net.runelite.api.TileObject) Tile(net.runelite.api.Tile) WorldPoint(net.runelite.api.coords.WorldPoint)

Aggregations

Tile (net.runelite.api.Tile)13 Region (net.runelite.api.Region)6 LocalPoint (net.runelite.api.coords.LocalPoint)6 Replace (net.runelite.api.mixins.Replace)4 WorldPoint (net.runelite.api.coords.WorldPoint)3 Subscribe (com.google.common.eventbus.Subscribe)2 Color (java.awt.Color)2 GameObject (net.runelite.api.GameObject)2 Item (net.runelite.api.Item)2 ItemLayer (net.runelite.api.ItemLayer)2 Node (net.runelite.api.Node)2 Player (net.runelite.api.Player)2 Area (java.awt.geom.Area)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Client (net.runelite.api.Client)1 ItemComposition (net.runelite.api.ItemComposition)1 MenuEntry (net.runelite.api.MenuEntry)1