Skip to content

Commit

Permalink
version 1.2.6 fix ReRun on steam (#17)
Browse files Browse the repository at this point in the history
* no more throw when image not found on resource, only throw when attemp to use it

* trigger stop app when error occured

* fixed ReRun on Steam

* up version 1.2.6

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Aug 30, 2021
1 parent eb1cb4d commit 428c2e2
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 352 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>bh.bot</groupId>
<artifactId>BitHeroes</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>

<dependencies>
</dependencies>
Expand Down
171 changes: 101 additions & 70 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ protected boolean clickImage(BwMatrixMeta im) {
}

protected Point findImageBasedOnLastClick(BwMatrixMeta im) {
im.throwIfNotAvailable();

int[] lastMatch = im.getLastMatchPoint();
if (lastMatch[0] < 0 || lastMatch[1] < 0) {
return null;
Expand Down Expand Up @@ -228,6 +230,8 @@ protected Point findImageBasedOnLastClick(BwMatrixMeta im) {
}

protected Point scanToFindImage(BwMatrixMeta im) {
im.throwIfNotAvailable();

ScreenCapturedResult screenCapturedResult = captureElementInEstimatedArea(im);
BufferedImage sc = screenCapturedResult.image;

Expand Down Expand Up @@ -306,6 +310,8 @@ protected boolean clickImageScanBW(BwMatrixMeta im) {
}

protected Point detectLabel(BwMatrixMeta im, int... mainColors) {
im.throwIfNotAvailable();

ScreenCapturedResult screenCapturedResult = captureElementInEstimatedArea(im);
BufferedImage sc = screenCapturedResult.image;
try {
Expand Down Expand Up @@ -372,6 +378,8 @@ protected Point detectLabelFishing() {

protected Tuple2<Point[], Byte> detectRadioButtons(Rectangle scanRect) {
final BwMatrixMeta im = BwMatrixMeta.Metas.Globally.Buttons.radioButton;
im.throwIfNotAvailable();

int positionTolerant = Math.min(10, Configuration.Tolerant.position);
ScreenCapturedResult screenCapturedResult = captureElementInEstimatedArea(
new Configuration.Offset(
Expand Down Expand Up @@ -481,98 +489,121 @@ protected Tuple2<Point[], Byte> detectRadioButtons(Rectangle scanRect) {
}

protected void doClickTalk(Supplier<Boolean> shouldStop) {
int sleepSecs = 60;
int sleepSecsWhenClicked = 3;
int cnt = sleepSecs;
while (!shouldStop.get()) {
cnt--;
sleep(1000);
if (cnt > 0) {
continue;
}
try {
int sleepSecs = 60;
int sleepSecsWhenClicked = 3;
int cnt = sleepSecs;
while (!shouldStop.get()) {
cnt--;
sleep(1000);
if (cnt > 0) {
continue;
}

cnt = sleepSecs;
if (clickImage(BwMatrixMeta.Metas.Globally.Buttons.talkRightArrow)) {
debug("clicked talk");
cnt = sleepSecsWhenClicked;
} else {
debug("No talk");
cnt = sleepSecs;
if (clickImage(BwMatrixMeta.Metas.Globally.Buttons.talkRightArrow)) {
debug("clicked talk");
cnt = sleepSecsWhenClicked;
} else {
debug("No talk");
}
}
} catch (Exception ex) {
ex.printStackTrace();
Telegram.sendMessage("Error occurs during execution: " + ex.getMessage(), true);
}
}

protected void detectDisconnected(AtomicBoolean masterSwitch) {
int sleepSecs = 60;
int cnt = sleepSecs;
while (!masterSwitch.get()) {
cnt--;
sleep(1000);
if (cnt > 0) {
continue;
}
try {
int sleepSecs = 60;
int cnt = sleepSecs;
while (!masterSwitch.get()) {
cnt--;
sleep(1000);
if (cnt > 0) {
continue;
}

cnt = sleepSecs;
if (clickImage(BwMatrixMeta.Metas.Globally.Buttons.reconnect)) {
masterSwitch.set(true);
Telegram.sendMessage("Disconnected", true);
cnt = sleepSecs;
if (clickImage(BwMatrixMeta.Metas.Globally.Buttons.reconnect)) {
masterSwitch.set(true);
Telegram.sendMessage("Disconnected", true);
}
}
} catch (Exception ex) {
ex.printStackTrace();
Telegram.sendMessage("Error occurs during execution: " + ex.getMessage(), true);
masterSwitch.set(true);
}
}

protected void autoReactiveAuto(AtomicBoolean masterSwitch) {
final int sleepMs = 10_000;
int continousRed = 0;
final int maxContinousRed = 6;
while (!masterSwitch.get()) {
sleep(sleepMs);
Point point = findImage(BwMatrixMeta.Metas.Globally.Buttons.autoG);
if (point == null) {
debug("AutoG button not found");
point = findImage(BwMatrixMeta.Metas.Globally.Buttons.autoR);
try {
final int sleepMs = 10_000;
int continousRed = 0;
final int maxContinousRed = 6;
while (!masterSwitch.get()) {
sleep(sleepMs);
Point point = findImage(BwMatrixMeta.Metas.Globally.Buttons.autoG);
if (point == null) {
debug("AutoR button not found");
debug("AutoG button not found");
point = findImage(BwMatrixMeta.Metas.Globally.Buttons.autoR);
if (point == null) {
debug("AutoR button not found");
continue;
}
}
debug("Found the Auto button at %d,%d", point.x, point.y);
Color color = getPixelColor(point.x - 5, point.y);
if (ImageUtil.isGreenLikeColor(color)) {
debug("Auto is currently ON (green)");
continousRed = 0;
continue;
}
}
debug("Found the Auto button at %d,%d", point.x, point.y);
Color color = getPixelColor(point.x - 5, point.y);
if (ImageUtil.isGreenLikeColor(color)) {
debug("Auto is currently ON (green)");
continousRed = 0;
continue;
}
if (ImageUtil.isRedLikeColor(color)) {
continousRed++;
if (continousRed >= 2)
info("Detected Auto is not turned on, gonna reactive it soon");
if (continousRed >= maxContinousRed) {
moveCursor(point);
sleep(100);
mouseClick();
hideCursor();

info("Sent re-active");
sleep(2_000);
if (ImageUtil.isRedLikeColor(color)) {
continousRed++;
if (continousRed >= 2)
info("Detected Auto is not turned on, gonna reactive it soon");
if (continousRed >= maxContinousRed) {
moveCursor(point);
sleep(100);
mouseClick();
hideCursor();

info("Sent re-active");
sleep(2_000);
}
} else {
debug("Red Auto not found");
}
} else {
debug("Red Auto not found");
}
} catch (Exception ex) {
ex.printStackTrace();
Telegram.sendMessage("Error occurs during execution: " + ex.getMessage(), true);
masterSwitch.set(true);
}
}

protected void autoExit(int exitAfterXSecs, AtomicBoolean masterSwitch) {
if (exitAfterXSecs < 1)
return;
while (exitAfterXSecs > 0) {
exitAfterXSecs--;
sleep(1000);
if (exitAfterXSecs % 60 == 0)
info("Exit after %d seconds", exitAfterXSecs);
if (masterSwitch.get())
break;
try {
if (exitAfterXSecs < 1)
return;
while (exitAfterXSecs > 0) {
exitAfterXSecs--;
sleep(1000);
if (exitAfterXSecs % 60 == 0)
info("Exit after %d seconds", exitAfterXSecs);
if (masterSwitch.get())
break;
}
masterSwitch.set(true);
info("Application is going to exit now");
} catch (Exception ex) {
ex.printStackTrace();
Telegram.sendMessage("Error occurs during execution: " + ex.getMessage(), true);
masterSwitch.set(true);
}
masterSwitch.set(true);
info("Application is going to exit now");
}

protected <T> T readInput(BufferedReader br, String ask, String desc, Function<String, Tuple3<Boolean, String, T>> transform) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bh/bot/app/AfkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void doLoop(
continuousNotFound++;
moveCursor(coordinateHideMouse);

if (continuousNotFound >= 3) { // TODO 12
if (continuousNotFound >= 6) {
for (AbstractDoFarmingApp.NextAction nextAction : outOfTurnNextActionList) {
if (clickImage(nextAction.image)) {
spamEscape(2);
Expand Down
Loading

0 comments on commit 428c2e2

Please sign in to comment.