Search in sources :

Example 1 with Condition

use of org.powerbot.script.Condition in project powerbot by powerbot.

the class TilePath method next.

@Override
public Tile next() {
    /* Wait for map not to be loading */
    final int state = ctx.game.clientState();
    if (state == Constants.GAME_MAP_LOADING) {
        Condition.wait(new Condition.Check() {

            @Override
            public boolean poll() {
                return ctx.game.clientState() != Constants.GAME_MAP_LOADING;
            }
        });
        return next();
    }
    if (state != Constants.GAME_MAP_LOADED) {
        return null;
    }
    /* Get current destination */
    final Tile dest = ctx.movement.destination();
    /* Label main loop for continuing purposes */
    out: /* Iterate over all tiles but the first tile (0) starting with the last (length - 1). */
    for (int i = tiles.length - 1; i > 0; --i) {
        /* The tiles not in view, go to the next. */
        if (!tiles[i].matrix(ctx).valid() || !tiles[i].matrix(ctx).onMap()) {
            continue;
        }
        /* LARGELY SPACED PATH SUPPORT: If the current destination is the tile on the map, return that tile
			 * as the next one will be coming soon (we hope/assume this, as short spaced paths should never experience
			 * this condition as one will be on map before it reaches the current target). */
        if (dest == Tile.NIL) {
            if (tiles[i].matrix(ctx).reachable()) {
                return tiles[i];
            }
            continue;
        } else if (tiles[i].distanceTo(dest) < 3d) {
            return tiles[i];
        }
        /* Tile is on map and isn't currently "targeted" (dest), let's check it out.
			 * Iterate over all tiles succeeding it. */
        for (int a = i - 1; a >= 0; --a) {
            /* The tile before the tile on map isn't on map.  Break out to the next tile.
				 * Explanation: Path wraps around something and must be followed.
				 * We cannot suddenly click out of a "pathable" region (104x104).
				 * In these cases, we can assume a better tile will become available. */
            if (!tiles[a].matrix(ctx).valid() || !tiles[a].matrix(ctx).onMap()) {
                continue out;
            }
            /* If a tile (successor) is currently targeted, return the tile that was the "best"
				 * on the map for getNext as we can safely assume we're following our path. */
            if (tiles[a].distanceTo(dest) < 3d) {
                return tiles[i];
            }
        }
    }
    /* Well, we've made it this far.  Return the first tile if nothing else is on our map.
		* CLICKING BACK AND FORTH PREVENTION: check for dest not to be null if we're just starting
		 * our path.  If our destination isn't null and we somehow got to our first tile then
		 * we can safely assume lag is being experienced and return null until next call of getNext.
		 * TELEPORTATION SUPPORT: If destination is set but but we're not moving, assume
		 * invalid destination tile from teleportation reset and return first tile. */
    final Player p = ctx.players.local();
    if (p != null && !p.inMotion() && dest != Tile.NIL) {
        for (int i = tiles.length - 1; i >= 0; --i) {
            if (tiles[i].matrix(ctx).onMap()) {
                return tiles[i];
            }
        }
    }
    if (tiles.length == 0 || !tiles[0].matrix(ctx).onMap()) {
        return null;
    }
    return tiles[0];
}
Also used : Condition(org.powerbot.script.Condition) Tile(org.powerbot.script.Tile)

Example 2 with Condition

use of org.powerbot.script.Condition in project powerbot by powerbot.

the class TilePath method next.

@Override
public Tile next() {
    /* Wait for map not to be loading */
    final int state = ctx.game.clientState();
    if (state == Constants.GAME_LOADING) {
        Condition.wait(new Condition.Check() {

            @Override
            public boolean poll() {
                return ctx.game.clientState() != Constants.GAME_LOADING;
            }
        });
        return next();
    }
    if (state != Constants.GAME_LOADED) {
        return null;
    }
    /* Get current destination */
    final Tile dest = ctx.movement.destination();
    /* Label main loop for continuing purposes */
    out: /* Iterate over all tiles but the first tile (0) starting with the last (length - 1). */
    for (int i = tiles.length - 1; i > 0; --i) {
        /* The tiles not in view, go to the next. */
        if (!tiles[i].matrix(ctx).valid() || !tiles[i].matrix(ctx).onMap()) {
            continue;
        }
        /* LARGELY SPACED PATH SUPPORT: If the current destination is the tile on the map, return that tile
			 * as the next one will be coming soon (we hope/assume this, as short spaced paths should never experience
			 * this condition as one will be on map before it reaches the current target). */
        if (dest == Tile.NIL) {
            if (tiles[i].matrix(ctx).reachable()) {
                return tiles[i];
            }
            continue;
        } else if (tiles[i].distanceTo(dest) < 3d) {
            return tiles[i];
        }
        /* Tile is on map and isn't currently "targeted" (dest), let's check it out.
			 * Iterate over all tiles succeeding it. */
        for (int a = i - 1; a >= 0; --a) {
            /* The tile before the tile on map isn't on map.  Break out to the next tile.
				 * Explanation: Path wraps around something and must be followed.
				 * We cannot suddenly click out of a "pathable" region (104x104).
				 * In these cases, we can assume a better tile will become available. */
            if (!tiles[a].matrix(ctx).valid() || !tiles[a].matrix(ctx).onMap()) {
                continue out;
            }
            /* If a tile (successor) is currently targeted, return the tile that was the "best"
				 * on the map for getNext as we can safely assume we're following our path. */
            if (tiles[a].distanceTo(dest) < 3d) {
                return tiles[i];
            }
        }
    }
    /* Well, we've made it this far.  Return the first tile if nothing else is on our map.
		* CLICKING BACK AND FORTH PREVENTION: check for dest not to be null if we're just starting
		 * our path.  If our destination isn't null and we somehow got to our first tile then
		 * we can safely assume lag is being experienced and return null until next call of getNext.
		 * TELEPORTATION SUPPORT: If destination is set but but we're not moving, assume
		 * invalid destination tile from teleportation reset and return first tile. */
    final Player p = ctx.players.local();
    if (p != null && !p.inMotion() && dest != Tile.NIL) {
        for (int i = tiles.length - 1; i >= 0; --i) {
            if (tiles[i].matrix(ctx).onMap()) {
                return tiles[i];
            }
        }
    }
    if (tiles.length == 0 || !tiles[0].matrix(ctx).onMap()) {
        return null;
    }
    return tiles[0];
}
Also used : Condition(org.powerbot.script.Condition) Tile(org.powerbot.script.Tile)

Aggregations

Condition (org.powerbot.script.Condition)2 Tile (org.powerbot.script.Tile)2