Search in sources :

Example 16 with Client

use of org.orcid.jaxb.model.v3.dev1.client.Client in project powerbot by powerbot.

the class Game method tileToMap.

/**
 * Calculates a point on the mini-map.
 *
 * @param locatable the {@link org.powerbot.script.Locatable} to convert to map point
 * @return the map {@link Point}
 */
public Point tileToMap(final Locatable locatable) {
    final Point bad = new Point(-1, -1);
    final Client client = ctx.client();
    final Tile b = ctx.game.mapOffset();
    final Tile t = locatable.tile().derive(-b.x(), -b.y());
    final int tx = t.x();
    final int ty = t.y();
    if (client == null || tx < 1 || tx > 103 || ty < 1 || ty > 103) {
        return bad;
    }
    final RelativeLocation r = ctx.players.local().relative();
    final float offX = (tx * 4 - r.x() / 128) + 2;
    final float offY = (ty * 4 - r.z() / 128) + 2;
    final int d = (int) Math.round(Math.sqrt(Math.pow(offX, 2) + Math.pow(offY, 2)));
    final Component component = mapComponent();
    final int w = component.scrollWidth();
    final int h = component.scrollHeight();
    final int radius = Math.max(w / 2, h / 2) + 10;
    if (d >= radius) /*|| component.contentType() != 1338*/
    {
        return bad;
    }
    final boolean f = client.getMinimapSettings() == client.reflector.getConstant("V_MINIMAP_SCALE_ON_VALUE");
    final double a = ctx.camera.rotation() * 16384d / (Math.PI * 2d);
    int i = 0x3fff & (int) a;
    if (!f) {
        i = 0x3fff & client.getMinimapOffset() + (int) a;
    }
    int sin = SIN_TABLE[i], cos = COS_TABLE[i];
    if (!f) {
        final int scale = 256 + client.getMinimapScale();
        sin = 256 * sin / scale;
        cos = 256 * cos / scale;
    }
    int rotX = (int) (cos * offX + sin * offY) >> 14;
    int rotY = (int) (cos * offY - sin * offX) >> 14;
    rotX += w / 2;
    rotY *= -1;
    rotY += h / 2;
    if (rotX > 4 && rotX < w - 4 && rotY > 4 && rotY < h - 4) {
        final Point basePoint = component.screenPoint();
        final int sX = rotX + (int) basePoint.getX();
        final int sY = rotY + (int) basePoint.getY();
        final Point p = new Point(sX, sY);
        if (ctx.hud.legacy()) {
            final Point mid = new Point(basePoint.x + component.width() / 2, basePoint.y + component.height() / 2);
            if (Math.pow(mid.x - p.x, 2) + Math.pow(mid.y - p.y, 2) >= Math.pow(68, 2)) {
                return bad;
            }
        } else {
            // entire tile and a half sized 'buffer' area
            final Rectangle rbuffer = new Rectangle(p.x - 6, p.y - 6, 12, 12);
            for (final Component blocking : mapBlockingComponents()) {
                if (blocking.viewportRect().intersects(rbuffer)) {
                    return bad;
                }
            }
        }
        return p;
    }
    return bad;
}
Also used : Rectangle(java.awt.Rectangle) Tile(org.powerbot.script.Tile) Point(java.awt.Point) Client(org.powerbot.bot.rt6.client.Client) Point(java.awt.Point)

Example 17 with Client

use of org.orcid.jaxb.model.v3.dev1.client.Client in project powerbot by powerbot.

the class Game method tileHeight.

/**
 * Determines the tile height at the provided point in the game region.
 *
 * @param rX    the relative x
 * @param rY    the relative y
 * @param plane the plane
 * @return the height at the given point
 */
public int tileHeight(final int rX, final int rY, int plane) {
    final Client c = ctx.client();
    if (c == null) {
        return 0;
    }
    if (plane == -1) {
        plane = c.getFloor();
    }
    final int x = rX >> 9, y = rY >> 9;
    final byte[][][] configs = c.getWorld().getFloorSettings().getBytes();
    if (x < 0 || x > 103 || y < 0 || y > 103) {
        return 0;
    }
    if (plane < 3 && (configs[1][x][y] & 2) != 0) {
        ++plane;
    }
    final Floor[] landscape = c.getWorld().getLandscape().getFloors();
    if (plane < 0 || plane >= landscape.length) {
        return 0;
    }
    try {
        final int[][] heights = landscape[plane].getHeights();
        final int aX = rX & 0x1ff;
        final int aY = rY & 0x1ff;
        final int start_h = heights[x][y] * (512 - aX) + heights[x + 1][y] * aX >> 9;
        final int end_h = heights[x][1 + y] * (512 - aX) + heights[x + 1][y + 1] * aX >> 9;
        return start_h * (512 - aY) + end_h * aY >> 9;
    } catch (final Exception ignored) {
    }
    return 0;
}
Also used : Floor(org.powerbot.bot.rt6.client.Floor) Client(org.powerbot.bot.rt6.client.Client) Point(java.awt.Point)

