Skip to content

Commit

Permalink
Add new features: Invasion & Trials. Upgrade version to 1.2.0 (#10)
Browse files Browse the repository at this point in the history
* migrated World Boss and PVP apps to extends AbstractDoFarmingApp

* New function Invasion

* New function Trials

* Upgrade version to 1.2.0

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Aug 26, 2021
1 parent 589fcd5 commit 074b52c
Show file tree
Hide file tree
Showing 29 changed files with 626 additions and 294 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ reconnect-hl.bmp
*.zip

latest.README.md
im.dev
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Only support English user interface
### Contains the following functions:
1. Detect and click **ReRun** button while in Dungeons and Raid
2. Auto fishing
3. World Boss
4. Launch game in mini client using Google Chrome
3. Farm World Boss
4. Farm PVP
5. Farm Invasion
6. Farm Trials
7. Launch game in mini client using Google Chrome

And some extra functions support developers on developing this bot:
- Matrix: read an image, keep only pixels which has color (eg. FF0000 is red) as the same as input. Used to produce picture for BwMatrixMeta objects
Expand Down Expand Up @@ -118,6 +121,16 @@ For: everyone

[Read at Wiki](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22pvp%22)

### Invasion
For: everyone

[Read at Wiki](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22invasion%22)

### Trials
For: everyone

[Read at Wiki](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22trials%22)

### Mini client using Google Chrome
For: everyone

Expand Down
17 changes: 15 additions & 2 deletions README.release.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Only support English user interface
### Contains the following functions:
1. Detect and click **ReRun** button while in Dungeons and Raid
2. Auto fishing
3. World Boss
4. Launch game in mini client using Google Chrome
3. Farm World Boss
4. Farm PVP
5. Farm Invasion
6. Farm Trials
7. Launch game in mini client using Google Chrome

[Also supports pushing messages to Telegram for notification purpose](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Configure-Telegram-in-able-to-receive-notification)

Expand Down Expand Up @@ -95,6 +98,16 @@ Supported flags:

[Read at Wiki](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22pvp%22)

### Invasion
For: everyone

[Read at Wiki](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22invasion%22)

### Trials
For: everyone

[Read at Wiki](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22trials%22)

### Mini client using Google Chrome
[Wiki](https://github.com/9-9-9-9/Bit-Heroes-bot/wiki/Function-%22client%22-(mini-client-on-Chrome))

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

java -jar ./BitHeroes.jar invasion $@
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.1.2</version>
<version>1.2.0</version>

<dependencies>
<!--
Expand Down
5 changes: 5 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ cp ./rerun.sh ./release/
cp ./client.sh ./release/
cp ./world-boss.sh ./release/
cp ./pvp.sh ./release/
cp ./invasion.sh ./release/
cp ./trials.sh ./release/

# Copy launch scripts for Windows
cp ./fishing.bat ./release/
cp ./rerun.bat ./release/
cp ./client.bat ./release/
cp ./world-boss.bat ./release/
cp ./pvp.bat ./release/
cp ./invasion.bat ./release/
cp ./trials.bat ./release/

# Copy steam scripts
cp ./steam.*.bat ./release/
Expand All @@ -89,6 +93,7 @@ rm -rf $DIR
mv ./release $DIR
zip -r $FILE $DIR

rm -f ./latest.README.md
cp $DIR/README.md ./latest.README.md

echo 'clean up'
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/bh/bot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static void main(String[] args) throws Exception {
new AfkApp(),
new WorldBoss(),
new PvpApp(),
new InvasionApp(),
new TrialsApp(),
new GenMiniClient(),
//
new KeepPixApp(),
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,7 @@ protected boolean clickImageScanBW(BwMatrixMeta im) {
if (!go) {
mouseMoveAndClickAndHide(p);
im.setLastMatchPoint(p.x, p.y);
if (im.getCoordinateOffset().X != p.x - Configuration.Offsets.gameScreenOffset.X || im.getCoordinateOffset().Y != p.y - Configuration.Offsets.gameScreenOffset.Y)
debug(
"Un-match offset! Defined %3d,%3d but actual %3d,%3d",
im.getCoordinateOffset().X, im.getCoordinateOffset().Y,
p.x - Configuration.Offsets.gameScreenOffset.X, p.y - Configuration.Offsets.gameScreenOffset.Y
);
printIfIncorrectImgPosition(im.getCoordinateOffset(), p);
return true;
}

Expand Down
162 changes: 162 additions & 0 deletions src/main/java/bh/bot/app/AbstractDoFarmingApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package bh.bot.app;

import bh.bot.Main;
import bh.bot.common.Telegram;
import bh.bot.common.types.AttendablePlace;
import bh.bot.common.types.images.BwMatrixMeta;
import bh.bot.common.types.tuples.Tuple2;
import bh.bot.common.types.tuples.Tuple3;
import bh.bot.common.utils.InteractionUtil;
import bh.bot.common.utils.ThreadUtil;

import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;

import static bh.bot.common.Log.debug;
import static bh.bot.common.Log.info;
import static bh.bot.common.utils.InteractionUtil.Mouse.mouseClick;
import static bh.bot.common.utils.InteractionUtil.Mouse.moveCursor;
import static bh.bot.common.utils.ThreadUtil.sleep;

public abstract class AbstractDoFarmingApp extends AbstractApplication {
protected abstract String getAppShortName();
protected abstract AttendablePlace getAttendablePlace();
protected abstract Tuple2<Boolean, Boolean> isClickedSomething();
protected abstract boolean isOutOfTicket();

protected final AttendablePlace ap = getAttendablePlace();
protected InteractionUtil.Screen.Game gameScreenInteractor;

@Override
protected void internalRun(String[] args) {
int loopCount;
try (
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
) {
try {
loopCount = Integer.parseInt(args[0]);
} catch (ArrayIndexOutOfBoundsException | NumberFormatException ex) {
info(getHelp());
loopCount = readInput(br, "Loop count:", "How many time do you want to do " + getAppShortName(), new Function<String, Tuple3<Boolean, String, Integer>>() {
@Override
public Tuple3<Boolean, String, Integer> apply(String s) {
try {
int result = Integer.parseInt(s, 16) & 0xFFFFFF;
return new Tuple3<>(true, null, result);
} catch (Exception ex2) {
return new Tuple3<>(false, "Unable to parse, error: " + ex.getMessage(), 0);
}
}
});
}
} catch (IOException ex) {
ex.printStackTrace();
System.exit(Main.EXIT_CODE_UNHANDLED_EXCEPTION);
throw new RuntimeException(ex);
}

final int cnt = loopCount;

this.gameScreenInteractor = InteractionUtil.Screen.Game.of(this);
AtomicBoolean masterSwitch = new AtomicBoolean(false);
ThreadUtil.waitDone(
() -> loop(cnt, masterSwitch),
() -> detectDisconnected(masterSwitch),
() -> autoExit(launchInfo.exitAfterXSecs, masterSwitch)
);
Telegram.sendMessage("Stopped", false);
}

protected void loop(int loopCount, AtomicBoolean masterSwitch) {
int continuousNotFound = 0;
final Point coordinateHideMouse = new Point(0, 0);
while (!masterSwitch.get() && loopCount > 0) {
sleep(5_000);

Tuple2<Boolean, Boolean> result = isClickedSomething();
boolean clickedSomething = result._1;
if (clickedSomething) {
debug("isClickedSomething");
continuousNotFound = 0;

boolean decreaseLoopCount = result._2;
if (decreaseLoopCount) {
loopCount--;
info("%d loop left", loopCount);
}

moveCursor(coordinateHideMouse);

continue;
}

if (clickImage(BwMatrixMeta.Metas.Globally.Dialogs.confirmStartNotFullTeam)) {
debug("confirmStartNotFullTeam");
InteractionUtil.Keyboard.sendSpaceKey();
continuousNotFound = 0;

moveCursor(coordinateHideMouse);

continue;
}

if (isOutOfTicket()) {
debug("isOutOfTicket");
InteractionUtil.Keyboard.sendEscape();
masterSwitch.set(true);
continuousNotFound = 0;

moveCursor(coordinateHideMouse);

continue;
}

debug("None");
continuousNotFound++;

if (continuousNotFound >= 12) {
debug("Finding %s icon", getAppShortName());
Point point = this.gameScreenInteractor.findAttendablePlace(ap);
if (point != null) {
moveCursor(point);
mouseClick();
sleep(100);
moveCursor(coordinateHideMouse);
}
continuousNotFound = 0;
}
}
}

@Override
protected String getAppName() {
return "BH-" + getAppShortName();
}

@Override
protected String getScriptFileName() {
return getAppCode();
}

@Override
protected String getUsage() {
return "<count>";
}

@Override
protected String getDescription() {
return "Do " + getAppShortName();
}

@Override
protected String getFlags() {
return buildFlags(
"--exit=X : exit after X seconds if turns not all consumed, can be used to make sure do not run after boost has expired"
);
}
}
56 changes: 56 additions & 0 deletions src/main/java/bh/bot/app/InvasionApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package bh.bot.app;

import bh.bot.common.exceptions.NotImplementedException;
import bh.bot.common.types.AttendablePlace;
import bh.bot.common.types.AttendablePlaces;
import bh.bot.common.types.images.BwMatrixMeta;
import bh.bot.common.types.tuples.Tuple2;

import static bh.bot.common.Log.debug;

public class InvasionApp extends AbstractDoFarmingApp {
@Override
protected String getAppShortName() {
return "Invasion";
}

@Override
protected AttendablePlace getAttendablePlace() {
return AttendablePlaces.invasion;
}

@Override
protected Tuple2<Boolean, Boolean> isClickedSomething() {
if (clickImage(BwMatrixMeta.Metas.Invasion.Buttons.play)) {
debug("play");
return new Tuple2<>(true, false);
}

if (clickImage(BwMatrixMeta.Metas.Invasion.Buttons.accept)) {
debug("accept");
return new Tuple2<>(true, false);
}

if (clickImage(BwMatrixMeta.Metas.Invasion.Buttons.town)) {
debug("town");
return new Tuple2<>(true, true);
}

return new Tuple2<>(false, false);
}

@Override
protected boolean isOutOfTicket() {
return clickImage(BwMatrixMeta.Metas.Invasion.Dialogs.notEnoughBadges);
}

@Override
public String getAppCode() {
return "invasion";
}

@Override
protected String getLimitationExplain() {
return "This function does not support select badge cost, so choose it before turn this on";
}
}
Loading

0 comments on commit 074b52c

Please sign in to comment.