Search in sources :

Example 1 with InputSimulator

use of org.powerbot.bot.InputSimulator 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);
}
Also used : Condition(org.powerbot.script.Condition) InputSimulator(org.powerbot.bot.InputSimulator) Dimension(java.awt.Dimension) Client(org.powerbot.bot.rt4.client.Client) Component(java.awt.Component) Point(java.awt.Point)

Aggregations

Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 InputSimulator (org.powerbot.bot.InputSimulator)1 Client (org.powerbot.bot.rt4.client.Client)1 Condition (org.powerbot.script.Condition)1