use of client.Client in project powerbot by powerbot.
the class Chat method register.
public void register() {
if (!registered.compareAndSet(false, true)) {
return;
}
final EventDispatcher e = ((AbstractBot) ctx.bot()).dispatcher;
e.add(new PaintListener() {
private final AtomicReference<Entry> previous = new AtomicReference<Entry>(null);
@Override
public void repaint(final Graphics graphics) {
final Client client = ctx.client();
if (client == null) {
return;
}
final EntryList q = client.getLoggerEntries();
final Entry s = q.getSentinel();
Entry c = s.getNext();
final Entry f = c;
while (!s.equals(c) && !c.isNull() && !c.equals(previous.get())) {
final MessageEntry m = new MessageEntry(c.reflector, c);
e.dispatch(new MessageEvent(m));
c = c.getNext();
}
previous.set(f);
}
});
}
use of client.Client in project powerbot by powerbot.
the class Component method screenPoint.
public Point screenPoint() {
final Client client = ctx.client();
final org.powerbot.bot.rt4.client.Widget widget = getInternal();
if (client == null || widget == null) {
return new Point(-1, -1);
}
final int uid = parentId();
if (uid != -1) {
final Component c = ctx.widgets.widget(uid >> 16).component(uid & 0xffff);
final Point p = c.screenPoint();
if (p.x != -1 && p.y != -1) {
final boolean b = widget.getScrollHeight() == 0;
return new Point(p.x + widget.getX() - (b ? c.scrollX() : 0), p.y + widget.getY() - (b ? c.scrollY() : 0));
}
}
final int[] boundsX = client.getWidgetBoundsX(), boundsY = client.getWidgetBoundsY();
final int bounds = boundsIndex();
if (boundsX != null && boundsY != null && bounds >= 0 && bounds < boundsX.length && bounds < boundsY.length) {
final int x = boundsX[bounds], y = boundsY[bounds];
return new Point(x - widget.getScrollX(), y - widget.getScrollY());
}
return new Point(-1, -1);
}
use of client.Client in project powerbot by powerbot.
the class Component method parentId.
public int parentId() {
final Client client = ctx.client();
final org.powerbot.bot.rt4.client.Widget w = getInternal();
if (client == null || w == null) {
return -1;
}
final int p = w.getParentId();
if (p != -1) {
return p;
}
final int uid = id() >>> 16;
for (final WidgetNode node : new HashTable<WidgetNode>(client.getWidgetTable(), WidgetNode.class)) {
if (uid == node.getUid()) {
return (int) node.getId();
}
}
return -1;
}
use of client.Client in project powerbot by powerbot.
the class Component method getInternal.
private org.powerbot.bot.rt4.client.Widget getInternal() {
final int wi = widget.id();
if (wi < 1 || index < 0) {
return null;
}
if (component != null) {
final org.powerbot.bot.rt4.client.Widget _i = component.getInternal();
final org.powerbot.bot.rt4.client.Widget[] arr = _i != null ? _i.getChildren() : null;
if (arr != null && index < arr.length) {
return arr[index];
}
return null;
}
final Client client = ctx.client();
final org.powerbot.bot.rt4.client.Widget[][] arr = client != null ? client.getWidgets() : null;
if (arr != null && wi < arr.length) {
final org.powerbot.bot.rt4.client.Widget[] comps = arr[wi];
return comps != null && index < comps.length ? comps[index] : null;
}
return null;
}
use of client.Client in project powerbot by powerbot.
the class Game method tileHeight.
/**
* Returns the tile height of the relative 2-dimensional tile. The
* 3-dimensional axis is flipped to represent the X axis being horizontal,
* Y axis being Vertical, and Z axis to be depth.
*
* @param relativeX The x-axis value relative to the origin
* @param relativeZ The z-axis value relative to the origin
* @return The tile height
*/
public int tileHeight(final int relativeX, final int relativeZ) {
final Client client = ctx.client();
if (client == null) {
return 0;
}
int floor = client.getFloor();
int x = relativeX >> 7;
int y = relativeZ >> 7;
if (x < 0 || y < 0 || x > 103 || y > 103 || floor < 0 || floor > 3) {
return 0;
}
final byte[][][] meta = client.getLandscapeMeta();
final int[][][] heights = client.getTileHeights();
if (meta == null) {
return 0;
}
if (floor < 3 && (meta[1][x][y] & 0x2) == 2) {
floor++;
}
x &= 0x7f;
y &= 0x7f;
final int heightStart = x * heights[floor][1 + x][y] + heights[floor][x][y] * (128 - x) >> 7;
final int heightEnd = (128 - x) * heights[floor][x][1 + y] + x * heights[floor][1 + x][y + 1] >> 7;
return y * heightEnd + heightStart * (128 - y) >> 7;
}
Aggregations