Example #1
0
  @Override
  public int loop() {
    System.out.println("Mainloop called.");

    while (gui.isShowing()) {
      System.out.println("Waiting for the GUI!");
      return Random.nextInt(100, 200);
    }

    if (stopScript) {
      System.out.println("Terminating script!");
      return -1;
    }

    if (container != null) {
      Node job = container.state();
      if (job != null) {
        container.set(job);
        getContainer().submit(job);
        job.join();
      }
    }

    return Random.nextInt(50, 100);
  }
Example #2
0
 public Point getNextViewportPoint() {
   final Rectangle rect = getBoundingRectangle();
   if (rect.x == -1 || rect.y == -1 || rect.width == -1 || rect.height == -1) {
     return new Point(-1, -1);
   }
   final int min_x = rect.x + 1, min_y = rect.y + 1;
   final int max_x = min_x + rect.width - 2, max_y = min_y + rect.height - 2;
   return new Point(
       Random.nextGaussian(min_x, max_x, rect.width / 3),
       Random.nextGaussian(min_y, max_y, rect.height / 3));
 }
Example #3
0
 public void setCameraRelativeTo(final Locatable reference) {
   final Tile playerTile = Players.getLocal().getLocation();
   final Tile referenceTile = reference.getLocation();
   if (playerTile.getX() < referenceTile.getX()) {
     Camera.setAngle(Random.nextInt(250, 270));
   } else if (playerTile.getX() > referenceTile.getX()) {
     Camera.setAngle(Random.nextInt(80, 100));
   } else if (playerTile.getY() > referenceTile.getY()) {
     Camera.setAngle(Random.nextInt(170, 180));
   } else if (playerTile.getY() < referenceTile.getY()) {
     Camera.setAngle(Random.nextInt(350, 360));
   }
 }
 void dropAllExcept(int lowerBound, int upperBound, int... dontDropThis) {
   for (Item i : Inventory.getItems()) {
     for (int id : dontDropThis) {
       if (!(i.getId() == id)) {
         Mouse.hop(
             i.getWidgetChild().getAbsoluteX() + Random.nextInt(lowerBound, upperBound),
             i.getWidgetChild().getAbsoluteY() + Random.nextInt(lowerBound, upperBound));
         i.getWidgetChild().interact("Drop");
         Status = "Dropping logs";
       }
     }
   }
 }
Example #5
0
 public boolean traverseWebPath() {
   for (Edge e : steps) {
     System.out.println(e);
     Time.sleep(Random.nextInt(300, 800));
     WebComponent component = e.getComponent();
     if (e.isaToB()) {
       if (component.hasActionAtoB()) {
         if (component.doActionAtoB()) {
           continue;
         }
         return false;
       } else {
         walkToTile(component.getB());
       }
     } else {
       if (component.hasActionBtoA()) {
         if (component.doActionBtoA()) {
           continue;
         }
         return false;
       } else {
         walkToTile(component.getA());
       }
     }
   }
   if (Calculations.distance(Players.getLocal().getPosition(), getEndTile()) > 10) {
     walkToTile(getEndTile());
   }
   return Calculations.distance(Players.getLocal().getPosition(), getEndTile()) < 10;
 }
 @Override
 public void execute() {
   if (Random.nextInt(1, 250) < 14) {
     executeAntiban();
   }
   Task.sleep(1000, 2000);
 }
Example #7
0
 public void run() {
   if (!Calculations.isPointOnScreen(Safespot.startTile.getCentralPoint())
       ? Walking.walk(Safespot.startTile)
       : Safespot.startTile.click(true)) {
     Sleeping.waitWhileMoving();
     Time.sleep(Random.nextInt(200, 500));
   }
 }
Example #8
0
  @Override
  public int loop() {
    if (lost) {
      return Random.nextInt(1000, 3000);
    }
    if (!start) return Random.nextInt(1000, 2000);

    if (jobContainer != null) {
      final Node job = jobContainer.state();
      if (job != null) {
        jobContainer.set(job);
        getContainer().submit(job);
        job.join();
      }
    }
    return Random.nextInt(50, 250);
  }
 /**
  * Selects the specified item in the inventory
  *
  * @param item The item to select.
  * @return <tt>true</tt> if the item was selected; otherwise <tt>false</tt>.
  */
 public static boolean selectItem(final Item item) { // TODO fix index 0
   final int itemID = item.getId();
   Item selItem = getSelectedItem();
   if (selItem != null && selItem.getId() == itemID) {
     return true;
   }
   if (selItem != null) {
     selItem.getWidgetChild().interact("Use");
     Task.sleep(Random.nextInt(500, 700));
   }
   if (!item.getWidgetChild().interact("Use")) {
     return false;
   }
   for (int c = 0; c < 5 && (selItem = getSelectedItem()) == null; c++) {
     Task.sleep(Random.nextInt(500, 700));
   }
   return selItem != null && selItem.getId() == itemID;
 }
Example #10
0
 public static void eat() {
   if (Players.getLocal().getHpPercent() < 80 && Inventory.getCount(Main.Food) > 0) {
     for (Item food : Inventory.getItems()) {
       if (food.getId() == Main.Food) {
         if (food.getWidgetChild().click(true)) {
           Time.sleep(Random.nextInt(500, 2500));
         }
       }
     }
   }
 }
 void executeAntiban() {
   int dx, dy;
   int r = Random.nextInt(0, 4);
   switch (r) {
     case 0:
     case 1:
     default:
       Status = "AntiBan";
       Camera.setAngle(Random.nextInt(20, 300));
       break;
     case 2:
     case 3:
       Status = "AntiBan";
       dx = Random.nextInt(-30, 30);
       dy = Random.nextInt(-30, 30);
       Mouse.move(Mouse.getX() + dx, Mouse.getY() + dy);
       Task.sleep(20, 150);
       break;
   }
 }
Example #12
0
 @Override
 public int loop() {
   if (jobContainer != null) {
     final Node job = jobContainer.state();
     if (job != null) {
       jobContainer.set(job);
       getContainer().submit(job);
       job.join();
     }
   }
   return Random.nextInt(10, 50);
 }
 boolean interact(Entity entity, int lowerBound, int upperBound, String action) {
   while (!Mouse.isReady()) ;
   if (entity == null || !entity.validate()) {
     return false;
   }
   Point entityPoint =
       new Point(
           entity.getCentralPoint().x + Random.nextInt(lowerBound, upperBound),
           entity.getCentralPoint().y + Random.nextInt(lowerBound, upperBound));
   while (!Mouse.getLocation().equals(entityPoint)) {
     Mouse.hop(
         entity.getCentralPoint().x + Random.nextInt(lowerBound, upperBound),
         entity.getCentralPoint().y + Random.nextInt(lowerBound, upperBound));
   }
   if (Mouse.getLocation().equals(entityPoint)) {
     Mouse.click(false);
     if (Menu.contains(action)) {
       Menu.select(action);
     }
   }
   return true;
 }
 public int loop() {
   if (jobs == null) {
     jobs = new Tree(new Node[] {new Chopper(), new Dropper()});
   }
   final Node job = jobs.state();
   if (job != null) {
     jobs.set(job);
     getContainer().submit(job);
     job.join();
     return 0;
   }
   return Random.nextInt(200, 300);
 }
Example #15
0
  @Override
  public void execute() {

    switch (Random.nextInt(0, 200)) {
      case 0:
        Camera.setAngle(Random.nextInt(10, 80));
        break;
      case 1:
        Camera.setAngle(Random.nextInt(80, 220));
        break;
      case 2:
        Tabs.STATS.open();
        Mouse.move(644, 465);
        sleep(1000, 2000);
        Tabs.INVENTORY.open();
        break;
      case 3:
        Tabs.FRIENDS.open();
        sleep(1000, 2000);
        Tabs.INVENTORY.open();
        break;
    }
  }
