use of org.powerbot.script.Tile in project powerbot by powerbot.
the class Movement method closestOnMap.
/**
* Grabs the closest tile on map relative to the given {@link Locatable}.
*
* @param locatable The locatable
* @return the {@link Tile}
*/
public Tile closestOnMap(final Locatable locatable) {
final Tile local = ctx.players.local().tile();
final Tile tile = locatable.tile();
if (local == Tile.NIL || tile == Tile.NIL) {
return Tile.NIL;
}
if (new TileMatrix(ctx, tile).onMap()) {
return tile;
}
final int x2 = local.x();
final int y2 = local.y();
int x1 = tile.x();
int y1 = tile.y();
final int dx = Math.abs(x2 - x1);
final int dy = Math.abs(y2 - y1);
final int sx = (x1 < x2) ? 1 : -1;
final int sy = (y1 < y2) ? 1 : -1;
int off = dx - dy;
for (; ; ) {
final Tile t = new Tile(x1, y1, local.floor());
if (new TileMatrix(ctx, t).onMap()) {
return t;
}
if (x1 == x2 && y1 == y2) {
break;
}
final int e2 = 2 * off;
if (e2 > -dy) {
off = off - dy;
x1 = x1 + sx;
}
if (e2 < dx) {
off = off + dx;
y1 = y1 + sy;
}
}
return Tile.NIL;
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class Bank method getBank.
private Interactive getBank() {
final Player p = ctx.players.local();
final Tile t = p.tile();
ctx.npcs.select().id(Constants.BANK_NPCS).viewable().select(UNREACHABLE_FILTER).nearest();
ctx.objects.select().id(Constants.BANK_BOOTHS, Constants.BANK_COUNTERS, Constants.BANK_CHESTS).viewable().select(UNREACHABLE_FILTER).nearest();
if (!ctx.properties.getProperty("bank.antipattern", "").equals("disable")) {
final Npc npc = ctx.npcs.poll();
final GameObject object = ctx.objects.poll();
return t.distanceTo(npc) < t.distanceTo(object) ? npc : object;
}
final double dist = Math.min(t.distanceTo(ctx.npcs.peek()), t.distanceTo(ctx.objects.peek()));
final double d2 = Math.min(2d, Math.max(0d, dist - 1d));
final List<Interactive> interactives = new ArrayList<Interactive>();
ctx.npcs.within(dist + Random.nextInt(2, 5)).within(ctx.npcs.peek(), d2);
ctx.objects.within(dist + Random.nextInt(2, 5)).within(ctx.objects.peek(), d2);
ctx.npcs.addTo(interactives);
ctx.objects.addTo(interactives);
final int len = interactives.size();
return len == 0 ? ctx.npcs.nil() : interactives.get(Random.nextInt(0, len));
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class Bank method nearest.
/**
* Returns the absolute nearest bank for walking purposes. Do not use this to open the bank.
*
* @return the {@link Locatable} of the nearest bank or {@link Tile#NIL}
* @see #open()
*/
public Locatable nearest() {
Locatable nearest = ctx.npcs.select().select(UNREACHABLE_FILTER).id(Constants.BANK_NPCS).nearest().poll();
final Tile loc = ctx.players.local().tile();
for (final GameObject object : ctx.objects.select().select(UNREACHABLE_FILTER).id(Constants.BANK_BOOTHS, Constants.BANK_COUNTERS, Constants.BANK_CHESTS).nearest().limit(1)) {
if (loc.distanceTo(object) < loc.distanceTo(nearest)) {
nearest = object;
}
}
if (nearest.tile() != Tile.NIL) {
return nearest;
}
return Tile.NIL;
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class GameObject method tile.
@Override
public Tile tile() {
final Client client = ctx.client();
final int r = relative();
final int rx = r >> 16, rz = r & 0xffff;
if (client != null && rx != 0 && rz != 0) {
return new Tile(client.getOffsetX() + (rx >> 7), client.getOffsetY() + (rz >> 7), client.getFloor());
}
return Tile.NIL;
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class GroundItem method valid.
@Override
public boolean valid() {
final Client c = ctx.client();
if (c == null || node.isNull()) {
return false;
}
final NodeDeque[][][] nd = c.getGroundItems();
if (nd != null) {
final int f = c.getFloor();
if (f < 0 || f >= nd.length || nd[f] == null) {
return false;
}
final Tile t = tile.tile().derive(-c.getOffsetX(), -c.getOffsetY());
if (t.x() < 0 || t.y() < 0 || t.x() >= nd[f].length) {
return false;
}
final NodeDeque[] nd2 = nd[f][t.x()];
if (nd2 == null || t.y() >= nd2.length) {
return false;
}
final NodeDeque d = nd2[t.y()];
return d != null && NodeQueue.get(d, ItemNode.class).contains(node);
}
return false;
}
Aggregations