Search in sources :

Example 36 with Client

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);
        }
    });
}
Also used : Graphics(java.awt.Graphics) Entry(org.powerbot.bot.rt4.client.Entry) MessageEntry(org.powerbot.bot.rt4.client.MessageEntry) EventDispatcher(org.powerbot.bot.EventDispatcher) PaintListener(org.powerbot.script.PaintListener) MessageEvent(org.powerbot.script.MessageEvent) MessageEntry(org.powerbot.bot.rt4.client.MessageEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) EntryList(org.powerbot.bot.rt4.client.EntryList) Client(org.powerbot.bot.rt4.client.Client) AbstractBot(org.powerbot.bot.AbstractBot)

Example 37 with Client

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);
}
Also used : Point(java.awt.Point) Client(org.powerbot.bot.rt4.client.Client) Point(java.awt.Point)

Example 38 with Client

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;
}
Also used : HashTable(org.powerbot.bot.rt4.HashTable) WidgetNode(org.powerbot.bot.rt4.client.WidgetNode) Client(org.powerbot.bot.rt4.client.Client) Point(java.awt.Point)

Example 39 with Client

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;
}
Also used : Client(org.powerbot.bot.rt4.client.Client) Point(java.awt.Point)

Example 40 with Client

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;
}
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