Example #16
0
  @Override
  public void execute() {

    int currentHp = Integer.parseInt(Widgets.get(748, 8).getText());
    if (currentHp < Data.totalHp * 0.5) {
      Item food = Inventory.getItem(Methods.getFoodId());
      if (food != null) {
        Data.status = "Eating food.";
        food.getWidgetChild().click(true);
      }
    }

    SceneObject rock = SceneEntities.getNearest(64699);
    Data.status = "Doing jump...";
    if (rock.isOnScreen()) {
      if (!Players.getLocal().isMoving() && Players.getLocal().getAnimation() == -1) {
        rock.interact("Cross");
        Task.sleep(Random.nextInt(400, 600));
      }
    } else {
      Camera.setPitch(Random.nextInt(5, 25));
      Camera.turnTo(rock, Random.nextInt(-25, 25));
    }
  }
Example #17
0
  @Override
  public void run() {
    Filter attackingGhoul =
        new Filter<NPC>() {
          public boolean accept(NPC npc) {
            return npc.getName().equals("Hellhound") && npc.getInteracting() == Players.getLocal();
          }
        };

    Filter freeGhoulToAttack =
        new Filter<NPC>() {
          public boolean accept(NPC npc) {
            return !npc.isInCombat() && npc.getName().equals("Hellhound");
          }
        };

    if (NPCs.getNearest(attackingGhoul) != null) Main.Hellhound = NPCs.getNearest(attackingGhoul);
    else Main.Hellhound = NPCs.getNearest(freeGhoulToAttack);

    if (Main.Hellhound.isOnScreen()) {
      if (Main.Hellhound.getInteracting() == null
          && !underAttack()
          && Main.Hellhound.isOnScreen()
          && Main.Hellhound != null) {
        Mouse.move(Main.Hellhound.getCentralPoint().x, Main.Hellhound.getCentralPoint().y);
        Time.sleep(50);
        if (!Menu.select("Attack")) {
          Mouse.move(Main.Hellhound.getCentralPoint().x, Main.Hellhound.getCentralPoint().y);
          Time.sleep(50);
          Menu.select("Attack");
        }
      }
    } else {
      if (Calculations.distance(Players.getLocal().getLocation(), Main.Hellhound.getLocation())
          <= 5) {
        Camera.turnTo(Main.Hellhound);
      } else {
        Walking.walk(Main.Hellhound.getLocation());
      }
    }
    Time.sleep(Random.nextInt(1000, 1200));
    while (Players.getLocal().isMoving() && !Main.Hellhound.isInCombat()) {
      Time.sleep(100);
    }
  }
Example #18
0
  // Author: Zasz
  public static void takeitem(GroundItem item) {
    Point point = item.getCentralPoint();
    point = new Point(point.x - 3, point.y - 10);
    boolean taken = false;
    for (int i = 0; i < 7; i++) {
      Mouse.move(point.x, point.y);
      Time.sleep(50);
      // log.info(item.getGroundItem().getName());
      if (Menu.select("Take", item.getGroundItem().getName())) {
        Sleeping.waitWhileMoving();
        taken = true;
        break;
      }
      if (i > 5) {
        Camera.setAngle(Camera.getAngleTo(Random.nextInt(15, 25)));
      }
      point = new Point(point.x + i, point.y + i);
    }

    if (taken) {
      addLootTaken(item.getGroundItem(), item.getGroundItem().getStackSize());
    }
  }
