Skip to content

Commit

Permalink
1.7.1 fix bug (#39)
Browse files Browse the repository at this point in the history
* now flag allow passing empty param

* warning when persuade screen appears

* auto bribe (persuade) kaleido

* temp dev feature

* change format notice when new update available

* fix bug detect screen steam

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Sep 20, 2021
1 parent e9f2978 commit b29fe87
Show file tree
Hide file tree
Showing 23 changed files with 317 additions and 32 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>99bot</artifactId>
<version>1.7.0</version>
<version>1.7.1</version>

<dependencies>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ cat ./README.release.md >> ./release/README.md

# Remove secret
rm -f ./release/bh-client/*.html
rm -f ./release/readonly.*.properties

# Compress output
FILE=Bit-Heroes-99bot-Release-v$VERSION.zip
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/bh/bot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
import bh.bot.common.Telegram;
import bh.bot.common.exceptions.InvalidFlagException;
import bh.bot.common.exceptions.NotImplementedException;
import bh.bot.common.types.Familiar;
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.FlagBribe;
import bh.bot.common.types.flags.FlagCloseGameWindowAfterExit;
import bh.bot.common.types.flags.FlagDoExpedition;
import bh.bot.common.types.flags.FlagDoGauntlet;
Expand Down Expand Up @@ -271,6 +273,7 @@ private static ParseArgumentsResult parseArguments(String[] args) throws Invalid
// Parse param
int exitAfter = 0;
String cfgProfileName = null;
ArrayList<Familiar> familiarToBribeWithGems = null;
for (FlagPattern flagPattern : usingFlagPatterns) {
if (!flagPattern.isAllowParam())
continue;
Expand All @@ -284,11 +287,19 @@ private static ParseArgumentsResult parseArguments(String[] args) throws Invalid
cfgProfileName = ((FlagProfileName) flagPattern).parseParams().get(0);
continue;
}

if (flagPattern instanceof FlagBribe) {
familiarToBribeWithGems = ((FlagBribe) flagPattern).parseParams();
continue;
}

throw new NotImplementedException(
String.format("Not implemented extracting param for flag '--%s' (Class: %s)", flagPattern.getName(),
flagPattern.getClass().getSimpleName()));
}

if (familiarToBribeWithGems == null)
familiarToBribeWithGems = new ArrayList<>();

info("Application will exit after %s", TimeUtil.niceTimeLong(exitAfter));

Expand Down Expand Up @@ -337,6 +348,7 @@ private static ParseArgumentsResult parseArguments(String[] args) throws Invalid
li.disableTelegramNoti = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagMuteNoti);
li.screenResolutionProfile = screenResolutionProfile;
li.cfgProfileName = cfgProfileName;
li.familiarToBribeWithGems = familiarToBribeWithGems;
// events
li.ePvp = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagDoPvp);
li.eWorldBoss = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagDoWorldBoss);
Expand Down
98 changes: 98 additions & 0 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import bh.bot.common.jna.MiniClientMacOsJna;
import bh.bot.common.jna.MiniClientWindowsJna;
import bh.bot.common.jna.SteamWindowsJna;
import bh.bot.common.types.Familiar;
import bh.bot.common.types.Offset;
import bh.bot.common.types.ParseArgumentsResult;
import bh.bot.common.types.ScreenResolutionProfile;
Expand All @@ -71,6 +72,7 @@
import bh.bot.common.utils.ColorizeUtil;
import bh.bot.common.utils.ImageUtil;
import bh.bot.common.utils.InteractionUtil;
import bh.bot.common.utils.InteractionUtil.Keyboard;
import bh.bot.common.utils.InteractionUtil.Screen.ScreenCapturedResult;
import bh.bot.common.utils.RandomUtil;
import bh.bot.common.utils.StringUtil;
Expand Down Expand Up @@ -595,6 +597,7 @@ protected Tuple2<Point[], Byte> detectRadioButtons(Rectangle scanRect) {
private static final int detectDcSleepSecs = 60;
private static final int reactiveAutoSleepSecs = 10;
private static final int closeEnterGameDialogNewsSleepSecs = 60;
private static final int persuadeSleepSecs = 60;

protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
try {
Expand All @@ -603,6 +606,16 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
long nextReactiveAuto = addSec(reactiveAutoSleepSecs);
final AtomicInteger continousRed = new AtomicInteger(0);
long nextCloseEnterGameDialogNews = addSec(closeEnterGameDialogNewsSleepSecs);
final AtomicInteger continousPersuadeScreen = new AtomicInteger(0);
long nextPersuade = addSec(persuadeSleepSecs);

if (st.persuade) {
if (Configuration.enableDevFeatures && !argumentInfo.familiarToBribeWithGems.contains(Familiar.Kaleido))
argumentInfo.familiarToBribeWithGems.add(Familiar.Kaleido);
for (Familiar f : argumentInfo.familiarToBribeWithGems)
warn("Will persuade %s with gems", f.name());
}

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

Expand All @@ -620,6 +633,9 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {

if (st.closeEnterGameNewsDialog && nextCloseEnterGameDialogNews <= System.currentTimeMillis())
nextCloseEnterGameDialogNews = closeEnterGameDialogNews();

if (st.persuade && nextPersuade <= System.currentTimeMillis())
nextPersuade = doPersuade(continousPersuadeScreen);
}
} catch (Exception ex) {
ex.printStackTrace();
Expand All @@ -638,13 +654,15 @@ protected static class SmallTasks {
public final boolean reactiveAuto;
public final boolean autoExit;
public final boolean closeEnterGameNewsDialog;
public final boolean persuade;

private SmallTasks(Builder b) {
this.clickTalk = b.f(0);
this.clickDisconnect = b.f(1);
this.reactiveAuto = b.f(2);
this.autoExit = b.f(3);
this.closeEnterGameNewsDialog = b.f(4);
this.persuade = b.f(5);
}

public static Builder builder() {
Expand Down Expand Up @@ -686,7 +704,87 @@ public Builder autoExit() {
public Builder closeEnterGameNewsDialog() {
return this.set(4);
}

public Builder persuade() {
return this.set(5);
}
}
}

private long doPersuade(AtomicInteger continousPersuadeScreen) {
Point pBribeButton = findImage(BwMatrixMeta.Metas.Globally.Buttons.persuadeBribe);
Point pPersuadeButton = pBribeButton != null ? null : findImage(BwMatrixMeta.Metas.Globally.Buttons.persuade);
if (pPersuadeButton != null || pBribeButton != null) {
int continous = continousPersuadeScreen.addAndGet(1);
if (continous > 0) {
if (continous % 10 == 1)
Telegram.sendMessage("Found persuade screen", true);

if (persuade(BwMatrixMeta.Metas.Persuade.Labels.kaleido, Familiar.Kaleido, pPersuadeButton, pBribeButton)) {
//
} else {
persuade(true, pPersuadeButton, pBribeButton);
}
} else {
info("Found persuade screen");
}
} else {
continousPersuadeScreen.set(0);
}
return addSec(persuadeSleepSecs);
}

private boolean persuade(BwMatrixMeta im, Familiar familiar, Point pPersuadeButton, Point pBribeButton) {
String name = familiar.name().toUpperCase();

if (im.notAvailable) {
warn("Persuading %s has not yet been implemented for this profile", name);
return false;
}

if (!argumentInfo.familiarToBribeWithGems.contains(familiar)) {
persuade(true, pPersuadeButton, pBribeButton);
info("Bribe %s with gold", name);
return true;
}

Point pFamiliar = findImage(im);
if (pFamiliar == null)
return false;
try {
persuade(false, pPersuadeButton, pBribeButton);
warn(name);
Telegram.sendMessage(name, false);
} catch (Exception e) {
e.printStackTrace();
err(name);
Telegram.sendMessage(String.format("%s failure: %s", name, e.getMessage()), true);
}
return true;
}

private void persuade(boolean gold, Point pPersuadeButton, Point pBribeButton) {
Point p = null;
if (gold) {
if (pPersuadeButton != null) {
p = pPersuadeButton;
} else if (pBribeButton != null) {
p = fromRelativeToAbsoluteBasedOnPreviousResult(BwMatrixMeta.Metas.Globally.Buttons.persuadeBribe, pBribeButton, Configuration.screenResolutionProfile.getOffsetButtonBribePersuade());
}
} else {
if (pPersuadeButton != null) {
p = fromRelativeToAbsoluteBasedOnPreviousResult(BwMatrixMeta.Metas.Globally.Buttons.persuade, pPersuadeButton, Configuration.screenResolutionProfile.getOffsetButtonPersuade());
} else if (pBribeButton != null) {
p = pBribeButton;
}
}

if (p == null)
throw new InvalidDataException("Implemented wrongly");

mouseMoveAndClickAndHide(p);
sleep(5_000);
Keyboard.sendEnter();
}

private long doClickTalk() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bh/bot/app/AfkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ protected void internalRun(String[] args) {
.reactiveAuto() //
.autoExit() //
.closeEnterGameNewsDialog() //
.persuade() //
.build() //
), //
() -> doCheckGameScreenOffset(masterSwitch) //
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/bh/bot/app/FishingApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ protected void internalRun(String[] args) {
final int loop = arg;
info("Loop: %d", loop);

try {
adjustScreenOffset();
} catch (Exception ex) {
err("Unable to detect screen offset: %s", ex.getMessage());
}

int retry = 5;
Point labelFishingCord;
while ((labelFishingCord = detectLabelFishing()) == null && retry-- > 0) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bh/bot/app/ReRunApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void internalRun(String[] args) {
.clickDisconnect() //
.reactiveAuto() //
.autoExit() //
.persuade() //
.build() //
), //
() -> detectDefeatedOnRaid(masterSwitch),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bh/bot/app/farming/AbstractDoFarmingApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected void internalRun(String[] args) {
.reactiveAuto() //
.autoExit() //
.closeEnterGameNewsDialog() //
.persuade() //
.build() //
), //
() -> doCheckGameScreenOffset(masterSwitch) //
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/bh/bot/common/types/Familiar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package bh.bot.common.types;

public enum Familiar {
Kaleido
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ParseArgumentsResult {
public boolean eRaid;
public ScreenResolutionProfile screenResolutionProfile;
public String cfgProfileName;
public ArrayList<Familiar> familiarToBribeWithGems;

@SuppressWarnings("rawtypes")
public ParseArgumentsResult(Class<? extends AbstractApplication> applicationClass, String[] arguments, ArrayList<FlagPattern> usingFlags) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/bh/bot/common/types/ScreenResolutionProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ public abstract class ScreenResolutionProfile {

public abstract Offset getOffsetDialogNews();

public abstract Offset getOffsetButtonPersuade();

public abstract Offset getOffsetButtonBribePersuade();

public abstract Offset getOffsetLabelPersuadeKaleido();

public static class WebProfile extends ScreenResolutionProfile {

@Override
Expand Down Expand Up @@ -644,6 +650,22 @@ public Offset getOffsetButtonAcceptExpedition() {
public Offset getOffsetDialogNews() {
return new Offset(356, 77);
}

@Override
public Offset getOffsetButtonPersuade() {
return new Offset(139, 329);
}

@Override
public Offset getOffsetButtonBribePersuade() {
return new Offset(567, 329);
}

@Override
public Offset getOffsetLabelPersuadeKaleido() {
// TODO Auto-generated method stub
return null;
}
}

public static class SteamProfile extends ScreenResolutionProfile {
Expand Down Expand Up @@ -1097,5 +1119,20 @@ public Offset getOffsetButtonAcceptExpedition() {
public Offset getOffsetDialogNews() {
return new Offset(359, 69);
}

@Override
public Offset getOffsetButtonPersuade() {
return new Offset(155, 305);
}

@Override
public Offset getOffsetButtonBribePersuade() {
return new Offset(556, 305);
}

@Override
public Offset getOffsetLabelPersuadeKaleido() {
return new Offset(202, 70);
}
}
}
59 changes: 59 additions & 0 deletions src/main/java/bh/bot/common/types/flags/FlagBribe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package bh.bot.common.types.flags;

import bh.bot.app.AbstractApplication;
import bh.bot.app.AfkApp;
import bh.bot.app.ReRunApp;
import bh.bot.app.farming.AbstractDoFarmingApp;
import bh.bot.common.exceptions.InvalidFlagException;
import bh.bot.common.exceptions.NotSupportedException;
import bh.bot.common.types.Familiar;

public class FlagBribe extends FlagPattern<Familiar> {

@Override
protected Familiar internalParseParam(String paramPart) throws InvalidFlagException {
String[] spl = paramPart.toLowerCase().split("[\\,\\;]");
for (String s : spl) {
switch (s) {
case "kaleido":
return Familiar.Kaleido;
default:
throw new NotSupportedException(String.format("Unknown value '%s' of flag %s", s, getCode()));
}
}
throw new InvalidFlagException(String.format("Passing invalid value for flag %s", getCode()));
}

@Override
public boolean isAllowParam() {
return true;
}

@Override
protected boolean isAllowMultiple() {
return true;
}

@Override
public boolean isGlobalFlag() {
return false;
}

@Override
public String getName() {
return "bribe";
}

@Override
public String getDescription() {
return "Auto bribe with gems";
}

@Override
protected boolean internalCheckIsSupportedByApp(AbstractApplication instance) {
return instance instanceof AfkApp
|| instance instanceof ReRunApp
|| instance instanceof AbstractDoFarmingApp;
}

}
Loading

0 comments on commit b29fe87

Please sign in to comment.