Skip to content

Commit

Permalink
Upgrade version to 1.3.0, release full feature for AFK (#19)
Browse files Browse the repository at this point in the history
AFK is now officially completed

* add `setting` app and scripts

* remove setting world boss mode

* afk `world-boss`

* refactor world boss, now select level

* upgrade version to 1.3.0, release enhancement for afk

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Sep 1, 2021
1 parent 755f972 commit 4afdd23
Show file tree
Hide file tree
Showing 27 changed files with 917 additions and 272 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ For: everyone

Supported flags:
- `--pvp` do PVP
- `--boss` do world boss
- `--boss` do world boss [(require setting)](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Select-Raid-World-Boss-level,-mode,..-using-%60setting%60-function)
- `--gvg` do GVG
- `--invasion` do Invasion
- `--trials` do Trials
- `--gauntlet` do Gauntlet
- `--raid` do Raid [(require setting)](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Select-Raid-World-Boss-level,-mode,..-using-%60setting%60-function)
- `--all` do everything above
- `--exit=X` means will exit after X secs if not completed, no matter how many loop remaining. Usage: `./afk.sh --exit=1800` means will stop after 1800 seconds (30m)
- [Global flags](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Application-flags)
Expand Down
3 changes: 2 additions & 1 deletion README.release.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ Enjoy it

Supported flags:
- `--pvp` do PVP
- `--boss` do world boss
- `--boss` do world boss [(require setting)](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Select-Raid-World-Boss-level,-mode,..-using-%60setting%60-function)
- `--gvg` do GVG
- `--invasion` do Invasion
- `--trials` do Trials
- `--gauntlet` do Gauntlet
- `--raid` do Raid [(require setting)](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Select-Raid-World-Boss-level,-mode,..-using-%60setting%60-function)
- `--all` do everything above
- `--exit=X` means will exit after X secs if not completed, no matter how many loop remaining. Usage: `./afk.sh --exit=1800` means will stop after 1800 seconds (30m)
- [Global flags](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Application-flags)
Expand Down
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.6</version>
<version>1.3.0</version>

<dependencies>
</dependencies>
Expand Down
2 changes: 2 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ cp ./trials.sh ./release/
cp ./gvg.sh ./release/
cp ./gauntlet.sh ./release/
cp ./afk.sh ./release/
cp ./setting.sh ./release/

# Copy launch scripts for Windows
cp ./fishing.bat ./release/
Expand All @@ -78,6 +79,7 @@ cp ./trials.bat ./release/
cp ./gvg.bat ./release/
cp ./gauntlet.bat ./release/
cp ./afk.bat ./release/
cp ./setting.bat ./release/

# Copy steam scripts
cp ./steam.*.bat ./release/
Expand Down
1 change: 1 addition & 0 deletions setting.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -jar BitHeroes.jar setting
3 changes: 3 additions & 0 deletions setting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

java -jar ./BitHeroes.jar setting $@
5 changes: 3 additions & 2 deletions src/main/java/bh/bot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static void main(String[] args) {
try {

Configuration.registerApplicationInstances(
SettingApp.class,
//
ReRunApp.class,
FishingApp.class,
AfkApp.class,
Expand Down Expand Up @@ -60,7 +62,6 @@ public static void main(String[] args) {
Telegram.disable();

Configuration.loadSystemConfig(parseArgumentsResult.screenResolutionProfile);
Configuration.loadUserConfig(parseArgumentsResult.profileNumber);
InteractionUtil.init();

Constructor<?> cons = parseArgumentsResult.applicationClass.getConstructors()[0];
Expand Down Expand Up @@ -202,6 +203,6 @@ private static ParseArgumentsResult parseArguments(String[] args) throws Invalid
public static final int EXIT_CODE_EXTERNAL_REASON = 7;
public static final int EXIT_CODE_INVALID_FLAG = 8;
public static final int EXIT_CODE_UNABLE_DETECTING_FISHING_ANCHOR = 9;
public static final int EXIT_CODE_INCORRECT_PROFILE_NUMBER = 10;
public static final int EXIT_CODE_INCORRECT_LEVEL_AND_DIFFICULTY_CONFIGURATION = 11;
public static final int EXIT_CODE_UNHANDLED_EXCEPTION = -1;
}
46 changes: 44 additions & 2 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import bh.bot.common.types.tuples.Tuple2;
import bh.bot.common.types.tuples.Tuple3;
import bh.bot.common.utils.ImageUtil;
import bh.bot.common.utils.InteractionUtil;

import javax.imageio.ImageIO;
import java.awt.*;
Expand Down Expand Up @@ -190,7 +191,7 @@ protected Point findImageBasedOnLastClick(BwMatrixMeta im) {
Color c = getPixelColor(p);
if (!im.isMatchBlackRgb(c.getRGB()))
return null;
// debug("findImageBasedOnLastClick match success 1");
debug("findImageBasedOnLastClick match success 1 for %s", im.getImageNameCode());

BufferedImage sc = captureScreen(lastMatch[0], lastMatch[1], im.getWidth(), im.getHeight());

Expand Down Expand Up @@ -231,7 +232,7 @@ protected Point scanToFindImage(BwMatrixMeta im) {
BufferedImage sc = screenCapturedResult.image;

try {
saveDebugImage(sc, "scanToFindImage");
saveDebugImage(sc, "scanToFindImage." + im.getImageNameCode());

boolean go = true;
Point p = new Point();
Expand Down Expand Up @@ -647,4 +648,45 @@ protected <T> T readInput(BufferedReader br, String ask, String desc, Supplier<L
return null;
}
}

protected boolean tryEnterWorldBoss(boolean doWorldBoss, Configuration.UserConfig userConfig, Supplier<Boolean> isBlocked) {
Point coord = findImage(BwMatrixMeta.Metas.WorldBoss.Labels.labelInSummonDialog);
if (coord == null)
return false;
if (isBlocked.get() || !doWorldBoss) {
spamEscape(1);
return false;
}
mouseMoveAndClickAndHide(coord);
BwMatrixMeta.Metas.WorldBoss.Labels.labelInSummonDialog.setLastMatchPoint(coord.x, coord.y);
Tuple2<Point[], Byte> result = detectRadioButtons(Configuration.screenResolutionProfile.getRectangleRadioButtonsOfRaidAndWorldBoss());
Point[] points = result._1;
int selectedLevel = result._2 + 1;
info("Found %d, selected %d", points.length, selectedLevel);
if (selectedLevel != userConfig.worldBossLevel)
clickRadioButton(userConfig.worldBossLevel, points, "World Boss");
sleep(3_000);
result = detectRadioButtons(Configuration.screenResolutionProfile.getRectangleRadioButtonsOfRaidAndWorldBoss());
selectedLevel = result._2 + 1;
if (selectedLevel != userConfig.worldBossLevel) {
err("Failure on selecting world boss level");
spamEscape(1);
return false;
}
sleep(1_000);
return clickImage(BwMatrixMeta.Metas.WorldBoss.Buttons.summonOnListingWorldBosses);
}

protected void spamEscape(int expectedCount) {
int cnt = expectedCount + 4;
while (cnt-- > 0) {
sleep(1_000);
InteractionUtil.Keyboard.sendEscape();
}
}

protected void printRequiresSetting() {
err("You have to do setting before using this function");
err("Please launch script 'setting.%s' and follow instruction", Configuration.OS.isWin ? "bat" : "sh");
}
}
Loading

0 comments on commit 4afdd23

Please sign in to comment.