Skip to content

Commit d902ff6

Browse files
authored
1.5.8 with new flags --ear and --close-game, add expedition to setting (#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>
1 parent e2fdb90 commit d902ff6

32 files changed

+414
-152
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>bh.bot</groupId>
88
<artifactId>99bot</artifactId>
9-
<version>1.5.7</version>
9+
<version>1.5.8</version>
1010

1111
<dependencies>
1212
<dependency>

src/main/java/bh/bot/Main.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static String[] buildArgument(String[] args) {
125125
}
126126
}
127127

128-
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);
128+
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);
129129
if (addMoreFlags) {
130130
final Supplier<List<String>> selectedFlagsInfoProvider = () -> lArgs.stream().filter(x -> x.startsWith("--")).collect(Collectors.toList());
131131
while (true) {
@@ -276,7 +276,9 @@ private static ParseArgumentsResult parseArguments(String[] args)
276276

277277
ParseArgumentsResult li = new ParseArgumentsResult(applicationClassFromAppCode, args, usingFlagPatterns);
278278
li.exitAfterXSecs = exitAfter;
279-
li.shutdownAfterFinished = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagShutdownAfterFinished);
279+
li.exitAfkIfWaitForResourceGeneration = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagExitAfkAfterIfWaitResourceGeneration);
280+
li.shutdownAfterExit = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagShutdownAfterExit);
281+
li.closeGameWindowAfterExit = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagCloseGameWindowAfterExit);
280282
li.displayHelp = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagPrintHelpMessage);
281283
li.enableSavingDebugImages = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagSaveDebugImages);
282284
li.enableDebugMessages = usingFlagPatterns.stream().anyMatch(x -> x instanceof FlagShowDebugMessages);
@@ -322,9 +324,9 @@ public static boolean readYesNoInput(String ask, String desc) {
322324
public static boolean readYesNoInput(String ask, String desc, boolean emptyAsNo) {
323325
Boolean result = readInput(ask, desc == null ? "Answer by typing Y/N" : desc, s -> {
324326
String answer = s.trim().toLowerCase();
325-
if ("yes".equals(answer) || "y".equals(answer))
327+
if ("y".equals(answer) || "yes".equals(answer))
326328
return new Tuple3<>(true, null, true);
327-
if ("no".equals(answer) || "n".equals(answer))
329+
if ("n".equals(answer) || "no".equals(answer))
328330
return new Tuple3<>(true, null, false);
329331
return new Tuple3<>(false, "Not a valid answer", null);
330332
}, emptyAsNo);

src/main/java/bh/bot/app/AbstractApplication.java

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package bh.bot.app;
22

33
import bh.bot.Main;
4-
import bh.bot.app.farming.ExpeditionApp.ExpeditionPlace;
54
import bh.bot.common.Configuration;
65
import bh.bot.common.OS;
76
import bh.bot.common.Telegram;
@@ -33,9 +32,7 @@
3332
import java.util.List;
3433
import java.util.concurrent.atomic.AtomicBoolean;
3534
import java.util.function.Supplier;
36-
import java.util.stream.Collector;
3735
import java.util.stream.Collectors;
38-
import java.util.stream.Stream;
3936

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

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

8279
internalRun(launchInfo.arguments);
80+
tryToCloseGameWindow(launchInfo.closeGameWindowAfterExit);
8381

84-
final int shutdownAfterMinutes = FlagShutdownAfterFinished.shutdownAfterXMinutes;
82+
final int shutdownAfterMinutes = FlagShutdownAfterExit.shutdownAfterXMinutes;
8583
final int notiEverySec = 30;
8684
warn("System is going to shutdown after %d minutes", shutdownAfterMinutes);
8785
final int sleepPerRound = notiEverySec * 1_000;
@@ -100,6 +98,16 @@ else if (OS.isLinux) {
10098
}
10199
} else {
102100
internalRun(launchInfo.arguments);
101+
tryToCloseGameWindow(launchInfo.closeGameWindowAfterExit);
102+
}
103+
}
104+
105+
private void tryToCloseGameWindow(boolean closeGameWindowAfterExit) {
106+
if (!closeGameWindowAfterExit) return;
107+
try {
108+
getJnaInstance().tryToCloseGameWindow();
109+
} catch (Exception ignored) {
110+
//
103111
}
104112
}
105113

@@ -651,20 +659,20 @@ protected void autoExit(int exitAfterXSecs, AtomicBoolean masterSwitch) {
651659
}
652660
}
653661

