NissanNut

LazyGulls v1.0

Jun 7th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.55 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.Point;
  7. import java.awt.Rectangle;
  8. import java.io.IOException;
  9. import java.net.URL;
  10. import java.util.LinkedList;
  11. import java.util.List;
  12.  
  13. import javax.imageio.ImageIO;
  14.  
  15. import org.nut.api.util.Timer;
  16. import org.cb.api.Script;
  17. import org.cb.api.ScriptDetails;
  18.  
  19. @ScriptDetails(
  20.         author = "Nissan Nut",
  21.         description = "A basic seagull killer",
  22.         name = "LazyGulls",
  23.         version = 1.0
  24.         )
  25.  
  26. public class LazyGulls extends Script {
  27.    
  28.     private final Color c0 = new Color(0, 38, 0);
  29.     private final Color c1 = new Color(160, 160, 153);
  30.     private final Color c2 = new Color(224, 224, 214);
  31.    
  32.     private List <Point> C1;
  33.     private List <Point> C2;
  34.     private List <Point> COMBAT = new LinkedList<Point> ();
  35.    
  36.     private Point Gull = null;
  37.    
  38.     private Rectangle NPC = null;
  39.     private final Rectangle VIEW = new Rectangle(4, 5, 511, 332);
  40.     private final Rectangle HPBAR = new Rectangle(231, 134, 59, 17);
  41.    
  42.     private Timer Wait = new Timer(4000);
  43.    
  44.     private int clicks = 0;
  45.     public long millis = 0, hours = 0, minutes = 0, seconds = 0, startTime = 0;
  46.    
  47.     private final Image img1 = getImage("http://www.upload.ee/image/2407603/Untitled.png");
  48.    
  49.     @Override
  50.     public long loop() throws InterruptedException {
  51.         //theMouse.setSpeed(random(4, 7));
  52.        
  53.         if (Gull != null && !inCombat() && Wait.getValue() < 0){
  54.             theMouse.click(Gull, theMouse.LEFT_CLICK);
  55.             clicks++;
  56.             Wait.endIn(random(4000, 5000));
  57.         }
  58.  
  59.         C1 = findColourArray(VIEW, c1, 1);
  60.         C2 = findColourArray(VIEW, c2, 1);
  61.         COMBAT = findColourArray(HPBAR, c0, 1);
  62.        
  63.         Gull = null;
  64.         if (C1 != null && C2 != null){
  65.             for (Point p1 : C1){
  66.                 NPC = new Rectangle(p1.x-5, p1.y-5, 10, 10);
  67.                 for (Point p2 : C2){
  68.                     if (NPC.contains(p2)){
  69.                         Gull = new Point(p2.x + random(-1, 1), p2.y + random(-1, 1));
  70.                         return 5;
  71.                     }
  72.                 }
  73.             }
  74.         }
  75.    
  76.         return 15;
  77.     }
  78.  
  79.     private boolean inCombat() {
  80.         if (COMBAT .isEmpty()){
  81.             return false;
  82.         }
  83.         return true;
  84.     }
  85.  
  86.     @Override
  87.     public void onEnd() throws InterruptedException {
  88.         // TODO Auto-generated method stub
  89.  
  90.     }
  91.  
  92.     @Override
  93.     public void onStart() throws InterruptedException {
  94.         startTime = System.currentTimeMillis();
  95.     }
  96.    
  97.     @Override
  98.     public void onRepaint(Graphics g1){
  99.         Graphics2D g = (Graphics2D) g1;
  100.         millis = System.currentTimeMillis() - startTime;
  101.         hours = millis / (1000 * 60 * 60);
  102.         millis -= hours * (1000 * 60 * 60);
  103.         minutes = millis / (1000 * 60);
  104.         millis -= minutes * (1000 * 60);
  105.         seconds = millis / 1000;
  106.        
  107.         if (C1 != null){
  108.             g.setColor(Color.BLUE);
  109.             for (Point p : C1){
  110.                 g.drawLine(p.x, p.y - 2, p.x, p.y + 2);
  111.                 g.drawLine(p.x - 2, p.y, p.x + 2, p.y);
  112.             }
  113.         }
  114.         if (C2 != null){
  115.             g.setColor(Color.RED);
  116.             for (Point p : C2){
  117.                 g.drawLine(p.x, p.y - 2, p.x, p.y + 2);
  118.                 g.drawLine(p.x - 2, p.y, p.x + 2, p.y);
  119.             }
  120.         }
  121.        
  122.         if (Gull != null){
  123.             g.setColor(Color.GREEN);
  124.             g.draw(new Rectangle(Gull.x-5, Gull.y-5, 10, 10));
  125.             g.drawString("Target", Gull.x-15, Gull.y-8);
  126.            
  127.         }
  128.        
  129.         g.drawImage(img1, 307, 341, null);
  130.         g.setFont(new Font("Calibri", 0, 12));
  131.         g.setColor(Color.WHITE);
  132.         g.drawString("Runtime: " + hours + ":" + minutes + ":" + seconds, 333, 400);
  133.         g.drawString("Clicks: " + clicks, 333, 415);
  134.        
  135.     }
  136.    
  137.      private Image getImage(String url) {
  138.             try {
  139.                 return ImageIO.read(new URL(url));
  140.             } catch (IOException e) {
  141.                 return null;
  142.             }
  143.         }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment