Advertisement
deww1

AleBuyer.java

May 8th, 2011
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.62 KB | None | 0 0
  1. import org.rsbot.script.*;
  2. import org.rsbot.script.Script;
  3. import org.rsbot.script.wrappers.*;
  4. import java.awt.*;
  5. import org.rsbot.event.events.MessageEvent;
  6. import org.rsbot.event.listeners.MessageListener;
  7. import org.rsbot.event.listeners.PaintListener;
  8.  
  9. import javax.imageio.ImageIO;
  10. import java.io.IOException;
  11. import java.net.URL;
  12. import java.awt.image.BufferedImage;
  13. import java.io.IOException;
  14. import java.net.MalformedURLException;
  15.  
  16. @ScriptManifest(authors = "Havefunpeeps, Deww1 ", keywords = "", name = "Beer Buyer", version = 1.02, description = "Buys Asgarnian Ales at West Falador")
  17.  
  18. public class AleBuyer extends Script implements MessageListener, PaintListener {
  19.  
  20.     int CoinsID = 995;
  21.     int AleID = 1905;
  22.     int NPCID = 736;
  23.     int AlePrice;
  24.         int BANK = 11758;
  25.         antiban antiban = new antiban();
  26.  
  27.  
  28.     BufferedImage normal = null;
  29.     BufferedImage clicked = null;
  30.     public String cursorU;//Cursor unclicked
  31.     public String cursorC;//Cursor clicked
  32.     private String status = "Setting up";
  33.     private String MouseSpeed = "Unknown";
  34.  
  35.     public long startTime = 0;
  36.     public long millis = 0;
  37.     public long hours = 0;
  38.     public long minutes = 0;
  39.     public long seconds = 0;
  40.  
  41.     private int aleCollected = 0;
  42.     private int AleCollected = 0;
  43.     public int OreCollected = 0;
  44.     private int banked;
  45.     private int aleHr = 0;
  46.  
  47.     public void messageReceived(MessageEvent e) {
  48.     String x = e.getMessage().toLowerCase();
  49.     if (x.contains("buy an")){
  50.      aleCollected++;
  51.      AleCollected++;
  52.     }
  53.   }
  54.     private void loadsBanked() {
  55.         if (AleCollected == 27) {
  56.             AleCollected = 0;
  57.             banked++;
  58.         }
  59.     }
  60.  
  61.     public final RSArea BarArea = new RSArea(new RSTile[] {
  62.         new RSTile(2953, 3365), new RSTile(2961, 3364),
  63.         new RSTile(2962, 3375), new RSTile(2953, 3376)
  64.     });
  65.     public final RSArea BankArea = new RSArea(new RSTile[] {
  66.         new RSTile(2940, 3362), new RSTile(2940, 3374),
  67.         new RSTile(2949, 3374), new RSTile(2949, 3361)
  68.     });
  69.     public final RSTile[] ToBar = {
  70.         new RSTile(2946, 3369), new RSTile(2946, 3371),
  71.         new RSTile(2946, 3372), new RSTile(2946, 3373),
  72.         new RSTile(2946, 3373), new RSTile(2947, 3373),
  73.         new RSTile(2948, 3374), new RSTile(2948, 3374),
  74.         new RSTile(2949, 3375), new RSTile(2949, 3376),
  75.         new RSTile(2949, 3377), new RSTile(2950, 3377),
  76.         new RSTile(2950, 3378), new RSTile(2951, 3378),
  77.         new RSTile(2952, 3379), new RSTile(2953, 3380),
  78.         new RSTile(2954, 3380), new RSTile(2955, 3380),
  79.         new RSTile(2956, 3380), new RSTile(2956, 3379),
  80.         new RSTile(2956, 3377), new RSTile(2957, 3375),
  81.         new RSTile(2957, 3373), new RSTile(2957, 3373),
  82.         new RSTile(2957, 3371), new RSTile(2957, 3371)
  83.     };
  84.     public final RSTile[] ToBank = {
  85.         new RSTile(2957, 3371), new RSTile(2956, 3372),
  86.         new RSTile(2956, 3374), new RSTile(2956, 3375),
  87.         new RSTile(2956, 3377), new RSTile(2957, 3378),
  88.         new RSTile(2956, 3380), new RSTile(2953, 3379),
  89.         new RSTile(2953, 3379), new RSTile(2953, 3378),
  90.         new RSTile(2951, 3376), new RSTile(2950, 3375),
  91.         new RSTile(2949, 3374), new RSTile(2948, 3373),
  92.         new RSTile(2945, 3369)
  93.     };
  94.  
  95.     @Override
  96.     public boolean onStart(){
  97.         startTime = System.currentTimeMillis();
  98.         AlePrice = grandExchange.lookup(AleID).getGuidePrice();
  99.         if(!inventory.contains(CoinsID)){
  100.             log("Please have coins");
  101.             onFinish();
  102.         }
  103.                 cursorU = "http://rkdewbots.site50.net/images/ironpickup/mouseReg.png";
  104.                 cursorC = "http://rkdewbots.site50.net/images/ironpickup/mouseClicked.png";
  105.                 try {
  106.                     final URL cursorURL = new URL(cursorU);
  107.                     final URL cursor80URL = new URL(cursorC);
  108.                     normal = ImageIO.read(cursorURL);
  109.                     clicked = ImageIO.read(cursor80URL);
  110.                 } catch (MalformedURLException e) {
  111.                     log("Unable to buffer cursor.");
  112.                 } catch (IOException e) {
  113.                     log("Unable to open cursor image.");
  114.                 }
  115.         return true;
  116.     }
  117.  
  118.     private boolean walkPath(RSTile[] path) {
  119.         if (calc.distanceTo(path[path.length - 1]) > 4) {
  120.             RSTile n = getNext(path);
  121.             if (n != null) {
  122.                 antiban.antiBanCamera();
  123.                 walking.walkTileMM(n.randomize(2, 2));
  124.                 if (random(1, 6) != 2) {
  125.                     mouse.moveRandomly(20);
  126.                 }
  127.             }
  128.         }
  129.         return false;
  130.     }
  131.  
  132.     private RSTile getNext(RSTile[] path) {
  133.         boolean found = false;
  134.         for (int a = 0; a < path.length && !found; a++) {
  135.             if (calc.tileOnMap(path[path.length - 1 - a])) {
  136.                 found = true;
  137.                 return path[path.length - 1 - a];
  138.             }
  139.         }
  140.         return null;
  141.     }
  142.  
  143.     public int loop() { //Not sure where you want to add antiban. Add it with antiBan() wherever you want.
  144.             mouseSpeed();
  145.             loadsBanked();
  146.         if(BankArea.contains(getMyPlayer().getLocation())) {
  147.             if(inventory.isFull()){
  148.                 bank();
  149.             }else{
  150.                             status = "walking to the bar";
  151.                 walkPath(ToBar);
  152.             }
  153.         }
  154.         if(BarArea.contains(getMyPlayer().getLocation())) {
  155.             if(inventory.isFull()) {
  156.                             status = "walking to the bank";
  157.                 walkPath(ToBank);
  158.             }else{
  159.                 BuyBeer();
  160.             }
  161.         }
  162.         if(inventory.getItem(CoinsID).getStackSize() < 3) {
  163.             log("Ran out of coins");
  164.             onFinish();
  165.         }
  166.         return random(300, 900);
  167.     }
  168.         @Override
  169.         public void onFinish() {
  170.             log("You have made "+(AlePrice-3)*aleCollected+" GP in total with "+aleCollected+" Ale collected!");
  171.             log("Thank you for using Beer Buyer!");
  172.         }
  173.  
  174.     public int bankOpen() {
  175.         if (BankArea.contains(getMyPlayer().getLocation()) && players.getMyPlayer().isIdle()) {
  176.             status = "Opening Bank.";
  177.             RSObject bankBooth = objects.getNearest(BANK);
  178.             if (random(1, 4) > 1) {
  179.                 bankBooth.doAction("Use-quickly");
  180.             } else {
  181.                 antiban.antiBan();
  182.             }
  183.         }
  184.         return random(800, 1300);
  185.     }
  186.  
  187.     public int depositBank() {
  188.         status = "Depositing ores";
  189.         bank.depositAllExcept(coinsID);
  190.         return random(300, 1100);
  191.     }
  192.  
  193.     public void bank() {
  194.         if (!bank.isOpen()) {
  195.             bankOpen();
  196.             antiban.antiBanMouse();
  197.         }
  198.         if (bank.isOpen()) {
  199.             depositBank();
  200.             antiban.antiBanMouse();
  201.             sleep(random(100, 500));
  202.         }
  203.     }
  204.     public void BuyBeer() {
  205.         RSNPC BeerPerson = npcs.getNearest(NPCID);
  206.         if(!interfaces.getComponent(241, 5).isValid() && !interfaces.getComponent(64, 5).isValid() && !interfaces.getComponent(242, 6).isValid() && !interfaces.getComponent(232, 2).isValid()) {
  207.             BeerPerson.doAction("Talk-to");
  208.                         status = "Buyin beers!";
  209.             sleep(500, 1000);
  210.         }else{
  211.             if(interfaces.getComponent(241, 5).isValid()) {
  212.                 interfaces.getComponent(241, 5).doClick();
  213.                 sleep(random(1300, 1500));
  214.             }
  215.             if(interfaces.getComponent(64, 5).isValid()) {
  216.                 interfaces.getComponent(64, 5).doClick();
  217.                 sleep(random(1300, 1500));
  218.             }
  219.             if(interfaces.getComponent(242, 6).isValid()) {
  220.                 interfaces.getComponent(242, 6).doClick();
  221.                 sleep(random(1300, 1500));
  222.             }
  223.             if(interfaces.getComponent(232, 2).isValid()) {
  224.                 interfaces.getComponent(232, 2).doClick();
  225.                 sleep(random(1300, 1500));
  226.             }
  227.         }
  228.     }
  229.             //START: Code generated using Enfilade's Easel
  230.     private final RenderingHints antialiasing = new RenderingHints(
  231.             RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  232.  
  233.     private Image getImage(String url) {
  234.         try {
  235.             return ImageIO.read(new URL(url));
  236.         } catch(IOException e) {
  237.             return null;
  238.         }
  239.     }
  240.     private void mouseSpeed() {
  241.             int rand = random(1, 5);
  242.             if (rand == 1) {
  243.                 mouse.setSpeed(random(4, 7));
  244.             }
  245.             if (rand == 2) {
  246.                 mouse.setSpeed(random(5, 10));
  247.             }
  248.             if (rand == 3) {
  249.                 mouse.setSpeed(random(2, 5));
  250.             }
  251.             if (rand == 4) {
  252.                 mouse.setSpeed(random(2, 10));
  253.             }
  254.             mouseSet();
  255.     }
  256.  
  257.     private void mouseSet() {
  258.         if (mouse.getSpeed() >= 1 && mouse.getSpeed() <= 3) {
  259.             MouseSpeed = "Extremely fast";
  260.         }
  261.         if (mouse.getSpeed() >= 4 && mouse.getSpeed() <= 6) {
  262.             MouseSpeed = "Regular";
  263.         }
  264.         if (mouse.getSpeed() >= 7 && mouse.getSpeed() <= 10) {
  265.             MouseSpeed = "Slow";
  266.         }
  267.     }
  268.  
  269.     private final Color color1 = new Color(0, 0, 0);
  270.     private final Color color2 = new Color(255, 255, 255);
  271.     private final Color color3 = new Color(0, 0, 0, 133);
  272.  
  273.     private final Font font1 = new Font("Times New Roman", 0, 11);
  274.     private final Font font2 = new Font("Times New Roman", 0, 13);
  275.  
  276.     private final Image img1 = getImage("http://rkdewbots.site50.net/scripts/alebuyer/AleBuyerPaint.png");
  277.  
  278.     public void onRepaint(Graphics g1) {
  279.         Graphics2D g = (Graphics2D)g1;
  280.         if (normal != null) {
  281.  
  282.             final int mouse_x = mouse.getLocation().x;
  283.             final int mouse_y = mouse.getLocation().y;
  284.             final int mouse_x2 = mouse.getPressLocation().x;
  285.             final int mouse_y2 = mouse.getPressLocation().y;
  286.             final long mpt = System.currentTimeMillis()
  287.                     - mouse.getPressTime();
  288.             if (mouse.getPressTime() == -1 || mpt >= 1000) {
  289.                 g.drawImage(normal, mouse_x - 8, mouse_y - 8, null); //this show the mouse when its not clicked
  290.             }
  291.             if (mpt < 1000) {
  292.                 g.drawImage(clicked, mouse_x2 - 8, mouse_y2 - 8, null); //this show the four squares where you clicked.
  293.                 g.drawImage(normal, mouse_x - 8, mouse_y - 8, null); //this show the mouse as normal when its/just clicked
  294.             }
  295.         }
  296.         g.setRenderingHints(antialiasing);
  297.         aleHr = (int) ((aleCollected) * 3600000D / (System.currentTimeMillis() - startTime));
  298.             millis = System.currentTimeMillis() - startTime;
  299.             hours = millis / (1000 * 60 * 60);
  300.             millis -= hours * (1000 * 60 * 60);
  301.             minutes = millis / (1000 * 60);
  302.             millis -= minutes * (1000 * 60);
  303.             seconds = millis / 1000;
  304.         g.drawImage(img1, -1, 308, null);
  305.         g.setFont(font1);
  306.         g.setColor(color1);
  307.         g.drawString(""+AleBuyer.class.getAnnotation(ScriptManifest.class).version(), 119, 453);
  308.         g.setColor(color2);
  309.         g.drawString("Run Time: " + hours + ":" + minutes + ":" + seconds, 360, 464);
  310.         g.setFont(font2);
  311.         g.setColor(color1);
  312.         g.drawString("Ale's Bought: "+aleCollected, 21, 390);
  313.         g.setColor(color2);
  314.         g.drawString("Ale Price: "+AlePrice, 354, 343);
  315.         g.setColor(color1);
  316.         g.drawString("Ale's Bought/hr: "+aleHr, 21, 423);
  317.         g.drawString("Mouse Speed: "+MouseSpeed, 348, 443);
  318.         g.drawString("Status: "+status, 186, 384);
  319.         g.drawString("Bank Trips: "+banked, 348, 420);
  320.         g.setColor(color3);
  321.         g.drawString("Paint by: Deww1", 247, 471);
  322.     }
  323.     //END: Code generated using Enfilade's Easel
  324.     public class antiban {
  325.         public void antiBanMouse() {
  326.         int randomNum1 = random(1, 50);
  327.         if (randomNum1 == 1 || randomNum1 == 2 || randomNum1 == 3) {
  328.             mouse.moveSlightly();
  329.             mouse.moveSlightly();
  330.         }
  331.         if (randomNum1 == 4 || randomNum1 == 5 || randomNum1 == 6) {
  332.             mouse.move(random(175, 325), random(75, 225));
  333.         }
  334.         if (randomNum1 == 7) {
  335.             mouse.moveRandomly(10, 150);
  336.         }
  337.         if (randomNum1 == 10 || randomNum1 == 11 || randomNum1 == 12
  338.                 || randomNum1 == 13) {
  339.  
  340.             mouse.moveSlightly();
  341.             mouse.moveRandomly(random(30, 39), random(40, 60));
  342.         }
  343.         if (randomNum1 == 14) {
  344.             mouse.moveOffScreen();
  345.         }
  346.         if (randomNum1 == 15) {
  347.             mouse.moveSlightly();
  348.             mouse.move(random(350, 700), random(50, 300));
  349.         }
  350.         if (randomNum1 == 16) {
  351.             mouse.moveSlightly();
  352.             mouse.moveSlightly();
  353.             mouse.moveSlightly();
  354.             mouse.moveSlightly();
  355.         }
  356.         if (randomNum1 > 16) {
  357.             int randomNum2 = random(1, 3);
  358.             if (randomNum2 == 1) {
  359.                 mouse.moveSlightly();
  360.             }
  361.             if (randomNum2 == 2) {
  362.                 mouse.moveRandomly(30, 50);
  363.             }
  364.             if (randomNum2 == 3) {
  365.                 mouse.moveSlightly();
  366.                 mouse.moveRandomly(30, 50);
  367.             }
  368.         }
  369.         sleep(random(100, 400));
  370.     }
  371.  
  372.     public void antiBanCamera() {
  373.         int randomNumber3 = random(1, 40);
  374.         if (randomNumber3 == 1 || randomNumber3 == 2 || randomNumber3 == 3) {
  375.             camera.setPitch(random(40, 68));
  376.         }
  377.         if (randomNumber3 == 4 || randomNumber3 == 5 || randomNumber3 == 6) {
  378.             camera.moveRandomly(random(800, 1200));
  379.         }
  380.         if (randomNumber3 == 7 || randomNumber3 == 8 || randomNumber3 == 9) {
  381.             camera.setAngle(random(10, 50));
  382.         }
  383.         if (randomNumber3 == 10 || randomNumber3 == 11) {
  384.             camera.setPitch(true);
  385.         }
  386.         if (randomNumber3 == 12 || randomNumber3 == 13) {
  387.             camera.setPitch(false);
  388.         }
  389.         if (randomNumber3 == 14) {
  390.             camera.moveRandomly(random(400, 800));
  391.         }
  392.         if (randomNumber3 == 15) {
  393.             camera.setAngle(random(5, 40));
  394.             sleep(random(200, 300));
  395.         }
  396.         if (randomNumber3 > 15 && randomNumber3 < 30) {
  397.             camera.setPitch(true);
  398.         }
  399.         if (randomNumber3 > 29) {
  400.             camera.moveRandomly(random(200, 800));
  401.         }
  402.     }
  403.  
  404.     public void antiBan(){
  405.         int randomNumber123 = random(1, 3);
  406.         if(randomNumber123 == 1) {
  407.             antiBanMouse();
  408.         }
  409.         if(randomNumber123 == 2) {
  410.             antiBanCamera();
  411.         }
  412.     }
  413.     }
  414. }//Paint :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement