Search in sources :

Example 31 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class Movement method closestOnMap.

/**
 * Grabs the closest tile on map relative to the given {@link Locatable}.
 *
 * @param locatable The locatable
 * @return the {@link Tile}
 */
public Tile closestOnMap(final Locatable locatable) {
    final Tile local = ctx.players.local().tile();
    final Tile tile = locatable.tile();
    if (local == Tile.NIL || tile == Tile.NIL) {
        return Tile.NIL;
    }
    if (new TileMatrix(ctx, tile).onMap()) {
        return tile;
    }
    final int x2 = local.x();
    final int y2 = local.y();
    int x1 = tile.x();
    int y1 = tile.y();
    final int dx = Math.abs(x2 - x1);
    final int dy = Math.abs(y2 - y1);
    final int sx = (x1 < x2) ? 1 : -1;
    final int sy = (y1 < y2) ? 1 : -1;
    int off = dx - dy;
    for (; ; ) {
        final Tile t = new Tile(x1, y1, local.floor());
        if (new TileMatrix(ctx, t).onMap()) {
            return t;
        }
        if (x1 == x2 && y1 == y2) {
            break;
        }
        final int e2 = 2 * off;
        if (e2 > -dy) {
            off = off - dy;
            x1 = x1 + sx;
        }
        if (e2 < dx) {
            off = off + dx;
            y1 = y1 + sy;
        }
    }
    return Tile.NIL;
}
Also used : Tile(org.powerbot.script.Tile) Point(java.awt.Point)

Example 32 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class Bank method getBank.

private Interactive getBank() {
    final Player p = ctx.players.local();
    final Tile t = p.tile();
    ctx.npcs.select().id(Constants.BANK_NPCS).viewable().select(UNREACHABLE_FILTER).nearest();
    ctx.objects.select().id(Constants.BANK_BOOTHS, Constants.BANK_COUNTERS, Constants.BANK_CHESTS).viewable().select(UNREACHABLE_FILTER).nearest();
    if (!ctx.properties.getProperty("bank.antipattern", "").equals("disable")) {
        final Npc npc = ctx.npcs.poll();
        final GameObject object = ctx.objects.poll();
        return t.distanceTo(npc) < t.distanceTo(object) ? npc : object;
    }
    final double dist = Math.min(t.distanceTo(ctx.npcs.peek()), t.distanceTo(ctx.objects.peek()));
    final double d2 = Math.min(2d, Math.max(0d, dist - 1d));
    final List<Interactive> interactives = new ArrayList<Interactive>();
    ctx.npcs.within(dist + Random.nextInt(2, 5)).within(ctx.npcs.peek(), d2);
    ctx.objects.within(dist + Random.nextInt(2, 5)).within(ctx.objects.peek(), d2);
    ctx.npcs.addTo(interactives);
    ctx.objects.addTo(interactives);
    final int len = interactives.size();
    return len == 0 ? ctx.npcs.nil() : interactives.get(Random.nextInt(0, len));
}
Also used : ArrayList(java.util.ArrayList) Tile(org.powerbot.script.Tile)

Example 33 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class Bank method nearest.

/**
 * Returns the absolute nearest bank for walking purposes. Do not use this to open the bank.
 *
 * @return the {@link Locatable} of the nearest bank or {@link Tile#NIL}
 * @see #open()
 */
public Locatable nearest() {
    Locatable nearest = ctx.npcs.select().select(UNREACHABLE_FILTER).id(Constants.BANK_NPCS).nearest().poll();
    final Tile loc = ctx.players.local().tile();
    for (final GameObject object : ctx.objects.select().select(UNREACHABLE_FILTER).id(Constants.BANK_BOOTHS, Constants.BANK_COUNTERS, Constants.BANK_CHESTS).nearest().limit(1)) {
        if (loc.distanceTo(object) < loc.distanceTo(nearest)) {
            nearest = object;
        }
    }
    if (nearest.tile() != Tile.NIL) {
        return nearest;
    }
    return Tile.NIL;
}
Also used : Tile(org.powerbot.script.Tile) Locatable(org.powerbot.script.Locatable)

Example 34 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class GameObject method tile.

@Override
public Tile tile() {
    final Client client = ctx.client();
    final int r = relative();
    final int rx = r >> 16, rz = r & 0xffff;
    if (client != null && rx != 0 && rz != 0) {
        return new Tile(client.getOffsetX() + (rx >> 7), client.getOffsetY() + (rz >> 7), client.getFloor());
    }
    return Tile.NIL;
}
Also used : Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt4.client.Client) Point(java.awt.Point)

Example 35 with Tile

use of org.powerbot.script.Tile in project powerbot by powerbot.

the class GroundItem method valid.

@Override
public boolean valid() {
    final Client c = ctx.client();
    if (c == null || node.isNull()) {
        return false;
    }
    final NodeDeque[][][] nd = c.getGroundItems();
    if (nd != null) {
        final int f = c.getFloor();
        if (f < 0 || f >= nd.length || nd[f] == null) {
            return false;
        }
        final Tile t = tile.tile().derive(-c.getOffsetX(), -c.getOffsetY());
        if (t.x() < 0 || t.y() < 0 || t.x() >= nd[f].length) {
            return false;
        }
        final NodeDeque[] nd2 = nd[f][t.x()];
        if (nd2 == null || t.y() >= nd2.length) {
            return false;
        }
        final NodeDeque d = nd2[t.y()];
        return d != null && NodeQueue.get(d, ItemNode.class).contains(node);
    }
    return false;
}
Also used : Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt4.client.Client) NodeDeque(org.powerbot.bot.rt4.client.NodeDeque) Point(java.awt.Point)

Aggregations

Tile (org.powerbot.script.Tile)40 Point (java.awt.Point)16 ArrayList (java.util.ArrayList)5 Client (org.powerbot.bot.rt4.client.Client)5 FontMetrics (java.awt.FontMetrics)4 Condition (org.powerbot.script.Condition)4 Rectangle (java.awt.Rectangle)3 Client (org.powerbot.bot.rt6.client.Client)3 Player (org.powerbot.script.rt4.Player)3 Player (org.powerbot.script.rt6.Player)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NodeDeque (org.powerbot.bot.rt4.client.NodeDeque)2 Filter (org.powerbot.script.Filter)2 Locatable (org.powerbot.script.Locatable)2 Targetable (org.powerbot.script.Targetable)2 TileMatrix (org.powerbot.script.rt6.TileMatrix)2 LinkedList (java.util.LinkedList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ItemNode (org.powerbot.bot.rt4.client.ItemNode)1