Example #19
0
  @Override
  public void run() {
    if (Widgets.clickContinue()) {
      verbose("Listening to his energetic shouting in this black hole...");
      Time.sleep(Random.nextInt(2000, 3500));
      return;
    }

    if (getSlotId(0) != -1) {
      verbose("WIDGET VALIDATED: Quiz question");
      final int[] slots = {getSlotId(0), getSlotId(1), getSlotId(2)};
      verbose("WIDGET DEBUG: Slots " + Arrays.toString(slots));

      int[] valid = null;
      verbose("Attempting matches");
      int name_index = 0;
      for (final int[] QUIZ_ITEMS : WIDGET_QUIZ_ITEMS) {
        verbose("Checking " + WIDGET_QUIZ_NAMES[name_index] + " " + Arrays.toString(QUIZ_ITEMS));
        int count = 0;
        for (final int ITEM : QUIZ_ITEMS) {
          verbose("SEARCH: " + ITEM + " in " + Arrays.toString(QUIZ_ITEMS));
          for (final int slot : slots) {
            if (slot == ITEM) {
              count++;
            }
          }
          verbose("NEW COUNT: " + count);
        }
        verbose("FINAL COUNT: " + count);

        if (count == 2) {
          verbose(
              "Generalized type: "
                  + WIDGET_QUIZ_NAMES[name_index]
                  + " "
                  + Arrays.toString(QUIZ_ITEMS)
                  + ".");
          valid = QUIZ_ITEMS;
          break;
        }

        ++name_index;
      }

      if (valid != null) {
        verbose("== ENTER SEARCH ==");
        for (int index = 0; index < slots.length; index++) {
          int count = 0;
          for (final int id : valid) {
            if (id == slots[index]) {
              count++;
            }
          }
          verbose(
              "SEARCH "
                  + index
                  + " ("
                  + slots[index]
                  + ") IN "
                  + Arrays.toString(valid)
                  + " RETURNED "
                  + count);
          if (count == 0) {
            verbose("NO MATCH == FOUND INVALID CHILD");
            final WidgetChild widgetChild = getSlot(index);
            verbose("Attempting click.");
            if (widgetChild != null && widgetChild.validate()) {
              verbose(
                  "WIDGET INTERACT: \"Continue\": "
                      + Boolean.toString(widgetChild.interact("Continue")));
              Time.sleep(Random.nextInt(800, 1200));
            }
            return;
          }
        }
      }
    }
  }
Example #20
0
 @Override
 public void execute() {
   Widgets.get(905, 14).click(true);
   Variables.status = "mixing";
   Task.sleep(Random.nextInt(400, 900));
 }
Example #21
0
  public static void DyanmicSleep() {
    Area InsideBank = Areas.Bank;
    String SleepType = SleepName;

    // Dynamic Sleeps
    switch (SleepType) {
      case "EnterAlter": // Dynamic EnterAlter Sleep
        while (tenSeconds.isRunning()) {
          dynamicSleepStatus = "In EnterAlter";
          Area OutsideAlter = Areas.AlterEntrence;
          if (!OutsideAlter.contains(Players.getLocal().getLocation())) {
            dynamicSleepStatus = "Not In";
            break;
          }
        }
        break;
      case "CraftRunes": // Dynamic Crafting Runes Sleep
        while (tenSeconds.isRunning()) {
          dynamicSleepStatus = "In CraftRunes";
          if (Inventory.getItem(CRAFTEDRUNE_ID) != null) {
            dynamicSleepStatus = "Not In";
            break;
          }
        }
        break;
      case "ExitPortal": // Dynamic Leaving Alter Sleep
        while (tenSeconds.isRunning()) {
          dynamicSleepStatus = "In ExitPortal";
          Area InsideAlter = Areas.InsideAlter;
          if (!InsideAlter.contains(Players.getLocal().getLocation())) {
            dynamicSleepStatus = "Not In";
            break;
          }
        }
        break;
      case "Resting": // Dynamic Resting Sleep
        while (twoMinutes.isRunning()) {
          dynamicSleepStatus = "In Resting";
          int EnergyLevel = Walking.getEnergy();
          if (EnergyLevel == Random.nextInt(90, 100)) {
            dynamicSleepStatus = "Not In";
            break;
          }
        }
        break;
      case "OpenBank": // Dynamic Bank is Open Sleep
        while (tenSeconds.isRunning()) {
          dynamicSleepStatus = "In OpenBank";
          if (Bank.isOpen()) {
            dynamicSleepStatus = "Not In";
            break;
          }
        }
        break;
      case "PlayerIsIdle": // Dynamic Player is Idle Sleep
        while (tenSeconds.isRunning()) {
          dynamicSleepStatus = "In PlayerIsIdle";
          if (Players.getLocal().isIdle()) {
            dynamicSleepStatus = "Not In";
            break;
          }
        }
        break;
      case "EssenceInInventory": // Dynamic Essences in Inventory Sleep
        while (tenSeconds.isRunning()) {
          dynamicSleepStatus = "In EssenceInInventory";
          if (Inventory.getItem(ESSENCE_ID) == null) {
            dynamicSleepStatus = "Not In";
            break;
          }
        }
        break;
    }
  }
