1
0
mirror of https://github.com/davpapp/PowerMiner synced 2024-11-14 05:25:08 -05:00

World hopping working but very hacky

This commit is contained in:
davpapp 2018-03-15 20:52:57 -04:00
parent 33b07054dd
commit b232e57ec4
14 changed files with 75 additions and 73 deletions

View File

@ -36,7 +36,7 @@ public class Constants {
public static final int INVENTORY_ICON_HEIGHT = 25;
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_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_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() {
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);
}
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() {
return new Rectangle(MINING_XP_STAT_OFFSET_X, MINING_XP_STAT_OFFSET_Y, MINING_XP_STAT_WIDTH, MINING_XP_STAT_HEIGHT);
}

View File

@ -11,7 +11,7 @@ public class InventoryItem {
public InventoryItem(String itemDirectoryPath, String itemName) throws IOException {
initializeImage(itemDirectoryPath, itemName);
this.minimumNumberOfMatchingPixels = 200;
this.minimumNumberOfMatchingPixels = 250;
}
private void initializeImage(String itemDirectoryPath, String itemName) throws IOException {

View File

@ -34,7 +34,6 @@ public class IronMiner {
HumanBehavior humanBehavior;
CameraCalibrator cameraCalibrator;
RandomDetector randomDetector;
WorldHopper worldHopper;
MiningSuccessHistory miningSuccessHistory;
ObjectDetectionHistory objectDetectionHistory;
@ -48,7 +47,6 @@ public class IronMiner {
robot = new Robot();
humanBehavior = new HumanBehavior();
randomDetector = new RandomDetector();
worldHopper = new WorldHopper();
cameraCalibrator = new CameraCalibrator(targetNumberOfDetectedOres);
miningSuccessHistory = new MiningSuccessHistory();
objectDetectionHistory = new ObjectDetectionHistory(targetNumberOfDetectedOres);
@ -56,9 +54,10 @@ public class IronMiner {
public void run() throws Exception {
long startTime = System.currentTimeMillis();
int worldHopCounter = 0;
int count = 0;
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 85) {
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 93) {
BufferedImage screenCapture = objectDetector.captureScreenshotGameWindow();
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
@ -68,11 +67,13 @@ public class IronMiner {
DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres);
if (closestIronOre != null) {
Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
int ironOreInInventory = inventory.getFirstIronOreInInventory();
int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
int numberOfOresInInventoryAfter = 0;
boolean miningSuccess = false;
if (ironOreInInventory > -1) {
int ironOreInInventoryColumn = ironOreInInventory % 7;
@ -89,27 +90,30 @@ public class IronMiner {
trackerThread.waitTillDone();
dropperThread.waitTillDone();
Point rightClickLocation = cursor.getCurrentCursorPoint();
cursorTask.leftClickDropOption(cursor, rightClickLocation, 0);
numberOfOresInInventoryAfter = inventory.getNumberOfItemsOfTypeInInventory("ironOre") + 1;
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") >= numberOfOresInInventoryBefore) {
miningSuccess = true;
}
}
else {
TrackerThread trackerThread = new TrackerThread(screenCapture, closestIronOre, objectDetector);
trackerThread.start();
trackerThread.waitTillDone();
numberOfOresInInventoryAfter = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") > numberOfOresInInventoryBefore) {
miningSuccess = true;
}
}
count++;
boolean miningSuccess = (numberOfOresInInventoryAfter > numberOfOresInInventoryBefore);
//System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
System.out.println(count + ", time: " + ((System.currentTimeMillis() - startTime) / 1000 / 60));
System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
if (worldHopped) {
worldHopCounter++;
}
System.out.println(count + ", time: " + ((System.currentTimeMillis() - startTime) / 1000 / 60) + ". Hops: " + worldHopCounter);
}
humanBehavior.randomlyCheckMiningXP(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);
if (hopWorld) {
//System.out.println("Hopping worlds (Theoretically)");
System.out.println("Hopping worlds");
WorldHopper.hopWorld(cursor);
miningSuccessHistory.resetQueue();
return true;
}
return false;
}
private void readjustCameraIfObjectsAreNotBeingDetected(int detectedObjectsSize) throws Exception {

View File

@ -29,7 +29,7 @@ public class MiningSuccessHistory {
}
private boolean isMiningRateSufficient() {
return numberOfTruesInQueue < (queueSize * 0.6);
return numberOfTruesInQueue < (queueSize * 0.8);
}
public void resetQueue() {

View File

@ -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();
}
}

View File

@ -29,6 +29,9 @@ public class RandomDetector {
cursor.moveAndLeftClickAtCoordinatesWithRandomness(cursor.getOffsetPoint(getDismissOptionClickLocation(speakerPoint)), 40, 10, 6);
Thread.sleep(1743, 2313);
}
else {
cursor.moveCursorToCoordinatesWithRandomness(new Point(Constants.GAME_WINDOW_OFFSET_X, Constants.GAME_WINDOW_OFFSET_Y), 20, 20);
}
}
}

View File

@ -1,52 +1,36 @@
import java.awt.AWTException;
import java.awt.Point;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
public class WorldHopper {
int numberOfOresMined;
int queueSize;
//int numberOfFramesWithOtherPlayers;
//Queue<Boolean> frames;
Queue<Boolean> oresMined;
//Set<Integer> visitedWorlds;
public WorldHopper() {
numberOfOresMined = 0;
queueSize = 30;
//numberOfFramesWithOtherPlayers = 0;
//frames = new LinkedList<Boolean>();
/*for (int i = 0; i < 600; i++) {
frames.add(false);
}*/
oresMined = new LinkedList<Boolean>();
for (int i = 0; i < queueSize; i++) {
oresMined.add(true);
}
}
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() {
public static void hopWorld(Cursor cursor) throws Exception {
cursor.moveAndLeftClickInBoundingRectangle(Constants.getLogoutIconRectangle());
Thread.sleep(650, 900);
//cursor.moveAndLeftClickInBoundingRectangle(Constants.getWorldSwitchButtonRectangle());
Thread.sleep(2150, 3080);
Random random = new Random();
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;
cursor.moveAndLeftClickAtCoordinates(new Point(x, y));
Thread.sleep(4300, 5320);
cursor.moveAndLeftClickInBoundingRectangle(Constants.getInventoryIconRectangle());
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.