Example 18 with Client

use of org.orcid.jaxb.model.v3.dev1.client.Client in project powerbot by powerbot.

the class Game method crosshair.

/**
 * Determines the current {@link Crosshair} displayed.
 *
 * @return the displayed {@link Crosshair}
 */
public Crosshair crosshair() {
    final Client client = ctx.client();
    final int type = client != null ? client.getCrossHairType() : -1;
    if (type < 0 || type > 2) {
        return Crosshair.NONE;
    }
    return Crosshair.values()[type];
}
Also used : Client(org.powerbot.bot.rt6.client.Client) Point(java.awt.Point)

Example 19 with Client

use of org.orcid.jaxb.model.v3.dev1.client.Client in project powerbot by powerbot.

the class Game method mapOffset.

/**
 * Determines the base of the loaded region.
 *
 * @return the {@link Tile} of the base
 */
public Tile mapOffset() {
    final Client client = ctx.client();
    if (client == null) {
        return Tile.NIL;
    }
    final MapOffset b = client.getWorld().getMapOffset();
    if (b.isNull()) {
        return Tile.NIL;
    }
    return new Tile(b.getX(), b.getY(), client.getFloor());
}
Also used : MapOffset(org.powerbot.bot.rt6.client.MapOffset) Tile(org.powerbot.script.Tile) Client(org.powerbot.bot.rt6.client.Client)

Example 20 with Client

use of org.orcid.jaxb.model.v3.dev1.client.Client in project powerbot by powerbot.

the class Game method clientState.

/**
 * Returns the current client state.
 *
 * @return the client state
 * @see org.powerbot.script.rt6.Constants#GAME_LOGIN
 * @see org.powerbot.script.rt6.Constants#GAME_LOBBY
 * @see org.powerbot.script.rt6.Constants#GAME_LOGGING
 * @see org.powerbot.script.rt6.Constants#GAME_MAP_LOADED
 * @see org.powerbot.script.rt6.Constants#GAME_MAP_LOADING
 */
public int clientState() {
    final Client client = ctx.client();
    if (client == null) {
        return -1;
    }
    final int state = client.getClientState();
    if (state == client.reflector.getConstant("V_CLIENT_GAMESTATE_LOGIN_SCREEN")) {
        return Constants.GAME_LOGIN;
    } else if (state == client.reflector.getConstant("V_CLIENT_GAMESTATE_LOBBY_SCREEN")) {
        return Constants.GAME_LOBBY;
    } else if (state == client.reflector.getConstant("V_CLIENT_GAMESTATE_LOGGING_IN")) {
        return Constants.GAME_LOGGING;
    } else if (state == client.reflector.getConstant("V_CLIENT_GAMESTATE_ENVIRONMENT_PLAYABLE")) {
        return Constants.GAME_MAP_LOADED;
    } else if (state == client.reflector.getConstant("V_CLIENT_GAMESTATE_ENVIRONMENT_LOADING")) {
        return Constants.GAME_MAP_LOADING;
    }
    return -1;
}
Also used : Client(org.powerbot.bot.rt6.client.Client) Point(java.awt.Point)

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)18 Test (org.junit.Test)17 Client (org.orcid.jaxb.model.v3.dev1.client.Client)11 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)9 Tile (org.powerbot.script.Tile)8 HashSet (java.util.HashSet)6 ClientRedirectUri (org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri)5 Rectangle (java.awt.Rectangle)4 ClientSummary (org.orcid.jaxb.model.v3.dev1.client.ClientSummary)4 DBUnitTest (org.orcid.test.DBUnitTest)4 Reflector (org.powerbot.bot.Reflector)4 Condition (org.powerbot.script.Condition)4 Client (client.Client)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)3 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)3