Skip to content

Commit

Permalink
⚡ 脚本内容与主程序分离, 增加注意事项, 增加健壮性
Browse files Browse the repository at this point in the history
  • Loading branch information
MRSlouzk committed Aug 21, 2023
1 parent e4f2b6c commit 59e9d44
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 223 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- 确保网络通畅, 中途尽量不要出现连接失败以及掉线的状况
- 请关闭手机休眠
- 游戏设置中的`Quality`调整为`high`
- 语言请使用`English`
- 游戏宽高比设置为`16:9`
- 如果加入了社团请先退出, 否则会导致操作失败
- 目前版本仅能抽取30抽, 40抽预计下个版本支持
Expand Down
243 changes: 32 additions & 211 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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类变量
Expand All @@ -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():
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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("请选择模式: ")
Expand All @@ -339,6 +159,7 @@ def _verify_device():
break
run()
elif mode == 6:
print("感谢使用~")
sys.exit(0)
else:
print("请选择正确的模式")
Expand Down
12 changes: 1 addition & 11 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Loading

0 comments on commit 59e9d44

Please sign in to comment.