Skip to content

Commit

Permalink
1.5.8 with new flags --ear and --close-game, add expedition to se…
Browse files Browse the repository at this point in the history
…tting (#35)

* better events selection menu for afk

* new flag `--ear`

* new flag `--close-game`

* add expedition to setting

* 1.5.8

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Sep 8, 2021
1 parent e2fdb90 commit d902ff6
Show file tree
Hide file tree
Showing 32 changed files with 414 additions and 152 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.5.7</version>
<version>1.5.8</version>

<dependencies>
<dependency>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/bh/bot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static String[] buildArgument(String[] args) {
}
}

boolean addMoreFlags = readYesNoInput("Do you want to add some add some flags? (Yes/No, empty is No)", String.format("You can pass flags like '--exit=3600'/'--steam'/'--all'/'--help'... here. For list of supported flags available for each function, please run file '%s'", scriptFileName("help")), true);
boolean addMoreFlags = readYesNoInput("Do you want to add some add some flags? (Y/N, empty is No)", String.format("You can pass flags like '--exit=3600'/'--steam'/'--all'/'--help'... here. For list of supported flags available for each function, please run file '%s'", scriptFileName("help")), true);
if (addMoreFlags) {
final Supplier<List<String>> selectedFlagsInfoProvider = () -> lArgs.stream().filter(x -> x.startsWith("--")).collect(Collectors.toList());
while (true) {
Expand Down Expand Up @@ -276,7 +276,9 @@ private static ParseArgumentsResult parseArguments(String[] args)

ParseArgumentsResult li = new ParseArgumentsResult(applicationClassFromAppCode, args, usingFlagPatterns);
li.exitAfterXSecs = exitAfter;
li.shutdownAfterFinished = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagShutdownAfterFinished);
li.exitAfkIfWaitForResourceGeneration = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagExitAfkAfterIfWaitResourceGeneration);
li.shutdownAfterExit = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagShutdownAfterExit);
li.closeGameWindowAfterExit = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagCloseGameWindowAfterExit);
li.displayHelp = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagPrintHelpMessage);
li.enableSavingDebugImages = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagSaveDebugImages);
li.enableDebugMessages = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagShowDebugMessages);
Expand Down Expand Up @@ -322,9 +324,9 @@ public static boolean readYesNoInput(String ask, String desc) {
public static boolean readYesNoInput(String ask, String desc, boolean emptyAsNo) {
Boolean result = readInput(ask, desc == null ? "Answer by typing Y/N" : desc, s -> {
String answer = s.trim().toLowerCase();
if ("yes".equals(answer) || "y".equals(answer))
if ("y".equals(answer) || "yes".equals(answer))
return new Tuple3<>(true, null, true);
if ("no".equals(answer) || "n".equals(answer))
if ("n".equals(answer) || "no".equals(answer))
return new Tuple3<>(true, null, false);
return new Tuple3<>(false, "Not a valid answer", null);
}, emptyAsNo);
Expand Down
71 changes: 39 additions & 32 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bh.bot.app;

import bh.bot.Main;
import bh.bot.app.farming.ExpeditionApp.ExpeditionPlace;
import bh.bot.common.Configuration;
import bh.bot.common.OS;
import bh.bot.common.Telegram;
Expand Down Expand Up @@ -33,9 +32,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static bh.bot.Main.readInput;
import static bh.bot.common.Log.*;
Expand All @@ -61,7 +58,7 @@ public void run(ParseArgumentsResult launchInfo) throws Exception {
Telegram.setAppName(getAppName());
warn(getLimitationExplain());

if (launchInfo.shutdownAfterFinished) {
if (launchInfo.shutdownAfterExit) {
String command;
if (OS.isWin)
command = "shutdown -s -t 0";
Expand All @@ -80,8 +77,9 @@ else if (OS.isLinux) {
throw new NotSupportedException(String.format("Shutdown command is not supported on %s OS", OS.name));

internalRun(launchInfo.arguments);
tryToCloseGameWindow(launchInfo.closeGameWindowAfterExit);

final int shutdownAfterMinutes = FlagShutdownAfterFinished.shutdownAfterXMinutes;
final int shutdownAfterMinutes = FlagShutdownAfterExit.shutdownAfterXMinutes;
final int notiEverySec = 30;
warn("System is going to shutdown after %d minutes", shutdownAfterMinutes);
final int sleepPerRound = notiEverySec * 1_000;
Expand All @@ -100,6 +98,16 @@ else if (OS.isLinux) {
}
} else {
internalRun(launchInfo.arguments);
tryToCloseGameWindow(launchInfo.closeGameWindowAfterExit);
}
}

private void tryToCloseGameWindow(boolean closeGameWindowAfterExit) {
if (!closeGameWindowAfterExit) return;
try {
getJnaInstance().tryToCloseGameWindow();
} catch (Exception ignored) {
//
}
}

Expand Down Expand Up @@ -651,20 +659,20 @@ protected void autoExit(int exitAfterXSecs, AtomicBoolean masterSwitch) {
}
}

protected boolean tryEnterExpedition(boolean doExpedition, ExpeditionPlace place) {
protected boolean tryEnterExpedition(boolean doExpedition, byte place) {
if (doExpedition && clickImage(BwMatrixMeta.Metas.Expedition.Labels.idolDimension)) {
Point p;
switch (place) {
case BlubLix:
case 1:
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionBlubLix().toScreenCoordinate();
break;
case Mowhi:
case 2:
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionMowhi().toScreenCoordinate();
break;
case WizBot:
case 3:
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionWizBot().toScreenCoordinate();
break;
case Astamus:
case 4:
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionAstamus().toScreenCoordinate();
break;
default:
Expand Down Expand Up @@ -772,31 +780,24 @@ private Point fromRelativeToAbsoluteBasedOnPreviousResult(BwMatrixMeta sampleImg
return new Point(x + targetOffset.X, y + targetOffset.Y);
}

protected ExpeditionPlace selectExpeditionPlace() {
protected byte selectExpeditionPlace() {
//noinspection StringBufferReplaceableByString
StringBuilder sb = new StringBuilder("Select a place to do Expedition:\n");
sb.append(String.format(" 1. %s\n", ExpeditionPlace.BlubLix));
sb.append(String.format(" 2. %s\n", ExpeditionPlace.Mowhi));
sb.append(String.format(" 3. %s\n", ExpeditionPlace.WizBot));
sb.append(String.format(" 4. %s\n", ExpeditionPlace.Astamus));
ExpeditionPlace place = readInput(sb.toString(), null,
final Tuple2<Byte, Byte> expeditionPlaceRange = UserConfig.getExpeditionPlaceRange();
for (int i = expeditionPlaceRange._1; i <= expeditionPlaceRange._2; i++)
sb.append(String.format(" %d. %s\n", i, UserConfig.getExpeditionPlaceDesc(i)));
byte place = (readInput(sb.toString(), null,
s -> {
try {
int num = Integer.parseInt(s.trim());
if (num == 1)
return new Tuple3<>(true, null, ExpeditionPlace.BlubLix);
if (num == 2)
return new Tuple3<>(true, null, ExpeditionPlace.Mowhi);
if (num == 3)
return new Tuple3<>(true, null, ExpeditionPlace.WizBot);
if (num == 4)
return new Tuple3<>(true, null, ExpeditionPlace.Astamus);
return new Tuple3<>(false, "Not a valid option", ExpeditionPlace.Astamus);
int num = Byte.parseByte(s.trim());
if (expeditionPlaceRange._1 <= num && num <= expeditionPlaceRange._2)
return new Tuple3<>(true, null, num);
return new Tuple3<>(false, "Not a valid option", 0);
} catch (NumberFormatException ex) {
return new Tuple3<>(false, "Not a number", ExpeditionPlace.Astamus);
return new Tuple3<>(false, "Not a number", 0);
}
});
info("Going to farm %s in Expedition", place.toString().toUpperCase());
})).byteValue();
info("Going to farm %s in Expedition", UserConfig.getExpeditionPlaceDesc(place));
return place;
}

Expand Down Expand Up @@ -875,10 +876,8 @@ protected void doCheckGameScreenOffset(AtomicBoolean masterSwicth) {
}

protected IJna getJnaInstance() {
if (Configuration.isSteamProfile)
return new SteamWindowsJna();
if (OS.isWin)
return new MiniClientWindowsJna();
return Configuration.isSteamProfile ? new SteamWindowsJna() : new MiniClientWindowsJna();
if (OS.isLinux)
return new MiniClientLinuxJna();
if (OS.isMac)
Expand Down Expand Up @@ -983,4 +982,12 @@ protected UserConfig getPredefinedUserConfigFromProfileName(String ask) throws I
}
return resultLoadUserConfig._2;
}

protected void printWarningExpeditionImplementation() {
warn("Inferno Dimension has not yet been implemented");
warn("Hallowed Dimension has not yet been implemented");
warn("Jammie Dimension has not yet been implemented");
warn("Battle Bards has not yet been implemented");
warn("Currently, Expedition only supports Idol Dimension");
}
}
71 changes: 48 additions & 23 deletions src/main/java/bh/bot/app/AfkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import bh.bot.Main;
import bh.bot.app.farming.*;
import bh.bot.app.farming.ExpeditionApp.ExpeditionPlace;
import bh.bot.common.Configuration;
import bh.bot.common.Telegram;
import bh.bot.common.exceptions.InvalidDataException;
Expand All @@ -11,6 +10,7 @@
import bh.bot.common.types.AttendablePlaces;
import bh.bot.common.types.UserConfig;
import bh.bot.common.types.annotations.AppMeta;
import bh.bot.common.types.flags.FlagExitAfkAfterIfWaitResourceGeneration;
import bh.bot.common.types.images.BwMatrixMeta;
import bh.bot.common.types.tuples.Tuple3;
import bh.bot.common.utils.ColorizeUtil;
Expand All @@ -32,7 +32,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.*;
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;

@AppMeta(code = "afk", name = "AFK", displayOrder = 1)
Expand All @@ -43,7 +44,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 ExpeditionPlace place = ExpeditionPlace.Astamus;
private byte expeditionPlace = UserConfig.getExpeditionPlaceRange()._1;

@Override
protected void internalRun(String[] args) {
Expand All @@ -57,8 +58,8 @@ 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) {
userConfig = getPredefinedUserConfigFromProfileName("You want to do Raid/World Boss so you have to specific profile name first!\nSelect an existing profile:");
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:");

try {
if (doRaid && doWorldBoss) {
Expand All @@ -69,21 +70,27 @@ protected void internalRun(String[] args) {
} else if (doRaid) {
info(ColorizeUtil.formatInfo, "You have selected %s mode of %s", userConfig.getRaidModeDesc(),
userConfig.getRaidLevelDesc());
} else //noinspection ConstantConditions
if (doWorldBoss) {
info(ColorizeUtil.formatInfo, "You have selected world boss %s", userConfig.getWorldBossLevelDesc());
warn("This function 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 (doWorldBoss) {
info(ColorizeUtil.formatInfo, "You have selected world boss %s", userConfig.getWorldBossLevelDesc());
warn("This function 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");
}

if (doExpedition) {
try {
info(ColorizeUtil.formatInfo, "You have selected to farm %s of Expedition", userConfig.getExpeditionPlaceDesc());
expeditionPlace = userConfig.expeditionPlace;
} catch (InvalidDataException ex2) {
warn("You haven't specified an Expedition door to enter so you have to select manually");
expeditionPlace = selectExpeditionPlace();
}
}
} catch (InvalidDataException ex2) {
err(ex2.getMessage());
printRequiresSetting();
System.exit(Main.EXIT_CODE_INCORRECT_LEVEL_AND_DIFFICULTY_CONFIGURATION);
return;
}
}

if (doExpedition)
this.place = selectExpeditionPlace();
} catch (IOException ex) {
ex.printStackTrace();
System.exit(Main.EXIT_CODE_UNHANDLED_EXCEPTION);
Expand Down Expand Up @@ -183,6 +190,15 @@ private void doLoop(//
final Supplier<Boolean> isWorldBossBlocked = () -> !isNotBlocked(blockWorldBossUntil);
final Supplier<Boolean> isRaidBlocked = () -> !isNotBlocked(blockRaidUntil);

if (doRaid)
info(ColorizeUtil.formatInfo, "Raid: %s of %s", userConfig.getRaidModeDesc(), userConfig.getRaidLevelDesc());
if (doWorldBoss)
info(ColorizeUtil.formatInfo, "World Boss: %s", userConfig.getWorldBossLevelDesc());
if (doExpedition) {
info(ColorizeUtil.formatInfo, "Expedition: (%d) %s", this.expeditionPlace, UserConfig.getExpeditionPlaceDesc(this.expeditionPlace));
printWarningExpeditionImplementation();
}

ML:
while (!masterSwitch.get()) {
sleep(loopSleep);
Expand Down Expand Up @@ -224,6 +240,12 @@ private void doLoop(//

if (taskList.stream().noneMatch(x -> isNotBlocked(x._2))) {
info("Waiting for resource generation, sleeping %d minutes", minutesSleepWaitingResourceGeneration);
if (this.argumentInfo.exitAfkIfWaitForResourceGeneration) {
masterSwitch.set(true);
FlagExitAfkAfterIfWaitResourceGeneration flag = new FlagExitAfkAfterIfWaitResourceGeneration();
warn("Due to flag '%s', AFK will exit now", flag.getCode());
info("Flag '%s': %s",flag.getCode(), flag.getDescription());
}
sleepWhileWaitingResourceRegen = originalSleepWhileWaitingResourceRegen;
continue ML;
}
Expand Down Expand Up @@ -270,7 +292,7 @@ private void doLoop(//
continue ML;
}

if (tryEnterExpedition(doExpedition, this.place)) {
if (tryEnterExpedition(doExpedition, this.expeditionPlace)) {
debug("tryEnterExpedition");
continuousNotFound = 0;
moveCursor(coordinateHideMouse);
Expand Down Expand Up @@ -428,16 +450,19 @@ private ArrayList<AttendablePlace> getAttendablePlaces() {
eventList.add(AttendablePlaces.raid);
//
if (eventList.size() == 0) {

final List<MenuItem> menuItems = Stream
.concat(allAttendablePlaces.stream().map(MenuItem::from), Stream.of(
MenuItem.from(AttendablePlaces.invasion, AttendablePlaces.trials),
MenuItem.from(AttendablePlaces.expedition, AttendablePlaces.trials),
MenuItem.from(AttendablePlaces.gvg, AttendablePlaces.gauntlet),
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid),
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid,
AttendablePlaces.expedition, AttendablePlaces.trials)))
.collect(Collectors.toList());
final List<MenuItem> menuItems = Stream.of(
MenuItem.from(AttendablePlaces.pvp),
MenuItem.from(AttendablePlaces.worldBoss),
MenuItem.from(AttendablePlaces.raid),
MenuItem.from(AttendablePlaces.invasion),
MenuItem.from("GVG/Expedition", AttendablePlaces.gvg, AttendablePlaces.expedition),
MenuItem.from("GVG/Expedition/Invasion", AttendablePlaces.gvg, AttendablePlaces.expedition, AttendablePlaces.invasion),
MenuItem.from("Trials/Gauntlet", AttendablePlaces.trials, AttendablePlaces.gauntlet),
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid),
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid,
AttendablePlaces.expedition, AttendablePlaces.trials),
MenuItem.from("All", allAttendablePlaces.toArray(new AttendablePlace[0]))
).collect(Collectors.toList());

String menuItem = menuItems.stream().map(x -> String.format(" %3d. %s", x.num, x.name))
.collect(Collectors.joining("\n"));
Expand Down
Loading

0 comments on commit d902ff6

Please sign in to comment.