Guest User

Untitled

a guest
Jun 23rd, 2013
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.54 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Container;
  3. import java.awt.Dimension;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Insets;
  7. import java.awt.Point;
  8. import java.awt.Rectangle;
  9. import java.awt.event.*;
  10. import java.text.DateFormat;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Calendar;
  13. import java.util.List;
  14.  
  15. import javax.swing.*;
  16.  
  17. import javax.swing.DefaultComboBoxModel;
  18. import javax.swing.JButton;
  19. import javax.swing.JCheckBox;
  20. import javax.swing.JComboBox;
  21. import javax.swing.JFrame;
  22. import javax.swing.JLabel;
  23.  
  24. import org.osbot.script.Script;
  25. import org.osbot.script.ScriptManifest;
  26. import org.osbot.script.rs2.model.Entity;
  27. import org.osbot.script.rs2.model.GroundItem;
  28. import org.osbot.script.rs2.model.Item;
  29. import org.osbot.script.rs2.model.Player;
  30. import org.osbot.script.rs2.model.RS2Object;
  31. import org.osbot.script.rs2.skill.Skill;
  32. import org.osbot.script.rs2.ui.Tab;
  33. import org.osbot.script.rs2.utility.Area;
  34.  
  35.  
  36. @ScriptManifest(
  37.     name = "Chop Everywhere",
  38.     author = "Merccy",
  39.     version = 1D,
  40.     info = "Now you can chop every tree on any location! It will pick up birdnests and train your firemaking if you want."
  41. )
  42. public class ChopEverywhere extends Script{
  43.  
  44.     private Object treeToChop = null;
  45.    
  46.     // IDS
  47.     public int[] trees = { 1276, 1278, 10041 };
  48.     public int[] oak = { 1281 };
  49.     public int[] willow = { 1307, 1308, 2467, 1309 };
  50.     public int[] maple = { 2782 };
  51.     public int[] yew = { 2468 };
  52.     public int[] magictree = { 1306 };
  53.     public int[] axes = { 1353, 1349, 1351, 1355, 1357, 1359, 1361, 6739 };
  54.     public int[] nests = { 5073, 5070, 5074 };
  55.     public int[][] logs = { { 1511, 1 }, { 2862, 1 }, { 1521, 15 }, { 1519, 30 }, { 6333, 35 }, { 10810, 42 }, { 1517, 45 }, { 6332, 50 }, { 1515, 60 }, { 1513, 75 } };
  56.     public int[] dontDropElse = { 590 };
  57.     public int tinderbox = 590;
  58.    
  59.     // Options
  60.     public int[] toUse;
  61.     public int[] dontDrop;
  62.     public int aBanVal;
  63.     public boolean birdsNest;
  64.     public boolean willLight;
  65.    
  66.     // GUI Data
  67.     public long startTime;
  68.     public long runTime;
  69.     public long startXP;
  70.     public long startLevel;
  71.     public long startFXP;
  72.     public long startFLevel;
  73.     public int cut = 0;
  74.     public long seconds,minutes,hours;
  75.    
  76.     //GUI
  77.     ChopEverywhereGUI g = new ChopEverywhereGUI();
  78.     public boolean guiWait = true;
  79.    
  80.     public void onStart(){
  81.         log("Chop Everywhere started.");
  82.         g.setVisible(true);
  83.         while(guiWait){
  84.            
  85.         }
  86.         this.startXP = this.client.getSkills().getExperience(Skill.WOODCUTTING);
  87.         this.startLevel = this.client.getSkills().getCurrentLevel(Skill.WOODCUTTING);
  88.         this.startFXP = this.client.getSkills().getExperience(Skill.FIREMAKING);
  89.         this.startFLevel = this.client.getSkills().getLevel(Skill.FIREMAKING);
  90.     }
  91.    
  92.     public int onLoop(){
  93.         try{   
  94.             ChopState now = getState();
  95.            
  96.             if(this.birdsNest){
  97.                 pickupNests();
  98.             }
  99.            
  100.             handleState(now);
  101.            
  102.             if(random(aBanVal)==0){
  103.                 sleep(antiBan());
  104.             }
  105.            
  106.         } catch(Exception e) {}
  107.         return 50;
  108.     }
  109.    
  110.     public void onMessage(String message){
  111.         if(message.contains("logs.")){
  112.             this.cut += 1;
  113.         }
  114.         if(message.contains("can't light a fire")){
  115.             findEmptyTile();
  116.         }
  117.     }
  118.    
  119.     public void onPaint(Graphics g){
  120.         this.runTime = (System.currentTimeMillis() - this.startTime);
  121.         this.seconds = (this.runTime / 1000L);
  122.         if (this.seconds >= 60L) {
  123.           this.minutes = (this.seconds / 60L);
  124.           this.seconds -= this.minutes * 60L;
  125.         }
  126.         if (this.minutes >= 60L) {
  127.           this.hours = (this.minutes / 60L);
  128.           this.minutes -= this.hours * 60L;
  129.         }
  130.        
  131.         long XPGained = (this.client.getSkills().getExperience(Skill.WOODCUTTING) - this.startXP);
  132.         long XPHour = ((int)(3600000.0D / this.runTime * XPGained));
  133.         long LevelsGained = (this.client.getSkills().getLevel(Skill.WOODCUTTING) - this.startLevel);
  134.         long LevelsPH = ((int)(3600000.0D / this.runTime * LevelsGained));
  135.        
  136.         long XPFGained = (this.client.getSkills().getExperience(Skill.FIREMAKING) - this.startFXP);
  137.         long XPFHour = ((int)(3600000.0D / this.runTime * XPFGained));
  138.         long LevelsFGained = (this.client.getSkills().getLevel(Skill.FIREMAKING) - this.startFLevel);
  139.         long LevelsFPH = ((int)(3600000.0D / this.runTime * LevelsFGained));
  140.        
  141.         long cutph = ((int)(3600000.0D / this.runTime * this.cut));
  142.        
  143.         int widthAcross = this.client.getInterface(548).getChild(98).getWidth();
  144.         int heightAcross = this.client.getInterface(548).getChild(98).getHeight();
  145.         int paintWidth = widthAcross;
  146.        
  147.         g.setColor(new Color(0, 0, 0, 150));
  148.         g.fill3DRect(547, 205, paintWidth, heightAcross, true);
  149.         this.rowx = 559;
  150.         this.rowy = 224;
  151.         Color white = new Color(255,255,255);
  152.         Font calibri = new Font("Arial", 0, 12);
  153.         g.setColor(white);
  154.         g.setFont(new Font("Arial", 0, 16));
  155.         g.drawString("Chop Everywhere by Merccy", this.rowx, this.rowy);
  156.         this.rowy += 25;
  157.         writeText(g, calibri, white, "Logs chopped:  " + this.cut);
  158.         writeText(g, calibri, white, "Logs/hour: " + cutph);
  159.         writeText(g, calibri, white, "XP Gained: " + XPGained);
  160.         writeText(g, calibri, white, "XP/hour: " + XPHour);
  161.         writeText(g, calibri, white, "Levels Gained: " + LevelsGained);
  162.         writeText(g, calibri, white, "Levels/hour: " + LevelsPH);
  163.         this.rowy += 25;
  164.         writeText(g, calibri, white, "Fire XP Gained: " + XPFGained);
  165.         writeText(g, calibri, white, "Fire XP/hour: " + XPFHour);
  166.         writeText(g, calibri, white, "Fire Levels Gained: " + LevelsFGained);
  167.         writeText(g, calibri, white, "Fire Levels/hour: " + LevelsFPH);
  168.         this.rowy += 25;
  169.         writeText(g, calibri, white, "Runtime: H:" + this.hours + " M:" + this.minutes + " S:" + this.seconds);
  170.     }
  171.    
  172.     public int rowx;
  173.     public int rowy;
  174.     public void writeText(Graphics g, Font f, Color c, String t){
  175.         g.setColor(c);
  176.         g.setFont(f);
  177.         g.drawString(t, this.rowx, this.rowy);
  178.         this.rowy += 15;
  179.     }
  180.    
  181.     public void pickupNests() throws InterruptedException{
  182.         GroundItem nest = closestGroundItem(this.nests);
  183.         if(nest != null){
  184.             if(nest.isVisible()){
  185.                 nest.interact("Take");
  186.                 sleep(random(1000,2000));
  187.             }else{
  188.                 this.client.moveCameraToEntity(nest);
  189.                 walkExact(nest.position);
  190.             }
  191.         }
  192.     }
  193.    
  194.     public int antiBan() throws InterruptedException{
  195.         log("Antiban...");
  196.         int rnd = random(1,12);
  197.         if(rnd == 1){
  198.             this.client.setMouseSpeed(random(3,7));
  199.         }else if(rnd == 2){
  200.             this.client.rotateCameraPitch(random(30,100));
  201.         }else if(rnd == 3){
  202.             this.client.rotateCameraToAngle(random(30, 150));
  203.         }else if(rnd == 4){
  204.             if(currentTab() != Tab.SKILLS){
  205.                 openTab(Tab.SKILLS);
  206.                 sleep(1500 + random(1000));
  207.                 this.client.rotateCameraPitch(random(180));
  208.                 sleep(1250 + random(1250));
  209.                 openTab(Tab.INVENTORY);
  210.             }
  211.         }else if(rnd == 5){
  212.             this.client.getInterface(548).getChild(89).hover();
  213.         }else if(rnd == 6){
  214.             this.client.getInterface(548).getChild(85).hover();
  215.         }else if(rnd == 7){
  216.             this.client.getInterface(548).getChild(109).hover();
  217.         }else if(rnd == 8){
  218.             this.client.getInterface(548).getChild(84).hover();
  219.         }else if (rnd == 9){
  220.             if (this.client.getInterface(320).getChild(144).isVisible()) {
  221.                 this.client.getInterface(548).getChild(50).interact();
  222.                 sleep(random(0, 600));
  223.             }
  224.             this.client.rotateCameraToAngle(random(60, 160));
  225.         }else if (rnd == 10){
  226.             this.client.getInterface(548).getChild(75).hover();
  227.         }else if (rnd == 11){
  228.             this.client.getInterface(548).getChild(100).hover();
  229.         }else if (rnd == 12){
  230.             this.client.getInterface(548).getChild(44).hover();
  231.         }
  232.        
  233.         return random(1000,2500);
  234.     }
  235.    
  236.     public void findEmptyTile(){
  237.         int[] c = { this.client.getMyPlayer().getX(), this.client.getMyPlayer().getY() };
  238.         Area a = null;
  239.         int r = random(4);
  240.         if (r == 0)
  241.               a = new Area(c[0] + 1, c[1], c[0] + 1, c[1]);
  242.             else if (r == 1)
  243.               a = new Area(c[0] - 1, c[1], c[0] - 1, c[1]);
  244.             else if (r == 2)
  245.               a = new Area(c[0], c[1] + 1, c[0], c[1] + 1);
  246.             else if (r == 3)
  247.               a = new Area(c[0], c[1] - 1, c[0], c[1] + 1);
  248.         List fires = this.closestObjectListForName(new String[] { "Fire" });
  249.         for(int x = 0; x < fires.size(); x++){
  250.             RS2Object f = (RS2Object)fires.get(x);
  251.             if(a.contains(f.getX(), f.getY())){
  252.             }
  253.         }
  254.         try{
  255.             if(!a.contains(c[0], c[1])){
  256.                 walk(a);
  257.             }
  258.         }catch(Exception e){}
  259.     }
  260.    
  261.     public ChopState getState() throws InterruptedException{
  262.         Player player = this.client.getMyPlayer();
  263.         this.treeToChop = closestObject(toUse);
  264.         if(this.client.getInventory().isFull()){
  265.             if(willLight){
  266.                 return ChopState.Lighting;
  267.             }else{
  268.                 return ChopState.Dropping;
  269.             }
  270.         }
  271.         if(!this.client.getInventory().isFull()){
  272.             if((this.treeToChop != null) && (!player.isAnimating())){
  273.                 return ChopState.Chopping;
  274.             }
  275.         }
  276.         return ChopState.Waiting;
  277.     }
  278.    
  279.     public void handleState(ChopState state) throws InterruptedException{
  280.         switch(state){
  281.             case Waiting:
  282.                 break;
  283.             case Dropping:
  284.                 this.client.getInventory().dropAllExcept(this.dontDrop);
  285.                 sleep(200 + random(400));
  286.                 break;
  287.             case Lighting:
  288.                 for(int i = 0; i < this.logs.length; i++){
  289.                     if((this.client.getSkills().getLevel(Skill.FIREMAKING) > this.logs[i][1]) && (this.client.getInventory().contains(this.logs[i][0]))){
  290.                         for (Item it : this.client.getInventory().getItems()){
  291.                             if(it.getId() == this.logs[i][0]){
  292.                                 Area a = new Area(this.client.getMyPlayer().getX(), this.client.getMyPlayer().getY(),this.client.getMyPlayer().getX(), this.client.getMyPlayer().getY());
  293.                                 List fires = this.closestObjectListForName(new String[] { "Fire" });
  294.                                 for(int x = 0; x < fires.size(); x++){
  295.                                     RS2Object f = (RS2Object)fires.get(x);
  296.                                     if(a.contains(f.getX(), f.getY())){
  297.                                         findEmptyTile();
  298.                                         sleep(random(250,750));
  299.                                     }
  300.                                 }
  301.                                 selectInventoryOption(this.client.getInventory().getSlotForId(it.getId()), "Use");
  302.                                 selectInventoryOption(this.client.getInventory().getSlotForId(this.tinderbox), "Use");
  303.                                 sleep(random(500,1000));
  304.                                 while((this.client.getMyPlayer().isAnimating() && this.client.getMyPlayer().getAnimation() == 733) || this.client.getMyPlayer().isMoving()){
  305.                                     sleep(100);
  306.                                 }
  307.                             }
  308.                         }
  309.                     }
  310.                 }
  311.                 break;
  312.             case Chopping:
  313.                 if(this.client.getRunEnergy() > 25){
  314.                     setRunning(true);
  315.                 }
  316.                 Entity tree = (Entity)this.treeToChop;
  317.                 if(!tree.isVisible()){
  318.                     this.client.moveCameraToEntity(tree);
  319.                     this.client.rotateCameraPitch(60 + gRandom(7, 1.0D));
  320.                 }
  321.                 tree.interact("Chop down", false, true);
  322.                 sleep(750 + random(750));
  323.                 break;
  324.         }
  325.     }
  326.    
  327.     final static public int[] merge(final int[] ...arrays ) {
  328.         int size = 0;
  329.         for ( int[] a: arrays )
  330.             size += a.length;
  331.  
  332.             int[] res = new int[size];
  333.  
  334.             int destPos = 0;
  335.             for ( int i = 0; i < arrays.length; i++ ) {
  336.                 if ( i > 0 ) destPos += arrays[i-1].length;
  337.                 int length = arrays[i].length;
  338.                 System.arraycopy(arrays[i], 0, res, destPos, length);
  339.             }
  340.  
  341.             return res;
  342.     }
  343.    
  344.     public static String convertMilliSecondsToDate(long milliSeconds, String dateFormat)
  345.     {
  346.         // Create a DateFormatter object for displaying date in specified format.
  347.         DateFormat formatter = new SimpleDateFormat(dateFormat);
  348.  
  349.         // Create a calendar object that will convert the date and time value in milliseconds to date.
  350.          Calendar calendar = Calendar.getInstance();
  351.          calendar.setTimeInMillis(milliSeconds);
  352.  
  353.          return formatter.format(calendar.getTime());
  354.     }
  355.    
  356.     public static boolean isInteger(String s) {
  357.         try {
  358.             Integer.parseInt(s);
  359.         } catch(NumberFormatException e) {
  360.             return false;
  361.         }
  362.         // only got here if we didn't return false
  363.         return true;
  364.     }
  365.    
  366.     private enum ChopState{
  367.         Waiting, Dropping, Lighting, Chopping
  368.     }
  369.    
  370.    
  371.     //GUI!!!
  372.     public class ChopEverywhereGUI extends JFrame {
  373.         public ChopEverywhereGUI() {
  374.             initComponents();
  375.         }
  376.  
  377.         private void startButtonActionPerformed(ActionEvent e) {
  378.             String combo = comboBox1.getSelectedItem().toString();
  379.             if(combo.equalsIgnoreCase("tree")){
  380.                 toUse = trees;
  381.             }else if(combo.equalsIgnoreCase("oak")){
  382.                 toUse = oak;
  383.             }else if(combo.equalsIgnoreCase("willow")){
  384.                 toUse = willow;
  385.             }else if(combo.equalsIgnoreCase("maple")){
  386.                 toUse = maple;
  387.             }else if(combo.equalsIgnoreCase("yew")){
  388.                 toUse = yew;
  389.             }else if(combo.equalsIgnoreCase("magic")){
  390.                 toUse = magictree;
  391.             }
  392.             birdsNest = checkBNest.isSelected();
  393.             willLight = checkLight.isSelected();
  394.             dontDrop = merge(axes, dontDropElse);
  395.             if(birdsNest){
  396.                 dontDrop = merge(axes, nests, dontDropElse);
  397.             }
  398.             if(isInteger(antibanVal.getText())){
  399.                 aBanVal = Integer.parseInt(antibanVal.getText());
  400.             }else{
  401.                 aBanVal = 25;
  402.             }
  403.             startTime = System.currentTimeMillis();
  404.             guiWait = false;
  405.             g.dispose();
  406.         }
  407.  
  408.         private void initComponents() {
  409.             // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
  410.             label1 = new JLabel();
  411.             label2 = new JLabel();
  412.             comboBox1 = new JComboBox<>();
  413.             startButton = new JButton();
  414.             label3 = new JLabel();
  415.             checkBNest = new JCheckBox();
  416.             label4 = new JLabel();
  417.             checkLight = new JCheckBox();
  418.             label5 = new JLabel();
  419.             antibanVal = new JTextField();
  420.  
  421.             //======== this ========
  422.             setTitle("Chop Everywhere Settings");
  423.             Container contentPane = getContentPane();
  424.             contentPane.setLayout(null);
  425.  
  426.             //---- label1 ----
  427.             label1.setText("Chop Everywhere");
  428.             label1.setFont(new Font("Segoe UI", Font.BOLD, 22));
  429.             contentPane.add(label1);
  430.             label1.setBounds(105, 5, 194, 35);
  431.  
  432.             //---- label2 ----
  433.             label2.setText("Tree to chop: ");
  434.             contentPane.add(label2);
  435.             label2.setBounds(new Rectangle(new Point(10, 45), label2.getPreferredSize()));
  436.  
  437.             //---- comboBox1 ----
  438.             comboBox1.setModel(new DefaultComboBoxModel<>(new String[] {
  439.                 "Tree",
  440.                 "Oak",
  441.                 "Willow",
  442.                 "Maple",
  443.                 "Yew",
  444.                 "Magic"
  445.             }));
  446.             contentPane.add(comboBox1);
  447.             comboBox1.setBounds(125, 40, 252, comboBox1.getPreferredSize().height);
  448.  
  449.             //---- startButton ----
  450.             startButton.setText("Start");
  451.             startButton.addActionListener(new ActionListener() {
  452.                 @Override
  453.                 public void actionPerformed(ActionEvent e) {
  454.                     startButtonActionPerformed(e);
  455.                 }
  456.             });
  457.             contentPane.add(startButton);
  458.             startButton.setBounds(165, 145, startButton.getPreferredSize().width, 25);
  459.  
  460.             //---- label3 ----
  461.             label3.setText("Pick up birdsnests: ");
  462.             contentPane.add(label3);
  463.             label3.setBounds(10, 70, 110, 15);
  464.             contentPane.add(checkBNest);
  465.             checkBNest.setBounds(new Rectangle(new Point(125, 65), checkBNest.getPreferredSize()));
  466.  
  467.             //---- label4 ----
  468.             label4.setText("Light instead of drop");
  469.             contentPane.add(label4);
  470.             label4.setBounds(10, 95, 110, 15);
  471.             contentPane.add(checkLight);
  472.             checkLight.setBounds(125, 90, 21, 21);
  473.  
  474.             //---- label5 ----
  475.             label5.setText("Antiban 1 in XX:");
  476.             contentPane.add(label5);
  477.             label5.setBounds(10, 120, 110, 15);
  478.  
  479.             //---- antibanVal ----
  480.             antibanVal.setText("25");
  481.             contentPane.add(antibanVal);
  482.             antibanVal.setBounds(130, 120, 240, antibanVal.getPreferredSize().height);
  483.  
  484.             { // compute preferred size
  485.                 Dimension preferredSize = new Dimension();
  486.                 for(int i = 0; i < contentPane.getComponentCount(); i++) {
  487.                     Rectangle bounds = contentPane.getComponent(i).getBounds();
  488.                     preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
  489.                     preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
  490.                 }
  491.                 Insets insets = contentPane.getInsets();
  492.                 preferredSize.width += insets.right;
  493.                 preferredSize.height += insets.bottom;
  494.                 contentPane.setMinimumSize(preferredSize);
  495.                 contentPane.setPreferredSize(preferredSize);
  496.             }
  497.             pack();
  498.             setLocationRelativeTo(getOwner());
  499.             // JFormDesigner - End of component initialization  //GEN-END:initComponents
  500.         }
  501.  
  502.         // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
  503.         // Generated using JFormDesigner Evaluation license - Henk Tenk
  504.         private JLabel label1;
  505.         private JLabel label2;
  506.         private JComboBox<String> comboBox1;
  507.         private JButton startButton;
  508.         private JLabel label3;
  509.         private JCheckBox checkBNest;
  510.         private JLabel label4;
  511.         private JCheckBox checkLight;
  512.         private JLabel label5;
  513.         private JTextField antibanVal;
  514.         // JFormDesigner - End of variables declaration  //GEN-END:variables
  515.     }
  516.  
  517.  
  518.  
  519. }
Advertisement
Add Comment
Please, Sign In to add comment