diff --git a/README.md b/README.md index 24529dc..953c9c8 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ - 确保网络通畅, 中途尽量不要出现连接失败以及掉线的状况 - 请关闭手机休眠 - 游戏设置中的`Quality`调整为`high` +- 语言请使用`English` - 游戏宽高比设置为`16:9` - 如果加入了社团请先退出, 否则会导致操作失败 - 目前版本仅能抽取30抽, 40抽预计下个版本支持 diff --git a/main.py b/main.py index 92c3961..094fbf3 100644 --- a/main.py +++ b/main.py @@ -4,8 +4,9 @@ from typing import Optional from utils import adb +from script import script -__version__ = "0.0.1" +__version__ = "1.0.0" device_now = "" adb_con: Optional[adb.ADB] = None # adb类变量 @@ -22,22 +23,31 @@ def _if_adb_exists(): def menu(): - print("\n" * 3) + print("\n" * 1) if device_now: - print("当前设备: " + device_now + "端口: " + str(port)) + print("当前设备: " + device_now + "端口: " + str(port) + "\n") else: - print("当前未连接设备") + print("当前未连接设备\n") print("1. 注意事项(必读)") - print("2. 扫描设备(TODO)") + print("2. 扫描设备") print("3. 截图适配(TODO)") - print("4. 加载") + print("4. 加载(TODO)") print("5. 运行脚本") print("6. 退出") def notice(): - pass + notice = """ +- 确保网络通畅, 中途尽量不要出现连接失败以及掉线的状况 +- 请关闭手机休眠 +- 游戏设置中的`Quality`调整为`high` +- 语言请使用`English` +- 游戏宽高比设置为`16:9` +- 如果加入了社团请先退出, 否则会导致操作失败 +- 目前版本仅能抽取30抽, 40抽预计下个版本支持""" + print(notice) + input("按任意键以继续...") def scan(): @@ -53,6 +63,8 @@ def scan(): print("2. 重新扫描") for i, device in enumerate(device_lst): print(f"{i + 3}. {device}") + if "127.0.0.1" in device: # 消除重复设备 + continue all_device_lst[i + 3] = device.split(" ")[0] if len(device_lst) == 0: @@ -95,211 +107,19 @@ def load(): def run(): - def skip_story(): - adb_con.click(95, 5) - adb_con.click(95, 15) - adb_con.click(63, 71) - global adb_con - name = input("请输入你想要的昵称(禁止非法字符): ") - path = Path("./data/16_9/") - mapping = json.load(open(path.joinpath("mapping.json"), "r", encoding="utf-8")) - - while not adb_con.compare_img( - *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") - ): - adb_con.back() - - logger.info("已回到主菜单,开始销号") - adb_con.click(95, 4) - adb_con.click(60, 40) - adb_con.click(70, 50) - adb_con.click(55, 45) - adb_con.input_text("BlueArchive") - adb_con.click(58, 67) - adb_con.click(58, 67) - adb_con.multi_click(55, 70, 5) - - logger.success("1. 创建账号") - while not adb_con.compare_img( - *mapping["start_menu_icon.png"], img=path.joinpath("start_menu_icon.png") - ): - adb_con.sleep(1) - logger.info("已进入开始界面") - - adb_con.multi_click(50, 70, 4) - while not adb_con.compare_img( - *mapping["start_name.png"], img=path.joinpath("start_name.png") - ): - adb_con.click(50, 70) - logger.info("输入名字") - adb_con.click(50, 50) - - adb_con.input_text(name) - adb_con.multi_click(50, 70, 40) - - logger.success("2. 初始剧情") - while not adb_con.compare_img( - *mapping["story_menu.png"], img=path.joinpath("story_menu.png") - ): - adb_con.click(50, 50) - skip_story() - logger.success("3. 战斗1") - logger.info("跳过介绍") - adb_con.multi_click(50, 70, 25) - while not adb_con.compare_img( - *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") - ): - logger.info("尝试使用技能") - for _ in range(2): - adb_con.click(80, 88) - adb_con.click(80, 35) - adb_con.click(70, 88) - adb_con.click(43, 52) - logger.info("战斗结束") - adb_con.click(90, 90) - logger.success("4. 两段剧情") - for _ in range(2): - while not adb_con.compare_img( - *mapping["story_menu.png"], img=path.joinpath("story_menu.png") - ): - adb_con.click(50, 50) - skip_story() - logger.success("5. 战斗2") - adb_con.multi_click(50, 50, 15) - for i in range(4): - while not adb_con.compare_img( - *mapping["story_menu.png"], img=path.joinpath("story_menu.png") - ): - adb_con.multi_click(50, 50, 3) - logger.info(f"第 {i + 1} 段剧情") - skip_story() - logger.success("使用技能") - adb_con.multi_click(50, 50, 5) - adb_con.click(70, 88) - adb_con.click(80, 20) - while not adb_con.compare_img( - *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") - ): - adb_con.sleep(1) - adb_con.click(90, 90) - logger.success("5. 两段剧情") - while not adb_con.compare_img( - *mapping["story_menu.png"], img=path.joinpath("story_menu.png") - ): - adb_con.click(50, 50) - for _ in range(4): - skip_story() - logger.success("6. OP 动画") - adb_con.multi_click(60, 70, 10) - - logger.success("1. 开局抽卡") - while not adb_con.compare_img( - *mapping["main_recurit.png"], img=path.joinpath("main_recurit.png"), confidence=0.6 - ): - adb_con.multi_click(50, 50, 3) - adb_con.click(70, 90) - adb_con.sleep(10) - adb_con.click(76, 72) - adb_con.click(60, 70) - adb_con.multi_click(50, 75, 10) - while not adb_con.compare_img( - *mapping["recurit_confirm.png"], img=path.joinpath("recurit_confirm.png") - ): - adb_con.multi_click(92, 7, 5) - adb_con.screenshot("1.png") - adb_con.click(50, 90) - adb_con.sleep(10) - logger.success("2. 开始作战") - adb_con.multi_click(88, 35, 4) - adb_con.multi_click(75, 75, 3) - adb_con.multi_click(40, 65, 10) - logger.success("3. 开始编队") - adb_con.multi_click(95, 25, 5) - adb_con.sleep(3) - adb_con.multi_click(25, 50, 10) - logger.success("4. 开始道中作战") - adb_con.multi_click(90, 80, 2) - for _ in range(2): - adb_con.multi_click(90, 90, 2) - adb_con.sleep(5) - adb_con.multi_click(50, 63, 5) - adb_con.sleep(10) - logger.success("5. 开启auto") - adb_con.click(95, 95) - while not adb_con.compare_img( - *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") - ): - adb_con.sleep(1) - logger.success("6. 完成作战") - adb_con.click(90, 90) - adb_con.sleep(5) - adb_con.click(50, 90) - adb_con.sleep(5) - adb_con.multi_click(90, 90, 5) - logger.success("7. 开始BOSS作战") - adb_con.multi_click(60, 55, 5) - while not adb_con.compare_img( - *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") - ): - adb_con.sleep(1) - logger.success("8. 完成作战") - adb_con.multi_click(90, 90, 5) - adb_con.multi_click(85, 90, 10) - logger.success("9. 返回大厅") - adb_con.multi_click(40, 90, 20) - while not adb_con.compare_img( - *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") - ): - adb_con.multi_click(40, 90, 5) - logger.success("10. MomoTalk & 收取邮件") - while not adb_con.compare_img( - *mapping["no_mail.png"], img=path.joinpath("no_mail.png"), confidence=0.5 - ): - for _ in range(2): - adb_con.click(12.18, 18.66) - adb_con.click(11.56, 41.11) - adb_con.click(88, 5) - adb_con.click(88, 5) - adb_con.click(82.5, 94.44) - logger.success("11. 开始抽卡") - while not adb_con.compare_img( - *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") - ): - for _ in range(3): - adb_con.back() - logger.info("进入抽卡") - adb_con.multi_click(70, 90, 3) - while not adb_con.compare_img( - *mapping["recurit_page.png"], img=path.joinpath("recurit_page.png") - ): - logger.info("翻页") - adb_con.click(3, 55) - logger.debug("切换卡池") - adb_con.multi_click(3, 55, 2) - logger.info("开始抽卡") - adb_con.click(76, 72) - adb_con.click(60, 70) - adb_con.sleep(5) - for i in range(2): - adb_con.multi_click(50, 75, 5) - while not adb_con.compare_img( - *mapping["recurit_confirm.png"], img=path.joinpath("recurit_confirm.png") - ): - adb_con.multi_click(92, 7, 3) - adb_con.screenshot(f"{i + 2}.png") - adb_con.click(50, 90) - adb_con.sleep(3) - adb_con.click(60, 90) - adb_con.click(60, 65) - logger.info("回到主菜单") - while not adb_con.compare_img( - *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") - ): - for _ in range(3): - adb_con.back() - + try: + mapping = json.load(open(path.joinpath("mapping.json"), "r", encoding="utf-8")) + except FileNotFoundError: + logger.error("未找到资源文件, 请确认下载是否完整") + return + + script( + adb_con, + path, + mapping + ) def _verify_device(): global adb_con @@ -312,7 +132,7 @@ def _verify_device(): if __name__ == '__main__': print(f"欢迎使用BlueArchive-Starter-cli, 当前版本{__version__}, 作者: ACGN-Alliance, 交流群: 769521861") - # time.sleep(2) + time.sleep(2) while True: menu() mode = input("请选择模式: ") @@ -339,6 +159,7 @@ def _verify_device(): break run() elif mode == 6: + print("感谢使用~") sys.exit(0) else: print("请选择正确的模式") diff --git a/pdm.lock b/pdm.lock index 83cad55..ae1141f 100644 --- a/pdm.lock +++ b/pdm.lock @@ -6,7 +6,7 @@ groups = ["default"] cross_platform = true static_urls = false lock_version = "4.3" -content_hash = "sha256:b9930618fda8a52c32bd90d7104f164965a5ae4064a9c3921d7a0b4eee7e11f4" +content_hash = "sha256:96b4d4bea41d906bb83711a0509b500a54c0e370a377084dadaaabb6fa0e9eb7" [[package]] name = "colorama" @@ -96,16 +96,6 @@ files = [ {file = "Pillow-10.0.0.tar.gz", hash = "sha256:9c82b5b3e043c7af0d95792d0d20ccf68f61a1fec6b3530e718b688422727396"}, ] -[[package]] -name = "setuptools" -version = "68.1.0" -requires_python = ">=3.8" -summary = "Easily download, build, install, upgrade, and uninstall Python packages" -files = [ - {file = "setuptools-68.1.0-py3-none-any.whl", hash = "sha256:e13e1b0bc760e9b0127eda042845999b2f913e12437046e663b833aa96d89715"}, - {file = "setuptools-68.1.0.tar.gz", hash = "sha256:d59c97e7b774979a5ccb96388efc9eb65518004537e85d52e81eaee89ab6dd91"}, -] - [[package]] name = "win32-setctime" version = "1.1.0" diff --git a/pyproject.toml b/pyproject.toml index c70b4e6..c59fb69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ authors = [ dependencies = [ "loguru>=0.7.0", "pillow>=10.0.0", - "setuptools>=68.1.0", ] requires-python = ">=3.8" license = {text = "MIT"} diff --git a/script.py b/script.py new file mode 100644 index 0000000..9f208bb --- /dev/null +++ b/script.py @@ -0,0 +1,220 @@ +import pathlib +from typing import Any +from loguru import logger + +from utils import adb + +def script( + adb_con: adb.ADB, + path: pathlib.Path, + mapping: Any, + *args, + load_point = 0 +): + """ + 执行脚本 + adb_con: adb连接对象 + path: 图片加载地址 + mapping: 图片映射表 + load_point: 起始位置 + """ + def skip_story(): + adb_con.click(95, 5) + adb_con.click(95, 15) + adb_con.click(63, 71) + + name = input("请输入你想要的昵称(禁止非法字符): ") + + while not adb_con.compare_img( + *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") + ): + adb_con.back() + + logger.info("已回到主菜单,开始销号") + adb_con.click(95, 4) + adb_con.click(60, 40) + adb_con.click(70, 50) + adb_con.click(55, 45) + adb_con.input_text("BlueArchive") + adb_con.click(58, 67) + adb_con.click(58, 67) + adb_con.multi_click(55, 70, 5) + + logger.success("1. 创建账号") + while not adb_con.compare_img( + *mapping["start_menu_icon.png"], img=path.joinpath("start_menu_icon.png") + ): + adb_con.sleep(1) + logger.info("已进入开始界面") + + adb_con.multi_click(50, 70, 4) + while not adb_con.compare_img( + *mapping["start_name.png"], img=path.joinpath("start_name.png") + ): + adb_con.click(50, 70) + logger.info("输入名字") + adb_con.click(50, 50) + + adb_con.input_text(name) + adb_con.multi_click(50, 70, 40) + + logger.success("2. 初始剧情") + while not adb_con.compare_img( + *mapping["story_menu.png"], img=path.joinpath("story_menu.png") + ): + adb_con.click(50, 50) + skip_story() + logger.success("3. 战斗1") + logger.info("跳过介绍") + adb_con.multi_click(50, 70, 25) + while not adb_con.compare_img( + *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") + ): + logger.info("尝试使用技能") + for _ in range(2): + adb_con.click(80, 88) + adb_con.click(80, 35) + adb_con.click(70, 88) + adb_con.click(43, 52) + logger.info("战斗结束") + adb_con.click(90, 90) + logger.success("4. 两段剧情") + for _ in range(2): + while not adb_con.compare_img( + *mapping["story_menu.png"], img=path.joinpath("story_menu.png") + ): + adb_con.click(50, 50) + skip_story() + logger.success("5. 战斗2") + adb_con.multi_click(50, 50, 15) + for i in range(4): + while not adb_con.compare_img( + *mapping["story_menu.png"], img=path.joinpath("story_menu.png") + ): + adb_con.multi_click(50, 50, 3) + logger.info(f"第 {i + 1} 段剧情") + skip_story() + logger.success("使用技能") + adb_con.multi_click(50, 50, 5) + adb_con.click(70, 88) + adb_con.click(80, 20) + while not adb_con.compare_img( + *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") + ): + adb_con.sleep(1) + adb_con.click(90, 90) + logger.success("5. 两段剧情") + while not adb_con.compare_img( + *mapping["story_menu.png"], img=path.joinpath("story_menu.png") + ): + adb_con.click(50, 50) + for _ in range(4): + skip_story() + logger.success("6. OP 动画") + adb_con.multi_click(60, 70, 10) + + logger.success("1. 开局抽卡") + while not adb_con.compare_img( + *mapping["main_recurit.png"], img=path.joinpath("main_recurit.png"), confidence=0.6 + ): + adb_con.multi_click(50, 50, 3) + adb_con.click(70, 90) + adb_con.sleep(10) + adb_con.click(76, 72) + adb_con.click(60, 70) + adb_con.multi_click(50, 75, 10) + while not adb_con.compare_img( + *mapping["recurit_confirm.png"], img=path.joinpath("recurit_confirm.png") + ): + adb_con.multi_click(92, 7, 5) + adb_con.screenshot("1.png") + adb_con.click(50, 90) + adb_con.sleep(10) + logger.success("2. 开始作战") + adb_con.multi_click(88, 35, 4) + adb_con.multi_click(75, 75, 3) + adb_con.multi_click(40, 65, 10) + logger.success("3. 开始编队") + adb_con.multi_click(95, 25, 5) + adb_con.sleep(3) + adb_con.multi_click(25, 50, 10) + logger.success("4. 开始道中作战") + adb_con.multi_click(90, 80, 2) + for _ in range(2): + adb_con.multi_click(90, 90, 2) + adb_con.sleep(5) + adb_con.multi_click(50, 63, 5) + adb_con.sleep(10) + logger.success("5. 开启auto") + adb_con.click(95, 95) + while not adb_con.compare_img( + *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") + ): + adb_con.sleep(1) + logger.success("6. 完成作战") + adb_con.click(90, 90) + adb_con.sleep(5) + adb_con.click(50, 90) + adb_con.sleep(5) + adb_con.multi_click(90, 90, 5) + logger.success("7. 开始BOSS作战") + adb_con.multi_click(60, 55, 5) + while not adb_con.compare_img( + *mapping["battle_finish.png"], img=path.joinpath("battle_finish.png") + ): + adb_con.sleep(1) + logger.success("8. 完成作战") + adb_con.multi_click(90, 90, 5) + adb_con.multi_click(85, 90, 10) + logger.success("9. 返回大厅") + adb_con.multi_click(40, 90, 20) + while not adb_con.compare_img( + *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") + ): + adb_con.multi_click(40, 90, 5) + logger.success("10. MomoTalk & 收取邮件") + while not adb_con.compare_img( + *mapping["no_mail.png"], img=path.joinpath("no_mail.png"), confidence=0.5 + ): + for _ in range(2): + adb_con.click(12.18, 18.66) + adb_con.click(11.56, 41.11) + adb_con.click(88, 5) + adb_con.click(88, 5) + adb_con.click(82.5, 94.44) + logger.success("11. 开始抽卡") + while not adb_con.compare_img( + *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") + ): + for _ in range(3): + adb_con.back() + logger.info("进入抽卡") + adb_con.multi_click(70, 90, 3) + while not adb_con.compare_img( + *mapping["recurit_page.png"], img=path.joinpath("recurit_page.png") + ): + logger.info("翻页") + adb_con.click(3, 55) + logger.debug("切换卡池") + adb_con.multi_click(3, 55, 2) + logger.info("开始抽卡") + adb_con.click(76, 72) + adb_con.click(60, 70) + adb_con.sleep(5) + for i in range(2): + adb_con.multi_click(50, 75, 5) + while not adb_con.compare_img( + *mapping["recurit_confirm.png"], img=path.joinpath("recurit_confirm.png") + ): + adb_con.multi_click(92, 7, 3) + adb_con.screenshot(f"{i + 2}.png") + adb_con.click(50, 90) + adb_con.sleep(3) + adb_con.click(60, 90) + adb_con.click(60, 65) + logger.info("回到主菜单") + while not adb_con.compare_img( + *mapping["main_momotalk.png"], img=path.joinpath("main_momotalk.png") + ): + for _ in range(3): + adb_con.back() \ No newline at end of file