megaalgos

MegaBlacksmith 1.2

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