private void attackSpider() {
   RSNPC spider = npc.getNearestFreeToAttackByID(4400);
   run();
   if (spider != null) {
     try {
       if (spider.isOnScreen() && spider.action("Attack")) {
         if (tries != 0) {
           tries = 0;
         }
         wait(random(800, 900));
         waitToStop();
         waitSafely(random(2200, 2400));
       } else {
         if (tries > 60) { // if there is no spider on screen in 6-12 seconds
           if (room == 1) {
             walk.to(room1.getRandomTile());
           } else {
             walk.to(room2);
           }
           tries = 0;
         } else {
           tries++;
         }
       }
     } catch (final Exception e) {
     }
   }
 }
示例#2
0
  public boolean onStart() {
    log("Welcome to Sneaky's Herb farmer");

    if (game.isLoggedIn()) {
      camera.setPitch(100);
      antiBan = new AntiBan(this);
      antiBan.start();
    } else {
      log("Please log in before starting this script.");
      scriptRunning = false;
      return false;
    }

    if (!camelotFarmingArea.contains(getMyPlayer().getLocation())) {
      log("Not in Camelot farming patch. Please start the script there.");
      scriptRunning = false;
      return false;
    }

    // Start GUI to select which Herb to farm
    HerbFarmerGUI GUI = new HerbFarmerGUI();
    GUI.setVisible(true);
    while (GUI.isVisible()) {
      sleep(50);
    }

    currentLocation = Location.CAMELOT;
    currentState = State.CHECK_CROPS;

    notedID = grimyID + 1;
    if (inventory.contains(notedID)) startingNoteSize = inventory.getItem(notedID).getStackSize();

    runTime = new Timer(0);
    marketPriceOfHerbs = grandExchange.lookup(grimyID).getGuidePrice();
    marketPriceOfSeeds = grandExchange.lookup(seedID).getGuidePrice();
    log("You are farming " + seedType);
    log("The market price of each " + seedType + " seed is: " + marketPriceOfSeeds + "gp");
    log("The market price of each " + seedType + " herb is: " + marketPriceOfHerbs + "gp");

    // check if inventory contains seeds, rake, dibber, spade
    if (!checkInventory()) {
      log("You do not have all of the required materials in your inventory");
      log("(Seeds, rake, dibber, and spade). Stopping script.");
      scriptRunning = false;
      return false;
    }

    return true;
  }
  @Override
  public int loop() {
    if (!inventory.contains(foodID)) {
      needBank = true;
      atSpiders = false;
      if (changeRooms) {
        room = random(1, 3);
      }
    }
    if (eat()) {
      return random(100, 250);
    }
    if (dropRewards()) {
      return random(600, 700);
    }
    if (atSpiders) {
      if ((RSNPC) player.getMine().getInteracting() == null) {
        attackSpider();
      } else {
        if (!drinkPots()) {
          mouseAntiban();
          antiban();
        }
      }
      return random(100, 250);
    }
    loc = player.getMine().getLocation();
    if (loc != null) {
      base = Bot.getClient().getBaseY();
      if (needBank && teleport && base > 4000 && teleport()) {
        return random(5000, 6000);
      }
      if (needBank && inventory.contains(229) && base < 4000) {
        if (dropVial()) {
          return random(600, 700);
        }
      }
      if (base < 4000) {
        if (needBank) {
          if (calculate.distanceTo(bankTile) < 4) {
            int ct = 0;
            try {
              if (!bank.isOpen()) {
                if (bank.open()) {
                  wait(random(500, 800));
                }
                while (!bank.isOpen()) {
                  wait(180);
                  ct++;
                  if (ct > 30) {
                    tries++;
                  }
                }
              }
            } catch (final Exception e) {
            }
            if (bank.isOpen()) {
              if (tries != 0) {
                tries = 0;
              }
              if (teleport) {
                if (tabs) {
                  if (bank.getCount(8007) > 0 && !inventory.contains(8007)) {
                    bank.withdraw(8007, 1);
                    return random(800, 1000);
                  }
                } else {
                  if (!inventory.contains(563)
                      || inventory.getCount(556) < 3
                      || !inventory.contains(554)) {
                    if (!inventory.contains(563) && bank.getCount(563) > 0) {
                      bank.withdraw(563, 1);
                      return random(800, 1000);
                    }
                    if (!inventory.contains(554) && bank.getCount(554) > 0) {
                      bank.withdraw(554, 1);
                      return random(800, 1000);
                    }
                    if (inventory.getCount(556) < 3 && bank.getCount(556) >= 3) {
                      bank.withdraw(556, 3);
                      return random(800, 1000);
                    }
                  }
                }
              }
              if (pots) {
                if (potions[0] == 1
                    && bank.getCount(potionID[0]) > 0
                    && inventory.getCount(potionID[0]) < amounts[0]) {
                  withdrawPotion(potionID[0], amounts[0]);
                  return random(800, 1000);
                } else if (potions[1] == 1
                    && bank.getCount(potionID[1]) > 0
                    && inventory.getCount(potionID[1]) < amounts[1]) {
                  withdrawPotion(potionID[1], amounts[1]);
                  return random(800, 1000);
                } else if (potions[2] == 1
                    && bank.getCount(potionID[2]) > 0
                    && inventory.getCount(potionID[2]) < amounts[2]) {
                  withdrawPotion(potionID[2], amounts[2]);
                  return random(800, 1000);
                } else if (potions[3] == 1
                    && bank.getCount(potionID[3]) > 0
                    && inventory.getCount(potionID[3]) < amounts[3]) {
                  withdrawPotion(potionID[3], amounts[3]);
                  return random(800, 1000);
                }
              }
              if (inventory.contains(foodID)) {
                needBank = false;
              } else {
                if (bank.getCount(foodID) < 1) {
                  log("no food left, stopping script...");
                  stopScript();
                }
                bank.withdraw(foodID, 0);
                return random(800, 1000);
              }
            } else {
              if (tries > 3) {
                walk.to(bankTile);
                tries = 0;
              } else {
                try {
                  if (!bank.isOpen()) {
                    if (bank.open()) {
                      wait(random(500, 800));
                    }
                    while (!bank.isOpen()) {
                      wait(180);
                      ct++;
                      if (ct > 30) {
                        tries++;
                      }
                    }
                  }
                } catch (final Exception e) {
                }
                // clickObject((!edge ? 782 : 26972), "Use-quickly");

              }
            }
          } else {
            walk.pathMM((!edge ? bankingPath : edgeBankingPath));
          }
        } else {
          if (calculate.distanceTo(entranceTile) < 5) {
            clickObject(16154, "Climb-down");
          } else {
            walk.pathMM(walk.reversePath((!edge ? bankingPath : edgeBankingPath)));
          }
        }
      } else if (base >= 5192 && base < 5200 && floor1.contains(loc)) {
        if (!needBank) {
          clickObject(16150, "Enter");
        } else {
          clickObject(16148, "Climb-up");
        }
      } else if (base >= 5168 && base < 5192 && floor1Middle.contains(loc)) {
        clickObject(16149, "Climb-down");
      } else if (base >= 5192 && base < 5200 && floor2.contains(loc)) {
        if (!needBank) {
          clickObject(16082, "Enter");
        } else {
          clickObject(16080, "Climb-up");
        }
      } else if (base >= 5192 && base < 5200 && floor2Middle.contains(loc)) {
        clickObject(16081, "Climb-down");
      } else if (base >= 5200 && floor3.contains(loc)) {
        if (!needBank) {
          clickDoor(doors[0], 's');
        } else {
          clickObject(16114, "Climb-up");
        }
      } else if (base >= 5200 && floor3Front.contains(loc)) {
        if (!needBank) {
          clickDoor(doors[0], 's');
        } else {
          clickObject(16114, "Climb-up");
        }
      } else if (base >= 5200 && doors1.contains(loc)) {
        if (!needBank) {
          clickDoor(doors[1], 's');
        } else {
          clickDoor(doors[0], 's');
        }
      } else if (base >= 5200 && loc.getY() >= 5260 && loc.getY() <= 5278) {
        if (!needBank) {
          if (room == 1) {
            if (room1.contains(loc)) {
              atSpiders = true;
            } else {
              walk.to(room1.getRandomTile());
            }
          } else {
            clickDoor(doors[2], 'n');
          }
        } else {
          clickDoor(doors[1], 's');
        }
      } else if (base >= 5200 && doors2.contains(loc)) {
        if (!needBank && room == 2) {
          clickDoor(doors[3], 'n');
        } else {
          clickDoor(doors[2], 'n');
        }
      } else if (base >= 5200 && loc.getY() >= 5282 && loc.getY() <= 5295 && loc.getX() <= 2137) {
        if (!needBank && room == 2) {
          clickDoor(doors[4], 'w');
        } else {
          clickDoor(doors[3], 'n');
        }
      } else if (base >= 5200 && doors3.contains(loc)) {
        if (!needBank && room == 2) {
          clickDoor(doors[5], 'w');
        } else {
          clickDoor(doors[4], 'w');
        }
      } else if (base >= 5200 && loc.getY() >= 5294 && loc.getY() <= 5298 && loc.getX() >= 2141) {
        if (!needBank && room == 2) {
          clickDoor(doors[6], 's');
        } else {
          clickDoor(doors[5], 'w');
        }
      } else if (base >= 5200 && doors4.contains(loc)) {
        if (!needBank && room == 2) {
          clickDoor(doors[7], 's');
        } else {
          clickDoor(doors[6], 's');
        }
      } else if (base >= 5200 && loc.getY() >= 5302) {
        if (!needBank && room == 2) {
          walk.to(room2);
          atSpiders = true;
        } else {
          clickDoor(doors[7], 's');
        }
      }
    }
    return random(100, 250);
  }