Advertisement
illpastethat

CrossbowBuyer.java Commented

Jun 5th, 2011
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.79 KB | None | 0 0
  1.  import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Image;
  6. import java.awt.RenderingHints;
  7. import java.io.IOException;
  8. import java.net.URL;
  9. import java.text.DecimalFormat;
  10. import java.text.DecimalFormatSymbols;
  11.  
  12. import javax.imageio.ImageIO;
  13.  
  14. import org.rsbot.event.events.ServerMessageEvent;
  15. import org.rsbot.event.listeners.PaintListener;
  16. import org.rsbot.event.listeners.ServerMessageListener;
  17. import org.rsbot.script.Script;
  18. import org.rsbot.script.ScriptManifest;
  19. import org.rsbot.script.util.Timer;
  20. import org.rsbot.script.wrappers.RSArea;
  21. import org.rsbot.script.wrappers.RSComponent;
  22. import org.rsbot.script.wrappers.RSNPC;
  23. import org.rsbot.script.wrappers.RSObject;
  24. import org.rsbot.script.wrappers.RSTile;
  25.  
  26.  
  27.  
  28. @ScriptManifest( authors = {"ShadowMoose"}, keywords = "Money", version = 0.2, name = "CrossBow Buyer", description =
  29.                     "This script is amazing at getting you Crossbows!")
  30.  
  31.  
  32.  
  33. public class CrossbowBuyer extends Script implements PaintListener, ServerMessageListener
  34. {
  35.    
  36.     //OBJECTS
  37.     int door = 1533;// -- door("Open" if On screen);
  38.  
  39.     //ITEMS
  40.     int Bow = 10156;// -- Crossbows!
  41.     int gp = 995;// -- GP!
  42.     int bought = 0;
  43.     Boolean ANTIBAN = true;
  44.     int price = 1;
  45.  
  46.     //NPCs
  47.     int LeonID = 5111;// -- Leon("Talk-to L");
  48.    
  49.     //Tiles
  50.     RSArea Shop = new RSArea(new RSTile(2564, 3079), new RSTile(2570, 3085));
  51.     RSTile Bank = new RSTile(2612, 3092);
  52.     RSTile[] toBank = {new RSTile(2563, 3082), new RSTile(2574, 3089), new RSTile(2584, 3097), new RSTile(2598, 3098), new RSTile(2603, 3094), new RSTile(2611, 3093)};
  53.  
  54.     //Paint:
  55.     private final Color color1 = new Color(255, 51, 51);
  56.  
  57.     private final Font font1 = new Font("Arial", 0, 15);
  58.     private final Font font2 = new Font("Arial", 0, 12);
  59.     private final Font font3 = new Font("Arial", 0, 10);
  60.  
  61.     private final Image img1 = getImage("http://www.zybez.net/img/idbimg/crossbow_hunter.png");
  62.     private final Image img2 = getImage("http://www.runescape.com/img/main/kbase/items/misc/coins.gif");
  63.     Timer time = new Timer(0);
  64.    
  65.    
  66.     public boolean onStart(){
  67.         mouse.setSpeed(random(1, 3));
  68.         price = grandExchange.lookup(Bow).getGuidePrice();
  69.         new Thread() {
  70.             public void run() {
  71.                 log("AntiBan started!");
  72.                 while(ANTIBAN) {
  73.                     // Do thread functions here.
  74.                     //log.severe("AntiBan: Rotating camera.");
  75.                     if(game.isLoggedIn()){camera.setAngle(random(10, 360));}
  76.                     mouse.setSpeed(random(1, 3));
  77.                     // Wait for 10/100 of a second
  78.                     try {Thread.sleep((random(100, 23*1000)));} catch (Exception e) {log.severe("Error Waiting!");}
  79.                 }
  80.             }
  81.         }.start();
  82.         return true;
  83.     }
  84.    
  85.     public void shutDown(){//logs you out & stops the script.
  86.         ANTIBAN = false;
  87.         bought++;
  88.         while(bank.isOpen()){bank.close(); sleep(random(1000, 2000));}
  89.        
  90.         while (!game.isOnLogoutTab() && !getMyPlayer().isInCombat()) {
  91.             interfaces.get(548).getComponent(178).doClick();
  92.             sleep(random(1000, 2000));
  93.         }
  94.        
  95.         while(game.isLoggedIn() && game.isOnLogoutTab() && !getMyPlayer().isInCombat()){
  96.             interfaces.get(182).getComponent(15).doClick();
  97.             sleep(random(1000, 2000));
  98.         }
  99.        
  100.         log.severe("Total bought:"+bought);
  101.         stopScript();
  102.     }
  103.    
  104.      private Image getImage(String url) {
  105.           try {
  106.               return ImageIO.read(new URL(url));
  107.           } catch(IOException e) {
  108.               return null;
  109.           }
  110.       }
  111.        
  112.     @Override
  113.     public int loop() {
  114.         RSObject openMe = objects.getNearest(door);
  115.         if(inventory.getCount(true, gp) < 1300){shutDown();}
  116.         if(Shop.contains(getMyPlayer().getLocation()) && inventory.getCount(true, gp) >= 1300 && !inventory.isFull()){
  117.             //time to buy crossbows.
  118.             RSNPC leon = npcs.getNearest(LeonID);
  119.             if(leon != null && leon.isOnScreen()){
  120.                 if(doChat()){return 100;}//return if we're already chatting.
  121.                 leon.doAction("Talk-to L");
  122.                 int i=0;
  123.                 while(interfaces.getComponent(232, 3) == null || interfaces.getComponent(232, 3) != null && !interfaces.getComponent(232, 3).getText().contains("ross")){
  124.                     i++;
  125.                     if(i>50){return 10;}
  126.                     sleep(random(100, 150));
  127.                     if(interfaces.getComponent(230, 3) != null && interfaces.getComponent(230, 3).getText().contains("Can I")){return 10;}
  128.                 }
  129.                 return 100;
  130.             }
  131.         }
  132.        
  133.         if(inventory.isFull()){
  134.             if(openMe != null && openMe.isOnScreen()){//Open the door if it's closed.
  135.                 openMe.doAction("Open");
  136.                 return random(1000, 3000);
  137.             }
  138.             if(calc.distanceTo(Bank) > 4){walking.walkPathMM(walking.randomizePath(toBank,2,2)); return random(2700, 3500);}
  139.             try{
  140.                 bank.open();
  141.                 if(bank.isOpen()){
  142.                     bought++;
  143.                     bank.depositAllExcept(gp);
  144.                     bank.close();
  145.                 }
  146.             }catch(Exception e){log.severe("Error opening bank!");}
  147.         }
  148.        
  149.         if(!Shop.contains(getMyPlayer().getLocation()) && !inventory.isFull() && inventory.getCount(true, gp) >= 1300){
  150.             if(openMe != null && openMe.isOnScreen()){//Open the door if it's closed.
  151.                 openMe.doAction("Open");
  152.                 return random(1000, 3000);
  153.             }
  154.             walking.walkPathMM(walking.randomizePath(walking.reversePath(toBank),2,2));
  155.             if(calc.tileOnMap(Shop.getCentralTile())){walking.walkTileMM(walking.randomizeTile(Shop.getCentralTile(), 2, 2));}
  156.             return random(2500, 3500);
  157.         }
  158.        
  159.        
  160.         return random(2500, 3700);
  161.     }
  162.  
  163.     public boolean doChat(){
  164.         RSComponent cont = interfaces.getComponent(64, 5);
  165.         RSComponent Lcont = interfaces.getComponent(242, 6);
  166.         RSComponent start = interfaces.getComponent(232, 3);
  167.         RSComponent start2 = interfaces.getComponent(230, 3);
  168.         RSComponent offer = interfaces.getComponent(241, 5);
  169.         RSComponent accept = interfaces.getComponent(230, 2);
  170.         RSComponent done = interfaces.getComponent(211,3);
  171.         if(cont != null && cont.getText().contains("ontinue")){click(cont); pause(cont,"ontinue"); return true;}
  172.         if(Lcont != null && Lcont.getText().contains("ontinue")){click(Lcont); pause(Lcont,"ontinue"); return true;}
  173.         if(start != null && start.getText().contains("ross")){click(start); pause(start,"ross"); return true;}
  174.         if(start2 != null && start2.getText().contains("ross")){click(start2); pause(start2,"ross"); return true;}
  175.         if(offer != null && offer.getText().contains("ontinue")){click(offer); pause(offer,"ontinue"); return true;}
  176.         if(accept != null && accept.getText().contains("Ok,")){click(accept); pause(accept,"Ok,"); return true;}
  177.         if(done != null && done.getText().contains("ontinue")){bought++; return false;}
  178.         return false;
  179.     }
  180.    
  181.     public void pause(RSComponent component, String stringToCheck){//waits for an interface to be gone.
  182.         String s = stringToCheck;
  183.         RSComponent c = component;
  184.         for(int i=0; i<=40 && c.getText().contains(s); i++){
  185.             sleep(random(100, 150));
  186.             RSComponent cc = interfaces.getComponent(242, 4);
  187.             if(cc != null && cc.getText().contains("Of course,")){i = 41; break;}
  188.         }
  189.        
  190.     }
  191.    
  192.     public void click(RSComponent c){//clicks the interface... Guaranteed.
  193.         if(c.isValid() && !c.doClick()){
  194.             mouse.click(true);
  195.         }
  196.     }
  197.    
  198.     public String insertCommas(long num) {
  199.         DecimalFormat df = new DecimalFormat();
  200.         DecimalFormatSymbols dfs = new DecimalFormatSymbols();
  201.         dfs.setGroupingSeparator(',');
  202.  
  203.         df.setDecimalFormatSymbols(dfs);
  204.         return((String)df.format((int)num));
  205.     }
  206.    
  207.     @Override
  208.     public void onRepaint(Graphics g) {
  209.         ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  210.         long seconds, minutes, hours, millis;
  211.         millis = time.getElapsed();
  212.         hours = millis / (1000 * 60 * 60);
  213.         millis -= hours * (1000 * 60 * 60);
  214.         minutes = millis / (1000 * 60);
  215.         millis -= minutes * (1000 * 60);
  216.         seconds = millis / 1000;
  217.  
  218.         g.drawImage(img1, 550, 208, null);
  219.         g.drawImage(img1, 686, 205, null);
  220.         g.drawImage(img1, 548, 304, null);
  221.         g.drawImage(img1, 688, 305, null);
  222.         g.drawImage(img1, 686, 413, null);
  223.         g.drawImage(img1, 550, 414, null);
  224.         g.drawImage(img2, 627, 433, null);
  225.         g.drawImage(img2, 700, 371, null);
  226.         g.drawImage(img2, 561, 374, null);
  227.         g.drawImage(img2, 556, 268, null);
  228.         g.drawImage(img2, 701, 268, null);
  229.         g.drawImage(img2, 628, 216, null);
  230.         g.setFont(font1);
  231.         g.setColor(color1);
  232.         g.drawString("CrossbowBuyer", 590, 264);
  233.         g.setFont(font2);
  234.         g.drawString("By: ShadowMoose", 590, 288);
  235.         g.setFont(font3);
  236.         g.drawString("Crossbows Bought: "+insertCommas(bought), 597, 326);
  237.         //if(millis > 0){g.drawString("Crossbows p/h: "+(((bought)/millis)*60*60), 596, 343);}
  238.         g.drawString("Profit: "+insertCommas((bought*price)-(bought*1300)), 598, 382);
  239.         //g.drawString("Profit Per Hour: ", 597, 402);
  240.         g.drawString("Run Time: "+time.toElapsedString(), 598, 430);
  241.     }
  242.  
  243.     @Override
  244.     public void serverMessageRecieved(ServerMessageEvent e) {
  245.         // TODO Auto-generated method stub
  246.        
  247.     }
  248.    
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement