Search in sources :

Example 1 with Filter

use of org.powerbot.script.Filter 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 Filter

use of org.powerbot.script.Filter 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)

Example 3 with Filter

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

the class Interactive method interact.

/**
 * {@inheritDoc}
 */
@Override
public final boolean interact(final boolean auto, final Filter<? super MenuCommand> f) {
    if (!valid()) {
        return false;
    }
    final Filter<Point> f_auto = new Filter<Point>() {

        @Override
        public boolean accept(final Point point) {
            return Condition.wait(new Condition.Check() {

                @Override
                public boolean poll() {
                    return ctx.menu.indexOf(f) != -1;
                }
            }, 15, 10);
        }
    };
    Rectangle r = new Rectangle(-1, -1, -1, -1);
    for (int i = 0; i < 3; i++) {
        final Rectangle c = r;
        if (!ctx.input.apply(this, auto ? f_auto : new Filter<Point>() {

            @Override
            public boolean accept(final Point point) {
                return !(c.contains(point) && ctx.menu.opened()) && ctx.input.click(false) && Condition.wait(new Condition.Check() {

                    @Override
                    public boolean poll() {
                        return ctx.menu.opened() && !ctx.menu.bounds().equals(c);
                    }
                }, 20, 10);
            }
        })) {
            continue;
        }
        if (ctx.menu.click(f)) {
            return true;
        }
        r = ctx.menu.bounds();
        if (auto || r.contains(nextPoint())) {
            ctx.menu.close();
        }
    }
    ctx.menu.close();
    return false;
}
Also used : Condition(org.powerbot.script.Condition) Filter(org.powerbot.script.Filter) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Example 4 with Filter

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

the class Interactive method interact.

/**
 * {@inheritDoc}
 */
@Override
public final boolean interact(final boolean auto, final Filter<? super MenuCommand> f) {
    if (!valid()) {
        return false;
    }
    final Filter<Point> f_auto = new Filter<Point>() {

        @Override
        public boolean accept(final Point point) {
            return Condition.wait(new Condition.Check() {

                @Override
                public boolean poll() {
                    return ctx.menu.indexOf(f) != -1;
                }
            }, 15, 10);
        }
    };
    Rectangle r = new Rectangle(-1, -1, -1, -1);
    for (int i = 0; i < 3; i++) {
        final Rectangle c = r;
        if (!ctx.input.apply(this, auto ? f_auto : new Filter<Point>() {

            @Override
            public boolean accept(final Point point) {
                return !(c.contains(point) && ctx.menu.opened()) && ctx.input.click(false) && Condition.wait(new Condition.Check() {

                    @Override
                    public boolean poll() {
                        return ctx.menu.opened() && !ctx.menu.bounds().equals(c);
                    }
                }, 20, 10);
            }
        })) {
            continue;
        }
        if (ctx.menu.click(f)) {
            return true;
        }
        r = ctx.menu.bounds();
        if (auto || r.contains(nextPoint())) {
            ctx.menu.close();
        }
    }
    ctx.menu.close();
    return false;
}
Also used : Condition(org.powerbot.script.Condition) Filter(org.powerbot.script.Filter) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

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