654-
protected boolean tryEnterExpedition(boolean doExpedition, ExpeditionPlace place) {
662+
protected boolean tryEnterExpedition(boolean doExpedition, byte place) {
655663
if (doExpedition && clickImage(BwMatrixMeta.Metas.Expedition.Labels.idolDimension)) {
656664
Point p;
657665
switch (place) {
658-
case BlubLix:
666+
case 1:
659667
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionBlubLix().toScreenCoordinate();
660668
break;
661-
case Mowhi:
669+
case 2:
662670
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionMowhi().toScreenCoordinate();
663671
break;
664-
case WizBot:
672+
case 3:
665673
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionWizBot().toScreenCoordinate();
666674
break;
667-
case Astamus:
675+
case 4:
668676
p = Configuration.screenResolutionProfile.getOffsetEnterIdolDimensionAstamus().toScreenCoordinate();
669677
break;
670678
default:
@@ -772,31 +780,24 @@ private Point fromRelativeToAbsoluteBasedOnPreviousResult(BwMatrixMeta sampleImg
772780
return new Point(x + targetOffset.X, y + targetOffset.Y);
773781
}
774782

775-
protected ExpeditionPlace selectExpeditionPlace() {
783+
protected byte selectExpeditionPlace() {
776784
//noinspection StringBufferReplaceableByString
777785
StringBuilder sb = new StringBuilder("Select a place to do Expedition:\n");
778-
sb.append(String.format(" 1. %s\n", ExpeditionPlace.BlubLix));
779-
sb.append(String.format(" 2. %s\n", ExpeditionPlace.Mowhi));
780-
sb.append(String.format(" 3. %s\n", ExpeditionPlace.WizBot));
781-
sb.append(String.format(" 4. %s\n", ExpeditionPlace.Astamus));
782-
ExpeditionPlace place = readInput(sb.toString(), null,
786+
final Tuple2<Byte, Byte> expeditionPlaceRange = UserConfig.getExpeditionPlaceRange();
787+
for (int i = expeditionPlaceRange._1; i <= expeditionPlaceRange._2; i++)
788+
sb.append(String.format(" %d. %s\n", i, UserConfig.getExpeditionPlaceDesc(i)));
789+
byte place = (readInput(sb.toString(), null,
783790
s -> {
784791
try {
785-
int num = Integer.parseInt(s.trim());
786-
if (num == 1)
787-
return new Tuple3<>(true, null, ExpeditionPlace.BlubLix);
788-
if (num == 2)
789-
return new Tuple3<>(true, null, ExpeditionPlace.Mowhi);
790-
if (num == 3)
791-
return new Tuple3<>(true, null, ExpeditionPlace.WizBot);
792-
if (num == 4)
793-
return new Tuple3<>(true, null, ExpeditionPlace.Astamus);
794-
return new Tuple3<>(false, "Not a valid option", ExpeditionPlace.Astamus);
792+
int num = Byte.parseByte(s.trim());
793+
if (expeditionPlaceRange._1 <= num && num <= expeditionPlaceRange._2)
794+
return new Tuple3<>(true, null, num);
795+
return new Tuple3<>(false, "Not a valid option", 0);
795796
} catch (NumberFormatException ex) {
796-
return new Tuple3<>(false, "Not a number", ExpeditionPlace.Astamus);
797+
return new Tuple3<>(false, "Not a number", 0);
797798
}
798-
});
799-
info("Going to farm %s in Expedition", place.toString().toUpperCase());
799+
})).byteValue();
800+
info("Going to farm %s in Expedition", UserConfig.getExpeditionPlaceDesc(place));
800801
return place;
801802
}
802803

@@ -875,10 +876,8 @@ protected void doCheckGameScreenOffset(AtomicBoolean masterSwicth) {
875876
}
876877

877878
protected IJna getJnaInstance() {
878-
if (Configuration.isSteamProfile)
879-
return new SteamWindowsJna();
880879
if (OS.isWin)
881-
return new MiniClientWindowsJna();
880+
return Configuration.isSteamProfile ? new SteamWindowsJna() : new MiniClientWindowsJna();
882881
if (OS.isLinux)
883882
return new MiniClientLinuxJna();
884883
if (OS.isMac)
@@ -983,4 +982,12 @@ protected UserConfig getPredefinedUserConfigFromProfileName(String ask) throws I
983982
}
984983
return resultLoadUserConfig._2;
985984
}
985+
986+
protected void printWarningExpeditionImplementation() {
987+
warn("Inferno Dimension has not yet been implemented");
988+
warn("Hallowed Dimension has not yet been implemented");
989+
warn("Jammie Dimension has not yet been implemented");
990+
warn("Battle Bards has not yet been implemented");
991+
warn("Currently, Expedition only supports Idol Dimension");
992+
}
986993
}

src/main/java/bh/bot/app/AfkApp.java

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import bh.bot.Main;
44
import bh.bot.app.farming.*;
5-
import bh.bot.app.farming.ExpeditionApp.ExpeditionPlace;
65
import bh.bot.common.Configuration;
76
import bh.bot.common.Telegram;
87
import bh.bot.common.exceptions.InvalidDataException;
@@ -11,6 +10,7 @@
1110
import bh.bot.common.types.AttendablePlaces;
1211
import bh.bot.common.types.UserConfig;
1312
import bh.bot.common.types.annotations.AppMeta;
13+
import bh.bot.common.types.flags.FlagExitAfkAfterIfWaitResourceGeneration;
1414
import bh.bot.common.types.images.BwMatrixMeta;
1515
import bh.bot.common.types.tuples.Tuple3;
1616
import bh.bot.common.utils.ColorizeUtil;
@@ -32,7 +32,8 @@
3232
import static bh.bot.common.Log.*;
3333
import static bh.bot.common.types.AttendablePlace.MenuItem;
3434
import static bh.bot.common.utils.InteractionUtil.Keyboard.*;
35-
import static bh.bot.common.utils.InteractionUtil.Mouse.*;
35+
import static bh.bot.common.utils.InteractionUtil.Mouse.mouseClick;
36+
import static bh.bot.common.utils.InteractionUtil.Mouse.moveCursor;
3637
import static bh.bot.common.utils.ThreadUtil.sleep;
3738

3839
@AppMeta(code = "afk", name = "AFK", displayOrder = 1)
@@ -43,7 +44,7 @@ public class AfkApp extends AbstractApplication {
4344
private final AtomicLong blockRaidUntil = new AtomicLong(0);
4445
private final AtomicLong blockGvgAndInvasionAndExpeditionUntil = new AtomicLong(0);
4546
private final AtomicLong blockTrialsAndGauntletUntil = new AtomicLong(0);
46-
private ExpeditionPlace place = ExpeditionPlace.Astamus;
47+
private byte expeditionPlace = UserConfig.getExpeditionPlaceRange()._1;
4748

4849
@Override
4950
protected void internalRun(String[] args) {
@@ -57,8 +58,8 @@ protected void internalRun(String[] args) {
5758
boolean doRaid = eventList.contains(AttendablePlaces.raid);
5859
boolean doWorldBoss = eventList.contains(AttendablePlaces.worldBoss);
5960
boolean doExpedition = eventList.contains(AttendablePlaces.expedition);
60-
if (doRaid || doWorldBoss) {
61-
userConfig = getPredefinedUserConfigFromProfileName("You want to do Raid/World Boss so you have to specific profile name first!\nSelect an existing profile:");
61+
if (doRaid || doWorldBoss || doExpedition) {
62+
userConfig = getPredefinedUserConfigFromProfileName("You want to do Raid/World Boss/Expedition so you have to specific profile name first!\nSelect an existing profile:");
6263

6364
try {
6465
if (doRaid && doWorldBoss) {
@@ -69,21 +70,27 @@ protected void internalRun(String[] args) {
6970
} else if (doRaid) {
7071
info(ColorizeUtil.formatInfo, "You have selected %s mode of %s", userConfig.getRaidModeDesc(),
7172
userConfig.getRaidLevelDesc());
72-
} else //noinspection ConstantConditions
73-
if (doWorldBoss) {
74-
info(ColorizeUtil.formatInfo, "You have selected world boss %s", userConfig.getWorldBossLevelDesc());
75-
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");
73+
} else if (doWorldBoss) {
74+
info(ColorizeUtil.formatInfo, "You have selected world boss %s", userConfig.getWorldBossLevelDesc());
75+
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");
76+
}
77+
78+
if (doExpedition) {
79+
try {
80+
info(ColorizeUtil.formatInfo, "You have selected to farm %s of Expedition", userConfig.getExpeditionPlaceDesc());
81+
expeditionPlace = userConfig.expeditionPlace;
82+
} catch (InvalidDataException ex2) {
83+
warn("You haven't specified an Expedition door to enter so you have to select manually");
84+
expeditionPlace = selectExpeditionPlace();
7685
}
86+
}
7787
} catch (InvalidDataException ex2) {
7888
err(ex2.getMessage());
7989
printRequiresSetting();
8090
System.exit(Main.EXIT_CODE_INCORRECT_LEVEL_AND_DIFFICULTY_CONFIGURATION);
8191
return;
8292
}
8393
}
84-
85-
if (doExpedition)
86-
this.place = selectExpeditionPlace();
8794
} catch (IOException ex) {
8895
ex.printStackTrace();
8996
System.exit(Main.EXIT_CODE_UNHANDLED_EXCEPTION);
@@ -183,6 +190,15 @@ private void doLoop(//
183190
final Supplier<Boolean> isWorldBossBlocked = () -> !isNotBlocked(blockWorldBossUntil);
184191
final Supplier<Boolean> isRaidBlocked = () -> !isNotBlocked(blockRaidUntil);
185192

193+
if (doRaid)
194+
info(ColorizeUtil.formatInfo, "Raid: %s of %s", userConfig.getRaidModeDesc(), userConfig.getRaidLevelDesc());
195+
if (doWorldBoss)
196+
info(ColorizeUtil.formatInfo, "World Boss: %s", userConfig.getWorldBossLevelDesc());
197+
if (doExpedition) {
198+
info(ColorizeUtil.formatInfo, "Expedition: (%d) %s", this.expeditionPlace, UserConfig.getExpeditionPlaceDesc(this.expeditionPlace));
199+
printWarningExpeditionImplementation();
200+
}
201+
186202
ML:
187203
while (!masterSwitch.get()) {
188204
sleep(loopSleep);
@@ -224,6 +240,12 @@ private void doLoop(//
224240

225241
if (taskList.stream().noneMatch(x -> isNotBlocked(x._2))) {
226242
info("Waiting for resource generation, sleeping %d minutes", minutesSleepWaitingResourceGeneration);
243+
if (this.argumentInfo.exitAfkIfWaitForResourceGeneration) {
244+
masterSwitch.set(true);
245+
FlagExitAfkAfterIfWaitResourceGeneration flag = new FlagExitAfkAfterIfWaitResourceGeneration();
246+
warn("Due to flag '%s', AFK will exit now", flag.getCode());
247+
info("Flag '%s': %s",flag.getCode(), flag.getDescription());
248+
}
227249
sleepWhileWaitingResourceRegen = originalSleepWhileWaitingResourceRegen;
228250
continue ML;
229251
}
@@ -270,7 +292,7 @@ private void doLoop(//
270292
continue ML;
271293
}
272294

273-
if (tryEnterExpedition(doExpedition, this.place)) {
295+
if (tryEnterExpedition(doExpedition, this.expeditionPlace)) {
274296
debug("tryEnterExpedition");
275297
continuousNotFound = 0;
276298
moveCursor(coordinateHideMouse);
@@ -428,16 +450,19 @@ private ArrayList<AttendablePlace> getAttendablePlaces() {
428450
eventList.add(AttendablePlaces.raid);
429451
//
430452
if (eventList.size() == 0) {
431-
432-
final List<MenuItem> menuItems = Stream
433-
.concat(allAttendablePlaces.stream().map(MenuItem::from), Stream.of(
434-
MenuItem.from(AttendablePlaces.invasion, AttendablePlaces.trials),
435-
MenuItem.from(AttendablePlaces.expedition, AttendablePlaces.trials),
436-
MenuItem.from(AttendablePlaces.gvg, AttendablePlaces.gauntlet),
437-
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid),
438-
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid,
439-
AttendablePlaces.expedition, AttendablePlaces.trials)))
440-
.collect(Collectors.toList());
453+
final List<MenuItem> menuItems = Stream.of(
454+
MenuItem.from(AttendablePlaces.pvp),
455+
MenuItem.from(AttendablePlaces.worldBoss),
456+
MenuItem.from(AttendablePlaces.raid),
457+
MenuItem.from(AttendablePlaces.invasion),
458+
MenuItem.from("GVG/Expedition", AttendablePlaces.gvg, AttendablePlaces.expedition),
459+
MenuItem.from("GVG/Expedition/Invasion", AttendablePlaces.gvg, AttendablePlaces.expedition, AttendablePlaces.invasion),
460+
MenuItem.from("Trials/Gauntlet", AttendablePlaces.trials, AttendablePlaces.gauntlet),
461+
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid),
462+
MenuItem.from(AttendablePlaces.pvp, AttendablePlaces.worldBoss, AttendablePlaces.raid,
463+
AttendablePlaces.expedition, AttendablePlaces.trials),
464+
MenuItem.from("All", allAttendablePlaces.toArray(new AttendablePlace[0]))
465+
).collect(Collectors.toList());
441466

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

0 commit comments

Comments
 (0)