Search in sources :

Example 56 with Client

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

the class Menu method close.

/**
 * Closes the menu.
 *
 * @return {@code true} if the menu was closed, otherwise {@code false}
 */
public boolean close() {
    final Client client = ctx.client();
    if (client == null) {
        return false;
    }
    if (!client.isMenuOpen()) {
        return true;
    }
    final Game.Viewport v = ctx.game.getViewport();
    final int mx = client.getMenuX(), my = client.getMenuY();
    int x1, x2;
    final int y1, y2;
    x1 = x2 = mx;
    y1 = y2 = Math.min((int) v.my - 5, Math.max(4, my + Random.nextInt(-10, 10)));
    x1 = Math.max(4, x1 + Random.nextInt(-30, -10));
    x2 = x2 + client.getMenuWidth() + (client.isMenuCollapsed() ? client.getSubMenuWidth() : 0) + Random.nextInt(10, 30);
    if (x2 <= (int) v.mx - 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) Client(org.powerbot.bot.rt6.client.Client) Point(java.awt.Point)

Example 57 with Client

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

the class Menu method select.

private boolean select(final Filter<? super MenuCommand> filter, final boolean click) {
    final Client client = ctx.client();
    if (client == null) {
        return false;
    }
    int index = indexOf(filter);
    if (index == -1) {
        return false;
    }
    if (click && !client.isMenuOpen() && !Condition.wait(new Condition.Check() {

        @Override
        public boolean poll() {
            return indexOf(filter) != 0 && !filter.accept(tooltip());
        }
    }, 10, 10)) {
        return ctx.input.click(true);
    }
    if (!client.isMenuOpen()) {
        if (ctx.input.click(false)) {
            Condition.wait(new Condition.Check() {

                @Override
                public boolean poll() {
                    return client.isMenuOpen();
                }
            }, 5, 20);
            Condition.sleep(Random.hicks(index));
            if (!client.isMenuOpen()) {
                return false;
            }
            if ((index = indexOf(filter)) == -1) {
                close();
                return false;
            }
        }
    }
    final Point p = hoverIndex(client, index);
    return p.getX() != -1 && p.getY() != -1 && (!click || ctx.input.click(p, true));
}
Also used : Condition(org.powerbot.script.Condition) Point(java.awt.Point) Client(org.powerbot.bot.rt6.client.Client) Point(java.awt.Point)

Example 58 with Client

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

the class Menu method getMenuItemNodes.

private List<MenuItemNode> getMenuItemNodes() {
    final List<MenuItemNode> nodes = new LinkedList<MenuItemNode>();
    final Client client = ctx.client();
    if (client == null) {
        return nodes;
    }
    final boolean collapsed;
    if (collapsed = client.isMenuCollapsed()) {
        for (final MenuGroupNode n : NodeQueue.get(client.getCollapsedMenuItems(), MenuGroupNode.class)) {
            nodes.addAll(NodeQueue.get(n.getItems(), MenuItemNode.class));
        }
    } else {
        nodes.addAll(NodeQueue.get(client.getMenuItems(), MenuItemNode.class));
    }
    if (nodes.size() > 1) {
        final MenuItemNode node = nodes.get(0);
        final String action = node.getAction();
        if (action != null && StringUtils.stripHtml(action).equalsIgnoreCase(collapsed ? "Walk here" : "Cancel")) {
            Collections.reverse(nodes);
        }
    }
    return nodes;
}
Also used : MenuItemNode(org.powerbot.bot.rt6.client.MenuItemNode) Client(org.powerbot.bot.rt6.client.Client) MenuGroupNode(org.powerbot.bot.rt6.client.MenuGroupNode) LinkedList(java.util.LinkedList)

Example 59 with Client

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

the class Objects method get.

protected List<GameObject> get(final Locatable l, int radius) {
    radius = Math.min(radius, 110);
    final List<GameObject> items = new ArrayList<GameObject>();
    final Client client = ctx.client();
    if (client == null) {
        return items;
    }
    final Tile[][][] grounds = client.getWorld().getLandscape().getTiles();
    final int floor = ctx.game.floor();
    if (floor < 0 || floor >= grounds.length) {
        return items;
    }
    final Set<GameObject> set = new HashSet<GameObject>();
    final Tile[][] rows = grounds[floor];
    int start_x = 0, end_x = Integer.MAX_VALUE, start_y = 0, end_y = Integer.MAX_VALUE;
    if (radius >= 0) {
        final org.powerbot.script.Tile mo = ctx.game.mapOffset(), lp = l.tile();
        if (mo != org.powerbot.script.Tile.NIL && lp != org.powerbot.script.Tile.NIL) {
            final org.powerbot.script.Tile t = lp.derive(-mo.x(), -mo.y());
            start_x = t.x() - radius;
            end_x = t.x() + radius;
            start_y = t.y() - radius;
            end_y = t.y() + radius;
        }
    }
    for (int x = Math.max(0, start_x); x <= Math.min(end_x, rows.length - 1); x++) {
        final Tile[] col = rows[x];
        for (int y = Math.max(0, start_y); y <= Math.min(end_y, col.length - 1); y++) {
            final Tile tile = col[y];
            if (tile.isNull()) {
                continue;
            }
            for (RenderableNode node = tile.getInteractives(); !node.isNull(); node = node.getNext()) {
                final RenderableEntity r = node.getEntity();
                if (r.isNull()) {
                    continue;
                }
                if (r.isTypeOf(org.powerbot.bot.rt6.client.GameObject.class)) {
                    final org.powerbot.bot.rt6.client.GameObject o = new org.powerbot.bot.rt6.client.GameObject(r.reflector, r);
                    if (o.getId() != -1) {
                        set.add(new GameObject(ctx, new BasicObject(o, floor), GameObject.Type.INTERACTIVE));
                    }
                } else if (r.isTypeOf(DynamicGameObject.class)) {
                    final DynamicGameObject o = new DynamicGameObject(r.reflector, r);
                    if (o.getBridge().getId() != -1) {
                        set.add(new GameObject(ctx, new BasicObject(o, floor), GameObject.Type.INTERACTIVE));
                    }
                }
            }
            final Object[] objs = { tile.getBoundary1(), tile.getBoundary2(), tile.getFloorDecoration(), tile.getWallDecoration1(), tile.getWallDecoration2() };
            for (int i = 0; i < objs.length; i++) {
                if (objs[i] == null) {
                    continue;
                }
                Class<?> type = null;
                for (final Class<?> e : o_types[i]) {
                    @SuppressWarnings("unchecked") final Class<? extends ReflectProxy> c = (Class<? extends ReflectProxy>) e;
                    if (c != null && tile.reflector.isTypeOf(objs[i], c)) {
                        type = c;
                        break;
                    }
                }
                if (type == null) {
                    continue;
                }
                try {
                    items.add(new GameObject(ctx, new BasicObject((RenderableEntity) type.getConstructor(Reflector.class, Object.class).newInstance(tile.reflector, objs[i]), floor), types[i]));
                } catch (final InstantiationException ignored) {
                } catch (final IllegalAccessException ignored) {
                } catch (final InvocationTargetException ignored) {
                } catch (final NoSuchMethodException ignored) {
                }
            }
        }
    }
    items.addAll(set);
    set.clear();
    return items;
}
Also used : RenderableEntity(org.powerbot.bot.rt6.client.RenderableEntity) Reflector(org.powerbot.bot.Reflector) ArrayList(java.util.ArrayList) DynamicGameObject(org.powerbot.bot.rt6.client.DynamicGameObject) Client(org.powerbot.bot.rt6.client.Client) HashSet(java.util.HashSet) ReflectProxy(org.powerbot.bot.ReflectProxy) Tile(org.powerbot.bot.rt6.client.Tile) InvocationTargetException(java.lang.reflect.InvocationTargetException) DynamicGameObject(org.powerbot.bot.rt6.client.DynamicGameObject) DynamicGameObject(org.powerbot.bot.rt6.client.DynamicGameObject) DynamicBoundaryObject(org.powerbot.bot.rt6.client.DynamicBoundaryObject) BoundaryObject(org.powerbot.bot.rt6.client.BoundaryObject) FloorObject(org.powerbot.bot.rt6.client.FloorObject) DynamicFloorObject(org.powerbot.bot.rt6.client.DynamicFloorObject) DynamicWallObject(org.powerbot.bot.rt6.client.DynamicWallObject) WallObject(org.powerbot.bot.rt6.client.WallObject) RenderableNode(org.powerbot.bot.rt6.client.RenderableNode)

Example 60 with Client

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

the class LocalPath method getGraph.

static Graph getGraph(final ClientContext ctx) {
    final Client client = ctx.client();
    if (client == null) {
        return null;
    }
    final int floor = client.getFloor();
    final CollisionMap[] maps = client.getCollisionMaps();
    final CollisionMap map;
    if (maps == null || floor < 0 || floor >= maps.length || (map = maps[floor]) == null) {
        return null;
    }
    final int[][] arr = map.getFlags();
    final double[][] costs = getCosts(ctx, arr.length, arr.length);
    return arr != null ? new Graph(arr, costs, map.getOffsetX(), map.getOffsetY()) : null;
}
Also used : Client(org.powerbot.bot.rt4.client.Client) CollisionMap(org.powerbot.bot.rt4.client.CollisionMap)

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