Skip to content

Commit

Permalink
2.3.0 (#56)
Browse files Browse the repository at this point in the history
* update web UI

* pop-up web page of result after auto-update

* add page showing require java 8

* new flag `--disable-persuade`

* select PVP target

* add warning about PVP target on AFK

* able to disable functions `select pvp target` and `auto-update` remotely

* 2.3.0

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Oct 13, 2021
1 parent d7e48b0 commit 1ecc9d2
Show file tree
Hide file tree
Showing 37 changed files with 562 additions and 115 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ This project has inspiration from https://github.com/tiemonl/Bit-Heroes-Fishing-
___
[Wiki version](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki)

This readme file is for developers
**This readme file is for developers**

Normal users please [read at this page](https://github.com/9-9-9-9/Bit-Heroes-bot/blob/master/README.release.md)

[_There're some notes for MacOS users, please read here_](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Notes-for-MacOS-users)
___
Officially support [BitHeroes on Steam](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Does-this-bot-supports-Steam-version-of-Bit-Heroes%3F) and ([BitHeroes on web](https://www.kongregate.com/games/Juppiomenz/bit-heroes) + mini-client)
Officially support [BitHeroes on Steam](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Does-this-bot-supports-Steam-version-of-Bit-Heroes%3F) and [BitHeroes on web](https://www.kongregate.com/games/Juppiomenz/bit-heroes) + [mini-client](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22client%22-(mini-client-on-Chrome))

**Only support English user interface**

Expand Down
2 changes: 1 addition & 1 deletion README.release.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Developers please read [at my github](https://github.com/9-9-9-9/Bit-Heroes-bot)

[_There're some notes for MacOS users, please read here_](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Notes-for-MacOS-users)
___
Officially support [BitHeroes on Steam](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Does-this-bot-supports-Steam-version-of-Bit-Heroes%3F) and ([BitHeroes on web](https://www.kongregate.com/games/Juppiomenz/bit-heroes) + mini-client)
Officially support [BitHeroes on Steam](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Does-this-bot-supports-Steam-version-of-Bit-Heroes%3F) and [BitHeroes on web](https://www.kongregate.com/games/Juppiomenz/bit-heroes) + [mini-client](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22client%22-(mini-client-on-Chrome))

**Only support English user interface**

Expand Down
4 changes: 3 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
8. Hide some flags from displaying in `--help` (private use only)
9. Generate auto-update script on Windows
10. Fix getting bot version on release binaries
11. Fix release.sh script
11. Fix release.sh script
12. Flag disable persuade
13. Allow select PVP target (1-4)
21 changes: 15 additions & 6 deletions _.bat
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
@if not exist BitHeroes.jar (
@echo You are using 99bot from source code version which required to run build.bat in order to compile binary first
@echo If you are not a developer and you only want to use the bot, please download the zip file with name download-this-file.zip from my website at download.bh99bot.com
goto L_EXIT1
)

@where java >nul 2>nul
@if %errorlevel%==1 (
@echo ** ERROR ** You have to install Java 8 in order to use this bot
@echo ** LOI ** Ban can cai dat Java 8 truoc khi su dung
@echo You can download Java 8 from the following website: https://adoptium.net/?variant=openjdk8
start "" https://adoptium.net/?variant=openjdk8
goto L_EXIT
start "" https://bh99bot.com/require-java.html
goto L_EXIT1
)

java -jar BitHeroes.jar %*
@SET EXIT_LVL=%errorlevel%
@if %EXIT_LVL% NEQ 0 (
@echo exit code: %EXIT_LVL%
)

@goto L_EXIT0

@goto L_EXIT
:L_EXIT0
@pause
@exit /b 0

:L_EXIT
@pause
:L_EXIT1
@pause
@exit /b 1
6 changes: 6 additions & 0 deletions bot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
if [ ! -f ./BitHeroes.jar ]; then
echo 'You are using 99bot from source code version which required to run ./build.sh in order to compile binary first'
echo 'If you are not a developer and you only want to use the bot, please download the zip file with name download-this-file.zip from my website at download.bh99bot.com'
exit 1
fi

java -jar BitHeroes.jar $@
exit=$?

if [ $exit -ne 0 ]; then
echo 'Exit code '$exit
fi
16 changes: 9 additions & 7 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
@if not exist pom.xml goto to_exit
@if not exist pom.xml (
rem Wrong working directory
goto L_EXIT2
)

@CALL mvn clean package

@if not %errorlevel%==0 (
echo ** ERROR ** maven build failure
pause
goto EXIT_1
goto L_EXIT1
)

@if not exist out mkdir out
Expand All @@ -17,10 +20,9 @@
rem Generating mini client
@call client.bat
)

:to_exit
rem Wrong working directory
@exit /b 2

:EXIT_1
:L_EXIT1
@exit /b 1

:L_EXIT2
@exit /b 2
9 changes: 8 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

if [ ! -f ./pom.xml ]; then
echo 'Wrong working directory'
exit 1
exit 2
fi

/opt/app/apache-maven-3.6.3/bin/mvn clean package
EXIT=$?

if [ $EXIT -ne 0 ]; then
echo '** ERROR ** maven build failure'
exit 1
fi

mkdir -p ./out/
rm -f ./BitHeroes.jar
cp ./target/99bot-*-jar-with-dependencies.jar ./BitHeroes.jar
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>99bot</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>

<dependencies>
<dependency>
Expand Down
26 changes: 2 additions & 24 deletions src/main/java/bh/bot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import bh.bot.app.dev.*;
import bh.bot.common.extensions.Rad;
import bh.bot.common.types.flags.*;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.fusesource.jansi.AnsiConsole;
Expand Down Expand Up @@ -43,30 +44,6 @@
import bh.bot.common.types.ParseArgumentsResult;
import bh.bot.common.types.ScreenResolutionProfile;
import bh.bot.common.types.annotations.AppMeta;
import bh.bot.common.types.flags.FlagAlterLoopInterval;
import bh.bot.common.types.flags.FlagBribe;
import bh.bot.common.types.flags.FlagCloseGameWindowAfterExit;
import bh.bot.common.types.flags.FlagDisableMutex;
import bh.bot.common.types.flags.FlagDoExpedition;
import bh.bot.common.types.flags.FlagDoGauntlet;
import bh.bot.common.types.flags.FlagDoGvG;
import bh.bot.common.types.flags.FlagDoInvasion;
import bh.bot.common.types.flags.FlagDoPvp;
import bh.bot.common.types.flags.FlagDoRaid;
import bh.bot.common.types.flags.FlagDoTrials;
import bh.bot.common.types.flags.FlagDoWorldBoss;
import bh.bot.common.types.flags.FlagExitAfkAfterIfWaitResourceGeneration;
import bh.bot.common.types.flags.FlagExitAfterAmountOfSeconds;
import bh.bot.common.types.flags.FlagMuteNoti;
import bh.bot.common.types.flags.FlagPattern;
import bh.bot.common.types.flags.FlagPlayOnSteam;
import bh.bot.common.types.flags.FlagPlayOnWeb;
import bh.bot.common.types.flags.FlagPrintHelpMessage;
import bh.bot.common.types.flags.FlagProfileName;
import bh.bot.common.types.flags.FlagSaveDebugImages;
import bh.bot.common.types.flags.FlagShowDebugMessages;
import bh.bot.common.types.flags.FlagShutdownAfterExit;
import bh.bot.common.types.flags.Flags;
import bh.bot.common.types.tuples.Tuple2;
import bh.bot.common.types.tuples.Tuple3;
import bh.bot.common.utils.ColorizeUtil;
Expand Down Expand Up @@ -417,6 +394,7 @@ private static ParseArgumentsResult parseArguments(String[] args) throws Invalid
li.screenResolutionProfile = screenResolutionProfile;
li.cfgProfileName = cfgProfileName;
li.familiarToBribeWithGems = familiarToBribeWithGems;
li.disablePersuade = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagDisablePersuade);
// events
li.ePvp = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagDoPvp);
li.eWorldBoss = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagDoWorldBoss);
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ protected boolean skipCheckVersion() {

private void launchThreadCheckVersion(final String appCode) {
CompletableFuture.runAsync(() -> {
VersionUtil.fetchDisabledFunctions();
VersionUtil.quitIfCurrentVersionIsRejected(appCode);
});

Expand Down Expand Up @@ -724,8 +725,9 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
long nextCloseEnterGameDialogNews = addSec(closeEnterGameDialogNewsSleepSecs);
final AtomicInteger continousPersuadeScreen = new AtomicInteger(0);
long nextPersuade = addSec(persuadeSleepSecs);
boolean persuade = st.persuade && !argumentInfo.disablePersuade;

if (st.persuade) {
if (persuade) {
if (Configuration.enableDevFeatures) {
final String fileBribeName = "bribe.txt";
File fBribe = new File(fileBribeName);
Expand Down Expand Up @@ -757,6 +759,18 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
warn("Will persuade %s with gems", f.name());
}

if (st.persuade && argumentInfo.disablePersuade)
info(Cu.i()
.yellow("** WARNING ** ")
.red("Auto persuade/bribe has been disabled")
.yellow(" so please ")
.red("turn on in-game's auto persuade")
.yellow(" for all kind of familiars or ")
.red("always stay in front of your computer")
.yellow(" to persuade/bribe manually, otherwise bot can't continue your tasks and becomes waste of resources")
.reset()
);

while (!masterSwitch.get()) {
sleep(1_000);

Expand All @@ -775,7 +789,7 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
if (st.closeEnterGameNewsDialog && nextCloseEnterGameDialogNews <= System.currentTimeMillis())
nextCloseEnterGameDialogNews = closeEnterGameDialogNews();

if (st.persuade && nextPersuade <= System.currentTimeMillis())
if (persuade && nextPersuade <= System.currentTimeMillis())
nextPersuade = doPersuade(continousPersuadeScreen);
}
} catch (Exception ex) {
Expand Down Expand Up @@ -1490,6 +1504,10 @@ protected void printWarningExpeditionImplementation() {
info(Cu.i().yellow("** WARNING ** The other dimensions ").green("not yet implemented").yellow(" but will available asap: ").magenta("Battle Bards").yellow(" & ").magenta("Inferno").yellow(" & ").magenta("Jammie").yellow(" Dimensions").reset().toString());
}

protected void warningPvpTargetSelectionCase() {
info(Cu.i().yellow("** WARNING ** ").red("about selecting PVP target").yellow(" feature, to prevent wrong targeting and un-expected loss on other target-selectable ranking like GVG... (which having the same target-selection method), ").cyan("while doing AFK").yellow(", this feature works and ").cyan("only works when bot itself attends to PVP").yellow(" by selecting the PVP icon (top left of game screen). That means if you select the PVP icon yourself or enter PVP before bot click etc.., it only select the first line as target as default").reset());
}

protected int getDefaultMainLoopInterval() {
return 0;
}
Expand Down
69 changes: 55 additions & 14 deletions src/main/java/bh/bot/app/AfkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import bh.bot.Main;
import bh.bot.app.farming.*;
import bh.bot.app.farming.AbstractDoFarmingApp.NextAction;
import bh.bot.common.Configuration;
import bh.bot.common.Telegram;
import bh.bot.common.exceptions.InvalidDataException;
Expand All @@ -23,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
Expand All @@ -33,8 +35,8 @@
import static bh.bot.common.Log.*;
import static bh.bot.common.types.AttendablePlace.MenuItem;
import static bh.bot.common.utils.InteractionUtil.Keyboard.*;
import static bh.bot.common.utils.InteractionUtil.Mouse.mouseClick;
import static bh.bot.common.utils.InteractionUtil.Mouse.moveCursor;
import static bh.bot.common.utils.InteractionUtil.Mouse.*;
import static bh.bot.common.utils.InteractionUtil.Mouse.mouseMoveAndClickAndHide;
import static bh.bot.common.utils.ThreadUtil.sleep;
import static bh.bot.common.utils.ThreadUtil.waitDone;

Expand All @@ -47,6 +49,7 @@ public class AfkApp extends AbstractApplication {
private final AtomicLong blockRaidUntil = new AtomicLong(0);
private final AtomicLong blockGvgAndInvasionAndExpeditionUntil = new AtomicLong(0);
private final AtomicLong blockTrialsAndGauntletUntil = new AtomicLong(0);
private final AtomicBoolean isOnPvp = new AtomicBoolean(false);
private byte expeditionPlace = UserConfig.getExpeditionPlaceRange()._1;

@Override
Expand All @@ -61,19 +64,17 @@ protected void internalRun(String[] args) {
boolean doRaid = eventList.contains(AttendablePlaces.raid);
boolean doWorldBoss = eventList.contains(AttendablePlaces.worldBoss);
boolean doExpedition = eventList.contains(AttendablePlaces.expedition);
if (doRaid || doWorldBoss || doExpedition) {
userConfig = getPredefinedUserConfigFromProfileName("You want to do Raid/World Boss/Expedition so you have to specific profile name first!\nSelect an existing profile:");
boolean doPVP = eventList.contains(AttendablePlaces.pvp);
if (doRaid || doWorldBoss || doExpedition || doPVP) {
userConfig = getPredefinedUserConfigFromProfileName("You want to do Raid/World Boss/Expedition/PVP so you have to specific profile name first!\nSelect an existing profile:");

try {
if (doRaid && doWorldBoss) {
if (doRaid) {
info(ColorizeUtil.formatInfo, "You have selected %s mode of %s", userConfig.getRaidModeDesc(),
userConfig.getRaidLevelDesc());
info(ColorizeUtil.formatInfo, "and World Boss %s", userConfig.getWorldBossLevelDesc());
warn("World Boss is solo only and does not support select mode of World Boss (Normal/Hard/Heroic), only select by default So which boss do you want to hit? Choose it before turn this on");
} else if (doRaid) {
info(ColorizeUtil.formatInfo, "You have selected %s mode of %s", userConfig.getRaidModeDesc(),
userConfig.getRaidLevelDesc());
} else if (doWorldBoss) {
}

if (doWorldBoss) {
info(ColorizeUtil.formatInfo, "You have selected world boss %s", userConfig.getWorldBossLevelDesc());
warn("World Boss is solo only and does not support select mode of World Boss (Normal/Hard/Heroic), only select by default So which boss do you want to hit? Choose it before turn this on");
}
Expand All @@ -87,6 +88,9 @@ protected void internalRun(String[] args) {
expeditionPlace = selectExpeditionPlace();
}
}

if (doPVP)
info(ColorizeUtil.formatInfo, "You have chosen to select target on the %s of PVP", userConfig.getPvpTargetDesc());
} catch (InvalidDataException ex2) {
err(ex2.getMessage());
printRequiresSetting();
Expand Down Expand Up @@ -150,8 +154,25 @@ private void doLoop(//
int continuousNotFound = 0;
final Point coordinateHideMouse = new Point(0, 0);
final ArrayList<Tuple3<AttendablePlace, AtomicLong, List<AbstractDoFarmingApp.NextAction>>> taskList = new ArrayList<>();
if (doPvp)
taskList.add(new Tuple3<>(AttendablePlaces.pvp, blockPvpUntil, PvpApp.getPredefinedImageActions()));
NextAction naBtnFightPvp = null;
if (doPvp) {
List<AbstractDoFarmingApp.NextAction> pvpPia = PvpApp.getPredefinedImageActions();
if (userConfig.isValidPvpTarget()) {
final BwMatrixMeta fight1 = BwMatrixMeta.Metas.PvpArena.Buttons.fight1;
Optional<NextAction> first = pvpPia.stream().filter(x -> x.image == fight1).findFirst();
if (first.isPresent()) {
naBtnFightPvp = first.get();
final NextAction tmp = naBtnFightPvp;
if (naBtnFightPvp != null) {
pvpPia = pvpPia.stream().filter(x -> x != tmp).collect(Collectors.toList());
}
}
}
taskList.add(new Tuple3<>(AttendablePlaces.pvp, blockPvpUntil, pvpPia));
}
final int selectFightPvp = naBtnFightPvp != null ? userConfig.pvpTarget : 0;
final int offsetTargetPvp = selectFightPvp < 1 ? 0 : (selectFightPvp - 1) * Configuration.screenResolutionProfile.getOffsetDiffBetweenFightButtons();

if (doWorldBoss)
taskList.add(new Tuple3<>(AttendablePlaces.worldBoss, blockWorldBossUntil,
WorldBossApp.getPredefinedImageActions()));
Expand Down Expand Up @@ -213,6 +234,10 @@ private void doLoop(//
info(ColorizeUtil.formatInfo, "Expedition: (%d) %s", this.expeditionPlace, UserConfig.getExpeditionPlaceDesc(this.expeditionPlace));
printWarningExpeditionImplementation();
}
if (doPvp) {
info(ColorizeUtil.formatInfo, "PVP target: %s", userConfig.getPvpTargetDesc());
warningPvpTargetSelectionCase();
}

ML:
while (!masterSwitch.get()) {
Expand Down Expand Up @@ -317,8 +342,22 @@ private void doLoop(//
if (!isNotBlocked(tuple._2))
continue;
AbstractDoFarmingApp.NextAction nextAction = tryToClickOnBatch(tuple._3);
if (nextAction == null)
if (nextAction == null) {
if (selectFightPvp > 0 && tuple._1 == AttendablePlaces.pvp) {
if (isOnPvp.get()) {
Point p = findImage(naBtnFightPvp.image);
if (p != null) {
int offset = Configuration.Features.isFunctionDisabled("target-pvp") ? 0 : offsetTargetPvp;
mouseMoveAndClickAndHide(new Point(p.x, p.y + offset));
moveCursor(coordinateHideMouse);
continue ML;
}
} else if (clickImage(naBtnFightPvp.image)) {
continue ML;
}
}
continue;
}
debug(nextAction.image.getImageNameCode());
if (nextAction.isOutOfTurns) {
spamEscape(2);
Expand Down Expand Up @@ -347,6 +386,8 @@ private void doLoop(//
debug("Finding %s icon", tuple._1.name);
Point point = this.gameScreenInteractor.findAttendablePlace(tuple._1);
if (point != null) {
isOnPvp.set(tuple._1 == AttendablePlaces.pvp);

if (isUnknownGvgOrInvasionOrExpedition) {
if (tuple._1 == AttendablePlaces.gvg) {
isUnknownGvgOrInvasionOrExpedition = false;
Expand Down
Loading

0 comments on commit 1ecc9d2

Please sign in to comment.