megaalgos

MegaBlacksmith 1.1

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