diff --git a/src/CameraCalibrator.java b/src/CameraCalibrator.java index 8444054..3704f19 100644 --- a/src/CameraCalibrator.java +++ b/src/CameraCalibrator.java @@ -25,7 +25,7 @@ public class CameraCalibrator { randomlyRotateKeyboard(); screenCapture = objectDetector.captureScreenshotGameWindow(); detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30); - objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor); + detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor); } } diff --git a/src/IronMiner.java b/src/IronMiner.java index ee4daf1..d2b267b 100644 --- a/src/IronMiner.java +++ b/src/IronMiner.java @@ -46,7 +46,7 @@ public class IronMiner { public void run() throws Exception { long startTime = System.currentTimeMillis(); - long garbageCollectionTime = System.currentTimeMillis(); + long garbageCollectionTime = System.currentTimeMillis() + 60 * 5 * 1000; int framesWithoutObjects = 0; while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 85) { @@ -103,10 +103,10 @@ public class IronMiner { // Garbage Collection - if (((System.currentTimeMillis() - garbageCollectionTime) / 1000.0 / 60) > 10) { + if (((System.currentTimeMillis() - garbageCollectionTime) / 1000.0 / 60) > 0) { System.out.println("Running garbage collection."); System.gc(); - garbageCollectionTime = System.currentTimeMillis() + randomizer.nextGaussianWithinRange(8500, 19340); + garbageCollectionTime = System.currentTimeMillis() + randomizer.nextGaussianWithinRange(8500, 19340) * 60; } dropInventoryIfFull(); } @@ -140,32 +140,6 @@ public class IronMiner { return null; } - /*private Mat getMatFromBufferedImage(BufferedImage image) { - BufferedImage formattedImage = convertBufferedImage(image, BufferedImage.TYPE_3BYTE_BGR); - byte[] data = ((DataBufferByte) formattedImage.getData().getDataBuffer()).getData(); - bgr2rgb(data); - Mat matImage = new Mat(formattedImage.getWidth(), formattedImage.getHeight(), CvType.CV_8UC3); - byte[] pixels = ((DataBufferByte) formattedImage.getRaster().getDataBuffer()).getData(); - matImage.put(0, 0, pixels); - return matImage; - } - - private static BufferedImage convertBufferedImage(BufferedImage sourceImage, int bufferedImageType) { - BufferedImage image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), bufferedImageType); - Graphics2D g2d = image.createGraphics(); - g2d.drawImage(sourceImage, 0, 0, null); - g2d.dispose(); - return image; - } - - private static void bgr2rgb(byte[] data) { - for (int i = 0; i < data.length; i += 3) { - byte tmp = data[i]; - data[i] = data[i + 2]; - data[i + 2] = tmp; - } - }*/ - public int getDistanceBetweenPoints(Point startingPoint, Point goalPoint) { return (int) (Math.hypot(goalPoint.x - startingPoint.x, goalPoint.y - startingPoint.y)); } diff --git a/src/RandomDetector.java b/src/RandomDetector.java new file mode 100644 index 0000000..bcdcdeb --- /dev/null +++ b/src/RandomDetector.java @@ -0,0 +1,50 @@ +import java.awt.AWTException; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.image.BufferedImage; + +public class RandomDetector { + Robot robot; + + public RandomDetector() throws AWTException { + robot = new Robot(); + } + + public void dealWithRandoms(BufferedImage screenCapture) throws AWTException, InterruptedException { + if (isRandomEventPresent(screenCapture)) { + System.out.println("Deal with random here"); + } + } + + public boolean isRandomEventPresent(BufferedImage screenCapture) throws AWTException, InterruptedException + { + // only do this if it's close to center + boolean foundDialogue = false; + for (int x = 0; x < Constants.GAME_WINDOW_WIDTH; x += 5) { + for (int y = 0; y < Constants.GAME_WINDOW_HEIGHT; y += 1) { + int color = screenCapture.getRGB(x, y); + if (pixelsAreWithinRGBTolerance(color, 10)) { + return true; + } + + } + } + return false; + } + + private boolean pixelsAreWithinRGBTolerance(int rgb1, int rgb2) { + int[] colors1 = getRGBValuesFromPixel(rgb1); + int[] colors2 = getRGBValuesFromPixel(rgb2); + for (int i = 0; i < 3; i++) { + if (Math.abs(colors1[i] - colors2[i]) > 3) { + return false; + } + } + return true; + } + + private int[] getRGBValuesFromPixel(int pixel) { + int[] colors = {(pixel)&0xFF, (pixel>>8)&0xFF, (pixel>>16)&0xFF, (pixel>>24)&0xFF}; + return colors; + } +} diff --git a/target/classes/CameraCalibrator.class b/target/classes/CameraCalibrator.class index 4bd1245..5c38d75 100644 Binary files a/target/classes/CameraCalibrator.class and b/target/classes/CameraCalibrator.class differ diff --git a/target/classes/IronMiner.class b/target/classes/IronMiner.class index 8a9a8f6..0a5cc45 100644 Binary files a/target/classes/IronMiner.class and b/target/classes/IronMiner.class differ diff --git a/target/classes/RandomDetector.class b/target/classes/RandomDetector.class new file mode 100644 index 0000000..93141b9 Binary files /dev/null and b/target/classes/RandomDetector.class differ