Example #22
0
 @Override
 public void execute() {
   if (GlobalConstant.WIELDED_ID != -1
       && Settings.get(300) == 1000
       && Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 10 - 200) {
     if (Players.getLocal().getAppearance()[GlobalConstant.WEAPON] != GlobalConstant.EXCALIBUR
         && (Tabs.getCurrent().equals(Tabs.INVENTORY) || Tabs.INVENTORY.open())) {
       final Item excalibur = Inventory.getItem(GlobalConstant.EXCALIBUR);
       if (excalibur != null) {
         excalibur.getWidgetChild().click(true);
         PauseHandler.pause(
             new PauseHandler.Condition() {
               @Override
               public boolean validate() {
                 return Players.getLocal().getAppearance()[GlobalConstant.WEAPON]
                     == GlobalConstant.EXCALIBUR;
               }
             },
             (long) Random.nextInt(750, 1500));
       }
     } else if (Tabs.getCurrent().equals(Tabs.ATTACK) || Tabs.ATTACK.open()) {
       final WidgetChild bar = Widgets.get(884, 4);
       if (bar.validate()) {
         bar.click(true);
         PauseHandler.pause(
             new PauseHandler.Condition() {
               @Override
               public boolean validate() {
                 return Settings.get(300) != 1000;
               }
             },
             (long) Random.nextInt(400, 800));
       }
     }
     return;
   }
   if (GlobalConstant.KEEP_ALIVE
       && Checks.getLP() < Skills.getRealLevel(Skills.CONSTITUTION) * 0.4f * 10) {
     if (Checks.isOutside()) {
       if (Players.getLocal().getAnimation() == -1) {
         final WidgetChild[] widgets = {Widgets.get(750, 2), Widgets.get(750, 6)};
         if (widgets[0].validate() && widgets[1].validate()) {
           if (widgets[Random.nextInt(0, widgets.length)].interact("Rest"))
             PauseHandler.pause(
                 new PauseHandler.Condition() {
                   @Override
                   public boolean validate() {
                     return Players.getLocal().getAnimation() != -1;
                   }
                 },
                 (long) Random.nextInt(750, 1500));
         }
       }
       Task.sleep(400, 800);
     } else {
       if (Calculations.distanceTo(GlobalConstant.TILE_BANK) > 5) {
         if (Traverse.walk(GlobalConstant.TILE_BANK)) {
           PauseHandler.pause(
               new PauseHandler.Condition() {
                 @Override
                 public boolean validate() {
                   return Walking.getDestination() == null
                       || Calculations.distanceTo(Walking.getDestination()) < 8;
                 }
               },
               (long) Random.nextInt(500, 1000));
         }
       }
     }
   } else {
     if (Checks.isOutside()) {
       final SceneObject ladder = SceneEntities.getNearest(GlobalConstant.ROPE_DOWN_ID);
       if (ladder != null && ladder.interact("Climb"))
         PauseHandler.pause(
             new PauseHandler.Condition() {
               @Override
               public boolean validate() {
                 return !Checks.isOutside();
               }
             },
             750l);
       else if (ladder != null && Calculations.distanceTo(ladder) > 5)
         PauseHandler.walk(ladder, (long) Random.nextInt(250, 750));
     } else if (inCombat() || Players.getLocal().isInCombat()) {
       final Tile rockTile = GlobalConstant.TILE_ROCKS[Checks.isGold()][Mine.getCurrent()];
       if (true
           || Calculations.distanceTo(GlobalConstant.TILE_BANK)
               < Calculations.distanceTo(rockTile)) {
         if (Calculations.distanceTo(GlobalConstant.TILE_BANK) > 6
             && Traverse.walk(GlobalConstant.TILE_BANK)) {
           PauseHandler.pause(
               new PauseHandler.Condition() {
                 @Override
                 public boolean validate() {
                   return Walking.getDestination() == null
                       || Calculations.distanceTo(Walking.getDestination()) < 8;
                 }
               },
               (long) Random.nextInt(200, 500));
         }
       } else {
         final SceneObject rock = SceneEntities.getAt(rockTile);
         final NPC npc =
             NPCs.getNearest(
                 new Filter<NPC>() {
                   @Override
                   public boolean accept(final NPC npc) {
                     return npc.getInteracting() != null
                         && npc.getInteracting().equals(Players.getLocal())
                         && Arrays.binarySearch(GlobalConstant.LRC_NPC, npc.getId()) >= 0;
                   }
                 });
         if (rock != null && npc != null) {
           final Tile hardcodedSafe =
               GlobalConstant.MINE_GOLD && Mine.getCurrent() == 0
                   ? GlobalConstant.GOLD_SAFE_SPOT
                   : !GlobalConstant.MINE_GOLD && Mine.getCurrent() == 2
                       ? GlobalConstant.COAL_SAFE_SPOT
                       : null;
           if (hardcodedSafe != null) {
             hardcodedSafe
                 .randomize(0, Mine.getCurrent() == 2 ? 4 : 1, 1, Mine.getCurrent() == 0 ? -4 : 1)
                 .clickOnMap();
           } else {
             final Tile[] bounds = rock.getArea().getBoundingTiles();
             Arrays.sort(
                 bounds,
                 new Comparator<Tile>() {
                   @Override
                   public int compare(final Tile t1, final Tile t2) {
                     return Calculations.distance(t1, npc.getLocation())
                             < Calculations.distance(t2, npc.getLocation())
                         ? 1
                         : -1;
                   }
                 });
             final int[][] flags = Walking.getCollisionFlags(Game.getPlane());
             final Tile colOffset =
                 Walking.getCollisionOffset(Game.getPlane())
                     .derive(Game.getBaseX(), Game.getBaseY());
             Tile toWalk = null;
             for (final int[] offset : new int[][] {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}) {
               final Tile derive = bounds[0].derive(offset[0], offset[1]);
               if (Nodes.walkable(flags, colOffset, derive)) {
                 if (toWalk == null
                     || Calculations.distance(derive, npc) > Calculations.distance(toWalk, npc))
                   toWalk = derive;
               }
             }
             if (toWalk != null) {
               if (!toWalk.isOnScreen()) Camera.turnTo(toWalk);
               toWalk.interact("Walk here");
             }
           }
           Task.sleep(100, 300);
           final int lp = Checks.getLP();
           final Timer timer = new Timer((long) Random.nextInt(7500, 10000));
           while (Players.getLocal().isInCombat()
               && Checks.getLP() >= lp
               && !Context.get().getScriptHandler().isPaused()
               && timer.isRunning()) Task.sleep(200, 800);
         }
       }
     }
   }
 }