Search in sources :

Example 1 with Targetable

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

the class Movement method step.

/**
 * Attempts to use the mini-map to step towards the {@link Locatable}.
 *
 * @param locatable The location of where to step towards.
 * @return {@code true} if successfully clicked the mini-map, {@code false} otherwise.
 */
public boolean step(final Locatable locatable) {
    Tile loc = locatable.tile();
    if (!new TileMatrix(ctx, loc).onMap()) {
        loc = closestOnMap(loc);
        if (!new TileMatrix(ctx, loc).onMap()) {
            return false;
        }
    }
    final Tile t = loc;
    final Filter<Point> f = new Filter<Point>() {

        @Override
        public boolean accept(final Point point) {
            return ctx.input.click(true);
        }
    };
    return ctx.input.apply(new Targetable() {

        private final TileMatrix tile = new TileMatrix(ctx, t);

        @Override
        public Point nextPoint() {
            return tile.mapPoint();
        }

        @Override
        public boolean contains(final Point point) {
            final Point p = tile.mapPoint();
            final Rectangle t = new Rectangle(p.x - 2, p.y - 2, 4, 4);
            return t.contains(point);
        }
    }, f);
}
Also used : Targetable(org.powerbot.script.Targetable) Filter(org.powerbot.script.Filter) Rectangle(java.awt.Rectangle) Tile(org.powerbot.script.Tile) Point(java.awt.Point)

Example 2 with Targetable

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

the class Movement method step.

/**
 * Steps towards the provided {@link Locatable}.
 *
 * @param locatable the locatable to step towards
 * @return {@code true} if stepped; otherwise {@code false}
 */
public boolean step(final Locatable locatable) {
    Tile loc = locatable.tile();
    if (!new TileMatrix(ctx, loc).onMap()) {
        loc = closestOnMap(loc);
    }
    final Tile t = loc;
    final Filter<Point> f = new Filter<Point>() {

        @Override
        public boolean accept(final Point point) {
            return ctx.input.click(true);
        }
    };
    return ctx.input.apply(new Targetable() {

        private final TileMatrix tile = new TileMatrix(ctx, t);

        @Override
        public Point nextPoint() {
            return tile.mapPoint();
        }

        @Override
        public boolean contains(final Point point) {
            final Point p = tile.mapPoint();
            final Rectangle t = new Rectangle(p.x - 2, p.y - 2, 4, 4);
            return t.contains(point);
        }
    }, f);
}
Also used : Targetable(org.powerbot.script.Targetable) Filter(org.powerbot.script.Filter) Rectangle(java.awt.Rectangle) Tile(org.powerbot.script.Tile) Point(java.awt.Point)

Aggregations

Point (java.awt.Point)2 Rectangle (java.awt.Rectangle)2 Filter (org.powerbot.script.Filter)2 Targetable (org.powerbot.script.Targetable)2 Tile (org.powerbot.script.Tile)2