use of org.powerbot.bot.rt6.client.Client in project powerbot by powerbot.
the class Widget method getInternalComponents.
Object[] getInternalComponents() {
final Client client = ctx.client();
if (client == null) {
return null;
}
final Object[] containers = client.getWidgets();
final ComponentContainer container;
if (containers != null && index >= 0 && index < containers.length && !(container = new ComponentContainer(client.reflector, containers[index])).isNull()) {
return container.getComponents();
}
return null;
}
use of org.powerbot.bot.rt6.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);
}
use of org.powerbot.bot.rt6.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));
}
use of org.powerbot.bot.rt6.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;
}
use of org.powerbot.bot.rt6.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;
}
Aggregations