World hopping working but very hacky
This commit is contained in:
parent
33b07054dd
commit
b232e57ec4
|
@ -36,7 +36,7 @@ public class Constants {
|
||||||
public static final int INVENTORY_ICON_HEIGHT = 25;
|
public static final int INVENTORY_ICON_HEIGHT = 25;
|
||||||
|
|
||||||
public static final int LOGOUT_ICON_OFFSET_X = 728;
|
public static final int LOGOUT_ICON_OFFSET_X = 728;
|
||||||
public static final int LOGOUT_ICON_OFFSET_Y = 528;
|
public static final int LOGOUT_ICON_OFFSET_Y = 545;
|
||||||
public static final int LOGOUT_ICON_WIDTH = 25;
|
public static final int LOGOUT_ICON_WIDTH = 25;
|
||||||
public static final int LOGOUT_ICON_HEIGHT = 25;
|
public static final int LOGOUT_ICON_HEIGHT = 25;
|
||||||
|
|
||||||
|
@ -47,6 +47,19 @@ public class Constants {
|
||||||
public static final int MINING_XP_STAT_WIDTH = 50;
|
public static final int MINING_XP_STAT_WIDTH = 50;
|
||||||
public static final int MINING_XP_STAT_HEIGHT = 23;
|
public static final int MINING_XP_STAT_HEIGHT = 23;
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------- OTHER -----------------------------------------
|
||||||
|
|
||||||
|
public static final int WORLD_SWITCH_BUTTON_OFFSET_X = 674;
|
||||||
|
public static final int WORLD_SWITCH_BUTTON_OFFSET_Y = 454;
|
||||||
|
public static final int WORLD_SWITCH_BUTTON_WIDTH = 130;
|
||||||
|
public static final int WORLD_SWITCH_BUTTON_HEIGHT = 23;
|
||||||
|
|
||||||
|
public static final int WORLD_LISTING_OFFSET_X = 665;
|
||||||
|
public static final int WORLD_LISTING_OFFSET_Y = 320;
|
||||||
|
public static final int WORLD_LISTING_WIDTH = 150;
|
||||||
|
public static final int WORLD_LISTING_HEIGHT = 187;
|
||||||
|
|
||||||
public static Point getCharacterLocation() {
|
public static Point getCharacterLocation() {
|
||||||
return new Point(CHARACTER_CENTER_X, CHARACTER_CENTER_Y);
|
return new Point(CHARACTER_CENTER_X, CHARACTER_CENTER_Y);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +76,14 @@ public class Constants {
|
||||||
return new Rectangle(LOGOUT_ICON_OFFSET_X, LOGOUT_ICON_OFFSET_Y, LOGOUT_ICON_WIDTH, LOGOUT_ICON_HEIGHT);
|
return new Rectangle(LOGOUT_ICON_OFFSET_X, LOGOUT_ICON_OFFSET_Y, LOGOUT_ICON_WIDTH, LOGOUT_ICON_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Rectangle getWorldSwitchButtonRectangle() {
|
||||||
|
return new Rectangle(WORLD_SWITCH_BUTTON_OFFSET_X, WORLD_SWITCH_BUTTON_OFFSET_Y, WORLD_SWITCH_BUTTON_WIDTH, WORLD_SWITCH_BUTTON_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Rectangle getWorldListingRectangle() {
|
||||||
|
return new Rectangle(WORLD_LISTING_OFFSET_X, WORLD_LISTING_OFFSET_Y, WORLD_LISTING_WIDTH, WORLD_LISTING_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
public static Rectangle getMiningXPRectangle() {
|
public static Rectangle getMiningXPRectangle() {
|
||||||
return new Rectangle(MINING_XP_STAT_OFFSET_X, MINING_XP_STAT_OFFSET_Y, MINING_XP_STAT_WIDTH, MINING_XP_STAT_HEIGHT);
|
return new Rectangle(MINING_XP_STAT_OFFSET_X, MINING_XP_STAT_OFFSET_Y, MINING_XP_STAT_WIDTH, MINING_XP_STAT_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class InventoryItem {
|
||||||
|
|
||||||
public InventoryItem(String itemDirectoryPath, String itemName) throws IOException {
|
public InventoryItem(String itemDirectoryPath, String itemName) throws IOException {
|
||||||
initializeImage(itemDirectoryPath, itemName);
|
initializeImage(itemDirectoryPath, itemName);
|
||||||
this.minimumNumberOfMatchingPixels = 200;
|
this.minimumNumberOfMatchingPixels = 250;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeImage(String itemDirectoryPath, String itemName) throws IOException {
|
private void initializeImage(String itemDirectoryPath, String itemName) throws IOException {
|
||||||
|
|
|
@ -34,7 +34,6 @@ public class IronMiner {
|
||||||
HumanBehavior humanBehavior;
|
HumanBehavior humanBehavior;
|
||||||
CameraCalibrator cameraCalibrator;
|
CameraCalibrator cameraCalibrator;
|
||||||
RandomDetector randomDetector;
|
RandomDetector randomDetector;
|
||||||
WorldHopper worldHopper;
|
|
||||||
MiningSuccessHistory miningSuccessHistory;
|
MiningSuccessHistory miningSuccessHistory;
|
||||||
ObjectDetectionHistory objectDetectionHistory;
|
ObjectDetectionHistory objectDetectionHistory;
|
||||||
|
|
||||||
|
@ -48,7 +47,6 @@ public class IronMiner {
|
||||||
robot = new Robot();
|
robot = new Robot();
|
||||||
humanBehavior = new HumanBehavior();
|
humanBehavior = new HumanBehavior();
|
||||||
randomDetector = new RandomDetector();
|
randomDetector = new RandomDetector();
|
||||||
worldHopper = new WorldHopper();
|
|
||||||
cameraCalibrator = new CameraCalibrator(targetNumberOfDetectedOres);
|
cameraCalibrator = new CameraCalibrator(targetNumberOfDetectedOres);
|
||||||
miningSuccessHistory = new MiningSuccessHistory();
|
miningSuccessHistory = new MiningSuccessHistory();
|
||||||
objectDetectionHistory = new ObjectDetectionHistory(targetNumberOfDetectedOres);
|
objectDetectionHistory = new ObjectDetectionHistory(targetNumberOfDetectedOres);
|
||||||
|
@ -56,9 +54,10 @@ public class IronMiner {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
int worldHopCounter = 0;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 85) {
|
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 93) {
|
||||||
BufferedImage screenCapture = objectDetector.captureScreenshotGameWindow();
|
BufferedImage screenCapture = objectDetector.captureScreenshotGameWindow();
|
||||||
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
|
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
|
||||||
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
|
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
|
||||||
|
@ -68,11 +67,13 @@ public class IronMiner {
|
||||||
DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres);
|
DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres);
|
||||||
|
|
||||||
if (closestIronOre != null) {
|
if (closestIronOre != null) {
|
||||||
|
Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
|
||||||
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
|
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
|
||||||
|
|
||||||
int ironOreInInventory = inventory.getFirstIronOreInInventory();
|
int ironOreInInventory = inventory.getFirstIronOreInInventory();
|
||||||
|
|
||||||
int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
|
int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
|
||||||
int numberOfOresInInventoryAfter = 0;
|
boolean miningSuccess = false;
|
||||||
|
|
||||||
if (ironOreInInventory > -1) {
|
if (ironOreInInventory > -1) {
|
||||||
int ironOreInInventoryColumn = ironOreInInventory % 7;
|
int ironOreInInventoryColumn = ironOreInInventory % 7;
|
||||||
|
@ -89,27 +90,30 @@ public class IronMiner {
|
||||||
trackerThread.waitTillDone();
|
trackerThread.waitTillDone();
|
||||||
dropperThread.waitTillDone();
|
dropperThread.waitTillDone();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Point rightClickLocation = cursor.getCurrentCursorPoint();
|
Point rightClickLocation = cursor.getCurrentCursorPoint();
|
||||||
cursorTask.leftClickDropOption(cursor, rightClickLocation, 0);
|
cursorTask.leftClickDropOption(cursor, rightClickLocation, 0);
|
||||||
|
|
||||||
numberOfOresInInventoryAfter = inventory.getNumberOfItemsOfTypeInInventory("ironOre") + 1;
|
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") >= numberOfOresInInventoryBefore) {
|
||||||
|
miningSuccess = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TrackerThread trackerThread = new TrackerThread(screenCapture, closestIronOre, objectDetector);
|
TrackerThread trackerThread = new TrackerThread(screenCapture, closestIronOre, objectDetector);
|
||||||
trackerThread.start();
|
trackerThread.start();
|
||||||
trackerThread.waitTillDone();
|
trackerThread.waitTillDone();
|
||||||
|
|
||||||
numberOfOresInInventoryAfter = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
|
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") > numberOfOresInInventoryBefore) {
|
||||||
|
miningSuccess = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
boolean miningSuccess = (numberOfOresInInventoryAfter > numberOfOresInInventoryBefore);
|
System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
|
||||||
//System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
|
boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
|
||||||
hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
|
if (worldHopped) {
|
||||||
|
worldHopCounter++;
|
||||||
System.out.println(count + ", time: " + ((System.currentTimeMillis() - startTime) / 1000 / 60));
|
}
|
||||||
|
System.out.println(count + ", time: " + ((System.currentTimeMillis() - startTime) / 1000 / 60) + ". Hops: " + worldHopCounter);
|
||||||
}
|
}
|
||||||
humanBehavior.randomlyCheckMiningXP(cursor);
|
humanBehavior.randomlyCheckMiningXP(cursor);
|
||||||
randomDetector.dealWithRandoms(screenCapture, cursor);
|
randomDetector.dealWithRandoms(screenCapture, cursor);
|
||||||
|
@ -117,12 +121,15 @@ public class IronMiner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hopWorldsIfMiningSuccessRateIsLow(boolean miningSuccess) {
|
private boolean hopWorldsIfMiningSuccessRateIsLow(boolean miningSuccess) throws Exception {
|
||||||
boolean hopWorld = miningSuccessHistory.updateHistory(miningSuccess);
|
boolean hopWorld = miningSuccessHistory.updateHistory(miningSuccess);
|
||||||
if (hopWorld) {
|
if (hopWorld) {
|
||||||
//System.out.println("Hopping worlds (Theoretically)");
|
System.out.println("Hopping worlds");
|
||||||
|
WorldHopper.hopWorld(cursor);
|
||||||
miningSuccessHistory.resetQueue();
|
miningSuccessHistory.resetQueue();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readjustCameraIfObjectsAreNotBeingDetected(int detectedObjectsSize) throws Exception {
|
private void readjustCameraIfObjectsAreNotBeingDetected(int detectedObjectsSize) throws Exception {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class MiningSuccessHistory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMiningRateSufficient() {
|
private boolean isMiningRateSufficient() {
|
||||||
return numberOfTruesInQueue < (queueSize * 0.6);
|
return numberOfTruesInQueue < (queueSize * 0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetQueue() {
|
public void resetQueue() {
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
|
|
||||||
public class MultiThreadingExample {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
System.out.println("Starting multithreading...");
|
|
||||||
TrackerThread trackerThread = new TrackerThread();
|
|
||||||
trackerThread.start();
|
|
||||||
DropperThread dropperThread = new DropperThread();
|
|
||||||
dropperThread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -29,6 +29,9 @@ public class RandomDetector {
|
||||||
cursor.moveAndLeftClickAtCoordinatesWithRandomness(cursor.getOffsetPoint(getDismissOptionClickLocation(speakerPoint)), 40, 10, 6);
|
cursor.moveAndLeftClickAtCoordinatesWithRandomness(cursor.getOffsetPoint(getDismissOptionClickLocation(speakerPoint)), 40, 10, 6);
|
||||||
Thread.sleep(1743, 2313);
|
Thread.sleep(1743, 2313);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
cursor.moveCursorToCoordinatesWithRandomness(new Point(Constants.GAME_WINDOW_OFFSET_X, Constants.GAME_WINDOW_OFFSET_Y), 20, 20);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,52 +1,36 @@
|
||||||
|
import java.awt.AWTException;
|
||||||
|
import java.awt.Point;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class WorldHopper {
|
public class WorldHopper {
|
||||||
|
|
||||||
int numberOfOresMined;
|
//Set<Integer> visitedWorlds;
|
||||||
int queueSize;
|
|
||||||
//int numberOfFramesWithOtherPlayers;
|
|
||||||
//Queue<Boolean> frames;
|
|
||||||
Queue<Boolean> oresMined;
|
|
||||||
|
|
||||||
public WorldHopper() {
|
public static void hopWorld(Cursor cursor) throws Exception {
|
||||||
numberOfOresMined = 0;
|
cursor.moveAndLeftClickInBoundingRectangle(Constants.getLogoutIconRectangle());
|
||||||
queueSize = 30;
|
Thread.sleep(650, 900);
|
||||||
//numberOfFramesWithOtherPlayers = 0;
|
//cursor.moveAndLeftClickInBoundingRectangle(Constants.getWorldSwitchButtonRectangle());
|
||||||
//frames = new LinkedList<Boolean>();
|
Thread.sleep(2150, 3080);
|
||||||
/*for (int i = 0; i < 600; i++) {
|
Random random = new Random();
|
||||||
frames.add(false);
|
int x = random.nextInt(Constants.WORLD_LISTING_WIDTH) + Constants.WORLD_LISTING_OFFSET_X;
|
||||||
}*/
|
int y = random.nextInt(Constants.WORLD_LISTING_HEIGHT) + Constants.WORLD_LISTING_OFFSET_Y;
|
||||||
oresMined = new LinkedList<Boolean>();
|
cursor.moveAndLeftClickAtCoordinates(new Point(x, y));
|
||||||
for (int i = 0; i < queueSize; i++) {
|
Thread.sleep(4300, 5320);
|
||||||
oresMined.add(true);
|
cursor.moveAndLeftClickInBoundingRectangle(Constants.getInventoryIconRectangle());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hopWorldsIfMiningRateLow() {
|
|
||||||
updateOresMinedSuccessTracking();
|
|
||||||
if (areOtherPlayersLikelyPresent()) {
|
|
||||||
hopWorld();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void updateOresMinedSuccessTracking(boolean success) {
|
|
||||||
oresMined.add(success);
|
|
||||||
if (success) {
|
|
||||||
numberOfOresMined++;
|
|
||||||
}
|
|
||||||
if (oresMined.poll()) {
|
|
||||||
numberOfOresMined--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean areOtherPlayersLikelyPresent() {
|
|
||||||
return numberOfOresMined < (queueSize * 0.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hopWorld() {
|
|
||||||
System.out.println("Hopping worlds!");
|
System.out.println("Hopping worlds!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
Cursor cursor = new Cursor();
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
WorldHopper.hopWorld(cursor);
|
||||||
|
Thread.sleep(2500);
|
||||||
|
}
|
||||||
|
System.out.println("Done hopping...");
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue