Search in sources :

Example 36 with Tile

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

the class GroundItems method get.

private List<GroundItem> get(int radius, final int floor) {
    if (radius < 1) {
        radius = 110;
    }
    final List<GroundItem> r = new CopyOnWriteArrayList<GroundItem>();
    final Client client = ctx.client();
    final NodeDeque[][][] dequeArray;
    if (client == null || (dequeArray = client.getGroundItems()) == null) {
        return r;
    }
    final NodeDeque[][] rows;
    if (floor > -1 && floor < dequeArray.length) {
        rows = dequeArray[floor];
    } else {
        rows = null;
    }
    if (rows == null) {
        return r;
    }
    final List<GroundItem> list = new LinkedList<GroundItem>();
    final Tile tile = new Tile(client.getOffsetX(), client.getOffsetY(), floor);
    final Tile ct = ctx.players.local().tile().derive(-tile.x(), -tile.y());
    for (int x = Math.max(0, ct.x() - radius); x < Math.min(rows.length, ct.x() + radius + 1); x++) {
        final NodeDeque[] row = rows[x];
        if (row == null) {
            continue;
        }
        for (int y = Math.max(0, ct.y() - radius); y < Math.min(row.length, ct.y() + radius + 1); y++) {
            for (final ItemNode n : NodeQueue.get(row[y], ItemNode.class)) {
                list.add(new GroundItem(ctx, tile.derive(x, y), n));
            }
        }
    }
    return list;
}
Also used : ItemNode(org.powerbot.bot.rt4.client.ItemNode) Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt4.client.Client) NodeDeque(org.powerbot.bot.rt4.client.NodeDeque) LinkedList(java.util.LinkedList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 37 with Tile

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

the class TilePath method traverse.

@Override
public boolean traverse(final EnumSet<TraversalOption> options) {
    final Player local = ctx.players.local();
    final Tile next = next();
    if (next == null || local == null) {
        return false;
    }
    final Tile dest = ctx.movement.destination();
    if (next.equals(end())) {
        if (next.distanceTo(ctx.players.local()) <= 2) {
            return false;
        }
        if (end && (local.inMotion() || dest.equals(next))) {
            return false;
        }
        end = true;
    } else {
        end = false;
    }
    if (options != null) {
        if (options.contains(TraversalOption.HANDLE_RUN) && !ctx.movement.running()) {
            final int e = ctx.movement.energyLevel();
            run_energy.compareAndSet(-1, Random.nextInt(20, 90));
            if (e >= run_energy.get() && ctx.movement.running(true)) {
                run_energy.set(-1);
            }
        }
        if (options.contains(TraversalOption.SPACE_ACTIONS) && local.inMotion() && dest.distanceTo(last) > 3d) {
            spaced_action.compareAndSet(-1, Random.nextInt(5, 12));
            final double d, d2 = dest.distanceTo(local);
            if (d2 > spaced_action.get()) {
                d = d2;
            } else {
                final double d3 = ctx.movement.distance(dest);
                d = d3 != -1 ? d3 : d2;
            }
            if (d > (double) spaced_action.get()) {
                return true;
            }
        }
    }
    last = next;
    if (ctx.movement.step(next)) {
        spaced_action.set(-1);
        if (local.inMotion()) {
            return Condition.wait(new Condition.Check() {

                @Override
                public boolean poll() {
                    return ctx.movement.destination().distanceTo(next) < 3;
                }
            }, 60, 10);
        }
        return next.distanceTo(ctx.players.local()) < 5d || Condition.wait(new Condition.Check() {

            @Override
            public boolean poll() {
                return ctx.players.local().inMotion() && ctx.movement.destination().distanceTo(next) < 3;
            }
        }, 125, 10);
    }
    return false;
}
Also used : Condition(org.powerbot.script.Condition) Tile(org.powerbot.script.Tile)

Example 38 with Tile

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

the class Camera method getAngleToLocatable.

private int getAngleToLocatable(final Locatable mobile) {
    final Player local = ctx.players.local();
    final Tile t1 = local != null ? local.tile() : null;
    final Tile t2 = mobile.tile();
    return t1 != null && t2 != null ? ((int) Math.toDegrees(Math.atan2(t2.y() - t1.y(), t2.x() - t1.x()))) - 90 : 0;
}
Also used : Tile(org.powerbot.script.Tile)

Example 39 with Tile

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

the class DrawGroundItems method repaint.

public void repaint(final Graphics render) {
    if (ctx.game.clientState() != Constants.GAME_LOADED) {
        return;
    }
    final Player player = ctx.players.local();
    if (player == null) {
        return;
    }
    final Tile tile = player.tile();
    if (tile == null) {
        return;
    }
    final FontMetrics metrics = render.getFontMetrics();
    final int tHeight = metrics.getHeight();
    final List<GroundItem> check = new ArrayList<GroundItem>();
    ctx.groundItems.select(10).addTo(check);
    for (int x = -10; x <= 10; x++) {
        for (int y = -10; y <= 10; y++) {
            int d = 0;
            final Tile loc = tile.derive(x, y);
            final Point screen = new TileMatrix(ctx, loc).centerPoint();
            if (screen.x == -1) {
                continue;
            }
            for (final GroundItem groundItem : ctx.groundItems.select(check).at(loc)) {
                final String name = groundItem.name();
                String s = "";
                s += groundItem.id();
                if (!name.isEmpty()) {
                    s += " " + name;
                }
                final int stack = groundItem.stackSize();
                if (stack > 1) {
                    s += " (" + stack + ")";
                }
                final int ty = screen.y - tHeight * (++d) + tHeight / 2;
                final int tx = screen.x - metrics.stringWidth(s) / 2;
                render.setColor(Color.green);
                render.drawString(s, tx, ty);
            }
        }
    }
}
Also used : Player(org.powerbot.script.rt4.Player) FontMetrics(java.awt.FontMetrics) GroundItem(org.powerbot.script.rt4.GroundItem) ArrayList(java.util.ArrayList) Tile(org.powerbot.script.Tile) Point(java.awt.Point) Point(java.awt.Point) TileMatrix(org.powerbot.script.rt4.TileMatrix)

Example 40 with Tile

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

the class TDestination method draw.

public int draw(int idx, final Graphics render) {
    final Tile dest = ctx.movement.destination();
    drawLine(render, idx++, "Destination: " + (dest != null ? dest.toString() : "null"));
    return idx;
}
Also used : Tile(org.powerbot.script.Tile)

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