Search in sources :

Example 61 with Client

use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.

the class LocalPath method getCosts.

static double[][] getCosts(final ClientContext ctx, final int w, final int h) {
    final Client client = ctx.client();
    final Landscape landscape = client.getLandscape();
    final org.powerbot.bot.rt4.client.Tile[][][] tiles;
    final int floor = client.getFloor();
    final org.powerbot.bot.rt4.client.Tile[][] rows;
    if (landscape == null || (tiles = landscape.getTiles()) == null || floor < 0 || floor > tiles.length || (rows = tiles[floor]) == null) {
        return new double[0][0];
    }
    final double[][] arr = new double[w][h];
    for (int x = 0; x < Math.min(w, rows.length); x++) {
        final org.powerbot.bot.rt4.client.Tile[] row = rows[x];
        if (row == null) {
            continue;
        }
        final int h2 = row.length;
        for (int y = 0; y < Math.min(h, h2); y++) {
            final org.powerbot.bot.rt4.client.Tile tile = row[y];
            if (tile == null) {
                continue;
            }
            if (tile.getGameObjectLength() > 0 || tile.getBoundaryObject() != null || tile.getWallObject() != null) {
                for (int dx = Math.max(0, x - 1); dx <= Math.min(w - 1, x + 1); dx++) {
                    for (int dy = Math.max(0, y - 1); dy <= Math.min(h - 1, y + 1); dy++) {
                        arr[dx][dy] += Random.nextDouble();
                    }
                }
            }
        }
    }
    return arr;
}
Also used : Landscape(org.powerbot.bot.rt4.client.Landscape) Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt4.client.Client)

Example 62 with Client

use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.

the class Menu method click.

/**
 * Attempts to click the menu command provided by the filter.
 *
 * @param filter The filter to apply to the menu.
 * @param click Whether or not to left-click.
 * @return {@code true} if the mouse has successfully clicked within the bounds of the
 * MenuCommand.
 */
private boolean click(final Filter<? super MenuCommand> filter, final boolean click) {
    final Client client = ctx.client();
    int idx;
    if (client == null || (idx = indexOf(filter)) == -1) {
        return false;
    }
    if (click && !client.isMenuOpen() && idx == 0) {
        return ctx.input.click(true);
    }
    if (!client.isMenuOpen()) {
        if (!ctx.input.click(false)) {
            return false;
        }
    }
    if (!Condition.wait(new Condition.Check() {

        @Override
        public boolean poll() {
            return client.isMenuOpen();
        }
    }, 15, 10) || (idx = indexOf(filter)) == -1) {
        return false;
    }
    final Rectangle rectangle = new Rectangle(client.getMenuX(), client.getMenuY() + 19 + idx * 15, client.getMenuWidth(), 15);
    Condition.sleep(Random.hicks(idx));
    if (!ctx.input.move(Random.nextInt(rectangle.x, rectangle.x + rectangle.width), Random.nextInt(rectangle.y, rectangle.y + rectangle.height)) || !client.isMenuOpen()) {
        return false;
    }
    final Point p = ctx.input.getLocation();
    return client.isMenuOpen() && rectangle.contains(p) && (!click || ctx.input.click(true));
}
Also used : Condition(org.powerbot.script.Condition) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Client(org.powerbot.bot.rt4.client.Client) Point(java.awt.Point)

Example 63 with Client

use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.

the class Menu method close.

/**
 * Attempts to close the menu.
 *
 * @return {@code true} if the menu was closed, {@code false} otherwise.
 */
public boolean close() {
    final Client client = ctx.client();
    if (client == null) {
        return false;
    }
    if (!client.isMenuOpen()) {
        return true;
    }
    final Component c = ((InputSimulator) ctx.input).getComponent();
    final Dimension d = new Dimension(c != null ? c.getWidth() : 0, c != null ? c.getHeight() : 0);
    final int mx = client.getMenuX(), my = client.getMenuY();
    final int w = (int) d.getWidth(), h = (int) d.getHeight();
    int x1, x2;
    final int y1, y2;
    x1 = x2 = mx;
    y1 = y2 = Math.min(h - 5, Math.max(4, my + Random.nextInt(-10, 10)));
    x1 = Math.max(4, x1 + Random.nextInt(-30, -10));
    x2 = x2 + client.getMenuWidth() + Random.nextInt(10, 30);
    if (x2 <= w - 5 && (x1 - mx >= 5 || Random.nextBoolean())) {
        ctx.input.move(x2, y2);
    } else {
        ctx.input.move(x1, y1);
    }
    return Condition.wait(new Condition.Check() {

        @Override
        public boolean poll() {
            return client.isMenuOpen();
        }
    }, 10, 50);
}
Also used : Condition(org.powerbot.script.Condition) InputSimulator(org.powerbot.bot.InputSimulator) Dimension(java.awt.Dimension) Client(org.powerbot.bot.rt4.client.Client) Component(java.awt.Component) Point(java.awt.Point)

Example 64 with Client

use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.

the class Movement method destination.

/**
 * Returns the destination of the player, as represented by the red flag on the mini-map while
 * traversing. If the player is not moving, this will return {@link Tile#NIL}.
 *
 * @return The destination of the player.
 */
public Tile destination() {
    final Client client = ctx.client();
    if (client == null) {
        return Tile.NIL;
    }
    final int dX = client.getDestinationX(), dY = client.getDestinationY();
    if (dX <= 0 || dY <= 0) {
        return Tile.NIL;
    }
    return ctx.game.mapOffset().derive(dX, dY);
}
Also used : Client(org.powerbot.bot.rt4.client.Client) Point(java.awt.Point)

Example 65 with Client

use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.

the class Npc method valid.

@Override
public boolean valid() {
    final Client client = ctx.client();
    if (client == null || npc == null || npc.isNull()) {
        return false;
    }
    final org.powerbot.bot.rt4.client.Npc[] arr = client.getNpcs();
    for (final org.powerbot.bot.rt4.client.Npc a : arr) {
        if (npc.equals(a)) {
            return true;
        }
    }
    return false;
}
Also used : Client(org.powerbot.bot.rt4.client.Client)

Aggregations

Client (org.powerbot.bot.rt4.client.Client)36 Client (org.powerbot.bot.rt6.client.Client)33 Point (java.awt.Point)25 ArrayList (java.util.ArrayList)13 Client (org.orcid.jaxb.model.v3.dev1.client.Client)11 Test (org.junit.Test)8 Tile (org.powerbot.script.Tile)8 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 HashSet (java.util.HashSet)5 Rectangle (java.awt.Rectangle)4 Reflector (org.powerbot.bot.Reflector)4 Condition (org.powerbot.script.Condition)4 Client (client.Client)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ClientRedirectUri (org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri)3 Graphics (java.awt.Graphics)2 LinkedList (java.util.LinkedList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2