megaalgos

MegaBlacksmith 1.3

Apr 27th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.15 KB | None | 0 0
  1. // Version 1.3
  2. /**
  3.  * Fixed counting error and a few other bugs
  4.  */
  5. // Version 1.2
  6. /**
  7.  * Fixed depositing error
  8.  */
  9. // Version 1.1
  10. /**
  11.  * Fixed the messed up ids
  12.  * Fixed some banking errors and waiting methods
  13.  */
  14. import java.awt.*;
  15. import java.awt.event.*;
  16. import java.awt.image.BufferedImage;
  17. import java.io.*;
  18. import java.net.*;
  19. import java.text.DecimalFormat;
  20.  
  21. import javax.imageio.ImageIO;
  22. import javax.swing.*;
  23.  
  24. import com.rarebot.event.events.MessageEvent;
  25. import com.rarebot.event.listeners.MessageListener;
  26. import com.rarebot.event.listeners.PaintListener;
  27. import com.rarebot.script.Script;
  28. import com.rarebot.script.ScriptManifest;
  29. import com.rarebot.script.methods.Game.Tab;
  30. import com.rarebot.script.methods.Skills;
  31. import com.rarebot.script.wrappers.RSObject;
  32. import com.rarebot.script.wrappers.RSPlayer;
  33. import com.rarebot.script.wrappers.RSTile;
  34. import com.rarebot.script.wrappers.RSWeb;
  35.  
  36. @ScriptManifest(authors = { "MegaAlgos" }, version = 1.3, keywords = ("Smithing"), description = "Smithing and smelting needs", name = "MegaBlacksmith")
  37. public class MegaBlacksmith extends Script implements PaintListener, MessageListener,MouseListener {
  38.  
  39.     // Script Info for paint and proggies...
  40.     public double getVersion() {
  41.         return (1.3);
  42.     }
  43.  
  44.     public String getName() {
  45.         return ("MegaBlacksmith");
  46.     }
  47.  
  48.     public String getAuthor() {
  49.         return ("MegaAlgos");
  50.     }
  51.  
  52.     RSTile b, m, anvilTile;
  53.     int o, o2, oCount, o2Count, bar, cI, barLeft, counter, iCount,
  54.     sXP, cXP, sLVL, cLVL;
  55.     double work = 0, hXP, TTNL;
  56.     boolean smelt = false, start = false, scroll = false, safe = false,
  57.             hidePaint = false, timedOut, misClick = false;
  58.     Point mP;
  59.     String pName, whatToDo, status, location;
  60.     long startTime;
  61.     Image arrow = null;
  62.     Rectangle r;
  63.  
  64.  
  65.     public boolean onStart() {
  66.         log("MegaBlacksmith, for all your smelting and smithing needs");
  67.  
  68.         java.awt.EventQueue.invokeLater(new Runnable() {
  69.             @Override
  70.             public void run() {
  71.                 new MegaGUI().setVisible(true);
  72.             }
  73.         });
  74.  
  75.         if (getOVersion() != getVersion()) {
  76.             java.awt.EventQueue.invokeLater(new Runnable() {
  77.                 @Override
  78.                 public void run() {
  79.                     new VersionGUI().setVisible(true);
  80.                 }
  81.             });
  82.         }
  83.  
  84.  
  85.         try {
  86.             arrow = ImageIO.read(new URL("http://megascripts.comyr.com/Arrow.png").openStream());
  87.         } catch (IOException e) {
  88.             // TODO Auto-generated catch block
  89.             e.printStackTrace();
  90.         }
  91.  
  92.         while (!start) {
  93.             sleep(1000);
  94.         }
  95.         mouse.setSpeed(6);
  96.         startTime = System.currentTimeMillis();
  97.         return true;
  98.     }
  99.  
  100.     // Script's graphics
  101.     public void onRepaint(Graphics g) {
  102.         long runTime = System.currentTimeMillis() - startTime;
  103.         long TotalSecs = runTime / 1000;
  104.         long TotalMins = TotalSecs / 60;
  105.         long TotalHours = TotalMins / 60;
  106.         int seconds = (int) TotalSecs % 60;
  107.         int minutes = (int) TotalMins % 60;
  108.         int hours = (int) TotalHours % 60;
  109.  
  110.         StringBuilder b = new StringBuilder();
  111.  
  112.         if (hours < 10)
  113.             b.append('0');
  114.         b.append(hours);
  115.         b.append(':');
  116.         if (minutes < 10)
  117.             b.append('0');
  118.         b.append(minutes);
  119.         b.append(':');
  120.         if (seconds < 10)
  121.             b.append('0');
  122.         b.append(seconds);
  123.  
  124.         if (start) {
  125.             work = iCount / (minutes + hours * 60 + seconds / 60f) * 60f;
  126.             if (minutes == 30 && seconds == 1 || minutes == 0 && seconds == 30
  127.                     && game.isLoggedIn()) {
  128.                 String fS = File.separator;
  129.                 String path = null;
  130.                 File directory;
  131.                 try {
  132.                     path = new File(".").getCanonicalPath();
  133.                 } catch (IOException e) {
  134.                     // TODO Auto-generated catch block
  135.                     e.printStackTrace();
  136.                 }
  137.                 directory = new File(path + fS + getName() + " " + getVersion());
  138.                 if (!directory.exists()) {
  139.                     directory.mkdirs();
  140.                     log("Made the directory for proggies");
  141.                 }
  142.                 BufferedImage img = new BufferedImage(184, 242,
  143.                         BufferedImage.TYPE_INT_RGB);
  144.                 File file = new File(directory + fS + "MegaBlacksmith " + counter
  145.                         + ".gif");
  146.                 g = img.getGraphics();
  147.                 g.setColor(new Color(153, 0, 0));
  148.                 g.fill3DRect(0, 0, 184, 242, true);
  149.  
  150.                 int w = 0;
  151.                 int z = 0;
  152.                 g.setColor(Color.black);
  153.                 g.drawString(getName() + " " + getVersion(), w, z += 20);
  154.                 g.setFont(new Font("Verdana", 0, 12));
  155.                 g.drawString("Ran for: " + b.toString(), w += 20, z += 27);
  156.                 g.drawString("Made: " + iCount + " " + pName, w, z += 19);
  157.                 g.drawString("Making: " + roundToTenth(work) + " " + pName +"/hour.", w,
  158.                         z += 19);
  159.                 g.drawString("Gained: " + (cXP - sXP) + " xp", w, z += 19);
  160.                 g.drawString("Gaining: " + hXP + " an hour", w, z += 19);
  161.                 g.drawString("LVLs gained: " + (cLVL - sLVL), w, z += 19);
  162.                 g.drawString("Current LVL: " + cLVL , w, z += 19);
  163.                 try {
  164.                     ImageIO.write(img, "gif", file);
  165.                 } catch (IOException e) {
  166.                     // TODO Auto-generated catch block
  167.                     e.printStackTrace();
  168.                 }
  169.                 log("Sent a proggy image to the MegaBlacksmith folder in program files folder...");
  170.                 counter++;
  171.                 sleep(2000);
  172.             }
  173.         }
  174.  
  175.         if (game.isLoggedIn()) {
  176.             if (sXP == 0 && sLVL == 0) {
  177.                 sXP = skills.getCurrentExp(Skills.SMITHING);
  178.                 sLVL = skills.getCurrentLevel(Skills.SMITHING);
  179.             }
  180.             cXP = skills.getCurrentExp(Skills.SMITHING);;
  181.             cLVL = skills.getCurrentLevel(Skills.SMITHING);
  182.  
  183.             hXP = (cXP - sXP) /  (minutes + hours * 60 + seconds / 60f) * 60f;
  184.  
  185.             if ((cXP - sXP) != 0) {
  186.                 TTNL = skills.getExpToNextLevel(Skills.SMITHING) / ((cXP - sXP) / (minutes + hours * 60 + seconds / 60f));
  187.             }
  188.             if (arrow != null) {
  189.                 g.drawImage(arrow, mouse.getLocation().x - 9, mouse.getLocation().y - 2, null);
  190.             }
  191.             if (!hidePaint) {
  192.                 g.setColor(new Color(153, 0, 0, 225));
  193.                 g.fillRoundRect(551, 217, 184, 242, 16, 16);
  194.  
  195.                 g.setColor(new Color(102, 102, 102));
  196.                 r = new Rectangle(596, 415, 88, 36);
  197.                 g.fillRect(596, 415, 88, 36);
  198.  
  199.                 g.setFont(new Font("Verdana", 1, 16));
  200.                 g.setColor(new Color(167, 91, 3));
  201.                 g.drawString(getName() + " " + getVersion(), 555, 251);
  202.  
  203.                 g.setColor(Color.black);
  204.                 g.setFont(new Font("Verdana", 1, 18));
  205.                 g.drawString("Hide", 611, 443);
  206.  
  207.                 int x = 550;
  208.                 int y = 254;
  209.                 g.setFont(new Font("Verdana", 0, 12));
  210.                 g.drawString("Ran for: " + b.toString(), x, y += 23);
  211.                 g.drawString("Made: " + iCount + " " + pName, x, y += 15);
  212.                 g.drawString("Making: " + addCommas((int)roundToTenth(work), false) + " " + pName +"/hour.", x,
  213.                         y += 15);
  214.                 g.drawString("Gained: " + addCommas((cXP - sXP), false) + " xp", x, y += 15);
  215.                 g.drawString("Gaining: " + addCommas((int)roundToTenth(hXP), false) + " an hour", x, y += 15);
  216.                 g.drawString("LVLs gained: " + (cLVL - sLVL), x, y += 15);
  217.                 g.drawString("Current LVL: " + cLVL , x, y += 15);
  218.                 g.drawString("Time till n/lvl: " + roundToTenth(TTNL) + " min(s)", x, y += 15);
  219.                 g.setFont(new Font("Verdana", 0, 10));
  220.                 g.drawString("Status: " + status, x, y += 15);
  221.             } else {
  222.                 g.setColor(new Color(102, 102, 102, 175));
  223.                 r = new Rectangle(596, 415, 88, 36);
  224.                 g.fillRect(596, 415, 88, 36);
  225.  
  226.                 g.setColor(Color.white);
  227.                 g.setFont(new Font("Verdana", 1, 18));
  228.                 g.drawString("Show", 611, 443);
  229.             }
  230.         }
  231.     }
  232.  
  233.  
  234.     @Override
  235.     public int loop() {
  236.         int c = 0;
  237.         if (whatToDo == "Smelt") {
  238.             if (smelt) {
  239.                 if (inventory.getCount(o) == 0) {
  240.                     smelt = false;
  241.                     return 50;
  242.                 }
  243.                 return 1;
  244.             }
  245.            
  246.             if (o2 > 0) {
  247.                 sleep(500);
  248.                 if (inventory.getCount(o) == oCount
  249.                         && inventory.getCount(o2) == o2Count) {
  250.                     if (atSmith()) {
  251.                         smith();
  252.                     } else {
  253.                         walkToSmith();
  254.                     }
  255.  
  256.                 } else {
  257.                     if (atBank()) {
  258.                         depositAndGetItems();
  259.                     } else {
  260.                         walkToBank();
  261.                     }
  262.                 }
  263.             } else {
  264.                 sleep(500);
  265.                 if (inventory.getCount(o) == oCount) {
  266.                     if (atSmith()) {
  267.                         smith();
  268.                     } else {
  269.                         walkToSmith();
  270.                     }
  271.  
  272.                 } else {
  273.                     if (atBank()) {
  274.                         depositAndGetItems();
  275.                     } else {
  276.                         walkToBank();
  277.                     }
  278.                 }
  279.             }
  280.  
  281.         } else if (whatToDo == "Smith") {
  282.             if (smelt) {
  283.                 timedOut = !waitForInvChange(bar, 3500);
  284.                 if (inventory.getCount(bar) == barLeft || timedOut) {
  285.                     smelt = false;
  286.                     return 50;
  287.                 }
  288.             }
  289.  
  290.             if (inventory.getCount(bar) > barLeft) {
  291.                 if (atSmith()) {
  292.                     smith();
  293.                 } else {
  294.                     walkToSmith();
  295.                 }
  296.             } else {
  297.                 if (atBank()) {
  298.                     depositAndGetItems();
  299.                 } else {
  300.                     walkToBank();
  301.                 }
  302.             }
  303.         }
  304.         return random(300, 500);
  305.     }
  306.  
  307.     public boolean smithing() {
  308.         status = "Smithing";
  309.         int iCount = inventory.getCount(bar);
  310.         sleep(3000);
  311.         if (inventory.getCount(bar) == iCount) {
  312.             safe = true;
  313.             return true;
  314.         }
  315.         return false;
  316.     }
  317.  
  318.  
  319.     public void smith() {
  320.         status = "Smithing";
  321.         int counter = 0;
  322.         if (whatToDo == "Smelt") {
  323.             RSObject furnace = objects.getNearest(11666);
  324.             if (furnace != null && getMyPlayer().getAnimation() == -1
  325.                     && getMyPlayer().isIdle()) {
  326.                 if (clickObject(furnace, "Smelt")) {
  327.                     sleep(1500);
  328.                     if (interfaces.get(916).isValid()) {
  329.                         mouse.click(mP, 10, 10, true);
  330.                         smelt = true;
  331.                         sleep(100);
  332.                         antiBan();
  333.                     }
  334.                     return;
  335.                 }
  336.             }
  337.  
  338.         } else {
  339.             RSObject anvil = objects.getNearest(2783);
  340.             if (anvil != null && getMyPlayer().getAnimation() == -1
  341.                     && getMyPlayer().isIdle()) {
  342.                 if (interfaces.get(300).isValid()) {
  343.                     if (interfaces.clickComponent(interfaces.getComponent(300, cI), "Make all")) {
  344.                         smelt = true;
  345.                         sleep(100);
  346.                     }
  347.                     return;
  348.                 }
  349.                 if (tiles.interact(anvilTile, "Smith")) {
  350.                     if (!interfaces.waitFor(interfaces.get(300), true, 4000)) {
  351.                         tiles.interact(anvilTile, "Smith");
  352.                         sleep(2000);
  353.                     }
  354.                     if (interfaces.get(300).isValid()) {
  355.                         if (cI > 185 && interfaces.getComponent(300, 16).getComponents()[1].getAbsoluteY() < 140) {
  356.  
  357.                             mouse.move(interfaces.getComponent(300, 16).getComponents()[1].getPoint());
  358.                             mouse.drag(interfaces.getComponent(300, 16).getComponents()[1].getPoint().x,
  359.                                     interfaces.getComponent(300, 16).getComponents()[1].getPoint().y + 69);
  360.                         }
  361.                         if (interfaces.clickComponent(interfaces.getComponent(300, cI), "Make all")) {
  362.                             smelt = true;
  363.                             sleep(100);
  364.                         }
  365.                     }
  366.                 }
  367.  
  368.             }
  369.         }
  370.     }
  371.  
  372.     public boolean atSmith() {
  373.         if (calc.tileOnScreen(m)) {
  374.             return true;
  375.         }
  376.         return false;
  377.     }
  378.  
  379.     public boolean atBank() {
  380.         if (calc.tileOnScreen(b)) {
  381.             return true;
  382.         }
  383.         return false;
  384.     }
  385.  
  386.     // Walks to bank
  387.     public boolean walkToBank() {
  388.         status = "Walking to bank";
  389.         RSWeb walkWeb = web.getWeb(b);
  390.  
  391.         if (walkWeb != null) {
  392.             if (getMyPlayer().isMoving() && !walkWeb.finished()) {
  393.                 if (calc.distanceTo(walking.getDestination()) < 10) {
  394.                     walkWeb.step();
  395.                     return true;
  396.                 } else {
  397.                     sleep(250);
  398.                     return true;
  399.                 }
  400.             }
  401.             walkWeb.step();
  402.         }
  403.         return true;
  404.     }
  405.  
  406.     // Walks to operator
  407.     public boolean walkToSmith() {
  408.         status = "Walking to smithing area";
  409.         if (whatToDo.contains("Smelt")) {
  410.             RSWeb walkWeb = web.getWeb(m);
  411.             if (walkWeb != null) {
  412.                 if (getMyPlayer().isMoving() && !walkWeb.finished()) {
  413.                     if (calc.distanceTo(walking.getDestination()) < 10) {
  414.                         walkWeb.step();
  415.                         return true;
  416.                     } else {
  417.                         sleep(250);
  418.                         return true;
  419.                     }
  420.                 }
  421.                 walkWeb.step();
  422.             }
  423.         } else {
  424.             if (getMyPlayer().isMoving()) {
  425.                 return true;
  426.             }
  427.             mouse.click(calc.tileToMinimap(m).x + 5, calc.tileToMinimap(m).y, 0, 0, true);
  428.         }
  429.         return true;
  430.     }
  431.  
  432.     public boolean depositAndGetItems() {
  433.         status = "Depositing and getting items";
  434.         if (bank.open()) {
  435.             if (!interfaces.waitFor(bank.getInterface(), true, 1500)) {
  436.                 bank.open();
  437.             }
  438.         }
  439.         if (bank.isOpen()) {
  440.             if (inventory.getCount() > 0) {
  441.                 bank.depositAll();
  442.                 waitForInvChange(0, 1000);
  443.             }
  444.             if (whatToDo == "Smelt") {
  445.                 if (o2 > 0) {
  446.                     if (bank.getCount(o) < 27 || bank.getCount(o2) < 27) {
  447.                         log("Out of bars stopping script");
  448.                         stopScript();
  449.                     }
  450.                 } else {
  451.                     if (bank.getCount(o) < 27) {
  452.                         log("Out of bars stopping script");
  453.                         stopScript();
  454.                     }
  455.                 }
  456.                 if (bank.withdraw(o, oCount)) {
  457.                     waitForInvChange(0, 1000);
  458.                 }
  459.                 if (o2 > 0) {
  460.                     if (bank.withdraw(o2, 0)) {
  461.                         waitForInvChange(0, 1000);
  462.                     }
  463.                 }
  464.             } else {
  465.                 if (bank.getCount(bar) < 27) {
  466.                     log("Out of bars stopping script");
  467.                     stopScript();
  468.                 }
  469.                 if (bank.withdraw(bar, 28)) {
  470.                     waitForInvChange(0, 1000);
  471.                 }
  472.             }
  473.         } else {
  474.             return false;
  475.         }
  476.         return true;
  477.     }
  478.  
  479.     // Waits for the item to show up in inventory
  480.  
  481.     public boolean waitFor(int item, int item2, int itemC, int itemC2, int timer) {
  482.         for (int w = 0; w < timer; w++) {
  483.             if (item2 != 0) {
  484.                 if(inventory.getCount(item) == itemC &&
  485.                         inventory.getCount(item2) == itemC2) {
  486.                     return true;
  487.                 }
  488.             } else {
  489.                 if (inventory.getCount(item) == itemC) {
  490.                     return true;
  491.                 }
  492.             }
  493.             sleep(1);
  494.         }
  495.         return false;
  496.     }
  497.  
  498.  
  499.     public boolean waitForInvChange(int item, int timer) {
  500.         int count;
  501.         if (item == 0) {
  502.             count = inventory.getCount();
  503.         } else {
  504.             count = inventory.getCount(item);
  505.         }
  506.         for (int w = 0; w < timer; w++) {
  507.             if (item == 0) {
  508.                 if (inventory.getCount() != count) {
  509.                     return true;
  510.                 }
  511.             } else {
  512.                 if (inventory.getCount(item) != count) {
  513.                     return true;
  514.                 }
  515.             }
  516.             if(random(0,100000) == 500) {
  517.                 antiBan();
  518.             }
  519.             sleep(1);
  520.         }
  521.         return false;
  522.     }
  523.  
  524.     public boolean clickObject(RSObject c, String action) {
  525.         try {
  526.             while (getMyPlayer().isMoving()) {
  527.                 sleep(50);
  528.             }
  529.             Point screenLoc = calc.tileToScreen(c.getLocation());
  530.             mouse.move(screenLoc, 5, 5);
  531.  
  532.             String[] items = menu.getActions();
  533.             if (items.length <= 1) {
  534.                 return false;
  535.             }
  536.  
  537.             if (items[0].toLowerCase().contains(action.toLowerCase())) {
  538.                 mouse.click(true);
  539.                 return true;
  540.             } else {
  541.                 mouse.click(false);
  542.                 return menu.doAction(action);
  543.             }
  544.         } catch (NullPointerException e) {
  545.         }
  546.         return true;
  547.     }
  548.  
  549.     // Rounds a double to the nearest tenth
  550.     public double roundToTenth(double d) {
  551.         DecimalFormat twoDForm = new DecimalFormat("#.#");
  552.         twoDForm = new DecimalFormat("#.#");
  553.         return Double.valueOf(twoDForm.format(d));
  554.     }
  555.  
  556.     public String addCommas(int d, boolean money) {
  557.         DecimalFormat twoDForm = new DecimalFormat("###,###");
  558.         if(money) {
  559.             twoDForm = new DecimalFormat("$###,###");
  560.             return twoDForm.format(d);
  561.         }
  562.         return twoDForm.format(d);
  563.     }
  564.  
  565.     // Checks for the recent version
  566.     public double getOVersion() {
  567.         try {
  568.             URL url = new URL("http://megascripts.comyr.com/MegaBlacksmith/Version");
  569.             BufferedReader br = new BufferedReader(new InputStreamReader(
  570.                     new BufferedInputStream(url.openConnection()
  571.                             .getInputStream())));
  572.             double ver = Double.parseDouble(br.readLine().trim());
  573.             br.close();
  574.             return ver;
  575.         } catch (IOException e) {
  576.             throw new RuntimeException(e);
  577.         }
  578.     }
  579.  
  580.     public int antiBan() {
  581.         Point m;
  582.         int x = random(0, 750);
  583.         int y = random(0, 500);
  584.         int xx = random(710, 554);
  585.         int yy = random(444, 230);
  586.         int screenx = random(1, 510);
  587.         int screeny = random(1, 450);
  588.  
  589.         int gamble = random(0, 22);
  590.  
  591.         final long start = System.currentTimeMillis();
  592.         final RSPlayer myPlayer = getMyPlayer();
  593.  
  594.         int anim = -1;
  595.         while (System.currentTimeMillis() - start > 2000) {
  596.             if ((anim = myPlayer.getAnimation()) != -1) {
  597.                 break;
  598.             }
  599.             sleep(15);
  600.         }
  601.  
  602.         switch (gamble) {
  603.         case 1:
  604.  
  605.             break;
  606.         case 2:
  607.             mouse.move(x, y);
  608.  
  609.             while (System.currentTimeMillis() - start > 2000) {
  610.  
  611.                 if ((anim = myPlayer.getAnimation()) != -1) {
  612.                     break;
  613.                 }
  614.  
  615.             }
  616.  
  617.  
  618.             break;
  619.         case 3:
  620.             game.openTab(Tab.INVENTORY);
  621.  
  622.             break;
  623.         case 4:
  624.             if (getMyPlayer().isMoving()) {
  625.                 break;
  626.             }
  627.         case 5:
  628.             mouse.move(x, y);
  629.             int checkTime = 0;
  630.             long lastCheck = 0;
  631.             if (System.currentTimeMillis() - lastCheck >= checkTime) {
  632.                 lastCheck = System.currentTimeMillis();
  633.                 checkTime = random(60000, 180000);
  634.                 break;
  635.             }
  636.         case 6:
  637.             if (game.getTab() != Tab.STATS) {
  638.                 game.openTab(Tab.STATS);
  639.                 mouse.move(xx, yy);
  640.                 sleep(1500,3000);
  641.                 game.openTab(Tab.INVENTORY);
  642.                 break;
  643.             }
  644.         case 8:
  645.             mouse.move(screenx, screeny);
  646.             break;
  647.         case 9:
  648.             mouse.move(screenx, screeny);
  649.             break;
  650.         case 10:
  651.             game.openTab(game.getRandomTab());
  652.             break;
  653.         case 11:
  654.             mouse.move(x, y);
  655.             break;
  656.         case 13:
  657.             mouse.move(x, y);
  658.             break;
  659.         case 12:
  660.             mouse.move(x, y);
  661.             break;
  662.         case 14:
  663.             m = mouse.getLocation();
  664.             mouse.move(m, 20, 20); 
  665.             break;
  666.         case 15:
  667.             m = mouse.getLocation();
  668.             mouse.move(m, 20, 20);         
  669.             break;
  670.         case 16:
  671.             m = mouse.getLocation();
  672.             mouse.move(m, 20, 20);
  673.             break;
  674.         case 17:
  675.             m = mouse.getLocation();
  676.             mouse.move(m, 20, 20);
  677.             break;
  678.         case 19:
  679.             mouse.move(x, y);
  680.             break;
  681.         case 20:
  682.             mouse.move(x, y);
  683.             break;
  684.         case 21:
  685.             mouse.move(x, y);
  686.             break;
  687.  
  688.         }
  689.  
  690.         return 100;
  691.     }
  692.  
  693.     // JButton startButton;
  694.     // JComboBox whereandwhat;
  695.     // JLabel text;
  696.     // JLabel text2;
  697.     // String[] list = { "Smelt", "Smith"};
  698.     // String[] list2 = { "Bronze", "Iron", "Steel" };
  699.  
  700.     public class MegaGUI extends JFrame implements ItemListener, ActionListener {
  701.  
  702.         /**
  703.          * Initialize the contents of the
  704.          */
  705.         JLabel text;
  706.         JLabel lblWhatItem;
  707.         JLabel lblWhatBar;
  708.         JComboBox comboBox;
  709.         JComboBox comboBox_1;
  710.         JComboBox comboBox_2;
  711.         JButton btnStart;
  712.  
  713.         public MegaGUI() {
  714.             setTitle("MegaBlacksmith");
  715.             setSize(350, 239);
  716.             setLocationRelativeTo(null);
  717.             getContentPane().setLayout(null);
  718.  
  719.             text = new JLabel("Smelt or Smith?");
  720.             text.setBounds(25, 11, 91, 20);
  721.             getContentPane().add(text);
  722.  
  723.             comboBox = new JComboBox();
  724.             comboBox.addItemListener((ItemListener) this);
  725.             comboBox.setModel(new DefaultComboBoxModel(new String[] { "Smelt",
  726.             "Smith" }));
  727.             comboBox.setMaximumRowCount(2);
  728.             comboBox.setBounds(122, 11, 73, 20);
  729.             getContentPane().add(comboBox);
  730.  
  731.             lblWhatBar = new JLabel("What bar?");
  732.             lblWhatBar.setBounds(25, 56, 73, 14);
  733.             getContentPane().add(lblWhatBar);
  734.  
  735.             comboBox_1 = new JComboBox();
  736.             comboBox_1.setModel(new DefaultComboBoxModel(new String[] {
  737.                     "Bronze", "Iron", "Silver", "Steel", "Gold", "Mithril", "Adamant", "Rune" }));
  738.             comboBox_1.setBounds(122, 53, 73, 20);
  739.             getContentPane().add(comboBox_1);
  740.  
  741.             btnStart = new JButton("Start");
  742.             btnStart.setBounds(122, 145, 89, 23);
  743.             btnStart.addActionListener(this);
  744.             getContentPane().add(btnStart);
  745.  
  746.             lblWhatItem = new JLabel("What item?");
  747.             lblWhatItem.setBounds(25, 100, 73, 14);
  748.             getContentPane().add(lblWhatItem);
  749.             lblWhatItem.setVisible(false);
  750.  
  751.             comboBox_2 = new JComboBox();
  752.             comboBox_2.setModel(new DefaultComboBoxModel(new String[] {
  753.                     "Dagger", "Hatchet", "Mace", "Bolts", "Med helm",
  754.                     "Dart tips", "Sword", "Nails", "Arrow tips",
  755.                     "Scimitar", "Limbs", "Longsword", "Throwing knives",
  756.                     "Full helm", "Square shield", "Warhammer", "Battleaxe",
  757.                     "Chainbody", "Kiteshield", "Claws", "2h sword",
  758.                     "Platelegs", "Plateskirt", "Platebody" }));
  759.             comboBox_2.setBounds(122, 97, 95, 20);
  760.             getContentPane().add(comboBox_2);
  761.             comboBox_2.setVisible(false);
  762.         }
  763.  
  764.         public void itemStateChanged(ItemEvent e) {
  765.             if (e.getItem().equals("Smith")) {
  766.                 comboBox_1.setModel(new DefaultComboBoxModel(new String[] {
  767.                         "Bronze", "Iron", "Steel", "Mithril", "Adamant", "Rune" }));
  768.                 lblWhatItem.setVisible(true);
  769.                 comboBox_2.setVisible(true);
  770.             } else {
  771.                 comboBox_1.setModel(new DefaultComboBoxModel(new String[] {
  772.                         "Bronze", "Iron", "Silver", "Steel", "Gold", "Mithril", "Adamant", "Rune" }));
  773.                 lblWhatItem.setVisible(false);
  774.                 comboBox_2.setVisible(false);
  775.             }
  776.         }
  777.  
  778.         @Override
  779.         public void actionPerformed(ActionEvent e) {
  780.             if (e.getActionCommand().contains("Start")) {
  781.                 String doingString = comboBox.getSelectedItem().toString();
  782.                 String barString = comboBox_1.getSelectedItem().toString();
  783.                 String itemString = comboBox_2.getSelectedItem().toString();
  784.  
  785.                 if (doingString.equals("Smelt")) {
  786.                     location = "Al-Kharid";
  787.                     b = new RSTile(3270, 3168);
  788.                     m = new RSTile(3276, 3186);
  789.                     whatToDo = "Smelt";
  790.                     pName = barString;
  791.                     if (barString.equals("Bronze")) {
  792.                         o = 436;
  793.                         o2 = 438;
  794.                         oCount = 14;
  795.                         o2Count = 14;
  796.                         mP = new Point(260, 425);
  797.                         bar = 2349;
  798.                     }
  799.                     if (barString.equals("Iron")) {
  800.                         o = 440;
  801.                         oCount = 28;
  802.                         mP = new Point(260, 425);
  803.                         bar = 2351;
  804.                     }
  805.                     if (barString.equals("Silver")) {
  806.                         o = 442;
  807.                         oCount = 28;
  808.                         mP = new Point(260, 425);
  809.                         bar = 2355;
  810.                     }
  811.                     if (barString.equals("Steel")) {
  812.                         o = 440;
  813.                         o2 = 453;
  814.                         oCount = 9;
  815.                         o2Count = 19;
  816.                         mP = new Point(290, 425);
  817.                         bar = 2353;
  818.                     }
  819.                     if (barString.equals("Gold")) {
  820.                         o = 444;
  821.                         oCount = 28;
  822.                         mP = new Point(260, 425);
  823.                         bar = 2357;
  824.                     }
  825.                     if (barString.equals("Mithril")) {
  826.                         o = 447;
  827.                         o2 = 453;
  828.                         oCount = 5;
  829.                         o2Count = 23;
  830.                         mP = new Point(260, 425);
  831.                         bar = 2359;
  832.                     }
  833.                     if (barString.equals("Adamant")) {
  834.                         o = 449;
  835.                         o2 = 453;
  836.                         oCount = 5;
  837.                         o2Count = 23;
  838.                         mP = new Point(260, 425);
  839.                         bar = 2361;
  840.                     }
  841.                     if (barString.equals("Rune")) {
  842.                         o = 451;
  843.                         o2 = 453;
  844.                         oCount = 3;
  845.                         o2Count = 25;
  846.                         mP = new Point(260, 425);
  847.                         bar = 2363;
  848.                     }
  849.                     log("Making " + pName + " bars");
  850.                 } else {
  851.                     location = "Varrock";
  852.                     anvilTile = new RSTile(3188, 3426);
  853.                     b = new RSTile(3187, 3435);
  854.                     m = new RSTile(3187, 3426);
  855.                     whatToDo = "Smith";
  856.                     if (barString.equals("Bronze")) {
  857.                         log("Using bronze bars");
  858.                         bar = 2349;
  859.                     }
  860.                     if (barString.equals("Iron")) {
  861.                         log("Using iron bars");
  862.                         bar = 2351;
  863.                     }
  864.                     if (barString.equals("Steel")) {
  865.                         log("Using steel bars");
  866.                         bar = 2353;
  867.                     }
  868.                     if (barString.equals("Mithril")) {
  869.                         log("Using mithril bars");
  870.                         bar = 2359;
  871.                     }
  872.                     if (barString.equals("Adamant")) {
  873.                         log("Using adamant bars");
  874.                         bar = 2361;
  875.                     }
  876.                     if (barString.equals("Rune")) {
  877.                         log("Using rune bars");
  878.                         bar = 2363;
  879.                     }
  880.  
  881.                     if (itemString.contains("Dagger")) {
  882.                         cI = 21;
  883.                         barLeft = 0;
  884.                     }
  885.                     if (itemString.contains("Hatchet")) {
  886.                         cI = 27;
  887.                         barLeft = 0;
  888.                     }
  889.                     if (itemString.contains("Mace")) {
  890.                         cI = 35;
  891.                         barLeft = 0;
  892.                     }
  893.                     if (itemString.contains("Bolts")) {
  894.                         cI = 51;
  895.                         barLeft = 0;
  896.                     }
  897.                     if (itemString.contains("Med helm")) {
  898.                         cI = 43;
  899.                         barLeft = 0;
  900.                     }
  901.                     if (itemString.contains("Dart tips")) {
  902.                         cI = 67;
  903.                         barLeft = 0;
  904.                     }
  905.                     if (itemString.contains("Sword")) {
  906.                         cI = 59;
  907.                         barLeft = 0;
  908.                     }
  909.                     if (itemString.contains("Nails")) {
  910.                         cI = 21;
  911.                         barLeft = 0;
  912.                     }
  913.                     if (itemString.contains("Scimitar")) {
  914.                         cI = 117;
  915.                         barLeft = 0;
  916.                     }
  917.                     if (itemString.contains("Arrow tips")) {
  918.                         cI = 107;
  919.                         barLeft = 0;
  920.                     }
  921.                     if (itemString.contains("Limbs")) {
  922.                         cI = 125;
  923.                         barLeft = 0;
  924.                     }
  925.                     if (itemString.contains("Longsword")) {
  926.                         cI = 133;
  927.                         barLeft = 0;
  928.                     }
  929.                     if (itemString.contains("Throwing knives")) {
  930.                         cI = 141;
  931.                         barLeft = 0;
  932.                     }
  933.                     if (itemString.contains("Full helm")) {
  934.                         cI = 149;
  935.                         barLeft = 0;
  936.                     }
  937.                     if (itemString.contains("Square shield")) {
  938.                         cI = 157;
  939.                         barLeft = 0;
  940.                     }
  941.                     if (itemString.contains("Claws")) {
  942.                         cI = 213;
  943.                         barLeft = 0;
  944.                     }
  945.                     if (itemString.contains("Warhammer")) {
  946.                         cI = 181;
  947.                         barLeft = 1;
  948.                     }
  949.                     if (itemString.contains("Battleaxe")) {
  950.                         cI = 189;
  951.                         barLeft = 1;
  952.                     }
  953.                     if (itemString.contains("Chainbody")) {
  954.                         cI = 197;
  955.                         barLeft = 1;
  956.                     }
  957.                     if (itemString.contains("2h sword")) {
  958.                         cI = 221;
  959.                         barLeft = 1;
  960.                     }
  961.                     if (itemString.contains("Plateskirt")) {
  962.                         cI = 229;
  963.                         barLeft = 1;
  964.                     }
  965.                     if (itemString.contains("Platelegs")) {
  966.                         cI = 237;
  967.                         barLeft = 1;
  968.                     }
  969.                     if (itemString.contains("Kiteshield")) {
  970.                         cI = 205;
  971.                         barLeft = 1;
  972.                     }
  973.  
  974.                     if (itemString.contains("Platebody")) {
  975.                         cI = 245;
  976.                         scroll = true;
  977.                         barLeft = 3;
  978.                     }
  979.                     pName = itemString;
  980.                     log("Making " + pName + "s");
  981.                 }
  982.                 dispose();
  983.                 setVisible(false);
  984.                 start = true;
  985.             }
  986.         }
  987.  
  988.     }
  989.  
  990.     JButton oB;
  991.     JButton gN;
  992.     JLabel oL;
  993.  
  994.     public class VersionGUI extends JFrame implements ActionListener {
  995.  
  996.         public VersionGUI() {
  997.             setTitle("OUTDATED");
  998.  
  999.             oB = new JButton("Okay");
  1000.             oL = new JLabel("OUTDATED");
  1001.             gN = new JButton("Get new version");
  1002.  
  1003.             setLayout(null);
  1004.             setResizable(false);
  1005.             setSize(150, 185);
  1006.             setLocationRelativeTo(null);
  1007.  
  1008.             oB.setBounds(20, 35, 65, 25);
  1009.             gN.setBounds(20, 85, 115, 25);
  1010.             oB.addActionListener(this);
  1011.             gN.addActionListener(this);
  1012.             oL.setBounds(20, 5, 182, 21);
  1013.  
  1014.             add(oL);
  1015.             add(gN);
  1016.             add(oB);
  1017.  
  1018.             setVisible(true);
  1019.         }
  1020.  
  1021.         public void getNewVersion() {
  1022.             File directory = getCacheDirectory();
  1023.             File newDirectory = new File(new File(new File(
  1024.                     directory.getParent()).getParent()).getParent()
  1025.                     + File.separator
  1026.                     + "Scripts"
  1027.                     + File.separator
  1028.                     + "Sources"
  1029.                     + File.separator + "MegaBlacksmith.java");
  1030.  
  1031.             BufferedInputStream in;
  1032.             try {
  1033.                 in = new BufferedInputStream(
  1034.                         new URL(
  1035.                                 "http://megascripts.comyr.com/MegaBlacksmith/MegaBlacksmith.java")
  1036.                         .openStream());
  1037.                 FileOutputStream fos = new FileOutputStream(newDirectory);
  1038.                 BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
  1039.                 byte[] data = new byte[1024];
  1040.                 int x = 0;
  1041.                 while ((x = in.read(data, 0, 1024)) >= 0) {
  1042.                     bout.write(data, 0, x);
  1043.                 }
  1044.                 bout.close();
  1045.                 in.close();
  1046.             } catch (MalformedURLException e) {
  1047.                 // TODO Auto-generated catch block
  1048.                 e.printStackTrace();
  1049.             } catch (IOException e) {
  1050.                 // TODO Auto-generated catch block
  1051.                 e.printStackTrace();
  1052.             }
  1053.         }
  1054.  
  1055.         @Override
  1056.         public void actionPerformed(ActionEvent e) {
  1057.             if (e.getActionCommand().contains("Okay")) {
  1058.                 dispose();
  1059.                 setVisible(false);
  1060.             }
  1061.             if (e.getActionCommand().contains("Get new version")) {
  1062.                 getNewVersion();
  1063.                 sleep(1000);
  1064.                 oL.setText("Recompile the script");
  1065.                 repaint();
  1066.                 stopScript();
  1067.             }
  1068.         }
  1069.     }
  1070.  
  1071.     @Override
  1072.     public void mouseClicked(MouseEvent arg0) {
  1073.         if (r.contains(arg0.getPoint())) {
  1074.             if (hidePaint) {
  1075.                 hidePaint = false;
  1076.             } else {
  1077.                 hidePaint = true;
  1078.             }
  1079.         }
  1080.     }
  1081.  
  1082.     @Override
  1083.     public void mouseEntered(MouseEvent arg0) {
  1084.         // TODO Auto-generated method stub
  1085.  
  1086.     }
  1087.  
  1088.     @Override
  1089.     public void mouseExited(MouseEvent arg0) {
  1090.         // TODO Auto-generated method stub
  1091.  
  1092.     }
  1093.  
  1094.     @Override
  1095.     public void mousePressed(MouseEvent arg0) {
  1096.         // TODO Auto-generated method stub
  1097.  
  1098.     }
  1099.  
  1100.     @Override
  1101.     public void mouseReleased(MouseEvent arg0) {
  1102.         // TODO Auto-generated method stub
  1103.  
  1104.     }
  1105.  
  1106.     @Override
  1107.     public void messageReceived(MessageEvent m) {
  1108.         if(m.getMessage().contains("You make")) {
  1109.             iCount++;
  1110.         }
  1111.         if (pName.contains("Iron")) {
  1112.             if(m.getMessage().contains("You retrieve")) {
  1113.                 iCount++;
  1114.             }
  1115.         } else {
  1116.             if(m.getMessage().contains("You smelt")) {
  1117.                 iCount++;
  1118.             }
  1119.         }
  1120.     }
  1121. }
Advertisement
Add Comment
Please, Sign In to add comment