Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Change Character App #91

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions src/main/java/bh/bot/app/ChangeCharacterApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package bh.bot.app;

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

import java.awt.Point;
import java.util.concurrent.atomic.AtomicBoolean;

import bh.bot.Main;
import bh.bot.common.Configuration;
import bh.bot.common.Telegram;
import bh.bot.common.exceptions.NotSupportedException;
import bh.bot.common.types.Offset;
import bh.bot.common.types.annotations.AppMeta;
import bh.bot.common.types.annotations.RequireSingleInstance;
import bh.bot.common.types.images.BwMatrixMeta;
import bh.bot.common.utils.ColorizeUtil;
import bh.bot.common.utils.InteractionUtil;
import bh.bot.common.utils.ThreadUtil;

@AppMeta(code = "character", name = "Change Character", displayOrder = 1, argType = "number", argAsk = "What character slot do you want to pick?", argDefault = "1", argRequired = true)
@RequireSingleInstance
public class ChangeCharacterApp extends AbstractApplication {

@Override
protected void internalRun(String[] args) {
int arg;
try {
arg = Integer.parseInt(args[0]);
} catch (ArrayIndexOutOfBoundsException | NumberFormatException ex) {
info(getHelp());
arg = readInputLoopCount("What character slot do you want to pick?");
}

final int characterSlot = arg;
info("Character in slot %3d ", characterSlot);
AtomicBoolean masterSwitch = new AtomicBoolean(false);
ThreadUtil.waitDone(
() -> doLoopClickImage(characterSlot, masterSwitch),
() -> internalDoSmallTasks( //
masterSwitch, //
SmallTasks //
.builder() //
.clickTalk() //
Copy link
Owner

@9-9-9-9 9-9-9-9 Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are those options needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No clue! Didn't want to break anything :P I just started using your bot on Friday

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you adopt the code base so fast, really impressive, ty

.clickDisconnect() //
.reactiveAuto() //
.autoExit() //
.detectChatboxDirectMessage() //
.build() //
), //
() -> doCheckGameScreenOffset(masterSwitch));
Telegram.sendMessage("Stopped", false);
}

private void doLoopClickImage(int characterSlot, AtomicBoolean masterSwitch) {
info(ColorizeUtil.formatInfo, "\n\nStarting Character Change");
Main.warningSupport();
try {
final int mainLoopInterval = Configuration.Interval.Loop.getMainLoopInterval(getDefaultMainLoopInterval());

moveCursor(new Offset(100, 500).toScreenCoordinate());
boolean characterLoaded = false;
boolean loadedSelect = false;
boolean characterSelected = false;
int loopCount = 0;
while (!characterLoaded && !masterSwitch.get()) {
sleep(mainLoopInterval);
if (clickImage(BwMatrixMeta.Metas.Character.Buttons.characterSelect)) {
debug("Loading Character Selection");
}
if (characterSelected) {
loopCount += 1;
if (loopCount > 10) {
debug("We probably loaded the character, or already on it, so breaking out of the loop!");
InteractionUtil.Keyboard.sendEscape();
InteractionUtil.Keyboard.sendEscape();
break;
}
}
if (loadedSelect) {
if (characterSelected) {
sleep(mainLoopInterval);
if (clickImage(BwMatrixMeta.Metas.Character.Dialogs.loading)) {
debug("Character Loading!");
characterLoaded = true;
break;
}
} else {
debug("Selecting Character in Slot #" + characterSlot);
if (characterSlot == 1) {
InteractionUtil.Mouse.mouseMoveAndClickAndHide(new Offset(250, 200).toScreenCoordinate());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded offset

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are hardcoded as there is no unique image in that location that can be recognized.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main purpose of Profile design is too support multiple screen resolution

} else if (characterSlot == 2) {
InteractionUtil.Mouse.mouseMoveAndClickAndHide(new Offset(375, 200).toScreenCoordinate());
9-9-9-9 marked this conversation as resolved.
Show resolved Hide resolved
} else if (characterSlot == 3) {
InteractionUtil.Mouse.mouseMoveAndClickAndHide(new Offset(500, 200).toScreenCoordinate());
9-9-9-9 marked this conversation as resolved.
Show resolved Hide resolved
} else {
throw new NotSupportedException("Cannot select character in this slot.");
}
sleep(mainLoopInterval);
if (clickImage(BwMatrixMeta.Metas.Character.Buttons.confirm)) {
info(ColorizeUtil.formatInfo, "\n\nCharacter Changed to Slot #" + characterSlot);
characterSelected = true;
}
}
} else {
if (clickImage(BwMatrixMeta.Metas.Character.Labels.heroes)) {
loadedSelect = true;
debug("Character Select Menu Loaded");
sleep(mainLoopInterval);
}
}
}
masterSwitch.set(true);
} catch (Exception ex) {
ex.printStackTrace();
Telegram.sendMessage("Error occurs during execution: " + ex.getMessage(), true);
masterSwitch.set(true);
}
}

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

@Override
protected String getDescription() {
return "Change character button. Used to switch between character slots";
}

@Override
protected String getLimitationExplain() {
return "This function only supports clicking the Character slots #1 #2 and #3 right now. Feel free to add support for more yourself.";
}

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

import bh.bot.app.AbstractApplication;
import bh.bot.app.AfkApp;
import bh.bot.app.ChangeCharacterApp;
import bh.bot.app.FishingApp;
import bh.bot.app.ReRunApp;
import bh.bot.common.exceptions.InvalidDataException;
Expand Down Expand Up @@ -29,6 +30,7 @@ protected void internalRun(String[] args) {
List<AbstractApplication> apps = Arrays.asList(
new ReRunApp(), //
new FishingApp(), //
new ChangeCharacterApp(), //
new AfkApp() //
);

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/bh/bot/common/types/ScreenResolutionProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public abstract class ScreenResolutionProfile {

public abstract int getSupportedGameResolutionHeight();

public abstract Offset getOffsetDialogCharacterLoading();

public abstract Offset getOffsetLabelCharacterConfirm();

public abstract Offset getOffsetLabelCharacterSelect();

public abstract Offset getOffsetLabelCharacterHeroes();

public abstract Offset getOffsetButtonDungeonReRun();

public abstract Offset getOffsetButtonTalkRightArrow();
Expand Down Expand Up @@ -253,6 +261,26 @@ public int getSupportedGameResolutionHeight() {
return 520;
}

@Override
public Offset getOffsetDialogCharacterLoading() {
return new Offset(325, 175);
}

@Override
public Offset getOffsetLabelCharacterConfirm() {
return new Offset(350, 400);
}

@Override
public Offset getOffsetLabelCharacterSelect() {
return new Offset(80, 400);
}

@Override
public Offset getOffsetLabelCharacterHeroes() {
return new Offset(280, 50);
}

@Override
public Offset getOffsetButtonDungeonReRun() {
return new Offset(309, 468);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public boolean internalCheckIsSupportedByApp(AbstractApplication instance) {
return instance instanceof ReRunApp
|| instance instanceof FishingApp
|| instance instanceof AbstractDoFarmingApp
|| instance instanceof ChangeCharacterApp
|| instance instanceof AfkApp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import bh.bot.app.AbstractApplication;
import bh.bot.app.AfkApp;
import bh.bot.app.ChangeCharacterApp;
import bh.bot.app.FishingApp;
import bh.bot.app.ReRunApp;
import bh.bot.app.farming.AbstractDoFarmingApp;
Expand Down Expand Up @@ -41,6 +42,7 @@ protected boolean internalCheckIsSupportedByApp(AbstractApplication instance) {
|| instance instanceof FishingApp
|| instance instanceof AbstractDoFarmingApp
|| instance instanceof AfkApp
|| instance instanceof ChangeCharacterApp
|| instance instanceof WorldBossTeamApp;
}

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/bh/bot/common/types/images/BwMatrixMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ public static class Labels {
}
}

public static class Character {
public static class Labels {
public static BwMatrixMeta heroes;
}

public static class Dialogs {
public static BwMatrixMeta loading;
}

public static class Buttons {
public static BwMatrixMeta characterSelect;
public static BwMatrixMeta confirm;
}
}

public static class Dungeons {
public static class Buttons {
public static BwMatrixMeta rerun;
Expand Down Expand Up @@ -498,6 +513,28 @@ public static void load() throws IOException {
Configuration.screenResolutionProfile.getOffsetLabelPersuadeMoghur(), //
0xFF807D
);

// Character Select
Metas.Character.Dialogs.loading = BwMatrixMeta.from(//
"dialogs/character.loading2?",
Configuration.screenResolutionProfile.getOffsetDialogCharacterLoading(), //
0xFFFFFF
);
Metas.Character.Buttons.confirm = BwMatrixMeta.from(//
"buttons/character.confirm2?",
Configuration.screenResolutionProfile.getOffsetLabelCharacterConfirm(), //
0xFFFFFF
);
Metas.Character.Buttons.characterSelect = BwMatrixMeta.from(//
"buttons/character.select2?",
Configuration.screenResolutionProfile.getOffsetLabelCharacterSelect(), //
0xFFFFFF
);
Metas.Character.Labels.heroes = BwMatrixMeta.from(//
"labels/character.heroes2?",
Configuration.screenResolutionProfile.getOffsetLabelCharacterHeroes(), //
0xFFFFFF
);

// Fishing
Metas.Fishing.Labels.fishing = BwMatrixMeta.from(//
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.