use of org.powerbot.script.Tile in project powerbot by powerbot.
the class GroundItems method get.
private List<GroundItem> get(int radius, final int floor) {
if (radius < 1) {
radius = 110;
}
final List<GroundItem> r = new CopyOnWriteArrayList<GroundItem>();
final Client client = ctx.client();
final NodeDeque[][][] dequeArray;
if (client == null || (dequeArray = client.getGroundItems()) == null) {
return r;
}
final NodeDeque[][] rows;
if (floor > -1 && floor < dequeArray.length) {
rows = dequeArray[floor];
} else {
rows = null;
}
if (rows == null) {
return r;
}
final List<GroundItem> list = new LinkedList<GroundItem>();
final Tile tile = new Tile(client.getOffsetX(), client.getOffsetY(), floor);
final Tile ct = ctx.players.local().tile().derive(-tile.x(), -tile.y());
for (int x = Math.max(0, ct.x() - radius); x < Math.min(rows.length, ct.x() + radius + 1); x++) {
final NodeDeque[] row = rows[x];
if (row == null) {
continue;
}
for (int y = Math.max(0, ct.y() - radius); y < Math.min(row.length, ct.y() + radius + 1); y++) {
for (final ItemNode n : NodeQueue.get(row[y], ItemNode.class)) {
list.add(new GroundItem(ctx, tile.derive(x, y), n));
}
}
}
return list;
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class TilePath method traverse.
@Override
public boolean traverse(final EnumSet<TraversalOption> options) {
final Player local = ctx.players.local();
final Tile next = next();
if (next == null || local == null) {
return false;
}
final Tile dest = ctx.movement.destination();
if (next.equals(end())) {
if (next.distanceTo(ctx.players.local()) <= 2) {
return false;
}
if (end && (local.inMotion() || dest.equals(next))) {
return false;
}
end = true;
} else {
end = false;
}
if (options != null) {
if (options.contains(TraversalOption.HANDLE_RUN) && !ctx.movement.running()) {
final int e = ctx.movement.energyLevel();
run_energy.compareAndSet(-1, Random.nextInt(20, 90));
if (e >= run_energy.get() && ctx.movement.running(true)) {
run_energy.set(-1);
}
}
if (options.contains(TraversalOption.SPACE_ACTIONS) && local.inMotion() && dest.distanceTo(last) > 3d) {
spaced_action.compareAndSet(-1, Random.nextInt(5, 12));
final double d, d2 = dest.distanceTo(local);
if (d2 > spaced_action.get()) {
d = d2;
} else {
final double d3 = ctx.movement.distance(dest);
d = d3 != -1 ? d3 : d2;
}
if (d > (double) spaced_action.get()) {
return true;
}
}
}
last = next;
if (ctx.movement.step(next)) {
spaced_action.set(-1);
if (local.inMotion()) {
return Condition.wait(new Condition.Check() {
@Override
public boolean poll() {
return ctx.movement.destination().distanceTo(next) < 3;
}
}, 60, 10);
}
return next.distanceTo(ctx.players.local()) < 5d || Condition.wait(new Condition.Check() {
@Override
public boolean poll() {
return ctx.players.local().inMotion() && ctx.movement.destination().distanceTo(next) < 3;
}
}, 125, 10);
}
return false;
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class Camera method getAngleToLocatable.
private int getAngleToLocatable(final Locatable mobile) {
final Player local = ctx.players.local();
final Tile t1 = local != null ? local.tile() : null;
final Tile t2 = mobile.tile();
return t1 != null && t2 != null ? ((int) Math.toDegrees(Math.atan2(t2.y() - t1.y(), t2.x() - t1.x()))) - 90 : 0;
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class DrawGroundItems method repaint.
public void repaint(final Graphics render) {
if (ctx.game.clientState() != Constants.GAME_LOADED) {
return;
}
final Player player = ctx.players.local();
if (player == null) {
return;
}
final Tile tile = player.tile();
if (tile == null) {
return;
}
final FontMetrics metrics = render.getFontMetrics();
final int tHeight = metrics.getHeight();
final List<GroundItem> check = new ArrayList<GroundItem>();
ctx.groundItems.select(10).addTo(check);
for (int x = -10; x <= 10; x++) {
for (int y = -10; y <= 10; y++) {
int d = 0;
final Tile loc = tile.derive(x, y);
final Point screen = new TileMatrix(ctx, loc).centerPoint();
if (screen.x == -1) {
continue;
}
for (final GroundItem groundItem : ctx.groundItems.select(check).at(loc)) {
final String name = groundItem.name();
String s = "";
s += groundItem.id();
if (!name.isEmpty()) {
s += " " + name;
}
final int stack = groundItem.stackSize();
if (stack > 1) {
s += " (" + stack + ")";
}
final int ty = screen.y - tHeight * (++d) + tHeight / 2;
final int tx = screen.x - metrics.stringWidth(s) / 2;
render.setColor(Color.green);
render.drawString(s, tx, ty);
}
}
}
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class TDestination method draw.
public int draw(int idx, final Graphics render) {
final Tile dest = ctx.movement.destination();
drawLine(render, idx++, "Destination: " + (dest != null ? dest.toString() : "null"));
return idx;
}
Aggregations