megaalgos

MegaPlanker 1.2

Apr 9th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.14 KB | None | 0 0
  1. //Version 1.2
  2. /**
  3.  * Fixed paint, I must have been sleeping when I did the math...
  4.  * Made even more failsafes, script should run "more" efficient
  5.  */
  6.  
  7. //Version 1.1
  8. /**
  9.  * Made failsafes for my methods so the script doesnt just sit there.
  10.  * Made the running method as efficient as I could think it.
  11.  */
  12. import java.awt.*;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.KeyEvent;
  16. import java.awt.image.BufferedImage;
  17. import java.io.BufferedInputStream;
  18. import java.io.BufferedOutputStream;
  19. import java.io.BufferedReader;
  20. import java.io.File;
  21. import java.io.FileOutputStream;
  22. import java.io.IOException;
  23. import java.io.InputStreamReader;
  24. import java.net.MalformedURLException;
  25. import java.net.URL;
  26. import java.text.DecimalFormat;
  27.  
  28. import javax.imageio.ImageIO;
  29. import javax.swing.*;
  30.  
  31. import com.rarebot.script.Script;
  32. import com.rarebot.client.m;
  33. import com.rarebot.event.events.MessageEvent;
  34. import com.rarebot.event.listeners.*;
  35. import com.rarebot.script.ScriptManifest;
  36. import com.rarebot.script.methods.Game.Tab;
  37. import com.rarebot.script.wrappers.*;
  38.  
  39. // Script Info
  40. @ScriptManifest(authors = { "MegaAlgos" }, version = 1.1, keywords = ("Money Making"), description = "Makes planks at Varrock East", name = "MegaPlanker")
  41. public class MegaPlanker extends Script implements PaintListener,
  42. MessageListener {
  43.  
  44.     // Script Info for paint and proggies...
  45.     public double getVersion() {
  46.         return (1.1);
  47.     }
  48.  
  49.     public String getName() {
  50.         return ("MegaPlanker");
  51.     }
  52.  
  53.     public String getAuthor() {
  54.         return ("MegaAlgos");
  55.     }
  56.  
  57.     // Script Variables
  58.     RSNPC banker, operator;
  59.     int gePrice = 0, moneyMade, profitHour, planks, counter, fullPrice,
  60.             emptyPrice;
  61.     int pID, lID, iComponent;
  62.     String status, pName, fName;
  63.     String[] list = { "Wood plank", "Oak plank", "Teak plank", "Mahogany Plank" };
  64.     private static final String GE_URL = "http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj=";
  65.     long startTime, checkForFilling;
  66.     double work = 0;
  67.     boolean start = false, fOnScreen = false,
  68.             startUP = false;
  69.     int vP;
  70.     int jP;
  71.     int buP;
  72.     int boP;
  73.     Image arrow = null;
  74.     RSTile[] tO = { new RSTile(3267, 3428), new RSTile(3278, 3436),
  75.             new RSTile(3285, 3449), new RSTile(3290, 3463),
  76.             new RSTile(3299, 3476), new RSTile(3302, 3490) },
  77.             tB = { new RSTile(3293, 3478), new RSTile(3286, 3460),
  78.             new RSTile(3282, 3444), new RSTile(3276, 3429),
  79.             new RSTile(3263, 3429), new RSTile(3253, 3420) };
  80.  
  81.     // What it does on the start of the script
  82.     public boolean onStart() {
  83.         mouse.setSpeed(7);
  84.         startTime = System.currentTimeMillis();
  85.         log("MegaPlanker! Aimed to make you planks... hours on end");
  86.         java.awt.EventQueue.invokeLater(new Runnable() {
  87.             @Override
  88.             public void run() {
  89.                 new MegaGUI().setVisible(true);
  90.             }
  91.         });
  92.  
  93.         if (getOVersion() != getVersion()) {
  94.             java.awt.EventQueue.invokeLater(new Runnable() {
  95.                 @Override
  96.                 public void run() {
  97.                     new VersionGUI().setVisible(true);
  98.                 }
  99.             });
  100.         }
  101.  
  102.         while (!start) {
  103.             sleep(1000);
  104.         }
  105.        
  106.         try {
  107.             arrow = ImageIO.read(new URL("http://megascripts.comyr.com/Arrow.png").openStream());
  108.         } catch (IOException e) {
  109.             // TODO Auto-generated catch block
  110.             e.printStackTrace();
  111.         }
  112.  
  113.         fullPrice = getPrice(pID);
  114.         emptyPrice = getPrice(lID);
  115.         log("" + whereandwhat.getSelectedItem().toString() + " price: "
  116.                 + fullPrice);
  117.         return true;
  118.     }
  119.  
  120.     // Sees the messages in game
  121.     @Override
  122.     public void messageReceived(MessageEvent arg0) {
  123.         if (arg0.getMessage().contains("You fill")) {
  124.         }
  125.  
  126.     }
  127.  
  128.     // Script's graphics
  129.     public void onRepaint(Graphics g) {
  130.         long runTime = System.currentTimeMillis() - startTime;
  131.         long TotalSecs = runTime / 1000;
  132.         long TotalMins = TotalSecs / 60;
  133.         long TotalHours = TotalMins / 60;
  134.         int seconds = (int) TotalSecs % 60;
  135.         int minutes = (int) TotalMins % 60;
  136.         int hours = (int) TotalHours % 60;
  137.  
  138.         StringBuilder b = new StringBuilder();
  139.  
  140.         if (hours < 10)
  141.             b.append('0');
  142.         b.append(hours);
  143.         b.append(':');
  144.         if (minutes < 10)
  145.             b.append('0');
  146.         b.append(minutes);
  147.         b.append(':');
  148.         if (seconds < 10)
  149.             b.append('0');
  150.         b.append(seconds);
  151.  
  152.         if (start) {
  153.             work = planks / (minutes + hours * 60 + seconds / 60f) * 60f;
  154.  
  155.             moneyMade = (planks * fullPrice) - (planks * emptyPrice);
  156.  
  157.             profitHour = (int) (moneyMade
  158.                     / (minutes + hours * 60 + seconds / 60f) * 60f);
  159.  
  160.             if (minutes == 30 && seconds == 1 || minutes == 0 && seconds == 30
  161.                     && game.isLoggedIn()) {
  162.                 String fS = File.separator;
  163.                 String path = null;
  164.                 File directory;
  165.                 try {
  166.                     path = new File(".").getCanonicalPath();
  167.                 } catch (IOException e) {
  168.                     // TODO Auto-generated catch block
  169.                     e.printStackTrace();
  170.                 }
  171.                 directory = new File(path + fS + getName() + " " + getVersion());
  172.                 if (!directory.exists()) {
  173.                     directory.mkdirs();
  174.                     log("Made the directory for proggies");
  175.                 }
  176.                 BufferedImage img = new BufferedImage(155, 140,
  177.                         BufferedImage.TYPE_INT_RGB);
  178.                 File file = new File(directory + fS + "MegaPlanker " + counter
  179.                         + ".gif");
  180.                 g = img.getGraphics();
  181.                 g.setColor(new Color(76, 67, 69));
  182.                 g.fill3DRect(0, 0, 155, 140, true);
  183.  
  184.                 int w = 0;
  185.                 int z = 0;
  186.                 g.setColor(new Color(80, 207, 58));
  187.                 g.drawString(getName() + " " + getVersion(), w, z += 20);
  188.                 g.drawString("Ran for: " + b.toString(), w, z += 25);
  189.                 g.drawString("Made " + planks + " " + pName + "s", w, z += 20);
  190.                 g.drawString("Making: " + roundToTenth(work) + pName +" per hour.",
  191.                         w, z += 20);
  192.                 g.drawString("Made: " + addCommas(moneyMade, true) + " profit", w, z += 20);
  193.                 g.drawString("Making: " + addCommas(profitHour, true) + " an hour", w, z += 20);
  194.                 try {
  195.                     ImageIO.write(img, "gif", file);
  196.                 } catch (IOException e) {
  197.                     // TODO Auto-generated catch block
  198.                     e.printStackTrace();
  199.                 }
  200.                 log("Sent a proggy image to the MegaPlanker folder in program files folder...");
  201.                 counter++;
  202.                 sleep(2000);
  203.             }
  204.         }
  205.  
  206.         if (game.isLoggedIn()) {
  207.             if (arrow != null) {
  208.                 g.drawImage(arrow, mouse.getLocation().x - 9, mouse.getLocation().y - 2, null);
  209.             }
  210.            
  211.             g.setColor(new Color(76, 67, 69, 185));
  212.             g.fill3DRect(360, 180, 158, 165, true);
  213.             int x = 365;
  214.             int y = 185;
  215.             g.setColor(new Color(80, 207, 58));
  216.             g.drawString(getName() + " " + getVersion(), x, y += 20);
  217.             g.drawString("Ran for: " + b.toString(), x, y += 25);
  218.             g.drawString("Made: " + planks + " planks", x, y += 20);
  219.             g.drawString("Making: " + roundToTenth(work) + " " + pName +"/hour.", x,
  220.                     y += 20);
  221.             g.drawString("Made: " + addCommas(moneyMade, true) + " proffit", x, y += 20);
  222.             g.drawString("Making: " + addCommas(profitHour, true) + " an hour", x, y += 20);
  223.             g.drawString("Status: " + status, x, y += 20);
  224.         }
  225.     }
  226.  
  227.     // Main method to run.. the methods.
  228.     @Override
  229.     public int loop() {
  230.         // Checks if we are logged in!
  231.         if (!game.isLoggedIn()) {
  232.             return 1000;
  233.         }
  234.         // Moves camera up if down
  235.         if (camera.getPitch() < 50) {
  236.             camera.setPitch(true);
  237.         }
  238.         if (getMyPlayer().getAnimation() == 5713
  239.                 || getMyPlayer().getAnimation() == 11786
  240.                 && walking.getEnergy() > 80) {
  241.             mouse.move(calc.tileToScreen(getMyPlayer().getLocation()));
  242.             mouse.click(true);
  243.         }
  244.         // Checks if energy is low
  245.         if (walking.getEnergy() < 10 && getMyPlayer().isIdle()) {
  246.             walking.rest();
  247.         }
  248.         // Checks if the run is off and the energy is above 75
  249.         if (!walking.isRunEnabled() && walking.getEnergy() > 75) {
  250.             // If run is off we should turn it on
  251.             walking.setRun(true);
  252.         }
  253.  
  254.         // Checks if inventory is full
  255.         if (inventory.isFull()) {
  256.             switch (stateFull()) {
  257.             case 1:
  258.                 walkToOperator();
  259.                 return 223;
  260.             case 2:
  261.                 makePlanks();
  262.                 return 243;
  263.             case 3:
  264.                 walkToBank();
  265.                 return 233;
  266.             case 4:
  267.                 depositPlanks();
  268.                 return 253;
  269.             case 0:
  270.                 return 1;
  271.             }
  272.         } else { // IF NOT FULL
  273.             RSTile bankerTile = new RSTile(3253, 3418);
  274.             // banker = npcs.getNearest("Banker"); // bank
  275.             if (calc.distanceTo(bankerTile) < 5) { // If close to bank
  276.                 if (bank.open()) {
  277.                     if (bank.withdraw(lID, 0)) {
  278.                         while (!inventory.isFull()) {
  279.                             sleep(100);
  280.                         }
  281.                         return random(33, 100);
  282.                     }
  283.                 } else {
  284.                     if (tiles.interact(bankerTile, "Bank Banker")) {
  285.                         sleep(random(33, 210));
  286.                     }
  287.                 }
  288.                 // if (banker.interact("Bank Banker")) {
  289.                 // return random(33, 210);
  290.                 // }
  291.                 return 50;
  292.             }
  293.             if (getMyPlayer().isMoving()) {
  294.                 return 50;
  295.             } else {
  296.                 if (walkToBank()) {
  297.                     // Walking back to bank!
  298.                     return 500;
  299.                 } else {
  300.                     // Something is wrong.
  301.                     return 100;
  302.                 }
  303.             }
  304.         }
  305.         return random(300, 500);
  306.     }
  307.  
  308.     // Other Methods!
  309.  
  310.     // The state we are in when inventory is full.
  311.     public int stateFull() {
  312.         RSTile f = new RSTile(3302, 3491);
  313.         if (calc.tileOnScreen(f)) {
  314.             fOnScreen = true;
  315.         } else {
  316.             fOnScreen = false;
  317.         }
  318.  
  319.         if (inventory.containsAll(lID) && !fOnScreen) {
  320.             status = "Walking to operator";
  321.             return 1;
  322.         }
  323.         if (inventory.containsAll(lID) && fOnScreen) {
  324.             status = "Making " + pName;
  325.             return 2;
  326.         }
  327.         // banker = npcs.getNearest(2718);
  328.         // if(banker == null) {
  329.         // walkToBank();
  330.         // return 0;
  331.         // }
  332.         RSTile bankerTile = new RSTile(3253, 3421);
  333.         if (inventory.containsAll(pID)
  334.                 && !calc.tileOnScreen(bankerTile)) {
  335.             status = "Walking to bank";
  336.             return 3;
  337.         }
  338.         if (inventory.containsAll(pID)
  339.                 && calc.tileOnScreen(bankerTile)) {
  340.             status = "Depositing";
  341.             return 4;
  342.         }
  343.  
  344.         return 0;
  345.     }
  346.  
  347.     // Walks to bank
  348.     public boolean walkToBank() {
  349.         RSTile bankTile = new RSTile(3253, 3421);
  350.         RSWeb walkWeb = web.getWeb(bankTile);
  351.         int counter = 0;
  352.         if (walkWeb.step()) {
  353.             while (!calc.tileOnScreen(bankTile)) {
  354.                 while (getMyPlayer().isMoving()) {
  355.                     while(calc.distanceTo(walking.getDestination()) > 5) {
  356.                         checkRest();
  357.                         sleep(500);
  358.                     }
  359.                     if(calc.distanceTo(walking.getDestination()) < 5) {
  360.                         walkWeb.update();
  361.                         walkWeb.step();
  362.                     }
  363.                 }
  364.                 if (!getMyPlayer().isMoving()) {
  365.                     counter++;
  366.                     if(counter > 3) {
  367.                         walkWeb.step();
  368.                         break;
  369.                     }
  370.                     checkRest();
  371.                 }
  372.             }
  373.         }
  374.         sleep(500);
  375.         return true;
  376.     }
  377.  
  378.     // Walks to operator
  379.     public boolean walkToOperator() {
  380.         RSTile fTile = new RSTile(3302, 3491);
  381.         RSWeb walkWeb = web.getWeb(fTile);
  382.         if (walkWeb.step()) {
  383.             while (calc.distanceTo(fTile) > 7) {
  384.                 while (getMyPlayer().isMoving()) {
  385.                     while(calc.distanceTo(walking.getDestination()) > 5) {
  386.                         checkRest();
  387.                         sleep(500);
  388.                     }
  389.                     if(calc.distanceTo(walking.getDestination()) < 5) {
  390.                         walkWeb.update();
  391.                         walkWeb.step();
  392.                     }
  393.                 }
  394.                 if (!getMyPlayer().isMoving()) {
  395.                     counter++;
  396.                     if(counter > 3) {
  397.                         walkWeb.step();
  398.                         break;
  399.                     }
  400.                     checkRest();
  401.                 }
  402.             }
  403.         }
  404.         sleep(500);
  405.         return true;
  406.     }
  407.    
  408.     public void checkRest() {
  409.         // Checks if energy is low
  410.         if (walking.getEnergy() < 10) {
  411.             walking.rest();
  412.             sleep(500);
  413.         }
  414.         if (getMyPlayer().getAnimation() == 5713
  415.                 || getMyPlayer().getAnimation() == 11786
  416.                 && walking.getEnergy() > 85) {
  417.         mouse.move(calc.tileToScreen(getMyPlayer().getLocation()));
  418.         mouse.click(true);
  419.         }
  420.         if (getMyPlayer().getAnimation() == 5713
  421.                 || getMyPlayer().getAnimation() == 11786) {
  422.             sleep(500);
  423.             while (walking.getEnergy() < 85) {
  424.                 sleep(500);
  425.             }
  426.            
  427.         }
  428.         // Checks if the run is off and the energy is above 55
  429.         if (!walking.isRunEnabled() && walking.getEnergy() > 85) {
  430.             // If run is off we should turn it on
  431.             walking.setRun(true);
  432.             return;
  433.         }
  434.     }
  435.  
  436.     // Fills planks
  437.     public boolean makePlanks() {
  438.         if (interfaces.get(403).isValid()) {
  439.             if (interfaces.get(403).getComponent(iComponent).interact("Buy all " + pName)) {
  440.                 planks = planks + 28;
  441.                 sleep(500);
  442.                 while(inventory.containsAll(lID)) {
  443.                     sleep(500);
  444.                     counter++;
  445.                     if(counter > 3) {
  446.                         counter = 0;
  447.                         break;
  448.                     }
  449.                 }
  450.             }
  451.         }
  452.         operator = npcs.getNearest("Sawmill operator");
  453.         int counter = 0;
  454.         if (operator.interact("Buy-plank Sawmill operator")) {
  455.             sleep(350);
  456.             while (!interfaces.get(403).isValid()) {
  457.                 sleep(500);
  458.                 counter++;
  459.                 if (counter > 3) {
  460.                     operator.interact("Buy-plank Sawmill operator");
  461.                     counter = 0;
  462.                 }
  463.             }
  464.             if (interfaces.get(403).isValid()) {
  465.                 if (interfaces.get(403).getComponent(iComponent).interact("Buy all " + pName)) {
  466.                     planks = planks + 28;
  467.                     sleep(500);
  468.                     while(inventory.containsAll(lID)) {
  469.                         sleep(500);
  470.                         counter++;
  471.                         if(counter > 5) {
  472.                             counter = 0;
  473.                             break;
  474.                         }
  475.                     }
  476.                 }
  477.             }
  478.             return true;
  479.         }
  480.         return false;
  481.     }
  482.  
  483.     // Deposits planks
  484.     public boolean depositPlanks() {
  485.         // banker = npcs.getNearest("Banker"); // bank
  486.         // if (banker.interact("Bank Banker")) {
  487.         // sleep(random(350, 500));
  488.         // }
  489.         int counter = 0;
  490.         RSTile bankerTile = new RSTile(3253, 3419);
  491.         if (tiles.interact(bankerTile, "Bank Bank Booth")) {
  492.             while (!bank.isOpen()) {
  493.                 sleep(500);
  494.                 counter++;
  495.                 if(counter > 5) {
  496.                     tiles.interact(bankerTile, "Bank Bank Booth");
  497.                     counter = 0;
  498.                 }
  499.             }
  500.         }
  501.         if (bank.isOpen()) {
  502.             if (bank.depositAllExcept(995)) {
  503.                 while (inventory.isFull()) {
  504.                     sleep(500);
  505.                 }
  506.             }
  507.         } else {
  508.             return false;
  509.         }
  510.         return true;
  511.     }
  512.  
  513.     public boolean clickTile(RSTile c, String action) {
  514.         try {
  515.             while (getMyPlayer().isMoving()) {
  516.                 sleep(750);
  517.             }
  518.             Point screenLoc = calc.tileToScreen(c);
  519.             mouse.move(screenLoc);
  520.             if (!mouse.getLocation().equals(screenLoc))
  521.                 return false;
  522.  
  523.             mouse.click(screenLoc, false);
  524.             return menu.doAction(action);
  525.  
  526.         } catch (NullPointerException e) {
  527.         }
  528.         return true;
  529.     }
  530.  
  531.     // Clicks tile accurately
  532.     public boolean clickTile2(RSTile c, String action) {
  533.         try {
  534.             Point screenLoc = null;
  535.             screenLoc = calc.tileToScreen(c);
  536.             if (c == null || !calc.pointOnScreen(screenLoc)) {
  537.                 System.out.println("Not on screen " + action);
  538.                 return false;
  539.             }
  540.  
  541.             mouse.move(screenLoc);
  542.             screenLoc = calc.tileToScreen(c);
  543.  
  544.             String[] items = menu.getItems();
  545.             if (items.length <= 1)
  546.                 return false;
  547.             if (items[0].toLowerCase().contains(action.toLowerCase())) {
  548.                 mouse.click(screenLoc, true);
  549.                 return true;
  550.             } else {
  551.                 mouse.click(screenLoc, false);
  552.                 return menu.doAction(action);
  553.             }
  554.  
  555.         } catch (NullPointerException e) {
  556.         }
  557.         return true;
  558.     }
  559.  
  560.     // Rounds a double to the nearest tenth
  561.     public double roundToTenth(double d) {
  562.         DecimalFormat twoDForm = new DecimalFormat("#.#");
  563.         twoDForm = new DecimalFormat("#.#");
  564.         return Double.valueOf(twoDForm.format(d));
  565.     }
  566.    
  567.     public String addCommas(int d, boolean money) {
  568.         DecimalFormat twoDForm = new DecimalFormat("###,###");
  569.         if(money) {
  570.             twoDForm = new DecimalFormat("$###,###");
  571.         return twoDForm.format(d);
  572.         }
  573.         return twoDForm.format(d);
  574.     }
  575.  
  576.     // Checks for the recent version
  577.     public double getOVersion() {
  578.         try {
  579.             URL url = new URL("http://megascripts.comyr.com/MegaPlanker/Version");
  580.             BufferedReader br = new BufferedReader(new InputStreamReader(
  581.                     new BufferedInputStream(url.openConnection()
  582.                             .getInputStream())));
  583.             double ver = Double.parseDouble(br.readLine().trim());
  584.             br.close();
  585.             return ver;
  586.         } catch (IOException e) {
  587.             throw new RuntimeException(e);
  588.         }
  589.     }
  590.  
  591.     // ANTI-BAN STUFF
  592.     public int antiBan() {
  593.         Point m;
  594.         int x = random(0, 750);
  595.         int y = random(0, 500);
  596.         int xx = random(710, 554);
  597.         int yy = random(444, 230);
  598.         int screenx = random(1, 510);
  599.         int screeny = random(1, 450);
  600.  
  601.         int gamble = random(0, 22);
  602.  
  603.         final long start = System.currentTimeMillis();
  604.         final RSPlayer myPlayer = getMyPlayer();
  605.  
  606.         int anim = -1;
  607.         while (System.currentTimeMillis() - start > 2000) {
  608.             if ((anim = myPlayer.getAnimation()) != -1) {
  609.                 break;
  610.             }
  611.             sleep(15);
  612.         }
  613.  
  614.         switch (gamble) {
  615.         case 1:
  616.  
  617.             sleep(random(1000, 2500));
  618.  
  619.             break;
  620.         case 2:
  621.             mouse.move(x, y);
  622.  
  623.             while (System.currentTimeMillis() - start > 2000) {
  624.  
  625.                 if ((anim = myPlayer.getAnimation()) != -1) {
  626.                     break;
  627.                 }
  628.                 sleep(random(15, 55));
  629.             }
  630.  
  631.             sleep(random(1000, 2500));
  632.             break;
  633.         case 3:
  634.             game.openTab(Tab.INVENTORY);
  635.             sleep(random(1000, 2500));
  636.             break;
  637.         case 4:
  638.             if (getMyPlayer().isMoving()) {
  639.                 sleep(random(1000, 2500));
  640.                 break;
  641.             }
  642.         case 5:
  643.             mouse.move(x, y);
  644.             int checkTime = 0;
  645.             long lastCheck = 0;
  646.             sleep(random(1000, 2500));
  647.             if (System.currentTimeMillis() - lastCheck >= checkTime) {
  648.                 lastCheck = System.currentTimeMillis();
  649.                 checkTime = random(60000, 180000);
  650.                 break;
  651.             }
  652.         case 6:
  653.             if (game.getTab() != Tab.STATS) {
  654.                 game.openTab(Tab.STATS);
  655.                 mouse.move(xx, yy);
  656.                 sleep(random(2000, 3500));
  657.                 game.openTab(Tab.INVENTORY);
  658.                 break;
  659.             }
  660.         case 7:
  661.             sleep(random(750, 1500));
  662.             break;
  663.         case 8:
  664.             mouse.move(screenx, screeny);
  665.             sleep(random(750, 1500));
  666.             break;
  667.         case 9:
  668.             mouse.move(screenx, screeny);
  669.             sleep(random(750, 1500));
  670.             break;
  671.         case 10:
  672.             game.openTab(game.getRandomTab());
  673.             sleep(random(750, 1500));
  674.             break;
  675.  
  676.         case 11:
  677.             mouse.move(x, y);
  678.             sleep(random(750, 1500));
  679.             break;
  680.         case 13:
  681.             mouse.move(x, y);
  682.             sleep(random(750, 1500));
  683.             break;
  684.         case 12:
  685.             mouse.move(x, y);
  686.             sleep(random(750, 1500));
  687.             break;
  688.         case 14:
  689.             m = mouse.getLocation();
  690.             sleep(random(300, 500));
  691.             mouse.move(m, 20, 20);
  692.             sleep(random(100, 200));
  693.             break;
  694.         case 15:
  695.             m = mouse.getLocation();
  696.             sleep(random(300, 500));
  697.             mouse.move(m, 20, 20);
  698.             sleep(random(100, 200));
  699.             break;
  700.         case 16:
  701.             m = mouse.getLocation();
  702.             sleep(random(300, 500));
  703.             mouse.move(m, 20, 20);
  704.             sleep(random(100, 200));
  705.             break;
  706.         case 17:
  707.             m = mouse.getLocation();
  708.             sleep(random(300, 500));
  709.             mouse.move(m, 20, 20);
  710.             sleep(random(100, 200));
  711.             break;
  712.         case 19:
  713.             mouse.move(x, y);
  714.             sleep(random(750, 1500));
  715.             break;
  716.         case 20:
  717.             mouse.move(x, y);
  718.             sleep(random(750, 1500));
  719.             break;
  720.         case 21:
  721.             mouse.move(x, y);
  722.             sleep(random(750, 1500));
  723.             break;
  724.  
  725.         }
  726.  
  727.         return 100;
  728.     }
  729.  
  730.     // Grand exchange price lookup
  731.     private int getPrice(int itemID) {
  732.         try {
  733.             URL url = new URL(GE_URL + String.valueOf(itemID));
  734.             BufferedReader x = new BufferedReader(new InputStreamReader(
  735.                     url.openStream()));
  736.             String inputLine;
  737.             while ((inputLine = x.readLine()) != null) {
  738.                 if (inputLine
  739.                         .contains("<th scope=\"row\">Current guide price:</th>")) {
  740.                     return (int) parsePrice(x.readLine());
  741.                 }
  742.             }
  743.             x.close();
  744.         } catch (MalformedURLException e) {
  745.             e.printStackTrace();
  746.         } catch (IOException e) {
  747.             e.printStackTrace();
  748.         }
  749.         return -1;
  750.     }
  751.  
  752.     private double parsePrice(String str) {
  753.         if (str != null && !str.isEmpty()) {
  754.             str = stripFormatting(str);
  755.             str = str.substring(str.indexOf(58) + 1, str.length());
  756.             str = str.replace(",", "");
  757.             str = str.trim();
  758.             if (!str.endsWith("%")) {
  759.                 if (!str.endsWith("k") && !str.endsWith("m")
  760.                         && !str.endsWith("b")) {
  761.                     return Double.parseDouble(str);
  762.                 }
  763.                 return Double.parseDouble(str.substring(0, str.length() - 1))
  764.                         * (str.endsWith("b") ? 1000000000
  765.                                 : str.endsWith("m") ? 1000000 : 1000);
  766.             }
  767.             final int k = str.startsWith("+") ? 1 : -1;
  768.             str = str.substring(0);
  769.             return Double.parseDouble(str.substring(0, str.length() - 1)) * k;
  770.         }
  771.         return -1D;
  772.     }
  773.  
  774.     private String stripFormatting(final String str) {
  775.         if (str != null && !str.isEmpty()) {
  776.             return str.replaceAll("(^[^<]+>|<[^>]+>|<[^>]+$)", "");
  777.         }
  778.         return "";
  779.     }
  780.  
  781.     // End Grand exchange price lookup
  782.  
  783.     JButton startButton;
  784.     JComboBox whereandwhat;
  785.     JLabel text;
  786.  
  787.     public class MegaGUI extends JFrame implements ActionListener {
  788.  
  789.         public MegaGUI() {
  790.             setTitle("MegaPlanker");
  791.  
  792.             startButton = new JButton("Start");
  793.             text = new JLabel("What plank to make?");
  794.             whereandwhat = new JComboBox(list);
  795.  
  796.             setLayout(null);
  797.             setResizable(false);
  798.             setSize(390, 255);
  799.             setLocationRelativeTo(null);
  800.  
  801.             text.setBounds(20, 20, 182, 21);
  802.             startButton.setBounds(135, 148, 83, 28);
  803.             startButton.addActionListener(this);
  804.             whereandwhat.setBounds(65, 71, 200, 22);
  805.  
  806.             add(text);
  807.             add(whereandwhat);
  808.             add(startButton);
  809.  
  810.             setVisible(true);
  811.         }
  812.  
  813.         @Override
  814.         public void actionPerformed(ActionEvent e) {
  815.             if (e.getActionCommand().contains("Start")) {
  816.                 if (whereandwhat.getSelectedItem().toString().equals("Wood plank")) {
  817.                     lID = 1511;
  818.                     pID = 960;
  819.                     iComponent = 12;
  820.                     pName = "Wood plank";
  821.                     log("Making wood planks");
  822.                 } else if (whereandwhat.getSelectedItem().toString()
  823.                         .equals("Oak plank")) {
  824.                     lID = 1521;
  825.                     pID = 8778;
  826.                     iComponent = 13;
  827.                     pName = "Oak plank";
  828.                     log("Making oak planks");
  829.                 } else if (whereandwhat.getSelectedItem().toString()
  830.                         .equals("Teak plank")) {
  831.                     lID = 6333;
  832.                     pID = 8780;
  833.                     iComponent = 14;
  834.                     pName = "Teak plank";
  835.                     log("Making teak planks");
  836.                 } else if (whereandwhat.getSelectedItem().toString()
  837.                         .equals("Mohagany plank")) {
  838.                     lID = 6332;
  839.                     pID = 8782;
  840.                     iComponent = 15;
  841.                     pName = "Mohagany Plank";
  842.                     log("Making mohagany planks");
  843.                 }
  844.                 dispose();
  845.                 setVisible(false);
  846.                 start = true;
  847.             }
  848.         }
  849.  
  850.     }
  851.  
  852.     JButton oB;
  853.     JButton gN;
  854.     JLabel oL;
  855.  
  856.     public class VersionGUI extends JFrame implements ActionListener {
  857.  
  858.         public VersionGUI() {
  859.             setTitle("OUTDATED");
  860.  
  861.             oB = new JButton("Okay");
  862.             oL = new JLabel("OUTDATED");
  863.             gN = new JButton("Get new version");
  864.  
  865.             setLayout(null);
  866.             setResizable(false);
  867.             setSize(150, 185);
  868.             setLocationRelativeTo(null);
  869.  
  870.             oB.setBounds(20, 35, 65, 25);
  871.             gN.setBounds(20, 85, 115, 25);
  872.             oB.addActionListener(this);
  873.             gN.addActionListener(this);
  874.             oL.setBounds(20, 5, 182, 21);
  875.  
  876.             add(oL);
  877.             add(gN);
  878.             add(oB);
  879.  
  880.             setVisible(true);
  881.         }
  882.  
  883.         public void getNewVersion() {
  884.             File directory = getCacheDirectory();
  885.              File newDirectory =
  886.                      new File(new File(new File(directory.getParent()).getParent()).getParent()
  887.                              + File.separator + "Scripts" + File.separator +
  888.                              "Sources" + File.separator + "MegaPlanker.java");
  889.              
  890.             BufferedInputStream in;
  891.             try {
  892.                 in = new BufferedInputStream(
  893.                         new URL("http://megascripts.comyr.com/MegaPlanker/MegaPlanker.java").openStream());
  894.             FileOutputStream fos = new FileOutputStream(newDirectory);
  895.             BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
  896.             byte[] data = new byte[1024];
  897.             int x=0;
  898.             while((x=in.read(data,0,1024))>=0) {
  899.                 bout.write(data,0,x);
  900.             }
  901.             bout.close();
  902.             in.close();
  903.             } catch (MalformedURLException e) {
  904.                 // TODO Auto-generated catch block
  905.                 e.printStackTrace();
  906.             } catch (IOException e) {
  907.                 // TODO Auto-generated catch block
  908.                 e.printStackTrace();
  909.             }
  910.         }
  911.  
  912.         @Override
  913.         public void actionPerformed(ActionEvent e) {
  914.             if (e.getActionCommand().contains("Okay")) {
  915.                 dispose();
  916.                 setVisible(false);
  917.             }
  918.             if (e.getActionCommand().contains("Get new version")) {
  919.                 getNewVersion();
  920.                 sleep(1000);
  921.                 oL.setText("Recompile the script");
  922.                 repaint();
  923.                 stopScript();
  924.             }
  925.         }
  926.     }
  927. }
Advertisement
Add Comment
Please, Sign In to add comment