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.loggedIn()) {
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 int plane = ctx.game.floor();
final List<GroundItem> check = new ArrayList<GroundItem>();
ctx.groundItems.select(10).addTo(check);
for (int x = tile.x() - 10; x <= tile.x() + 10; x++) {
n: for (int y = tile.y() - 10; y <= tile.y() + 10; y++) {
int d = 0;
final Tile loc = new Tile(x, y, plane);
for (final GroundItem groundItem : ctx.groundItems.select(check).at(loc)) {
final Point screen = new TileMatrix(ctx, loc).centerPoint();
if (screen.x == -1 || screen.y == -1) {
continue n;
}
final String name = groundItem.name();
String s = "";
s += groundItem.id();
if (!name.isEmpty()) {
s += " " + name;
}
final int stack = groundItem.stackSize();
if (stack > 1) {
s += " (" + groundItem.stackSize() + ")";
}
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 DrawObjects method repaint.
@Override
public void repaint(final Graphics render) {
if (!ctx.game.loggedIn()) {
return;
}
final Player player = ctx.players.local();
if (player == null) {
return;
}
final FontMetrics metrics = render.getFontMetrics();
final int textHeight = metrics.getHeight();
final Map<Tile, AtomicInteger> counts = new HashMap<Tile, AtomicInteger>();
for (final GameObject object : ctx.objects.select(15)) {
final Tile t = object.tile();
if (!counts.containsKey(t)) {
counts.put(t, new AtomicInteger(0));
}
final Point p = object.centerPoint();
if (p.x == -1) {
continue;
}
render.setColor(Color.black);
render.fillRect(p.x - 1, p.y - 1, 2, 2);
final int mainId = object.mainId();
final int animation = object.animation();
final String n = object.name();
String s = (n.isEmpty() ? "" : n + " - ") + object.id();
if (animation != -1) {
s = s + " (A: " + animation + ")";
}
if (mainId != -1) {
if (animation != -1) {
s = s.replace(')', ',') + " MID: " + mainId + ")";
} else {
s = s + " (MID: " + mainId + ")";
}
}
final int ty = p.y - textHeight / 2;
final int tx = p.x - metrics.stringWidth(s) / 2;
render.setColor(C[object.type().ordinal()]);
render.drawString(s, tx, ty - textHeight * counts.get(t).getAndIncrement());
}
}
use of org.powerbot.script.Tile in project powerbot by powerbot.
the class DrawProjectiles method repaint.
@Override
public void repaint(final Graphics render) {
if (!ctx.game.loggedIn()) {
return;
}
for (final Projectile projectile : ctx.projectiles.select()) {
final Tile t = projectile.tile();
final TileMatrix m = new TileMatrix(ctx, t);
if (!m.valid()) {
continue;
}
m.bounds(new int[] { -128, 128, -256, 0, -128, 128 });
m.draw(render, 255);
}
}
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;
}
Aggregations