megaalgos

MegaFiller 2.4

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