Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.text.DecimalFormat;
- import java.util.LinkedList;
- import javax.imageio.ImageIO;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import org.runedream.q;
- import org.runedream.api.Script;
- import org.runedream.api.ScriptManifest;
- import org.runedream.api.methods.Calculations;
- import org.runedream.api.methods.Camera;
- import org.runedream.api.methods.Game;
- import org.runedream.api.methods.ImageUtil;
- import org.runedream.api.methods.Inventory;
- import org.runedream.api.methods.Mouse;
- import org.runedream.api.methods.OCR;
- import org.runedream.api.methods.Skills;
- import org.runedream.api.methods.Tabs;
- import org.runedream.api.util.Random;
- import org.runedream.api.util.SkillTracker;
- import org.runedream.api.util.Time;
- import org.runedream.api.wrappers.Entity;
- import org.runedream.api.wrappers.Grid;
- import org.runedream.api.wrappers.Menu;
- import org.runedream.api.wrappers.Tab;
- @ScriptManifest(authors = { "MegaAlgos" }, name = "MegaKaramja", version = 1.0, description = "Fishes for lobsters to stiles in Karamaja", keywords = { "Fishing" }, language = {
- true, true, true, true })
- public class MegaKaramja extends Script implements MouseListener,
- MouseMotionListener {
- private Color[] cagingColor = { new Color(161, 164, 168),
- new Color(140, 150, 170), new Color(136, 146, 167),
- new Color(154, 159, 166), new Color(151, 158, 173),
- new Color(155, 160, 168), new Color(156, 161, 170),
- new Color(128, 133, 139), };
- private Color[] stiles = { new Color(56, 53, 53) };
- private Color lobster = new Color(99, 56, 30);
- Color[] rColor = { new Color(63, 60, 60), new Color(47, 45, 45),
- new Color(58, 55, 55) };
- boolean fishing, setCamera, walkingToStiles, exchange, walkToLobs,
- triedWalking = false, offScreen, pickedColor, getRect, atStiles,
- getStart, newLVL, start, lobsters;
- Point nearest = null, headPoint = new Point(262, 152);
- int counter = 1, times, rNumber, fishCount, fishCountHour, lastInvCount;
- double dist = -1;
- Point CHECK = new Point(258, 175), pointCheck;
- Point[] toStiles = { new Point(630, 50), new Point(571, 109),
- new Point(571, 123), new Point(571, 123), new Point(571, 115),
- new Point(571, 123), new Point(605, 110), new Point(605, 110),
- new Point(605, 110), new Point(605, 110) };
- Point[] toLob = { new Point(690, 56), new Point(690, 56),
- new Point(690, 56), new Point(691, 62), new Point(679, 75),
- new Point(645, 50) };
- LinkedList<Point> cagingSpots, stilesPoints;
- Point spot, stilesPoint;
- Entity stileEntity = new Entity(stiles);
- Entity fishingEntity = new Entity(cagingColor);
- private Color[] fC = { new Color(116, 119, 113), new Color(86, 87, 93),
- new Color(92, 91, 97), new Color(88, 90, 95) };
- BufferedImage STILES = null;
- Rectangle SRECT = null;
- Color[] SCOLOR, headColorArray;
- Color headColor;
- BufferedImage paintPic = null;
- SkillTracker sTrack = new SkillTracker(Skills.Skill.FISHING);
- int startXP, curXP, curLVL, startLVL, getNextLVLXP, XPTill, TTNL;
- double hourXP;
- long startTime;
- String status = "Starting up";
- Rectangle headRect = new Rectangle(262, 152, 2, 2);
- Rectangle headRect2 = new Rectangle(257, 155, 5, 6);
- // Check fishing variables
- Color[] CFC = { new Color(116, 123, 137), new Color(105, 109, 119),
- new Color(99, 103, 111), new Color(120, 128, 147) };
- Color CFH = new Color(87, 63, 12);
- Rectangle[] CFR;
- int CFAIL = 0;
- @Override
- public boolean onStart() {
- log("Lobsters!!! script started");
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new MegaGUI().setVisible(true);
- }
- });
- try {
- paintPic = ImageIO
- .read(new URL(
- "http://i1149.photobucket.com/albums/o592/AverageRS/Graphics/Paints/megakaramja.png")
- .openStream());
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- while (!start) {
- wait(1000, 10001);
- }
- startTime = System.currentTimeMillis();
- return true;
- }
- @Override
- public void onStop() {
- log("Lobster script stopped, THANKS FOR USING");
- }
- @Override
- public void onRepaint(Graphics g) {
- long runTime = System.currentTimeMillis() - startTime;
- long TotalSecs = runTime / 1000;
- long TotalMins = TotalSecs / 60;
- long TotalHours = TotalMins / 60;
- int seconds = (int) TotalSecs % 60;
- int minutes = (int) TotalMins % 60;
- int hours = (int) TotalHours % 60;
- StringBuilder b = new StringBuilder();
- if (hours < 10)
- b.append('0');
- b.append(hours);
- b.append(':');
- if (minutes < 10)
- b.append('0');
- b.append(minutes);
- b.append(':');
- if (seconds < 10)
- b.append('0');
- b.append(seconds);
- hourXP = (curXP - startXP) / (minutes + hours * 60 + seconds / 60f)
- * 60f;
- fishCountHour = (int) (fishCount
- / (minutes + hours * 60 + seconds / 60f) * 60f);
- XPTill = (getNextLVLXP - (curXP - startXP));
- if ((curXP - startXP) != 0) {
- TTNL = (int) (XPTill / ((curXP - startXP) / (minutes + hours * 60 + seconds / 60f)));
- }
- if (XPTill <= 0) {
- newLVL = true;
- }
- if (paintPic != null) {
- g.drawImage(paintPic, 0, 233, null);
- }
- g.setColor(Color.WHITE);
- g.setFont(new Font("Verdana", 1, 13));
- g.drawString("" + fishCount, 87, 382);
- g.drawString("" + fishCountHour, 136, 399);
- g.drawString("" + TTLString(TTNL), 40, 426);
- g.drawString("" + curLVL + "(" + (curLVL - startLVL) + ")", 95, 440);
- g.drawString("" + addCommas((curXP - startXP), false), 314, 382);
- g.drawString("" + addCommas((int) hourXP, false), 321, 400);
- g.drawString(status, 243, 425);
- g.drawString(b.toString(), 287, 440);
- if (rects != null && rects.length > 0) {
- for (final Rectangle r : rects) {
- if (r != null) {
- final int x = r.x, y = r.y, width = r.width, height = r.height;
- g.setColor(new Color(255, 0, 0, 150));
- g.fillRect(x, y, width, height);
- g.setColor(Color.white);
- g.drawRect(x, y, width, height);
- }
- }
- }
- if (rects2 != null && rects2.length > 0) {
- for (final Rectangle r : rects2) {
- if (r != null) {
- final int x = r.x, y = r.y, width = r.width, height = r.height;
- g.setColor(Color.green);
- g.fillRect(x, y, width, height);
- g.setColor(Color.white);
- g.drawRect(x, y, width, height);
- }
- }
- }
- if (lobsters) {
- if (CFR != null && CFR.length > 0) {
- for (final Rectangle r : CFR) {
- if (r != null) {
- final int x = r.x, y = r.y, width = r.width, height = r.height;
- g.setColor(Color.black);
- g.fillRect(x, y, width, height);
- g.setColor(Color.white);
- g.drawRect(x, y, width, height);
- }
- }
- }
- } else {
- if (harpoonRects != null && harpoonRects.length > 0) {
- for (final Rectangle r : harpoonRects) {
- if (r != null) {
- final int x = r.x, y = r.y, width = r.width, height = r.height;
- g.setColor(Color.yellow);
- g.fillRect(x, y, width, height);
- g.setColor(Color.white);
- g.drawRect(x, y, width, height);
- }
- }
- }
- }
- // if (headRects != null && headRects.length > 0) {
- // for (final Rectangle r : headRects) {
- // if (r != null) {
- // final int x = r.x, y = r.y, width = r.width, height = r.height;
- // g.setColor(Color.orange);
- // g.fillRect(x, y, width, height);
- // g.setColor(Color.white);
- // g.drawRect(x, y, width, height);
- // }
- // }
- // }
- // g.setColor(new Color(255, 255, 255, 50));
- // grid.draw(g);
- }
- public String TTLString(int rTime) {
- long runTime = rTime * 60000;
- long TotalSecs = runTime / 1000;
- long TotalMins = TotalSecs / 60;
- long TotalHours = TotalMins / 60;
- int seconds = (int) TotalSecs % 60;
- int minutes = (int) TotalMins % 60;
- int hours = (int) TotalHours % 60;
- StringBuilder b = new StringBuilder();
- if (hours < 10)
- b.append('0');
- b.append(hours);
- b.append(':');
- if (minutes < 10)
- b.append('0');
- b.append(minutes);
- b.append(':');
- if (seconds < 10)
- b.append('0');
- b.append(seconds);
- return b.toString();
- }
- Rectangle[] rS1;
- final Grid grid = new Grid(Game.VIEWPORT, 15);
- private Rectangle[] rects;
- private Rectangle[] rects2;
- private Rectangle[] headRects;
- private Rectangle[] harpoonRects;
- @Override
- public int loop() {
- // checkFC();
- // if (true) {
- // return 155;
- // }
- if (!getStart || newLVL) {
- headColor = getHeadColor();
- checkXP();
- getStart = true;
- newLVL = false;
- Tabs.openTab(Tab.INVENTORY, false);
- }
- checkInventory();
- rects = getRectangleSpots(grid, 5, cagingColor);
- rects2 = grid.getContaining(1, rColor);
- headRects = grid.getContaining(headColor);
- harpoonRects = grid.getContaining(1, new Color(87, 63, 12));
- if (!getRect) {
- rects2 = grid.getContaining(1, rColor);
- getRect = true;
- }
- if (exchange) {
- status = "Exchanging";
- exchange();
- return 1;
- }
- if (walkingToStiles) {
- status = "Walking to Stiles";
- walkToStiles();
- triedWalking = true;
- exchange = true;
- walkingToStiles = false;
- return 1;
- }
- if (!setCamera) {
- Mouse.click(544, 27);
- Time.sleep(500);
- Camera.pitchUp(2755);
- setCamera = true;
- }
- Color c = ImageUtil.getColorAt(Game.getImage(), 710, 443);
- // !Game.getColorAt(new Point(701, 433)).equals(new Color(65, 57, 46))
- if (Inventory.getCount() == 28) {
- log("Inventory is full");
- rects2 = grid.getContaining(1, rColor);
- if (rects2.length > 1) {
- log("going to exchange");
- triedWalking = false;
- exchange = true;
- } else {
- walkingToStiles = true;
- }
- fishing = false;
- counter = 1;
- return 1;
- }
- if (walkToLobs) {
- status = "Walking to port";
- walkToLob();
- walkToLobs = false;
- Time.sleep(3000);
- return 1;
- }
- if (fishing) {
- status = "Fishing";
- if (checkFC()) {
- fishing = true;
- CFAIL = 0;
- } else {
- CFAIL++;
- }
- if (CFAIL > 1) {
- fishing = false;
- }
- if (!offScreen) {
- moveMouseOutOfScreen();
- offScreen = true;
- }
- // if (checkHead()) {
- // fishing = false;
- // counter = 1;
- // return Random.random(125, 400);
- // }
- // if (!waitForLobsters(1000)) {
- // fishing = false;
- // counter = 1;
- // }
- Time.sleep(2500);
- } else {
- offScreen = false;
- status = "Attempting to fish";
- fish();
- // LinkedList<Point> p = new LinkedList<Point>();
- // while (p.size() < 0) {
- // if ((p = findNearestColors(cagingColor)).size() > 0) {
- // spot = p.get(0);
- // log("found points");
- // break;
- // }
- // }
- // if ((p = findNearestColors(cagingColor)).size() > 0) {
- // spot = p.get(0);
- // log("found points");
- // } else {
- // spot = fishingEntity.findPoint();
- // }
- /*
- * if (spot != null) { Mouse.move(spot); Time.sleep(1000); if
- * (OCR.getUpText().contains("Cage")) { Mouse.click(); pointCheck =
- * spot; fishing = true; Time.sleep(2500); } } else {
- * LinkedList<Point> points2 = new LinkedList<Point>(); int counter3
- * = 0; for (int three = 0; three < cagingColor.length - 1; three++)
- * { Time.sleep(500); cagingSpots =
- * ImageUtil.getPointsWithColor(Game.getImage(), Game.VIEWPORT,
- * cagingColor[three]); if (cagingSpots.size() > 0) {
- * points2.add(counter3, cagingSpots.get(0)); counter3++; } }
- *
- * for (int fisher = 0; fisher < points2.size(); fisher++) {
- * log(fisher + " = " + points2.get(fisher));
- * Mouse.move(points2.get(fisher)); Time.sleep(1000); if (fisher >
- * 10) { break; } if (OCR.getUpText().contains("Cage")) {
- * Mouse.click(); pointCheck = spot; fishing = true;
- * Time.sleep(2500); break; } } }
- */
- }
- return 1;
- }
- public boolean checkFC() {
- if (lobsters) {
- for (int C = 0; C < 2; C++) {
- CFR = getRectangleSpots(grid, 0, CFC);
- for (Rectangle R : CFR) {
- if (Calculations.getDistanceBetween(
- new Point((int) R.getCenterX(), (int) R
- .getCenterY()), new Point(259, 173)) < 31) {
- return true;
- }
- wait(150, 250);
- }
- wait(200, 300);
- }
- } else {
- // for (int C = 0; C < 5; C++) {
- // harpoonRects = getRectangleSpots(grid, 0, CFH);
- // for (Rectangle R : harpoonRects) {
- // log(Calculations.getDistanceBetween(
- // new Point((int) R.getCenterX(), (int) R
- // .getCenterY()), new Point(245, 143)));
- //
- // if (Calculations.getDistanceBetween(
- // new Point((int) R.getCenterX(), (int) R
- // .getCenterY()), new Point(245, 143)) < 14) {
- // return true;
- // }
- // wait(150, 250);
- // }
- // wait(200, 300);
- // }
- waitForInv(1500);
- }
- return false;
- }
- public boolean checkHead() {
- headRects = grid.getContaining(5, headColor);
- for (Rectangle h : headRects) {
- if (h.contains(headPoint)) {
- return true;
- }
- }
- // for (Point p : ImageUtil.getPointsWithColor(Game.getImage(),
- // headColor, 5)) {
- // if (Calculations.getDistanceBetween(p, headPoint) < 5) {
- // return true;
- // }
- // }
- return false;
- }
- public boolean rectangleContainsColor(Rectangle r, Color c, int tol) {
- for (int w = 0; w < r.width; w++) {
- for (int h = 0; h < r.height; h++) {
- if (isColor(
- ImageUtil.getColorAt(Game.getImage(), new Point(w, h)),
- c, tol)) {
- return true;
- }
- }
- }
- return false;
- }
- public Color[] getHeadColorRectangle() {
- LinkedList<Color> c = new LinkedList<Color>();
- for (int w = 0; w < headRect.width; w++) {
- for (int h = 0; h < headRect.height; h++) {
- c.add(ImageUtil.getColorAt(Game.getImage(), new Point(w, h)));
- }
- }
- return (Color[]) c.toArray(new Color[c.size()]);
- }
- public Color getHeadColor() {
- return ImageUtil.getColorAt(Game.getImage(), headPoint);
- }
- public String addCommas(int d, boolean money) {
- DecimalFormat twoDForm = new DecimalFormat("###,###");
- if (money) {
- twoDForm = new DecimalFormat("$###,###");
- return twoDForm.format(d);
- }
- return twoDForm.format(d);
- }
- public void checkXP() {
- sTrack.update();
- wait(150, 350);
- if (startXP == 0) {
- startXP = sTrack.getExperience();
- startLVL = Skills.Skill.FISHING.getLevel();
- }
- curXP = sTrack.getExperience();
- curLVL = Skills.Skill.FISHING.getLevel();
- getNextLVLXP = Skills.Skill.FISHING.getExperienceToLevel();
- }
- public void wait(int r1, int r2) {
- Time.sleep(r1, r2);
- }
- public Color[] getColorArrayFromImage(BufferedImage i) {
- Color[] colorArray = new Color[i.getWidth() * i.getHeight()];
- int counter = 0;
- for (int width = 0; width < i.getWidth(); width++) {
- for (int height = 0; height < i.getHeight(); height++) {
- int clr = i.getRGB(width, height);
- int red = (clr & 0x00ff0000) >> 16;
- int green = (clr & 0x0000ff00) >> 8;
- int blue = clr & 0x000000ff;
- colorArray[counter] = new Color(red, green, blue);
- counter++;
- }
- }
- return colorArray;
- }
- public void checkInventory() {
- final int count = Inventory.getCount();
- if (lastInvCount == 0) {
- lastInvCount = count;
- return;
- }
- if (count > lastInvCount) {
- fishCount = fishCount + (count - lastInvCount);
- lastInvCount = count;
- curXP = startXP + (90 * fishCount);
- }
- }
- public void exchange() {
- rects2 = grid.getContaining(1, rColor);
- if (rects2.length > 0) {
- int failCount = 0;
- for (Rectangle r : rects2) {
- if (failCount > 1) {
- break;
- }
- Mouse.move(new Point((int) r.getCenterX(), (int) r.getCenterY()));
- wait(500, 600);
- Mouse.click(false);
- wait(700, 800);
- if (Menu.find() != null && Menu.find().contains("Exchange")) {
- Menu.interact("Exchange");
- atStiles = true;
- Time.sleep(750);
- Mouse.move(Mouse.getLocation().x,
- Mouse.getLocation().y + 46);
- Time.sleep(3750);
- break;
- } else {
- failCount++;
- Menu.interact("Cancel");
- }
- }
- if (!Inventory.isFull()) {
- exchange = false;
- walkToLobs = true;
- lastInvCount = 0;
- } else {
- if (!atStiles) {
- walkToStiles();
- }
- }
- }
- }
- public void fish() {
- if (lobsters) {
- Rectangle last = null;
- boolean con;
- rects = getRectangleSpots(grid, 5, cagingColor);
- for (Rectangle r : rects) {
- if (last != null) {
- if (Calculations.getDistanceBetween(
- new Point((int) r.getCenterX(), (int) r
- .getCenterY()),
- new Point((int) last.getCenterX(), (int) last
- .getCenterY())) < 30) {
- log("rects too clos");
- con = false;
- } else {
- con = true;
- }
- } else {
- con = true;
- }
- if (r != null && con) {
- Mouse.move((int) r.getCenterX(), (int) r.getCenterY());
- Time.sleep(1000);
- if (OCR.getUpText().contains("Cage")) {
- Mouse.click();
- pointCheck = new Point((int) r.getCenterX(),
- (int) r.getCenterY());
- fishing = true;
- Time.sleep(2500);
- break;
- }
- last = r;
- }
- }
- wait(1000, 2000);
- } else {
- Rectangle last = null;
- boolean con;
- rects = getRectangleSpots(grid, 5, cagingColor);
- for (Rectangle r : rects) {
- if (last != null) {
- if (Calculations.getDistanceBetween(
- new Point((int) r.getCenterX(), (int) r
- .getCenterY()),
- new Point((int) last.getCenterX(), (int) last
- .getCenterY())) < 30) {
- log("rects too clos");
- con = false;
- } else {
- con = true;
- }
- } else {
- con = true;
- }
- if (r != null && con) {
- Mouse.move((int) r.getCenterX(), (int) r.getCenterY());
- Time.sleep(1000);
- if (OCR.getUpText().contains("Cage")) {
- Mouse.click(false);
- if (Menu.find() != null
- && Menu.find().contains("Harpoon")) {
- Menu.interact("Harpoon");
- wait(500, 1000);
- pointCheck = new Point((int) r.getCenterX(),
- (int) r.getCenterY());
- fishing = true;
- break;
- } else {
- Menu.interact("Cancel");
- }
- }
- last = r;
- }
- }
- wait(1000, 2000);
- }
- }
- public Rectangle[] getRectangleSpots(Grid g, int tol, Color... c) {
- Rectangle[] gridRect = g.getContaining(tol, c);
- LinkedList<Rectangle> r = new LinkedList<Rectangle>();
- for (int color = 0; color < c.length; color++) {
- gridRect = g.getContaining(0, c[color]);
- for (int p = 0; p < gridRect.length; p++) {
- if (gridRect.length > 0) {
- if (!r.contains(gridRect[p])) {
- r.add(gridRect[p]);
- }
- }
- }
- }
- // for (int i = 0; i < 5; i++) {
- // gridRect = g.getContaining(tol, c);
- // for (int p = 0; p < gridRect.length; p++) {
- // if (gridRect.length > 0) {
- // if (!r.contains(gridRect[p])) {
- // r.add(gridRect[p]);
- // }
- // }
- // }
- // wait(100, 200);
- // }
- return (Rectangle[]) r.toArray(new Rectangle[r.size()]);
- }
- public LinkedList<Point> findNearestColors(Color[] c) {
- dist = -1;
- LinkedList<Point> POINTS = new LinkedList<Point>();
- LinkedList<Point> lists = new LinkedList<Point>();
- int COUNTER = 0;
- for (int three = 0; three < c.length - 1; three++) {
- lists = ImageUtil.getPointsWithColor(Game.getImage(),
- Game.VIEWPORT, c[three]);
- for (int zero = 0; zero < lists.size(); zero++) {
- POINTS.add(COUNTER, lists.get(zero));
- COUNTER++;
- }
- }
- return POINTS;
- }
- public boolean waitForInv(int wait) {
- int iCount = Inventory.getCount();
- for (int i = 0; i < wait; i++) {
- if (Inventory.getCount() != iCount) {
- return true;
- }
- }
- return false;
- }
- public void walkToStiles() {
- // VectorPath p = new VectorPath(toStilesTest);
- // for (VectorTile tile : toStilesTest) {
- // p.traverse();
- // Time.sleep(6500);
- // if (tile == p.getEnd()) {
- // break;
- // }
- // }
- for (int i = 0; i < toStiles.length; i++) {
- rects2 = grid.getContaining(1, rColor);
- if (rects2.length > 0 && i > 5) {
- break;
- }
- Mouse.click(toStiles[i]);
- if (i > 4) {
- Time.sleep(3500);
- } else {
- Time.sleep(7500);
- }
- }
- atStiles = true;
- Time.sleep(111);
- }
- public void walkToLob() {
- for (Point i : toLob) {
- Mouse.click(i);
- Time.sleep(6850);
- }
- atStiles = false;
- Time.sleep(1546);
- }
- public boolean checkFishing() {
- log("checking if we are fishing");
- LinkedList<Point> points = new LinkedList<Point>();
- int counter2 = 0;
- for (int wait = 0; wait < 500; wait++) {
- cagingSpots = ImageUtil.getPointsWithColors(Game.getImage(),
- Game.VIEWPORT, fC);
- for (int zero = 0; zero < cagingSpots.size(); zero++) {
- points.add(counter2, cagingSpots.get(zero));
- counter2++;
- Time.sleep(100);
- }
- }
- nearest = null;
- dist = 24;
- for (Point point : points) {
- double distTmp = Calculations.getDistanceBetween(point, CHECK);
- if (nearest == null) {
- dist = distTmp;
- nearest = point;
- } else if (distTmp < dist) {
- nearest = point;
- dist = distTmp;
- }
- log("dist = " + dist);
- log("abs = " + Math.abs((CHECK.y - nearest.y)));
- if (Math.abs((CHECK.y - nearest.y)) > 10) {
- log("fishing spot change2?");
- return false;
- }
- }
- return true;
- }
- public boolean stillFishing() {
- LinkedList<Point> points = new LinkedList<Point>();
- int counter2 = 0;
- if (fishing) {
- for (int three = 0; three < cagingColor.length - 1; three++) {
- cagingSpots = ImageUtil.getPointsWithColor(Game.getImage(),
- Game.VIEWPORT, cagingColor[three]);
- for (int zero = 0; zero < cagingSpots.size(); zero++) {
- points.add(counter2, cagingSpots.get(zero));
- counter2++;
- Time.sleep(500);
- }
- }
- nearest = null;
- dist = 24;
- for (Point point : points) {
- double distTmp = Calculations.getDistanceBetween(point, CHECK);
- if (nearest == null) {
- dist = distTmp;
- nearest = point;
- } else if (distTmp < dist) {
- nearest = point;
- dist = distTmp;
- }
- if (dist < 15) {
- return true;
- }
- }
- log("dist = " + dist);
- if (dist > 39) {
- log("fishing spot change?");
- return false;
- }
- }
- return true;
- }
- public void moveMouseOutOfScreen() {
- move(Random.random(10, 293), -1);
- }
- public Point getNearestPoint(LinkedList<Point> p) {
- nearest = null;
- dist = 20;
- for (Point point : p) {
- double distTmp = Calculations.getDistanceBetween(point, CHECK);
- if (nearest == null) {
- dist = distTmp;
- nearest = point;
- } else if (distTmp < dist) {
- nearest = point;
- dist = distTmp;
- }
- }
- return nearest;
- }
- public static void move(int paramInt1, int paramInt2) {
- Point localPoint = Mouse.getLocation();
- q.a(10, localPoint.x, localPoint.y, paramInt1, paramInt2, 0, 0);
- }
- /**
- * @param size
- * the size of the rectangle to look for
- * @param tolerance
- * the tolerance in which you want to allow (0 to 255)
- * @param searchArea
- * the rectangle you would like to search within for the
- * rectangles.
- * @param colors
- * the colors the rectangle must contain
- *
- * @return an array of rectangles containing an array of colors within a
- * tolerance of 'tolerance' inside 'searchArea'.
- *
- * @author Dang
- */
- public static Rectangle[] findRectangles(final int sizeX, final int sizeY,
- final int tolerance, final Rectangle searchArea,
- final Color... colors) {
- final java.util.List<Rectangle> rects = new LinkedList<Rectangle>();
- final int jumpSizeX = sizeX / 2;
- final int jumpSizeY = sizeY / 2;
- final BufferedImage i = Game.getImage();
- for (int x = searchArea.x; x <= searchArea.x + searchArea.width - sizeX; x += jumpSizeX) {
- for (int y = searchArea.y; y <= searchArea.y + searchArea.height
- - sizeY; y += jumpSizeY) {
- final Rectangle r = new Rectangle(x, y, sizeX, sizeY);
- for (int count = 0; count < colors.length; count++) {
- final int[] sub_pixels = i.getRGB(x, y, sizeX, sizeY, null,
- 0, sizeX * sizeY);
- if (imageContains(sub_pixels, colors[count], tolerance)) {
- rects.add(r);
- } else {
- count = colors.length + 1;
- }
- }
- }
- }
- return rects.toArray(new Rectangle[rects.size()]);
- }
- /**
- *
- * @param pixels
- * the pixel values of the image
- * @param color
- * the color to check if the image contains
- * @param tolerance
- * the tolerance to allow
- * @return the image contains 'color'
- */
- public static boolean imageContains(final int[] pixels, final Color color,
- final int tolerance) {
- for (final int pixel : pixels) {
- if (isColor(new Color(pixel), color, tolerance)) {
- return true;
- }
- }
- return false;
- }
- /**
- *
- * @param colorOne
- * the first color to compare
- * @param colorTwo
- * the color to compare 'colorOne' to
- * @param tolerance
- * the tolerance to allow between each color
- * @return if the color's RGS values are within the tolerance given
- */
- public static boolean isColor(final Color colorOne, final Color colorTwo,
- final int tolerance) {
- final int[] one = { colorOne.getRed(), colorOne.getGreen(),
- colorOne.getBlue() };
- final int[] two = { colorTwo.getRed(), colorTwo.getGreen(),
- colorTwo.getBlue() };
- return isWithinTolerance(one[0], two[0], tolerance)
- && isWithinTolerance(one[1], two[1], tolerance)
- && isWithinTolerance(one[2], two[2], tolerance);
- }
- /**
- *
- * @param num
- * the first number to compare
- * @param num2
- * the number to compare to 'num'
- * @param tolerance
- * the amount to allow between the values
- * @return if num and num2 are within the given tolerance of eachother
- */
- public static boolean isWithinTolerance(final int num, final int num2,
- final int tolerance) {
- return num <= num2 + tolerance && num >= num2 - tolerance;
- }
- int rectX, rectY, rectX2, rectY2;
- Rectangle colorRect = null;
- LinkedList<Color> rectColor = new LinkedList<Color>();
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // if (!pickedColor) {
- // rColor = Game.getColorAt(arg0.getPoint());
- // pickedColor = true;
- // walkToLobs = true;
- // }
- }
- @Override
- public void mouseEntered(MouseEvent arg0) {
- }
- @Override
- public void mouseExited(MouseEvent arg0) {
- }
- @Override
- public void mousePressed(MouseEvent arg0) {
- if (!pickedColor) {
- rectX = arg0.getX();
- rectY = arg0.getY();
- }
- }
- @Override
- public void mouseReleased(MouseEvent arg0) {
- // if (!pickedColor) {
- // colorRect = new Rectangle(rectX, rectY, rectX2 - rectX, rectY2
- // - rectY);
- // for (int width = 0; width < colorRect.width; width++) {
- // for (int height = 0; height < colorRect.height; height++) {
- // rectColor.add(Game.getColorAt(colorRect.x + width,
- // colorRect.y + height));
- // }
- // }
- // rColor = rectColor.toArray(new Color[rectColor.size()]);
- // pickedColor = true;
- // walkToLobs = true;
- // }
- }
- @Override
- public void mouseDragged(MouseEvent e) {
- if (!pickedColor) {
- rectX2 = e.getX();
- rectY2 = e.getY();
- colorRect = new Rectangle(rectX, rectY, rectX2 - rectX, rectY2
- - rectY);
- }
- }
- JButton startButton;
- JComboBox whereandwhat;
- JLabel text;
- String[] list = { "Lobsters", "Swordies and Tuna" };
- @Override
- public void mouseMoved(MouseEvent e) {
- }
- public class MegaGUI extends JFrame implements ActionListener {
- public MegaGUI() {
- setTitle("MegaPlanker");
- startButton = new JButton("Start");
- text = new JLabel("What fish?????");
- whereandwhat = new JComboBox(list);
- setLayout(null);
- setResizable(false);
- setSize(390, 255);
- setLocationRelativeTo(null);
- text.setBounds(20, 20, 182, 21);
- startButton.setBounds(135, 148, 83, 28);
- startButton.addActionListener(this);
- whereandwhat.setBounds(65, 71, 200, 22);
- add(text);
- add(whereandwhat);
- add(startButton);
- setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().contains("Start")) {
- if (whereandwhat.getSelectedItem().toString()
- .equals("Lobsters")) {
- lobsters = true;
- } else {
- lobsters = false;
- }
- dispose();
- setVisible(false);
- start = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment