Share Pastebin
Guest
Public paste!

Pyratepig

By: a guest | Mar 21st, 2010 | Syntax: JavaScript | Size: 19.09 KB | Hits: 57 | Expires: Never
Copy text to clipboard
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Point;
  4. import java.awt.event.KeyEvent;
  5. import java.util.ArrayList;
  6. import java.util.Map;
  7.  
  8. import org.rsbot.bot.Bot;
  9. import org.rsbot.event.events.ServerMessageEvent;
  10. import org.rsbot.event.listeners.PaintListener;
  11. import org.rsbot.event.listeners.ServerMessageListener;
  12. import org.rsbot.script.Constants;
  13. import org.rsbot.script.Script;
  14. import org.rsbot.script.ScriptManifest;
  15. import org.rsbot.script.Skills;
  16. import org.rsbot.script.wrappers.RSInterface;
  17. import org.rsbot.script.wrappers.RSInterfaceChild;
  18. import org.rsbot.script.wrappers.RSObject;
  19. import org.rsbot.script.wrappers.RSTile;
  20.  
  21. @ScriptManifest(authors = { "Pyratepig" }, category = "Crafting", name = "Pyratepig's Crafter", version = 1.0, description =
  22.  
  23. "<html><head>"
  24.     + "</head><body>"
  25.     + "<center>"
  26.     + "<b><font size=\"5\" color=\"green\">"
  27.     + "Pyratepig's Crafter"
  28.     + "Version 1.0"
  29.     + "</font></b>"
  30.     + "<br></br>"
  31.     + "<i><font size=\"4\" color=\"black\">Makes pots, bowls, pie dishes, or plantpots in Barbarian Village.</font></i>"
  32.     + "<br></br>"
  33.     + "<i><font size=\"4\" color=\"blue\">Please start in the West Varrock bank with soft clay visible in your bank.</font></i>"
  34.     + "<br></br>"
  35.     + "<b><font size=\"4\" color=\"black\">Which type of pottery would you like to make?</font></b>"
  36.     + "<br></br>"
  37.     + "<select name='pottery'>"
  38.     + "<option>Pot"
  39.     + "<option>Pie Dish"
  40.     + "<option>Bowl"
  41.     + "<option>Plantpot"
  42.     + "<br></br>"
  43.     + "</body></html>")
  44. public class PyratepigCrafter extends Script implements PaintListener, ServerMessageListener {
  45.  
  46.     public enum Action {
  47.         BANK, DO_WORK, WALK_TO_FURNACE, WALK_TO_BANK, OPENBANK, WAIT, ANTIBAN, CLICK
  48. }
  49.     public int wheelAnimation = 883;
  50.     public int furnaceAnimation = 899;
  51.     public int furnace = 11601;
  52.     public int wheel = 2642;
  53.     public int clay = 1761;
  54.     public int potsMade = 0;
  55.     public int toChoose;
  56.     PyratepigCrafterAntiBan antiban;
  57.     Thread t;
  58.     Action action;
  59.     public int toMake;
  60.     public boolean neededClay;
  61.     String pottery = "";
  62.     String Pottery = "";
  63.     private String status = "";
  64.     public int thePot;
  65.     public int x2 = getInventoryCount(clay);
  66.     public int x4 = 28 * 3910;
  67.     public int x5 = x4 * 1;
  68.     public int compPot;
  69.     public int levelsGained = 0;
  70.     public int bankID = 11402;
  71.     public int energy = random(11, 70);
  72.     public final int levelUp = 740;
  73.     public final int potInterface = 513;
  74.    
  75.     //Paint Variables
  76.     public static final int CRAFTING_STAT = Skills.getStatIndex("CRAFTING");
  77.     public long startTime = System.currentTimeMillis();
  78.     int startLVL = skills.getCurrentSkillLevel(Constants.STAT_CRAFTING);
  79.     int nextLVL = skills.getXPToNextLevel(Constants.STAT_CRAFTING);
  80.    
  81.     //Paths
  82.     RSTile[] bankToFurnace = { new RSTile(3183, 3436),
  83.             new RSTile(3176, 3429), new RSTile(3165, 3424),
  84.             new RSTile(3153, 3421), //MUSIC
  85.             new RSTile(3146, 3417), new RSTile(3136, 3416),
  86.             new RSTile(3122, 3416), new RSTile(3110, 3421), //Gate
  87.             new RSTile(3097, 3420), new RSTile(3084, 3417),
  88.             new RSTile(3085, 3409) };
  89.     RSTile[] furnaceToBank = reversePath(bankToFurnace);
  90.     RSTile bankTile = new RSTile(3185, 3435);
  91.     RSTile furnaceTile = new RSTile(3085, 3409);
  92.    
  93.     //Other Variables
  94.     final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);      
  95.    
  96.     public boolean shouldRun() {
  97.         return runEnergy() > energy + random(-10, 10);
  98.     }
  99.    
  100.     public boolean clickcontinue() {
  101.         if (getContinueChildInterface() != null) {
  102.             if (getContinueChildInterface().getText().contains("to continue")) {
  103.                 return atInterface(getContinueChildInterface());
  104.             }
  105.         }
  106.         return false;
  107.     }
  108.    
  109.     public boolean openBank() {
  110.         final RSObject bank = getNearestObjectByID(bankID);
  111.         if (bank == null) {
  112.             return false;
  113.         }
  114.         if (!tileOnScreen(bank.getLocation())) {
  115.             turnToTile(bank.getLocation(), 15);
  116.         }
  117.         return atTile(bank.getLocation(), "Use-quickly");
  118.     }
  119.  
  120.     public int runEnergy() {
  121.         int a;
  122.         try {
  123.             a = Integer.parseInt(RSInterface.getChildInterface(750, 5)
  124.                     .getText());
  125.         } catch (final Exception e) {
  126.             a = 0;
  127.         }
  128.         return a;
  129.     }
  130.  
  131.     public boolean atInventoryItem(final int itemID, final String option) {
  132.         if (getCurrentTab() != Constants.TAB_INVENTORY
  133.                 && !RSInterface.getInterface(Constants.INTERFACE_BANK)
  134.                         .isValid()
  135.                 && !RSInterface.getInterface(Constants.INTERFACE_STORE)
  136.                         .isValid()) {
  137.             openTab(Constants.TAB_INVENTORY);
  138.         }
  139.         final int[] items = getInventoryArray();
  140.         final java.util.List<Integer> possible = new ArrayList<Integer>();
  141.         for (int i = 0; i < items.length; i++) {
  142.             if (items[i] == itemID) {
  143.                 possible.add(i);
  144.             }
  145.         }
  146.         if (possible.size() == 0) {
  147.             return false;
  148.         }
  149.         final int idx = possible.get(random(0, possible.size()));
  150.         final Point t = getInventoryItemPoint(idx);
  151.         moveMouse(t, 5, 5);
  152.         getMenuItems();
  153.         final long waitTime = System.currentTimeMillis() + random(50, 250);
  154.         boolean found = false;
  155.         while (!found && System.currentTimeMillis() < waitTime) {
  156.             wait(15);
  157.             if (getMenuItems().get(0).toLowerCase().contains(
  158.                     option.toLowerCase())) {
  159.                 found = true;
  160.             }
  161.         }
  162.         if (found) {
  163.             clickMouse(true);
  164.             wait(random(150, 250));
  165.             return true;
  166.         }
  167.         clickMouse(false);
  168.         wait(random(150, 250));
  169.         return atMenu(option);
  170.     }
  171.    
  172.     public boolean onStart(Map<String, String> args) {
  173.         antiban = new pyratepigCrafterAntiBan();
  174.         t = new Thread(antiban);
  175.         potsMade = 0;
  176.         levelsGained = 0;
  177.         final String FCP = args.get("pottery");
  178.        
  179.         if(FCP.equals("Pot")) {
  180.             Pottery = "Pot";
  181.             toChoose = 3;
  182.             toMake = random(28, 51);
  183.             thePot = 1787;
  184.             compPot = 1931;
  185.        
  186.         } else if(FCP.equals("Bowl")) {
  187.             Pottery = "Bowl";
  188.             toChoose = 5;
  189.             toMake = random(28, 51);
  190.             thePot = 1791;
  191.             compPot = 1923;
  192.            
  193.         } else if(FCP.equals("Pie Dish")) {
  194.             Pottery = "Pie Dish";
  195.             toChoose = 4;
  196.             toMake = random(28, 51);
  197.             thePot = 1789;
  198.             compPot = 2313;
  199.            
  200.         } else if(FCP.equals("Plantpot")) {
  201.             Pottery = "Plantpot";
  202.             toChoose = 6;
  203.             toMake = random(28, 51);
  204.             thePot = 5352;
  205.             compPot = 5350;
  206.         }
  207.        
  208.         if (getCurrentTab() != Constants.TAB_INVENTORY) {
  209.             wait(random(2000, 4000));
  210.             openTab(Constants.TAB_INVENTORY);
  211.             wait(random(200, 400));
  212.         }
  213.         return true;
  214.     }      
  215.    
  216.     public Action getAction() {
  217.         try {
  218.         if (!inventoryContains(clay)) {
  219.                 if (bank.isOpen()) {
  220.                         return Action.BANK;
  221.                 } else if (distanceTo(bankTile) <= 6) {
  222.                         return Action.OPENBANK;
  223.                 } else {
  224.                     if(distanceTo(bankTile) >=12 && getInventoryCount(compPot) >=28)
  225.                         return Action.WALK_TO_BANK;
  226.                 }
  227.         } else {
  228.                 if (getMyPlayer().getAnimation() == wheelAnimation || (getMyPlayer().getAnimation() == furnaceAnimation) || !
  229.  
  230. getInterface(752).isValid()) {
  231.                         return Action.WAIT;
  232.                 } else if (getInterface(levelUp).isValid()) {
  233.                     atInterface(levelUp, 3);
  234.                     return Action.CLICK;
  235.                 } else if (distanceTo(furnaceTile) <= 6) {
  236.                         return Action.DO_WORK;
  237.                 } else {                  
  238.                     if (inventoryContains(clay))
  239.                         return Action.WALK_TO_FURNACE;                      
  240.                     }
  241.     }            
  242.  } catch (final Exception e) {
  243.             e.printStackTrace();
  244.         }
  245.  return Action.ANTIBAN;
  246.     }
  247.  
  248.  
  249.     public int loop() {
  250.         if (!t.isAlive()) {
  251.             t.start();
  252.             status = "Doing AntiBan";
  253.     }
  254.         try {
  255.         switch (getAction()) {  
  256.         case BANK:
  257.             status = "Banking";                
  258.             if (RSInterface.getInterface(Constants.INTERFACE_BANK).isValid()) {
  259.                 bank.depositAllExcept(clay);
  260.             status = "Withdrawing";
  261.              if(!isInventoryFull()){
  262.                  bank.withdraw(clay, 0);
  263.                  wait(random(2000, 2130));
  264.                  if(bank.getItemByID(clay) == null){
  265.                      log("Not enough clay left! Stopping Script.");
  266.                      stopScript();
  267.                  }            
  268.              }
  269.              if(inventoryContains(clay)){
  270.                  status = "Closing Bank";
  271.              bank.close();        
  272.             }
  273.             }
  274.             action = Action.WALK_TO_FURNACE;
  275.                 break;              
  276.         case OPENBANK:
  277.                 status = "Opening Bank";
  278.                 openBank();
  279.                 break;
  280.         case WALK_TO_BANK:
  281.             status = "Walking to Bank";
  282.             walkPath(furnaceToBank);
  283.             break;
  284.         case WAIT:
  285.             status = "Waiting";
  286.             break;
  287.         case CLICK:
  288.             status = "Clicking Continue";
  289.             atInterface(levelUp, 3);
  290.             break;
  291.         case WALK_TO_FURNACE:                    
  292.                 status = "Walking to Furnace";          
  293.                 walkPath(bankToFurnace);
  294.                 break;
  295.         case DO_WORK:          
  296.             status = "Forming Pots";
  297.                 final RSInterfaceChild potMaker = getInterface(513, toChoose);
  298.                 final RSObject whl = getNearestObjectByID(wheel);
  299.                 final RSObject frn = getNearestObjectByID(furnace);
  300.                 if (frn == null) {
  301.                     log("Furnace not found. Please contact Pyratepig.");
  302.                     wait(random(1200, 2000));
  303.                 }
  304.                 if (whl == null) {
  305.                     log("Pottery wheel not found. Please contact Pyratepig.");
  306.                     wait(random(1200, 2000));
  307.                 }                
  308.                 if(canContinue()){
  309.                     log("Attempting to click Continue.");
  310.                     clickcontinue();
  311.                 }
  312.                 if (RSInterface.getInterface(740).isValid()) {
  313.             atInterface(RSInterface.getInterface(740).getChild(3));            
  314.                 }
  315.                 if (!getInterface(potInterface).isValid()) {
  316.                     atInventoryItem(clay, "Use");
  317.                     wait(random(1800, 2000));
  318.                     atObject(whl, "Use");
  319.                     wait(random(2000, 2500));                                              
  320.                     atInterface(potMaker, "Make X");
  321.                         wait(random(800, 2000));
  322.                     sendText("28", true);
  323.                     wait(random(36000, 40000));
  324.                 if (getInventoryCount(thePot) == 28) {
  325.                     status = "Firing Pots";                                                                  
  326.                         atObject(frn, "Fire");
  327.                         wait(random(2000, 2500));                        
  328.                         atInterface(potMaker, "Make X");
  329.                             wait(random(1700, 2200));                    
  330.                             sendText("28", true);
  331.                         wait(random(x4, x5));                
  332.                         }
  333.                 }
  334.                 break;              
  335.         }
  336.  } catch (final Exception e) {
  337.             e.printStackTrace();
  338.  }
  339. return random(300, 400);
  340.     }
  341.    
  342.     public void serverMessageRecieved(final ServerMessageEvent arg0) {
  343.         final String serverString = arg0.getMessage();
  344.         if (serverString.contains("You've just advanced")) {
  345.             levelsGained++;            
  346.             log("Level Up! Attempting to click Continue");
  347.             clickcontinue();            
  348.         }
  349.         if (serverString.contains("You remove the")) {
  350.             potsMade++;
  351.         }    
  352.         if (serverString.contains("You need to play on a members world")) {
  353.             log("You need to be a member to make a plantpot. Stopping Script.");
  354.             stopScript();
  355.         }
  356.         if (serverString.contains("wishes to trade with you")) {
  357.             sendText("No thanks", true);
  358.         }        
  359.     }
  360.        
  361.     public void onRepaint(Graphics g) {
  362.         if(!isLoggedIn() ||  isLoginScreen()) {
  363.             return;
  364.         }    
  365.         long millis = System.currentTimeMillis() - startTime;
  366.         final long hours = millis / (1000 * 60 * 60);
  367.         millis -= hours * 1000 * 60 * 60;
  368.         final long minutes = millis / (1000 * 60);
  369.         millis -= minutes * 1000 * 60;
  370.         final long seconds = millis / 1000;
  371.         final int x = 561;
  372.         final int y = 225;
  373.         g.setColor(new Color(0, 0, 0, 175));
  374.         g.fillRoundRect(555, 210, 175, 250, 10, 10);
  375.         g.setColor(Color.black);
  376.         g.drawString("Pyratepig's Crafter", x + 1, y + 1);
  377.         g.setColor(Color.white);
  378.         g.drawString("Pyratepig's Crafter", x, y);
  379.         g.setColor(Color.white);
  380.         g.drawString("Crafting Level: "+ skills.getCurrentSkillLevel(Constants.STAT_CRAFTING) + "", 561,255);
  381.         g.drawString("Pottery Made: " + Integer.toString(potsMade) + "", 561,275);
  382.         g.drawString("Levels Gained: " + Integer.toString(levelsGained) + "",561, 295);
  383.         g.drawString("EXP Till Next Level: "+ skills.getXPToNextLevel(Constants.STAT_CRAFTING) + "",561, 315);
  384.         g.drawString("Percent Till Next Level: "+ skills.getPercentToNextLevel(Constants.STAT_CRAFTING) + "%",561, 365);
  385.         g.drawString("Time Running:", 561, 335);
  386.         g.drawString("" + hours + ":" + minutes + ":" + seconds + "", 561, 345);    
  387.         g.drawString("Status: " + status, 561, 395);
  388.     }
  389.    
  390.     public void onFinish() {
  391.         Bot.getEventManager().removeListener(PaintListener.class, this);
  392.         Bot.getEventManager().removeListener(ServerMessageListener.class, this);
  393.         antiban.stopThread = true;
  394.         log("Thank You for using Pyratepig's Crafter!");
  395.         log("Pottery Made: " + potsMade);
  396.         log("Levels Gained: " + levelsGained);
  397.     }    
  398.  
  399.     private int start(final RSTile[] path) {
  400.         int start = 0;
  401.         for (int a = path.length - 1; a > 0; a--) {
  402.             if (tileOnMinimap(path[a])) {
  403.                 start = a;
  404.                 break;
  405.             }
  406.         }
  407.         return start;
  408.     }
  409.  
  410.     private boolean tileOnMinimap(final RSTile tile) {
  411.         final Point p = tileToMinimap(tile);
  412.         return Math.sqrt(Math.pow(627 - p.x, 2) + Math.pow(85 - p.y, 2)) < random(
  413.                 60, 74);
  414.     }
  415.    
  416.     private RSTile checkTile(final RSTile tile) {
  417.         if (tileOnMap(tile)) {
  418.             return tile;
  419.         }
  420.         final RSTile loc = getMyPlayer().getLocation();
  421.         final RSTile walk = new RSTile((loc.getX() + tile.getX()) / 2, (loc
  422.                 .getY() + tile.getY()) / 2);
  423.         return tileOnMap(walk) ? walk : checkTile(walk);
  424.     }
  425.  
  426.     private boolean walkPath(final RSTile[] path) {
  427.         for (int i = start(path); i < path.length; i++) {
  428.             if (!isRunning() && getEnergy() > random(40, 60)) {
  429.                 clickMouse(random(707, 762), random(90, 121), true);
  430.             }
  431.             walkTo(randomizeTile(path[i], 1, 1));
  432.             waitToMove(2000);
  433.             if (path[i] == path[path.length - 1]) {
  434.                 break;
  435.             }
  436.             while (!tileOnMinimap(path[i + 1])) {
  437.                 if (!getMyPlayer().isMoving()) {
  438.                     walkTo(checkTile(randomizeTile(path[i + 1], 1, 1)));
  439.                 }                
  440.             }
  441.         }        
  442.         return distanceTo(path[path.length - 1]) <= 4;
  443.     }
  444.     private class PyratepigCrafterAntiBan implements Runnable {
  445.         public boolean stopThread;
  446.  
  447.         public void run() {
  448.                 while (!stopThread) {
  449.                         try {
  450.                                 if (random(0, 15) == 0) {
  451.                                         final char[] LR = new char[] { KeyEvent.VK_LEFT,
  452.                                                         KeyEvent.VK_RIGHT };
  453.                                         final char[] UD = new char[] { KeyEvent.VK_DOWN,
  454.                                                         KeyEvent.VK_UP };
  455.                                         final char[] LRUD = new char[] { KeyEvent.VK_LEFT,
  456.                                                         KeyEvent.VK_RIGHT, KeyEvent.VK_UP,
  457.                                                         KeyEvent.VK_UP };
  458.                                         final int random2 = random(0, 2);
  459.                                         final int random1 = random(0, 2);
  460.                                         final int random4 = random(0, 4);
  461.  
  462.                                         if (random(0, 3) == 0) {
  463.                                                 Bot.getInputManager().pressKey(LR[random1]);
  464.                                                 Thread.sleep(random(100, 400));
  465.                                                 Bot.getInputManager().pressKey(UD[random2]);
  466.                                                 Thread.sleep(random(300, 600));
  467.                                                 Bot.getInputManager().releaseKey(UD[random2]);
  468.                                                 Thread.sleep(random(100, 400));
  469.                                                 Bot.getInputManager().releaseKey(LR[random1]);
  470.                                         } else {
  471.                                                 Bot.getInputManager().pressKey(LRUD[random4]);
  472.                                                 if (random4 > 1) {
  473.                                                         Thread.sleep(random(300, 600));
  474.                                                 } else {
  475.                                                         Thread.sleep(random(500, 900));
  476.                                                 }
  477.                                                 Bot.getInputManager().releaseKey(LRUD[random4]);
  478.                                         }
  479.                                 } else {
  480.                                         Thread.sleep(random(200, 2000));
  481.                                 }
  482.                         } catch (final Exception e) {
  483.                                 e.printStackTrace();
  484.                         }
  485.                 }
  486.         }
  487. }
  488. }