use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.
the class LocalPath method getCosts.
static double[][] getCosts(final ClientContext ctx, final int w, final int h) {
final Client client = ctx.client();
final Landscape landscape = client.getLandscape();
final org.powerbot.bot.rt4.client.Tile[][][] tiles;
final int floor = client.getFloor();
final org.powerbot.bot.rt4.client.Tile[][] rows;
if (landscape == null || (tiles = landscape.getTiles()) == null || floor < 0 || floor > tiles.length || (rows = tiles[floor]) == null) {
return new double[0][0];
}
final double[][] arr = new double[w][h];
for (int x = 0; x < Math.min(w, rows.length); x++) {
final org.powerbot.bot.rt4.client.Tile[] row = rows[x];
if (row == null) {
continue;
}
final int h2 = row.length;
for (int y = 0; y < Math.min(h, h2); y++) {
final org.powerbot.bot.rt4.client.Tile tile = row[y];
if (tile == null) {
continue;
}
if (tile.getGameObjectLength() > 0 || tile.getBoundaryObject() != null || tile.getWallObject() != null) {
for (int dx = Math.max(0, x - 1); dx <= Math.min(w - 1, x + 1); dx++) {
for (int dy = Math.max(0, y - 1); dy <= Math.min(h - 1, y + 1); dy++) {
arr[dx][dy] += Random.nextDouble();
}
}
}
}
}
return arr;
}
use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.
the class Menu method click.
/**
* Attempts to click the menu command provided by the filter.
*
* @param filter The filter to apply to the menu.
* @param click Whether or not to left-click.
* @return {@code true} if the mouse has successfully clicked within the bounds of the
* MenuCommand.
*/
private boolean click(final Filter<? super MenuCommand> filter, final boolean click) {
final Client client = ctx.client();
int idx;
if (client == null || (idx = indexOf(filter)) == -1) {
return false;
}
if (click && !client.isMenuOpen() && idx == 0) {
return ctx.input.click(true);
}
if (!client.isMenuOpen()) {
if (!ctx.input.click(false)) {
return false;
}
}
if (!Condition.wait(new Condition.Check() {
@Override
public boolean poll() {
return client.isMenuOpen();
}
}, 15, 10) || (idx = indexOf(filter)) == -1) {
return false;
}
final Rectangle rectangle = new Rectangle(client.getMenuX(), client.getMenuY() + 19 + idx * 15, client.getMenuWidth(), 15);
Condition.sleep(Random.hicks(idx));
if (!ctx.input.move(Random.nextInt(rectangle.x, rectangle.x + rectangle.width), Random.nextInt(rectangle.y, rectangle.y + rectangle.height)) || !client.isMenuOpen()) {
return false;
}
final Point p = ctx.input.getLocation();
return client.isMenuOpen() && rectangle.contains(p) && (!click || ctx.input.click(true));
}
use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.
the class Menu method close.
/**
* Attempts to close the menu.
*
* @return {@code true} if the menu was closed, {@code false} otherwise.
*/
public boolean close() {
final Client client = ctx.client();
if (client == null) {
return false;
}
if (!client.isMenuOpen()) {
return true;
}
final Component c = ((InputSimulator) ctx.input).getComponent();
final Dimension d = new Dimension(c != null ? c.getWidth() : 0, c != null ? c.getHeight() : 0);
final int mx = client.getMenuX(), my = client.getMenuY();
final int w = (int) d.getWidth(), h = (int) d.getHeight();
int x1, x2;
final int y1, y2;
x1 = x2 = mx;
y1 = y2 = Math.min(h - 5, Math.max(4, my + Random.nextInt(-10, 10)));
x1 = Math.max(4, x1 + Random.nextInt(-30, -10));
x2 = x2 + client.getMenuWidth() + Random.nextInt(10, 30);
if (x2 <= w - 5 && (x1 - mx >= 5 || Random.nextBoolean())) {
ctx.input.move(x2, y2);
} else {
ctx.input.move(x1, y1);
}
return Condition.wait(new Condition.Check() {
@Override
public boolean poll() {
return client.isMenuOpen();
}
}, 10, 50);
}
use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.
the class Movement method destination.
/**
* Returns the destination of the player, as represented by the red flag on the mini-map while
* traversing. If the player is not moving, this will return {@link Tile#NIL}.
*
* @return The destination of the player.
*/
public Tile destination() {
final Client client = ctx.client();
if (client == null) {
return Tile.NIL;
}
final int dX = client.getDestinationX(), dY = client.getDestinationY();
if (dX <= 0 || dY <= 0) {
return Tile.NIL;
}
return ctx.game.mapOffset().derive(dX, dY);
}
use of ru.compscicenter.hpc2016.ha1.client.Client in project powerbot by powerbot.
the class Npc method valid.
@Override
public boolean valid() {
final Client client = ctx.client();
if (client == null || npc == null || npc.isNull()) {
return false;
}
final org.powerbot.bot.rt4.client.Npc[] arr = client.getNpcs();
for (final org.powerbot.bot.rt4.client.Npc a : arr) {
if (npc.equals(a)) {
return true;
}
}
return false;
}
Aggregations