use of org.powerbot.bot.rt6.client.Node in project powerbot by powerbot.
the class Menu method commands.
/**
* Returns an array of all the current menu commands.
*
* @return the array of menu commands
*/
public MenuCommand[] commands() {
final List<MenuItemNode> items = getMenuItemNodes();
final int size = items.size();
final MenuCommand[] arr = new MenuCommand[size];
for (int i = 0; i < size; i++) {
final MenuItemNode node = items.get(i);
arr[i] = new MenuCommand(node.getAction(), node.getOption());
}
return arr;
}
use of org.powerbot.bot.rt6.client.Node 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.Node 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;
}
use of org.powerbot.bot.rt6.client.Node in project powerbot by powerbot.
the class HintArrow method tile.
@Override
public Tile tile() {
final Client client = ctx.client();
if (client == null || arrow.obj.get() == null) {
return Tile.NIL;
}
final int type = type();
final int target = targetId();
if (type == -1 || type == 0) {
return Tile.NIL;
}
if (type == 1) {
org.powerbot.script.rt6.Npc npc = null;
final Node node = HashTable.lookup(client.getNpcTable(), target, Node.class);
if (!node.isNull()) {
final Reflector r = client.reflector;
if (node.isTypeOf(NpcNode.class)) {
npc = new org.powerbot.script.rt6.Npc(ctx, new NpcNode(r, node).getNpc());
} else if (node.isTypeOf(Npc.class)) {
npc = new org.powerbot.script.rt6.Npc(ctx, new Npc(r, node));
}
}
return npc != null ? npc.tile() : Tile.NIL;
} else if (type == 2) {
return ctx.game.mapOffset().derive(arrow.getX() >> 9, arrow.getY() >> 9, floor());
}
final Player[] players = client.getPlayers();
if (type != 10 || target < 0 || target >= players.length) {
return Tile.NIL;
}
final Player localPlayer = players[target];
if (localPlayer != null) {
return new org.powerbot.script.rt6.Player(ctx, localPlayer).tile();
}
return Tile.NIL;
}
use of org.powerbot.bot.rt6.client.Node in project powerbot by powerbot.
the class Component method parentId.
public int parentId() {
final Client client = ctx.client();
final Widget component = getInternalComponent();
if (client == null || component == null) {
return -1;
}
final int pId = component.getParentId();
if (pId != -1) {
return pId;
}
final int uid = id() >>> 16;
int i = 0;
for (final ComponentNode node : new HashTable<ComponentNode>(client.getWidgetTable(), ComponentNode.class)) {
if (uid == node.getUid()) {
return (int) node.getId();
}
if (i++ >= 1500) {
System.out.printf("WARNING: parentId operation killed -- beyond depth of %d.%n", 1500);
break;
}
}
return -1;
}
Aggregations