Advertisement
Rudie221

MultiCooker

Jun 2nd, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.10 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. import javax.swing.*;
  5. import java.awt.Color;
  6. import javax.imageio.ImageIO;
  7. import java.io.IOException;
  8. import java.net.URL;
  9.  
  10. import com.rarebot.event.events.MessageEvent;
  11. import com.rarebot.event.listeners.MessageListener;
  12. import com.rarebot.event.listeners.PaintListener;
  13. import com.rarebot.script.Script;
  14. import com.rarebot.script.ScriptManifest;
  15. import com.rarebot.script.methods.Skills;
  16. import com.rarebot.script.wrappers.RSComponent;
  17. import com.rarebot.script.wrappers.RSItem;
  18. import com.rarebot.script.wrappers.RSObject;
  19. import com.rarebot.script.wrappers.RSTile;
  20. import com.rarebot.script.wrappers.RSWeb;
  21.  
  22. @ScriptManifest(
  23.         authors = {"Rudie"},
  24.         version = 1.0,
  25.         keywords = ("cooker, cooking, aio, rudie"),
  26.         description = "Cooks all types of food!",
  27.         name = "MultiCooker"
  28. )
  29. public class MultiCooker extends Script implements PaintListener, MessageListener, MouseListener {
  30.    
  31.     public int foodID;
  32.     public int rangeID = 25730;
  33.     public int[] boothID = {};
  34.    
  35.     RSTile Banktile = new RSTile(3270, 3167, 0);
  36.     RSTile Rangetile = new RSTile(3273, 3180, 0);
  37.    
  38.     long startTime;
  39.     private String status = "Loading...";
  40.    
  41.        int expGained = 0;
  42.        int startExp = 0;
  43.        int foodCooked = 0;
  44.        int foodBurnt = 0;
  45.        int gainedLvl = 0;
  46.        private static boolean hide = false;
  47.        public boolean showPaint = true ;
  48.        public boolean clicked = false;
  49.    
  50.     MultiCookerGUI g;
  51.     private boolean guiWait = true;
  52.    
  53.     public boolean onStart() {
  54.         log(Color.RED, "Welcome to MultiCooker.");
  55.         startTime = System.currentTimeMillis();
  56.         mouse.setSpeed(random(5, 7));
  57.         startExp = skills.getCurrentExp(Skills.COOKING);
  58.         try {
  59.             SwingUtilities.invokeAndWait(new Runnable() {
  60.  
  61.                 public void run() {
  62.                     g = new MultiCookerGUI();
  63.                     g.setVisible(true);
  64.                 }
  65.             });
  66.         } catch (Throwable e) {
  67.             log("Fail.");
  68.         }
  69.        
  70.         while(guiWait) sleep(500);
  71.        
  72.         return true;
  73.     }
  74.  
  75.     @Override
  76.     public int loop() {
  77.         RSObject r = objects.getNearest(rangeID);
  78.         if(inventory.contains(foodID) && r.isOnScreen()) {
  79.             cook();
  80.             AntiBan();
  81.             AntiBanCamera();
  82.         } else {
  83.             if(!inventory.contains(foodID)) {
  84.             walktoBank();
  85.         }
  86.         }
  87.             if(!inventory.contains(foodID)) {
  88.                 doBank();
  89.         } else {
  90.             walktoRange();
  91.             }
  92.         return random(500, 800);
  93.     }
  94.  
  95.     private void walktoBank() {
  96.             RSWeb walkWeb = web.getWeb(Banktile);
  97.             if (walkWeb != null && !walkWeb.finished()) {
  98.                 walkWeb.step();
  99.                 sleep(200, 300);
  100.                 clicked = false;
  101.             } else if (walkWeb == null) {
  102.                 walkWeb = web.getWeb(Banktile);
  103.                 clicked = false;
  104.             }}
  105.    
  106.     private void walktoRange() {
  107.             RSWeb walkWeb = web.getWeb(Rangetile);
  108.             if (walkWeb != null && !walkWeb.finished()) {
  109.                 walkWeb.step();
  110.                 sleep(200, 300);
  111.             } else if (walkWeb == null) {
  112.                 walkWeb = web.getWeb(Rangetile);
  113.             }}
  114.  
  115.     private void cook() {
  116.         RSItem f = inventory.getItem(foodID);
  117.         RSObject r = objects.getNearest(rangeID);
  118.         if(r != null && getMyPlayer().getAnimation() == -1 && !cookingInterface().isValid() && clicked == false) {
  119.             camera.turnTo(r);
  120.             status = "Cooking";
  121.             sleep(1500, 2000);
  122.             f.interact("Use");
  123.             sleep(500, 1000);
  124.             r.doClick();
  125.             sleep(2000, 2250);
  126.         } else {
  127.             if (cookingInterface().isValid()) {
  128.                     interfaces.getComponent(905, 14).doClick();
  129.                     clicked = true;
  130.                     status = "Cooking";
  131.                 sleep(1200, 1400);
  132.             }
  133.         }
  134.     }
  135.  
  136.     private void doBank() {
  137.         if (bank.isOpen()) {
  138.             if (inventory.getCountExcept(foodID) > 0) {
  139.                 if (bank.depositAll()) {
  140.                     status = "Banking";
  141.                     sleep(400, 450);
  142.                 }
  143.             }
  144.             if (!inventory.contains(foodID)) {
  145.                 if (bank.getCount(foodID) > 0) {
  146.                     if (bank.withdraw(foodID, 0)) {
  147.                         status = "Banking";
  148.                         sleep(250, 300);
  149.                     }}}
  150.         } else {
  151.             bank.open();
  152.             status = "Banking";
  153.             sleep(1000, 1200);
  154.         }
  155.     }
  156.    
  157.     private RSComponent cookingInterface() {
  158.         return interfaces.getComponent(905, 14);
  159.     }
  160.    
  161.     @Override
  162.     public void messageReceived(MessageEvent e) {
  163.         String txt = e.getMessage().toLowerCase();
  164.         if(txt.contains("successfully"))  {
  165.             foodCooked++;
  166.         }
  167.         if(txt.contains("burn")) {
  168.             foodBurnt++;
  169.         }
  170.         if(txt.contains("cooking level")) {
  171.             gainedLvl++;
  172.         }
  173.     }
  174.    
  175.     private Image getImage(String url) {
  176.         try {
  177.             return ImageIO.read(new URL(url));
  178.         } catch(IOException e) {
  179.             return null;
  180.         }
  181.     }
  182.  
  183.     private final Color color1 = new Color(255, 255, 255);
  184.     private final Color color2 = new Color(255, 255, 255, 0);
  185.     private final Color color3 = new Color(178, 34, 34);
  186.  
  187.     private final BasicStroke stroke1 = new BasicStroke(1);
  188.  
  189.     private final Font font1 = new Font("Arial", 1, 14);
  190.  
  191.     private final Image img1 = getImage("http://epicscape668.org/images/cook.png");
  192.  
  193.     public void onRepaint(Graphics g) {
  194.         expGained = skills.getCurrentExp(Skills.COOKING) - startExp;
  195.        
  196.         long millis = System.currentTimeMillis() - startTime;
  197.         long hours = millis / (1000 * 60 * 60);
  198.         millis -= hours * (1000 * 60 * 60);
  199.         long minutes = millis / (1000 * 60);
  200.         millis -= minutes * (1000 * 60);
  201.         long seconds = millis / 1000;
  202.        
  203.         float xpsec = 0;
  204.         if((minutes > 0 || hours > 0 || seconds > 0)&& expGained > 0) {
  205.             xpsec = ((float) expGained)/(float)(seconds + (minutes*60) + (hours*60*60));
  206.         }
  207.         float xpmin = xpsec * 60;
  208.         float xphour = xpmin * 60;
  209.        
  210.         float foodsec = 0;
  211.         if((minutes > 0 || hours > 0 || seconds > 0)&& foodCooked > 0) {
  212.             foodsec = ((float) foodCooked)/(float)(seconds + (minutes*60) + (hours*60*60));
  213.         }
  214.         float foodmin = foodsec * 60;
  215.         float foodhour = foodmin * 60;
  216.        
  217.         Graphics2D g1 = (Graphics2D)g;
  218.         g1.setColor(color2);
  219.         g1.fillRect(336, 346, 75, 17);
  220.         g1.setColor(color3);
  221.         g1.setStroke(stroke1);
  222.         g1.drawRect(336, 346, 75, 17);
  223.         g1.drawString("Show", 357, 360);
  224.         g.setColor(Color.WHITE);
  225.         g.drawLine(0, (int)(mouse.getLocation().getY()), 800, (int)(mouse.getLocation().getY()));
  226.         g.drawLine((int)(mouse.getLocation().getX()), 0, (int)(mouse.getLocation().getX()), 800);
  227.         if(!hide) {
  228.         g1.drawImage(img1, -7, -30, null);
  229.         g1.setFont(font1);
  230.         g1.setColor(color1);
  231.         g1.drawString("" + hours + ":" + minutes + ":" + seconds, 120, 391);
  232.         g1.drawString("" + expGained, 139, 416);
  233.         g1.drawString("" + (int) xphour, 96, 444);
  234.         g1.drawString("" + foodBurnt, 146, 470);
  235.         g1.drawString("" + foodCooked, 409, 391);
  236.         g1.drawString("" + (int) foodhour, 355, 415);
  237.         g1.drawString("" + status, 345, 443);
  238.         g1.drawString("" + gainedLvl + " (C:"+skills.getCurrentLevel(Skills.COOKING)+")", 407, 471);
  239.         g1.setColor(color2);
  240.         g1.fillRect(336, 346, 75, 17);
  241.         g1.setColor(color1);
  242.         g1.setStroke(stroke1);
  243.         g1.drawRect(336, 346, 75, 17);
  244.         g1.drawString("Hide", 357, 360);
  245.         g.setColor(Color.WHITE);
  246.         g.drawLine(0, (int)(mouse.getLocation().getY()), 800, (int)(mouse.getLocation().getY()));
  247.         g.drawLine((int)(mouse.getLocation().getX()), 0, (int)(mouse.getLocation().getX()), 800);
  248.         }
  249.         }
  250.  
  251.     @Override
  252.     public void mouseClicked(MouseEvent e) {
  253.         final Rectangle rect = new Rectangle(336, 346, 75, 17);
  254.         final Point p = e.getPoint();
  255.         if (rect.contains(p) && !hide) {
  256.             hide = true;
  257.         } else if (rect.contains(p) && hide) {
  258.             hide = false;
  259.         }
  260.     }
  261.    
  262.       private void AntiBanCamera() {
  263.             int randomNum = random(1, 160);
  264.             if (randomNum == 1 || randomNum == 2 || randomNum == 3) {
  265.               camera.moveRandomly(random(2000, 5500));
  266.             }
  267.             if (randomNum == 4 || randomNum == 5) {
  268.               camera.setAngle(random(10, 40));
  269.             }
  270.             if (randomNum == 6) {
  271.               camera.setPitch(random(40, 68));
  272.             }
  273.             if (randomNum == 7) {
  274.               camera.setPitch(random(20, 45));
  275.             }
  276.             if (randomNum == 8) {
  277.               camera.setPitch(random(68, 90));
  278.             } else
  279.               sleep(50, 70);
  280.           }
  281.      
  282.       @SuppressWarnings("deprecation")
  283.     private void AntiBan() {
  284.             int randomProd = random(1, 60);
  285.             if (randomProd == 1) {
  286.               int randomMore = random(1, 5);
  287.               if (randomMore == 1) {
  288.                 if (game.getCurrentTab() != 2) {
  289.                   game.openTab(2);
  290.                   sleep(350, 500);
  291.                   skills.doHover(Skills.COOKING);
  292.                   sleep(2000, 3500);
  293.                 } else {
  294.                   mouse.move(random(678, 728), random(213, 232));
  295.                   sleep(2000, 3500);
  296.                 }
  297.               } else {
  298.                 sleep(1200, 2500);
  299.               }
  300.             }
  301.             if (randomProd == 2 || randomProd == 3 || randomProd == 4) {
  302.               sleep(1000, 2500);
  303.             }
  304.             if (randomProd >= 52) {
  305.               mouse.moveRandomly(65, 350);
  306.             } else
  307.               sleep(10, 30);
  308.           }
  309.    
  310.     public void onFinish() {
  311.         log(Color.RED, "Thanks for using: MultiCooker!");
  312.         env.saveScreenshot(true);
  313.     }
  314.    
  315.      class MultiCookerGUI extends JFrame {
  316.          /**
  317.              *
  318.              */
  319.             private static final long serialVersionUID = 1L;
  320.             public MultiCookerGUI() {
  321.                 initComponents();
  322.             }
  323.  
  324.             private void startActionPerformed(ActionEvent e) {
  325.                 foodID = Integer.parseInt(foodfield.getText());
  326.                 guiWait = false;
  327.                 g.dispose();
  328.             }
  329.  
  330.             private void initComponents() {
  331.                 // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
  332.                 // Generated using JFormDesigner Evaluation license - Rudie Visser
  333.                 label1 = new JLabel();
  334.                 start = new JButton();
  335.                 label2 = new JLabel();
  336.                 label3 = new JLabel();
  337.                 foodfield = new JTextField();
  338.  
  339.                 //======== this ========
  340.                 setTitle("MultiCooker GUI");
  341.                 Container contentPane = getContentPane();
  342.  
  343.                 //---- label1 ----
  344.                 label1.setText("MultiCooker GUI");
  345.                 label1.setForeground(Color.red);
  346.                 label1.setFont(new Font("Tahoma", Font.PLAIN, 48));
  347.  
  348.                 //---- start ----
  349.                 start.setText("Start Cooking!");
  350.                 start.addActionListener(new ActionListener() {
  351.                     @Override
  352.                     public void actionPerformed(ActionEvent e) {
  353.                         startActionPerformed(e);
  354.                     }
  355.                 });
  356.  
  357.                 //---- label2 ----
  358.                 label2.setText("To start cooking simply fill in your food id what you want to cook:");
  359.  
  360.                 //---- label3 ----
  361.                 label3.setText("And then press: \"Start Cooking\".");
  362.  
  363.                 GroupLayout contentPaneLayout = new GroupLayout(contentPane);
  364.                 contentPane.setLayout(contentPaneLayout);
  365.                 contentPaneLayout.setHorizontalGroup(
  366.                     contentPaneLayout.createParallelGroup()
  367.                         .addGroup(contentPaneLayout.createSequentialGroup()
  368.                             .addContainerGap()
  369.                             .addComponent(label1)
  370.                             .addContainerGap(14, Short.MAX_VALUE))
  371.                         .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
  372.                             .addContainerGap(31, Short.MAX_VALUE)
  373.                             .addComponent(label2)
  374.                             .addGap(27, 27, 27))
  375.                         .addGroup(contentPaneLayout.createSequentialGroup()
  376.                             .addGap(95, 95, 95)
  377.                             .addComponent(label3)
  378.                             .addContainerGap(117, Short.MAX_VALUE))
  379.                         .addGroup(contentPaneLayout.createSequentialGroup()
  380.                             .addGap(123, 123, 123)
  381.                             .addComponent(start, GroupLayout.PREFERRED_SIZE, 123, GroupLayout.PREFERRED_SIZE)
  382.                             .addContainerGap(123, Short.MAX_VALUE))
  383.                         .addGroup(contentPaneLayout.createSequentialGroup()
  384.                             .addGap(43, 43, 43)
  385.                             .addComponent(foodfield, GroupLayout.PREFERRED_SIZE, 283, GroupLayout.PREFERRED_SIZE)
  386.                             .addContainerGap(43, Short.MAX_VALUE))
  387.                 );
  388.                 contentPaneLayout.setVerticalGroup(
  389.                     contentPaneLayout.createParallelGroup()
  390.                         .addGroup(contentPaneLayout.createSequentialGroup()
  391.                             .addContainerGap()
  392.                             .addComponent(label1)
  393.                             .addGap(41, 41, 41)
  394.                             .addComponent(label2)
  395.                             .addGap(2, 2, 2)
  396.                             .addComponent(label3)
  397.                             .addGap(18, 18, 18)
  398.                             .addComponent(foodfield, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  399.                             .addGap(27, 27, 27)
  400.                             .addComponent(start, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE)
  401.                             .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  402.                 );
  403.                 pack();
  404.                 setLocationRelativeTo(getOwner());
  405.                 // JFormDesigner - End of component initialization  //GEN-END:initComponents
  406.             }
  407.  
  408.             // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
  409.             // Generated using JFormDesigner Evaluation license - Rudie Visser
  410.             private JLabel label1;
  411.             private JButton start;
  412.             private JLabel label2;
  413.             private JLabel label3;
  414.             private JTextField foodfield;
  415.             // JFormDesigner - End of variables declaration  //GEN-END:variables
  416.         }
  417.  
  418.     @Override
  419.     public void mouseEntered(MouseEvent arg0) {
  420.         // TODO Auto-generated method stub
  421.        
  422.     }
  423.  
  424.     @Override
  425.     public void mouseExited(MouseEvent arg0) {
  426.         // TODO Auto-generated method stub
  427.        
  428.     }
  429.  
  430.     @Override
  431.     public void mousePressed(MouseEvent arg0) {
  432.         // TODO Auto-generated method stub
  433.        
  434.     }
  435.  
  436.     @Override
  437.     public void mouseReleased(MouseEvent arg0) {
  438.         // TODO Auto-generated method stub
  439.        
  440.     }
  441. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement