Guest User

MegaKaramja 1.0

a guest
May 15th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.61 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.MouseEvent;
  9. import java.awt.event.MouseListener;
  10. import java.awt.event.MouseMotionListener;
  11. import java.awt.image.BufferedImage;
  12. import java.io.IOException;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.text.DecimalFormat;
  16. import java.util.LinkedList;
  17.  
  18. import javax.imageio.ImageIO;
  19. import javax.swing.JButton;
  20. import javax.swing.JComboBox;
  21. import javax.swing.JFrame;
  22. import javax.swing.JLabel;
  23.  
  24. import org.runedream.q;
  25. import org.runedream.api.Script;
  26. import org.runedream.api.ScriptManifest;
  27. import org.runedream.api.methods.Calculations;
  28. import org.runedream.api.methods.Camera;
  29. import org.runedream.api.methods.Game;
  30. import org.runedream.api.methods.ImageUtil;
  31. import org.runedream.api.methods.Inventory;
  32. import org.runedream.api.methods.Mouse;
  33. import org.runedream.api.methods.OCR;
  34. import org.runedream.api.methods.Skills;
  35. import org.runedream.api.methods.Tabs;
  36. import org.runedream.api.util.Random;
  37. import org.runedream.api.util.SkillTracker;
  38. import org.runedream.api.util.Time;
  39. import org.runedream.api.wrappers.Entity;
  40. import org.runedream.api.wrappers.Grid;
  41. import org.runedream.api.wrappers.Menu;
  42. import org.runedream.api.wrappers.Tab;
  43.  
  44. @ScriptManifest(authors = { "MegaAlgos" }, name = "MegaKaramja", version = 1.0, description = "Fishes for lobsters to stiles in Karamaja", keywords = { "Fishing" }, language = {
  45.         true, true, true, true })
  46. public class MegaKaramja extends Script implements MouseListener,
  47.         MouseMotionListener {
  48.  
  49.     private Color[] cagingColor = { new Color(161, 164, 168),
  50.             new Color(140, 150, 170), new Color(136, 146, 167),
  51.             new Color(154, 159, 166), new Color(151, 158, 173),
  52.             new Color(155, 160, 168), new Color(156, 161, 170),
  53.             new Color(128, 133, 139), };
  54.     private Color[] stiles = { new Color(56, 53, 53) };
  55.     private Color lobster = new Color(99, 56, 30);
  56.     Color[] rColor = { new Color(63, 60, 60), new Color(47, 45, 45),
  57.             new Color(58, 55, 55) };
  58.     boolean fishing, setCamera, walkingToStiles, exchange, walkToLobs,
  59.             triedWalking = false, offScreen, pickedColor, getRect, atStiles,
  60.             getStart, newLVL, start, lobsters;
  61.     Point nearest = null, headPoint = new Point(262, 152);
  62.     int counter = 1, times, rNumber, fishCount, fishCountHour, lastInvCount;
  63.     double dist = -1;
  64.     Point CHECK = new Point(258, 175), pointCheck;
  65.     Point[] toStiles = { new Point(630, 50), new Point(571, 109),
  66.             new Point(571, 123), new Point(571, 123), new Point(571, 115),
  67.             new Point(571, 123), new Point(605, 110), new Point(605, 110),
  68.             new Point(605, 110), new Point(605, 110) };
  69.     Point[] toLob = { new Point(690, 56), new Point(690, 56),
  70.             new Point(690, 56), new Point(691, 62), new Point(679, 75),
  71.             new Point(645, 50) };
  72.     LinkedList<Point> cagingSpots, stilesPoints;
  73.     Point spot, stilesPoint;
  74.     Entity stileEntity = new Entity(stiles);
  75.     Entity fishingEntity = new Entity(cagingColor);
  76.  
  77.     private Color[] fC = { new Color(116, 119, 113), new Color(86, 87, 93),
  78.             new Color(92, 91, 97), new Color(88, 90, 95) };
  79.     BufferedImage STILES = null;
  80.     Rectangle SRECT = null;
  81.     Color[] SCOLOR, headColorArray;
  82.     Color headColor;
  83.     BufferedImage paintPic = null;
  84.     SkillTracker sTrack = new SkillTracker(Skills.Skill.FISHING);
  85.     int startXP, curXP, curLVL, startLVL, getNextLVLXP, XPTill, TTNL;
  86.     double hourXP;
  87.     long startTime;
  88.     String status = "Starting up";
  89.     Rectangle headRect = new Rectangle(262, 152, 2, 2);
  90.     Rectangle headRect2 = new Rectangle(257, 155, 5, 6);
  91.  
  92.     // Check fishing variables
  93.     Color[] CFC = { new Color(116, 123, 137), new Color(105, 109, 119),
  94.             new Color(99, 103, 111), new Color(120, 128, 147) };
  95.     Color CFH = new Color(87, 63, 12);
  96.     Rectangle[] CFR;
  97.     int CFAIL = 0;
  98.  
  99.     @Override
  100.     public boolean onStart() {
  101.         log("Lobsters!!! script started");
  102.         java.awt.EventQueue.invokeLater(new Runnable() {
  103.             @Override
  104.             public void run() {
  105.                 new MegaGUI().setVisible(true);
  106.             }
  107.         });
  108.         try {
  109.             paintPic = ImageIO
  110.                     .read(new URL(
  111.                             "http://i1149.photobucket.com/albums/o592/AverageRS/Graphics/Paints/megakaramja.png")
  112.                             .openStream());
  113.         } catch (MalformedURLException e) {
  114.             // TODO Auto-generated catch block
  115.             e.printStackTrace();
  116.         } catch (IOException e) {
  117.             // TODO Auto-generated catch block
  118.             e.printStackTrace();
  119.         }
  120.         while (!start) {
  121.             wait(1000, 10001);
  122.         }
  123.         startTime = System.currentTimeMillis();
  124.         return true;
  125.     }
  126.  
  127.     @Override
  128.     public void onStop() {
  129.         log("Lobster script stopped, THANKS FOR USING");
  130.     }
  131.  
  132.     @Override
  133.     public void onRepaint(Graphics g) {
  134.         long runTime = System.currentTimeMillis() - startTime;
  135.         long TotalSecs = runTime / 1000;
  136.         long TotalMins = TotalSecs / 60;
  137.         long TotalHours = TotalMins / 60;
  138.         int seconds = (int) TotalSecs % 60;
  139.         int minutes = (int) TotalMins % 60;
  140.         int hours = (int) TotalHours % 60;
  141.  
  142.         StringBuilder b = new StringBuilder();
  143.  
  144.         if (hours < 10)
  145.             b.append('0');
  146.         b.append(hours);
  147.         b.append(':');
  148.         if (minutes < 10)
  149.             b.append('0');
  150.         b.append(minutes);
  151.         b.append(':');
  152.         if (seconds < 10)
  153.             b.append('0');
  154.         b.append(seconds);
  155.  
  156.         hourXP = (curXP - startXP) / (minutes + hours * 60 + seconds / 60f)
  157.                 * 60f;
  158.         fishCountHour = (int) (fishCount
  159.                 / (minutes + hours * 60 + seconds / 60f) * 60f);
  160.         XPTill = (getNextLVLXP - (curXP - startXP));
  161.         if ((curXP - startXP) != 0) {
  162.             TTNL = (int) (XPTill / ((curXP - startXP) / (minutes + hours * 60 + seconds / 60f)));
  163.         }
  164.  
  165.         if (XPTill <= 0) {
  166.             newLVL = true;
  167.         }
  168.  
  169.         if (paintPic != null) {
  170.             g.drawImage(paintPic, 0, 233, null);
  171.         }
  172.  
  173.         g.setColor(Color.WHITE);
  174.         g.setFont(new Font("Verdana", 1, 13));
  175.         g.drawString("" + fishCount, 87, 382);
  176.         g.drawString("" + fishCountHour, 136, 399);
  177.         g.drawString("" + TTLString(TTNL), 40, 426);
  178.         g.drawString("" + curLVL + "(" + (curLVL - startLVL) + ")", 95, 440);
  179.         g.drawString("" + addCommas((curXP - startXP), false), 314, 382);
  180.         g.drawString("" + addCommas((int) hourXP, false), 321, 400);
  181.         g.drawString(status, 243, 425);
  182.         g.drawString(b.toString(), 287, 440);
  183.  
  184.         if (rects != null && rects.length > 0) {
  185.             for (final Rectangle r : rects) {
  186.                 if (r != null) {
  187.                     final int x = r.x, y = r.y, width = r.width, height = r.height;
  188.                     g.setColor(new Color(255, 0, 0, 150));
  189.                     g.fillRect(x, y, width, height);
  190.                     g.setColor(Color.white);
  191.                     g.drawRect(x, y, width, height);
  192.                 }
  193.             }
  194.         }
  195.         if (rects2 != null && rects2.length > 0) {
  196.             for (final Rectangle r : rects2) {
  197.                 if (r != null) {
  198.                     final int x = r.x, y = r.y, width = r.width, height = r.height;
  199.                     g.setColor(Color.green);
  200.                     g.fillRect(x, y, width, height);
  201.                     g.setColor(Color.white);
  202.                     g.drawRect(x, y, width, height);
  203.                 }
  204.             }
  205.         }
  206.         if (lobsters) {
  207.             if (CFR != null && CFR.length > 0) {
  208.                 for (final Rectangle r : CFR) {
  209.                     if (r != null) {
  210.                         final int x = r.x, y = r.y, width = r.width, height = r.height;
  211.                         g.setColor(Color.black);
  212.                         g.fillRect(x, y, width, height);
  213.                         g.setColor(Color.white);
  214.                         g.drawRect(x, y, width, height);
  215.                     }
  216.                 }
  217.             }
  218.         } else {
  219.             if (harpoonRects != null && harpoonRects.length > 0) {
  220.                 for (final Rectangle r : harpoonRects) {
  221.                     if (r != null) {
  222.                         final int x = r.x, y = r.y, width = r.width, height = r.height;
  223.                         g.setColor(Color.yellow);
  224.                         g.fillRect(x, y, width, height);
  225.                         g.setColor(Color.white);
  226.                         g.drawRect(x, y, width, height);
  227.                     }
  228.                 }
  229.             }
  230.         }
  231.         // if (headRects != null && headRects.length > 0) {
  232.         // for (final Rectangle r : headRects) {
  233.         // if (r != null) {
  234.         // final int x = r.x, y = r.y, width = r.width, height = r.height;
  235.         // g.setColor(Color.orange);
  236.         // g.fillRect(x, y, width, height);
  237.         // g.setColor(Color.white);
  238.         // g.drawRect(x, y, width, height);
  239.         // }
  240.         // }
  241.         // }
  242.         // g.setColor(new Color(255, 255, 255, 50));
  243.         // grid.draw(g);
  244.     }
  245.  
  246.     public String TTLString(int rTime) {
  247.         long runTime = rTime * 60000;
  248.         long TotalSecs = runTime / 1000;
  249.         long TotalMins = TotalSecs / 60;
  250.         long TotalHours = TotalMins / 60;
  251.         int seconds = (int) TotalSecs % 60;
  252.         int minutes = (int) TotalMins % 60;
  253.         int hours = (int) TotalHours % 60;
  254.  
  255.         StringBuilder b = new StringBuilder();
  256.  
  257.         if (hours < 10)
  258.             b.append('0');
  259.         b.append(hours);
  260.         b.append(':');
  261.         if (minutes < 10)
  262.             b.append('0');
  263.         b.append(minutes);
  264.         b.append(':');
  265.         if (seconds < 10)
  266.             b.append('0');
  267.         b.append(seconds);
  268.  
  269.         return b.toString();
  270.     }
  271.  
  272.     Rectangle[] rS1;
  273.  
  274.     final Grid grid = new Grid(Game.VIEWPORT, 15);
  275.     private Rectangle[] rects;
  276.     private Rectangle[] rects2;
  277.     private Rectangle[] headRects;
  278.     private Rectangle[] harpoonRects;
  279.  
  280.     @Override
  281.     public int loop() {
  282.         // checkFC();
  283.         // if (true) {
  284.         // return 155;
  285.         // }
  286.         if (!getStart || newLVL) {
  287.             headColor = getHeadColor();
  288.             checkXP();
  289.             getStart = true;
  290.             newLVL = false;
  291.             Tabs.openTab(Tab.INVENTORY, false);
  292.         }
  293.  
  294.         checkInventory();
  295.  
  296.         rects = getRectangleSpots(grid, 5, cagingColor);
  297.         rects2 = grid.getContaining(1, rColor);
  298.         headRects = grid.getContaining(headColor);
  299.         harpoonRects = grid.getContaining(1, new Color(87, 63, 12));
  300.  
  301.         if (!getRect) {
  302.             rects2 = grid.getContaining(1, rColor);
  303.             getRect = true;
  304.         }
  305.         if (exchange) {
  306.             status = "Exchanging";
  307.             exchange();
  308.             return 1;
  309.         }
  310.         if (walkingToStiles) {
  311.             status = "Walking to Stiles";
  312.             walkToStiles();
  313.             triedWalking = true;
  314.             exchange = true;
  315.             walkingToStiles = false;
  316.             return 1;
  317.         }
  318.  
  319.         if (!setCamera) {
  320.             Mouse.click(544, 27);
  321.             Time.sleep(500);
  322.             Camera.pitchUp(2755);
  323.             setCamera = true;
  324.         }
  325.         Color c = ImageUtil.getColorAt(Game.getImage(), 710, 443);
  326.         // !Game.getColorAt(new Point(701, 433)).equals(new Color(65, 57, 46))
  327.         if (Inventory.getCount() == 28) {
  328.             log("Inventory is full");
  329.  
  330.             rects2 = grid.getContaining(1, rColor);
  331.  
  332.             if (rects2.length > 1) {
  333.                 log("going to exchange");
  334.                 triedWalking = false;
  335.                 exchange = true;
  336.             } else {
  337.                 walkingToStiles = true;
  338.             }
  339.             fishing = false;
  340.             counter = 1;
  341.             return 1;
  342.         }
  343.  
  344.         if (walkToLobs) {
  345.             status = "Walking to port";
  346.             walkToLob();
  347.             walkToLobs = false;
  348.             Time.sleep(3000);
  349.             return 1;
  350.         }
  351.  
  352.         if (fishing) {
  353.             status = "Fishing";
  354.             if (checkFC()) {
  355.                 fishing = true;
  356.                 CFAIL = 0;
  357.             } else {
  358.                 CFAIL++;
  359.             }
  360.             if (CFAIL > 1) {
  361.                 fishing = false;
  362.             }
  363.             if (!offScreen) {
  364.                 moveMouseOutOfScreen();
  365.                 offScreen = true;
  366.             }
  367.             // if (checkHead()) {
  368.             // fishing = false;
  369.             // counter = 1;
  370.             // return Random.random(125, 400);
  371.             // }
  372.             // if (!waitForLobsters(1000)) {
  373.             // fishing = false;
  374.             // counter = 1;
  375.             // }
  376.             Time.sleep(2500);
  377.         } else {
  378.             offScreen = false;
  379.             status = "Attempting to fish";
  380.  
  381.             fish();
  382.             // LinkedList<Point> p = new LinkedList<Point>();
  383.             // while (p.size() < 0) {
  384.             // if ((p = findNearestColors(cagingColor)).size() > 0) {
  385.             // spot = p.get(0);
  386.             // log("found points");
  387.             // break;
  388.             // }
  389.             // }
  390.  
  391.             // if ((p = findNearestColors(cagingColor)).size() > 0) {
  392.             // spot = p.get(0);
  393.             // log("found points");
  394.             // } else {
  395.             // spot = fishingEntity.findPoint();
  396.             // }
  397.  
  398.             /*
  399.              * if (spot != null) { Mouse.move(spot); Time.sleep(1000); if
  400.              * (OCR.getUpText().contains("Cage")) { Mouse.click(); pointCheck =
  401.              * spot; fishing = true; Time.sleep(2500); } } else {
  402.              * LinkedList<Point> points2 = new LinkedList<Point>(); int counter3
  403.              * = 0; for (int three = 0; three < cagingColor.length - 1; three++)
  404.              * { Time.sleep(500); cagingSpots =
  405.              * ImageUtil.getPointsWithColor(Game.getImage(), Game.VIEWPORT,
  406.              * cagingColor[three]); if (cagingSpots.size() > 0) {
  407.              * points2.add(counter3, cagingSpots.get(0)); counter3++; } }
  408.              *
  409.              * for (int fisher = 0; fisher < points2.size(); fisher++) {
  410.              * log(fisher + " = " + points2.get(fisher));
  411.              * Mouse.move(points2.get(fisher)); Time.sleep(1000); if (fisher >
  412.              * 10) { break; } if (OCR.getUpText().contains("Cage")) {
  413.              * Mouse.click(); pointCheck = spot; fishing = true;
  414.              * Time.sleep(2500); break; } } }
  415.              */
  416.  
  417.         }
  418.         return 1;
  419.     }
  420.  
  421.     public boolean checkFC() {
  422.         if (lobsters) {
  423.             for (int C = 0; C < 2; C++) {
  424.                 CFR = getRectangleSpots(grid, 0, CFC);
  425.                 for (Rectangle R : CFR) {
  426.                     if (Calculations.getDistanceBetween(
  427.                             new Point((int) R.getCenterX(), (int) R
  428.                                     .getCenterY()), new Point(259, 173)) < 31) {
  429.                         return true;
  430.                     }
  431.                     wait(150, 250);
  432.                 }
  433.                 wait(200, 300);
  434.             }
  435.         } else {
  436.             // for (int C = 0; C < 5; C++) {
  437.             // harpoonRects = getRectangleSpots(grid, 0, CFH);
  438.             // for (Rectangle R : harpoonRects) {
  439.             // log(Calculations.getDistanceBetween(
  440.             // new Point((int) R.getCenterX(), (int) R
  441.             // .getCenterY()), new Point(245, 143)));
  442.             //
  443.             // if (Calculations.getDistanceBetween(
  444.             // new Point((int) R.getCenterX(), (int) R
  445.             // .getCenterY()), new Point(245, 143)) < 14) {
  446.             // return true;
  447.             // }
  448.             // wait(150, 250);
  449.             // }
  450.             // wait(200, 300);
  451.             // }
  452.             waitForInv(1500);
  453.         }
  454.         return false;
  455.     }
  456.  
  457.     public boolean checkHead() {
  458.         headRects = grid.getContaining(5, headColor);
  459.         for (Rectangle h : headRects) {
  460.             if (h.contains(headPoint)) {
  461.                 return true;
  462.             }
  463.         }
  464.  
  465.         // for (Point p : ImageUtil.getPointsWithColor(Game.getImage(),
  466.         // headColor, 5)) {
  467.         // if (Calculations.getDistanceBetween(p, headPoint) < 5) {
  468.         // return true;
  469.         // }
  470.         // }
  471.         return false;
  472.     }
  473.  
  474.     public boolean rectangleContainsColor(Rectangle r, Color c, int tol) {
  475.         for (int w = 0; w < r.width; w++) {
  476.             for (int h = 0; h < r.height; h++) {
  477.                 if (isColor(
  478.                         ImageUtil.getColorAt(Game.getImage(), new Point(w, h)),
  479.                         c, tol)) {
  480.                     return true;
  481.                 }
  482.             }
  483.         }
  484.         return false;
  485.     }
  486.  
  487.     public Color[] getHeadColorRectangle() {
  488.         LinkedList<Color> c = new LinkedList<Color>();
  489.         for (int w = 0; w < headRect.width; w++) {
  490.             for (int h = 0; h < headRect.height; h++) {
  491.                 c.add(ImageUtil.getColorAt(Game.getImage(), new Point(w, h)));
  492.             }
  493.         }
  494.         return (Color[]) c.toArray(new Color[c.size()]);
  495.     }
  496.  
  497.     public Color getHeadColor() {
  498.         return ImageUtil.getColorAt(Game.getImage(), headPoint);
  499.     }
  500.  
  501.     public String addCommas(int d, boolean money) {
  502.         DecimalFormat twoDForm = new DecimalFormat("###,###");
  503.         if (money) {
  504.             twoDForm = new DecimalFormat("$###,###");
  505.             return twoDForm.format(d);
  506.         }
  507.         return twoDForm.format(d);
  508.     }
  509.  
  510.     public void checkXP() {
  511.         sTrack.update();
  512.         wait(150, 350);
  513.         if (startXP == 0) {
  514.             startXP = sTrack.getExperience();
  515.             startLVL = Skills.Skill.FISHING.getLevel();
  516.         }
  517.         curXP = sTrack.getExperience();
  518.         curLVL = Skills.Skill.FISHING.getLevel();
  519.         getNextLVLXP = Skills.Skill.FISHING.getExperienceToLevel();
  520.     }
  521.  
  522.     public void wait(int r1, int r2) {
  523.         Time.sleep(r1, r2);
  524.     }
  525.  
  526.     public Color[] getColorArrayFromImage(BufferedImage i) {
  527.         Color[] colorArray = new Color[i.getWidth() * i.getHeight()];
  528.         int counter = 0;
  529.         for (int width = 0; width < i.getWidth(); width++) {
  530.             for (int height = 0; height < i.getHeight(); height++) {
  531.                 int clr = i.getRGB(width, height);
  532.                 int red = (clr & 0x00ff0000) >> 16;
  533.                 int green = (clr & 0x0000ff00) >> 8;
  534.                 int blue = clr & 0x000000ff;
  535.                 colorArray[counter] = new Color(red, green, blue);
  536.                 counter++;
  537.             }
  538.         }
  539.         return colorArray;
  540.     }
  541.  
  542.     public void checkInventory() {
  543.         final int count = Inventory.getCount();
  544.         if (lastInvCount == 0) {
  545.             lastInvCount = count;
  546.             return;
  547.         }
  548.         if (count > lastInvCount) {
  549.             fishCount = fishCount + (count - lastInvCount);
  550.             lastInvCount = count;
  551.             curXP = startXP + (90 * fishCount);
  552.         }
  553.     }
  554.  
  555.     public void exchange() {
  556.         rects2 = grid.getContaining(1, rColor);
  557.         if (rects2.length > 0) {
  558.             int failCount = 0;
  559.             for (Rectangle r : rects2) {
  560.                 if (failCount > 1) {
  561.                     break;
  562.                 }
  563.                 Mouse.move(new Point((int) r.getCenterX(), (int) r.getCenterY()));
  564.                 wait(500, 600);
  565.                 Mouse.click(false);
  566.                 wait(700, 800);
  567.  
  568.                 if (Menu.find() != null && Menu.find().contains("Exchange")) {
  569.                     Menu.interact("Exchange");
  570.                     atStiles = true;
  571.                     Time.sleep(750);
  572.                     Mouse.move(Mouse.getLocation().x,
  573.                             Mouse.getLocation().y + 46);
  574.                     Time.sleep(3750);
  575.                     break;
  576.                 } else {
  577.                     failCount++;
  578.                     Menu.interact("Cancel");
  579.                 }
  580.             }
  581.             if (!Inventory.isFull()) {
  582.                 exchange = false;
  583.                 walkToLobs = true;
  584.                 lastInvCount = 0;
  585.             } else {
  586.                 if (!atStiles) {
  587.                     walkToStiles();
  588.                 }
  589.             }
  590.         }
  591.     }
  592.  
  593.     public void fish() {
  594.         if (lobsters) {
  595.             Rectangle last = null;
  596.             boolean con;
  597.             rects = getRectangleSpots(grid, 5, cagingColor);
  598.             for (Rectangle r : rects) {
  599.                 if (last != null) {
  600.                     if (Calculations.getDistanceBetween(
  601.                             new Point((int) r.getCenterX(), (int) r
  602.                                     .getCenterY()),
  603.                             new Point((int) last.getCenterX(), (int) last
  604.                                     .getCenterY())) < 30) {
  605.                         log("rects too clos");
  606.                         con = false;
  607.                     } else {
  608.                         con = true;
  609.                     }
  610.                 } else {
  611.                     con = true;
  612.                 }
  613.  
  614.                 if (r != null && con) {
  615.                     Mouse.move((int) r.getCenterX(), (int) r.getCenterY());
  616.                     Time.sleep(1000);
  617.                     if (OCR.getUpText().contains("Cage")) {
  618.                         Mouse.click();
  619.                         pointCheck = new Point((int) r.getCenterX(),
  620.                                 (int) r.getCenterY());
  621.                         fishing = true;
  622.                         Time.sleep(2500);
  623.                         break;
  624.                     }
  625.                     last = r;
  626.                 }
  627.             }
  628.             wait(1000, 2000);
  629.         } else {
  630.             Rectangle last = null;
  631.             boolean con;
  632.             rects = getRectangleSpots(grid, 5, cagingColor);
  633.             for (Rectangle r : rects) {
  634.                 if (last != null) {
  635.                     if (Calculations.getDistanceBetween(
  636.                             new Point((int) r.getCenterX(), (int) r
  637.                                     .getCenterY()),
  638.                             new Point((int) last.getCenterX(), (int) last
  639.                                     .getCenterY())) < 30) {
  640.                         log("rects too clos");
  641.                         con = false;
  642.                     } else {
  643.                         con = true;
  644.                     }
  645.                 } else {
  646.                     con = true;
  647.                 }
  648.  
  649.                 if (r != null && con) {
  650.                     Mouse.move((int) r.getCenterX(), (int) r.getCenterY());
  651.                     Time.sleep(1000);
  652.                     if (OCR.getUpText().contains("Cage")) {
  653.                         Mouse.click(false);
  654.                         if (Menu.find() != null
  655.                                 && Menu.find().contains("Harpoon")) {
  656.                             Menu.interact("Harpoon");
  657.                             wait(500, 1000);
  658.                             pointCheck = new Point((int) r.getCenterX(),
  659.                                     (int) r.getCenterY());
  660.                             fishing = true;
  661.                             break;
  662.                         } else {
  663.                             Menu.interact("Cancel");
  664.                         }
  665.                     }
  666.                     last = r;
  667.                 }
  668.             }
  669.             wait(1000, 2000);
  670.         }
  671.     }
  672.  
  673.     public Rectangle[] getRectangleSpots(Grid g, int tol, Color... c) {
  674.         Rectangle[] gridRect = g.getContaining(tol, c);
  675.         LinkedList<Rectangle> r = new LinkedList<Rectangle>();
  676.         for (int color = 0; color < c.length; color++) {
  677.             gridRect = g.getContaining(0, c[color]);
  678.             for (int p = 0; p < gridRect.length; p++) {
  679.                 if (gridRect.length > 0) {
  680.                     if (!r.contains(gridRect[p])) {
  681.                         r.add(gridRect[p]);
  682.                     }
  683.                 }
  684.             }
  685.         }
  686.         // for (int i = 0; i < 5; i++) {
  687.         // gridRect = g.getContaining(tol, c);
  688.         // for (int p = 0; p < gridRect.length; p++) {
  689.         // if (gridRect.length > 0) {
  690.         // if (!r.contains(gridRect[p])) {
  691.         // r.add(gridRect[p]);
  692.         // }
  693.         // }
  694.         // }
  695.         // wait(100, 200);
  696.         // }
  697.         return (Rectangle[]) r.toArray(new Rectangle[r.size()]);
  698.     }
  699.  
  700.     public LinkedList<Point> findNearestColors(Color[] c) {
  701.         dist = -1;
  702.         LinkedList<Point> POINTS = new LinkedList<Point>();
  703.         LinkedList<Point> lists = new LinkedList<Point>();
  704.         int COUNTER = 0;
  705.  
  706.         for (int three = 0; three < c.length - 1; three++) {
  707.             lists = ImageUtil.getPointsWithColor(Game.getImage(),
  708.                     Game.VIEWPORT, c[three]);
  709.             for (int zero = 0; zero < lists.size(); zero++) {
  710.                 POINTS.add(COUNTER, lists.get(zero));
  711.                 COUNTER++;
  712.             }
  713.         }
  714.         return POINTS;
  715.     }
  716.  
  717.     public boolean waitForInv(int wait) {
  718.         int iCount = Inventory.getCount();
  719.         for (int i = 0; i < wait; i++) {
  720.             if (Inventory.getCount() != iCount) {
  721.                 return true;
  722.             }
  723.         }
  724.         return false;
  725.     }
  726.  
  727.     public void walkToStiles() {
  728.         // VectorPath p = new VectorPath(toStilesTest);
  729.         // for (VectorTile tile : toStilesTest) {
  730.         // p.traverse();
  731.         // Time.sleep(6500);
  732.         // if (tile == p.getEnd()) {
  733.         // break;
  734.         // }
  735.         // }
  736.         for (int i = 0; i < toStiles.length; i++) {
  737.             rects2 = grid.getContaining(1, rColor);
  738.             if (rects2.length > 0 && i > 5) {
  739.                 break;
  740.             }
  741.             Mouse.click(toStiles[i]);
  742.             if (i > 4) {
  743.                 Time.sleep(3500);
  744.             } else {
  745.                 Time.sleep(7500);
  746.             }
  747.         }
  748.         atStiles = true;
  749.         Time.sleep(111);
  750.     }
  751.  
  752.     public void walkToLob() {
  753.         for (Point i : toLob) {
  754.             Mouse.click(i);
  755.             Time.sleep(6850);
  756.         }
  757.         atStiles = false;
  758.         Time.sleep(1546);
  759.     }
  760.  
  761.     public boolean checkFishing() {
  762.         log("checking if we are fishing");
  763.         LinkedList<Point> points = new LinkedList<Point>();
  764.         int counter2 = 0;
  765.         for (int wait = 0; wait < 500; wait++) {
  766.             cagingSpots = ImageUtil.getPointsWithColors(Game.getImage(),
  767.                     Game.VIEWPORT, fC);
  768.             for (int zero = 0; zero < cagingSpots.size(); zero++) {
  769.                 points.add(counter2, cagingSpots.get(zero));
  770.                 counter2++;
  771.                 Time.sleep(100);
  772.             }
  773.  
  774.         }
  775.         nearest = null;
  776.         dist = 24;
  777.         for (Point point : points) {
  778.             double distTmp = Calculations.getDistanceBetween(point, CHECK);
  779.             if (nearest == null) {
  780.                 dist = distTmp;
  781.                 nearest = point;
  782.             } else if (distTmp < dist) {
  783.                 nearest = point;
  784.                 dist = distTmp;
  785.             }
  786.             log("dist = " + dist);
  787.             log("abs = " + Math.abs((CHECK.y - nearest.y)));
  788.             if (Math.abs((CHECK.y - nearest.y)) > 10) {
  789.                 log("fishing spot change2?");
  790.                 return false;
  791.             }
  792.         }
  793.         return true;
  794.     }
  795.  
  796.     public boolean stillFishing() {
  797.         LinkedList<Point> points = new LinkedList<Point>();
  798.         int counter2 = 0;
  799.         if (fishing) {
  800.             for (int three = 0; three < cagingColor.length - 1; three++) {
  801.                 cagingSpots = ImageUtil.getPointsWithColor(Game.getImage(),
  802.                         Game.VIEWPORT, cagingColor[three]);
  803.                 for (int zero = 0; zero < cagingSpots.size(); zero++) {
  804.                     points.add(counter2, cagingSpots.get(zero));
  805.                     counter2++;
  806.                     Time.sleep(500);
  807.                 }
  808.             }
  809.             nearest = null;
  810.             dist = 24;
  811.             for (Point point : points) {
  812.                 double distTmp = Calculations.getDistanceBetween(point, CHECK);
  813.                 if (nearest == null) {
  814.                     dist = distTmp;
  815.                     nearest = point;
  816.                 } else if (distTmp < dist) {
  817.                     nearest = point;
  818.                     dist = distTmp;
  819.                 }
  820.                 if (dist < 15) {
  821.                     return true;
  822.                 }
  823.             }
  824.             log("dist = " + dist);
  825.             if (dist > 39) {
  826.                 log("fishing spot change?");
  827.                 return false;
  828.             }
  829.         }
  830.         return true;
  831.     }
  832.  
  833.     public void moveMouseOutOfScreen() {
  834.         move(Random.random(10, 293), -1);
  835.     }
  836.  
  837.     public Point getNearestPoint(LinkedList<Point> p) {
  838.         nearest = null;
  839.         dist = 20;
  840.         for (Point point : p) {
  841.             double distTmp = Calculations.getDistanceBetween(point, CHECK);
  842.             if (nearest == null) {
  843.                 dist = distTmp;
  844.                 nearest = point;
  845.             } else if (distTmp < dist) {
  846.                 nearest = point;
  847.                 dist = distTmp;
  848.             }
  849.         }
  850.         return nearest;
  851.     }
  852.  
  853.     public static void move(int paramInt1, int paramInt2) {
  854.         Point localPoint = Mouse.getLocation();
  855.         q.a(10, localPoint.x, localPoint.y, paramInt1, paramInt2, 0, 0);
  856.     }
  857.  
  858.     /**
  859.      * @param size
  860.      *            the size of the rectangle to look for
  861.      * @param tolerance
  862.      *            the tolerance in which you want to allow (0 to 255)
  863.      * @param searchArea
  864.      *            the rectangle you would like to search within for the
  865.      *            rectangles.
  866.      * @param colors
  867.      *            the colors the rectangle must contain
  868.      *
  869.      * @return an array of rectangles containing an array of colors within a
  870.      *         tolerance of 'tolerance' inside 'searchArea'.
  871.      *
  872.      * @author Dang
  873.      */
  874.     public static Rectangle[] findRectangles(final int sizeX, final int sizeY,
  875.             final int tolerance, final Rectangle searchArea,
  876.             final Color... colors) {
  877.         final java.util.List<Rectangle> rects = new LinkedList<Rectangle>();
  878.         final int jumpSizeX = sizeX / 2;
  879.         final int jumpSizeY = sizeY / 2;
  880.         final BufferedImage i = Game.getImage();
  881.         for (int x = searchArea.x; x <= searchArea.x + searchArea.width - sizeX; x += jumpSizeX) {
  882.             for (int y = searchArea.y; y <= searchArea.y + searchArea.height
  883.                     - sizeY; y += jumpSizeY) {
  884.                 final Rectangle r = new Rectangle(x, y, sizeX, sizeY);
  885.                 for (int count = 0; count < colors.length; count++) {
  886.                     final int[] sub_pixels = i.getRGB(x, y, sizeX, sizeY, null,
  887.                             0, sizeX * sizeY);
  888.                     if (imageContains(sub_pixels, colors[count], tolerance)) {
  889.                         rects.add(r);
  890.                     } else {
  891.                         count = colors.length + 1;
  892.                     }
  893.                 }
  894.             }
  895.         }
  896.         return rects.toArray(new Rectangle[rects.size()]);
  897.     }
  898.  
  899.     /**
  900.      *
  901.      * @param pixels
  902.      *            the pixel values of the image
  903.      * @param color
  904.      *            the color to check if the image contains
  905.      * @param tolerance
  906.      *            the tolerance to allow
  907.      * @return the image contains 'color'
  908.      */
  909.     public static boolean imageContains(final int[] pixels, final Color color,
  910.             final int tolerance) {
  911.         for (final int pixel : pixels) {
  912.             if (isColor(new Color(pixel), color, tolerance)) {
  913.                 return true;
  914.             }
  915.         }
  916.         return false;
  917.     }
  918.  
  919.     /**
  920.      *
  921.      * @param colorOne
  922.      *            the first color to compare
  923.      * @param colorTwo
  924.      *            the color to compare 'colorOne' to
  925.      * @param tolerance
  926.      *            the tolerance to allow between each color
  927.      * @return if the color's RGS values are within the tolerance given
  928.      */
  929.     public static boolean isColor(final Color colorOne, final Color colorTwo,
  930.             final int tolerance) {
  931.         final int[] one = { colorOne.getRed(), colorOne.getGreen(),
  932.                 colorOne.getBlue() };
  933.         final int[] two = { colorTwo.getRed(), colorTwo.getGreen(),
  934.                 colorTwo.getBlue() };
  935.         return isWithinTolerance(one[0], two[0], tolerance)
  936.                 && isWithinTolerance(one[1], two[1], tolerance)
  937.                 && isWithinTolerance(one[2], two[2], tolerance);
  938.     }
  939.  
  940.     /**
  941.      *
  942.      * @param num
  943.      *            the first number to compare
  944.      * @param num2
  945.      *            the number to compare to 'num'
  946.      * @param tolerance
  947.      *            the amount to allow between the values
  948.      * @return if num and num2 are within the given tolerance of eachother
  949.      */
  950.     public static boolean isWithinTolerance(final int num, final int num2,
  951.             final int tolerance) {
  952.         return num <= num2 + tolerance && num >= num2 - tolerance;
  953.     }
  954.  
  955.     int rectX, rectY, rectX2, rectY2;
  956.     Rectangle colorRect = null;
  957.     LinkedList<Color> rectColor = new LinkedList<Color>();
  958.  
  959.     @Override
  960.     public void mouseClicked(MouseEvent arg0) {
  961.         // if (!pickedColor) {
  962.         // rColor = Game.getColorAt(arg0.getPoint());
  963.         // pickedColor = true;
  964.         // walkToLobs = true;
  965.         // }
  966.     }
  967.  
  968.     @Override
  969.     public void mouseEntered(MouseEvent arg0) {
  970.     }
  971.  
  972.     @Override
  973.     public void mouseExited(MouseEvent arg0) {
  974.     }
  975.  
  976.     @Override
  977.     public void mousePressed(MouseEvent arg0) {
  978.         if (!pickedColor) {
  979.             rectX = arg0.getX();
  980.             rectY = arg0.getY();
  981.         }
  982.     }
  983.  
  984.     @Override
  985.     public void mouseReleased(MouseEvent arg0) {
  986.         // if (!pickedColor) {
  987.         // colorRect = new Rectangle(rectX, rectY, rectX2 - rectX, rectY2
  988.         // - rectY);
  989.         // for (int width = 0; width < colorRect.width; width++) {
  990.         // for (int height = 0; height < colorRect.height; height++) {
  991.         // rectColor.add(Game.getColorAt(colorRect.x + width,
  992.         // colorRect.y + height));
  993.         // }
  994.         // }
  995.         // rColor = rectColor.toArray(new Color[rectColor.size()]);
  996.         // pickedColor = true;
  997.         // walkToLobs = true;
  998.         // }
  999.     }
  1000.  
  1001.     @Override
  1002.     public void mouseDragged(MouseEvent e) {
  1003.         if (!pickedColor) {
  1004.             rectX2 = e.getX();
  1005.             rectY2 = e.getY();
  1006.             colorRect = new Rectangle(rectX, rectY, rectX2 - rectX, rectY2
  1007.                     - rectY);
  1008.         }
  1009.     }
  1010.  
  1011.     JButton startButton;
  1012.     JComboBox whereandwhat;
  1013.     JLabel text;
  1014.     String[] list = { "Lobsters", "Swordies and Tuna" };
  1015.  
  1016.     @Override
  1017.     public void mouseMoved(MouseEvent e) {
  1018.     }
  1019.  
  1020.     public class MegaGUI extends JFrame implements ActionListener {
  1021.  
  1022.         public MegaGUI() {
  1023.             setTitle("MegaPlanker");
  1024.  
  1025.             startButton = new JButton("Start");
  1026.             text = new JLabel("What fish?????");
  1027.             whereandwhat = new JComboBox(list);
  1028.  
  1029.             setLayout(null);
  1030.             setResizable(false);
  1031.             setSize(390, 255);
  1032.             setLocationRelativeTo(null);
  1033.  
  1034.             text.setBounds(20, 20, 182, 21);
  1035.             startButton.setBounds(135, 148, 83, 28);
  1036.             startButton.addActionListener(this);
  1037.             whereandwhat.setBounds(65, 71, 200, 22);
  1038.  
  1039.             add(text);
  1040.             add(whereandwhat);
  1041.             add(startButton);
  1042.  
  1043.             setVisible(true);
  1044.         }
  1045.  
  1046.         @Override
  1047.         public void actionPerformed(ActionEvent e) {
  1048.             if (e.getActionCommand().contains("Start")) {
  1049.                 if (whereandwhat.getSelectedItem().toString()
  1050.                         .equals("Lobsters")) {
  1051.                     lobsters = true;
  1052.                 } else {
  1053.                     lobsters = false;
  1054.                 }
  1055.                 dispose();
  1056.                 setVisible(false);
  1057.                 start = true;
  1058.             }
  1059.         }
  1060.  
  1061.     }
  1062. }
Advertisement
Add Comment
Please, Sign In to add comment