예제 #1
0
 /**
  * Types a sequence of text
  *
  * @param text The text to type
  * @param minDelay The minimum delay between each key in milliseconds
  * @param maxDelay The maximum delay between each key in milliseconds
  */
 public void type(String text, int minDelay, int maxDelay) {
   final char[] chars = text.toCharArray();
   for (char c : chars) {
     type(c);
     Utils.sleep(Utils.random(minDelay, maxDelay));
   }
 }
예제 #2
0
 /**
  * Types a sequence of text
  *
  * @param text The text to type
  */
 public void type(String text) {
   final char[] chars = text.toCharArray();
   for (char c : chars) {
     type(c);
     Utils.sleep(Utils.random(60, 250));
   }
 }
예제 #3
0
 public boolean open() {
   if (isOpen()) {
     return true;
   }
   GameObject box =
       ctx.objects.getNearest(
           new Filter<GameObject>() {
             @Override
             public boolean accept(GameObject element) {
               for (int id : DEPOSIT_BOX_IDS) {
                 if (id == element.getId()) {
                   return true;
                 }
               }
               return false;
             }
           });
   if (box != null) {
     box.interact("Deposit");
     Timer t = new Timer(3000);
     while (!isOpen() && t.isRunning()) {
       Utils.sleep(150);
     }
   }
   return isOpen();
 }
예제 #4
0
 public boolean close() {
   if (!isOpen()) {
     return true;
   }
   Widget close =
       ctx.widgets
           .getValidated(
               new Filter<Widget>() {
                 @Override
                 public boolean accept(Widget element) {
                   return element.getParentId() == WIDGET_ID && element.getId() == CLOE_COMP_ID;
                 }
               })
           .get(0);
   if (close != null) {
     Point p = getCenter(close.getBounds());
     ctx.mouse.click(p.x, p.y);
     Timer t = new Timer(3000);
     while (isOpen() && t.isRunning()) {
       Utils.sleep(Utils.random(100, 200));
     }
   }
   return !isOpen();
 }
예제 #5
0
 public boolean deposit(int itemId, int amt) {
   int[] ids =
       ctx.widgets
           .getValidated(
               new Filter<Widget>() {
                 @Override
                 public boolean accept(Widget element) {
                   return element.getParentId() == WIDGET_ID && element.getId() == ITEM_COMP_ID;
                 }
               })
           .get(0)
           .getSlotContents();
   int count = 0;
   boolean stack = false;
   if (ctx.inventory.getItem(itemId).getAmount() > 1) {
     count = ctx.inventory.getCount(true, itemId);
     stack = true;
   } else {
     count = ctx.inventory.getCount(false, itemId);
   }
   int index = -1;
   for (int i = 0; i < ids.length; i++) {
     if (ids[i] == itemId) {
       index = i;
       break;
     }
   }
   if (index == -1) {
     return false;
   }
   DepositBoxSlot[] slots = DepositBoxSlot.values();
   DepositBoxSlot slot = null;
   for (DepositBoxSlot slot1 : slots) {
     if (slot1.getInvIndex() == index) {
       slot = slot1;
       break;
     }
   }
   if (slot == null) {
     return false;
   }
   switch (amt) {
     case 1:
     case 5:
     case 10:
       if (ctx.menu.getBounds() == null) {
         ctx.mouse.move(slot.getRandomPoint().x, slot.getRandomPoint().y);
         Utils.sleep(Utils.random(100, 250));
         Timer t = new Timer(3000);
         while (ctx.menu.getBounds() == null && t.isRunning()) {
           Utils.sleep(100);
         }
       }
       if (ctx.menu.getBounds() != null) {
         Point p = ctx.menu.getClickPoint(ctx.menu.getIndex("Deposit " + amt));
         ctx.mouse.click(p.x, p.y);
         Utils.sleep(Utils.random(100, 250));
       }
       break;
     default:
       if (ctx.menu.getBounds() == null) {
         ctx.mouse.move(slot.getRandomPoint().x, slot.getRandomPoint().y);
         Utils.sleep(Utils.random(100, 250));
         Timer t = new Timer(3000);
         while (ctx.menu.getBounds() == null && t.isRunning()) {
           Utils.sleep(100);
         }
       }
       if (amt >= ctx.inventory.getItem(itemId).getAmount() || amt == 0) {
         if (ctx.menu.getBounds() != null) {
           Point p = ctx.menu.getClickPoint(ctx.menu.getIndex("Deposit " + amt));
           ctx.mouse.click(p.x, p.y);
           Utils.sleep(Utils.random(100, 250));
         }
       } else {
         if (ctx.menu.getBounds() != null) {
           Point p = ctx.menu.getClickPoint(ctx.menu.getIndex("Deposit-X"));
           ctx.mouse.click(p.x, p.y);
           Utils.sleep(Utils.random(100, 250));
         }
       }
       break;
   }
   if (stack) {
     return ctx.inventory.getItem(itemId).getAmount() == count - amt;
   }
   return ctx.inventory.getCount(false, itemId) == count - amt;
 }
예제 #6
0
 /**
  * Holds a key down for a random time between min and max millis
  *
  * @param keycode The keycode, such as KeyEvent.VK_X
  * @param minMillis The minimum time to hold the key down for in milliseconds
  * @param maxMillis The maximum time to hold the key down for in milliseconds
  */
 public void hold(int keycode, int minMillis, int maxMillis) {
   hold(keycode, Utils.random(minMillis, maxMillis));
 }
예제 #7
0
 /**
  * Holds a key down for the given time
  *
  * @param keycode The keycode, such as KeyEvent.VK_X
  * @param millis The time to hold the key down for in milliseconds
  */
 public void hold(int keycode, int millis) {
   handler.pressKey(keycode);
   Utils.sleep(millis);
   handler.releaseKey(keycode);
 }
예제 #8
0
 /** Simulates pressing the 'enter' or 'return' key on the keyboard */
 public void enter() {
   ctx.keyboard.hold(KeyEvent.VK_ENTER, Utils.random(20, 50));
 }