Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Author lolbus of Roach Killer
- * lols
- * Report bug at powerbot or bear with it.
- *
- * Finished in less than 4hours.
- *
- *
- */
- import org.powerbot.game.api.methods.Tabs;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Mouse;
- import org.powerbot.game.api.methods.node.GroundItems;
- import org.powerbot.game.api.methods.node.Locations;
- import org.powerbot.game.api.methods.node.Menu;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.concurrent.Task;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.interactive.Npcs;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.widget.Camera;
- import org.powerbot.game.api.methods.*;
- import org.powerbot.game.api.util.Filter;
- import org.powerbot.game.api.util.Random;
- import org.powerbot.game.api.wrappers.*;
- import org.powerbot.game.api.wrappers.interactive.Npc;
- import org.powerbot.game.api.wrappers.node.GroundItem;
- import org.powerbot.game.api.wrappers.node.Item;
- import org.powerbot.game.api.wrappers.node.Location;
- @Manifest(name = "RoachKillers", description = "kill roach till your sick of roach", version = 2.0, authors = {"lolbus"})
- public class RoachKiller extends ActiveScript {
- public final int foodID = 333;
- public final int quantity = 5;
- public final int eatWhenHp = 600;
- private final Tile[] roachPath = {
- new Tile(3088,3488,0), new Tile(3084, 3485, 0), new Tile(3081, 3477,0),
- new Tile(3084,3465,0), new Tile(3079,3464,0)
- };
- private final Tile[] homePath = {
- new Tile(3082,3466,0), new Tile(3082, 3475, 0), new Tile(3084, 3484,0),
- new Tile(3088,3491,0), new Tile(3093,3493,0)
- };
- public boolean outOfRoach(){
- if(isInArea(3137,3170,4269,4273)){
- return true;
- } else
- return false;
- }
- public boolean haveItem(int itemID){
- for(Item i : Inventory.getItems()){
- if (i.getId()==itemID)
- return true;
- }
- return false;
- }
- final public int drops[] = {448,450,563,447,565,1619,1617,1631,5304,5300,1185,1249,1247,12160,1333,995,12158,12163,12159,18778,560};
- public void log (String s){
- if(!s.isEmpty()){
- Time.sleep(80);
- log.info(s);
- }
- }
- public float distanceTo(Tile tile){
- return (float) Calculations.distance(Players.getLocal().getPosition(), tile);
- }
- public void turnCameraRandomly(){
- Camera.setAngle(Random.nextInt(0, 360));
- Time.sleep(500);
- }
- public void sleep(int min, int max){
- Time.sleep(Random.nextInt(min, max));
- }
- public int random(int min, int max){
- return Random.nextInt(min, max);
- }
- public boolean isInArea(int minX, int maxX, int minY, int maxY){
- int myX = Players.getLocal().getPosition().getX();
- int myY = Players.getLocal().getPosition().getY();
- if(myX >= minX && myX <= maxX && myY >= minY && myY <= maxY){
- return true;
- }
- else
- return false;
- }
- public boolean nearCervice(){
- return isInArea(3072, 3082, 3461, 3469);
- }
- public boolean atBank(){
- return isInArea(3091, 3098, 3487, 3498);
- }
- public boolean atTown(){
- return isInArea(3070, 3101, 3459, 3503);
- }
- public boolean atRoach(){
- return isInArea(3146, 3160, 4274, 4281);
- }
- public void handleCervice(){
- Location hole = Locations.getNearest(29728);
- if(hole!=null){
- if(!hole.isOnScreen()){
- Camera.turnTo(hole);
- }
- Mouse.click((int)hole.getCentralPoint().getX(), (int)hole.getCentralPoint().getY(), false);
- sleep(500,600);
- if(Menu.isOpen()){
- Menu.select("Enter");
- sleep(1000,1500);
- }
- }
- }
- public int angleTo(Tile tile) {
- double ydif = tile.getY() - Players.getLocal().getPosition().getY();
- double xdif = tile.getX() - Players.getLocal().getPosition().getX();
- return (int) (Math.atan2(ydif, xdif) * 180 / Math.PI);
- }
- public boolean walkTileMM(Tile tile, int rnd) {
- double angle = angleTo(tile) - Camera.getAngleTo(0);
- double distance = distanceTo(tile);
- angle = angle * Math.PI / 180;
- int x = 627, y = 85;
- int dx = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
- .cos(angle));
- int dy = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
- .sin(angle));
- return Mouse.click(x + dx, y - dy, true);
- }
- public void handleRope(){
- Location rope = Locations.getNearest(29729);
- if(rope!=null){
- if(distanceTo(rope.getPosition()) > 3){
- log.info("too far going nearer");
- walkTileMM(rope.getPosition(),0);
- sleep(900,1400);
- }
- if(!rope.isOnScreen()){
- Camera.turnTo(rope);
- log.info("tan cam");
- sleep(900,1400);
- }
- Mouse.click((int)rope.getCentralPoint().getX(), (int)rope.getCentralPoint().getY(), false);
- sleep(500,550);
- if(Menu.isOpen()){
- if(Menu.contains("Climb")){
- Menu.select("Climb");
- sleep(1900,2700);
- }
- }
- } else if (rope ==null){
- log("ops rope is null");
- }
- }
- private void walk(Tile[] fullTile) {
- if (Walking.getEnergy() > random(30, 50)) {
- Walking.setRun(true);
- }
- for (int i = fullTile.length - 1; i >= 0; i--) {
- if (Walking.walk(fullTile[i])) {
- break;
- }
- }
- }
- public class toRoachs extends Strategy implements Task{
- @Override
- public void run() {
- sleep(80,150);
- // TODO Auto-generated method stub
- if(!nearCervice() && atTown() && haveItem(foodID)){
- walk(roachPath);
- } else if (nearCervice() && atTown() && haveItem(foodID)){
- handleCervice();
- }
- }
- @Override
- public boolean validate(){
- //log.info(""+(atTown()&&haveItem(foodID)));
- return (atTown()&&haveItem(foodID));
- }
- }
- public class returnToBank extends Strategy implements Task{
- @Override
- public void run() {
- sleep(100,200);
- // TODO Auto-generated method stub
- if(atRoach()){
- handleRope();
- } else if (atTown() &&!atBank()){
- walk(homePath);
- }
- }
- @Override
- public boolean validate(){
- //log.info(" returns to bank!"+!haveItem(foodID));
- return ((!haveItem(foodID) && !atRoach()) ||
- (atRoach() && !haveItem(foodID) && (Integer.parseInt(Widgets.get(748, 8).getText()) <= 120 + (Random.nextInt(-3, 3))))
- );
- }
- }
- public boolean clickRandomRoach(){
- Npc target = Npcs.getNearest(new Filter<Npc>(){
- public boolean accept(Npc i){
- if(i.getId()== 7160 && i.getPosition().getY() >= 4274){
- return true;
- } else return false;
- }
- });
- if(target!=null){
- if(distanceTo(target.getPosition())> 3){
- walkTileMM(target.getPosition(), 0);
- sleep(600,800);
- }
- else if(!target.isOnScreen()){
- Camera.turnTo(target);
- } else {
- Mouse.click((int)target.getCentralPoint().getX(),(int)target.getCentralPoint().getY(), false);
- sleep(500,600);
- if(Menu.isOpen() && Menu.contains("Attack")){
- Menu.select("Attack");
- sleep(1500,2200);
- }
- }
- }
- return false;
- }
- public class fightRoach extends Strategy implements Task{
- @Override
- public void run() {
- sleep(100,200);
- // TODO Auto-generated method stub
- GroundItem loot = GroundItems.getNearest(new Filter <GroundItem>(){
- public boolean accept(GroundItem i){
- for(GroundItem a : GroundItems.getLoaded()){
- for(int z = 0; z < drops.length; z++){
- if(a.getGroundItem().getId()==drops[z]){
- return true;
- }
- }
- }
- return false;
- }
- });
- if(loot!=null){
- if(distanceTo(loot.getPosition())>3){
- walkTileMM(loot.getPosition(),0);
- sleep(300,500);
- }
- if(!loot.isOnScreen()){
- Camera.turnTo(loot);
- sleep(300,500);
- }
- Mouse.click((int)loot.getCentralPoint().getX(), (int)loot.getCentralPoint().getY(), false);
- sleep(500,600);
- if(Menu.isOpen() && Menu.contains("Take")){
- Menu.select("Take");
- sleep(400,600);
- }
- } else {
- if(!Players.getLocal().isInCombat()){
- clickRandomRoach();
- sleep(400,600);
- } else {
- sleep(2000,3000);
- }
- }
- }
- @Override
- public boolean validate(){
- //log.info(" returns to bank!"+!haveItem(foodID));
- return ((Integer.parseInt(Widgets.get(748, 8).getText()) > 120 + (Random.nextInt(-3, 3))) && atRoach());
- }
- }
- public class basicNeeds extends Strategy implements Task{
- @Override
- public void run() {
- if(outOfRoach()){
- walkTileMM(new Tile(3157,4277,0),0);
- sleep(1000,1500);
- }
- sleep(80,150);
- if(Random.nextInt(1, 110)>95){
- // log.info("Antiban activated");
- wiggle();
- turnCameraRandomly();
- }
- if(Camera.getPitch()>0){
- Camera.setPitch(true);
- }
- // TODO Auto-generated method stub
- }
- public void wiggle() {
- int x, y;
- x = Random.nextInt(500, 650);
- y = Random.nextInt(300, 420);
- Mouse.move(x, y);
- Time.sleep(Random.nextInt(25, 674));
- x = Random.nextInt(500, 650);
- y = Random.nextInt(300, 420);
- Mouse.move(x, y);
- Time.sleep(Random.nextInt(1, 240));
- }
- @Override
- public boolean validate(){
- return true;
- }
- }
- public class eating extends Strategy implements Task {
- @Override
- public void run() {
- sleep(100,150);
- // TODO Auto-generated method stub
- if(Tabs.getCurrent() != Tabs.INVENTORY)
- Tabs.INVENTORY.open();
- for (Item i : Inventory.getItems()){
- if(i.getId() == foodID){
- i.getWidgetChild().click(true);
- sleep(800,1200);
- break;
- }
- }
- }
- @Override
- public boolean validate(){
- return (haveItem(foodID) && Integer.parseInt(Widgets.get(748, 8).getText()) <= eatWhenHp);
- }
- }
- public class banking extends Strategy implements Task{
- @Override
- public void run() {
- sleep(80,150);
- // TODO Auto-generated method stub
- if(!bank.isOpen()){
- bank.openBank();
- sleep(1000,1200);
- } else if (Inventory.getCount()>0){
- bank.depositAll();
- sleep(500,600);
- } else {
- bank.withdraw(foodID, quantity);
- sleep(500,600);
- }
- }
- @Override
- public boolean validate(){
- return (!haveItem(foodID) && atBank());
- }
- }
- @Override
- protected void setup() {
- basicNeeds z = new basicNeeds();
- Strategy DOES_BASIC = new Strategy(z, z);
- provide(DOES_BASIC);
- banking b = new banking();
- Strategy BANKING = new Strategy(b, b);
- provide(BANKING);
- toRoachs c = new toRoachs();
- Strategy TOWARDS_ROACH = new Strategy(c, c);
- provide(TOWARDS_ROACH);
- fightRoach e = new fightRoach();
- Strategy FIGHT_ROACH = new Strategy(e, e);
- provide(FIGHT_ROACH);
- eating x = new eating();
- Strategy EAT_FOOD = new Strategy(x, x);
- provide(EAT_FOOD);
- returnToBank d = new returnToBank();
- Strategy BANK_RETURN = new Strategy(d, d);
- provide(BANK_RETURN);
- }
- }
Add Comment
Please, Sign In to add comment