Search in sources :

Example 21 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 22 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.loggedIn()) {
        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 int plane = ctx.game.floor();
    final List<GroundItem> check = new ArrayList<GroundItem>();
    ctx.groundItems.select(10).addTo(check);
    for (int x = tile.x() - 10; x <= tile.x() + 10; x++) {
        n: for (int y = tile.y() - 10; y <= tile.y() + 10; y++) {
            int d = 0;
            final Tile loc = new Tile(x, y, plane);
            for (final GroundItem groundItem : ctx.groundItems.select(check).at(loc)) {
                final Point screen = new TileMatrix(ctx, loc).centerPoint();
                if (screen.x == -1 || screen.y == -1) {
                    continue n;
                }
                final String name = groundItem.name();
                String s = "";
                s += groundItem.id();
                if (!name.isEmpty()) {
                    s += " " + name;
                }
                final int stack = groundItem.stackSize();
                if (stack > 1) {
                    s += " (" + groundItem.stackSize() + ")";
                }
                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.rt6.Player) FontMetrics(java.awt.FontMetrics) GroundItem(org.powerbot.script.rt6.GroundItem) ArrayList(java.util.ArrayList) Tile(org.powerbot.script.Tile) Point(java.awt.Point) Point(java.awt.Point) TileMatrix(org.powerbot.script.rt6.TileMatrix)

Example 23 with Tile

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

the class DrawObjects method repaint.

@Override
public void repaint(final Graphics render) {
    if (!ctx.game.loggedIn()) {
        return;
    }
    final Player player = ctx.players.local();
    if (player == null) {
        return;
    }
    final FontMetrics metrics = render.getFontMetrics();
    final int textHeight = metrics.getHeight();
    final Map<Tile, AtomicInteger> counts = new HashMap<Tile, AtomicInteger>();
    for (final GameObject object : ctx.objects.select(15)) {
        final Tile t = object.tile();
        if (!counts.containsKey(t)) {
            counts.put(t, new AtomicInteger(0));
        }
        final Point p = object.centerPoint();
        if (p.x == -1) {
            continue;
        }
        render.setColor(Color.black);
        render.fillRect(p.x - 1, p.y - 1, 2, 2);
        final int mainId = object.mainId();
        final int animation = object.animation();
        final String n = object.name();
        String s = (n.isEmpty() ? "" : n + " - ") + object.id();
        if (animation != -1) {
            s = s + " (A: " + animation + ")";
        }
        if (mainId != -1) {
            if (animation != -1) {
                s = s.replace(')', ',') + " MID: " + mainId + ")";
            } else {
                s = s + " (MID: " + mainId + ")";
            }
        }
        final int ty = p.y - textHeight / 2;
        final int tx = p.x - metrics.stringWidth(s) / 2;
        render.setColor(C[object.type().ordinal()]);
        render.drawString(s, tx, ty - textHeight * counts.get(t).getAndIncrement());
    }
}
Also used : Player(org.powerbot.script.rt6.Player) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) FontMetrics(java.awt.FontMetrics) GameObject(org.powerbot.script.rt6.GameObject) Tile(org.powerbot.script.Tile) Point(java.awt.Point) Point(java.awt.Point)

Example 24 with Tile

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

the class DrawProjectiles method repaint.

@Override
public void repaint(final Graphics render) {
    if (!ctx.game.loggedIn()) {
        return;
    }
    for (final Projectile projectile : ctx.projectiles.select()) {
        final Tile t = projectile.tile();
        final TileMatrix m = new TileMatrix(ctx, t);
        if (!m.valid()) {
            continue;
        }
        m.bounds(new int[] { -128, 128, -256, 0, -128, 128 });
        m.draw(render, 255);
    }
}
Also used : Tile(org.powerbot.script.Tile) TileMatrix(org.powerbot.script.rt6.TileMatrix) Projectile(org.powerbot.script.rt6.Projectile)

Example 25 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)

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