Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
1,847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.95 KB | None | 0 0
  1. package main;
  2.  
  3. import org.osbot.rs07.script.Script;
  4. import org.osbot.rs07.script.ScriptManifest;
  5. import org.osbot.rs07.api.map.Position;
  6. import org.osbot.rs07.api.model.RS2Object;
  7. import org.osbot.rs07.api.ui.Message;
  8. import org.osbot.rs07.api.ui.Skill;
  9. import org.osbot.rs07.event.WalkingEvent;
  10. import org.osbot.rs07.utility.ConditionalSleep;
  11.  
  12. import javax.swing.DefaultComboBoxModel;
  13. import javax.swing.JButton;
  14. import javax.swing.JComboBox;
  15. import javax.swing.JFrame;
  16. import javax.swing.JPanel;
  17. import javax.swing.border.EmptyBorder;
  18.  
  19. import java.awt.*;
  20. import java.awt.Color;
  21. import java.awt.EventQueue;
  22. import java.awt.event.ActionEvent;
  23. import java.awt.event.ActionListener;
  24.  
  25. @ScriptManifest(name = "ChopDropBurn", author = "Noidlox", version = 1.0, info = "Chops Logs & Drops OR Burns EM!", logo = "http://i.imgur.com/djBLoUs.png")
  26. public class ChopDropBurn extends Script {  
  27.            
  28.     private Position playerPosition;
  29.    
  30.     private long startTime, testTime;
  31.    
  32.     private boolean inputAccepted = false, shouldChop = true;
  33.    
  34.     private String selectedTree, selectedLog, selectedAction = "Nulling";
  35.    
  36.     private String[] groundObjects = {"Fire", "Daisies", "Fern", "Stones", "Thistle"};
  37.    
  38.     private int logsChopped = 0, firesMade = 0, startingLevelWC, startingLevelFM, pseudoAntiBanCounter;
  39.    
  40.     private String[] typesOfAxes = {"Bronze axe", "Iron axe", "Steel axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe"};
  41.    
  42.     private String[] inventoryList = {"Tinderbox", "Bronze axe", "Iron axe", "Steel axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe"};
  43.    
  44.     private String[] typesOfLogs = {"Logs", "Oak logs", "Willow logs", "Maple logs", "Mahogany logs", "Yew logs", "Magic logs"};
  45.        
  46.     private enum State { CHOP, DROP, BURN, EXIT };
  47.        
  48.         private State getState() {
  49.                                    
  50.             if (inventory.isFull() && (!(inventory.contains("Tinderbox")))) return State.DROP;
  51.            
  52.             if (inventory.contains(typesOfAxes) && shouldChop) return State.CHOP;
  53.                                
  54.             if (inventory.contains(typesOfLogs) && inventory.contains("Tinderbox")) return State.BURN;
  55.                        
  56.             return State.EXIT;
  57.         }
  58.        
  59.     public void chopLogs() throws InterruptedException {
  60.         log("Chopping " + selectedTree + " Trees");
  61.         selectedAction = "Cutting";
  62.         if (!myPlayer().isAnimating()) {
  63.             RS2Object tree = objects.closest(selectedTree);
  64.             if (tree != null && tree.interact("Chop down")) {
  65.                     new ConditionalSleep(5000) {
  66.                           @Override
  67.                           public boolean condition() { return (myPlayer().isAnimating()); }
  68.                     }.sleep();
  69.                 }
  70.         } else if (myPlayer().isAnimating() && (!selectedTree.equalsIgnoreCase("Tree")) && mouse.isOnScreen()) { mouse.moveOutsideScreen(); }
  71.        
  72.         if (inventory.isFull()) { shouldChop = false; }
  73.     }
  74.    
  75.     public void dropLogs() throws InterruptedException {
  76.         log("Dropping " + selectedTree + " Logs");
  77.         selectedAction = "Dropping";
  78.         if (inventory.dropAll(typesOfLogs)) {
  79.             shouldChop = true;
  80.             new ConditionalSleep(1000) {
  81.                   @Override
  82.                   public boolean condition() { return !(inventory.isFull()); }
  83.             }.sleep();
  84.         }
  85.     }
  86.        
  87.     public void burnLogs() throws InterruptedException {
  88.         log("Burning " + selectedTree + " Logs");
  89.         selectedAction = "Burning";
  90.        
  91.         Position pol = myPlayer().getPosition().translate(14, -2);
  92.         for (int i = 1; i <= 14; i++) {
  93.             if (map.canReach(pol) && map.realDistance(pol) > 0 && map.realDistance(pol) < 16) {
  94.                 WalkingEvent newPosition = new WalkingEvent(new Position(pol));
  95.                 execute(newPosition);
  96.                 break;
  97.             } else {
  98.                 pol = myPlayer().getPosition().translate(14 - i, 0);
  99.                 if (i == 14 && !map.canReach(pol)) {
  100.                     pol = myPlayer().getPosition().translate(14 - i, 1);
  101.                     i = 0;
  102.                 }
  103.             }
  104.         }
  105.    
  106.         while (inventory.contains(typesOfLogs)) {
  107.             log("looop");
  108.             RS2Object groundCollision = objects.closest(groundObjects);
  109.             while (groundCollision != null && groundCollision.getPosition().equals(myPlayer().getPosition())) {
  110.                 log("go elsewhere");
  111.                 sleep(2000);
  112.                 if (inventory.isItemSelected()) { inventory.deselectItem(); }
  113.                
  114.                 // TODO: CHECK SURROUNDING AREA
  115.                
  116.                 if(!(myPlayer().isAnimating()) && inventory.interact("Use", "Tinderbox")) {
  117.                     if (inventory.isItemSelected() && inventory.interactWithNameThatContains("Use", "logs")) {
  118.                         new ConditionalSleep(3000) {
  119.                             @Override
  120.                             public boolean condition() {
  121.                                 return (myPlayer().isAnimating());
  122.                              }
  123.                         }.sleep();
  124.                     }
  125.                 }
  126.             }
  127.         }      
  128.        
  129.         if (!(inventory.contains("Logs"))) {
  130.             shouldChop = true;
  131.             walkToStartingPosition();
  132.         }
  133.     }
  134.    
  135.     public void walkToStartingPosition() {
  136.         selectedAction = "Walking";
  137.         if (!(myPlayer().getPosition().equals(playerPosition))) {
  138.             WalkingEvent newPosition = new WalkingEvent(new Position(playerPosition));
  139.             execute(newPosition);
  140.         }  
  141.     }
  142.                
  143.     @Override
  144.     public void onStart() {
  145.        
  146.         log("Starting Script...");
  147.         Menu gui = new Menu();
  148.         gui.setVisible(true);
  149.        
  150.         getExperienceTracker().start(Skill.WOODCUTTING);
  151.         startingLevelWC = getSkills().getStatic(Skill.WOODCUTTING);
  152.        
  153.         getExperienceTracker().start(Skill.FIREMAKING);
  154.         startingLevelFM = getSkills().getStatic(Skill.FIREMAKING);
  155.        
  156.         playerPosition = myPlayer().getPosition();
  157.         startTime = System.currentTimeMillis();    
  158.     }
  159.    
  160.     @Override
  161.     public int onLoop() throws InterruptedException {
  162.        
  163.         if(inputAccepted) {
  164.            
  165.             if (myPlayer().isUnderAttack()) { walkToStartingPosition(); }
  166.                        
  167.             switch (getState()) {
  168.            
  169.                 case CHOP:
  170.                     chopLogs();
  171.                     break;
  172.                
  173.                 case BURN:
  174.                     burnLogs();
  175.                     break;
  176.                
  177.                 case DROP:
  178.                     dropLogs();
  179.                     break;
  180.                    
  181.                 case EXIT:
  182.                     log("Missing some items, exiting script");
  183.                     stop();
  184.                     break;
  185.             }
  186.         }
  187.        
  188.         return random(300, 3000);
  189.     }
  190.    
  191.     @Override
  192.     public void onExit() { log("Thank You For Using My Script. Please Report All Bugs To Noidlox On OSBot"); }
  193.  
  194.     @Override
  195.     public void onMessage(Message m) {
  196.        
  197.         if (inputAccepted) {
  198.             if (m.getMessage().contains("You get some")) logsChopped++;
  199.             if (m.getMessage().contains("The fire catches")) firesMade++;
  200.             //if (m.getMessage().contains("You can't light")) movePosition();
  201.             if (m.getMessage().contains("You need a Firemaking level of")) stop();
  202.             if (m.getMessage().contains("You do not have an axe which you have")) stop();
  203.             if (m.getMessage().contains("I can't reach")) walkToStartingPosition();
  204.         }
  205.     }
  206.    
  207.     @Override
  208.     public void onPaint(Graphics2D g) {
  209.  
  210.         if(inputAccepted) {
  211.            
  212.             String currentTime = formatTime(System.currentTimeMillis() - startTime);
  213.             testTime = (System.currentTimeMillis() - startTime) / 60000;
  214.             g.setColor(Color.black);
  215.             g.setColor(new Color(0, 0, 0, 200));
  216.             g.fillRect(7, 345, 506, 130);
  217.            
  218.             Font font = new Font("Times New Roman", Font.BOLD, 22);
  219.             g.setFont(font);
  220.            
  221.             g.setColor(Color.white);
  222.             g.drawString("Chop, Drop, & Burn | By Noidlox | v" + getVersion(), 17, 374);
  223.            
  224.             font = new Font("Arial", Font.PLAIN, 12);
  225.             g.setFont(font);
  226.            
  227.             g.drawString("Time Ran: " + currentTime, 20, 398);
  228.             g.drawString("Cutting " + selectedTree + " Trees", 140, 398);
  229.             g.drawString("We Are " + selectedAction, 280, 398);
  230.             //g.drawString("pAB Actions: " + pseudoAntiBanCounter, 380, 398);
  231.            
  232.             g.drawString("Logs Chopped: " + logsChopped, 20, 418);
  233.             g.drawString("W.C. XP Gained: " + getExperienceTracker().getGainedXP(Skill.WOODCUTTING), 140, 418);
  234.             g.drawString("Per Hour: " + getExperienceTracker().getGainedXPPerHour(Skill.WOODCUTTING) , 280, 418);
  235.             g.drawString("Started At: " + startingLevelWC + " (" + getExperienceTracker().getGainedLevels(Skill.WOODCUTTING) + ")"
  236.                     , 380, 418);
  237.  
  238.             g.drawString("Fires Made: " + firesMade, 20, 438);
  239.             g.drawString("F.M. XP Gained: " + getExperienceTracker().getGainedXP(Skill.FIREMAKING), 140, 438);
  240.             g.drawString("Per Hour: " + getExperienceTracker().getGainedXPPerHour(Skill.FIREMAKING) , 280, 438);
  241.             g.drawString("Started At: " + startingLevelFM + " (" + getExperienceTracker().getGainedLevels(Skill.FIREMAKING) + ")"
  242.                     , 380, 438);
  243.            
  244.             g.drawString("Please Report All Bugs To Me On OSBot | Feel Free To PM Me | Cheers, Noidlox", 20, 471);
  245.         }
  246.     }
  247.    
  248.     public final String formatTime(final long ms) {
  249.         long s = ms / 1000, m = s / 60, h = m / 60;
  250.         s %= 60; m %= 60; h %= 24;
  251.         return String.format("%02d:%02d:%02d", h, m, s);
  252.     }
  253.    
  254.     public class Menu extends JFrame {
  255.          
  256.         private JPanel contentPane;
  257.  
  258.         public void main(String[] args) {
  259.             EventQueue.invokeLater(new Runnable() {
  260.                 public void run() {
  261.                     try {
  262.                         Menu frame = new Menu();
  263.                         frame.setVisible(true);
  264.                     } catch (Exception e) {
  265.                         e.printStackTrace();
  266.                     }
  267.                 }
  268.             });
  269.         }
  270.  
  271.         public Menu() {
  272.            
  273.             setResizable(false);
  274.             setAlwaysOnTop(true);
  275.             setTitle("G.U.I");
  276.             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  277.             setBounds(100, 100, 170, 140);
  278.             contentPane = new JPanel();
  279.             contentPane.setForeground(Color.WHITE);
  280.             contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  281.             setContentPane(contentPane);
  282.             contentPane.setLayout(null);
  283.            
  284.             JComboBox cmbSelectTree = new JComboBox();
  285.             cmbSelectTree.setModel(new DefaultComboBoxModel(new String[] {"Tree", "Oak", "Willow", "Maple", "Mahogany", "Yew", "Magic"}));
  286.             cmbSelectTree.setMaximumRowCount(7);
  287.             cmbSelectTree.setBounds(20, 25, 130, 27);
  288.             contentPane.add(cmbSelectTree);
  289.            
  290.             JButton btnStart = new JButton("Start");
  291.             btnStart.addActionListener(new ActionListener() {
  292.                
  293.                 public void actionPerformed(ActionEvent e) {
  294.                     selectedTree = (String)cmbSelectTree.getSelectedItem();
  295.                                      
  296.                     if (selectedTree.equalsIgnoreCase("Tree")) { selectedLog = "Logs"; }
  297.                     else { selectedLog = selectedTree + "logs"; }
  298.                                        
  299.                     inputAccepted = true;
  300.                     setVisible(false);
  301.                    
  302.                 }
  303.             });
  304.             btnStart.setBounds(20, 65, 130, 29);
  305.             contentPane.add(btnStart);
  306.         }
  307.     }
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement