megaalgos

MegaPlanker 1.4

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